[ ai ]llmathsha c0f450edocumented-only
back to workA proof assistantthat decides when to compute.
I paired a fine-tuned DeepSeek-Math 7B with FAISS retrieval over NaturalProofs and a SymPy tool registry, then let one autonomous ReAct loop decide when to reach for each. A documented ablation puts it at 77.6% on TheoremQA, up from a 41.2% prompted baseline.
- autonomous ReAct on TheoremQA, sample ablation
- 77.6%
autonomous ReAct on TheoremQA, sample ablation
- prompted baseline, no tools, same sample
- 41.2%
prompted baseline, no tools, same sample
- fewer tokens per correct answer, same sample
- ~36%
fewer tokens per correct answer, same sample
- ~4k LOC, one clean package
- 9
~4k LOC, one clean package
▮ on the benchmark numbers
01the problem
A model that talks fluently about math cannot be trusted to do it.
Ask a general LLM for a derivation and it hands you something that reads like a proof: confident prose, plausible algebra, the right vocabulary. Then a sign flips, a term drops, and the conclusion is wrong. Fluent proofs are not correct proofs, and a fine-tuned model alone has no grounding in known theorems and no way to check its own algebra.
A bigger model writing nicer proofs was not the question. The question: how much accuracy and token efficiency do you actually gain by handing the model a retrieval index of real theorems, verified symbolic tools, and the freedom to decide when to use them?
02the approach
Three sources of ground truth behind one model.
Each layer removes a way the model can be wrong, and the agent chooses which one it needs. Retrieval grounds claims in real theorems. Symbolic tools ground the algebra in something that cannot hand-wave. The fine-tuned model supplies the reasoning that ties them together.
Retrieval
retrieval/faiss_retriever.pySymbolic tools
tools/registry.pyFine-tuned model
inference/model_loader.py · config.py
03the architecture
The loop is the whole idea.
The agent runs a bounded think, tool, observe, answer cycle, parsed off a strict XML protocol. I built it to degrade gracefully instead of crashing when the model breaks the format. The manual pipeline follows a fixed path. The autonomous agent emits the same tool calls itself.
manual pipeline · the system routes
- input
Question, e.g. "derivative of x²·sin(x)"
- retrievalretrieval/
TheoremKB → FAISS IndexFlatIP, top-k cosine
- toolstools/
SymPy registry: simplify · solve · diff · integrate
- promptsprompts/
Prompt builder: retrieval + tool outputs → context
- modelinference/
DeepSeek-Math 7B + LoRA · generate() · 4-bit capable
- output
Proof-style answer
autonomous ReAct · the model decides
for iteration in 1..max_iterations
<think>Free-form reasoning. The model plans its next move.
<tool>Exactly one call as tool_name: args. Generation stops on </tool>.
<observe>System-injected tool output. Appended to context, never generated.
<answer>Ends the loop. Generation stops on </answer>; tokens accrue per step.
react trace · diff: x²·sin(x) · abridged from docs/react-protocol.md
<think>Retrieve the relevant theorem.</think><tool>retrieve: derivative of product</tool><observe>[T1] Product Rule: d/dx(f·g) = f'·g + f·g' ...</observe><think>Apply the product rule and compute the derivative.</think><tool>diff: x**2*sin(x)</tool><observe>2*x*sin(x) + x**2*cos(x)</observe><answer>The derivative follows from the product rule and the computation above.</answer>
04tradeoffs
What I gave up, and the one that needs stating.
won · simplicity
A strict contract over model freedom
won · zero deps
Hand-built SVG charts, no matplotlib
won · safety
Retrieval that refuses to mismatch
▮ honest loss
The headline numbers are sample data
05the benchmark
The ablation ladder.
Each rung adds one grounding layer against the prompted baseline, and the deltas carry the argument. The figures are from benchmarks/results.sample.json.
TheoremQA accuracy · higher is better
n=800 · documented sample
- model only · no tools41.2%anchor
- retrieval only58.1%+16.9 pp
- retrieval + SymPy69.8%+11.7 pp
- full ReAct loop77.6%+7.8 pp
tool-call precision
retrieval recall@k
avg iterations
fewer tokens/correct
These are documented sample figures, not a recorded GPU run. Raw data.
python · DeepSeek-Math 7B · FAISS · SymPy · LoRA · Gradio