E-Gen: Leveraging E-Graphs to Improve Continuous Representations of Symbolic Expressions
Hongbo Zheng, Suyuan Wang, Neeraj Gangwar, Nickvash Kani
TL;DR
E-Gen introduces an e-graph–based corpus generation framework to produce large, diverse clusters of semantically equivalent mathematical expressions. By training embeddings with seq2seq and contrastive learning on this cluster-based data, the approach achieves strong performance on clustering, semantic understanding beyond syntax, mistake detection, and embedding algebra, often outperforming prior SymPy-based methods and GPT-4o. The results demonstrate that rich, transformation-aware representations can be learned from synthetic, structure-focused data, with significant implications for mathematical information retrieval and reasoning. The work highlights the importance of operator diversity and semantic clustering in embedding symbolic mathematics for robust downstream applications.
Abstract
Vector representations have been pivotal in advancing natural language processing (NLP), with prior research focusing on embedding techniques for mathematical expressions using mathematically equivalent formulations. While effective, these approaches are constrained by the size and diversity of training data. In this work, we address these limitations by introducing E-Gen, a novel e-graph-based dataset generation scheme that synthesizes large and diverse mathematical expression datasets, surpassing prior methods in size and operator variety. Leveraging this dataset, we train embedding models using two strategies: (1) generating mathematically equivalent expressions, and (2) contrastive learning to explicitly group equivalent expressions. We evaluate these embeddings on both in-distribution and out-of-distribution mathematical language processing tasks, comparing them against prior methods. Finally, we demonstrate that our embedding-based approach outperforms state-of-the-art large language models (LLMs) on several tasks, underscoring the necessity of optimizing embedding methods for the mathematical data modality. The source code and datasets are available at https://github.com/MLPgroup/E-Gen.
