Tactic
cas_nf
Rewrites the real terms of a goal or a hypothesis to a normal form, with a checked proof of each rewrite.
cas_nfcas_nf at hat h ⊢ and at * choose locations as for simp.cas_nf using hconv => cas_nfcas_nf using h.cas closes a goal or leaves it alone. Sometimes I want something in between: the goal is not finished, but one quotient in it should cancel, or a hypothesis should look like the goal. cas_nf rewrites to a normal form and leaves the rest of the proof to me.
Examples (15)#
Basic Examples (3)
A polynomial identity becomes reflexive, and the goal closes:
example (x y : ℝ) : (x + y) ^ 2 = x ^ 2 + 2 * x * y + y ^ 2 := by cas_nf
Lean accepts the proof.
A hypothesis and the goal brought to the same form:
example (x y c : ℝ) (h : (x + y) ^ 2 ≤ c) : x ^ 2 + 2 * x * y + y ^ 2 ≤ c := by cas_nf at h ⊢ exact h
Lean accepts the proof.
A quotient that cancels, under a function you know nothing about, with the denominator condition passed by using:
example (F : ℝ → ℝ) (x y z : ℝ) (hden : x - y ≠ 0) (h : F (x + y) = z) : F ((x ^ 2 - y ^ 2) / (x - y)) = z := by cas_nf using hden exact h
Lean accepts the proof.
Scope (4)
The Pythagorean identity inside a hypothesis:
example (P : ℝ → Prop) (x : ℝ) (h : P (Real.sin x ^ 2 + Real.cos x ^ 2)) : P 1 := by cas_nf at h exact h
Lean accepts the proof.
The normal form of depends on what you know about :
example (P : ℝ → Prop) (x : ℝ) (hx : 0 < x) (h : P (Real.exp (Real.log x))) : P x := by cas_nf using hx at h exact h
Lean accepts the proof.
example (P : ℝ → Prop) (x : ℝ) (hx : x ≠ 0) (h : P (Real.exp (Real.log x))) : P |x| := by cas_nf using hx at h exact h
Lean accepts the proof.
example (P : ℝ → Prop) (x : ℝ) (hx : x < 0) (h : P (Real.exp (Real.log x))) : P (-x) := by cas_nf using hx at h exact h
Lean accepts the proof.
Square roots, with and without a sign condition:
example (P : ℝ → Prop) (x : ℝ) (hx : 0 ≤ x) (h : P (√x ^ 2)) : P x := by cas_nf using hx at h exact h
Lean accepts the proof.
example (P : ℝ → Prop) (x : ℝ) (h : P (√(x ^ 2))) : P |x| := by cas_nf at h exact h
Lean accepts the proof.
Two conditions at once:
example (P : ℝ → Prop) (F : ℝ → ℝ → ℝ) (x y z : ℝ) (hz : 0 < z) (hden : x - y ≠ 0) (h : P (F (Real.exp (Real.log z)) ((x ^ 2 - y ^ 2) / (x - y)))) : P (F z (x + y)) := by cas_nf using And.intro hz hden at h exact h
Lean accepts the proof.
Options (2)
In conv mode only the focused term changes. Here the first argument is rewritten and the second, the same term, is not:
example (P : ℝ → ℝ → Prop) (x y : ℝ) (h : P (x * y * 2 + x ^ 2 + y ^ 2) ((x + y) ^ 2)) : P ((x + y) ^ 2) ((x + y) ^ 2) := by conv => arg 1 cas_nf exact h
Lean accepts the proof.
cas_nf using h works under a binder too:
example (F : ℝ → ℝ) (hden : ∀ t, F t ≠ 0) : (fun t ↦ F t / F t) = (fun _ ↦ (1 : ℝ)) := by conv => lhs intro t cas_nf using hden t
Lean accepts the proof.
Applications (1)
A theorem whose proof is one normalization and one exact. Only the three standard axioms are used:
theorem square_le (x y c : ℝ) (h : (x + y) ^ 2 ≤ c) : x ^ 2 + 2 * x * y + y ^ 2 ≤ c := by cas_nf at h ⊢ exact h #print axioms square_le
square_le depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (2)
cancel shows the same cancellation as a #cas report, with its condition:
#cas [cancel] ((x ^ 2 - y ^ 2) / (x - y))
cancelled
x + y- Input (rational function)
((x ^ 2 - y ^ 2) / (x - y))- Conditions
Checked by Lean’s kernel: Identity with the cancelled form
∀ (x y : ℝ), x - y ≠ 0 → (x ^ 2 - y ^ 2) / (x - y) = x + y
The certificate: 1 checked step
Identity with the cancelled form
∀ (x y : ℝ), x - y ≠ 0 → (x ^ 2 - y ^ 2) / (x - y) = x + y
Lean’s division is total. cas_nf keeps that meaning, so is :
example (P : ℝ → Prop) (x : ℝ) (h : P (x / 0)) : P 0 := by cas_nf at h exact h
Lean accepts the proof.
Possible Issues (2)
cas_nf fails when it changes nothing. This goal is in normal form already, and exact h closes it:
example (P : ℝ → Prop) (x : ℝ) (h : P x) : P x := by cas_nf
Error
`cas_nf` made no progress on the goal
A cancellation needs its condition. Here is missing. The message says what kind of condition to supply and lists the missing one, written x + ↑(-1) ≠ 0:
example (P : ℝ → Prop) (x : ℝ) (h : P ((x ^ 2 - 1) / (x - 1))) : P (x + 1) := by cas_nf at h exact h
Error
cas_nf could not prove the real analytic domain conditions. A denominator or logarithm argument may need to be nonzero, a square-root argument may need to be positive, or an inverse-trigonometric argument may need to avoid a branch endpoint. Supply the relevant ordinary hypothesis with `cas_nf using h`. Unproved conditions: x + ↑(-1) ≠ 0
Neat Examples (1)
Arguments are normalized before equal atoms are collected, so becomes :
example (P : ℝ → Prop) (F : ℝ → ℝ) (x : ℝ) (h : P (F (x + 0) + F x)) : P (2 * F x) := by cas_nf at h exact h
Lean accepts the proof.
