Tree Structured Generation of Mathematical Expressions

87 concepts65 papers3 proposals

Standard language models excel at processing text because natural language is largely fluid and sequential. However, when these models encounter mathematics, this sequential paradigm breaks down.

In standard sequence-to-sequence architectures, a mathematical formula is treated as a flat string of characters (e.g., (3 + 5) * 2). To generate this correctly, a model must implicitly learn the rules of parentheses, operator precedence, and token balancing entirely from data. As noted by Scarlatos et al. in Tree-Based Representation and Generation of Natural and Mathematical Language, treating formulas as flat character sequences frequently violates the rigid, structural rules of mathematics. Zhao et al. in Handwritten Mathematical Expression Recognition with Bidirectionally Trained Transformer echo this limitation, pointing out that linear decoders fail to fully capture multi-level, deeply nested mathematical notation.

To resolve this fundamental mismatch, a prominent research direction abandons linear strings in favor of tree-structured decoding. By representing and generating mathematical expressions as hierarchical trees, models can natively respect the syntax and logic of mathematics.

The Operator Tree Representation

The core intuition behind this approach is to map mathematical expressions to an Abstract Syntax Tree (AST) or an operator tree. In this representation:

  • Internal nodes represent mathematical operators (such as $+$, $\times$, or $\div$).
  • Leaf nodes represent operands, which can be variables, constants, or numerical values.
       [ × ]          <-- Root Operator
      /     \
   [ + ]    [ c ]     <-- Internal Operator & Leaf Operand
   /   \
 [ a ] [ b ]          <-- Leaf Operands

As described by Zhang et al. in Math Operation Embeddings for Open-ended Solution Analysis and Feedback and Wang et al. in Mathematical Formula Representation via Tree Embeddings, this structure explicitly maps out the branching logic of an equation. The tree structure naturally preserves the scope of operators and the nesting of variables, preventing the structural information loss that occurs during linearization.

Why It Works: Native Syntactic and Logical Constraints

Shifting from a flat sequence to a hierarchical tree provides three critical advantages that make mathematical reasoning more robust:

1. Guaranteed Syntactic Validity

In a linear sequence, a model might emit an operator without its required arguments (for example, generating 5 + * 3). A tree-structured decoder avoids this by natively enforcing operator arity (the number of arguments an operator requires). As Xie et al. demonstrate in A Goal-Driven Tree-Structured Neural Model for Math Word Problems, a tree-based generation process ensures that every operator node is structurally guaranteed to branch into the correct number of child operands, eliminating syntactically invalid equations.

2. Explicit Operator Precedence

Instead of forcing a neural network to infer the order of operations from string positions or parentheses, the tree structure encodes precedence through depth. Operations lower in the tree are evaluated first. Wang et al. in Translating Math Word Problem to Expression Tree show that predicting tree traversals removes the ambiguity of operator precedence, allowing models to handle complex, multi-step equations smoothly.

3. Capturing Semantic Invariance

Mathematical logic is invariant to certain surface-level changes; for instance, $a+b$ is functionally identical to $b+a$. Chen notes in AlphaSAGE: Structure-Aware Alpha Mining via GFlowNets for Robust Exploration that encoding expressions as hierarchical graphs or trees captures this underlying semantic invariance. This prevents models from treating functionally identical operations as completely different entities based on character-level representations.

Decoding Mechanics: Top-Down and Bottom-Up Generation

To generate these trees auto-regressively, researchers have developed specialized decoding strategies that dictate how the neural network traverses and constructs the mathematical architecture.

Top-Down Generation

The most common paradigm is top-down, pre-order traversal decoding, which mimics human goal decomposition. The model identifies a final mathematical goal (the root operator) and recursively breaks it down into smaller sub-goals.

Liu et al. in Tree-structured Decoding for Solving Math Word Problems implement this by explicitly modeling parent-child and sibling relationships using an auxiliary stack to manage the decoding process. Similarly, Wu et al. in A Knowledge-Aware Sequence-to-Tree Network for Math Word Problem Solving use pre-order traversal to map operators to parent nodes and numerical values to leaf nodes. To determine when a deeply nested branch is complete, the tree decoder designed by Wang et al. in Mathematical Formula Representation via Tree Embeddings incorporates explicit termination signals ("end" nodes), allowing the model to safely conclude a specific mathematical branch.

Bottom-Up Generation

Alternatively, models can build expressions from the ground up. Cao et al. in A Bottom-Up DAG Structure Extraction Model for Math Word Problems propose a bottom-up extraction process. This method iteratively combines known quantities and variables into Directed Acyclic Graphs (DAGs), which naturally handles problems involving multiple shared variables while natively incorporating mathematical properties like the commutative law.

Compositionality and Verification

The benefits of tree structures extend beyond generation to representation and verification. In Combining Symbolic Expressions and Black-box Function Evaluations in Neural Programs, the authors utilize a tree-structured recursive architecture where each mathematical operator corresponds to a specific neural cell. This design mirrors the equation's parse tree to capture the inherent compositionality of mathematical logic.

This structural alignment is highly effective for verification tasks, where a model must check its work or map an equation back to its text source. For instance, Bin et al. in Solving Math Word Problems with Reexamination demonstrate that graph- and tree-based encoders significantly outperform sequential representations when verifying whether a predicted equation accurately matches the original natural language problem description.

Applications in Retrieval and Discovery

Because tree structures isolate core algebraic logic from surface-level text, they enable highly precise mathematical information retrieval and formula discovery.

In retrieval, Goel et al. in MWPRanker: An Expression Similarity Based Math Word Problem Retriever and Gao et al. in ICST Math Retrieval System for NTCIR-11 Math-2 Task decompose formulas into hierarchies of sub-trees. This allows retrieval systems to perform structural sub-expression matching, identifying logically identical problems regardless of whether the word problem is phrased around calculating interest rates or counting objects.

In the domain of scientific discovery, Sun in Symbolic Physics Learner: Discovering governing equations via Monte Carlo tree search leverages tree-based representations within a Monte Carlo Tree Search framework. By treating equation discovery as a tree search, the framework flexibly constructs and evaluates diverse functional forms, successfully uncovering the underlying governing equations of complex physical systems directly from raw data.

Key Foundational Work

Learning University Mathematics (1995) — contributed 1 concept elements to this direction.
History & citationVersion 2 · 2026-10-04

Current · Permanent link

  1. Version 2 (latest) · 2026-10-04 · 63 papers
  2. Version 1 · 2026-10-04 · 112 papers
Cite this direction

Latest version (a living page):

@misc{lacuna_tree_structured_decoding_de04f89c,
  title = {tree-structured decoding},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/tree-structured-decoding/rdr_de04f89ce3f242afb0146797278c6d4a},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-26},
}

This exact version (version 2, frozen text):

@misc{lacuna_tree_structured_decoding_de04f89c_v2,
  title = {tree-structured decoding},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/tree-structured-decoding/rdr_de04f89ce3f242afb0146797278c6d4a/v/2},
  note = {Version 2, frozen 2026-10-04. Accessed 2026-11-26},
}
About

These directions overlap with this one through shared papers.

See something wrong? Report a mistake