Mode of #cas
groebner
Gives the reduced lexicographic Gröbner basis of a polynomial ideal, with theorems about Ideal.span in MvPolynomial.
#cas [groebner x, y, …] [f₁, …, fₘ]MvPolynomial.A Gröbner basis reorganizes a system of polynomial equations into a form that is easier to solve, and groebner computes one for the input ideal. The lexicographic basis eliminates variables. When the system has finitely many complex solutions, its last elements involve only the last variables, so you can read off the common zeros one variable at a time, much as you would back-substitute in a triangular linear system.
The report proves two theorems about Mathlib’s Ideal.span in MvPolynomial (Fin n) ℚ. The first says that the basis spans the same ideal as the input. The second says that it is a Gröbner basis for MonomialOrder.lex: the leading term of every nonzero element of the ideal is divisible by the leading term of a basis element. The first alone holds for the input as well, and the second is the property that the elimination above relies on.
Examples (16)#
Basic Examples (2)
The circle and the hyperbola . The last element of the basis is a polynomial in alone:
#cas [groebner x, y] [x^2 + y^2 - 5, x*y - 2]
Gröbner basis of the same ideal (checked)
2*x + y^3 - 5*y, y^4 - 5*y^2 + 4- Domain
ℚ[x, y] as MvPolynomial (Fin 2) ℚ, with x = X 0, y = X 1- Input (polynomials)
x^2 + y^2 - 5, x*y - 2
Checked by Lean’s kernel: Ideal of the inputs
Ideal.span {X 0 ^ 2 + X 1 ^ 2 - 5, X 0 * X 1 - 2} =
Ideal.span {2 * X 0 + X 1 ^ 3 - 5 * X 1, X 1 ^ 4 - 5 * X 1 ^ 2 + 4}The certificate: 2 checked steps
Ideal of the inputs
Ideal.span {X 0 ^ 2 + X 1 ^ 2 - 5, X 0 * X 1 - 2} = Ideal.span {2 * X 0 + X 1 ^ 3 - 5 * X 1, X 1 ^ 4 - 5 * X 1 ^ 2 + 4}Gröbner property of the basis
∀ p ∈ Ideal.span {2 * X 0 + X 1 ^ 3 - 5 * X 1, X 1 ^ 4 - 5 * X 1 ^ 2 + 4}, p ≠ 0 → ∃ g ∈ {2 * X 0 + X 1 ^ 3 - 5 * X 1, X 1 ^ 4 - 5 * X 1 ^ 2 + 4}, MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p
The computation
Gröbner basis
the reduced basis for the lexicographic order x > y, each element scaled to coprime integer coefficients with a positive leading coefficient; computed by SymLean's Buchberger algorithm, 4 polynomials in the derivation, 2 in the basis
The unit sphere, the paraboloid and the plane . The basis is triangular and ends with a polynomial in :
#cas [groebner x, y, z] [x^2 + y^2 + z^2 - 1, x^2 + z^2 - y, x - z]
Gröbner basis of the same ideal (checked)
x - z, y - 2*z^2, 4*z^4 + 2*z^2 - 1- Domain
ℚ[x, y, z] as MvPolynomial (Fin 3) ℚ, with x = X 0, y = X 1, z = X 2- Input (polynomials)
x^2 + y^2 + z^2 - 1, x^2 + z^2 - y, x - z
Checked by Lean’s kernel: Ideal of the inputs
Ideal.span {X 0 ^ 2 + X 1 ^ 2 + X 2 ^ 2 - 1, X 0 ^ 2 + X 2 ^ 2 - X 1, X 0 - X 2} =
Ideal.span {X 0 - X 2, X 1 - 2 * X 2 ^ 2, 4 * X 2 ^ 4 + 2 * X 2 ^ 2 - 1}The certificate: 2 checked steps
Ideal of the inputs
Ideal.span {X 0 ^ 2 + X 1 ^ 2 + X 2 ^ 2 - 1, X 0 ^ 2 + X 2 ^ 2 - X 1, X 0 - X 2} = Ideal.span {X 0 - X 2, X 1 - 2 * X 2 ^ 2, 4 * X 2 ^ 4 + 2 * X 2 ^ 2 - 1}Gröbner property of the basis
∀ p ∈ Ideal.span {X 0 - X 2, X 1 - 2 * X 2 ^ 2, 4 * X 2 ^ 4 + 2 * X 2 ^ 2 - 1}, p ≠ 0 → ∃ g ∈ {X 0 - X 2, X 1 - 2 * X 2 ^ 2, 4 * X 2 ^ 4 + 2 * X 2 ^ 2 - 1}, MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p
The computation
Gröbner basis
the reduced basis for the lexicographic order x > y > z, each element scaled to coprime integer coefficients with a positive leading coefficient; computed by SymLean's Buchberger algorithm, 6 polynomials in the derivation, 3 in the basis
Scope (3)
Rational coefficients are allowed, and each element of the basis is scaled to coprime integer coefficients. In the theorem the coefficient of the input is the constant polynomial C (1 / 2):
#cas [groebner x, y] [x/2 + y - 1, x^2 - y]
Gröbner basis of the same ideal (checked)
x + 2*y - 2, 4*y^2 - 9*y + 4- Domain
ℚ[x, y] as MvPolynomial (Fin 2) ℚ, with x = X 0, y = X 1- Input (polynomials)
x/2 + y - 1, x^2 - y
Checked by Lean’s kernel: Ideal of the inputs
Ideal.span {C (1 / 2) * X 0 + X 1 - 1, X 0 ^ 2 - X 1} =
Ideal.span {X 0 + 2 * X 1 - 2, 4 * X 1 ^ 2 - 9 * X 1 + 4}The certificate: 2 checked steps
Ideal of the inputs
Ideal.span {C (1 / 2) * X 0 + X 1 - 1, X 0 ^ 2 - X 1} = Ideal.span {X 0 + 2 * X 1 - 2, 4 * X 1 ^ 2 - 9 * X 1 + 4}Gröbner property of the basis
∀ p ∈ Ideal.span {X 0 + 2 * X 1 - 2, 4 * X 1 ^ 2 - 9 * X 1 + 4}, p ≠ 0 → ∃ g ∈ {X 0 + 2 * X 1 - 2, 4 * X 1 ^ 2 - 9 * X 1 + 4}, MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p
The computation
Gröbner basis
the reduced basis for the lexicographic order x > y, each element scaled to coprime integer coefficients with a positive leading coefficient; computed by SymLean's Buchberger algorithm, 4 polynomials in the derivation, 2 in the basis
The polynomials and have no common zero. The basis is , and the ideal is the whole ring:
#cas [groebner x, y] [x*y - 1, x]
Gröbner basis of the same ideal (checked)
1- Domain
ℚ[x, y] as MvPolynomial (Fin 2) ℚ, with x = X 0, y = X 1- Input (polynomials)
x*y - 1, x
Checked by Lean’s kernel: Ideal of the inputs
Ideal.span {X 0 * X 1 - 1, X 0} = Ideal.span {1}The certificate: 2 checked steps
Ideal of the inputs
Ideal.span {X 0 * X 1 - 1, X 0} = Ideal.span {1}Gröbner property of the basis
∀ p ∈ Ideal.span {1}, p ≠ 0 → ∃ g ∈ {1}, MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p
The computation
Gröbner basis
the reduced basis for the lexicographic order x > y, each element scaled to coprime integer coefficients with a positive leading coefficient; computed by SymLean's Buchberger algorithm, 3 polynomials in the derivation, 1 in the basis
The zero ideal has the empty basis, printed :
#cas [groebner x, y] [x - x]
Gröbner basis of the same ideal (checked)
0- Domain
ℚ[x, y] as MvPolynomial (Fin 2) ℚ, with x = X 0, y = X 1- Input (polynomials)
x - x
Checked by Lean’s kernel: Ideal of the inputs
Ideal.span {X 0 - X 0} = Ideal.span {0}The certificate: 2 checked steps
Ideal of the inputs
Ideal.span {X 0 - X 0} = Ideal.span {0}Gröbner property of the basis
∀ p ∈ Ideal.span {0}, p ≠ 0 → ∃ g ∈ {0}, MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p
The computation
Gröbner basis
the reduced basis for the lexicographic order x > y, each element scaled to coprime integer coefficients with a positive leading coefficient; computed by SymLean's Buchberger algorithm, 0 polynomials in the derivation, 0 in the basis
Options (1)
SageMath can propose the basis, with CASOracle.Ideal imported. Lean checks it in the same way and proves the same two theorems:
#cas [groebner x, y, oracle := sage] [x ^ 2 + y ^ 2 - 5, x * y - 2]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
Gröbner basis of the same ideal (checked)
2*x + y^3 - 5*y, y^4 - 5*y^2 + 4Applications (3)
The first example as a theorem about Mathlib’s Ideal.span. Only the three standard axioms are used:
open MvPolynomial in theorem span_circle_hyperbola : Ideal.span {(X 0 ^ 2 + X 1 ^ 2 - 5 : MvPolynomial (Fin 2) ℚ), X 0 * X 1 - 2} = Ideal.span {2 * X 0 + X 1 ^ 3 - 5 * X 1, X 1 ^ 4 - 5 * X 1 ^ 2 + 4} := by cas #print axioms span_circle_hyperbola
span_circle_hyperbola depends on the axioms propext, Classical.choice, Quot.sound.
The Gröbner property of its basis, which the tactic cas proves from Buchberger’s criterion:
open MvPolynomial in theorem groebner_circle_hyperbola : ∀ p ∈ Ideal.span ({2 * X 0 + X 1 ^ 3 - 5 * X 1, X 1 ^ 4 - 5 * X 1 ^ 2 + 4} : Set (MvPolynomial (Fin 2) ℚ)), p ≠ 0 → ∃ g ∈ ({2 * X 0 + X 1 ^ 3 - 5 * X 1, X 1 ^ 4 - 5 * X 1 ^ 2 + 4} : Set (MvPolynomial (Fin 2) ℚ)), MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p := by cas
Lean accepts the proof.
In the first example is a root of , and then . solve uses such a basis to prove the complete list of real solutions:
#cas [solve x, y] (x^2 + y^2 = 5 ∧ x * y = 2)
complete list of real solutions
{x = -1, y = -2}, {x = -2, y = -1}, {x = 2, y = 1}, {x = 1, y = 2}- Input (polynomial system)
(x^2 + y^2 = 5 ∧ x * y = 2)
Checked by Lean’s kernel: Complete list of real solutions
∀ (x y : ℝ), x ^ 2 + y ^ 2 = 5 ∧ x * y = 2 ↔ x = -1 ∧ y = -2 ∨ x = -2 ∧ y = -1 ∨ x = 2 ∧ y = 1 ∨ x = 1 ∧ y = 2
The certificate: 1 checked step
Complete list of real solutions
∀ (x y : ℝ), x ^ 2 + y ^ 2 = 5 ∧ x * y = 2 ↔ x = -1 ∧ y = -2 ∨ x = -2 ∧ y = -1 ∨ x = 2 ∧ y = 1 ∨ x = 1 ∧ y = 2
The computation
Gröbner basis
lexicographic basis in shape position with respect to y; eliminant of degree 4, 4 real roots, 4 polynomials in the derivation
Properties and Relations (2)
member writes an element of the ideal as a combination of the inputs. Here it is the last element of the first basis:
#cas [member x, y] (y^4 - 5*y^2 + 4) [x^2 + y^2 - 5, x*y - 2]
a combination of the generators (checked)
y^4 - 5*y^2 + 4 = y^2*(x^2 + y^2 - 5) + (-x*y - 2)*(x*y - 2)- Domain
ℚ[x, y] as MvPolynomial (Fin 2) ℚ, with x = X 0, y = X 1- Input (polynomial and ideal)
y^4 - 5*y^2 + 4 and ⟨x^2 + y^2 - 5, x*y - 2⟩
Checked by Lean’s kernel: Membership in the ideal of the generators
X 1 ^ 4 - 5 * X 1 ^ 2 + 4 ∈ Ideal.span {X 0 ^ 2 + X 1 ^ 2 - 5, X 0 * X 1 - 2}
The certificate: 1 checked step
Membership in the ideal of the generators
X 1 ^ 4 - 5 * X 1 ^ 2 + 4 ∈ Ideal.span {X 0 ^ 2 + X 1 ^ 2 - 5, X 0 * X 1 - 2}
The order of the variables is the order of elimination. With , the basis of the line and the parabola of Scope ends with a polynomial in :
#cas [groebner y, x] [x/2 + y - 1, x^2 - y]
Gröbner basis of the same ideal (checked)
2*y + x - 2, 2*x^2 + x - 2- Domain
ℚ[y, x] as MvPolynomial (Fin 2) ℚ, with y = X 0, x = X 1- Input (polynomials)
x/2 + y - 1, x^2 - y
Checked by Lean’s kernel: Ideal of the inputs
Ideal.span {C (1 / 2) * X 1 + X 0 - 1, X 1 ^ 2 - X 0} =
Ideal.span {2 * X 0 + X 1 - 2, 2 * X 1 ^ 2 + X 1 - 2}The certificate: 2 checked steps
Ideal of the inputs
Ideal.span {C (1 / 2) * X 1 + X 0 - 1, X 1 ^ 2 - X 0} = Ideal.span {2 * X 0 + X 1 - 2, 2 * X 1 ^ 2 + X 1 - 2}Gröbner property of the basis
∀ p ∈ Ideal.span {2 * X 0 + X 1 - 2, 2 * X 1 ^ 2 + X 1 - 2}, p ≠ 0 → ∃ g ∈ {2 * X 0 + X 1 - 2, 2 * X 1 ^ 2 + X 1 - 2}, MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p
The computation
Gröbner basis
the reduced basis for the lexicographic order y > x, each element scaled to coprime integer coefficients with a positive leading coefficient; computed by SymLean's Buchberger algorithm, 3 polynomials in the derivation, 2 in the basis
Possible Issues (4)
Every variable of the inputs is listed after the mode name:
#cas [groebner x, y] [x^2 + z, y]
Error
expression contains undeclared variables: z
The inputs are polynomials:
#cas [groebner x, y] [x^2 + sin y, y]
Error
groebner: x^2 + sin y is not a polynomial with rational coefficients
The tactic cas refuses the Gröbner property of a set that does not have it, and the rest of its message names a pair whose S-polynomial leaves a nonzero remainder. The parabolas and are such a set:
open MvPolynomial in example : ∀ p ∈ Ideal.span ({X 0 ^ 2 - X 1, X 1 ^ 2 - X 0} : Set (MvPolynomial (Fin 2) ℚ)), p ≠ 0 → ∃ g ∈ ({X 0 ^ 2 - X 1, X 1 ^ 2 - X 0} : Set (MvPolynomial (Fin 2) ℚ)), MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p := by cas
Error
cas expected a checked semantic proposition, reflected equality, arithmetic relation, an ordinary inequality on real variables bounded by rational literal hypotheses (a two-sided bound `a ≤ f x ∧ f x ≤ b`, a membership `f x ∈ Set.Icc a b`, or a universally quantified bound), or the statement of a `#cas` command (a limit, a polynomial root count, a polynomial sign condition)
The rest of the message
Command theorem route:
cas sign route expected a quantifier over ℝ
Box enclosure route:
cas box route: the goal has the head symbol `Exists`; the route proves `f x ≤ c`, `f x < c`, `c ≤ f x`, `c < f x` (also with `≥` and `>`), `|f x| ≤ c`, `|f x| < c`, `a ≤ f x ∧ f x ≤ b` (also with `<`), `f x ∈ Set.Icc a b` (also `Set.Ioo`, `Set.Ico`, `Set.Ioc`), `f x ≤ g x`, `f x < g x`, and conjunctions of these, with `c`, `a`, `b` closed and every real variable bounded by hypotheses `a ≤ x` and `x ≤ b`, `x ∈ Set.Icc a b`, or `|x| ≤ r` with rational literal endpoints
Registered route ideal:
cas: the basis is not a Gröbner basis for `MonomialOrder.lex`: the S-polynomial of
X 0 ^ 2 - X 1
and
X 1 ^ 2 - X 0
leaves the remainder
-X 1 ^ 4 + X 1
on division by the basis
Grind fallback:
`grind` failed (`set_option trace.cas.fallback true` shows its diagnostics)
norm_num fallback:
norm_num did not close the goalThe reduced basis of the same ideal has the property:
open MvPolynomial in theorem groebner_two_parabolas : ∀ p ∈ Ideal.span ({X 0 - X 1 ^ 2, X 1 ^ 4 - X 1} : Set (MvPolynomial (Fin 2) ℚ)), p ≠ 0 → ∃ g ∈ ({X 0 - X 1 ^ 2, X 1 ^ 4 - X 1} : Set (MvPolynomial (Fin 2) ℚ)), MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p := by cas
Lean accepts the proof.
The two sets in the statement are compared as written, so the same set listed in another order after ∃ g ∈ is refused. The reason is in the rest of the message, under “Registered route ideal”:
open MvPolynomial in example : ∀ p ∈ Ideal.span ({X 0, X 1} : Set (MvPolynomial (Fin 2) ℚ)), p ≠ 0 → ∃ g ∈ ({X 1, X 0} : Set (MvPolynomial (Fin 2) ℚ)), MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p := by cas
Error
cas expected a checked semantic proposition, reflected equality, arithmetic relation, an ordinary inequality on real variables bounded by rational literal hypotheses (a two-sided bound `a ≤ f x ∧ f x ≤ b`, a membership `f x ∈ Set.Icc a b`, or a universally quantified bound), or the statement of a `#cas` command (a limit, a polynomial root count, a polynomial sign condition)
The rest of the message
Command theorem route: cas sign route expected a quantifier over ℝ Box enclosure route: cas box route: the goal has the head symbol `Exists`; the route proves `f x ≤ c`, `f x < c`, `c ≤ f x`, `c < f x` (also with `≥` and `>`), `|f x| ≤ c`, `|f x| < c`, `a ≤ f x ∧ f x ≤ b` (also with `<`), `f x ∈ Set.Icc a b` (also `Set.Ioo`, `Set.Ico`, `Set.Ioc`), `f x ≤ g x`, `f x < g x`, and conjunctions of these, with `c`, `a`, `b` closed and every real variable bounded by hypotheses `a ≤ x` and `x ≤ b`, `x ∈ Set.Icc a b`, or `|x| ≤ r` with rational literal endpoints Registered route ideal: cas: on a goal `∀ p ∈ Ideal.span S, p ≠ 0 → ∃ …`, `cas` proves only the Gröbner property for `MonomialOrder.lex`, `∃ g ∈ S, MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p` with the same set `S`; other monomial orders and other conclusions are not supported Grind fallback: `grind` failed (`set_option trace.cas.fallback true` shows its diagnostics) norm_num fallback: norm_num did not close the goal
Neat Examples (1)
The elementary symmetric polynomials of , the last one shifted by . At a common zero, , and are the three roots of in some order, and the basis ends with :
#cas [groebner x, y, z] [x + y + z, x*y + y*z + z*x, x*y*z - 1]
Gröbner basis of the same ideal (checked)
x + y + z, y^2 + y*z + z^2, z^3 - 1- Domain
ℚ[x, y, z] as MvPolynomial (Fin 3) ℚ, with x = X 0, y = X 1, z = X 2- Input (polynomials)
x + y + z, x*y + y*z + z*x, x*y*z - 1
Checked by Lean’s kernel: Ideal of the inputs
Ideal.span {X 0 + X 1 + X 2, X 0 * X 1 + X 1 * X 2 + X 2 * X 0, X 0 * X 1 * X 2 - 1} =
Ideal.span {X 0 + X 1 + X 2, X 1 ^ 2 + X 1 * X 2 + X 2 ^ 2, X 2 ^ 3 - 1}The certificate: 2 checked steps
Ideal of the inputs
Ideal.span {X 0 + X 1 + X 2, X 0 * X 1 + X 1 * X 2 + X 2 * X 0, X 0 * X 1 * X 2 - 1} = Ideal.span {X 0 + X 1 + X 2, X 1 ^ 2 + X 1 * X 2 + X 2 ^ 2, X 2 ^ 3 - 1}Gröbner property of the basis
∀ p ∈ Ideal.span {X 0 + X 1 + X 2, X 1 ^ 2 + X 1 * X 2 + X 2 ^ 2, X 2 ^ 3 - 1}, p ≠ 0 → ∃ g ∈ {X 0 + X 1 + X 2, X 1 ^ 2 + X 1 * X 2 + X 2 ^ 2, X 2 ^ 3 - 1}, MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p
The computation
Gröbner basis
the reduced basis for the lexicographic order x > y > z, each element scaled to coprime integer coefficients with a positive leading coefficient; computed by SymLean's Buchberger algorithm, 5 polynomials in the derivation, 3 in the basis
See Also
member · solve · cas · oracle · polynomialRemainder
