Guide
Algebra
Simplifying, expanding, factoring and combining fractions, each with a theorem about real numbers and its conditions.
Most of the algebra I do on paper is moving an expression from one form to another: simplifying it, multiplying it out, factoring it, collecting the powers of one variable, or putting fractions over one denominator and splitting them apart again. These modes make those moves. Each answer comes with a theorem that the new form equals the input for all real values of the variables, under the conditions the rewriting needs.
The conditions come from division. Lean’s division is total (), so is false at , where the left side is . On paper I cancel that factor without a second thought. Here the modes that cancel or combine fractions print the denominators that must be nonzero, and the theorem has them as hypotheses.
Simplifying
simplifySimplifies a real expression by checked rewrites, with the conditions under which the result equals it.fullSimplifyTries many forms of a real expression and gives the simplest one that is proved equal to it, with the conditions the identity needs.
Expanding and factoring
expandMultiplies out a polynomial, with a theorem that the expansion equals the input for all real values.factorFactors a polynomial with rational coefficients, with a theorem that the product equals the input.collectWrites a polynomial as a sum of powers of one variable, with coefficients in the other variables, and proves that the two are equal.trigExpandExpands sines and cosines of sums, differences and double angles, with a theorem about Mathlib’s sine and cosine.
Rational functions
togetherWrites a rational expression as one fraction in lowest terms, with the conditions under which they agree.cancelCancels common factors in each summand of a rational expression, with the conditions under which the result equals the input.apartWrites a rational function of one variable as a polynomial plus partial fractions, with the conditions of the identity.numeratorGives the numerator of a rational expression brought to one fraction, with the conditions of the identity.denominatorGives the factored denominator of a rational expression brought to one fraction, with the conditions of the identity.
A factorization needs no conditions at all. This one is an identity for all real and , proved by Mathlib’s tactic ring, so the product is right whatever the factors turn out to be:
#cas [factor] (x^3*y - x*y^3)
x*y*(x - y)*(x + y)Checked by Lean’s kernel: Identity with the factored homogeneous polynomial
∀ (x y : ℝ), x ^ 3 * y - x * y ^ 3 = x * y * (x - y) * (x + y)
The certificate: 1 checked step
Identity with the factored homogeneous polynomial
∀ (x y : ℝ), x ^ 3 * y - x * y ^ 3 = x * y * (x - y) * (x + y)
The computation
Ranked candidates (proposals, not proof)
factored homogeneous polynomial: x*y*(x - y)*(x + y) [leafCount 11, conditions 0] factored homogeneous polynomial: -(y*x*(y - x)*(y + x)) [leafCount 13, conditions 0] input: x^3*y - x*y^3 [leafCount 11, conditions 0]
Adding fractions is where the conditions show up. Here the sum goes over one denominator, and the theorem holds where the divisors of the input are nonzero. They are taken as you wrote them, so the report lists and :
#cas [together] (1/(x^2-1) + 1/(x-1))
common denominator
(x + 2)/((x - 1)*(x + 1))- Input (rational function)
(1/(x^2-1) + 1/(x-1))- Conditions
- ,
Checked by Lean’s kernel: Identity with the common-denominator form
∀ (x : ℝ), x ^ 2 - 1 ≠ 0 → x - 1 ≠ 0 → 1 / (x ^ 2 - 1) + 1 / (x - 1) = (x + 2) / ((x - 1) * (x + 1))
The certificate: 1 checked step
Identity with the common-denominator form
∀ (x : ℝ), x ^ 2 - 1 ≠ 0 → x - 1 ≠ 0 → 1 / (x ^ 2 - 1) + 1 / (x - 1) = (x + 2) / ((x - 1) * (x + 1))
Each mode has its limits, and I’d rather you meet them here than in the middle of a proof. factor finds rational roots, perfect powers and homogeneous forms in two variables. A factor of degree two or more that’s left over is printed whole, and the report doesn’t claim it’s irreducible, so stays in one piece although it factors over . together, cancel and apart take the field operations and natural powers with polynomial divisors, and apart works in one variable. When there’s a square root, a logarithm or a sine in the expression, simplify and fullSimplify are the modes to use. trigExpand applies the addition and double-angle formulas and nothing else.
The same identities, written in Mathlib’s notation, are goals that the tactic cas proves, with the conditions as hypotheses.
