Computer algebra systems such as Mathematica, Maple and SymPy have long been part of how we do mathematics. Whether we are deriving an equation, working out an integral or simplifying a particularly unpleasant expression, it is often much easier to ask a computer to do the calculation. But when formalizing mathematics in Lean, we still need to prove that the resulting expression is correct. This can take considerably more effort than finding the answer itself. SymLean grew out of our interest in making these two processes work together. We wanted something that feels like a conventional computer algebra system but produces Lean theorems that we can use directly in our proofs.
The library covers symbolic algebra, differentiation, integration, series expansions, limits,
equation solving, special functions and certified numerical computation. We can run a calculation
interactively with #cas, or inside an existing Lean proof with the cas and cega tactics. The
nice part is that the algorithms we use to find an answer don't have to be trusted. They can be
heuristic, and we can even delegate computations to external computer algebra systems.
Dashed arrows are proposals, which nobody has to trust. SymLean turns them into certificates and proofs with Mathlib and FloatLib, and Lean's kernel checks the result.
Documentation · Getting started · Why SymLean · Trust assumptions
From a checkout of this repository, fetch the Mathlib cache and build SymLean:
lake exe cache get
lake buildUse the Lean version in lean-toolchain (v4.36.0, with Mathlib v4.36.0).
Dependency versions are pinned in lake-manifest.json.
In your own Lake project, add SymLean with require:
require SymLean from git "https://github.com/lean-dojo/SymLean.git" @ "main"Then run lake update SymLean and lake exe cache get, and start a file with import CAS. A library
that reads files into proofs with include_str or json_data% should add SymLean's facet
SymLean.embeddedInputs to its needs, so that Lake rebuilds a module when such a file changes (see
the library guide).
If you have used Mathematica, Maple or SymPy, #cas will feel familiar: you give it a mode and an
expression, and it answers. The difference is that every answer comes back as a theorem that Lean
has checked. Here is a short session, with the answers SymLean prints:
import CAS
#cas [factor] (2*x^3 - 3*x^2 + 1) -- (x - 1)^2*(2*x + 1)
#cas [derive x] (x ^ 2 * sin x) -- x*(2*sin(x) + x*cos(x))
#cas [integrate x] (atan x) -- x*atan(x) - 1/2*log(1 + x^2)
#cas [integrate x in [0, 1]] (x * exp x) -- 1
#cas [limit x → 0] (sin x / x) -- 1
#cas [series x 0 7] (sin x) -- x - 1/6*x^3 + 1/120*x^5 - 1/5040*x^7 + o(x^7)
#cas [sum k 1 n] (k^2) -- n*(n + 1)*(2*n + 1)/6
#cas [solve x] (x ^ 2 = 1) -- x = 1 ∨ x = -1
#cas [roots x] (x ^ 5 - x - 1 = 0) -- 1.16730397826141868425, the only real root
#cas [dsolve y x] (y'' + 3*y' + 2*y = 0) -- y(x) = c₁*exp(-x) + c₂*exp(-(2*x))
#cas [eigenvalues] !![2, 0, 0; 0, 3, 4; 0, 4, 9] -- [1, 2, 11]
#cas (zeta 4) -- pi^4/90
#cas [nintegrate x in [0, 1]] (exp (-x^2)) -- 0.746824 ± 10^-6
#cas [simplify] ((x ^ 4 - 1) / (x ^ 2 - 1)) -- x^2 + 1, when x^2 - 1 ≠ 0Each line also prints the theorem behind its answer, with the conditions under which it holds:
the simplification needs
In a proof, the tactics do the same work on your own goals:
theorem integral_x_exp : ∫ x in (0 : ℝ)..1, x * Real.exp x = 1 := by
cas
example (x : ℝ) (hx : x ≠ 0) : x / x = 1 := by
cas
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by
cegacas proves the definite integral in Mathlib's own terms. The second goal needs hx, because
division in Lean is total: hx the
tactic fails and names the missing hypothesis x ≠ 0. cega proves the bound cas? and cega? suggest a tactic call to keep.
Each group links its guide, and the documentation lists every mode with examples.
-
Simplification and fractions.
#cas [simplify]rewrites a real expression and proves that the result equals it wherever the printed conditions hold. Cancelling a divisor$d$ adds$d \neq 0$ , and combining real powers of$a$ adds$a > 0$ . In Mathlib$\tan x$ is$\sin x / \cos x$ , so#cas [simplify] (tan x * cos x)gives$\sin x$ under$\cos x \neq 0$ .fullSimplifyranks candidate forms byleafCount,depthorlengthand keeps the smallest one it can prove:log (x*y) - log x - log ybecomes$0$ under just$x \neq 0$ and$y \neq 0$ , since Mathlib's logarithm is$\log |x|$ .togetherputs a sum over one denominator,cancelreduces each summand on its own, andapartgives partial fractions in one variable, over the factors you wrote, refined by gcds. Their theorems assume that the divisors, as written, are nonzero. See the algebra guide. -
Expanding and factoring.
expandmultiplies out,factorwrites a polynomial as a product,collect xgroups the terms by powers of$x$ andtrigExpandapplies the addition and double-angle formulas. Each proves an identity for all real values, with no conditions, and the tacticcasproves the same identities.factorfinds rational roots, perfect powers and homogeneous forms in two variables, and it doesn't claim that a factor left over is irreducible:$x^4 + 4$ stays whole, although it factors over$\mathbb{Q}$ . WithCASOracle.Factorimported,#cas [factor, oracle := sympy] (x ^ 4 + 4)gets$(x^2 - 2x + 2)(x^2 + 2x + 2)$ from SymPy, and Lean checks the product, not that the factors are irreducible. See thefactorpage. -
Polynomials in one variable.
coefficientandexponentread off coefficients and degrees,polynomialQuotientRemainderdivides with remainder,polynomialGCDandpolynomialLCMgive gcds and lcms, andinterpolatingPolynomialinterpolates. The theorems are about Mathlib's owncoeff,natDegree,/,%,gcd,lcmandevalinℚ[X], and the tacticcasproves such goals and refuses a wrong coefficient, degree, gcd or lcm with the right one in its message. A gcd comes with its cofactors and a Bézout identity, so the kernel never reruns the Euclidean algorithm. Other variables entercoefficientandexponentas constants inℝ[X], andexponentassumes that a leading coefficient involving them is nonzero:#cas [exponent x] (a*x^2 + x + 1)gives the degree$2$ under$a \neq 0$ . See the polynomials guide. -
Ideals and Gröbner bases.
#cas [groebner x, y] [x^2 + y^2 - 5, x*y - 2]gives the reduced lexicographic basis, scaled to integer coefficients,$2x + y^3 - 5y$ and$y^4 - 5y^2 + 4$ , which ends with a polynomial in$y$ alone. It proves inMvPolynomial (Fin 2) ℚthat the basis spans the same ideal and, by Buchberger's criterion, that it is a Gröbner basis forMonomialOrder.lex, but not that it is reduced. The search stops after 400 polynomials or 4000 pairs. WithCASOracle.Idealimported,oracle := sage,singularorsympyproposes the basis instead, and Lean checks it the same way.memberprovesf ∈ Ideal.span {g₁, …, gₘ}with explicit cofactors, andcasproves such goals in any commutative ring, though a certificate with denominators needs a$\mathbb{Q}$ -algebra. A refusal proves nothing about non-membership. See thegroebnerpage.
-
Equations and inequalities. When
#cas [solve x]or#cas [roots x]succeeds on a polynomial equation with rational coefficients, it proves that no real solution is missing. The search can refuse an equation that needs more than 1024 cells. For a nonempty finite solution set,solveproves∀ x : ℝ, lhs = rhs ↔ x = r₁ ∨ … ∨ x = rₖ.rootsprints the irrational solutions to 20 decimals, or up to 60 with(digits := d), each in an interval proved to hold exactly one, androots z in ℂlists every complex solution.#cas [reduce x]proves exactly where a polynomial inequality holds, as a union of intervals.#cas [solve x, y]takes linear systems and polynomial systems with finitely many complex solutions. Other equations get one simple root at a time:#cas [findRoot x in [0, 1]] (cos x = x)proves that exactly one solution lies within$10^{-10}$ of 0.7390851332. In a proof,casproves thesolveequivalence, bounds on a root and counts of real roots. See the guide. -
Linear algebra. You write a matrix with rational entries in Mathlib's notation, such as
!![1, 2; 3, 4], and each answer is a theorem about Mathlib's own definitions.#cas [det]provesA.det = d,inverseprovesA⁻¹ = B,matrixRankprovesA.rank = r, androwReduceprovesE * A = R ∧ E.det ≠ 0 ∧ R.IsReducedRowEchelon.linearSolveandnullSpacedescribe every rational solution:#cas [linearSolve] (!![1, 2, 3; 2, 4, 6], ![1, 2])prints![1, 0, 0] + span of [![-2, 1, 0], ![-3, 0, 1]]and proves that there are no others. For a singular matrix, whose Mathlib inverse is the zero matrix,inverseprovesA.det = 0instead.dot,matrixPower,transposeandtracegive products, powers, transposes and traces, proved by kernel evaluation. A determinant with variables, such as Vandermonde's, goes in as a goal forcas. See the guide. -
Eigenvalues and positive definiteness.
#cas [eigenvalues]gives the exact eigenvalues with their multiplicities and proves that there are no others. For!![0, 1; 1, 1]it prints[1/2 - √5/2, 1/2 + √5/2], with a theorem about Mathlib'sspectrum ℝ. Eigenvalues of degree three or more, such as the roots of$x^3 - 2$ , are named by intervals.characteristicPolynomialprovesA.charpoly = p, andeigenvectorsproves a basis of every eigenspace, irrational eigenvalues included.positiveDefiniteprovesMatrix.PosDeffrom an exact$L D L^T$ factorization with positive pivots, or its negation from a rational$x \ne 0$ with$x^T A x \le 0$ or an entry that breaks the symmetry. For a symmetric matrix,eigenvalueBoundsproves sharp decimal bounds$c|x|^2 \le x^T A x \le \mu|x|^2$ for every$x$ , to 6 places or(digits := d). See the guide.
-
Derivatives and extrema.
#cas [derive x] eprints the derivative and proves a theorem about Mathlib'sHasDerivAt, with each condition it needs as a hypothesis, such as$2x + 2 > 0$ forsqrt (2 * x + 2).#cas [grad x, y] eproves aHasGradientAttheorem and each partial derivative on its own. In a proof,casprovesderiv,HasDerivAt,iteratedDerivand regularity goals such asContDiffandAnalyticAt, and aHasDerivAttheorem tagged@[cas_deriv]teaches it the derivative of your own function.#cas [minimize x] pgives the minimum of a polynomial in one variable, and#cas [minimize x in [a, b]] pits minimum on an interval, with a theorem that no value is smaller.maximizedoes the same for the maximum. The extremum is exact when a rational point attains it, and otherwise the theorem encloses its value. See the calculus guide. -
Integrals.
#cas [integrate x] efinds an antiderivativeF, checks it by differentiation, and proves∫ x in a..b, e = F b - F afor Mathlib's interval integral on every interval where the printed conditions hold. For1 / (x * log x)the answer is$\log(\log x)$ , under$x \neq 0$ and$\log x \neq 0$ .integratecovers substitution, rational functions, integration by parts, polynomials times exponentials, sines and cosines, rational functions of$\sin x$ and$\cos x$ , and Gaussians, which give SymLean'sCAS.erf. It does not factor a general denominator, so1 / (x ^ 3 - 1)is refused. In#cas [integrate x in [a, b]] ean end may be∞or-∞, and the theorem then states integrability too. In a proof,casproves definite and improper integrals, andcas [integrate primitive := F]checks a primitive you already have. See the integrate page. -
Series and limits.
#cas [series x a n] egives the Taylor polynomial of degreenat a rational pointa, with a theorem that the remainder is little-o of$(x - a)^n$ in Mathlib's=o[𝓝 a]. The coefficients are exact, so each function must sit where its value is rational, such aslogat$1$ , and the order is at most 12. A quotient with a pole atagets a Laurent series:#cas [series x 0 3] (1 / sin x)gives$1/x + x/6 + 7x^3/360 + o(x^3)$ .#cas [limit x → a] eproves aFilter.Tendstotheorem at a rational point, alsofrom aboveorfrom below, and at∞and-∞. A vanishing denominator is handled as with l'Hôpital's rule, and#cas [limit x → ∞] (sqrt (x^2 + 3 * x) - x)gives$3/2$ by comparing growth rates.casproves these limits but not the little-o statements, which you take as hypotheses. See the series and limits guide.
-
Sums and products.
#cas [sum k a n]gives the closed form of∑ k ∈ Finset.Icc a nand proves it for every$n \ge a - 1$ by induction. It takes polynomials, geometric terms and their products, and, by Gosper's algorithm, terms$c^k R(k)$ with a rational function$R$ and$c > 0$ :#cas [sum k 1 n] (1 / (k * (k + 1)))gives$n/(n + 1)$ , and$\sum 1/k$ has no such closed form.#cas [product k a n]does the same for a constant times powers of linear factors$k + s$ with integer$s$ , and in a proofcasproves both kinds of closed form when$a$ is 0 or 1. A numeral upper bound gives the exact value of a sum.#cas [sum k a ∞]sums series of polynomials times$r^k$ with$|r| < 1$ , and of$c/k^{2m}$ , with aHasSumtheorem that also says that the series converges:#cas [sum k 1 ∞] (1/k^2)gives$\pi^2/6$ . A summand with a parameter is refused. See the guide. -
Linear recurrences.
#cas [rsolve a n]gives the general solution of a linear recurrence with constant rational coefficients and proves that every solution has this form. When the right side has terms$c n^j r^n$ , we find a particular solution by undetermined coefficients. With initial values you get the only solution with those values. For#cas [rsolve a n, a 0 = 0, a 1 = 1] (a (n + 2) = a (n + 1) + a n), the theorem says that a sequencea : ℕ → ℝhas this recurrence and these values exactly when it is Binet's formula. Rational roots and the roots from the quadratic formula are exact, and the other characteristic roots, such as the plastic number of the Padovan numbers, are kernel-checked enclosures. In a proof,casdoes not prove these statements, but the closed form follows from the recurrence by induction. Seersolve. -
Number theory. You can work with divisors, divisor sums and Euler's totient, modular powers
and inverses, Bézout coefficients, simultaneous congruences, Jacobi symbols, digits in any base,
continued fractions, binomial coefficients, factorials and Fibonacci numbers. Each answer is a
theorem about Mathlib's definitions, such as
Nat.divisors,Nat.ModEq,ZModorNat.digits.#cas [chineseRemainder] ([2, 3, 2], [3, 5, 7])proves that the solutions are exactly the numbers$23 + 105k$ , and the moduli need not be coprime. When two congruences contradict each other, or a number has no inverse, the theorem says so. In a proof,casproves equations likeNat.totient 36 = 12.powerModuses repeated squaring, so its proof grows with the number of digits of the exponent.#casdoes not compute prime factorizations or test primality. See the guide.
-
Differential equations.
#cas [dsolve y x]solves a linear equation and proves that the printed family is exactly the set of solutions. With initial values,#cas [dsolve y x, y 0 = 1, y' 0 = 0] (y'' + y = 0)proves that$\cos x$ is the only solution. Any order works with rational constant coefficients, and in first order,y' + p * y = q,pandqmay also depend on$x$ or on parameters. A condition the family needs, such as$k + 2 \neq 0$ fory' + k * y = exp (2 * x), is a hypothesis of the theorem. Without a closed form,#cas [ndsolve y t in [t₀, T], y t₀ = y₀] (y' = f)proves that the solution exists and is unique on$[t_0, T]$ and encloses it at$T$ , or at the times inat [τ₁, …]. With(digits := d)each enclosure has width at most$10^{-d}$ .fis a polynomial of degree at most 4 intand iny. See the guide. -
Transforms and Fourier series.
#cas [laplace t s]transforms sums of polynomial, exponential, trigonometric and hyperbolic terms and proves, for every$s$ above a printed bound, that Mathlib's integral of$e^{-st} f(t)$ over$t > 0$ converges and equals the printed rational function.#cas [inverseLaplace s t] (1 / (s ^ 2 + 4))gives$\tfrac{1}{2} \sin 2t$ and proves that its transform is$1/(s^2 + 4)$ for$s > 0$ . Mathlib has no uniqueness theorem for the Laplace transform, so the theorem does not say this inverse is the only one.fourierTransformtakes Gaussians, in Mathlib's convention.fourier,fourierSinandfourierCosgive the coefficients of Fourier series on$[-\pi, \pi]$ and of sine and cosine series on$[0, L]$ as exact functions of$n$ , proved for every$n \ge 1$ . In a proof,casproves the integral behind one coefficient. See the guide. -
Special functions. The exact values of
gamma,zetaandBernoulliBcome with theorems about Mathlib'sReal.Gamma,riemannZetaandbernoulli.#cas (gamma (5/2))provesReal.Gamma (5 / 2) = 3 * √Real.pi / 4, and so doescasin a proof.zetatakes even positive integers and nonpositive ones, andBernoulliBgives Bernoulli numbers and polynomials with Mathlib's$B_1 = -\tfrac{1}{2}$ . Orthogonal polynomials print in monomials:ChebyshevT 5 xgives$16x^5 - 20x^3 + 5x$ , proved for Mathlib's polynomial in every commutative ring, andHermiteHandHermiteHeare the physicists' and the probabilists' Hermite polynomials.erfandBesselJgive only enclosures, of width at most$10^{-d}$ with[N d]. The Mathlib we build on has no error function, soerfis our ownCAS.erf, defined by the Gaussian integral. See the guide.
-
Digits and enclosures.
#cas [N d] easks for the firstdsignificant digits of a closed real expression, with a theorem that every printed digit is right: for$\sqrt 2$ to six digits it is$1.41421 \le \sqrt 2 < 1.41422$ . If the computation encloses the value but can't settle all the digits, it proves a decimal enclosure instead.#cas [enclose x in [a, b], y in [c, d]] eprints an interval that holds every value ofeon the box and proves it, along with an upper bound, a bound on the absolute value and a center with a radius. A box has rational endpoints and at most 8 coordinates by default, and every subexpression has to be defined on all of it.nintegrategives an integral to 6 places with a proved error of at most$10^{-6}$ ,findRootproves that an interval of half-width at most$10^{-10}$ around the printed root holds exactly one root, andeigenvalueBoundsproves sharp bounds on the extreme eigenvalues of a symmetric rational matrix. See the numerics guide. -
The
cegatactic. In a proof,cegaproves numerical bounds with a certificate that the kernel checks:Real.sin x ≤ 0.85from0 ≤ xandx ≤ 1,Real.exp 1 ≤ 2.72, or(∫ x in (0 : ℝ)..1, Real.exp (-x ^ 2)) ≤ 3 / 4, whose integrand has no elementary antiderivative. A goal can be a one-sided, two-sided or absolute bound,f ∈ Set.Icc a b,f ≤ gor a conjunction of these, and hypotheses such asa ≤ xandx ≤ b,x ∈ Set.Icc a bor|x| ≤ r, with rational endpoints, give the box. It also provesEnclosedOn f s lo hi, which says$\mathrm{lo} \le f(x) \le \mathrm{hi}$ for every$x \in s$ , and the similarBoundOn,ApproxOnandResidualBound, andcega using creuses such a certificate on a smaller domain or with wider bounds without evaluating the function again. A real inequality that the box route misses goes to FloatLib'sinterval, which also handles finite sums, and trigonometric polynomials in one variable with no bounds on the variable.(depth := n),(prec := n)and(panels := n)tune one call. See thecegareference. -
Exact rationals or IEEE floats.
cegacomputes its enclosures with exact rationals unless you ask for IEEE floats:cega [use_floats]for binary64,cega (arith := binary128)for another format, or oneweak.cega.arithmeticline in your lakefile for a whole build. At each operation FloatLib computes a rational enclosure in the kernel and rounds its ends outward into the format. The theorem doesn't change: it is still about real numbers, with the same three axioms. The float query has the exact planner's monotonicity faces and centered forms, so a bound attained where the format computes the expression exactly, such as$1 + 2y \le e^{2y}$ at$y = 0$ , is proved. A float call that can't prove its goal tries binary128 and binary256, then fails, names the format and the reason, and computes with rationals in its place only when you setcega.floatFallback. A goal proved in another arithmetic says so in an info message. With floats on,cegacomputes no integrals. Exact rationals take less kernel time in our measurements, so floats aren't for speed: they give you the computation in an IEEE format, with certified ends of a fixed size. See Certificates. -
Certificates of any size.
CAS.Cert, for tables and meshes, isn't part ofimport CAS. You write a condition once, in a small language,Cond: comparisons,and,or, a loopall nandonIccfor every point of a cell. Its test runs on balls, and byCond.holds_of_checka pass proves the condition for all real data in the balls.cert_condwrites the condition for a goal without data, such as$e^{xy} + x^2 \le 4$ on$[0, 1]^2$ . The size of the data changes only who runs the test: the kernel, in one module or in many (cert_shard,cert_aggregate), compiled code undercega.nativeCertificates, which also trusts Lean's compiler, or a program that reads files, whose runRun.Ok m familyis a hypothesis. Data too big to state enter the theorem asNonempty Tfor a certificate typeT, which a verified checker supplies from any input it accepts. See the guide.
- The
castactic. State the goal in Mathlib's terms and writecas. It proves identities, derivatives and regularity (HasDerivAt,iteratedDeriv,ContDiff,AnalyticAt), interval and improper integrals, and limits written with Mathlib's filters. It also proves closed forms of finite sums, ideal membership, determinants of matrix literals, the sign of a polynomial, counts of real roots and bounds on a box. Every route ends in a proof that Lean checks against your goal. A condition such asx ≠ 0comes from a hypothesis or fromcas using h, and a missing one is reported, never added.cas using [h₁, h₂]adds facts, andcas [l₁, l₂]passes lemmas or definitions to unfold.cas [integrate primitive := F]checks a primitive you supply,@[cas_deriv]teachescasa derivative, andcas_nfnormalizes a goal or a hypothesis. See the tactics guide. - Keeping the call that worked. While a proof takes shape, write
cas?orcega?. Each proves the goal ascasorcegawould, runs the call it suggests on the original goal before showing it, and names the route. The suggestion can be another tactic: after the box route,cas?proposescega. Forx * (1 - x) ≤ 1 / 4on[0, 1],cega?suggestscega [enclose x in [0, 1]] (x * (1 - x)), so the proof shows what was enclosed and where. If you start from a calculation,set_option cas.suggest trueturns a#casreport into anexampleto paste in place of the command. For#cas [derive x] (tan x)it is aHasDerivAtstatement with the hypothesisReal.cos x ≠ 0, proved bycas. Lean checks it where the command is, so a copy in another file can elaborate differently. See thecas?reference. - When a call refuses. A call that fails leaves the goal as it was, and its message names what
was missing and, where there is one, the call or setting to try. A false or too tight bound on a
box is refused with the value that the query certified and, in case the bound is true, a call
such as
cega (depth := 4). We'd rather have a call stop than hang, so calls run within budgets, and the message names the budget a call hit, such ascas.grindHeartbeatsorcega.maxDimension. Trace classes such astrace.cas.fallbackandtrace.cega.statedshow the steps of a route. The options page lists the budgets with their defaults.
-
Other computer algebra systems. The optional library
CASOracle, built on DSLean, lets SymPy, SageMath, Maxima, Giac, Singular, PARI/GP, FLINT and Gappa propose answers, and SymLean proves each one or refuses it. You name the system in the mode, so#cas [factor, oracle := sympy] (x ^ 4 + 4)asks SymPy and proves$x^4 + 4 = (x^2 - 2x + 2)(x^2 + 2x + 2)$ for every real$x$ . SymPy, SageMath and Giac propose antiderivatives, solutions of equations and differential equations, and closed forms of sums, which SymLean checks by differentiating, by substitution and by induction. SymPy and SageMath also propose factorizations, Gröbner bases and decimal integrals and eigenvalues, and SymPy decimal roots and sums of squares. Maxima proposes antiderivatives and factorizations, Singular factorizations and Gröbner bases, PARI/GP and FLINT factorizations (PARI/GP's in one variable) and decimal roots of polynomials, integrals and eigenvalues, and Gappa bounds on a box, whichcegaproves again. What we can't check, such as whether the factors are irreducible or a list of solutions is complete, is a hint outside the theorem, and a missing program or a run pastcas.oracle.timeout(two minutes by default) is a refusal with the reason. The oracle tests run with the real programs and with programs that answer wrongly, which SymLean refuses. Build the library withlake -R -Koracle=on build CASOracle. Its files aren't modules, like DSLean's, so amodulecan't import it. The oracle page has the setup and the versions that passed. -
Oracles in proofs.
cas [oracle := sympy]proves a definite integral, an equation that follows from the hypotheses, a membership in an ideal or an inequality between polynomials, and suggests a proof to keep that doesn't need SymPy. For an equation the suggestion is alinear_combination, which Mathlib'spolyrithfound until its Sage server was shut down. Fromh1 : x * y = 1andh2 : x = y, the tactic provesx ^ 2 = 1and suggestslinear_combination h1 + x * h2. SageMath and Singular find these too. For an integral the suggestion iscas [integrate primitive := F], with an antiderivative from SymPy, SageMath, Maxima or Giac. For an inequality it is a script that checks a sum of squares withringandpositivity. A membership, and an inequality whose printed script doesn't check, keep the call. See the oracle guide. -
SymLean as a library.
import CASbrings in the calculator and the tactics, and a file can import less, such asCAS.ExactTacticfor derivatives withcas. The certificates under the tactics conclude ordinary propositions, such asEnclosedOn f s lo hi, so you use what they prove like any other theorem. A library that lists the facetSymLean.embeddedInputsin itsneedshas its literalinclude_strinputs tracked, so editing a table rebuilds its modules. The library guide describes the forms the build rejects and the cases outside the check. -
Extending the tactics. You extend the tactics through registries, and an entry adds no
assumption, since a registry only chooses which theorem to apply.
@[cas_deriv]adds aHasDerivAttheorem to the derivative route ofcas, socasdifferentiates your own functions, with the theorem's premises proved at each use.@[cas_route name]adds a route ofcasandcas?, with an optional priority and goal filter, or a backend of the#casmodename.CAS.ExactTactic.routeOrderlists the routes in the ordercastries them.@[cega_carrier route projection]registers a type of attempts that plaincegathen tries, and a package with its own Euclidean derivative operators registers a backend with@[cas_derivative_backend]. See the library guide.
Computer algebra systems sometimes give wrong answers. One reason is that an answer only holds under
a condition they don't print. Richard Fateman's review of Mathematica (J. Symbolic Computation 13(5),
1992) reports that Integrate[1/x^2, {x, -1, 1}]
gave integrate(sqrt(2 - x)*sqrt(1/(2 - x)), (x, 0, 1)), although the integrand
is
SymLean gives none of these wrong answers. Interestingly, on Fateman's integral our own search
proposes #cas [integrate x in [-1, 1]] (1 / x ^ 2) refuses:
error: `cas` did not prove the value -2 of the integral: it could not prove that the conditions of the primitive -(1/x) hold on the interval (x ≠ 0). The endpoint calculation needs a primitive valid throughout the interval.
On SymPy's integrand our search finds no antiderivative and says so. For the matrix from Sage's
report, SymLean returns row operations
A theorem from SymLean relies on:
- its statement: the one you wrote, or the one the
#casreport prints; - the Mathlib definitions it mentions, such as
Real.arctan, and in a few answers SymLean's own short definitions, such asCAS.erf; - Lean's kernel, with the three standard axioms
propext,Classical.choiceandQuot.sound.
A report prints its statement through Lean's pretty printer, which writes a cast as ↑n without its
target type, so two different statements can look the same. When that matters, I'd write the
statement as an example in your own file and prove it there. set_option cas.suggest true offers
that example, ready to paste.
One option, off by default, trusts more: with cega.nativeCertificates, cega [fast] and the
certificate commands check large finite certificates with compiled code, and #print axioms then
shows the native axioms involved. TRUST.md lists everything a proof trusts with the reason
for each item, and the trust tutorial
goes through both profiles.
- A refusal proves nothing. A search can miss an answer that exists, and SymLean does not compute everything Mathematica can.
- An answer is correct, but complete only when the theorem says so, as with
roots.findRootproves one root and its uniqueness near the printed value. - A certified bound on a residual is not a bound on an error. It becomes one only through a stability theorem that your own proof supplies.
- Every answer pays for a proof. Checking large finite tables in the kernel can be slow. The certificate guide explains how to split the work across modules or opt into compiled evaluation.
We'd love help with SymLean, and CONTRIBUTING.md says where to start. Please
follow Mathlib's conventions and keep every proof complete. lake exe cache get and then
lake build check every proof, the examples included, with warnings as errors. The library
guide lists the test scripts,
scripts/dups.sh and the site build to run on a change.
Letting an untrusted search propose and the prover check is an old idea: Harrison and Théry combined HOL with Maple this way (J. Automated Reasoning 21, 1998). The closest project in Lean is Hex, the Lean FRO's really nice library of verified computational algebra, which proves factorization, determinants and primality in Lean. On Lean 4.35, SymLean called Hex for Berlekamp–Zassenhaus factoring, Bareiss determinants and primality certificates. That route comes back as soon as Hex is released for Lean 4.36, and we're in touch with its developers. We build on earlier work in HOL Light, Isabelle, Coq and Rocq, and Lean, and Why SymLean cites it.
SymLean is written at Caltech by Robert Joseph George, Changhe Yang, Peicong Song, Thomas Y. Hou and Anima Anandkumar. Everything here is built on Mathlib (The mathlib Community, "The Lean Mathematical Library", CPP 2020, https://doi.org/10.1145/3372885.3373824). The certified numerics use FloatLib by Robert Joseph George, Will Adkisson and Anima Anandkumar. Many thanks to taterowney and the DSLean contributors for DSLean, which is under CC BY 4.0.
SymLean is released under the Apache License 2.0; see LICENSE.