Mode of #cas
fullSimplify
Tries many forms of a real expression and gives the simplest one that is proved equal to it, with the conditions the identity needs.
#cas [fullSimplify] eleafCount that it proves equal to e, with the conditions under which it holds.#cas [fullSimplify c] eleafCount, depth and length.An expression usually has many equivalent forms, and fullSimplify looks for the simplest one. It gathers candidate forms, ranks them by size, and reports the simplest one whose identity with the input the kernel accepts. It plays the part of Mathematica’s FullSimplify with LeafCount, except that the answer is a theorem.
It works the way the rest of SymLean does: the search only proposes. A candidate that can’t be proved costs some time and nothing else, and the next one in the ranking is tried. So a bad guess can make the command slower, but it can’t make the answer wrong.
Examples (15)#
Basic Examples (3)
A polynomial that is a fifth power. The factored form counts 5, the input 27:
#cas [fullSimplify] (x^5 + 5*x^4 + 10*x^3 + 10*x^2 + 5*x + 1)
(x + 1)^5Checked by Lean’s kernel: Identity with the factored polynomial
∀ (x : ℝ), x ^ 5 + 5 * x ^ 4 + 10 * x ^ 3 + 10 * x ^ 2 + 5 * x + 1 = (x + 1) ^ 5
The certificate: 1 checked step
Identity with the factored polynomial
∀ (x : ℝ), x ^ 5 + 5 * x ^ 4 + 10 * x ^ 3 + 10 * x ^ 2 + 5 * x + 1 = (x + 1) ^ 5
The computation
Ranked candidates (proposals, not proof)
factored polynomial: (x + 1)^5 [leafCount 5, conditions 0] input: x^5 + 5*x^4 + 10*x^3 + 10*x^2 + 5*x + 1 [leafCount 27, conditions 0] exact passes: x^5 + 5*(x^4 + 2*(x^3 + x^2 + 1/2*(x + 1/5))) [leafCount 29, conditions 0]
Mathlib’s logarithm is , with , so the product rule needs only and , not positivity:
#cas [fullSimplify] (log (x*y) - log x - log y)
0- Conditions
- ,
Checked by Lean’s kernel: Identity with the logarithm expansion and simplification
∀ (x y : ℝ), x ≠ 0 → y ≠ 0 → Real.log (x * y) - Real.log x - Real.log y = 0
The certificate: 1 checked step
Identity with the logarithm expansion and simplification
∀ (x y : ℝ), x ≠ 0 → y ≠ 0 → Real.log (x * y) - Real.log x - Real.log y = 0
The computation
Ranked candidates (proposals, not proof)
logarithm expansion and simplification: 0 [leafCount 1, conditions 2] input: log(x*y) - log(x) - log(y) [leafCount 10, conditions 0] configured simplification: -log(x) - log(y) + log(x*y) [leafCount 12, conditions 0] exact passes: log(x*y) + -log(x) - log(y) [leafCount 12, conditions 0]
The square root of a perfect square is an absolute value, for every :
#cas [fullSimplify] (sqrt (x^2 + 2*x + 1))
|x + 1|Checked by Lean’s kernel: Identity with the square root of a square
∀ (x : ℝ), √(x ^ 2 + 2 * x + 1) = |x + 1|
The certificate: 1 checked step
Identity with the square root of a square
∀ (x : ℝ), √(x ^ 2 + 2 * x + 1) = |x + 1|
The computation
Ranked candidates (proposals, not proof)
square root of a square: |x + 1| [leafCount 4, conditions 0] input: sqrt(x^2 + 2*x + 1) [leafCount 10, conditions 0] configured simplification: sqrt(x^2 + 2*(x + 1/2)) [leafCount 12, conditions 0]
Scope (4)
Trigonometric identities that reduce to :
#cas [fullSimplify] (sin (2*x) - 2*sin x*cos x)
0Checked by Lean’s kernel: Identity with the trigonometric expansion and simplification
∀ (x : ℝ), Real.sin (2 * x) - 2 * Real.sin x * Real.cos x = 0
The certificate: 1 checked step
Identity with the trigonometric expansion and simplification
∀ (x : ℝ), Real.sin (2 * x) - 2 * Real.sin x * Real.cos x = 0
The computation
Ranked candidates (proposals, not proof)
trigonometric expansion and simplification: 0 [leafCount 1, conditions 0] input: sin(2*x) - 2*sin(x)*cos(x) [leafCount 12, conditions 0] configured simplification: sin(2*x) - 2*(sin(x)*cos(x)) [leafCount 12, conditions 0] trigonometric expansion: 2*sin(x)*cos(x) - 2*sin(x)*cos(x) [leafCount 15, conditions 0]
#cas [fullSimplify] (cos x ^ 2 - sin x ^ 2 - cos (2*x))
0Checked by Lean’s kernel: Identity with the trigonometric expansion and simplification
∀ (x : ℝ), Real.cos x ^ 2 - Real.sin x ^ 2 - Real.cos (2 * x) = 0
The certificate: 1 checked step
Identity with the trigonometric expansion and simplification
∀ (x : ℝ), Real.cos x ^ 2 - Real.sin x ^ 2 - Real.cos (2 * x) = 0
The computation
Ranked candidates (proposals, not proof)
trigonometric expansion and simplification: 0 [leafCount 1, conditions 0] configured simplification: 1 + -2*sin(x)^2 - cos(2*x) [leafCount 13, conditions 0] input: cos(x)^2 - sin(x)^2 - cos(2*x) [leafCount 14, conditions 0] exact passes: cos(x)^2 + -sin(x)^2 - cos(2*x) [leafCount 16, conditions 0] trigonometric expansion: cos(x)^2 - sin(x)^2 - (cos(x)^2 - sin(x)^2) [leafCount 19, conditions 0]
A quotient that cancels, with its condition:
#cas [fullSimplify] ((x^4 - 1)/(x^2 - 1))
x^2 + 1- Conditions
Checked by Lean’s kernel: Identity with the configured simplification
∀ (x : ℝ), x ^ 2 - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
The certificate: 1 checked step
Identity with the configured simplification
∀ (x : ℝ), x ^ 2 - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
The computation
Ranked candidates (proposals, not proof)
configured simplification: x^2 + 1 [leafCount 5, conditions 1] input: (x^4 - 1)/(x^2 - 1) [leafCount 11, conditions 0]
Several variables:
#cas [fullSimplify] (x^3 + 3*x^2*y + 3*x*y^2 + y^3)
(x + y)^3Checked by Lean’s kernel: Identity with the factored homogeneous polynomial
∀ (x y : ℝ), x ^ 3 + 3 * x ^ 2 * y + 3 * x * y ^ 2 + y ^ 3 = (x + y) ^ 3
The certificate: 1 checked step
Identity with the factored homogeneous polynomial
∀ (x y : ℝ), x ^ 3 + 3 * x ^ 2 * y + 3 * x * y ^ 2 + y ^ 3 = (x + y) ^ 3
The computation
Ranked candidates (proposals, not proof)
factored homogeneous polynomial: (x + y)^3 [leafCount 5, conditions 0] factored homogeneous polynomial: (y + x)^3 [leafCount 5, conditions 0] exact passes: x^3 + y*(3*x^2 + 3*(x*y) + y^2) [leafCount 21, conditions 0] input: x^3 + 3*x^2*y + 3*x*y^2 + y^3 [leafCount 23, conditions 0] configured simplification: x^3 + 3*(x^2*y) + 3*(x*y^2) + y^3 [leafCount 23, conditions 0]
In Mathlib for , and , so getting back needs :
#cas [fullSimplify] (exp (log x))
x- Conditions
Checked by Lean’s kernel: Identity with the configured simplification
∀ (x : ℝ), 0 < x → Real.exp (Real.log x) = x
The certificate: 1 checked step
Identity with the configured simplification
∀ (x : ℝ), 0 < x → Real.exp (Real.log x) = x
The computation
Ranked candidates (proposals, not proof)
configured simplification: x [leafCount 1, conditions 1] input: exp(log(x)) [leafCount 3, conditions 0]
Options (1)
With depth, the depth of the expression tree decides:
#cas [fullSimplify depth] (x^2 + 2*x + 1)
(x + 1)^2Checked by Lean’s kernel: Identity with the factored polynomial
∀ (x : ℝ), x ^ 2 + 2 * x + 1 = (x + 1) ^ 2
The certificate: 1 checked step
Identity with the factored polynomial
∀ (x : ℝ), x ^ 2 + 2 * x + 1 = (x + 1) ^ 2
The computation
Ranked candidates (proposals, not proof)
factored polynomial: (x + 1)^2 [depth 3, conditions 0] input: x^2 + 2*x + 1 [depth 4, conditions 0] exact passes: x^2 + 2*(x + 1/2) [depth 4, conditions 0]
#cas [fullSimplify depth] (sin (2*x) - 2*sin x*cos x)
0Checked by Lean’s kernel: Identity with the trigonometric expansion and simplification
∀ (x : ℝ), Real.sin (2 * x) - 2 * Real.sin x * Real.cos x = 0
The certificate: 1 checked step
Identity with the trigonometric expansion and simplification
∀ (x : ℝ), Real.sin (2 * x) - 2 * Real.sin x * Real.cos x = 0
The computation
Ranked candidates (proposals, not proof)
trigonometric expansion and simplification: 0 [depth 1, conditions 0] input: sin(2*x) - 2*sin(x)*cos(x) [depth 5, conditions 0] configured simplification: sin(2*x) - 2*(sin(x)*cos(x)) [depth 5, conditions 0] trigonometric expansion: 2*sin(x)*cos(x) - 2*sin(x)*cos(x) [depth 5, conditions 0]
Applications (2)
The logarithm identity as a theorem, with the printed conditions as hypotheses. Only the three standard axioms are used:
theorem log_mul_sub_logs (x y : ℝ) (hx : x ≠ 0) (hy : y ≠ 0) : Real.log (x * y) - Real.log x - Real.log y = 0 := by cas #print axioms log_mul_sub_logs
log_mul_sub_logs depends on the axioms propext, Classical.choice, Quot.sound.
Away from the logarithm sees , and cas proves the identity with the absolute value:
example (x : ℝ) (hx : x ≠ 0) : Real.exp (3 * Real.log x) = |x| ^ 3 := by cas
Lean accepts the proof.
Properties and Relations (1)
fullSimplify keeps , which counts 5, over , which counts 9. factor gives the factored form whatever its size:
#cas [fullSimplify] (x^3 - x)
x^3 - xChecked by Lean’s kernel: Identity with the input
∀ (x : ℝ), x ^ 3 - x = x ^ 3 - x
The certificate: 1 checked step
Identity with the input
∀ (x : ℝ), x ^ 3 - x = x ^ 3 - x
The computation
Ranked candidates (proposals, not proof)
input: x^3 - x [leafCount 5, conditions 0] exact passes: x*(x^2 - 1) [leafCount 7, conditions 0] factored polynomial: x*(x - 1)*(x + 1) [leafCount 9, conditions 0]
#cas [factor] (x ^ 3 - x)
x*(x - 1)*(x + 1)Checked by Lean’s kernel: Identity with the factored polynomial
∀ (x : ℝ), x ^ 3 - x = x * (x - 1) * (x + 1)
The certificate: 1 checked step
Identity with the factored polynomial
∀ (x : ℝ), x ^ 3 - x = x * (x - 1) * (x + 1)
The computation
Ranked candidates (proposals, not proof)
factored polynomial: x*(x - 1)*(x + 1) [leafCount 9, conditions 0] input: x^3 - x [leafCount 5, conditions 0]
Possible Issues (3)
The complexity function must be one of the three:
#cas [fullSimplify size] (x + 1)
Error
unknown complexity function size; use leafCount, depth or length
The tactic cas does not prove an identity with a square root without sign hypotheses, even one that fullSimplify proves for every . Its message lists the candidate conditions:
example (x : ℝ) : Real.sqrt (x ^ 2 + 2 * x + 1) = |x + 1| := by cas
Error
cas could not close this ordinary arithmetic goal. This goal contains branch-sensitive operations and may need nonnegative or positive square-root hypotheses. Put those facts in the local context; pass one explicit fact as `cas using h` when needed. The corresponding `#cas [simplify]` report shows the exact generated conditions. Detected candidate conditions: 0 ≤ x ^ 2 + 2 * x + 1.
The rest of the message
Polynomial equation route:
`grind` failed
case grind
x : ℝ
h : ¬√(x * (x + 2) + 1) = |x + 1|
⊢ False
[grind] Goal diagnostics
[facts] Asserted facts
[prop] ¬√(x * (x + 2) + 1) = |x + 1|
[eqc] False propositions
[prop] √(x * (x + 2) + 1) = |x + 1|
[ematch] E-matching patterns
[thm] Real.sq_sqrt': [Real.sqrt #0]
[thm] Real.sqrt_one: [Real.sqrt `[1]]
[thm] Real.sqrt_zero: [Real.sqrt `[0]]
[thm] abs_mul: [@abs #5 _ _ (@HMul.hMul _ _ _ _ #1 #0)]
[thm] abs.eq_1: [@abs #3 #2 #1 #0]
[limits] Thresholds reached
[limit] maximum number of E-matching rounds has been reached, threshold: `(ematch := 0)`
[limit] maximum number of case-splits has been reached, threshold: `(splits := 0)`
Checked identity route:
cas could not identify a side of the identity with its reflected form
Grind fallback:
`grind` failed (`set_option trace.cas.fallback true` shows its diagnostics)In a proof, Mathlib’s Real.sqrt_sq_eq_abs does it, the lemma behind the fullSimplify answer:
example (x : ℝ) : Real.sqrt (x ^ 2 + 2 * x + 1) = |x + 1| := by rw [show x ^ 2 + 2 * x + 1 = (x + 1) ^ 2 by ring] exact Real.sqrt_sq_eq_abs (x + 1)
Lean accepts the proof.
Neat Examples (1)
A quartic that is the square of a quadratic. The answer counts 7, while the full factorization would count 11:
#cas [fullSimplify] (x^4 - 2*x^2 + 1)
(x^2 - 1)^2Checked by Lean’s kernel: Identity with the perfect power
∀ (x : ℝ), x ^ 4 - 2 * x ^ 2 + 1 = (x ^ 2 - 1) ^ 2
The certificate: 1 checked step
Identity with the perfect power
∀ (x : ℝ), x ^ 4 - 2 * x ^ 2 + 1 = (x ^ 2 - 1) ^ 2
The computation
Ranked candidates (proposals, not proof)
perfect power: (x^2 - 1)^2 [leafCount 7, conditions 0] perfect power: ((x - 1)*(x + 1))^2 [leafCount 9, conditions 0] input: x^4 - 2*x^2 + 1 [leafCount 11, conditions 0] factored polynomial: (x - 1)^2*(x + 1)^2 [leafCount 11, conditions 0] exact passes: x^4 - 2*(x^2 - 1/2) [leafCount 13, conditions 0]
See Also
simplify · expand · factor · trigExpand · cas
