Mode of #cas

member

Proves that a polynomial lies in the ideal of given polynomials, and gives it as a combination of them.

#cas [member x, y, …] f [g₁, …, gₘ]
proves that the polynomial f lies in the ideal generated by g₁, …, gₘ in Mathlib’s MvPolynomial, and gives f as a combination of them.

With ideal membership, the proof is something you can write down. If f=c1g1+…+cmgm, then f vanishes wherever the gi do, and the cofactors ci are the proof. member looks for them. It prints f written as such a combination, as with Mathematica’s PolynomialReduce, and the theorem underneath is f ∈ Ideal.span {g₁, …, gₘ}.

We find the cofactors by dividing f by the lexicographic Gröbner basis of the generators (groebner) and following the derivation of that basis back to the generators. Then ring checks the identity.

Details and Options

  • The theorem is f ∈ Ideal.span {g₁, …, gₘ} in MvPolynomial (Fin n) ℚ, with the i-th listed variable read as X i, proved by explicit cofactors that ring checks.
  • f and the generators are polynomials with rational coefficients in the listed variables.
  • The cofactors are one choice among many: replacing c1 by c1+hg2 and c2 by c2−hg1 gives the same sum.
  • When the cofactors have more than 2000 terms, the proof goes through the basis, and the output says only that they have more than 2000 terms.
  • A nonzero remainder is a refusal and not a theorem. The basis is not proved to be a Gröbner basis on this route, so the refusal proves nothing about non-membership.
  • There are no options.
  • The tactic cas proves f ∈ Ideal.span {g₁, …, gₘ} in any commutative ring, with the same cofactors. A certificate with denominators needs a ℚ-algebra, so in ℤ the cofactors must have integer coefficients.
  • With CASOracle.Ideal imported, cas [oracle := sympy], cas [oracle := sage] and cas [oracle := singular] ask an external system for the cofactors, and Lean checks the identity. See oracle.

Examples (12)#

Basic Examples (2)

The polynomial x2−1 lies in the ideal of xy−1 and x−y:

In[1]:=
#cas [member x, y] (x^2 - 1) [x*y - 1, x - y]
Out[1]=

a combination of the generators (checked)

x2−1=(xy−1)+x(x−y)
x^2 - 1 = (x*y - 1) + x*(x - y)
Domain
ℚ[x, y] as MvPolynomial (Fin 2) ℚ, with x = X 0, y = X 1
Input (polynomial and ideal)
x^2 - 1 and ⟨x*y - 1, x - y⟩

Checked by Lean’s kernel: Membership in the ideal of the generators

X 0 ^ 2 - 1 ∈ Ideal.span {X 0 * X 1 - 1, X 0 - X 1}
The certificate: 1 checked step
  1. Membership in the ideal of the generators

    X 0 ^ 2 - 1 ∈ Ideal.span {X 0 * X 1 - 1, X 0 - X 1}

    Checked by Lean’s kernel


A generator that is not needed does not appear in the combination:

In[2]:=
#cas [member x, y, z] (x^3 - y^3) [x - y, z]
Out[2]=

a combination of the generators (checked)

x3−y3=(x2+xy+y2)(x−y)
x^3 - y^3 = (x^2 + x*y + y^2)*(x - y)
Domain
ℚ[x, y, z] as MvPolynomial (Fin 3) ℚ, with x = X 0, y = X 1, z = X 2
Input (polynomial and ideal)
x^3 - y^3 and ⟨x - y, z⟩

Checked by Lean’s kernel: Membership in the ideal of the generators

X 0 ^ 3 - X 1 ^ 3 ∈ Ideal.span {X 0 - X 1, X 2}
The certificate: 1 checked step
  1. Membership in the ideal of the generators

    X 0 ^ 3 - X 1 ^ 3 ∈ Ideal.span {X 0 - X 1, X 2}

    Checked by Lean’s kernel

Scope (2)

The twisted cubic (t,t2,t3) is the common zero set of y−x2 and z−x3. The polynomial xz−y2 vanishes on it, and it lies in their ideal:

In[3]:=
#cas [member x, y, z] (x*z - y^2) [y - x^2, z - x^3]
Out[3]=

a combination of the generators (checked)

xz−y2=(−x2−y)(y−x2)+x(z−x3)
x*z - y^2 = (-x^2 - y)*(y - x^2) + x*(z - x^3)
Domain
ℚ[x, y, z] as MvPolynomial (Fin 3) ℚ, with x = X 0, y = X 1, z = X 2
Input (polynomial and ideal)
x*z - y^2 and ⟨y - x^2, z - x^3⟩

Checked by Lean’s kernel: Membership in the ideal of the generators

X 0 * X 2 - X 1 ^ 2 ∈ Ideal.span {X 1 - X 0 ^ 2, X 2 - X 0 ^ 3}
The certificate: 1 checked step
  1. Membership in the ideal of the generators

    X 0 * X 2 - X 1 ^ 2 ∈ Ideal.span {X 1 - X 0 ^ 2, X 2 - X 0 ^ 3}

    Checked by Lean’s kernel


With one variable and one generator, membership is divisibility: the remainder of polynomialRemainder is 0, and the cofactor is the quotient:

In[4]:=
#cas [member x] (x^3 - 1) [x - 1]
Out[4]=

a combination of the generators (checked)

x3−1=(x2+x+1)(x−1)
x^3 - 1 = (x^2 + x + 1)*(x - 1)
Domain
ℚ[x] as MvPolynomial (Fin 1) ℚ, with x = X 0
Input (polynomial and ideal)
x^3 - 1 and ⟨x - 1⟩

Checked by Lean’s kernel: Membership in the ideal of the generators

