Solver API¶
Polynomial system solving via Gröbner bases. The groebner Cargo feature is included in all PyPI wheels by default since 2.3.1 — no special build flag needed.
- alkahest.solve(equations: list[Expr], variables: list[Expr]) list[dict] or GroebnerBasis¶
Solve a system of polynomial equations symbolically.
Uses Lex Gröbner basis computation followed by triangular back-substitution. Quadratic factors are solved exactly with symbolic square roots.
- Parameters:
equations – List of polynomial expressions (each equal to zero).
variables – Variables to solve for.
- Returns:
list[dict[Expr, Expr]]— one dict per solution, mapping variable → value (symbolic, e.g.sqrt(2)/2).[](empty list) — if the system is inconsistent.GroebnerBasis— for parametric (infinite) solution sets.
Example:
pool = ExprPool() x = pool.symbol("x") y = pool.symbol("y") # Linear system sols = solve([x + y - pool.integer(1), x - y], [x, y]) # → [{x: 1/2, y: 1/2}] # Circle ∩ line (irrational) sols = solve([x**2 + y**2 - pool.integer(1), y - x], [x, y]) # → [{x: sqrt(2)/2, y: sqrt(2)/2}, # {x: -sqrt(2)/2, y: -sqrt(2)/2}]
Note
Solutions are symbolic by default. Evaluate numerically with
eval_expr()when needed:from alkahest import eval_expr for sol in sols: for var, val in sol.items(): print(f"{var} ≈ {eval_expr(val, {}):.6f}")
Pass
numeric=Trueto return float values directly instead of symbolicExprsolutions.
GroebnerBasis¶
- class alkahest.GroebnerBasis¶
A Gröbner basis for a polynomial ideal.
- classmethod compute(polys: list[Expr], vars: list[Expr], order: str = 'GRevLex') GroebnerBasis¶
Compute a Gröbner basis using the F4 algorithm.
- Parameters:
order – Monomial order —
"Lex","GrLex", or"GRevLex". Use"Lex"for elimination;"GRevLex"is generally fastest.
Computes the basis using the F4 algorithm with product-criterion pruning.
- eliminate(vars: list[Expr]) GroebnerBasis¶
Compute the elimination ideal by removing generators that involve the specified variables.
Useful for implicitization of parametric curves and surfaces.
- class alkahest.GbPoly¶
A polynomial element of a Gröbner basis computation, with rational coefficients represented as FLINT rationals.