Table of Contents
Fetching ...

Quantifying Behavioral Dissimilarity Between Mathematical Expressions

Sebastian Mežnar, Sašo Džeroski, Ljupčo Todorovski

TL;DR

This work introduces Behavior-aware Expression Dissimilarity (BED), a distance between mathematical expressions with free parameters that captures behavioral differences by representing expressions as joint input-output distributions and measuring their divergence with the $W_1$ distance. A scalable stochastic approximation, using Latin Hypercube Sampling and empirical CDFs, makes BED computable and robust, enabling behavior-based clustering and guiding symbolic regression toward functionally similar expressions. Empirical results show BED achieves near-perfect clustering of behaviorally equivalent expressions, produces a substantially smoother error manifold than syntactic measures, and ranks near the oracle in predicting RMSE on large symbolic regression benchmarks. BED thus provides a principled foundation for behavior-based comparison, learning, and benchmarking of parameterized expressions, with implications for equation discovery and neuro-symbolic modeling.

Abstract

Quantifying the similarity between mathematical expressions is a fundamental problem in computational mathematics, symbolic reasoning, and scientific discovery. While behavioral notions of similarity have previously been explored in the context of software and program analysis, existing measures for mathematical expressions rely primarily on syntactic form, assessing similarity through symbolic structure rather than actual behavior. Yet syntactically distinct expressions can exhibit nearly identical outputs, while structurally similar ones may behave very differently-especially when the expressions contain free parameters that define families of functions. To address these limitations, we introduce Behavior-aware Expression Dissimilarity (BED), a principled framework for quantifying behavioral distance between mathematical expressions with free parameters. BED represents expressions as joint probability distributions over their input-output pairs and applies the Wasserstein distance to measure behavioral dissimilarity. A computationally efficient stochastic approximation is proposed and shown to be consistent, robust, and capable of inducing a smoother, more meaningful structure over the space of expressions than syntax-based measures. The approach provides a foundation for behavior-based comparison, clustering, and learning of mathematical expressions, with potential direct applications in equation discovery, symbolic regression, and neuro-symbolic modeling.

Quantifying Behavioral Dissimilarity Between Mathematical Expressions

TL;DR

This work introduces Behavior-aware Expression Dissimilarity (BED), a distance between mathematical expressions with free parameters that captures behavioral differences by representing expressions as joint input-output distributions and measuring their divergence with the distance. A scalable stochastic approximation, using Latin Hypercube Sampling and empirical CDFs, makes BED computable and robust, enabling behavior-based clustering and guiding symbolic regression toward functionally similar expressions. Empirical results show BED achieves near-perfect clustering of behaviorally equivalent expressions, produces a substantially smoother error manifold than syntactic measures, and ranks near the oracle in predicting RMSE on large symbolic regression benchmarks. BED thus provides a principled foundation for behavior-based comparison, learning, and benchmarking of parameterized expressions, with implications for equation discovery and neuro-symbolic modeling.

Abstract

Quantifying the similarity between mathematical expressions is a fundamental problem in computational mathematics, symbolic reasoning, and scientific discovery. While behavioral notions of similarity have previously been explored in the context of software and program analysis, existing measures for mathematical expressions rely primarily on syntactic form, assessing similarity through symbolic structure rather than actual behavior. Yet syntactically distinct expressions can exhibit nearly identical outputs, while structurally similar ones may behave very differently-especially when the expressions contain free parameters that define families of functions. To address these limitations, we introduce Behavior-aware Expression Dissimilarity (BED), a principled framework for quantifying behavioral distance between mathematical expressions with free parameters. BED represents expressions as joint probability distributions over their input-output pairs and applies the Wasserstein distance to measure behavioral dissimilarity. A computationally efficient stochastic approximation is proposed and shown to be consistent, robust, and capable of inducing a smoother, more meaningful structure over the space of expressions than syntax-based measures. The approach provides a foundation for behavior-based comparison, clustering, and learning of mathematical expressions, with potential direct applications in equation discovery, symbolic regression, and neuro-symbolic modeling.
Paper Structure (22 sections, 4 theorems, 17 equations, 11 figures, 4 tables)

This paper contains 22 sections, 4 theorems, 17 equations, 11 figures, 4 tables.

Key Result

Proposition A.1

The BED measure is non-negative, i.e., $\text{BED}^{(\mathcal{X})}(\mathit{E},\mathit{F}) \ge 0$.

Figures (11)

  • Figure 1: The left-hand side shows the behavior of the expression $y = \frac{1}{\sqrt{2\pi C}} \cdot e^{\frac{-x^2}{2 \cdot C^2}}$ modeled as a probability distribution. This figure illustrates how we define the behavior of an expression with free parameters. The distribution is obtained by sampling the free parameter $C$ (representing standard deviation) from the interval $[0.2, 2]$. The color intensity at each point indicates the conditional probability density of an output value $y$ given an input $x$. A higher density (green color) means that more sampled curves pass through that point. The red line shows the standard normal distribution, representing the behavior of a single expression with a fixed parameter value of $C = 1$. The right-hand side shows the distributions of output of the expression in the left figure at $x=0$ and $x=1$.
  • Figure 2: A visual breakdown of BED measure calculation. Left panels show the behaviors of expressions, $E := C_0 \cdot x + C_1 \cdot x$ and $F := 2 \cdot C_0 \cdot x$, across the domain $x \in [-2.5, 2.5]$. Values of the free parameters are sampled from the interval $[0.1, 5]$. The color bar on the right of each plot represents the probability of a given output value. Top-right panel compares the Cumulative Distribution Functions (CDFs) of both expressions at a specific point, $x=-2.0$. The shaded area between the two curves represents a single-point BED value between the expressions. Bottom-right panel plots the single-point BED values across the entire domain. The final BED score is the average of these values.
  • Figure 3: A heatmap depicting the consistency of BED across different hyperparameter settings of the sampling parameters (the number of variable and constant values sampled, #VS and #CS, respectively) for the expressions with at most two variables.
  • Figure 4: Multi-Dimensional Scaling (MDS) visualizations of expression dissimilarities. The left plot uses distances computed with BED, while the right plot uses tree edit distance. Each color and shape combination represents a ground truth group of behaviorally equivalent expressions. Observe how BED effectively brings equivalent expressions into tight clusters, showcasing a logical arrangement of behavioral groups, in contrast to the scattered representation by tree edit distance.
  • Figure 5: Median aggregated RMSE for top closest expressions across two benchmark equations. Each subfigure illustrates how the median RMSE of the top N expressions, ordered by different dissimilarity measures, evolves as N increases (from 1 to 250). BED consistently achieves significantly lower and smoother aggregated RMSE curves compared to syntactic measures, demonstrating its superior ability to induce a smooth error manifold.
  • ...and 6 more figures

Theorems & Definitions (8)

  • Proposition A.1: Non-Negativity
  • proof
  • Proposition A.2: Reflexivity
  • proof
  • Proposition A.3: Symmetry
  • proof
  • Proposition A.4: Triangle Inequality
  • proof