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 ⌀ |
|---|---|---|---|---|---|---|
rank_powerset (x : PSet) : rank (powerset x) = succ (rank x) := by
apply le_antisymm
· simp_rw [rank_le_iff, mem_powerset, lt_succ_iff]
intro
exact rank_mono
· rw [succ_le_iff]
apply rank_lt_of_mem
simp | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_powerset | null |
rank_sUnion_le (x : PSet) : rank (⋃₀ x) ≤ rank x := by
simp_rw [rank_le_iff, mem_sUnion]
intro _ ⟨_, _, _⟩
trans <;> apply rank_lt_of_mem <;> assumption | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_sUnion_le | For the rank of `⋃₀ x`, we only have `rank (⋃₀ x) ≤ rank x ≤ rank (⋃₀ x) + 1`.
This inequality is split into `rank_sUnion_le` and `le_succ_rank_sUnion`. |
le_succ_rank_sUnion (x : PSet) : rank x ≤ succ (rank (⋃₀ x)) := by
rw [← rank_powerset]
apply rank_mono
rw [subset_iff]
intro z _
rw [mem_powerset, subset_iff]
intro _ _
rw [mem_sUnion]
exists z | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | le_succ_rank_sUnion | null |
rank_eq_wfRank : lift.{u + 1, u} (rank x) = IsWellFounded.rank (α := PSet) (· ∈ ·) x := by
induction x using mem_wf.induction with | _ x ih
rw [IsWellFounded.rank_eq]
simp_rw [← fun y : { y // y ∈ x } => ih y y.2]
apply (le_of_forall_lt _).antisymm (Ordinal.iSup_le _) <;> intro h
· rw [lt_lift_iff]
rintro ⟨o, h, rfl⟩
simpa [Ordinal.lt_iSup_iff] using lt_rank_iff.1 h
· simpa using rank_lt_of_mem h.2 | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_eq_wfRank | `PSet.rank` is equal to the `IsWellFounded.rank` over `∈`. |
noncomputable rank : ZFSet.{u} → Ordinal.{u} :=
Quotient.lift _ fun _ _ => PSet.rank_congr | def | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank | The ordinal rank of a ZFC set |
rank_lt_of_mem : y ∈ x → rank y < rank x :=
Quotient.inductionOn₂ x y fun _ _ => PSet.rank_lt_of_mem | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_lt_of_mem | null |
rank_le_iff {o : Ordinal} : rank x ≤ o ↔ ∀ ⦃y⦄, y ∈ x → rank y < o :=
⟨fun h _ h' => (rank_lt_of_mem h').trans_le h,
Quotient.inductionOn x fun _ h =>
PSet.rank_le_iff.2 fun y h' => @h ⟦y⟧ h'⟩ | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_le_iff | null |
lt_rank_iff {o : Ordinal} : o < rank x ↔ ∃ y ∈ x, o ≤ rank y := by
rw [← not_iff_not, not_lt, rank_le_iff]
simp
@[gcongr] theorem rank_mono (h : x ⊆ y) : rank x ≤ rank y :=
rank_le_iff.2 fun _ h₁ => rank_lt_of_mem (h h₁)
@[simp] | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | lt_rank_iff | null |
rank_empty : rank ∅ = 0 := PSet.rank_empty
@[simp] | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_empty | null |
rank_insert (x y : ZFSet) : rank (insert x y) = max (succ (rank x)) (rank y) :=
Quotient.inductionOn₂ x y PSet.rank_insert
@[simp] | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_insert | null |
rank_singleton (x : ZFSet) : rank {x} = succ (rank x) :=
(rank_insert _ _).trans (by simp) | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_singleton | null |
rank_pair (x y : ZFSet) : rank {x, y} = max (succ (rank x)) (succ (rank y)) := by
simp
@[simp] | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_pair | null |
rank_union (x y : ZFSet) : rank (x ∪ y) = max (rank x) (rank y) := by
apply le_antisymm
· simp_rw [rank_le_iff, mem_union, lt_max_iff]
intro
apply Or.imp <;> apply rank_lt_of_mem
· apply max_le <;> apply rank_mono <;> intro _ h <;> simp [h]
@[simp] | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_union | null |
rank_powerset (x : ZFSet) : rank (powerset x) = succ (rank x) :=
Quotient.inductionOn x PSet.rank_powerset | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_powerset | null |
rank_sUnion_le (x : ZFSet) : rank (⋃₀ x) ≤ rank x := by
simp_rw [rank_le_iff, mem_sUnion]
intro _ ⟨_, _, _⟩
trans <;> apply rank_lt_of_mem <;> assumption | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_sUnion_le | For the rank of `⋃₀ x`, we only have `rank (⋃₀ x) ≤ rank x ≤ rank (⋃₀ x) + 1`.
This inequality is split into `rank_sUnion_le` and `le_succ_rank_sUnion`. |
le_succ_rank_sUnion (x : ZFSet) : rank x ≤ succ (rank (⋃₀ x)) := by
rw [← rank_powerset]
apply rank_mono
intro z _
rw [mem_powerset]
intro _ _
rw [mem_sUnion]
exists z
@[simp] | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | le_succ_rank_sUnion | null |
rank_range {α : Type*} [Small.{u} α] (f : α → ZFSet.{u}) :
rank (range f) = ⨆ i, succ (rank (f i)) := by
apply (Ordinal.iSup_le _).antisymm'
· simpa [rank_le_iff, ← succ_le_iff] using Ordinal.le_iSup _
· simp [rank_lt_of_mem] | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_range | null |
rank_eq_wfRank : lift.{u + 1, u} (rank x) = IsWellFounded.rank (α := ZFSet) (· ∈ ·) x := by
induction x using inductionOn with | _ x ih
rw [IsWellFounded.rank_eq]
simp_rw [← fun y : { y // y ∈ x } => ih y y.2]
apply (le_of_forall_lt _).antisymm (Ordinal.iSup_le _) <;> intro h
· rw [lt_lift_iff]
rintro ⟨o, h, rfl⟩
simpa [Ordinal.lt_iSup_iff] using lt_rank_iff.1 h
· simpa using rank_lt_of_mem h.2 | theorem | SetTheory | [
"Mathlib.Logic.UnivLE",
"Mathlib.SetTheory.Ordinal.Rank",
"Mathlib.SetTheory.ZFC.Basic"
] | Mathlib/SetTheory/ZFC/Rank.lean | rank_eq_wfRank | `ZFSet.rank` is equal to the `IsWellFounded.rank` over `∈`. |
noncomputable vonNeumann (o : Ordinal.{u}) : ZFSet.{u} :=
⋃₀ range fun a : Set.Iio o ↦ powerset (vonNeumann a)
termination_by o
decreasing_by exact a.2
@[inherit_doc]
scoped notation "V_ " => vonNeumann
variable {a b o : Ordinal.{u}} {x : ZFSet.{u}} | def | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | vonNeumann | The von Neumann hierarchy is defined so that `V_ o` is the union of the powersets of all
`V_ a` for `a < o`. It satisfies the following properties:
- `vonNeumann_zero`: `V_ 0 = ∅`
- `vonNeumann_succ`: `V_ (succ a) = powerset (V_ a)`
- `vonNeumann_of_isSuccPrelimit`: `IsSuccPrelimit a → V_ a = ⋃ b < a, V_ b` |
mem_vonNeumann' : x ∈ V_ o ↔ ∃ a < o, x ⊆ V_ a := by rw [vonNeumann]; simp | lemma | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | mem_vonNeumann' | null |
isTransitive_vonNeumann (o : Ordinal) : IsTransitive (V_ o) := by
rw [vonNeumann]
refine IsTransitive.sUnion' fun x hx ↦ ?_
obtain ⟨⟨a, _⟩, rfl⟩ := mem_range.1 hx
exact (isTransitive_vonNeumann a).powerset
termination_by o
@[gcongr] theorem vonNeumann_mem_of_lt (h : a < b) : V_ a ∈ V_ b := by
rw [vonNeumann]; aesop
@[gcongr] theorem vonNeumann_subset_of_le (h : a ≤ b) : V_ a ⊆ V_ b :=
h.eq_or_lt.rec (by simp_all) fun h ↦ isTransitive_vonNeumann _ _ <| vonNeumann_mem_of_lt h | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | isTransitive_vonNeumann | null |
subset_vonNeumann {o : Ordinal} {x : ZFSet} : x ⊆ V_ o ↔ rank x ≤ o := by
rw [rank_le_iff]
constructor <;> intro hx y hy
· apply (rank_lt_of_mem (hx hy)).trans_le
simp_rw [rank_le_iff, mem_vonNeumann']
rintro z ⟨a, ha, hz⟩
exact (subset_vonNeumann.1 hz).trans_lt ha
· rw [mem_vonNeumann']
have := hx hy
exact ⟨_, this, subset_vonNeumann.2 le_rfl⟩
termination_by o | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | subset_vonNeumann | null |
subset_vonNeumann_self (x : ZFSet) : x ⊆ V_ (rank x) := by
simp [subset_vonNeumann] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | subset_vonNeumann_self | null |
mem_vonNeumann : x ∈ V_ o ↔ rank x < o := by
simp_rw [mem_vonNeumann', subset_vonNeumann]
exact ⟨fun ⟨a, h₁, h₂⟩ ↦ h₂.trans_lt h₁, by aesop⟩ | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | mem_vonNeumann | null |
mem_vonNeumann_succ (x : ZFSet) : x ∈ V_ (succ (rank x)) := by
simp [mem_vonNeumann] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | mem_vonNeumann_succ | null |
exists_mem_vonNeumann (x : ZFSet) : ∃ o, x ∈ V_ o :=
⟨_, mem_vonNeumann_succ x⟩
@[simp] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | exists_mem_vonNeumann | Every set is in some element of the von Neumann hierarchy. |
rank_vonNeumann (o : Ordinal) : rank (V_ o) = o :=
le_antisymm (by rw [← subset_vonNeumann]) <| le_of_forall_lt fun a ha ↦
rank_vonNeumann a ▸ rank_lt_of_mem (vonNeumann_mem_of_lt ha)
termination_by o
@[simp] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | rank_vonNeumann | null |
vonNeumann_mem_vonNeumann_iff : V_ a ∈ V_ b ↔ a < b := by
simp [mem_vonNeumann]
@[simp] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | vonNeumann_mem_vonNeumann_iff | null |
vonNeumann_subset_vonNeumann_iff : V_ a ⊆ V_ b ↔ a ≤ b := by
simp [subset_vonNeumann] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | vonNeumann_subset_vonNeumann_iff | null |
mem_vonNeumann_of_subset {y : ZFSet} (h : x ⊆ y) (hy : y ∈ V_ o) : x ∈ V_ o := by
rw [mem_vonNeumann] at *
exact (rank_mono h).trans_lt hy | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | mem_vonNeumann_of_subset | null |
vonNeumann_strictMono : StrictMono vonNeumann :=
strictMono_of_le_iff_le (by simp) | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | vonNeumann_strictMono | null |
vonNeumann_injective : Function.Injective vonNeumann :=
vonNeumann_strictMono.injective
@[simp] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | vonNeumann_injective | null |
vonNeumann_inj : V_ a = V_ b ↔ a = b :=
vonNeumann_injective.eq_iff
@[gcongr]
alias ⟨_, _root_.GCongr.ZFSet.vonNeumann_inj⟩ := vonNeumann_inj
@[simp] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | vonNeumann_inj | null |
vonNeumann_zero : V_ 0 = ∅ :=
(eq_empty _).2 (by simp [mem_vonNeumann])
@[simp] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | vonNeumann_zero | null |
vonNeumann_succ (o : Ordinal) : V_ (succ o) = powerset (V_ o) :=
ext fun z ↦ by rw [mem_vonNeumann, mem_powerset, subset_vonNeumann, lt_succ_iff] | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | vonNeumann_succ | null |
vonNeumann_of_isSuccPrelimit (h : IsSuccPrelimit o) :
V_ o = (⋃₀ range fun a : Set.Iio o ↦ vonNeumann a : ZFSet) :=
ext fun z ↦ by simpa [mem_vonNeumann] using h.lt_iff_exists_lt | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | vonNeumann_of_isSuccPrelimit | null |
iUnion_vonNeumann : ⋃ o, (V_ o : Class) = Class.univ :=
Class.eq_univ_of_forall fun x ↦ Set.mem_iUnion.2 <| exists_mem_vonNeumann x | theorem | SetTheory | [
"Mathlib.SetTheory.ZFC.Class",
"Mathlib.SetTheory.ZFC.Ordinal",
"Mathlib.SetTheory.ZFC.Rank"
] | Mathlib/SetTheory/ZFC/VonNeumann.lean | iUnion_vonNeumann | null |
@[deprecated Std.HashMap.map (since := "2025-08-18")]
mapVal (f : α → β → γ) (m : HashMap α β) : HashMap α γ :=
m.fold (fun acc k v => acc.insert k (f k v)) ∅ | def | Std | [
"Std.Data.HashMap.AdditionalOperations",
"Mathlib.Tactic.Linter.DeprecatedModule"
] | Mathlib/Std/Data/HashMap.lean | mapVal | Apply a function to the values of a hash map. |
isZero (e : Q($α)) : MetaM Bool :=
match e with
| ~q(@OfNat.ofNat.{u} _ (nat_lit 0) $i) => return true
| _ => return false | def | Tactic | [
"Mathlib.Tactic.Bound.Init",
"Qq",
"Aesop"
] | Mathlib/Tactic/Bound/Attribute.lean | isZero | Check if an expression is zero |
ineqPriority (a b : Q($α)) : MetaM Nat := do
return if (← isZero a) || (← isZero b) then 1 else 10 | def | Tactic | [
"Mathlib.Tactic.Bound.Init",
"Qq",
"Aesop"
] | Mathlib/Tactic/Bound/Attribute.lean | ineqPriority | Map the arguments of an inequality expression to a score |
partial hypPriority (hyp : Q(Prop)) : MetaM Nat := do
match hyp with
| ~q($a ∧ $b) => pure <| (← hypPriority a) + (← hypPriority b)
| ~q($a ∨ $b) => pure <| 100 + (← hypPriority a) + (← hypPriority b)
| ~q(@LE.le _ $i $a $b) => ineqPriority a b
| ~q(@LT.lt _ $i $a $b) => ineqPriority a b
| ~q(@GE.ge _ $i $b $a) => ineqPriority a b
| ~q(@GT.gt _ $i $b $a) => ineqPriority a b
| _ => pure 0 | def | Tactic | [
"Mathlib.Tactic.Bound.Init",
"Qq",
"Aesop"
] | Mathlib/Tactic/Bound/Attribute.lean | hypPriority | Map a hypothesis type to a score |
typePriority (decl : Lean.Name) (type : Lean.Expr) : MetaM Nat :=
Lean.Meta.forallTelescope type fun xs t ↦ do
checkResult t
xs.foldlM (fun (t : Nat) x ↦ do return t + (← argPriority x)) 0
where
/-- Score the type of argument `x` -/
argPriority (x : Lean.Expr) : MetaM Nat := do
hypPriority (← Lean.Meta.inferType x)
/-- Insist that our conclusion is an inequality -/
checkResult (t : Q(Prop)) : MetaM Unit := do match t with
| ~q(@LE.le _ $i $a $b) => return ()
| ~q(@LT.lt _ $i $a $b) => return ()
| ~q(@GE.ge _ $i $b $a) => return ()
| ~q(@GT.gt _ $i $b $a) => return ()
| _ => throwError (f!"`{decl}` has invalid type `{type}` as a 'bound' lemma: \
it should be an inequality") | def | Tactic | [
"Mathlib.Tactic.Bound.Init",
"Qq",
"Aesop"
] | Mathlib/Tactic/Bound/Attribute.lean | typePriority | Map a type to a score |
declPriority (decl : Lean.Name) : Lean.MetaM Nat := do
match (← Lean.getEnv).find? decl with
| some info => do
typePriority decl info.type
| none => throwError "unknown declaration {decl}" | def | Tactic | [
"Mathlib.Tactic.Bound.Init",
"Qq",
"Aesop"
] | Mathlib/Tactic/Bound/Attribute.lean | declPriority | Map a theorem decl to a score (0 means `norm apply`, `0 <` means `safe apply`) |
scoreToConfig (decl : Lean.Name) (score : Nat) : Aesop.Frontend.RuleConfig :=
let (phase, priority) := match score with
| 0 => (Aesop.PhaseName.norm, 0) -- No hypotheses: this rule closes the goal immediately
| s => (Aesop.PhaseName.safe, s)
{ term? := some (Lean.mkIdent decl)
phase? := phase
priority? := some (Aesop.Frontend.Priority.int priority)
builder? := some (.regular .apply)
builderOptions := {}
ruleSets := ⟨#[`Bound]⟩ } | def | Tactic | [
"Mathlib.Tactic.Bound.Init",
"Qq",
"Aesop"
] | Mathlib/Tactic/Bound/Attribute.lean | scoreToConfig | Map a score to either `norm apply` or `safe apply <priority>` |
mul_subst {α} [CommRing α] {n1 n2 k e1 e2 t1 t2 : α}
(h1 : n1 * e1 = t1) (h2 : n2 * e2 = t2) (h3 : n1 * n2 = k) : k * (e1 * e2) = t1 * t2 := by
rw [← h3, mul_comm n1, mul_assoc n2, ← mul_assoc n1, h1,
← mul_assoc n2, mul_comm n2, mul_assoc, h2] | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | mul_subst | null |
div_subst {α} [Field α] {n1 n2 k e1 e2 t1 : α}
(h1 : n1 * e1 = t1) (h2 : n2 / e2 = 1) (h3 : n1 * n2 = k) : k * (e1 / e2) = t1 := by
rw [← h3, mul_assoc, mul_div_left_comm, h2, ← mul_assoc, h1, mul_comm, one_mul] | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | div_subst | null |
cancel_factors_eq_div {α} [Field α] {n e e' : α}
(h : n * e = e') (h2 : n ≠ 0) : e = e' / n :=
eq_div_of_mul_eq h2 <| by rwa [mul_comm] at h | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | cancel_factors_eq_div | null |
add_subst {α} [Ring α] {n e1 e2 t1 t2 : α} (h1 : n * e1 = t1) (h2 : n * e2 = t2) :
n * (e1 + e2) = t1 + t2 := by simp [left_distrib, *] | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | add_subst | null |
sub_subst {α} [Ring α] {n e1 e2 t1 t2 : α} (h1 : n * e1 = t1) (h2 : n * e2 = t2) :
n * (e1 - e2) = t1 - t2 := by simp [left_distrib, *, sub_eq_add_neg] | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | sub_subst | null |
neg_subst {α} [Ring α] {n e t : α} (h1 : n * e = t) : n * -e = -t := by simp [*] | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | neg_subst | null |
pow_subst {α} [CommRing α] {n e1 t1 k l : α} {e2 : ℕ}
(h1 : n * e1 = t1) (h2 : l * n ^ e2 = k) : k * (e1 ^ e2) = l * t1 ^ e2 := by
rw [← h2, ← h1, mul_pow, mul_assoc] | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | pow_subst | null |
inv_subst {α} [Field α] {n k e : α} (h2 : e ≠ 0) (h3 : n * e = k) :
k * (e ⁻¹) = n := by rw [← div_eq_mul_inv, ← h3, mul_div_cancel_right₀ _ h2] | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | inv_subst | null |
cancel_factors_lt {α} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
{a b ad bd a' b' gcd : α}
(ha : ad * a = a') (hb : bd * b = b') (had : 0 < ad) (hbd : 0 < bd) (hgcd : 0 < gcd) :
(a < b) = (1 / gcd * (bd * a') < 1 / gcd * (ad * b')) := by
rw [mul_lt_mul_iff_right₀, ← ha, ← hb, ← mul_assoc, ← mul_assoc, mul_comm bd,
mul_lt_mul_iff_right₀]
· exact mul_pos had hbd
· exact one_div_pos.2 hgcd | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | cancel_factors_lt | null |
cancel_factors_le {α} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
{a b ad bd a' b' gcd : α}
(ha : ad * a = a') (hb : bd * b = b') (had : 0 < ad) (hbd : 0 < bd) (hgcd : 0 < gcd) :
(a ≤ b) = (1 / gcd * (bd * a') ≤ 1 / gcd * (ad * b')) := by
rw [mul_le_mul_iff_right₀, ← ha, ← hb, ← mul_assoc, ← mul_assoc, mul_comm bd,
mul_le_mul_iff_right₀]
· exact mul_pos had hbd
· exact one_div_pos.2 hgcd | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | cancel_factors_le | null |
cancel_factors_eq {α} [Field α] {a b ad bd a' b' gcd : α} (ha : ad * a = a')
(hb : bd * b = b') (had : ad ≠ 0) (hbd : bd ≠ 0) (hgcd : gcd ≠ 0) :
(a = b) = (1 / gcd * (bd * a') = 1 / gcd * (ad * b')) := by
rw [← ha, ← hb, ← mul_assoc bd, ← mul_assoc ad, mul_comm bd]
ext; constructor
· rintro rfl
rfl
· intro h
simp only [← mul_assoc] at h
refine mul_left_cancel₀ (mul_ne_zero ?_ ?_) h
on_goal 1 => apply mul_ne_zero
on_goal 1 => apply div_ne_zero
· exact one_ne_zero
all_goals assumption | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | cancel_factors_eq | null |
cancel_factors_ne {α} [Field α] {a b ad bd a' b' gcd : α} (ha : ad * a = a')
(hb : bd * b = b') (had : ad ≠ 0) (hbd : bd ≠ 0) (hgcd : gcd ≠ 0) :
(a ≠ b) = (1 / gcd * (bd * a') ≠ 1 / gcd * (ad * b')) := by
classical
rw [eq_iff_iff, not_iff_not, cancel_factors_eq ha hb had hbd hgcd]
/-! ### Computing cancellation factors -/ | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | cancel_factors_ne | null |
partial findCancelFactor (e : Expr) : ℕ × Tree ℕ :=
match e.getAppFnArgs with
| (``HAdd.hAdd, #[_, _, _, _, e1, e2]) | (``HSub.hSub, #[_, _, _, _, e1, e2]) =>
let (v1, t1) := findCancelFactor e1
let (v2, t2) := findCancelFactor e2
let lcm := v1.lcm v2
(lcm, .node lcm t1 t2)
| (``HMul.hMul, #[_, _, _, _, e1, e2]) =>
let (v1, t1) := findCancelFactor e1
let (v2, t2) := findCancelFactor e2
let pd := v1 * v2
(pd, .node pd t1 t2)
| (``HDiv.hDiv, #[_, _, _, _, e1, e2]) =>
match e2.nat? with
| some q =>
let (v1, t1) := findCancelFactor e1
let n := v1 * q
(n, .node n t1 <| .node q .nil .nil)
| none => (1, .node 1 .nil .nil)
| (``Neg.neg, #[_, _, e]) => findCancelFactor e
| (``HPow.hPow, #[_, ℕ, _, _, e1, e2]) =>
match e2.nat? with
| some k =>
let (v1, t1) := findCancelFactor e1
let n := v1 ^ k
(n, .node n t1 <| .node k .nil .nil)
| none => (1, .node 1 .nil .nil)
| (``Inv.inv, #[_, _, e]) =>
match e.nat? with
| some q => (q, .node q .nil <| .node q .nil .nil)
| none => (1, .node 1 .nil .nil)
| _ => (1, .node 1 .nil .nil) | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | findCancelFactor | `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`. |
synthesizeUsingNormNum (type : Q(Prop)) : MetaM Q($type) := do
try
synthesizeUsingTactic' type (← `(tactic| norm_num))
catch e =>
throwError "Could not prove {type} using norm_num. {e.toMessageData}" | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | synthesizeUsingNormNum | null |
CancelResult {u : Level} {α : Q(Type u)} (mα : Q(Mul $α)) (e : Q($α)) (v : Q($α)) where
/-- An expression with denominators cancelled. -/
cancelled : Q($α)
/-- The proof that `cancelled` is valid. -/
pf : Q($v * $e = $cancelled) | structure | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | CancelResult | `CancelResult mα e v'` provides a value for `v * e` where the denominators have been cancelled. |
partial mkProdPrf {u : Level} (α : Q(Type u)) (sα : Q(Field $α)) (v : ℕ) (v' : Q($α))
(t : Tree ℕ) (e : Q($α)) : MetaM (CancelResult q(inferInstance) e v') := do
let amwo : Q(AddMonoidWithOne $α) := q(inferInstance)
trace[CancelDenoms] "mkProdPrf {e} {v}"
match t, e with
| .node _ lhs rhs, ~q($e1 + $e2) => do
let ⟨v1, hv1⟩ ← mkProdPrf α sα v v' lhs e1
let ⟨v2, hv2⟩ ← mkProdPrf α sα v v' rhs e2
return ⟨q($v1 + $v2), q(CancelDenoms.add_subst $hv1 $hv2)⟩
| .node _ lhs rhs, ~q($e1 - $e2) => do
let ⟨v1, hv1⟩ ← mkProdPrf α sα v v' lhs e1
let ⟨v2, hv2⟩ ← mkProdPrf α sα v v' rhs e2
return ⟨q($v1 - $v2), q(CancelDenoms.sub_subst $hv1 $hv2)⟩
| .node _ lhs@(.node ln _ _) rhs, ~q($e1 * $e2) => do
trace[CancelDenoms] "recursing into mul"
have ln' := (← mkOfNat α amwo <| mkRawNatLit ln).1
have vln' := (← mkOfNat α amwo <| mkRawNatLit (v/ln)).1
let ⟨v1, hv1⟩ ← mkProdPrf α sα ln ln' lhs e1
let ⟨v2, hv2⟩ ← mkProdPrf α sα (v / ln) vln' rhs e2
let npf ← synthesizeUsingNormNum q($ln' * $vln' = $v')
return ⟨q($v1 * $v2), q(CancelDenoms.mul_subst $hv1 $hv2 $npf)⟩
| .node _ lhs (.node rn _ _), ~q($e1 / $e2) => do
have rn' := (← mkOfNat α amwo <| mkRawNatLit rn).1
have vrn' := (← mkOfNat α amwo <| mkRawNatLit <| v / rn).1
let ⟨v1, hv1⟩ ← mkProdPrf α sα (v / rn) vrn' lhs e1
let npf ← synthesizeUsingNormNum q($rn' / $e2 = 1)
let npf2 ← synthesizeUsingNormNum q($vrn' * $rn' = $v')
return ⟨q($v1), q(CancelDenoms.div_subst $hv1 $npf $npf2)⟩
| t, ~q(-$e) => do
let ⟨v, hv⟩ ← mkProdPrf α sα v v' t e
return ⟨q(-$v), q(CancelDenoms.neg_subst $hv)⟩
| .node _ lhs@(.node k1 _ _) (.node k2 .nil .nil), ~q($e1 ^ $e2) => do
have k1' := (← mkOfNat α amwo <| mkRawNatLit k1).1
let ⟨v1, hv1⟩ ← mkProdPrf α sα k1 k1' lhs e1
have l : ℕ := v / (k1 ^ k2)
have l' := (← mkOfNat α amwo <| mkRawNatLit l).1
let npf ← synthesizeUsingNormNum q($l' * $k1' ^ $e2 = $v')
return ⟨q($l' * $v1 ^ $e2), q(CancelDenoms.pow_subst $hv1 $npf)⟩
| .node _ .nil (.node rn _ _), ~q($ei ⁻¹) => do
have rn' := (← mkOfNat α amwo <| mkRawNatLit rn).1
have vrn' := (← mkOfNat α amwo <| mkRawNatLit <| v / rn).1
have _ : $rn' =Q $ei := ⟨⟩
let npf ← synthesizeUsingNormNum q($rn' ≠ 0)
let npf2 ← synthesizeUsingNormNum q($vrn' * $rn' = $v')
return ⟨q($vrn'), q(CancelDenoms.inv_subst $npf $npf2)⟩
| _, _ => do
return ⟨q($v' * $e), q(rfl)⟩ | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | mkProdPrf | `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. |
deriveThms : List Name :=
[``div_div_eq_mul_div, ``div_neg] | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | deriveThms | 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. |
derive_trans {α} [Mul α] {a b c d : α} (h : a = b) (h' : c * b = d) : c * a = d := h ▸ h' | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | derive_trans | Helper lemma to chain together a `simp` proof and the result of `mkProdPrf`. |
derive_trans₂ {α} [Mul α] {a b c d e : α} (h : a = b) (h' : b = c) (h'' : d * c = e) :
d * a = e := h ▸ h' ▸ h'' | theorem | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | derive_trans₂ | Helper lemma to chain together two `simp` proofs and the result of `mkProdPrf`. |
derive (e : Expr) : MetaM (ℕ × Expr) := do
trace[CancelDenoms] "e = {e}"
let eSimp ← simpOnlyNames (config := Simp.neutralConfig) deriveThms e
trace[CancelDenoms] "e simplified = {eSimp.expr}"
let eSimpNormNum ← Mathlib.Meta.NormNum.deriveSimp (← Simp.mkContext) false eSimp.expr
trace[CancelDenoms] "e norm_num'd = {eSimpNormNum.expr}"
let (n, t) := findCancelFactor eSimpNormNum.expr
let ⟨u, tp, e⟩ ← inferTypeQ' eSimpNormNum.expr
let stp : Q(Field $tp) ← synthInstanceQ q(Field $tp)
try
have n' := (← mkOfNat tp q(inferInstance) <| mkRawNatLit <| n).1
let r ← mkProdPrf tp stp n n' t e
trace[CancelDenoms] "pf : {← inferType r.pf}"
let pf' ←
match eSimp.proof?, eSimpNormNum.proof? with
| some pfSimp, some pfSimp' => mkAppM ``derive_trans₂ #[pfSimp, pfSimp', r.pf]
| some pfSimp, none | none, some pfSimp => mkAppM ``derive_trans #[pfSimp, r.pf]
| none, none => pure r.pf
return (n, pf')
catch E => do
throwError "CancelDenoms.derive failed to normalize {e}.\n{E.toMessageData}" | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | derive | 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. |
findCompLemma (e : Expr) : MetaM (Option (Expr × Expr × Name × Bool)) := do
match (← whnfR e).getAppFnArgs with
| (``LT.lt, #[_, _, a, b]) => return (a, b, ``cancel_factors_lt, true)
| (``LE.le, #[_, _, a, b]) => return (a, b, ``cancel_factors_le, true)
| (``Eq, #[_, a, b]) => return (a, b, ``cancel_factors_eq, false)
| (``Not, #[p]) => match (← whnfR p).getAppFnArgs with
| (``Eq, #[_, a, b]) => return (a, b, ``cancel_factors_ne, false)
| _ => return none
| (``GE.ge, #[_, _, a, b]) => return (b, a, ``cancel_factors_le, true)
| (``GT.gt, #[_, _, a, b]) => return (b, a, ``cancel_factors_lt, true)
| _ => return none | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | findCompLemma | `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. |
cancelDenominatorsInType (h : Expr) : MetaM (Expr × Expr) := do
let some (lhs, rhs, lem, ord) ← findCompLemma h | throwError m!"cannot kill factors"
let (al, lhs_p) ← derive lhs
let ⟨u, α, _⟩ ← inferTypeQ' lhs
let amwo ← synthInstanceQ q(AddMonoidWithOne $α)
let (ar, rhs_p) ← derive rhs
let gcd := al.gcd ar
have al := (← mkOfNat α amwo <| mkRawNatLit al).1
have ar := (← mkOfNat α amwo <| mkRawNatLit ar).1
have gcd := (← mkOfNat α amwo <| mkRawNatLit gcd).1
let (al_cond, ar_cond, gcd_cond) ← if ord then do
let _ ← synthInstanceQ q(Field $α)
let _ ← synthInstanceQ q(LinearOrder $α)
let _ ← synthInstanceQ q(IsStrictOrderedRing $α)
let al_pos : Q(Prop) := q(0 < $al)
let ar_pos : Q(Prop) := q(0 < $ar)
let gcd_pos : Q(Prop) := q(0 < $gcd)
pure (al_pos, ar_pos, gcd_pos)
else do
let _ ← synthInstanceQ q(Field $α)
let al_ne : Q(Prop) := q($al ≠ 0)
let ar_ne : Q(Prop) := q($ar ≠ 0)
let gcd_ne : Q(Prop) := q($gcd ≠ 0)
pure (al_ne, ar_ne, gcd_ne)
let al_cond ← synthesizeUsingNormNum al_cond
let ar_cond ← synthesizeUsingNormNum ar_cond
let gcd_cond ← synthesizeUsingNormNum gcd_cond
let pf ← mkAppM lem #[lhs_p, rhs_p, al_cond, ar_cond, gcd_cond]
let pf_tp ← inferType pf
return ((← findCompLemma pf_tp).elim default (Prod.fst ∘ Prod.snd), pf) | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | cancelDenominatorsInType | `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'`. |
cancelDenominatorsAt (fvar : FVarId) : TacticM Unit := do
let t ← instantiateMVars (← fvar.getDecl).type
let (new, eqPrf) ← CancelDenoms.cancelDenominatorsInType t
liftMetaTactic' fun g => do
let res ← g.replaceLocalDecl fvar new eqPrf
return res.mvarId | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | cancelDenominatorsAt | null |
cancelDenominatorsTarget : TacticM Unit := do
let (new, eqPrf) ← CancelDenoms.cancelDenominatorsInType (← getMainTarget)
liftMetaTactic' fun g => g.replaceTargetEq new eqPrf | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | cancelDenominatorsTarget | null |
cancelDenominators (loc : Location) : TacticM Unit := do
withLocation loc cancelDenominatorsAt cancelDenominatorsTarget
(fun _ ↦ throwError "Failed to cancel any denominators")
elab "cancel_denoms" loc?:(location)? : tactic => do
cancelDenominators (expandOptLocation (Lean.mkOptionalNode loc?))
Lean.Elab.Tactic.evalTactic (← `(tactic| try norm_num [← mul_assoc] $[$loc?]?)) | def | Tactic | [
"Mathlib.Algebra.Field.Basic",
"Mathlib.Algebra.Order.Ring.Defs",
"Mathlib.Data.Tree.Basic",
"Mathlib.Logic.Basic",
"Mathlib.Tactic.NormNum.Core",
"Mathlib.Util.SynthesizeUsing",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/CancelDenoms/Core.lean | cancelDenominators | null |
BicategoricalCoherence (f g : a ⟶ b) where
/-- The chosen structural isomorphism between to 1-morphisms. -/
iso : f ≅ g | class | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | BicategoricalCoherence | A typeclass carrying a choice of bicategorical structural isomorphism between two objects.
Used by the `⊗≫` bicategorical composition operator, and the `coherence` tactic. |
bicategoricalIso (f g : a ⟶ b) [BicategoricalCoherence f g] : f ≅ g :=
⊗𝟙 | abbrev | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | bicategoricalIso | Notation for identities up to unitors and associators. -/
scoped[CategoryTheory.Bicategory] notation " ⊗𝟙 " =>
BicategoricalCoherence.iso -- type as \ot 𝟙
/-- Construct an isomorphism between two objects in a bicategorical category
out of unitors and associators. |
bicategoricalComp {f g h i : a ⟶ b} [BicategoricalCoherence g h]
(η : f ⟶ g) (θ : h ⟶ i) : f ⟶ i :=
η ≫ ⊗𝟙.hom ≫ θ
@[inherit_doc bicategoricalComp]
scoped[CategoryTheory.Bicategory] infixr:80 " ⊗≫ " => bicategoricalComp | def | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | bicategoricalComp | Compose two morphisms in a bicategorical category,
inserting unitors and associators between as necessary. |
bicategoricalIsoComp {f g h i : a ⟶ b} [BicategoricalCoherence g h]
(η : f ≅ g) (θ : h ≅ i) : f ≅ i :=
η ≪≫ ⊗𝟙 ≪≫ θ
@[inherit_doc bicategoricalIsoComp]
scoped[CategoryTheory.Bicategory] infixr:80 " ≪⊗≫ " =>
bicategoricalIsoComp -- type as \ll \ot \gg | def | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | bicategoricalIsoComp | Compose two isomorphisms in a bicategorical category,
inserting unitors and associators between as necessary. |
@[simps]
refl (f : a ⟶ b) : BicategoricalCoherence f f :=
⟨Iso.refl _⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | refl | null |
whiskerLeft (f : a ⟶ b) (g h : b ⟶ c)
[BicategoricalCoherence g h] : BicategoricalCoherence (f ≫ g) (f ≫ h) :=
⟨whiskerLeftIso f ⊗𝟙⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | whiskerLeft | null |
whiskerRight (f g : a ⟶ b) (h : b ⟶ c)
[BicategoricalCoherence f g] : BicategoricalCoherence (f ≫ h) (g ≫ h) :=
⟨whiskerRightIso ⊗𝟙 h⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | whiskerRight | null |
tensorRight (f : a ⟶ b) (g : b ⟶ b)
[BicategoricalCoherence (𝟙 b) g] : BicategoricalCoherence f (f ≫ g) :=
⟨(ρ_ f).symm ≪≫ (whiskerLeftIso f ⊗𝟙)⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | tensorRight | null |
tensorRight' (f : a ⟶ b) (g : b ⟶ b)
[BicategoricalCoherence g (𝟙 b)] : BicategoricalCoherence (f ≫ g) f :=
⟨whiskerLeftIso f ⊗𝟙 ≪≫ (ρ_ f)⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | tensorRight' | null |
left (f g : a ⟶ b) [BicategoricalCoherence f g] :
BicategoricalCoherence (𝟙 a ≫ f) g :=
⟨λ_ f ≪≫ ⊗𝟙⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | left | null |
left' (f g : a ⟶ b) [BicategoricalCoherence f g] :
BicategoricalCoherence f (𝟙 a ≫ g) :=
⟨⊗𝟙 ≪≫ (λ_ g).symm⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | left' | null |
right (f g : a ⟶ b) [BicategoricalCoherence f g] :
BicategoricalCoherence (f ≫ 𝟙 b) g :=
⟨ρ_ f ≪≫ ⊗𝟙⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | right | null |
right' (f g : a ⟶ b) [BicategoricalCoherence f g] :
BicategoricalCoherence f (g ≫ 𝟙 b) :=
⟨⊗𝟙 ≪≫ (ρ_ g).symm⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | right' | null |
assoc (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : a ⟶ d)
[BicategoricalCoherence (f ≫ g ≫ h) i] :
BicategoricalCoherence ((f ≫ g) ≫ h) i :=
⟨α_ f g h ≪≫ ⊗𝟙⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | assoc | null |
assoc' (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : a ⟶ d)
[BicategoricalCoherence i (f ≫ g ≫ h)] :
BicategoricalCoherence i ((f ≫ g) ≫ h) :=
⟨⊗𝟙 ≪≫ (α_ f g h).symm⟩ | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | assoc' | null |
@[simp]
bicategoricalComp_refl {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) : η ⊗≫ θ = η ≫ θ := by
dsimp [bicategoricalComp]; simp | theorem | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Basic"
] | Mathlib/Tactic/CategoryTheory/BicategoricalComp.lean | bicategoricalComp_refl | null |
LiftHom {a b : B} (f : a ⟶ b) where
/-- A lift of a morphism to the free bicategory.
This should only exist for "structural" morphisms. -/
lift : of.obj a ⟶ of.obj b | class | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | LiftHom | A typeclass carrying a choice of lift of a 1-morphism from `B` to `FreeBicategory B`. |
liftHomId : LiftHom (𝟙 a) where lift := 𝟙 (of.obj a) | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHomId | null |
liftHomComp (f : a ⟶ b) (g : b ⟶ c) [LiftHom f] [LiftHom g] : LiftHom (f ≫ g) where
lift := LiftHom.lift f ≫ LiftHom.lift g | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHomComp | null |
LiftHom₂ {f g : a ⟶ b} [LiftHom f] [LiftHom g] (η : f ⟶ g) where
/-- A lift of a 2-morphism to the free bicategory.
This should only exist for "structural" 2-morphisms. -/
lift : LiftHom.lift f ⟶ LiftHom.lift g | class | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | LiftHom₂ | A typeclass carrying a choice of lift of a 2-morphism from `B` to `FreeBicategory B`. |
liftHom₂Id (f : a ⟶ b) [LiftHom f] : LiftHom₂ (𝟙 f) where
lift := 𝟙 _ | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂Id | null |
liftHom₂LeftUnitorHom (f : a ⟶ b) [LiftHom f] : LiftHom₂ (λ_ f).hom where
lift := (λ_ (LiftHom.lift f)).hom | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂LeftUnitorHom | null |
liftHom₂LeftUnitorInv (f : a ⟶ b) [LiftHom f] : LiftHom₂ (λ_ f).inv where
lift := (λ_ (LiftHom.lift f)).inv | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂LeftUnitorInv | null |
liftHom₂RightUnitorHom (f : a ⟶ b) [LiftHom f] : LiftHom₂ (ρ_ f).hom where
lift := (ρ_ (LiftHom.lift f)).hom | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂RightUnitorHom | null |
liftHom₂RightUnitorInv (f : a ⟶ b) [LiftHom f] : LiftHom₂ (ρ_ f).inv where
lift := (ρ_ (LiftHom.lift f)).inv | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂RightUnitorInv | null |
liftHom₂AssociatorHom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) [LiftHom f] [LiftHom g]
[LiftHom h] : LiftHom₂ (α_ f g h).hom where
lift := (α_ (LiftHom.lift f) (LiftHom.lift g) (LiftHom.lift h)).hom | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂AssociatorHom | null |
liftHom₂AssociatorInv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) [LiftHom f] [LiftHom g]
[LiftHom h] : LiftHom₂ (α_ f g h).inv where
lift := (α_ (LiftHom.lift f) (LiftHom.lift g) (LiftHom.lift h)).inv | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂AssociatorInv | null |
liftHom₂Comp {f g h : a ⟶ b} [LiftHom f] [LiftHom g] [LiftHom h] (η : f ⟶ g) (θ : g ⟶ h)
[LiftHom₂ η] [LiftHom₂ θ] : LiftHom₂ (η ≫ θ) where
lift := LiftHom₂.lift η ≫ LiftHom₂.lift θ | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂Comp | null |
liftHom₂WhiskerLeft (f : a ⟶ b) [LiftHom f] {g h : b ⟶ c} (η : g ⟶ h) [LiftHom g]
[LiftHom h] [LiftHom₂ η] : LiftHom₂ (f ◁ η) where
lift := LiftHom.lift f ◁ LiftHom₂.lift η | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂WhiskerLeft | null |
liftHom₂WhiskerRight {f g : a ⟶ b} (η : f ⟶ g) [LiftHom f] [LiftHom g] [LiftHom₂ η]
{h : b ⟶ c} [LiftHom h] : LiftHom₂ (η ▷ h) where
lift := LiftHom₂.lift η ▷ LiftHom.lift h
open Lean Elab Tactic Meta | instance | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | liftHom₂WhiskerRight | null |
exception {α : Type} (g : MVarId) (msg : MessageData) : MetaM α :=
throwTacticEx `bicategorical_coherence g msg | def | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | exception | Helper function for throwing exceptions. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.