Command
#cas
The calculator: evaluates a call, simplifies an expression or runs a mode, and proves its answer.
#cas egamma (5/2), and otherwise simplifies it as #cas [simplify] does.#cas [mode] ederive x, factor or solve x.#cas (options) [mode] e(digits := 30).#cas is the calculator, and for me it is where most work with SymLean starts. You type an expression and get the answer, together with the theorem behind it, checked by Lean’s kernel. Nothing needs setting up beyond import CAS, and names like x and t are variables, as they would be on paper.
Examples (20)#
Basic Examples (3)
A call is evaluated exactly:
#cas (gamma (5/2))
exact value of Γ
3√π/4- Input (rational number)
5/2
Checked by Lean’s kernel: Gamma by a closed formula
Real.Gamma (5 / 2) = 3 * √Real.pi / 4
The certificate: 1 checked step
Gamma by a closed formula
Real.Gamma (5 / 2) = 3 * √Real.pi / 4
A binomial coefficient:
#cas (binomial 10 3)
binomial
120- Domain
ℕ- Input (natural numbers)
(10, 3)
Checked by Lean’s kernel: binomial
Nat.choose 10 3 = 120
The certificate: 1 checked step
binomial
Nat.choose 10 3 = 120
Any other input is simplified, with the conditions that the answer needs:
#cas ((x ^ 4 - 1) / (x ^ 2 - 1))
x^2 + 1- Conditions
Checked by Lean’s kernel: Identity with the simplified form
∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
from CAS.Command.eq_of_simplifyFinDisplayRoute
The certificate: 2 checked steps
Identity with the simplified form
∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
Simplification under generated rewrite assumptions
∀ (ρ : Fin 1 → ℝ), CAS.Verified.Expr.Alg.SideHolds ρ (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.nonzero → CAS.Verified.Expr.eval ρ (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.rhs = CAS.Verified.Expr.eval ρ (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.lhs
The computation
Variables: x
Checked symbolic computation
Raw checked nonzero requirements: x^2 - 1 Guarantee: these assumptions justify conditional rewrites and preserve real evaluation
Scope (4)
A family of polynomials takes the degree and the variable:
#cas (ChebyshevT 5 x)
polynomial with integer coefficients
16*x^5 - 20*x^3 + 5*x- Domain
Polynomial.Chebyshev.T R 5, every commutative ring R : Type- Input (polynomial in x)
ChebyshevT 5 x
Checked by Lean’s kernel: Monomial expansion of ChebyshevT 5
∀ (R : Type) [inst : CommRing R], Polynomial.Chebyshev.T R 5 = 16 * Polynomial.X ^ 5 - 20 * Polynomial.X ^ 3 + 5 * Polynomial.X
The certificate: 1 checked step
Monomial expansion of ChebyshevT 5
∀ (R : Type) [inst : CommRing R], Polynomial.Chebyshev.T R 5 = 16 * Polynomial.X ^ 5 - 20 * Polynomial.X ^ 3 + 5 * Polynomial.X
An exact value of the zeta function:
#cas (zeta 4)
exact value of ζ
pi^4/90- Domain
ℂ (Mathlib's riemannZeta)- Input (even positive integer)
s = 4
Checked by Lean’s kernel: ζ(2k) by Bernoulli numbers (riemannZeta_two_mul_nat)
riemannZeta 4 = ↑Real.pi ^ 4 / 90
The certificate: 1 checked step
ζ(2k) by Bernoulli numbers (riemannZeta_two_mul_nat)
riemannZeta 4 = ↑Real.pi ^ 4 / 90
Large arguments, and closed expressions as arguments:
#cas (powerMod 2 123456789123456789123456789 1000000007)
modular power
612059118- Domain
ℕ- Input (natural numbers)
2^123456789123456789123456789 mod 1000000007
Checked by Lean’s kernel: modular power
2 ^ 123456789123456789123456789 % 1000000007 = 612059118
The certificate: 1 checked step
modular power
2 ^ 123456789123456789123456789 % 1000000007 = 612059118
#cas (eulerPhi (2 ^ 10))
eulerPhi
512- Domain
ℕ- Input (natural numbers)
1024
Checked by Lean’s kernel: eulerPhi
Nat.totient 1024 = 512
The certificate: 1 checked step
eulerPhi
Nat.totient 1024 = 512
A mode in brackets. Here an antiderivative, which needs the error function:
#cas [integrate x] (exp (-x ^ 2))
antiderivative (with the interval integrals)
1/2*sqrt(pi)*erf(x)- Input (c e ^ (-α x ^ 2 + β x + γ), α > 0)
(exp (-x ^ 2))
Checked by Lean’s kernel: Integral of the input
∀ (a b : ℝ), ∫ (x : ℝ) in a..b, Real.exp (-x ^ 2) = 1 / 2 * √Real.pi * CAS.erf b - 1 / 2 * √Real.pi * CAS.erf a
from CAS.integral_gaussian_eq
The certificate: 2 checked steps
Integral of the input
∀ (a b : ℝ), ∫ (x : ℝ) in a..b, Real.exp (-x ^ 2) = 1 / 2 * √Real.pi * CAS.erf b - 1 / 2 * √Real.pi * CAS.erf a
Derivative of the primitive
∀ (x : ℝ), HasDerivAt (fun x ↦ 1 / 2 * √Real.pi * CAS.erf x) (Real.exp (-x ^ 2)) x
Options (2)
#cas e has no options, and a mode takes its own in parentheses before the bracket:
#cas (digits := 30) [findRoot x in [1, 2]] (x^2 - 2)
certified simple root
x = 1.414213562373095048801688724210 ± 10^-30- Domain
x ∈ [1, 2]
Checked by Lean’s kernel: Unique root in the interval
∃! x, x ∈ Set.Icc (1414213562373095048801688724209 / 10 ^ 30) (1414213562373095048801688724211 / 10 ^ 30) ∧ x ^ 2 - 2 = 0
The certificate: 1 checked step
Unique root in the interval
∃! x, x ∈ Set.Icc (1414213562373095048801688724209 / 10 ^ 30) (1414213562373095048801688724211 / 10 ^ 30) ∧ x ^ 2 - 2 = 0
The computation
Certified root
Sign change found by interval sampling and bisection (not proof) Unique root in [1.414213562373095048801688724209, 1.414213562373095048801688724211], within 10^-30 of 1.414213562373095048801688724210: endpoint signs and a derivative of one sign, checked by the kernel
With cas.suggest, the report also offers its theorem as an example to paste:
set_option cas.suggest true in #cas ((x ^ 4 - 1) / (x ^ 2 - 1))
x^2 + 1- Conditions
Checked by Lean’s kernel: Identity with the simplified form
∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
from CAS.Command.eq_of_simplifyFinDisplayRoute
The certificate: 2 checked steps
Identity with the simplified form
∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
Simplification under generated rewrite assumptions
∀ (ρ : Fin 1 → ℝ), CAS.Verified.Expr.Alg.SideHolds ρ (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.nonzero → CAS.Verified.Expr.eval ρ (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.rhs = CAS.Verified.Expr.eval ρ (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.lhs
The computation
Variables: x
Checked symbolic computation
Raw checked nonzero requirements: x^2 - 1 Guarantee: these assumptions justify conditional rewrites and preserve real evaluation
Try this
example (x : ℝ) (h : x * x - 1 ≠ 0) : (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1 := by cas
Applications (2)
The report of #cas (gamma (5/2)) states , and cas proves the statement. Only the three standard axioms are used:
theorem gamma_five_halves : Real.Gamma (5 / 2) = 3 * √Real.pi / 4 := by cas #print axioms gamma_five_halves
gamma_five_halves depends on the axioms propext, Classical.choice, Quot.sound.
The quotient from Basic Examples, as a theorem with its condition:
theorem simplify_quotient (x : ℝ) (h : x ^ 2 - 1 ≠ 0) : (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1 := by cas
Lean accepts the proof.
Properties and Relations (2)
#cas e is #cas [simplify] e when e is not a call:
#cas [simplify] ((x ^ 4 - 1) / (x ^ 2 - 1))
x^2 + 1- Conditions
Checked by Lean’s kernel: Identity with the simplified form
∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
from CAS.Command.eq_of_simplifyFinDisplayRoute
The certificate: 2 checked steps
Identity with the simplified form
∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
Simplification under generated rewrite assumptions
∀ (ρ : Fin 1 → ℝ), CAS.Verified.Expr.Alg.SideHolds ρ (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.nonzero → CAS.Verified.Expr.eval ρ (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.rhs = CAS.Verified.Expr.eval ρ (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.lhs
The computation
Variables: x
Checked symbolic computation
Raw checked nonzero requirements: x^2 - 1 Guarantee: these assumptions justify conditional rewrites and preserve real evaluation
A function with digits only is evaluated by #cas [N d]:
#cas [N 30] (erf 1)
decimal enclosure of width at most 10^-30, with 30 terms of the series
[0.8427007929497148693412206350826, 0.8427007929497148693412206350827]- Domain
error function erf x = 2/√π ∫₀ˣ e^(-t²) dt at a rational point
Checked by Lean’s kernel: Enclosure of erf 1
0.8427007929497148693412206350826 ≤ CAS.erf 1 ∧ CAS.erf 1 ≤ 0.8427007929497148693412206350827 ∧ 0.8427007929497148693412206350827 - 0.8427007929497148693412206350826 ≤ 1 / 10 ^ 30
from CAS.erfCheck_sound
The certificate: 1 checked step
Enclosure of erf 1
0.8427007929497148693412206350826 ≤ CAS.erf 1 ∧ CAS.erf 1 ≤ 0.8427007929497148693412206350827 ∧ 0.8427007929497148693412206350827 - 0.8427007929497148693412206350826 ≤ 1 / 10 ^ 30
Possible Issues (6)
The call must be the whole input:
#cas (2 * gamma (5/2))
Error
unsupported symbolic function 'gamma'; expected abs, sin, cos, tan, sinh, cosh, tanh, atan/arctan, asin/arcsin, acos/arccos, exp, log, or sqrt. `gamma x` is evaluated as the whole input of `#cas (gamma x)`
A family of polynomials needs the variable too:
#cas (ChebyshevT 5)
Error
ChebyshevT takes 2 arguments, as in `ChebyshevT n x`; the call has 1
#cas computes no exact value of the error function, only its digits:
#cas (erf 1)
Error
`#cas` computes no exact value of `erf x`; `#cas [N d] (erf x)` gives its digits
Mode words are case sensitive:
#cas [Simplify] (x + x)
Error
`Simplify` is no mode of `#cas`; the nearest mode is `simplify`
A function in the bracket gets the commands that evaluate it:
#cas [LegendreP 5]
Error
`LegendreP` is no mode of `#cas`; write `#cas (LegendreP n x)`, `#cas [expand] (LegendreP n x)` or `#cas [N d] (LegendreP n x)`
A value with more than 10000 digits is refused:
#cas (factorial 5000)
Error
factorial: the value has more than 10000 digits, the most that a call computes
Neat Examples (1)
The hundredth Fibonacci number, with the theorem that proves it:
#cas (fibonacci 100)
fibonacci
354224848179261915075- Domain
ℕ- Input (natural numbers)
100
Checked by Lean’s kernel: fibonacci
Nat.fib 100 = 354224848179261915075
The certificate: 1 checked step
fibonacci
Nat.fib 100 = 354224848179261915075
