Mode of #cas
solve
Every real solution of a polynomial equation or system, with a theorem that the list is complete.
#cas [solve x] (lhs = rhs)#cas [solve x, y, …] (e₁ ∧ … ∧ eₘ)solve finds all real solutions of a supported equation and proves that the list is complete. Checking that a value solves the equation is easy, since you can plug it back in. Knowing that you haven’t missed one is the harder half, and that is the half I wanted proved. So the theorem is an equivalence: the equation holds exactly when x is one of the printed values. False means that there is no real solution, and True that every real number is one.
Up to degree 2 the roots are written with square roots. From degree 3 on, a rational root is written exactly, and an irrational one as a named algebraic number ρ0, ρ1, … with an interval of width at most that contains no other root.
Examples (19)#
Basic Examples (3)
A quadratic equation:
#cas [solve x] (x ^ 2 = 1)
equivalent real solution predicate
x = 1 ∨ x = -1- Input (real relation)
(x ^ 2 = 1)
Checked by Lean’s kernel: Complete solution predicate for every real value
∀ (x : ℝ), x ^ 2 = 1 ↔ x = 1 ∨ x = -1
The certificate: 1 checked step
Complete solution predicate for every real value
∀ (x : ℝ), x ^ 2 = 1 ↔ x = 1 ∨ x = -1
The computation
Guarantee: the input and output are equivalent for every real value
A cubic with one irrational root, named ρ0 with its interval:
#cas [solve x] (x ^ 3 - 2 = 0)
equivalent real solution predicate
x = ρ0- Input (real relation)
(x ^ 3 - 2 = 0)- ρ0
the root of x^3 - 2 in (1.25992104, 1.25992105)
Checked by Lean’s kernel: Complete list of real solutions
(125992104 / 10 ^ 8 < CAS.AlgRoot.real [-2, 0, 0, 1] (125992104 / 10 ^ 8) (125992105 / 10 ^ 8) ∧ CAS.AlgRoot.real [-2, 0, 0, 1] (125992104 / 10 ^ 8) (125992105 / 10 ^ 8) < 125992105 / 10 ^ 8) ∧ ∀ (x : ℝ), x ^ 3 - 2 = 0 ↔ x = CAS.AlgRoot.real [-2, 0, 0, 1] (125992104 / 10 ^ 8) (125992105 / 10 ^ 8)
from CAS.Polynomial.RealRoot.solve_of_solveCheck
The certificate: 1 checked step
Complete list of real solutions
(125992104 / 10 ^ 8 < CAS.AlgRoot.real [-2, 0, 0, 1] (125992104 / 10 ^ 8) (125992105 / 10 ^ 8) ∧ CAS.AlgRoot.real [-2, 0, 0, 1] (125992104 / 10 ^ 8) (125992105 / 10 ^ 8) < 125992105 / 10 ^ 8) ∧ ∀ (x : ℝ), x ^ 3 - 2 = 0 ↔ x = CAS.AlgRoot.real [-2, 0, 0, 1] (125992104 / 10 ^ 8) (125992105 / 10 ^ 8)
The computation
Certified roots
Square-free polynomial of degree 3, Cauchy bound 3, 4 cells Guarantee: the input and output are equivalent for every real value; each ρj is the algebraic number AlgRoot.real a lo hi, the only root of x^3 - 2 in the interval (lo, hi)
A linear system, with the theorem about all pairs :
#cas [solve x, y] (2*x + y = 1 ∧ x - y = 2)
unique solution
x = 1 ∧ y = -1- Input (linear system)
(2*x + y = 1 ∧ x - y = 2)
Checked by Lean’s kernel: Equivalence with the solved form for every real assignment
∀ (x y : ℝ), 2 * x + y = 1 ∧ x - y = 2 ↔ x = 1 ∧ y = -1
The certificate: 1 checked step
Equivalence with the solved form for every real assignment
∀ (x y : ℝ), 2 * x + y = 1 ∧ x - y = 2 ↔ x = 1 ∧ y = -1
Scope (8)
Square roots from the quadratic formula:
#cas [solve x] (x ^ 2 = 2)
equivalent real solution predicate
x = sqrt(2) ∨ x = -sqrt(2)- Input (real relation)
(x ^ 2 = 2)
Checked by Lean’s kernel: Complete solution predicate for every real value
∀ (x : ℝ), x ^ 2 = 2 ↔ x = √2 ∨ x = -√2
The certificate: 1 checked step
Complete solution predicate for every real value
∀ (x : ℝ), x ^ 2 = 2 ↔ x = √2 ∨ x = -√2
The computation
Guarantee: the input and output are equivalent for every real value
No real solution gives False, and every real number gives True:
#cas [solve x] (x ^ 2 + 1 = 0)
equivalent real solution predicate
False- Input (real relation)
(x ^ 2 + 1 = 0)
Checked by Lean’s kernel: Complete solution predicate for every real value
∀ (x : ℝ), x ^ 2 + 1 = 0 ↔ False
The certificate: 1 checked step
Complete solution predicate for every real value
∀ (x : ℝ), x ^ 2 + 1 = 0 ↔ False
The computation
Guarantee: the input and output are equivalent for every real value
#cas [solve x] (x = x)
equivalent real solution predicate
True- Input (real relation)
(x = x)
Checked by Lean’s kernel: Complete solution predicate for every real value
∀ (x : ℝ), x = x ↔ TrueThe certificate: 1 checked step
Complete solution predicate for every real value
∀ (x : ℝ), x = x ↔ True
The computation
Guarantee: the input and output are equivalent for every real value
Three unknowns:
#cas [solve x, y, z] (x + y + z = 6 ∧ x - y = 0 ∧ x + 2*z = 7)
unique solution
x = 5/3 ∧ y = 5/3 ∧ z = 8/3- Input (linear system)
(x + y + z = 6 ∧ x - y = 0 ∧ x + 2*z = 7)
Checked by Lean’s kernel: Equivalence with the solved form for every real assignment
∀ (x y z : ℝ), x + y + z = 6 ∧ x - y = 0 ∧ x + 2 * z = 7 ↔ x = 5 / 3 ∧ y = 5 / 3 ∧ z = 8 / 3
The certificate: 1 checked step
Equivalence with the solved form for every real assignment
∀ (x y z : ℝ), x + y + z = 6 ∧ x - y = 0 ∧ x + 2 * z = 7 ↔ x = 5 / 3 ∧ y = 5 / 3 ∧ z = 8 / 3
A system with a free parameter, and one with no solution:
#cas [solve x, y, z] (x + y + z = 1 ∧ x - z = 2)
solutions with free parameters [z]
x = 2 + z ∧ y = -1 - 2*z- Input (linear system)
(x + y + z = 1 ∧ x - z = 2)
Checked by Lean’s kernel: Equivalence with the solved form for every real assignment
∀ (x y z : ℝ), x + y + z = 1 ∧ x - z = 2 ↔ x = 2 + z ∧ y = -1 - 2 * z
The certificate: 1 checked step
Equivalence with the solved form for every real assignment
∀ (x y z : ℝ), x + y + z = 1 ∧ x - z = 2 ↔ x = 2 + z ∧ y = -1 - 2 * z
#cas [solve x, y, z] (x + y + z = 6 ∧ x - y = 0 ∧ 2*x + z = 5)
equivalent real solution predicate
False- Input (linear system)
(x + y + z = 6 ∧ x - y = 0 ∧ 2*x + z = 5)
Checked by Lean’s kernel: The system has no real solution
∀ (x y z : ℝ), x + y + z = 6 ∧ x - y = 0 ∧ 2 * x + z = 5 → False
The certificate: 1 checked step
The system has no real solution
∀ (x y z : ℝ), x + y + z = 6 ∧ x - y = 0 ∧ 2 * x + z = 5 → False
A parameter in the coefficients. The answer splits into the cases , and :
#cas [solve x, y] (a*x + y = 1 ∧ x + a*y = 1)
solution by cases of the parameter
x = 1/(a + 1) ∧ y = 1/(a + 1) for a ≠ 1 ∧ a ≠ -1; a = 1: x = 1 - y; a = -1: no solution- Domain
(x, y) ∈ ℝ^2, a ∈ ℝ- Input (linear system with the parameter a)
(a*x + y = 1 ∧ x + a*y = 1)
Checked by Lean’s kernel: The solution for every value of the parameter
(∀ (a x y : ℝ), a ≠ 1 → a ≠ -1 → (a * x + y = 1 ∧ x + a * y = 1 ↔ x = 1 / (a + 1) ∧ y = 1 / (a + 1))) ∧ (∀ (a x y : ℝ), a = 1 → (a * x + y = 1 ∧ x + a * y = 1 ↔ x = 1 - y)) ∧ ∀ (a x y : ℝ), a = -1 → ¬(a * x + y = 1 ∧ x + a * y = 1)
The certificate: 1 checked step
The solution for every value of the parameter
(∀ (a x y : ℝ), a ≠ 1 → a ≠ -1 → (a * x + y = 1 ∧ x + a * y = 1 ↔ x = 1 / (a + 1) ∧ y = 1 / (a + 1))) ∧ (∀ (a x y : ℝ), a = 1 → (a * x + y = 1 ∧ x + a * y = 1 ↔ x = 1 - y)) ∧ ∀ (a x y : ℝ), a = -1 → ¬(a * x + y = 1 ∧ x + a * y = 1)
A polynomial system with four rational 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
The circle and the parabola meet at two irrational points:
#cas [solve x, y] (x^2 + y^2 = 1 ∧ y = x^2)
complete list of real solutions
{x = -0.78615137775742328606…, y ≈ 0.618033988749895}, {x = 0.78615137775742328606…, y ≈ 0.618033988749895}- Input (polynomial system)
(x^2 + y^2 = 1 ∧ y = x^2)
Checked by Lean’s kernel: Complete list of real solutions
∃ ρ, ((-78615137775742328607 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -78615137775742328606 / 10 ^ 20) ∧ 78615137775742328606 / 10 ^ 20 < ρ 1 ∧ ρ 1 < 78615137775742328607 / 10 ^ 20) ∧ ∀ (x y : ℝ), x ^ 2 + y ^ 2 = 1 ∧ y = x ^ 2 ↔ x = ρ 0 ∧ y = ρ 0 ^ 2 ∨ x = ρ 1 ∧ y = ρ 1 ^ 2
The certificate: 1 checked step
Complete list of real solutions
∃ ρ, ((-78615137775742328607 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -78615137775742328606 / 10 ^ 20) ∧ 78615137775742328606 / 10 ^ 20 < ρ 1 ∧ ρ 1 < 78615137775742328607 / 10 ^ 20) ∧ ∀ (x y : ℝ), x ^ 2 + y ^ 2 = 1 ∧ y = x ^ 2 ↔ x = ρ 0 ∧ y = ρ 0 ^ 2 ∨ x = ρ 1 ∧ y = ρ 1 ^ 2
The computation
Gröbner basis
lexicographic basis in shape position with respect to x; eliminant of degree 4, 2 real roots, 3 polynomials in the derivation
Three unknowns, two of them fixed by the third:
#cas [solve x, y, z] (x^2 + y^2 + z^2 = 3 ∧ x = y ∧ y = z)
complete list of real solutions
{x = -1, y = -1, z = -1}, {x = 1, y = 1, z = 1}- Input (polynomial system)
(x^2 + y^2 + z^2 = 3 ∧ x = y ∧ y = z)
Checked by Lean’s kernel: Complete list of real solutions
∀ (x y z : ℝ), x ^ 2 + y ^ 2 + z ^ 2 = 3 ∧ x = y ∧ y = z ↔ x = -1 ∧ y = -1 ∧ z = -1 ∨ x = 1 ∧ y = 1 ∧ z = 1
The certificate: 1 checked step
Complete list of real solutions
∀ (x y z : ℝ), x ^ 2 + y ^ 2 + z ^ 2 = 3 ∧ x = y ∧ y = z ↔ x = -1 ∧ y = -1 ∧ z = -1 ∨ x = 1 ∧ y = 1 ∧ z = 1
The computation
Gröbner basis
lexicographic basis in shape position with respect to z; eliminant of degree 2, 2 real roots, 5 polynomials in the derivation
Applications (1)
The equivalence for one unknown in a proof. cas proves it, and only the three standard axioms are used:
theorem solve_square : ∀ x : ℝ, x ^ 2 = 1 ↔ x = 1 ∨ x = -1 := by cas #print axioms solve_square
solve_square depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (1)
For an inequality, reduce gives the equivalent condition, here between the two roots of :
#cas [reduce x] (x^2 < 2)
equivalent condition on the real roots
ρ0 < x < ρ1, where ρ0 = -1.41421356237309504880…, ρ1 = 1.41421356237309504880…- Input (polynomial relation)
(x^2 < 2)
Checked by Lean’s kernel: Solution set for every real value
∃ ρ, ((-141421356237309504881 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -141421356237309504880 / 10 ^ 20) ∧ 141421356237309504880 / 10 ^ 20 < ρ 1 ∧ ρ 1 < 141421356237309504881 / 10 ^ 20) ∧ ∀ (x : ℝ), x ^ 2 < 2 ↔ ρ 0 < x ∧ x < ρ 1
The certificate: 1 checked step
Solution set for every real value
∃ ρ, ((-141421356237309504881 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -141421356237309504880 / 10 ^ 20) ∧ 141421356237309504880 / 10 ^ 20 < ρ 1 ∧ ρ 1 < 141421356237309504881 / 10 ^ 20) ∧ ∀ (x : ℝ), x ^ 2 < 2 ↔ ρ 0 < x ∧ x < ρ 1
The computation
Certified roots
2 real roots of the polynomial, 6 cells; cuts [-3, -1767766952966368811/1250000000000000000, 3]; signs [true, false, true]
Possible Issues (4)
Only polynomial equations. For other equations, the message points to findRoot:
#cas [solve x] (sin x = 0)
Error
supported fragment: polynomials with rational coefficients in one real variable; for other equations, #cas [findRoot x in [a, b]] (f = g) finds a certified root in an interval
An inequality is not an equation, and the message points to reduce:
#cas [solve x] (x < 1)
Error
solve expects an equation; use reduce for a comparison
A circle alone has infinitely many points, and the nonlinear solver needs finitely many complex solutions:
#cas [solve x, y] (x^2 + y^2 = 1)
Error
solve: the system has infinitely many complex solutions; the nonlinear solver takes systems with finitely many
A system with a repeated complex solution may be refused, as this one is. The method needs the complex solutions to be distinct in one combination of the unknowns:
#cas [solve x, y] (x^2 = 0 ∧ y^2 = 0)
Error
solve: no separating form x + c*y with c ≤ 7 gives a Gröbner basis in shape position, so the system has a repeated complex solution
Neat Examples (2)
The real and imaginary parts of . The three solutions are the cube roots of unity:
#cas [solve x, y] (x^3 - 3*x*y^2 = 1 ∧ 3*x^2*y - y^3 = 0)
complete list of real solutions
{x ≈ -0.5, y ≈ -0.866025403784439}, {x ≈ -0.5, y ≈ 0.866025403784439}, {x = 1, y = 0}- Input (polynomial system)
(x^3 - 3*x*y^2 = 1 ∧ 3*x^2*y - y^3 = 0)
Checked by Lean’s kernel: Complete list of real solutions
∃ ρ, ((-136602540378443864677 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -136602540378443864676 / 10 ^ 20) ∧ 36602540378443864676 / 10 ^ 20 < ρ 1 ∧ ρ 1 < 36602540378443864677 / 10 ^ 20) ∧ ∀ (x y : ℝ), x ^ 3 - 3 * x * y ^ 2 = 1 ∧ 3 * x ^ 2 * y - y ^ 3 = 0 ↔ x = 8 / 9 * ρ 0 ^ 7 + 14 / 9 * ρ 0 ^ 4 - 13 / 9 * ρ 0 ∧ y = -(8 / 9 * ρ 0 ^ 7) - 14 / 9 * ρ 0 ^ 4 + 22 / 9 * ρ 0 ∨ x = 8 / 9 * ρ 1 ^ 7 + 14 / 9 * ρ 1 ^ 4 - 13 / 9 * ρ 1 ∧ y = -(8 / 9 * ρ 1 ^ 7) - 14 / 9 * ρ 1 ^ 4 + 22 / 9 * ρ 1 ∨ x = 1 ∧ y = 0
The certificate: 1 checked step
Complete list of real solutions
∃ ρ, ((-136602540378443864677 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -136602540378443864676 / 10 ^ 20) ∧ 36602540378443864676 / 10 ^ 20 < ρ 1 ∧ ρ 1 < 36602540378443864677 / 10 ^ 20) ∧ ∀ (x y : ℝ), x ^ 3 - 3 * x * y ^ 2 = 1 ∧ 3 * x ^ 2 * y - y ^ 3 = 0 ↔ x = 8 / 9 * ρ 0 ^ 7 + 14 / 9 * ρ 0 ^ 4 - 13 / 9 * ρ 0 ∧ y = -(8 / 9 * ρ 0 ^ 7) - 14 / 9 * ρ 0 ^ 4 + 22 / 9 * ρ 0 ∨ x = 8 / 9 * ρ 1 ^ 7 + 14 / 9 * ρ 1 ^ 4 - 13 / 9 * ρ 1 ∧ y = -(8 / 9 * ρ 1 ^ 7) - 14 / 9 * ρ 1 ^ 4 + 22 / 9 * ρ 1 ∨ x = 1 ∧ y = 0
The computation
Gröbner basis
lexicographic basis in shape position with respect to the separating form x + y; eliminant of degree 9, 3 real roots, 11 polynomials in the derivation
The four points share their coordinates in pairs, so neither nor tells them apart, and the report separates them by :
#cas [solve x, y] (x^2 + y^2 = 1 ∧ x^2 - y^2 = 0)
complete list of real solutions
{x ≈ -0.707106781186548, y ≈ -0.707106781186548}, {x ≈ 0.707106781186548, y ≈ -0.707106781186548}, {x ≈ -0.707106781186548, y ≈ 0.707106781186548}, {x ≈ 0.707106781186548, y ≈ 0.707106781186548}- Input (polynomial system)
(x^2 + y^2 = 1 ∧ x^2 - y^2 = 0)
Checked by Lean’s kernel: Complete list of real solutions
∃ ρ, ((-212132034355964257321 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -212132034355964257320 / 10 ^ 20) ∧ (-70710678118654752441 / 10 ^ 20 < ρ 1 ∧ ρ 1 < -70710678118654752440 / 10 ^ 20) ∧ (70710678118654752440 / 10 ^ 20 < ρ 2 ∧ ρ 2 < 70710678118654752441 / 10 ^ 20) ∧ 212132034355964257320 / 10 ^ 20 < ρ 3 ∧ ρ 3 < 212132034355964257321 / 10 ^ 20) ∧ ∀ (x y : ℝ), x ^ 2 + y ^ 2 = 1 ∧ x ^ 2 - y ^ 2 = 0 ↔ x = 1 / 3 * ρ 0 ^ 3 - 7 / 6 * ρ 0 ∧ y = -(1 / 6 * ρ 0 ^ 3) + 13 / 12 * ρ 0 ∨ x = 1 / 3 * ρ 1 ^ 3 - 7 / 6 * ρ 1 ∧ y = -(1 / 6 * ρ 1 ^ 3) + 13 / 12 * ρ 1 ∨ x = 1 / 3 * ρ 2 ^ 3 - 7 / 6 * ρ 2 ∧ y = -(1 / 6 * ρ 2 ^ 3) + 13 / 12 * ρ 2 ∨ x = 1 / 3 * ρ 3 ^ 3 - 7 / 6 * ρ 3 ∧ y = -(1 / 6 * ρ 3 ^ 3) + 13 / 12 * ρ 3
The certificate: 1 checked step
Complete list of real solutions
∃ ρ, ((-212132034355964257321 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -212132034355964257320 / 10 ^ 20) ∧ (-70710678118654752441 / 10 ^ 20 < ρ 1 ∧ ρ 1 < -70710678118654752440 / 10 ^ 20) ∧ (70710678118654752440 / 10 ^ 20 < ρ 2 ∧ ρ 2 < 70710678118654752441 / 10 ^ 20) ∧ 212132034355964257320 / 10 ^ 20 < ρ 3 ∧ ρ 3 < 212132034355964257321 / 10 ^ 20) ∧ ∀ (x y : ℝ), x ^ 2 + y ^ 2 = 1 ∧ x ^ 2 - y ^ 2 = 0 ↔ x = 1 / 3 * ρ 0 ^ 3 - 7 / 6 * ρ 0 ∧ y = -(1 / 6 * ρ 0 ^ 3) + 13 / 12 * ρ 0 ∨ x = 1 / 3 * ρ 1 ^ 3 - 7 / 6 * ρ 1 ∧ y = -(1 / 6 * ρ 1 ^ 3) + 13 / 12 * ρ 1 ∨ x = 1 / 3 * ρ 2 ^ 3 - 7 / 6 * ρ 2 ∧ y = -(1 / 6 * ρ 2 ^ 3) + 13 / 12 * ρ 2 ∨ x = 1 / 3 * ρ 3 ^ 3 - 7 / 6 * ρ 3 ∧ y = -(1 / 6 * ρ 3 ^ 3) + 13 / 12 * ρ 3
The computation
Gröbner basis
lexicographic basis in shape position with respect to the separating form x + 2*y; eliminant of degree 4, 4 real roots, 8 polynomials in the derivation
