Documentation

CslibFrontier.Tactic.PositivityLemma

Sign lemmas for positivity #

Mathlib's positivity proves 0 < e, 0 ≤ e and e ≠ 0 by recursion on e, through an extension written for each operation. A definition it has no extension for, such as a rate or a spectral expansion defined in this library, is an atom to it. The lemma stating the sign of such a definition then has to be passed by hand into every monotonicity lemma, or stated as a hypothesis before each positivity, gcongr, grw or field_simp that needs it.

The attribute @[positivity_lemma] registers such a lemma with positivity. No extension is written for the definition: the single extension Mathlib.Meta.Positivity.evalSignLemma looks each subexpression up among the registered lemmas.

@[positivity_lemma]
theorem rate_pos (k : ℕ) : 0 < rate k := …

example (k : ℕ) (x : ℝ) (hx : 0 ≤ x) : 0 < (rate k + x) / rate k ^ 2 := by positivity
example (k : ℕ) (a b : ℝ) (h : a ≤ b) : rate k * a ≤ rate k * b := by gcongr
example (k : ℕ) (x : ℝ) : x / rate k * rate k = x := by field_simp

A registered lemma concludes 0 < e or 0 ≤ e, and e determines all of its data and type arguments: a lemma with a non-propositional argument that e does not determine is rejected. Typeclass instances whose types e determines are synthesized, and propositional hypotheses whose types e determines are discharged from local hypotheses, by recursive positivity, or, for linear comparisons over ℕ, ℤ and Fin, by omega. linarith and nlinarith do not call positivity on the atoms of a goal, so they still need the fact stated.

Main definitions #

The positivity extension for the lemmas registered with @[positivity_lemma]. positivity calls it on every subexpression it visits, and it tries the registered lemmas whose expression matches.

@[positivity_lemma] registers a lemma concluding 0 < e or 0 ≤ e with the positivity tactic. positivity then proves that statement, and e ≠ 0 from 0 < e, wherever an instance of e occurs in a goal: also in the side goals of gcongr and grw, in the side conditions of field_simp, and under casts and the other operations positivity knows.

The expression e must determine every data and type argument of the lemma: a lemma with a non-propositional argument that e does not determine is rejected, as is one whose e is a variable. Typeclass instances determined by e are synthesized, and propositional hypotheses determined by e are discharged from local hypotheses, by recursive positivity, or by omega on linear ℕ, ℤ and Fin goals.