MAMUT: A Novel Framework for Modifying Mathematical Formulas for the Generation of Specialized Datasets for Language Model Training

Jonathan Drechsel, Anja Reusch, Steffen Herbold

Abstract

Mathematical formulas are a fundamental and widely used component in various scientific fields, serving as a universal language for expressing complex concepts and relationships. While state-of-the-art transformer models excel in processing and understanding natural language, they encounter challenges with mathematical notation, which involves a complex structure and diverse representations. This study focuses on the development of specialized training datasets to enhance the encoding of mathematical content. We introduce Math Mutator (MAMUT), a framework capable of generating equivalent and falsified versions of a given mathematical formula in LaTeX notation, effectively capturing the mathematical variety in notation of the same concept. Based on MAMUT, we have generated four large mathematical datasets containing diverse notation, which can be used to train language models with enhanced mathematical embeddings. Experiments show that models trained on these datasets exhibit new SoTA performance on mathematical retrieval tasks. We publish our code, generated datasets, and pretrained mathematical models: https://github.com/aieng-lab/math-mutator.

Introduction

While Large Language Models (LLMs) have demonstrated remarkable proficiency in natural language processing, their performance often degrades when encountering mathematical notation. Unlike natural language, mathematics is a dense, symbolic system where minor structural variations—such as changing a variable name or an operator—can fundamentally alter the underlying logic.

Current models face three primary obstacles:

  1. Notation Variety: Mathematical concepts can be expressed through multiple equivalent LaTeX representations (e.g., $a/b$ vs. $\frac{a}{b}$).
  2. Symbol Abstraction: Models must recognize that identities are invariant to specific variable choices (e.g., $(a+b)^2$ vs. $(x+y)^2$).
  3. Data Scarcity: There is a lack of high-quality, large-scale datasets that include "hard negatives"—formulas that appear correct but contain subtle mathematical errors.

The MAMUT Framework

To address these challenges, we present Math Mutator (MAMUT), a framework designed to automate the generation of diverse mathematical training data. MAMUT operates by parsing LaTeX formulas into symbolic operator trees using the SymPy library and applying two primary mutation algorithms:

Equivalent Version Generation (EquVG)

EquVG generates "mathematical synonyms" by performing symbol substitution and randomized printing. Symbol substitution renames variables while maintaining their structural relationships, teaching the model symbolic invariance. Randomized printing varies the LaTeX output format (e.g., changing \cdot to *), ensuring the model is robust to stylistic differences.

The MAMUT mutation process: parsing an input formula into a symbolic expression, performing symbol substitution, and generating a new LaTeX version.

Falsified Version Generation (FalseVG)

FalseVG creates "hard negatives" by introducing surgical, mathematically incorrect modifications. This includes flipping inequalities, swapping operands in non-commutative operations, or omitting terms. These examples force models to move beyond superficial pattern matching and engage with the actual logic of the formula.

Generated Datasets

Using the MAMUT framework, we produced four large-scale datasets derived from sources such as AMPS and ARQMath. These datasets provide a rich foundation for training models on both masked language modeling (MLM) and retrieval tasks.

Overview of the four specialized mathematical datasets (MF, MT, NMF, MFR) generated using the MAMUT framework.

The datasets include:

  • Mathematical Formulas (MF): Over 3 million formula versions for MLM.
  • Mathematical Texts (MT): 7 million examples blending natural language with mathematical notation.
  • Named Mathematical Formulas (NMF): High-variance versions of famous identities based on a curated template set.
  • Mathematical Formula Retrieval (MFR): Pairs of formulas labeled as equivalent or non-equivalent for contrastive learning.

Results and Performance

We evaluated MAMUT-enhanced models (based on BERT and MPBERT architectures) on Mathematical Information Retrieval (MIR) tasks. The results indicate that pretraining on mutated data significantly improves a model's ability to encode mathematical structure.

The MAMUT-MPBERT-MLM model achieved state-of-the-art performance, specifically on the MFR-FT task (identifying equivalent formulas), where it reached an F1-score of 80.6%. This represents a substantial improvement over standard BERT (56.1%) and the original MPBERT (74.0%). Notably, even models previously specialized for math, such as MathBERT, showed performance gains when fine-tuned on MAMUT data, highlighting the unique value of structural "mutations."

Conclusion and Future Work

MAMUT provides a scalable solution for generating high-quality mathematical training data. By focusing on symbolic invariance and hard negatives, the framework enables language models to achieve a deeper understanding of mathematical logic. Future work will focus on expanding the framework beyond LaTeX to include formats like MathML and increasing the library of seed identities to cover more advanced university-level mathematics.

The code and datasets are available at: https://github.com/aieng-lab/math-mutator.

Summary updated

BibTeX
@article{drechsel2025mamut,
  author = {Jonathan Drechsel and Anja Reusch and Steffen Herbold},
  title = {{MAMUT: A Novel Framework for Modifying Mathematical Formulas for the Generation of Specialized Datasets for Language Model Training}},
  journal = {Accepted by TMLR},
  year = {2025},
  url = {https://openreview.net/forum?id=khODmRpQEx},
}
Figure