Option of #cas and cas
oracle
Asks SymPy, SageMath, Maxima, PARI/GP, FLINT, Giac, Singular or Gappa for a proposal, and proves it in Lean or refuses.
#cas [mode, oracle := tool] eintegrate, factor, groebner, solve, nsolve, nintegrate, eigenvalues, enclose, dsolve, sum and sos.#cas (digits := d) [mode, oracle := tool] ensolve, nintegrate, eigenvalues and enclose.cas [oracle := tool]Some searches are better done by a mature computer algebra system, and I’d rather hand those to one than write them again in Lean. With oracle := sympy, SymLean asks SymPy for a proposal (an antiderivative, a factorization, cofactors, a solution, a closed form or a decimal) and then proves the statement in Lean, or refuses. Nothing the oracle says is trusted. If SymPy proposes something wrong, the proof fails, and you get a refusal instead of a theorem.
The examples here are quoted from the oracle tests (tests/oracle), which call the real tools, and each output is the one that #guard_msgs pins there. The module docstrings of CASOracle name the version that each tool was tested with. On 24 November 2026 all of these tests passed, with SymPy 1.14.0, SageMath 10.10, Maxima 5.50.0, PARI/GP 2.17.4, FLINT 3.5.0, Gappa 1.8.3, Giac 2.0.0 and Singular 4.4.1. The site build runs none of these tests.
Examples (24)#
Basic Examples (3)
SymPy factors a polynomial and the identity is proved. That the factors are irreducible is not, and the report says so:
#cas [factor, oracle := sympy] (x ^ 4 + 4)
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
the identity is checked, irreducibility is not
(x^2 - 2*x + 2)*(x^2 + 2*x + 2)In a proof, SymPy finds how the goal follows from the hypotheses. The suggestion is the proof to keep, and it needs no oracle:
theorem combination_by_sympy (x y : ℝ) (h1 : x * y = 1) (h2 : x = y) : x ^ 2 = 1 := by cas [oracle := sympy]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
Try this
linear_combination h1 + x * h2
An antiderivative from SymPy, proved by differentiating it back:
#cas [integrate x, oracle := sympy] (x ^ 2 * sin x)
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
antiderivative
-(x^2*cos(x)) + 2*x*sin(x) + 2*cos(x)Scope (11)
Maxima integrates too:
#cas [integrate x, oracle := maxima] (x * exp x)
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
antiderivative
exp(x)*(x - 1)So does Giac:
#cas [integrate x, oracle := giac] (x ^ 2 * sin x)
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
antiderivative
2*cos(x) + 2*x*sin(x) - x^2*cos(x)A Gröbner basis of the same ideal. That the basis is reduced is a hint:
#cas [groebner x, y, oracle := sympy] [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 + 4Singular computes the same basis and lists it in its own order:
#cas [groebner x, y, oracle := singular] [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)
y^4 - 5*y^2 + 4, 2*x + y^3 - 5*ySolutions, each checked by substitution. That the list is complete is not checked:
#cas [solve x, y, oracle := sympy] (x ^ 2 + y ^ 2 = 5 ∧ x * y = 2)
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
solutions checked by substitution; completeness not checked
(x = -2, y = -1) ∨ (x = -1, y = -2) ∨ (x = 1, y = 2) ∨ (x = 2, y = 1)A family of solutions of a differential equation, from SageMath:
#cas [dsolve y x, oracle := sage] (y'' + y = 0)
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
a family of solutions (checked); that it is the general solution is not
y(x) = c1*sin(x) + c2*cos(x)A nonlinear equation, from Giac:
#cas [dsolve y x, oracle := giac] (y' = y ^ 2)
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
a family of solutions (checked); that it is the general solution is not
y(x) = 1/(-x + c1)A closed form of a sum, proved by induction:
#cas [sum k 1 n, oracle := sympy] (1 / (k * (k + 1)))
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
closed form, checked by induction for n ≥ 1
n/(n + 1)Eigenvalues, each within :
#cas [eigenvalues, oracle := sympy] !![2, 1, 0; 1, 3, 1; 0, 1, 4]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
a real eigenvalue in each interval (existence checked)
1.267949 ± 10^-6, 3.000000 ± 10^-6, 4.732051 ± 10^-6Gappa’s bounds on a box, checked by cega:
#cas [enclose x in [1/3, 2], oracle := gappa] (sqrt x / (1 + x))
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
enclosure on the box, checked by cega
[0.192450, 1.060661]An inequality between polynomials, by a sum of squares. The suggested script checks the identity with ring and the signs with positivity. The test pins only its start, since the squares come from a numerical solver:
theorem sos_quartic (x y : ℝ) : 0 ≤ x ^ 4 + y ^ 4 - 4 * x * y + 2 := by cas [oracle := sympy]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
Try this
(rw [show x ^ 4 + y ^ 4 - 4 * x * y + 2 = …
Options (1)
The numerical modes take (digits := d), from 1 to 12 and 6 by default. Here a cube root from FLINT:
#cas (digits := 8) [nsolve x, oracle := flint] (x ^ 3 = 2)
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
a root in each interval (existence checked)
1.25992105 ± 10^-8Applications (3)
A definite integral, with SymPy’s primitive. The suggestion is a call of cas [integrate primitive := F], which needs no oracle, and the theorem uses only the three standard axioms:
theorem integral_by_oracle : ∫ x in (0 : ℝ)..1, x * Real.exp x = 1 := by cas [oracle := sympy]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
Try this
cas [integrate primitive := fun x => (x - 1) * Real.exp x]
#print axioms integral_by_oracleQuoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output.
integral_by_oracle depends on the axioms propext, Classical.choice, Quot.sound.
SageMath finds the combination behind over :
theorem combination_by_sage (a b c : ℚ) (h₁ : a + b + c = 0) (h₂ : a * b + b * c + c * a = 0) : a ^ 2 + b ^ 2 + c ^ 2 = 0 := by cas [oracle := sage]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
Try this
linear_combination (a + b + c) * h₁ + (-2) * h₂Singular finds that a power of the goal follows: is not in the ideal of , but is.
theorem power_by_singular (x : ℝ) (h : x ^ 2 = 0) : x = 0 := by cas [oracle := singular]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
Try this
linear_combination (exp := 2) hProperties and Relations (2)
The suggested proofs stand on their own. Here two of them, SymPy’s combination and the integral, compiled for this page without any oracle:
example (x y : ℝ) (h1 : x * y = 1) (h2 : x = y) : x ^ 2 = 1 := by linear_combination h1 + x * h2
Lean accepts the proof.
example : ∫ x in (0 : ℝ)..1, x * Real.exp x = 1 := by cas [integrate primitive := fun x => (x - 1) * Real.exp x]
Lean accepts the proof.
SymPy’s digits for are the ones nintegrate proves without an oracle:
#cas [nintegrate x in [0, 1], oracle := sympy] (exp (-x ^ 2))
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
certified value of the integral
0.746824 ± 10^-6#cas [nintegrate x in [0, 1]] (exp (-x^2))
certified value of the integral
0.746824 ± 10^-6- Domain
x ∈ [0, 1]
Checked by Lean’s kernel: Certified Simpson panels in one kernel check
|(∫ (x : ℝ) in 0..1, Real.exp (-x ^ 2)) - 746824 / 10 ^ 6| ≤ 1 / 10 ^ 6
The certificate: 1 checked step
Certified Simpson panels in one kernel check
|(∫ (x : ℝ) in 0..1, Real.exp (-x ^ 2)) - 746824 / 10 ^ 6| ≤ 1 / 10 ^ 6
The computation
Certified quadrature
Batch Simpson certificate with 16 panels; fourth-derivative bounds by interval evaluation of the simplified symbolic derivative
Possible Issues (3)
A nonnegative polynomial need not be a sum of squares. For Motzkin’s polynomial the oracle finds no certificate, and the refusal proves nothing about the inequality:
example (x y : ℝ) : 0 ≤ x ^ 4 * y ^ 2 + x ^ 2 * y ^ 4 - 3 * x ^ 2 * y ^ 2 + 1 := by cas [oracle := sympy]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
Error
no positive semidefinite Gram matrix
The premise is not an inequality, so it is not sent, and without it there is no sum with a positive term:
example : ∀ x : ℝ, x ≠ 0 → 0 < x ^ 2 := by cas [oracle := sympy]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
Error
no sum of squares with a positive term
A variable printed as x✝ can’t be written back, so the script as printed doesn’t check. The goal is still proved from the same certificate, and the suggestion is the call itself:
theorem sos_hidden_atom : ∀ x : ℝ, 0 ≤ x ^ 2 + 1 := by intro cas [oracle := sympy]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output.
cas [oracle := sympy]: the script as printed does not check here, so no oracle-free script is suggested; the goal is proved from the same certificate over the elaborated atoms
Try this
cas [oracle := sympy]Neat Examples (1)
is positive but takes values below every positive constant, at for large , so no sum of squares plus a positive constant equals it. A multiplier works, since , and the oracle finds one:
theorem sos_not_attained : ∀ x y : ℝ, 0 < (x * y - 1) ^ 2 + x ^ 2 := by cas [oracle := sympy]
Quoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output (the part shown).
Try this
(intro x y; refine pos_of_mul_pos_right (a := …
#print axioms sos_not_attainedQuoted from tests/oracle/Oracles.lean, where #guard_msgs pins the output.
sos_not_attained depends on the axioms propext, Classical.choice, Quot.sound.
See Also
cas · cas [integrate primitive := F] · factor · nintegrate · enclose · Options
