Internalizing Geometric Law: Learning from Solver Residuals for Precision-Critical Generation

Rafael Cabral, Pang Zixi, Ziyi Shou, Shen XinarXiv 2026

Here is a blog-style summary of the research paper.

TL;DR

While Large Language Models (LLMs) excel at generating text and code, they frequently suffer from "precision hallucinations" when tasked with strict geometric and engineering constraints. This paper introduces PyGeoX, a framework that trains LLMs to directly generate precise geometric coordinates by learning from fine-grained solver residuals. By replacing standard global-norm rewards with a novel Saturating Additive Rewards (SAR) scheme, the authors prevent a single poorly satisfied constraint from destroying the model's learning signal, enabling an 8B model to rival massive frontier systems.

What Problem Does This Paper Address?

In fields like computer-aided design (CAD), technical diagramming, and kinematics, geometric constraints are absolute laws. A generated diagram might look visually plausible to a human, but if a linkage is mathematically impossible, it represents a critical functional failure.

Currently, researchers bypass this by using LLMs as mere translators that convert natural language into syntax for external symbolic or numerical solvers. However, this "translation-only" approach prevents the LLM from ever internalizing spatial logic or geometric laws.

When researchers try to use Reinforcement Learning with Verifiable Rewards (RLVR) to teach LLMs geometry, they hit a wall called Outlier Gradient Masking. Standard reward functions aggregate errors globally (e.g., using Mean Squared Error). If an LLM satisfies 15 out of 16 complex constraints perfectly but misses the last one by a wide margin, a global-norm reward collapses to near-zero. This "all-or-nothing" feedback zeroes out the policy gradient, completely hiding the model's partial progress and stalling the learning process.

Methods

To make end-to-end Geometric Constraint Solving (GCS) learnable, the authors developed the PyGeoX framework:

  1. The PyGeoX Engine: A programmable geometric environment that translates declarative text into a system of symbolic constraints, which are then compiled into a differentiable loss function using a SymPy backend and Numba's JIT compiler for speed.
  2. Saturating Additive Rewards (SAR): Instead of aggregating all constraint violations ($r_i$) into a single global norm, SAR scores each constraint independently using a bounded kernel (like a Boltzmann or Cauchy kernel) and sums them up: $$R_{\text{SAR}}(\mathbf{r}) = \sum_{i=1}^{C} \phi(r_i)$$ Because each constraint's reward is bounded between 0 and 1, a single massive outlier cannot drag the entire reward down to zero. This preserves the learning signal for the constraints the model did get right.

  3. Composite Reward Design: To push the model toward exact solutions and prevent cheating, the final reward combines SAR (dense shaping) with a Sparse Bonus (activated only when all constraints are fully satisfied) and a Degeneracy Penalty (to punish trivial solutions, like collapsing all points onto a single coordinate).

Figure 1: Task overview. The agent thinks and emits Python code containing exact coordinates and radii.

Datasets

The authors introduced a complete data and evaluation ecosystem:

  • Synthetic Training Corpus: A procedural pipeline that generated and validated $\sim$100k geometric problems, stratified into Easy, Medium, and Hard tiers based on the number of objects and constraints.
  • PyGeoX-Bench: A held-out evaluation suite consisting of 300 stratified problems (100 per difficulty tier).
  • PyGeoX-Wild: An out-of-distribution (OOD) diagnostic set of 86 problems adapted from a real middle-school geometry benchmark, featuring human-authored prose and unseen constraint combinations.

Key Insights and Ideas

  • Loss Functions $\neq$ Reward Functions: In supervised learning, large outlier errors are helpful because the gradient is directly proportional to the residual. In RL, however, the reward acts as a scalar multiplier for the log-probability gradient. If the reward collapses due to one outlier, the entire gradient update is nullified.
  • Protecting Sub-solutions: SAR acts as a safeguard for partial progress. If a model figures out how to solve a complex sub-assembly of a diagram, SAR rewards it, even if the rest of the diagram is still a mess.
  • Emergent Ruler-and-Compass Reasoning: When trained with SAR, the model doesn't just learn to output random numbers or rely blindly on numerical optimization loops. Instead, roughly 90% of successful hard-tier solutions showed the LLM executing step-by-step constructive geometric derivations directly in Python code.
Figure 2: Reward signal analysis for Qwen3-8B on PyGeoX-Bench. (Left) The global-norm reward collapses to zero on partially correct base-model outputs, providing no learning signal and SAR preserves dense signal even when some constraints remain violated. (Right) SAR-trained models achieve higher reward with fewer tokens across all difficulty tiers (E-Easy, M-Medium, H-Hard) compared to the sparse baseline.

Key Results

The authors evaluated their approach by training a Qwen3-8B model from scratch using Group Relative Policy Optimization (GRPO):

  • Massive Accuracy Boost: On the Hard tier of PyGeoX-Bench, the SAR composite reward achieved a 0.41 solving rate, outperforming the standard MSE baseline (0.18) by 2.3$\times$.
  • Competitive with Giants: The fine-tuned 8B model outperformed DeepSeek-V3.2 (0.25) on hard problems and performed competitively with much larger proprietary frontier models.
  • Token Efficiency: Models trained with SAR were significantly more direct, requiring 22.8% fewer tokens per task compared to models trained on sparse rewards alone, as they spent less time generating lengthy numerical-search traces.

Limitations and Future Work

  • Base Model Dependency: The framework requires a base model with strong inherent math and code capabilities. Attempts to train smaller models (like Qwen3-1.7B) resulted in unstable training and near-zero performance.
  • Dimensionality Constraints: The current PyGeoX engine is restricted to 2D static geometry. Extending this method to real-world 3D CAD modeling and dynamic kinematic mechanism design will require expanding the library's symbolic primitives.

Summary updated

BibTeX
@misc{cabral2026internalizing,
  author = {Rafael Cabral and Pang Zixi and Ziyi Shou and Shen Xin},
  title = {{Internalizing Geometric Law: Learning from Solver Residuals for Precision-Critical Generation}},
  year = {2026},
  eprint = {2606.09278},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.09278},
}
Figure