Learning to compute Gröbner bases

Hiroshi Kera, Yuki Ishihara, Yuta Kambe, Tristan Vaccon, Kazuhiro Yokoyama

Introduction

Solving polynomial systems is a foundational task in computational algebra, with applications spanning cryptography, robotics, and systems biology. The standard tool for this task is the Gröbner basis, which acts as a non-linear equivalent to Gaussian elimination. However, computing a Gröbner basis is notoriously difficult, possessing a worst-case time complexity that is doubly exponential relative to the number of variables.

This paper presents the first successful attempt to train Transformer models to compute Gröbner bases. By introducing a novel "backward" data generation method and a hybrid embedding strategy for continuous coefficients, the authors demonstrate that neural networks can effectively learn to navigate these complex algebraic structures.

The Challenges of Neural Algebra

To train a Transformer to learn the patterns of Gröbner basis computation, the authors had to overcome two significant hurdles:

  1. The Data Bottleneck: Deep learning models require millions of training examples. Because computing a single Gröbner basis using traditional algorithms (like F4 or F5) is computationally expensive, generating a sufficiently large dataset using a standard "forward" approach (generating a problem, then solving it) is practically impossible.
  2. The Coefficient Problem: Polynomials often feature coefficients from infinite fields, such as rational ($\mathbb{Q}$) or real ($\mathbb{R}$) numbers. Standard NLP tokenization, which treats each number as a discrete word, cannot scale to an infinite vocabulary and fails to capture the mathematical proximity of continuous values.

Methodology: Inverting the Problem

To make "Neural Gröbner" a reality, the researchers introduced two primary innovations:

The Backward Gröbner Problem

Instead of generating a random polynomial system and attempting to solve it, the authors started with the solution. They generated a random Gröbner basis in a specific "shape position" and applied random, invertible algebraic transformations to scramble it into a non-Gröbner system. This "backward" approach bypasses the NP-hard bottleneck of data creation, allowing the generation of millions of (Problem, Solution) pairs in mere seconds.

Hybrid Input Embedding

To handle continuous coefficients without exploding the model's vocabulary size, the authors utilized a small feed-forward neural network to embed continuous values. This introduces a "continuity bias," helping the model understand that a coefficient like $1.01$ is mathematically close to $1.00$, rather than treating them as entirely unrelated categorical symbols.

The underlying model utilizes a standard Transformer architecture (comprising 6 encoder and decoder layers) trained to map a sequence of polynomial tokens directly to their corresponding Gröbner basis.

Key Results: Overcoming the Data Bottleneck

The most significant breakthrough of this work is the efficiency of the data generation process.

Comparison of data generation times between forward (F.) and backward (B.) methods across varying numbers of variables ($n$).

As shown in the table above, the backward generation method (B. ours) is remarkably scalable. While traditional mathematical software using forward methods (F. STD, F. SLIMGB) experiences exponential time growth as the number of variables ($n$) increases to 5, the backward method remains incredibly fast, achieving a speedup of 2 to 3 orders of magnitude.

Other notable findings include:

  • The Learnability Gap: Surprisingly, the model performed better on infinite fields ($\mathbb{Q}, \mathbb{R}$) than on finite discrete fields ($\mathbb{F}_p$). The continuity of real numbers provided a stronger, more structured signal for the Transformer to learn the underlying algebraic rules.
  • High Accuracy and Speed: On rational numbers with 2 variables, the model achieved 93.7% accuracy. Furthermore, the model proved exceptionally good at predicting the support (the specific terms/monomials that appear in the answer) even when slightly missing exact numerical coefficients. Once trained, the Transformer produces candidate Gröbner bases in milliseconds, bypassing the timeout issues occasionally seen in traditional algorithms.

Limitations and Future Work

While groundbreaking, the current approach has limitations. The study is restricted to "0-dimensional radical ideals" (systems with a finite number of solutions), and extending this to higher-dimensional systems remains an open challenge. Additionally, the model struggled with out-of-distribution generalization on standard benchmarks like Katsura-$n$, indicating a need for more diverse backward generation strategies.

Finally, due to the quadratic cost of self-attention relative to sequence length, very dense or large polynomial systems are currently too long for the model to process efficiently. Future iterations may need to incorporate linear-attention mechanisms to scale to larger, more complex algebraic problems.

Summary updated

BibTeX
@inproceedings{kera2024learning,
  author = {Hiroshi Kera and Yuki Ishihara and Yuta Kambe and Tristan Vaccon and Kazuhiro Yokoyama},
  title = {{Learning to compute Gröbner bases}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=ZRz7XlxBzQ},
}
Figure