TL;DR
This paper introduces a novel approach to solving math word problems by combining the natural language understanding of Large Language Models (LLMs) with the rigorous logic of symbolic solvers like SymPy. By prompting LLMs to "declaratively" formalize problems into variables and equations rather than writing procedural code, the researchers achieved a 20% absolute accuracy boost over state-of-the-art methods on a new dataset of challenging algebra problems.
What Problem Does This Paper Address?
While LLMs have shown impressive reasoning capabilities, they consistently stumble on two fronts when it comes to math: performing precise arithmetic and handling "declarative" reasoning.
Previous state-of-the-art methods like Program-Aided Language models (PAL) try to fix this by having the LLM write a Python script to solve the problem. However, PAL is inherently procedural—it works best when the problem can be solved by a sequence of direct calculations (e.g., "Add 5, then multiply by 2").
Many real-world algebra problems are declarative: they describe relationships between variables without providing a clear step-by-step calculation path. For example, if a problem states "Mario has 3 more years of experience than Luigi, and together they have 10," a procedural model might struggle to find the starting point, whereas a declarative approach simply states the constraints ($m = l + 3$ and $m + l = 10$) and lets a solver do the rest.
Methods
The authors propose a two-step framework:
- Declarative and Incremental Formalization: Using few-shot prompting, the LLM (specifically
code-davinci-002) is trained to translate a word problem into a series of natural language sentences interleaved with formal tags. These tags identify variables[[var x]]and equations[[eq x + y = 10]]. - Symbolic Solving: Instead of letting the LLM guess the answer, the extracted equations are passed to SymPy, a Python library for symbolic mathematics, which algebraically solves the system of equations.
Crucially, the authors found that incremental formalization—mapping each sentence of the problem to a corresponding variable or equation—is far more effective than trying to generate a single complex equation for the entire problem at once.
Datasets
The researchers evaluated their approach on two benchmarks:
- GSM8K: A standard dataset of 1,319 grade-school math word problems.
- ALGEBRA: A new, more difficult dataset curated by the authors. It consists of 222 problems pulled from open-access Algebra textbooks, focusing on topics up to systems of equations. Unlike GSM8K, these problems often lack a straightforward procedural solution path.
Key Insights and Ideas
- Declarative > Procedural for Algebra: The core "aha" moment is that for complex math, describing what the relationships are is easier for an LLM than describing how to calculate the result. Figure 4 illustrates this perfectly: PAL and Chain-of-Thought (CoT) both fail on a problem where the calculation path is non-obvious, while the declarative approach succeeds.
- The "Solver Gap": The authors tested a variant where the LLM was asked to solve its own generated equations. Accuracy plummeted from 69.4% to 22.4% on GSM8K. This highlights that LLMs are surprisingly good at formalizing logic but terrible at executing it.
- Prompting Principles Matter: The authors defined five specific principles for the LLM to follow (e.g., "Each quantity is only named by one variable"). Prepending these principles to the prompt significantly improved performance.
Key Results
The declarative approach proved highly effective, especially as problem difficulty increased:
| Method | GSM8K Accuracy | ALGEBRA Accuracy |
|---|---|---|
| CoT (8-shot) | 62.5% | 45.3% |
| PAL (8-shot) | 70.2% | 51.7% |
| DECLARATIVE + SymPy (Ours) | 69.4% | 76.3% |
On the standard GSM8K benchmark, the method performed comparably to PAL. However, on the more challenging ALGEBRA dataset, it outperformed PAL by an absolute 20%, demonstrating its superior ability to handle complex, non-procedural reasoning.
Limitations and Future Work
The current study has a few notable boundaries:
- Scope: The ALGEBRA dataset currently excludes geometry, graphing, and inequalities, which would require more specialized symbolic solvers or different formalization strategies.
- Formalization Errors: The system still fails if the LLM misinterprets the natural language and generates an incorrect equation.
- Educational Application: While the paper mentions applications in education, the current output format is designed for a solver. Future work could focus on translating the symbolic solver's steps back into human-readable pedagogical explanations.
The code and datasets are available at https://github.com/joyheyueya/declarative-math-word-problem.
Summary updated