fact
stringlengths
6
3.84k
type
stringclasses
11 values
library
stringclasses
32 values
imports
listlengths
1
14
filename
stringlengths
20
95
symbolic_name
stringlengths
1
90
docstring
stringlengths
7
20k
zpow'_neg (a : α) (n : ℤ) : zpow' a (-n) = (zpow' a n)⁻¹ := by simp +contextual [zpow', apply_ite] split_ifs with h · tauto · tauto
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_neg
null
zpow'_mul (a : α) (m n : ℤ) : zpow' a (m * n) = zpow' (zpow' a m) n := by by_cases ha : a = 0 · simp [ha] by_cases hn : n = 0 · rw [hn] simp [zpow', ha, zpow_ne_zero ] by_cases hm : m = 0 · rw [hm] simp [zpow', ha] simpa [zpow', ha, hm, hn] using zpow_mul a m n
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_mul
null
zpow'_ofNat (a : α) {n : ℕ} (hn : n ≠ 0) : zpow' a n = a ^ n := by rw [zpow'_of_ne_zero_right] · simp exact_mod_cast hn
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_ofNat
null
mul_zpow' [CommGroupWithZero α] (n : ℤ) (a b : α) : zpow' (a * b) n = zpow' a n * zpow' b n := by by_cases ha : a = 0 · simp [ha] by_cases hb : b = 0 · simp [hb] simpa [zpow', ha, hb] using mul_zpow a b n
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
mul_zpow'
null
list_prod_zpow' [CommGroupWithZero α] {r : ℤ} {l : List α} : zpow' (prod l) r = prod (map (fun x ↦ zpow' x r) l) := let fr : α →* α := ⟨⟨fun b ↦ zpow' b r, one_zpow' r⟩, (mul_zpow' r)⟩ map_list_prod fr l
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
list_prod_zpow'
null
subst_add {M : Type*} [Semiring M] {x₁ x₂ X₁ X₂ Y y a : M} (h₁ : x₁ = a * X₁) (h₂ : x₂ = a * X₂) (H_atom : X₁ + X₂ = Y) (hy : a * Y = y) : x₁ + x₂ = y := by subst h₁ h₂ H_atom hy simp [mul_add]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
subst_add
null
subst_sub {M : Type*} [Ring M] {x₁ x₂ X₁ X₂ Y y a : M} (h₁ : x₁ = a * X₁) (h₂ : x₂ = a * X₂) (H_atom : X₁ - X₂ = Y) (hy : a * Y = y) : x₁ - x₂ = y := by subst h₁ h₂ H_atom hy simp [mul_sub]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
subst_sub
null
eq_div_of_eq_one_of_subst {M : Type*} [DivInvOneMonoid M] {l l_n n : M} (h : l = l_n / 1) (hn : l_n = n) : l = n := by rw [h, hn, div_one]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eq_div_of_eq_one_of_subst
null
eq_div_of_eq_one_of_subst' {M : Type*} [DivInvOneMonoid M] {l l_d d : M} (h : l = 1 / l_d) (hn : l_d = d) : l = d⁻¹ := by rw [h, hn, one_div]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eq_div_of_eq_one_of_subst'
null
eq_div_of_subst {M : Type*} [Div M] {l l_n l_d n d : M} (h : l = l_n / l_d) (hn : l_n = n) (hd : l_d = d) : l = n / d := by rw [h, hn, hd]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eq_div_of_subst
null
eq_mul_of_eq_eq_eq_mul {M : Type*} [Mul M] {a b c D e f : M} (h₁ : a = b) (h₂ : b = c) (h₃ : c = D * e) (h₄ : e = f) : a = D * f := by rw [h₁, h₂, h₃, h₄]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eq_mul_of_eq_eq_eq_mul
null
eq_eq_cancel_eq {M : Type*} [CancelMonoidWithZero M] {e₁ e₂ f₁ f₂ L : M} (H₁ : e₁ = L * f₁) (H₂ : e₂ = L * f₂) (HL : L ≠ 0) : (e₁ = e₂) = (f₁ = f₂) := by subst H₁ H₂ rw [mul_right_inj' HL]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eq_eq_cancel_eq
null
le_eq_cancel_le {M : Type*} [CancelMonoidWithZero M] [PartialOrder M] [PosMulMono M] [PosMulReflectLE M] {e₁ e₂ f₁ f₂ L : M} (H₁ : e₁ = L * f₁) (H₂ : e₂ = L * f₂) (HL : 0 < L) : (e₁ ≤ e₂) = (f₁ ≤ f₂) := by subst H₁ H₂ apply Iff.eq exact mul_le_mul_iff_right₀ HL
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
le_eq_cancel_le
null
lt_eq_cancel_lt {M : Type*} [CancelMonoidWithZero M] [PartialOrder M] [PosMulStrictMono M] [PosMulReflectLT M] {e₁ e₂ f₁ f₂ L : M} (H₁ : e₁ = L * f₁) (H₂ : e₂ = L * f₂) (HL : 0 < L) : (e₁ < e₂) = (f₁ < f₂) := by subst H₁ H₂ apply Iff.eq exact mul_lt_mul_iff_of_pos_left HL /-! ### Theory of lists of pairs (exponent, atom) This section contains the lemmas which are orchestrated by the `field_simp` tactic to prove goals in fields. The basic object which these lemmas concern is `NF M`, a type synonym for a list of ordered pairs in `ℤ × M`, where typically `M` is a field. -/
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
lt_eq_cancel_lt
null
NF (M : Type*) := List (ℤ × M)
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
NF
Basic theoretical "normal form" object of the `field_simp` tactic: a type synonym for a list of ordered pairs in `ℤ × M`, where typically `M` is a field. This is the form to which the tactics reduce field expressions.
@[match_pattern] cons (p : ℤ × M) (l : NF M) : NF M := p :: l @[inherit_doc cons] infixl:100 " ::ᵣ " => cons
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
cons
Augment a `FieldSimp.NF M` object `l`, i.e. a list of pairs in `ℤ × M`, by prepending another pair `p : ℤ × M`.
noncomputable eval [GroupWithZero M] (l : NF M) : M := (l.map (fun (⟨r, x⟩ : ℤ × M) ↦ zpow' x r)).prod @[simp] theorem eval_cons [CommGroupWithZero M] (p : ℤ × M) (l : NF M) : (p ::ᵣ l).eval = l.eval * zpow' p.2 p.1 := by unfold eval cons simp [mul_comm]
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval
Evaluate a `FieldSimp.NF M` object `l`, i.e. a list of pairs in `ℤ × M`, to an element of `M`, by forming the "multiplicative linear combination" it specifies: raise each `M` term to the power of the corresponding `ℤ` term, then multiply them all together.
cons_ne_zero [GroupWithZero M] (r : ℤ) {x : M} (hx : x ≠ 0) {l : NF M} (hl : l.eval ≠ 0) : ((r, x) ::ᵣ l).eval ≠ 0 := by unfold eval cons apply mul_ne_zero ?_ hl simp [zpow'_eq_zero_iff, hx]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
cons_ne_zero
null
cons_pos [GroupWithZero M] [PartialOrder M] [PosMulStrictMono M] [PosMulReflectLT M] [ZeroLEOneClass M] (r : ℤ) {x : M} (hx : 0 < x) {l : NF M} (hl : 0 < l.eval) : 0 < ((r, x) ::ᵣ l).eval := by unfold eval cons apply mul_pos ?_ hl simp only rw [zpow'_of_ne_zero_left _ _ hx.ne'] apply zpow_pos hx
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
cons_pos
null
atom_eq_eval [GroupWithZero M] (x : M) : x = NF.eval [(1, x)] := by simp [eval] variable (M) in
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
atom_eq_eval
null
one_eq_eval [GroupWithZero M] : (1:M) = NF.eval (M := M) [] := rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
one_eq_eval
null
mul_eq_eval₁ [CommGroupWithZero M] (a₁ : ℤ × M) {a₂ : ℤ × M} {l₁ l₂ l : NF M} (h : l₁.eval * (a₂ ::ᵣ l₂).eval = l.eval) : (a₁ ::ᵣ l₁).eval * (a₂ ::ᵣ l₂).eval = (a₁ ::ᵣ l).eval := by simp only [eval_cons, ← h] ac_rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
mul_eq_eval₁
null
mul_eq_eval₂ [CommGroupWithZero M] (r₁ r₂ : ℤ) (x : M) {l₁ l₂ l : NF M} (h : l₁.eval * l₂.eval = l.eval) : ((r₁, x) ::ᵣ l₁).eval * ((r₂, x) ::ᵣ l₂).eval = ((r₁ + r₂, x) ::ᵣ l).eval := by simp only [eval_cons, ← h, zpow'_add] ac_rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
mul_eq_eval₂
null
mul_eq_eval₃ [CommGroupWithZero M] {a₁ : ℤ × M} (a₂ : ℤ × M) {l₁ l₂ l : NF M} (h : (a₁ ::ᵣ l₁).eval * l₂.eval = l.eval) : (a₁ ::ᵣ l₁).eval * (a₂ ::ᵣ l₂).eval = (a₂ ::ᵣ l).eval := by simp only [eval_cons, ← h] ac_rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
mul_eq_eval₃
null
mul_eq_eval [GroupWithZero M] {l₁ l₂ l : NF M} {x₁ x₂ : M} (hx₁ : x₁ = l₁.eval) (hx₂ : x₂ = l₂.eval) (h : l₁.eval * l₂.eval = l.eval) : x₁ * x₂ = l.eval := by rw [hx₁, hx₂, h]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
mul_eq_eval
null
div_eq_eval₁ [CommGroupWithZero M] (a₁ : ℤ × M) {a₂ : ℤ × M} {l₁ l₂ l : NF M} (h : l₁.eval / (a₂ ::ᵣ l₂).eval = l.eval) : (a₁ ::ᵣ l₁).eval / (a₂ ::ᵣ l₂).eval = (a₁ ::ᵣ l).eval := by simp only [eval_cons, ← h, div_eq_mul_inv] ac_rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
div_eq_eval₁
null
div_eq_eval₂ [CommGroupWithZero M] (r₁ r₂ : ℤ) (x : M) {l₁ l₂ l : NF M} (h : l₁.eval / l₂.eval = l.eval) : ((r₁, x) ::ᵣ l₁).eval / ((r₂, x) ::ᵣ l₂).eval = ((r₁ - r₂, x) ::ᵣ l).eval := by simp only [← h, eval_cons, div_eq_mul_inv, mul_inv, ← zpow'_neg, sub_eq_add_neg, zpow'_add] ac_rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
div_eq_eval₂
null
div_eq_eval₃ [CommGroupWithZero M] {a₁ : ℤ × M} (a₂ : ℤ × M) {l₁ l₂ l : NF M} (h : (a₁ ::ᵣ l₁).eval / l₂.eval = l.eval) : (a₁ ::ᵣ l₁).eval / (a₂ ::ᵣ l₂).eval = ((-a₂.1, a₂.2) ::ᵣ l).eval := by simp only [eval_cons, ← h, zpow'_neg, div_eq_mul_inv, mul_inv, mul_assoc]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
div_eq_eval₃
null
div_eq_eval [GroupWithZero M] {l₁ l₂ l : NF M} {x₁ x₂ : M} (hx₁ : x₁ = l₁.eval) (hx₂ : x₂ = l₂.eval) (h : l₁.eval / l₂.eval = l.eval) : x₁ / x₂ = l.eval := by rw [hx₁, hx₂, h]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
div_eq_eval
null
eval_mul_eval_cons [CommGroupWithZero M] (n : ℤ) (e : M) {L l l' : NF M} (h : L.eval * l.eval = l'.eval) : L.eval * ((n, e) ::ᵣ l).eval = ((n, e) ::ᵣ l').eval := by rw [eval_cons, eval_cons, ← h, mul_assoc]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval_mul_eval_cons
null
eval_mul_eval_cons_zero [CommGroupWithZero M] {e : M} {L l l' l₀ : NF M} (h : L.eval * l.eval = l'.eval) (h' : ((0, e) ::ᵣ l).eval = l₀.eval) : L.eval * l₀.eval = ((0, e) ::ᵣ l').eval := by rw [← eval_mul_eval_cons 0 e h, h']
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval_mul_eval_cons_zero
null
eval_cons_mul_eval [CommGroupWithZero M] (n : ℤ) (e : M) {L l l' : NF M} (h : L.eval * l.eval = l'.eval) : ((n, e) ::ᵣ L).eval * l.eval = ((n, e) ::ᵣ l').eval := by rw [eval_cons, eval_cons, ← h] ac_rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval_cons_mul_eval
null
eval_cons_mul_eval_cons_neg [CommGroupWithZero M] (n : ℤ) {e : M} (he : e ≠ 0) {L l l' : NF M} (h : L.eval * l.eval = l'.eval) : ((n, e) ::ᵣ L).eval * ((-n, e) ::ᵣ l).eval = l'.eval := by rw [mul_eq_eval₂ n (-n) e h] simp [zpow'_zero_of_ne_zero he]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval_cons_mul_eval_cons_neg
null
cons_eq_div_of_eq_div [CommGroupWithZero M] (n : ℤ) (e : M) {t t_n t_d : NF M} (h : t.eval = t_n.eval / t_d.eval) : ((n, e) ::ᵣ t).eval = ((n, e) ::ᵣ t_n).eval / t_d.eval := by simp only [eval_cons, h, div_eq_mul_inv] ac_rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
cons_eq_div_of_eq_div
null
cons_eq_div_of_eq_div' [CommGroupWithZero M] (n : ℤ) (e : M) {t t_n t_d : NF M} (h : t.eval = t_n.eval / t_d.eval) : ((-n, e) ::ᵣ t).eval = t_n.eval / ((n, e) ::ᵣ t_d).eval := by simp only [eval_cons, h, zpow'_neg, div_eq_mul_inv, mul_inv] ac_rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
cons_eq_div_of_eq_div'
null
cons_zero_eq_div_of_eq_div [CommGroupWithZero M] (e : M) {t t_n t_d : NF M} (h : t.eval = t_n.eval / t_d.eval) : ((0, e) ::ᵣ t).eval = ((1, e) ::ᵣ t_n).eval / ((1, e) ::ᵣ t_d).eval := by simp only [eval_cons, h, div_eq_mul_inv, mul_inv, ← zpow'_neg, ← add_neg_cancel (1:ℤ), zpow'_add] ac_rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
cons_zero_eq_div_of_eq_div
null
eval_inv [CommGroupWithZero M] (l : NF M) : (l⁻¹).eval = l.eval⁻¹ := by simp only [NF.eval, List.map_map, NF.instInv, List.prod_inv] congr! 2 ext p simp [zpow'_neg]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval_inv
null
one_div_eq_eval [CommGroupWithZero M] (l : NF M) : 1 / l.eval = (l⁻¹).eval := by simp [eval_inv]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
one_div_eq_eval
null
inv_eq_eval [CommGroupWithZero M] {l : NF M} {x : M} (h : x = l.eval) : x⁻¹ = (l⁻¹).eval := by rw [h, eval_inv]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
inv_eq_eval
null
@[simp] zpow_apply (r : ℤ) (l : NF M) : l ^ r = l.map fun (a, x) ↦ (r * a, x) := rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow_apply
null
eval_zpow' [CommGroupWithZero M] (l : NF M) (r : ℤ) : (l ^ r).eval = zpow' l.eval r := by unfold NF.eval at ⊢ simp only [zpow_apply, list_prod_zpow', map_map] congr! 2 ext p simp [← zpow'_mul, mul_comm]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval_zpow'
null
zpow_eq_eval [CommGroupWithZero M] {l : NF M} {r : ℤ} (hr : r ≠ 0) {x : M} (hx : x = l.eval) : x ^ r = (l ^ r).eval := by rw [← zpow'_of_ne_zero_right x r hr, eval_zpow', hx]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow_eq_eval
null
@[simp] pow_apply (r : ℕ) (l : NF M) : l ^ r = l.map fun (a, x) ↦ (r * a, x) := rfl
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
pow_apply
null
eval_pow [CommGroupWithZero M] (l : NF M) (r : ℕ) : (l ^ r).eval = zpow' l.eval r := eval_zpow' l r
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval_pow
null
pow_eq_eval [CommGroupWithZero M] {l : NF M} {r : ℕ} (hr : r ≠ 0) {x : M} (hx : x = l.eval) : x ^ r = (l ^ r).eval := by rw [eval_pow, hx] rw [zpow'_ofNat _ hr]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
pow_eq_eval
null
eval_cons_of_pow_eq_zero [CommGroupWithZero M] {r : ℤ} (hr : r = 0) {x : M} (hx : x ≠ 0) (l : NF M) : ((r, x) ::ᵣ l).eval = NF.eval l := by simp [hr, zpow'_zero_of_ne_zero hx]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval_cons_of_pow_eq_zero
null
eval_cons_eq_eval_of_eq_of_eq [CommGroupWithZero M] (r : ℤ) (x : M) {t t' l' : NF M} (h : NF.eval t = NF.eval t') (h' : ((r, x) ::ᵣ t').eval = NF.eval l') : ((r, x) ::ᵣ t).eval = NF.eval l' := by rw [← h', eval_cons, eval_cons, h]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
eval_cons_eq_eval_of_eq_of_eq
null
Sign (M : Q(Type v)) | plus | minus (iM : Q(Field $M))
inductive
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign
Inductive type representing the options for the sign of an element in a type-expression `M` If the sign is "-", then we also carry an expression for a field instance on `M`, to allow us to construct that negation when needed.
Sign.expr : Sign M → Q($M) → Q($M) | plus, a => a | minus _, a => q(-$a)
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.expr
Given an expression `e : Q($M)`, construct an expression which is morally "± `e`", with the choice between + and - determined by an object `g : Sign M`.
Sign.mulRight (iM : Q(CommGroupWithZero $M)) (c y : Q($M)) (g : Sign M) : MetaM Q($(g.expr q($c * $y)) = $c * $(g.expr y)) := do match g with | .plus => pure q(rfl) | .minus _ => assumeInstancesCommute pure q(Eq.symm (mul_neg $c _))
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.mulRight
Given an expression `y : Q($M)` with specified sign (either + or -), construct a proof that the product with `c` of (± `y`) (here taking the specified sign) is ± `c * y`.
Sign.mul (iM : Q(CommGroupWithZero $M)) (y₁ y₂ : Q($M)) (g₁ g₂ : Sign M) : MetaM (Σ (G : Sign M), Q($(g₁.expr y₁) * $(g₂.expr y₂) = $(G.expr q($y₁ * $y₂)))) := do match g₁, g₂ with | .plus, .plus => pure ⟨.plus, q(rfl)⟩ | .plus, .minus i => assumeInstancesCommute pure ⟨.minus i, q(mul_neg $y₁ $y₂)⟩ | .minus i, .plus => assumeInstancesCommute pure ⟨.minus i, q(neg_mul $y₁ $y₂)⟩ | .minus _, .minus _ => assumeInstancesCommute pure ⟨.plus, q(neg_mul_neg $y₁ $y₂)⟩
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.mul
Given expressions `y₁ y₂ : Q($M)` with specified signs (either + or -), construct a proof that the product of (± `y₁`) and (± `y₂`) (here taking the specified signs) is ± `y₁ * y₂`; return this proof and the computed sign.
Sign.inv (iM : Q(CommGroupWithZero $M)) (y : Q($M)) (g : Sign M) : MetaM (Q($(g.expr y)⁻¹ = $(g.expr q($y⁻¹)))) := do match g with | .plus => pure q(rfl) | .minus _ => assumeInstancesCommute pure q(inv_neg (a := $y))
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.inv
Given an expression `y : Q($M)` with specified sign (either + or -), construct a proof that the inverse of (± `y`) (here taking the specified sign) is ± `y⁻¹`.
Sign.div (iM : Q(CommGroupWithZero $M)) (y₁ y₂ : Q($M)) (g₁ g₂ : Sign M) : MetaM (Σ (G : Sign M), Q($(g₁.expr y₁) / $(g₂.expr y₂) = $(G.expr q($y₁ / $y₂)))) := do match g₁, g₂ with | .plus, .plus => pure ⟨.plus, q(rfl)⟩ | .plus, .minus i => assumeInstancesCommute pure ⟨.minus i, q(div_neg $y₁ (b := $y₂))⟩ | .minus i, .plus => assumeInstancesCommute pure ⟨.minus i, q(neg_div $y₂ $y₁)⟩ | .minus _, .minus _ => assumeInstancesCommute pure ⟨.plus, q(neg_div_neg_eq $y₁ $y₂)⟩
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.div
Given expressions `y₁ y₂ : Q($M)` with specified signs (either + or -), construct a proof that the quotient of (± `y₁`) and (± `y₂`) (here taking the specified signs) is ± `y₁ / y₂`; return this proof and the computed sign.
Sign.neg (iM : Q(Field $M)) (y : Q($M)) (g : Sign M) : MetaM (Σ (G : Sign M), Q(-$(g.expr y) = $(G.expr y))) := do match g with | .plus => pure ⟨.minus iM, q(rfl)⟩ | .minus _ => assumeInstancesCommute pure ⟨.plus, q(neg_neg $y)⟩
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.neg
Given an expression `y : Q($M)` with specified sign (either + or -), construct a proof that the negation of (± `y`) (here taking the specified sign) is ∓ `y`.
Sign.pow (iM : Q(CommGroupWithZero $M)) (y : Q($M)) (g : Sign M) (s : ℕ) : MetaM (Σ (G : Sign M), Q($(g.expr y) ^ $s = $(G.expr q($y ^ $s)))) := do match g with | .plus => pure ⟨.plus, q(rfl)⟩ | .minus i => assumeInstancesCommute if Even s then let pf_s ← mkDecideProofQ q(Even $s) pure ⟨.plus, q(Even.neg_pow $pf_s $y)⟩ else let pf_s ← mkDecideProofQ q(Odd $s) pure ⟨.minus i, q(Odd.neg_pow $pf_s $y)⟩
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.pow
Given an expression `y : Q($M)` with specified sign (either + or -), construct a proof that the exponentiation to power `s : ℕ` of (± `y`) (here taking the specified signs) is ± `y ^ s`; return this proof and the computed sign.
Sign.zpow (iM : Q(CommGroupWithZero $M)) (y : Q($M)) (g : Sign M) (s : ℤ) : MetaM (Σ (G : Sign M), Q($(g.expr y) ^ $s = $(G.expr q($y ^ $s)))) := do match g with | .plus => pure ⟨.plus, q(rfl)⟩ | .minus i => assumeInstancesCommute if Even s then let pf_s ← mkDecideProofQ q(Even $s) pure ⟨.plus, q(Even.neg_zpow $pf_s $y)⟩ else let pf_s ← mkDecideProofQ q(Odd $s) pure ⟨.minus i, q(Odd.neg_zpow $pf_s $y)⟩
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.zpow
Given an expression `y : Q($M)` with specified sign (either + or -), construct a proof that the exponentiation to power `s : ℤ` of (± `y`) (here taking the specified signs) is ± `y ^ s`; return this proof and the computed sign.
Sign.congr {y y' : Q($M)} (g : Sign M) (pf : Q($y = $y')) : Q($(g.expr y)= $(g.expr y')) := match g with | .plus => pf | .minus _ => q(congr_arg Neg.neg $pf)
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.congr
Given a proof that two expressions `y₁ y₂ : Q($M)` are equal, construct a proof that (± `y₁`) and (± `y₂`) are equal, where the same sign is taken in both expression.
Sign.mkEqMul (iM : Q(CommGroupWithZero $M)) {a b C d e : Q($M)} {g : Sign M} (pf₁ : Q($a = $(g.expr b))) (pf₂ : Q($b = $C * $d)) (pf₃ : Q($d = $e)) : MetaM Q($a = $C * $(g.expr e)) := do let pf₂' : Q($(g.expr b) = $(g.expr q($C * $d))) := g.congr pf₂ let pf' ← Sign.mulRight iM C d g pure q(eq_mul_of_eq_eq_eq_mul $pf₁ $pf₂' $pf' $(g.congr pf₃))
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
Sign.mkEqMul
If `a` = ± `b`, `b = C * d`, and `d = e`, construct a proof that `a` = `C` * ± `e`.
private funPropHelpString : String := "`fun_prop` tactic to prove function properties like `Continuous`, `Differentiable`, `IsLinearMap`"
def
Tactic
[ "Mathlib.Tactic.FunProp.Decl", "Mathlib.Tactic.FunProp.Theorems" ]
Mathlib/Tactic/FunProp/Attr.lean
funPropHelpString
null
synthesizeInstance (thmId : Origin) (x type : Expr) : MetaM Bool := do match (← trySynthInstance type) with | .some val => if (← withReducibleAndInstances <| isDefEq x val) then return true else trace[Meta.Tactic.fun_prop] "{← ppOrigin thmId}, failed to assign instance{indentExpr type} synthesized value{indentExpr val}\nis not definitionally equal to{indentExpr x}" return false | _ => trace[Meta.Tactic.fun_prop] "{← ppOrigin thmId}, failed to synthesize instance{indentExpr type}" return false
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
synthesizeInstance
Synthesize instance of type `type` and 1. assign it to `x` if `x` is meta variable 2. check it is equal to `x`
synthesizeArgs (thmId : Origin) (xs : Array Expr) (funProp : Expr → FunPropM (Option Result)) : FunPropM Bool := do let mut postponed : Array Expr := #[] for x in xs do let type ← inferType x if (← instantiateMVars x).isMVar then if (← isClass? type).isSome then if (← synthesizeInstance thmId x type) then continue else if (← isFunProp type.getForallBody) then if let some ⟨proof⟩ ← funProp type then if (← isDefEq x proof) then continue else do trace[Meta.Tactic.fun_prop] "{← ppOrigin thmId}, failed to assign proof{indentExpr type}" return false else let ctx : Context ← read if (← isProp type) then if let some proof ← ctx.disch type then if (← isDefEq x proof) then continue else do trace[Meta.Tactic.fun_prop] "{← ppOrigin thmId}, failed to assign proof{indentExpr type}" return false else logError s!"Failed to prove necessary assumption `{← ppExpr type}` \ when applying theorem `{← ppOrigin' thmId}`." if ¬(← isProp type) then postponed := postponed.push x continue else trace[Meta.Tactic.fun_prop] "{← ppOrigin thmId}, failed to discharge hypotheses{indentExpr type}" return false for x in postponed do if (← instantiateMVars x).isMVar then logError s!"Failed to infer `({← ppExpr x} : {← ppExpr (← inferType x)})` \ when applying theorem `{← ppOrigin' thmId}`." trace[Meta.Tactic.fun_prop] "{← ppOrigin thmId}, failed to infer `({← ppExpr x} : {← ppExpr (← inferType x)})`" return false return true
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
synthesizeArgs
Synthesize arguments `xs` either with typeclass synthesis, with `fun_prop` or with discharger.
tryTheoremCore (xs : Array Expr) (val : Expr) (type : Expr) (e : Expr) (thmId : Origin) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do withTraceNode `Meta.Tactic.fun_prop (fun r => return s!"[{ExceptToEmoji.toEmoji r}] applying: {← ppOrigin' thmId}") do if (← isDefEq type e) then if ¬(← synthesizeArgs thmId xs funProp) then return none let proof ← instantiateMVars (mkAppN val xs) return some { proof := proof } else trace[Meta.Tactic.fun_prop] "failed to unify {← ppOrigin thmId}\n{type}\nwith\n{e}" return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
tryTheoremCore
Try to apply theorem - core function
tryTheoremWithHint? (e : Expr) (thmOrigin : Origin) (hint : Array (Nat × Expr)) (funProp : Expr → FunPropM (Option Result)) (newMCtxDepth : Bool := false) : FunPropM (Option Result) := do let go : FunPropM (Option Result) := do let thmProof ← thmOrigin.getValue let type ← inferType thmProof let (xs, _, type) ← forallMetaTelescope type for (i,x) in hint do try for (id,v) in hint do xs[id]!.mvarId!.assignIfDefEq v catch _ => trace[Debug.Meta.Tactic.fun_prop] "failed to use hint {i} `{← ppExpr x} when applying theorem {← ppOrigin thmOrigin}" tryTheoremCore xs thmProof type e thmOrigin funProp if newMCtxDepth then withNewMCtxDepth go else go
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
tryTheoremWithHint
Try to apply a theorem provided some of the theorem arguments.
tryTheorem? (e : Expr) (thmOrigin : Origin) (funProp : Expr → FunPropM (Option Result)) (newMCtxDepth : Bool := false) : FunPropM (Option Result) := tryTheoremWithHint? e thmOrigin #[] funProp newMCtxDepth
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
tryTheorem
Try to apply a theorem `thmOrigin` to the goal `e`.
applyIdRule (funPropDecl : FunPropDecl) (e : Expr) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do let thms ← getLambdaTheorems funPropDecl.funPropName .id if thms.size = 0 then let msg := s!"missing identity rule to prove `{← ppExpr e}`" logError msg trace[Meta.Tactic.fun_prop] msg return none for thm in thms do if let some r ← tryTheoremWithHint? e (.decl thm.thmName) #[] funProp then return r return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
applyIdRule
Try to prove `e` using using *identity lambda theorem*. For example, `e = q(Continuous fun x => x)` and `funPropDecl` is `FunPropDecl` for `Continuous`.
applyConstRule (funPropDecl : FunPropDecl) (e : Expr) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do let thms ← getLambdaTheorems funPropDecl.funPropName .const if thms.size = 0 then let msg := s!"missing constant rule to prove `{← ppExpr e}`" logError msg trace[Meta.Tactic.fun_prop] msg return none for thm in thms do let .const := thm.thmArgs | return none if let some r ← tryTheorem? e (.decl thm.thmName) funProp then return r return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
applyConstRule
Try to prove `e` using using *constant lambda theorem*. For example, `e = q(Continuous fun x => y)` and `funPropDecl` is `FunPropDecl` for `Continuous`.
applyApplyRule (funPropDecl : FunPropDecl) (e : Expr) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do let thms := (← getLambdaTheorems funPropDecl.funPropName .apply) for thm in thms do if let some r ← tryTheoremWithHint? e (.decl thm.thmName) #[] funProp then return r return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
applyApplyRule
Try to prove `e` using using *apply lambda theorem*. For example, `e = q(Continuous fun f => f x)` and `funPropDecl` is `FunPropDecl` for `Continuous`.
applyCompRule (funPropDecl : FunPropDecl) (e f g : Expr) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do let thms ← getLambdaTheorems funPropDecl.funPropName .comp if thms.size = 0 then let msg := s!"missing composition rule to prove `{← ppExpr e}`" logError msg trace[Meta.Tactic.fun_prop] msg return none for thm in thms do let .comp id_f id_g := thm.thmArgs | return none if let some r ← tryTheoremWithHint? e (.decl thm.thmName) #[(id_f, f), (id_g, g)] funProp then return r return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
applyCompRule
Try to prove `e` using *composition lambda theorem*. For example, `e = q(Continuous fun x => f (g x))` and `funPropDecl` is `FunPropDecl` for `Continuous` You also have to provide the functions `f` and `g`.
applyPiRule (funPropDecl : FunPropDecl) (e : Expr) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do let thms ← getLambdaTheorems funPropDecl.funPropName .pi if thms.size = 0 then let msg := s!"missing pi rule to prove `{← ppExpr e}`" logError msg trace[Meta.Tactic.fun_prop] msg return none for thm in thms do if let some r ← tryTheoremWithHint? e (.decl thm.thmName) #[] funProp then return r return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
applyPiRule
Try to prove `e` using *pi lambda theorem*. For example, `e = q(Continuous fun x y => f x y)` and `funPropDecl` is `FunPropDecl` for `Continuous`
letCase (funPropDecl : FunPropDecl) (e : Expr) (f : Expr) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do match f with | .lam xName xType (.letE yName yType yValue yBody _) xBi => do let yType := yType.consumeMData let yValue := yValue.consumeMData let yBody := yBody.consumeMData let yType := yType.headBeta if (yType.hasLooseBVar 0) then throwError "dependent type encountered {← ppExpr (Expr.forallE xName xType yType default)}" if ¬(yValue.hasLooseBVar 0) then let body := yBody.swapBVars 0 1 let e' := mkLet yName yType yValue (e.setArg (funPropDecl.funArgId) (.lam xName xType body xBi)) return ← funProp e' match (yBody.hasLooseBVar 0), (yBody.hasLooseBVar 1) with | true, true => let f ← mkUncurryFun 2 (Expr.lam xName xType (.lam yName yType yBody default) xBi) let g := Expr.lam xName xType (binderInfo := default) (mkAppN (← mkConstWithFreshMVarLevels ``Prod.mk) #[xType,yType,.bvar 0, yValue]) applyCompRule funPropDecl e f g funProp | true, false => let f := Expr.lam yName yType yBody default let g := Expr.lam xName xType yValue default applyCompRule funPropDecl e f g funProp | false, _ => let f := Expr.lam xName xType (yBody.lowerLooseBVars 1 1) xBi funProp (e.setArg (funPropDecl.funArgId) f) | _ => throwError "expected expression of the form `fun x => lam y := ..; ..`"
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
letCase
Try to prove `e = q(P (fun x => let y := φ x; ψ x y)`. For example, - `funPropDecl` is `FunPropDecl` for `Continuous` - `e = q(Continuous fun x => let y := φ x; ψ x y)` - `f = q(fun x => let y := φ x; ψ x y)`
applyMorRules (funPropDecl : FunPropDecl) (e : Expr) (fData : FunctionData) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do trace[Debug.Meta.Tactic.fun_prop] "applying morphism theorems to {← ppExpr e}" match ← fData.isMorApplication with | .none => throwError "fun_prop bug: invalid use of mor rules on {← ppExpr e}" | .underApplied => applyPiRule funPropDecl e funProp | .overApplied => let some (f, g) ← fData.peeloffArgDecomposition | return none applyCompRule funPropDecl e f g funProp | .exact => let candidates ← getMorphismTheorems e trace[Meta.Tactic.fun_prop] "candidate morphism theorems: {← candidates.mapM fun c => ppOrigin (.decl c.thmName)}" for c in candidates do if let some r ← tryTheorem? e (.decl c.thmName) funProp then return r trace[Debug.Meta.Tactic.fun_prop] "no theorem matched" return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
applyMorRules
Prove function property of using *morphism theorems*.
applyTransitionRules (e : Expr) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do withIncreasedTransitionDepth do let candidates ← getTransitionTheorems e trace[Meta.Tactic.fun_prop] "candidate transition theorems: {← candidates.mapM fun c => ppOrigin (.decl c.thmName)}" for c in candidates do if let some r ← tryTheorem? e (.decl c.thmName) funProp then return r trace[Debug.Meta.Tactic.fun_prop] "no theorem matched" return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
applyTransitionRules
Prove function property of using *transition theorems*.
removeArgRule (funPropDecl : FunPropDecl) (e : Expr) (fData : FunctionData) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do match h : fData.args.size with | 0 => throwError "fun_prop bug: invalid use of remove arg case {←ppExpr e}" | n + 1 => let arg := fData.args[n] if arg.coe.isSome then return ← applyMorRules funPropDecl e fData funProp else let some (f, g) ← fData.peeloffArgDecomposition | return none applyCompRule funPropDecl e f g funProp
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
removeArgRule
Try to remove applied argument i.e. prove `P (fun x => f x y)` from `P (fun x => f x)`. For example - `funPropDecl` is `FunPropDecl` for `Continuous` - `e = q(Continuous fun x => foo (bar x) y)` - `fData` contains info on `fun x => foo (bar x) y` This tries to prove `Continuous fun x => foo (bar x) y` from `Continuous fun x => foo (bar x)`
bvarAppCase (funPropDecl : FunPropDecl) (e : Expr) (fData : FunctionData) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do if (← fData.isMorApplication) != .none then applyMorRules funPropDecl e fData funProp else if let some (f, g) ← fData.nontrivialDecomposition then applyCompRule funPropDecl e f g funProp else applyApplyRule funPropDecl e funProp
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
bvarAppCase
Prove function property of `fun f => f x₁ ... xₙ`.
getDeclTheorems (funPropDecl : FunPropDecl) (funName : Name) (mainArgs : Array Nat) (appliedArgs : Nat) : MetaM (Array FunctionTheorem) := do let thms ← getTheoremsForFunction funName funPropDecl.funPropName let thms := thms |>.filter (fun thm => (isOrderedSubsetOf mainArgs thm.mainArgs)) |>.qsort (fun t s => let dt := (Int.ofNat t.appliedArgs - Int.ofNat appliedArgs).natAbs let ds := (Int.ofNat s.appliedArgs - Int.ofNat appliedArgs).natAbs match compare dt ds with | .lt => true | .gt => false | .eq => t.mainArgs.size < s.mainArgs.size) return thms
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
getDeclTheorems
Get candidate theorems from the environment for function property `funPropDecl` and function `funName`.
getLocalTheorems (funPropDecl : FunPropDecl) (funOrigin : Origin) (mainArgs : Array Nat) (appliedArgs : Nat) : FunPropM (Array FunctionTheorem) := do let mut thms : Array FunctionTheorem := #[] let lctx ← getLCtx for var in lctx do if (var.kind = Lean.LocalDeclKind.auxDecl) then continue let type ← instantiateMVars var.type let thm? : Option FunctionTheorem ← forallTelescope type fun _ b => do let b ← whnfR b let some (decl, f) ← getFunProp? b | return none unless decl.funPropName = funPropDecl.funPropName do return none let .data fData ← getFunctionData? f (← unfoldNamePred) | return none unless (fData.getFnOrigin == funOrigin) do return none unless isOrderedSubsetOf mainArgs fData.mainArgs do return none let dec? ← fData.nontrivialDecomposition let thm : FunctionTheorem := { funPropName := funPropDecl.funPropName thmOrigin := .fvar var.fvarId funOrigin := funOrigin mainArgs := fData.mainArgs appliedArgs := fData.args.size priority := eval_prio default form := if dec?.isSome then .comp else .uncurried } return some thm if let some thm := thm? then thms := thms.push thm thms := thms |>.qsort (fun t s => let dt := (Int.ofNat t.appliedArgs - Int.ofNat appliedArgs).natAbs let ds := (Int.ofNat s.appliedArgs - Int.ofNat appliedArgs).natAbs match compare dt ds with | .lt => true | .gt => false | .eq => t.mainArgs.size < s.mainArgs.size) return thms
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
getLocalTheorems
Get candidate theorems from the local context for function property `funPropDecl` and function `funName`.
tryTheorems (funPropDecl : FunPropDecl) (e : Expr) (fData : FunctionData) (thms : Array FunctionTheorem) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do let mut dec? : Option (Option (Expr × Expr)) := none for thm in thms do trace[Debug.Meta.Tactic.fun_prop] s!"trying theorem {← ppOrigin' thm.thmOrigin}" match compare thm.appliedArgs fData.args.size with | .lt => trace[Meta.Tactic.fun_prop] s!"removing argument to later use {← ppOrigin' thm.thmOrigin}" if let some r ← removeArgRule funPropDecl e fData funProp then return r continue | .gt => trace[Meta.Tactic.fun_prop] s!"adding argument to later use {← ppOrigin' thm.thmOrigin}" if let some r ← applyPiRule funPropDecl e funProp then return r continue | .eq => if thm.form == .comp then if let some r ← tryTheorem? e thm.thmOrigin funProp then return r else if thm.mainArgs.size == fData.mainArgs.size then if dec?.isNone then dec? := some (← fData.nontrivialDecomposition) match dec? with | some none => if let some r ← tryTheorem? e thm.thmOrigin funProp then return r | some (some (f, g)) => trace[Meta.Tactic.fun_prop] s!"decomposing to later use {←ppOrigin' thm.thmOrigin} as: ({← ppExpr f}) ∘ ({← ppExpr g})" if let some r ← applyCompRule funPropDecl e f g funProp then return r | _ => continue else let some (f, g) ← fData.decompositionOverArgs thm.mainArgs | continue trace[Meta.Tactic.fun_prop] s!"decomposing to later use {←ppOrigin' thm.thmOrigin} as: ({← ppExpr f}) ∘ ({← ppExpr g})" if let some r ← applyCompRule funPropDecl e f g funProp then return r return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
tryTheorems
Try to apply *function theorems* `thms` to `e`.
fvarAppCase (funPropDecl : FunPropDecl) (e : Expr) (fData : FunctionData) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do if let some (f, g) ← fData.nontrivialDecomposition then applyCompRule funPropDecl e f g funProp else let .fvar id := fData.fn | throwError "fun_prop bug: invalid use of fvar app case" let thms ← getLocalTheorems funPropDecl (.fvar id) fData.mainArgs fData.args.size trace[Meta.Tactic.fun_prop] s!"candidate local theorems for {←ppExpr (.fvar id)} \ {← thms.mapM fun thm => ppOrigin' thm.thmOrigin}" if let some r ← tryTheorems funPropDecl e fData thms funProp then return r if let some f ← fData.unfoldHeadFVar? then let e' := e.setArg funPropDecl.funArgId f if let some r ← funProp e' then return r if (← fData.isMorApplication) != .none then if let some r ← applyMorRules funPropDecl e fData funProp then return r if (← fData.nontrivialDecomposition).isNone then if let some r ← applyTransitionRules e funProp then return r if thms.size = 0 then logError s!"No theorems found for `{← ppExpr (.fvar id)}` in order to prove `{← ppExpr e}`" return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
fvarAppCase
Prove function property of `fun x => f x₁ ... xₙ` where `f` is free variable.
constAppCase (funPropDecl : FunPropDecl) (e : Expr) (fData : FunctionData) (funProp : Expr → FunPropM (Option Result)) : FunPropM (Option Result) := do let some (funName, _) := fData.fn.const? | throwError "fun_prop bug: invelid use of const app case" let globalThms ← getDeclTheorems funPropDecl funName fData.mainArgs fData.args.size trace[Meta.Tactic.fun_prop] s!"candidate theorems for {funName} {← globalThms.mapM fun thm => ppOrigin' thm.thmOrigin}" if let some r ← tryTheorems funPropDecl e fData globalThms funProp then return r let localThms ← getLocalTheorems funPropDecl (.decl funName) fData.mainArgs fData.args.size if localThms.size ≠ 0 then trace[Meta.Tactic.fun_prop] s!"candidate local theorems for {funName} \ {← localThms.mapM fun thm => ppOrigin' thm.thmOrigin}" if let some r ← tryTheorems funPropDecl e fData localThms funProp then return r if globalThms.size = 0 && localThms.size = 0 then logError s!"No theorems found for `{funName}` in order to prove `{← ppExpr e}`" if (← fData.isMorApplication) != .none then if let some r ← applyMorRules funPropDecl e fData funProp then return r if let some (f, g) ← fData.nontrivialDecomposition then trace[Meta.Tactic.fun_prop] s!"failed applying `{funPropDecl.funPropName}` theorems for `{funName}` trying again after decomposing function as: `({← ppExpr f}) ∘ ({← ppExpr g})`" if let some r ← applyCompRule funPropDecl e f g funProp then return r else trace[Meta.Tactic.fun_prop] s!"failed applying `{funPropDecl.funPropName}` theorems for `{funName}` now trying to prove `{funPropDecl.funPropName}` from another function property" if let some r ← applyTransitionRules e funProp then return r return none
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
constAppCase
Prove function property of `fun x => f x₁ ... xₙ` where `f` is declared function.
cacheResult (e : Expr) (r : Result) : FunPropM Result := do -- return proof? modify (fun s => { s with cache := s.cache.insert e { expr := q(True), proof? := r.proof} }) return r
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
cacheResult
Cache result if it does not have any subgoals.
cacheFailure (e : Expr) : FunPropM Unit := do -- return proof? modify (fun s => { s with failureCache := s.failureCache.insert e }) mutual /-- Main `funProp` function. Returns proof of `e`. -/ partial def funProp (e : Expr) : FunPropM (Option Result) := do let e ← instantiateMVars e withTraceNode `Meta.Tactic.fun_prop (fun r => do pure s!"[{ExceptToEmoji.toEmoji r}] {← ppExpr e}") do if let some { expr := _, proof? := some proof } := (← get).cache.find? e then trace[Meta.Tactic.fun_prop] "reusing previously found proof for {e}" return some { proof := proof } else if (← get).failureCache.contains e then trace[Meta.Tactic.fun_prop] "skipping proof search, proving {e} was tried already and failed" return none else match e with | .letE .. => letTelescope e fun xs b => do let some r ← funProp b | return none cacheResult e {proof := ← mkLambdaFVars (generalizeNondepLet := false) xs r.proof } | .forallE .. => forallTelescope e fun xs b => do let some r ← funProp b | return none cacheResult e {proof := ← mkLambdaFVars xs r.proof } | .mdata _ e' => funProp e' | _ => if let some r ← main e then cacheResult e r else cacheFailure e return none /-- Main `funProp` function. Returns proof of `e`. -/ private partial def main (e : Expr) : FunPropM (Option Result) := do let some (funPropDecl, f) ← getFunProp? e | return none increaseSteps if f.isLet then return ← funProp (← mapLetTelescope f fun _ b => pure <| e.setArg funPropDecl.funArgId b) match ← getFunctionData? f (← unfoldNamePred) with | .letE f => trace[Debug.Meta.Tactic.fun_prop] "let case on {← ppExpr f}" let e := e.setArg funPropDecl.funArgId f -- update e with reduced f letCase funPropDecl e f funProp | .lam f => trace[Debug.Meta.Tactic.fun_prop] "pi case on {← ppExpr f}" let e := e.setArg funPropDecl.funArgId f -- update e with reduced f applyPiRule funPropDecl e funProp | .data fData => let e := e.setArg funPropDecl.funArgId (← fData.toExpr) -- update e with reduced f ...
def
Tactic
[ "Mathlib.Tactic.FunProp.Theorems", "Mathlib.Tactic.FunProp.ToBatteries", "Mathlib.Tactic.FunProp.Types", "Mathlib.Lean.Expr.Basic", "Batteries.Tactic.Exact" ]
Mathlib/Tactic/FunProp/Core.lean
cacheFailure
Cache for failed goals such that `fun_prop` can fail fast next time.
FunPropDecl where /-- function transformation name -/ funPropName : Name /-- path for discrimination tree -/ path : Array DiscrTree.Key /-- argument index of a function this function property talks about. For example, this would be 4 for `@Continuous α β _ _ f` -/ funArgId : Nat deriving Inhabited, BEq
structure
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
FunPropDecl
Basic information about function property To use `funProp` to prove a function property `P : (α→β)→Prop` one has to provide `FunPropDecl`.
FunPropDecls where /-- Discrimination tree for function properties. -/ decls : DiscrTree FunPropDecl := {} deriving Inhabited set_option linter.style.docString.empty false in
structure
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
FunPropDecls
Discrimination tree for function properties.
FunPropDeclsExt := SimpleScopedEnvExtension FunPropDecl FunPropDecls
abbrev
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
FunPropDeclsExt
null
addFunPropDecl (declName : Name) : MetaM Unit := do let info ← getConstInfo declName let (xs, bi, b) ← forallMetaTelescope info.type if ¬b.isProp then throwError "invalid fun_prop declaration, has to be `Prop`-valued function" let lvls := info.levelParams.map (fun l => Level.param l) let e := mkAppN (.const declName lvls) xs let path ← DiscrTree.mkPath e let mut some funArgId ← (xs.zip bi).findIdxM? fun (x,bi) => do if (← inferType x).isForall && bi.isExplicit then return true else return false | throwError "invalid fun_prop declaration, can't find argument of type `α → β`" let decl : FunPropDecl := { funPropName := declName path := path funArgId := funArgId } modifyEnv fun env => funPropDeclsExt.addEntry env decl trace[Meta.Tactic.funProp.attr] "added new function property `{declName}`\nlook up pattern is `{path}`"
def
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
addFunPropDecl
Extension storing function properties tracked and used by the `fun_prop` attribute and tactic, including, for example, `Continuous`, `Measurable`, `Differentiable`, etc. -/ initialize funPropDeclsExt : FunPropDeclsExt ← registerSimpleScopedEnvExtension { name := by exact decl_name% initial := {} addEntry := fun d e => {d with decls := d.decls.insertCore e.path e} } /-- Register new function property.
getFunProp? (e : Expr) : MetaM (Option (FunPropDecl × Expr)) := do let ext := funPropDeclsExt.getState (← getEnv) let decls ← ext.decls.getMatch e (← read) if h : decls.size = 0 then return none else if decls.size > 1 then throwError "fun_prop bug: expression {← ppExpr e} matches multiple function properties\n\ {decls.map (fun d => d.funPropName)}" let decl := decls[0] unless decl.funArgId < e.getAppNumArgs do return none let f := e.getArg! decl.funArgId return (decl,f)
def
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
getFunProp
Is `e` a function property statement? If yes return function property declaration and the function it talks about.
isFunProp (e : Expr) : MetaM Bool := do return (← getFunProp? e).isSome
def
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
isFunProp
Is `e` a function property statement?
isFunPropGoal (e : Expr) : MetaM Bool := do forallTelescope e fun _ b => return (← getFunProp? b).isSome
def
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
isFunPropGoal
Is `e` a `fun_prop` goal? For example `∀ y z, Continuous fun x => f x y z`
getFunPropDecl? (e : Expr) : MetaM (Option FunPropDecl) := do match ← getFunProp? e with | some (decl, _) => return decl | none => return none
def
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
getFunPropDecl
Returns function property declaration from `e = P f`.
getFunPropFun? (e : Expr) : MetaM (Option Expr) := do match ← getFunProp? e with | some (_, f) => return f | none => return none open Elab Term in
def
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
getFunPropFun
Returns function `f` from `e = P f` and `P` is function property.
tacticToDischarge (tacticCode : TSyntax `tactic) : Expr → MetaM (Option Expr) := fun e => withTraceNode `Meta.Tactic.fun_prop (fun r => do pure s!"[{ExceptToEmoji.toEmoji r}] discharging: {← ppExpr e}") do let mvar ← mkFreshExprSyntheticOpaqueMVar e `funProp.discharger let runTac? : TermElabM (Option Expr) := try withoutModifyingStateWithInfoAndMessages do instantiateMVarDeclMVars mvar.mvarId! let _ ← withSynthesize (postpone := .no) do Tactic.run mvar.mvarId! (Tactic.evalTactic tacticCode *> Tactic.pruneSolvedGoals) let result ← instantiateMVars mvar if result.hasExprMVar then return none else return some result catch _ => return none let (result?, _) ← runTac?.run {} {} return result?
def
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/FunProp/Decl.lean
tacticToDischarge
Turn tactic syntax into a discharger function.
@[tactic funPropTacStx] funPropTac : Tactic | `(tactic| fun_prop $cfg:optConfig $[$d]? $[[$names,*]]?) => do let goal ← getMainGoal goal.withContext do let goalType ← goal.getType withReducible <| forallTelescopeReducing (← whnfR goalType) fun _ type => do unless (← getFunProp? type).isSome do let hint := if let some n := type.getAppFn.constName? then s!" Maybe you forgot marking `{n}` with `@[fun_prop]`." else "" throwError "`{← ppExpr type}` is not a `fun_prop` goal!{hint}" let cfg ← elabFunPropConfig cfg let disch ← show MetaM (Expr → MetaM (Option Expr)) from do match d with | none => pure emptyDischarge | some d => match d with | `(discharger| (discharger:=$tac)) => pure <| tacticToDischarge (← `(tactic| ($tac))) | _ => pure emptyDischarge let namesToUnfold : Array Name := match names with | none => #[] | some ns => ns.getElems.map (fun n => n.getId) let namesToUnfold := namesToUnfold.append defaultNamesToUnfold let ctx : Context := { config := cfg, disch := disch constToUnfold := .ofArray namesToUnfold _} let env ← getEnv let s := { morTheorems := morTheoremsExt.getState env transitionTheorems := transitionTheoremsExt.getState env } let (r?, s) ← funProp goalType ctx |>.run s if let some r := r? then goal.assign r.proof else let mut msg := s!"`fun_prop` was unable to prove `{← Meta.ppExpr goalType}`\n\n" msg := msg ++ "Issues:" msg := s.msgLog.foldl (init := msg) (fun msg m => msg ++ "\n " ++ m) throwError msg | _ => throwUnsupportedSyntax
def
Tactic
[ "Mathlib.Tactic.FunProp.Core" ]
Mathlib/Tactic/FunProp/Elab.lean
funPropTac
`fun_prop` config elaborator -/ declare_config_elab elabFunPropConfig FunProp.Config /-- Tactic to prove function properties -/ syntax (name := funPropTacStx) "fun_prop" optConfig (discharger)? (" [" withoutPosition(ident,*,?) "]")? : tactic private def emptyDischarge : Expr → MetaM (Option Expr) := fun e => withTraceNode `Meta.Tactic.fun_prop (fun r => do pure s!"[{ExceptToEmoji.toEmoji r}] discharging: {← ppExpr e}") do pure none /-- Tactic to prove function properties
FunctionData where /-- local context where `mainVar` exists -/ lctx : LocalContext /-- local instances -/ insts : LocalInstances /-- main function -/ fn : Expr /-- applied function arguments -/ args : Array Mor.Arg /-- main variable -/ mainVar : Expr /-- indices of `args` that contain `mainVars` -/ mainArgs : Array Nat
structure
Tactic
[ "Qq", "Mathlib.Tactic.FunProp.Mor", "Mathlib.Tactic.FunProp.ToBatteries" ]
Mathlib/Tactic/FunProp/FunctionData.lean
FunctionData
Structure storing parts of a function in funProp-normal form.
FunctionData.toExpr (f : FunctionData) : MetaM Expr := do withLCtx f.lctx f.insts do let body := Mor.mkAppN f.fn f.args mkLambdaFVars #[f.mainVar] body
def
Tactic
[ "Qq", "Mathlib.Tactic.FunProp.Mor", "Mathlib.Tactic.FunProp.ToBatteries" ]
Mathlib/Tactic/FunProp/FunctionData.lean
FunctionData.toExpr
Turn function data back to expression.
FunctionData.isIdentityFun (f : FunctionData) : Bool := (f.args.size = 0 && f.fn == f.mainVar)
def
Tactic
[ "Qq", "Mathlib.Tactic.FunProp.Mor", "Mathlib.Tactic.FunProp.ToBatteries" ]
Mathlib/Tactic/FunProp/FunctionData.lean
FunctionData.isIdentityFun
Is `f` an identity function?
FunctionData.isConstantFun (f : FunctionData) : Bool := ((f.mainArgs.size = 0) && !(f.fn.containsFVar f.mainVar.fvarId!))
def
Tactic
[ "Qq", "Mathlib.Tactic.FunProp.Mor", "Mathlib.Tactic.FunProp.ToBatteries" ]
Mathlib/Tactic/FunProp/FunctionData.lean
FunctionData.isConstantFun
Is `f` a constant function?
FunctionData.domainType (f : FunctionData) : MetaM Expr := withLCtx f.lctx f.insts do inferType f.mainVar
def
Tactic
[ "Qq", "Mathlib.Tactic.FunProp.Mor", "Mathlib.Tactic.FunProp.ToBatteries" ]
Mathlib/Tactic/FunProp/FunctionData.lean
FunctionData.domainType
Domain type of `f`.
FunctionData.getFnConstName? (f : FunctionData) : MetaM (Option Name) := do match f.fn with | .const n _ => return n | .proj typeName idx _ => let some info := getStructureInfo? (← getEnv) typeName | return none let some projName := info.getProjFn? idx | return none return projName | _ => return none
def
Tactic
[ "Qq", "Mathlib.Tactic.FunProp.Mor", "Mathlib.Tactic.FunProp.ToBatteries" ]
Mathlib/Tactic/FunProp/FunctionData.lean
FunctionData.getFnConstName
Is head function of `f` a constant? If the head of `f` is a projection return the name of corresponding projection function.
getFunctionData (f : Expr) : MetaM FunctionData := do lambdaTelescope f fun xs b => do let xId := xs[0]!.fvarId! Mor.withApp b fun fn args => do let mut fn := fn let mut args := args if let .proj n i x := fn then let some info := getStructureInfo? (← getEnv) n | unreachable! let some projName := info.getProjFn? i | unreachable! let p ← mkAppM projName #[x] fn := p.getAppFn args := p.getAppArgs.map (fun a => {expr:=a}) ++ args let mainArgs := args |>.mapIdx (fun i ⟨arg,_⟩ => if arg.containsFVar xId then some i else none) |>.filterMap id return { lctx := ← getLCtx insts := ← getLocalInstances fn := fn args := args mainVar := xs[0]! mainArgs := mainArgs }
def
Tactic
[ "Qq", "Mathlib.Tactic.FunProp.Mor", "Mathlib.Tactic.FunProp.ToBatteries" ]
Mathlib/Tactic/FunProp/FunctionData.lean
getFunctionData
Get `FunctionData` for `f`. Throws if `f` can't be put into funProp-normal form.
MaybeFunctionData where /-- Can't generate function data as function body has let binder. -/ | letE (f : Expr) /-- Can't generate function data as function body has lambda binder. -/ | lam (f : Expr) /-- Function data has been successfully generated. -/ | data (fData : FunctionData)
inductive
Tactic
[ "Qq", "Mathlib.Tactic.FunProp.Mor", "Mathlib.Tactic.FunProp.ToBatteries" ]
Mathlib/Tactic/FunProp/FunctionData.lean
MaybeFunctionData
Result of `getFunctionData?`. It returns function data if the function is in the form `fun x => f y₁ ... yₙ`. Two other cases are `fun x => let y := ...` or `fun x y => ...`