The areas / V34. The tactics of Mathlib
Mathlib.Tactic.CancelDenoms.Core
29 declarations. Mathlib docs · Source
A tactic for canceling numeric denominators
This file defines tactics that cancel numeric denominators from field Expressions.
As an example, we want to transform a comparison 5*(a/3 + b/4) < c/3 into the equivalent
5*(4*a + 3*b) < 4*c.
Implementation notes
The tooling here was originally written for linarith, not intended as an interactive tactic.
The interactive version has been split off because it is sometimes convenient to use on its own.
There are likely some rough edges to it.
Improving this tactic would be a good project for someone interested in learning tactic programming.
Lemmas used in the procedure
Computing cancellation factors
def Mathlib.Tactic.CancelDenoms.CancelResult.ctorIdx E1 #
{u : Lean.Level} →
{α : Q(Type u)} → {mα : Q(Mul «$α»)} → {e v : Q(«$α»)} → Mathlib.Tactic.CancelDenoms.CancelResult mα e v → ℕ
theorem Mathlib.Tactic.CancelDenoms.CancelResult.mk.injEq E0 #
∀ {u : Lean.Level} {α : Q(Type u)} {mα : Q(Mul «$α»)} {e v : Q(«$α»)} (cancelled : Q(«$α»))
(pf : Q(«$v» * «$e» = «$cancelled»)) (cancelled_1 : Q(«$α»)) (pf_1 : Q(«$v» * «$e» = «$cancelled_1»)),
({ cancelled := cancelled, pf := pf } = { cancelled := cancelled_1, pf := pf_1 }) =
(cancelled = cancelled_1 ∧ pf = pf_1)
theorem Mathlib.Tactic.CancelDenoms.CancelResult.mk.inj E1 #
∀ {u : Lean.Level} {α : Q(Type u)} {mα : Q(Mul «$α»)} {e v cancelled : Q(«$α»)} {pf : Q(«$v» * «$e» = «$cancelled»)}
{cancelled_1 : Q(«$α»)} {pf_1 : Q(«$v» * «$e» = «$cancelled_1»)},
{ cancelled := cancelled, pf := pf } = { cancelled := cancelled_1, pf := pf_1 } → cancelled = cancelled_1 ∧ pf = pf_1
theorem Mathlib.Tactic.CancelDenoms.mul_subst E1 #
∀ {α : Type u_1} [inst : CommRing α] {n1 n2 k e1 e2 t1 t2 : α},
n1 * e1 = t1 → n2 * e2 = t2 → n1 * n2 = k → k * (e1 * e2) = t1 * t2
theorem Mathlib.Tactic.CancelDenoms.div_subst E1 #
∀ {α : Type u_1} [inst : Field α] {n1 n2 k e1 e2 t1 : α}, n1 * e1 = t1 → n2 / e2 = 1 → n1 * n2 = k → k * (e1 / e2) = t1
theorem Mathlib.Tactic.CancelDenoms.cancel_factors_eq_div E1 #
∀ {α : Type u_1} [inst : Field α] {n e e' : α}, n * e = e' → n ≠ 0 → e = e' / n
theorem Mathlib.Tactic.CancelDenoms.add_subst E1 #
∀ {α : Type u_1} [inst : Ring α] {n e1 e2 t1 t2 : α}, n * e1 = t1 → n * e2 = t2 → n * (e1 + e2) = t1 + t2
theorem Mathlib.Tactic.CancelDenoms.sub_subst E1 #
∀ {α : Type u_1} [inst : Ring α] {n e1 e2 t1 t2 : α}, n * e1 = t1 → n * e2 = t2 → n * (e1 - e2) = t1 - t2
theorem Mathlib.Tactic.CancelDenoms.neg_subst E1 #
∀ {α : Type u_1} [inst : Ring α] {n e t : α}, n * e = t → n * -e = -t
theorem Mathlib.Tactic.CancelDenoms.pow_subst E1 #
∀ {α : Type u_1} [inst : CommRing α] {n e1 t1 k l : α} {e2 : ℕ},
n * e1 = t1 → l * n ^ e2 = k → k * e1 ^ e2 = l * t1 ^ e2
theorem Mathlib.Tactic.CancelDenoms.inv_subst E1 #
∀ {α : Type u_1} [inst : Field α] {n k e : α}, e ≠ 0 → n * e = k → k * e⁻¹ = n
theorem Mathlib.Tactic.CancelDenoms.cancel_factors_lt E1 #
∀ {α : Type u_1} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] {a b ad bd a' b' gcd : α},
ad * a = a' → bd * b = b' → 0 < ad → 0 < bd → 0 < gcd → (a < b) = (1 / gcd * (bd * a') < 1 / gcd * (ad * b'))
theorem Mathlib.Tactic.CancelDenoms.cancel_factors_le E1 #
∀ {α : Type u_1} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] {a b ad bd a' b' gcd : α},
ad * a = a' → bd * b = b' → 0 < ad → 0 < bd → 0 < gcd → (a ≤ b) = (1 / gcd * (bd * a') ≤ 1 / gcd * (ad * b'))
theorem Mathlib.Tactic.CancelDenoms.cancel_factors_eq E0 #
∀ {α : Type u_1} [inst : Field α] {a b ad bd a' b' gcd : α},
ad * a = a' → bd * b = b' → ad ≠ 0 → bd ≠ 0 → gcd ≠ 0 → (a = b) = (1 / gcd * (bd * a') = 1 / gcd * (ad * b'))
theorem Mathlib.Tactic.CancelDenoms.cancel_factors_ne E1 #
∀ {α : Type u_1} [inst : Field α] {a b ad bd a' b' gcd : α},
ad * a = a' → bd * b = b' → ad ≠ 0 → bd ≠ 0 → gcd ≠ 0 → (a ≠ b) = (1 / gcd * (bd * a') ≠ 1 / gcd * (ad * b'))
opaque Mathlib.Tactic.CancelDenoms.findCancelFactor E1 #
Lean.Expr → ℕ × BinaryTree ℕ
findCancelFactor e produces a natural number n, such that multiplying e by n will
be able to cancel all the numeric denominators in e. The returned Tree describes how to
distribute the value n over products inside e.
structure Mathlib.Tactic.CancelDenoms.CancelResult E1 #
{u : Lean.Level} → {α : Q(Type u)} → Q(Mul «$α») → Q(«$α») → Q(«$α») → Type
CancelResult mα e v' provides a value for v * e where the denominators have been cancelled.
ctor Mathlib.Tactic.CancelDenoms.CancelResult.mk E0 #
{u : Lean.Level} →
{α : Q(Type u)} →
{mα : Q(Mul «$α»)} →
{e v : Q(«$α»)} →
(cancelled : Q(«$α»)) → Q(«$v» * «$e» = «$cancelled») → Mathlib.Tactic.CancelDenoms.CancelResult mα e v
abbrev Mathlib.Tactic.CancelDenoms.CancelResult.cancelled E1 #
{u : Lean.Level} →
{α : Q(Type u)} → {mα : Q(Mul «$α»)} → {e v : Q(«$α»)} → Mathlib.Tactic.CancelDenoms.CancelResult mα e v → Q(«$α»)
An expression with denominators cancelled.
abbrev Mathlib.Tactic.CancelDenoms.CancelResult.pf E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{mα : Q(Mul «$α»)} →
{e v : Q(«$α»)} → (self : Mathlib.Tactic.CancelDenoms.CancelResult mα e v) → Q(«$v» * «$e» = unknown_1)
The proof that cancelled is valid.
opaque Mathlib.Tactic.CancelDenoms.mkProdPrf E1 #
{u : Lean.Level} →
(α : Q(Type u)) →
(sα : Q(Field «$α»)) →
ℕ →
(v' : Q(«$α»)) →
BinaryTree ℕ → (e : Q(«$α»)) → Lean.MetaM (Mathlib.Tactic.CancelDenoms.CancelResult q(inferInstance) e v')
mkProdPrf α sα v v' tr e produces a proof of v'*e = e', where numeric denominators have been
canceled in e', distributing v proportionally according to the tree tr computed
by findCancelFactor.
The v' argument is a numeral expression corresponding to v, which we need in order to state
the return type accurately.
def Mathlib.Tactic.CancelDenoms.deriveThms E1 #
List Lean.Name
Theorems to get expression into a form that findCancelFactor and mkProdPrf
can more easily handle. These are important for dividing by rationals and negative integers.
theorem Mathlib.Tactic.CancelDenoms.derive_trans E2 #
∀ {α : Type u_1} [inst : Mul α] {a b c d : α}, a = b → c * b = d → c * a = d
Helper lemma to chain together a simp proof and the result of mkProdPrf.
theorem Mathlib.Tactic.CancelDenoms.derive_trans₂ E2 #
∀ {α : Type u_1} [inst : Mul α] {a b c d e : α}, a = b → b = c → d * c = e → d * a = e
Helper lemma to chain together two simp proofs and the result of mkProdPrf.
def Mathlib.Tactic.CancelDenoms.derive E1 #
Lean.Expr → Lean.MetaM (ℕ × Lean.Expr)
Given e, a term with rational division, produces a natural number n and a proof of n*e = e',
where e' has no division. Assumes "well-behaved" division.
def Mathlib.Tactic.CancelDenoms.findCompLemma E1 #
Lean.Expr → Lean.MetaM (Option (Lean.Expr × Lean.Expr × Lean.Name × Bool))
findCompLemma e arranges e in the form lhs R rhs, where R ∈ {<, ≤, =, ≠}, and returns
lhs, rhs, the cancel_factors lemma corresponding to R, and a Boolean indicating whether
R involves the order (i.e. < and ≤) or not (i.e. = and ≠).
In the case of LT, LE, GE, and GT an order on the type is needed, in the last case
it is not, the final component of the return value tracks this.
def Mathlib.Tactic.CancelDenoms.cancelDenominatorsInType E1 #
Lean.Expr → Lean.MetaM (Lean.Expr × Lean.Expr)
cancelDenominatorsInType h assumes that h is of the form lhs R rhs,
where R ∈ {<, ≤, =, ≠, ≥, >}.
It produces an Expression h' of the form lhs' R rhs' and a proof that h = h'.
Numeric denominators have been canceled in lhs' and rhs'.
def Mathlib.Tactic.cancelDenoms E1 #
Lean.ParserDescr
cancel_denoms attempts to remove numerals from the denominators of fractions.
It works on propositions that are field-valued inequalities.
variable [LinearOrderedField α] (a b c : α)
example (h : a / 5 + b / 4 < c) : 4*a + 5*b < 20*c := by
cancel_denoms at h
exact h
example (h : a > 0) : a / 5 > 0 := by
cancel_denoms
exact h
def Mathlib.Tactic.tacticCancel_denoms_ E1 #
Lean.ParserDescr
cancel_denoms attempts to remove numerals from the denominators of fractions.
It works on propositions that are field-valued inequalities.
variable [LinearOrderedField α] (a b c : α)
example (h : a / 5 + b / 4 < c) : 4*a + 5*b < 20*c := by
cancel_denoms at h
exact h
example (h : a > 0) : a / 5 > 0 := by
cancel_denoms
exact h