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.
