Suggesting Variable Order for Cylindrical Algebraic Decomposition via Reinforcement Learning

Fuqi Jia, Yuhang Dong, Minghao Liu, Pei Huang, Feifei Ma, Jian ZhangNeurIPS 2023

This paper, presented at NeurIPS 2023, tackles a classic nightmare in symbolic computation: the double-exponential complexity of Cylindrical Algebraic Decomposition (CAD). By framing variable ordering as a reinforcement learning problem, the authors demonstrate that a model trained on simple 3-variable problems can effectively navigate much more complex mathematical terrain.

TL;DR

Researchers have developed GRL-SVO, a Reinforcement Learning approach using Graph Neural Networks to optimize variable ordering in Cylindrical Algebraic Decomposition (CAD). Their method outperforms existing learning-based heuristics and generalizes remarkably well, successfully handling 9-variable problems even when trained only on 3-variable datasets.

What Problem Does This Paper Address?

Cylindrical Algebraic Decomposition (CAD) is a fundamental algorithm used to solve problems involving polynomial constraints—think robot motion planning, geometric theorem proving, and formal verification. However, CAD has a massive Achilles' heel: its worst-case complexity is double exponential relative to the number of variables.

The efficiency of CAD is hyper-sensitive to the variable order (the sequence in which variables are "projected" or eliminated). Choosing a "bad" order can result in millions of algebraic "cells" and a system crash, while a "good" order might yield a result in milliseconds with only a few dozen cells.

Visualizing how different variable orderings affect the complexity of Cylindrical Algebraic Decomposition.

Historically, humans used "expert heuristics" (rules of thumb based on degrees and occurrences). Recent machine learning attempts used supervised learning, but these struggled because the number of possible orders grows factorially ($n!$), making it impossible to treat variable ordering as a simple classification task for high-dimensional problems.

Methods

The authors propose GRL-SVO (Graph-based Reinforcement Learning for Suggesting Variable Order), which treats the selection of variables as a sequential decision process.

  1. Graph Representation: They represent a set of polynomials as an undirected graph where variables are nodes. An edge exists between two nodes if those variables appear together in the same polynomial.
  2. The Architecture: They use a Graph Neural Network (GNN) to encode the structural features of the polynomials into embeddings. These embeddings are fed into an Advantage Actor-Critic (A2C) reinforcement learning framework.
  3. Two Variants:
    • GRL-SVO(UP): This version interacts directly with the symbolic computation tool. After picking a variable, it performs the actual mathematical "projection" to see the new state. It is highly accurate but computationally expensive.
  4. GRL-SVO(NUP): This "Fast" version doesn't perform the math. Instead, it uses a "delete and update" rule on the graph to simulate the projection step. This allows it to suggest a total variable order almost instantly.
Architecture of the GRL-SVO models: GRL-SVO(UP) with symbolic projection and GRL-SVO(NUP) with simulated graph updates.
  1. The Reward: The RL agent is rewarded based on the negative number of cells produced (fewer cells = higher reward).

Datasets

  • Random Dataset: 20,000 instances of 3-variable polynomials generated using Maple's randpoly function. This served as the primary training ground.
  • Generalization Sets: Testing sets ranging from 4 to 9 variables to test if the model could scale.
  • SMT-LIB: A real-world dataset of benchmarks from the Satisfiability Modulo Theories library, providing a "wild" environment to test the model's practical utility.

Key Insights and Ideas

  • Generalization is the "Killer App": The most striking finding is that a model trained only on 3-variable random polynomials performs excellently on 9-variable real-world problems. This suggests the GNN is capturing fundamental structural properties of algebraic projection that are invariant to the number of variables.
  • Simulated Math Works: The NUP (Not Utilizing Project) variant proves that you don't need to do the heavy algebraic lifting during the decision phase. By simply updating the graph structure, the model maintains enough context to make high-quality decisions.
  • Breaking the Factorial Barrier: Unlike supervised learning, which requires labels for every possible permutation, the RL approach learns a policy to pick the next best variable, naturally handling the combinatorial explosion of variable orders.

Key Results

  • Performance: GRL-SVO(UP) achieved the best performance across almost all categories, often producing significantly fewer cells than expert-based heuristics like sotd (sum of total degree) or brown.
  • Robustness: In 5-variable tests, traditional heuristics like sotd began to time out frequently due to the complexity of the projection phase. GRL-SVO maintained high success rates.
  • Real-World Utility: On the SMT-LIB dataset, GRL-SVO was competitive with the best expert-designed algorithms, proving it isn't just a "lab curiosity" but a viable tool for symbolic solvers.
  • Efficiency: GRL-SVO(NUP) provided orders in a fraction of a second, making it suitable for integration into automated reasoning tools like Z3 or CVC5.

Limitations and Future Work

  • Information Loss: The current graph representation ignores specific coefficient values (e.g., it treats $x^2 + 2y$ the same as $x^2 + 100y$). The authors acknowledge that coefficients do matter and plan to incorporate them in future embeddings.
  • Infrastructure Overhead: The current implementation relies on Python and PyTorch, which introduces some latency compared to the C++ or Maple environments where CAD usually lives.
  • Future Directions: The authors aim to build a dedicated RL-based package for Maple and integrate their variable ordering logic into non-linear arithmetic solvers for broader use in the formal verification community.

Summary updated

BibTeX
@inproceedings{jia2023suggesting,
  author = {Fuqi Jia and Yuhang Dong and Minghao Liu and Pei Huang and Feifei Ma and Jian Zhang},
  title = {{Suggesting Variable Order for Cylindrical Algebraic Decomposition via Reinforcement Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=vNsdFwjPtL},
}
Figure