X 0 ^ 3 - 1 ∈ Ideal.span {X 0 - 1}
The certificate: 1 checked step
  1. Membership in the ideal of the generators

    X 0 ^ 3 - 1 ∈ Ideal.span {X 0 - 1}

    Checked by Lean’s kernel

Applications (4)

The first example as a theorem about Mathlib’s Ideal.span. Only the three standard axioms are used:

In[5]:=
open MvPolynomial in
theorem sq_sub_one_mem_span :
    (X 0 ^ 2 - 1 : MvPolynomial (Fin 2) ℚ) ∈ Ideal.span {X 0 * X 1 - 1, X 0 - X 1} := by
  cas

#print axioms sq_sub_one_mem_span
Out[5]=

sq_sub_one_mem_span depends on the axioms propext, Classical.choice, Quot.sound.


The tactic cas proves the same membership in the real numbers:

In[6]:=
theorem sq_sub_one_mem_span_real (a b : ℝ) : a ^ 2 - 1 ∈ Ideal.span {a * b - 1, a - b} := by
  cas
Out[6]=

Lean accepts the proof.


The cofactors 1 and a have integer coefficients, so the membership holds in ℤ as well, and this proof does not use Classical.choice:

In[7]:=
theorem sq_sub_one_mem_span_int (a b : ℤ) : a ^ 2 - 1 ∈ Ideal.span {a * b - 1, a - b} := by
  cas

#print axioms sq_sub_one_mem_span_int
Out[7]=

sq_sub_one_mem_span_int depends on the axioms propext, Quot.sound.


The same cofactors prove that x2=1 follows from xy=1 and x=y, with Mathlib’s linear_combination:

In[8]:=
example (x y : ℝ) (h1 : x * y = 1) (h2 : x = y) : x ^ 2 = 1 := by
  linear_combination h1 + x * h2
Out[8]=

Lean accepts the proof.

Properties and Relations (1)

The cofactors come from the division by the lexicographic Gröbner basis of the generators, here x−y and y2−1 (groebner):

In[9]:=
#cas [groebner x, y] [x*y - 1, x - y]
Out[9]=

Gröbner basis of the same ideal (checked)

x−y,y2−1
x - y, y^2 - 1
Domain
ℚ[x, y] as MvPolynomial (Fin 2) ℚ, with x = X 0, y = X 1
Input (polynomials)
x*y - 1, x - y

Checked by Lean’s kernel: Ideal of the inputs

Ideal.span {X 0 * X 1 - 1, X 0 - X 1} = Ideal.span {X 0 - X 1, X 1 ^ 2 - 1}
The certificate: 2 checked steps
  1. Ideal of the inputs

    Ideal.span {X 0 * X 1 - 1, X 0 - X 1} = Ideal.span {X 0 - X 1, X 1 ^ 2 - 1}

    Checked by Lean’s kernel

  2. Gröbner property of the basis

    ∀ p ∈ Ideal.span {X 0 - X 1, X 1 ^ 2 - 1},
      p ≠ 0 → ∃ g ∈ {X 0 - X 1, X 1 ^ 2 - 1}, MonomialOrder.lex.leadingTerm g ∣ MonomialOrder.lex.leadingTerm p

    Checked by Lean’s kernel

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, 2 in the basis

Possible Issues (2)

A polynomial with a nonzero remainder is refused. The refusal proves nothing about non-membership, although here x is in fact outside the ideal:

In[10]:=
#cas [member x, y] x [x^2, y]
Out[10]=

Error

member: x is not shown to be in the ideal: its remainder modulo the computed lexicographic basis is x. The basis is not proved to be a Gröbner basis, so this proves nothing about non-membership

In ℤ, a certificate with denominators is refused. Over ℚ, a=12(2a), but for a=2 the membership is false in ℤ:

In[11]:=
example (a : ℤ) : a ∈ Ideal.span {2 * a, a ^ 2} := by
  cas
Out[11]=

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:
  no `#cas` command states a goal of this shape
Box enclosure route:
  cas box route: the goal has the head symbol `Membership.mem`; 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:
  the certificate divides by 2, and ℤ is not a ℚ-algebra
Grind fallback:
  `grind` failed (`set_option trace.cas.fallback true` shows its diagnostics)

Neat Examples (1)

The factor x+y+z of x3+y3+z3−3xyz, with its cofactor:

In[12]:=
#cas [member x, y, z] (x^3 + y^3 + z^3 - 3*x*y*z) [x + y + z]
Out[12]=

a combination of the generators (checked)

x3−3xyz+y3+z3=(x2−xy−xz+y2−yz+z2)(x+y+z)
x^3 - 3*x*y*z + y^3 + z^3 = (x^2 - x*y - x*z + y^2 - y*z + z^2)*(x + y + z)
Domain
ℚ[x, y, z] as MvPolynomial (Fin 3) ℚ, with x = X 0, y = X 1, z = X 2
Input (polynomial and ideal)
x^3 + y^3 + z^3 - 3*x*y*z and ⟨x + y + z⟩

Checked by Lean’s kernel: Membership in the ideal of the generators

X 0 ^ 3 + X 1 ^ 3 + X 2 ^ 3 - 3 * X 0 * X 1 * X 2 ∈ Ideal.span {X 0 + X 1 + X 2}
The certificate: 1 checked step
  1. Membership in the ideal of the generators

    X 0 ^ 3 + X 1 ^ 3 + X 2 ^ 3 - 3 * X 0 * X 1 * X 2 ∈ Ideal.span {X 0 + X 1 + X 2}

    Checked by Lean’s kernel

See Also

groebner · cas · polynomialRemainder · oracle