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
eq_ite_iff : a = ite P b c ↔ P ∧ a = b ∨ ¬P ∧ a = c := eq_comm.trans <| ite_eq_iff.trans <| (Iff.rfl.and eq_comm).or (Iff.rfl.and eq_comm)
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
eq_ite_iff
null
dite_eq_iff' : dite P A B = c ↔ (∀ h, A h = c) ∧ ∀ h, B h = c := ⟨fun he ↦ ⟨fun h ↦ (dif_pos h).symm.trans he, fun h ↦ (dif_neg h).symm.trans he⟩, fun he ↦ (em P).elim (fun h ↦ (dif_pos h).trans <| he.1 h) fun h ↦ (dif_neg h).trans <| he.2 h⟩
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
dite_eq_iff'
null
ite_eq_iff' : ite P a b = c ↔ (P → a = c) ∧ (¬P → b = c) := dite_eq_iff'
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_eq_iff'
null
dite_ne_left_iff : dite P (fun _ ↦ a) B ≠ a ↔ ∃ h, a ≠ B h := by grind
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
dite_ne_left_iff
null
dite_ne_right_iff : (dite P A fun _ ↦ b) ≠ b ↔ ∃ h, A h ≠ b := by simp only [Ne, dite_eq_right_iff, not_forall]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
dite_ne_right_iff
null
ite_ne_left_iff : ite P a b ≠ a ↔ ¬P ∧ a ≠ b := dite_ne_left_iff.trans <| by rw [exists_prop]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_ne_left_iff
null
ite_ne_right_iff : ite P a b ≠ b ↔ P ∧ a ≠ b := dite_ne_right_iff.trans <| by rw [exists_prop]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_ne_right_iff
null
protected Ne.dite_eq_left_iff (h : ∀ h, a ≠ B h) : dite P (fun _ ↦ a) B = a ↔ P := dite_eq_left_iff.trans ⟨fun H ↦ of_not_not fun h' ↦ h h' (H h').symm, fun h H ↦ (H h).elim⟩
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
Ne.dite_eq_left_iff
null
protected Ne.dite_eq_right_iff (h : ∀ h, A h ≠ b) : (dite P A fun _ ↦ b) = b ↔ ¬P := dite_eq_right_iff.trans ⟨fun H h' ↦ h h' (H h'), fun h' H ↦ (h' H).elim⟩
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
Ne.dite_eq_right_iff
null
protected Ne.ite_eq_left_iff (h : a ≠ b) : ite P a b = a ↔ P := Ne.dite_eq_left_iff fun _ ↦ h
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
Ne.ite_eq_left_iff
null
protected Ne.ite_eq_right_iff (h : a ≠ b) : ite P a b = b ↔ ¬P := Ne.dite_eq_right_iff fun _ ↦ h
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
Ne.ite_eq_right_iff
null
protected Ne.dite_ne_left_iff (h : ∀ h, a ≠ B h) : dite P (fun _ ↦ a) B ≠ a ↔ ¬P := dite_ne_left_iff.trans <| exists_iff_of_forall h
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
Ne.dite_ne_left_iff
null
protected Ne.dite_ne_right_iff (h : ∀ h, A h ≠ b) : (dite P A fun _ ↦ b) ≠ b ↔ P := dite_ne_right_iff.trans <| exists_iff_of_forall h
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
Ne.dite_ne_right_iff
null
protected Ne.ite_ne_left_iff (h : a ≠ b) : ite P a b ≠ a ↔ ¬P := Ne.dite_ne_left_iff fun _ ↦ h
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
Ne.ite_ne_left_iff
null
protected Ne.ite_ne_right_iff (h : a ≠ b) : ite P a b ≠ b ↔ P := Ne.dite_ne_right_iff fun _ ↦ h variable (P Q a b)
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
Ne.ite_ne_right_iff
null
dite_eq_or_eq : (∃ h, dite P A B = A h) ∨ ∃ h, dite P A B = B h := if h : _ then .inl ⟨h, dif_pos h⟩ else .inr ⟨h, dif_neg h⟩
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
dite_eq_or_eq
null
ite_eq_or_eq : ite P a b = a ∨ ite P a b = b := if h : _ then .inl (if_pos h) else .inr (if_neg h)
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_eq_or_eq
null
apply_dite₂ {α β γ : Sort*} (f : α → β → γ) (P : Prop) [Decidable P] (a : P → α) (b : ¬P → α) (c : P → β) (d : ¬P → β) : f (dite P a b) (dite P c d) = dite P (fun h ↦ f (a h) (c h)) fun h ↦ f (b h) (d h) := by by_cases h : P <;> simp [h]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
apply_dite₂
A two-argument function applied to two `dite`s is a `dite` of that two-argument function applied to each of the branches.
apply_ite₂ {α β γ : Sort*} (f : α → β → γ) (P : Prop) [Decidable P] (a b : α) (c d : β) : f (ite P a b) (ite P c d) = ite P (f a c) (f b d) := apply_dite₂ f P (fun _ ↦ a) (fun _ ↦ b) (fun _ ↦ c) fun _ ↦ d
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
apply_ite₂
A two-argument function applied to two `ite`s is a `ite` of that two-argument function applied to each of the branches.
dite_apply (f : P → ∀ a, σ a) (g : ¬P → ∀ a, σ a) (a : α) : (dite P f g) a = dite P (fun h ↦ f h a) fun h ↦ g h a := by by_cases h : P <;> simp [h]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
dite_apply
A 'dite' producing a `Pi` type `Π a, σ a`, applied to a value `a : α` is a `dite` that applies either branch to `a`.
ite_apply (f g : ∀ a, σ a) (a : α) : (ite P f g) a = ite P (f a) (g a) := dite_apply P (fun _ ↦ f) (fun _ ↦ g) a
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_apply
A 'ite' producing a `Pi` type `Π a, σ a`, applied to a value `a : α` is a `ite` that applies either branch to `a`.
ite_and : ite (P ∧ Q) a b = ite P (ite Q a b) b := by by_cases hp : P <;> by_cases hq : Q <;> simp [hp, hq]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_and
null
ite_or : ite (P ∨ Q) a b = ite P a (ite Q a b) := by by_cases hp : P <;> by_cases hq : Q <;> simp [hp, hq]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_or
null
dite_dite_comm {B : Q → α} {C : ¬P → ¬Q → α} (h : P → ¬Q) : (if p : P then A p else if q : Q then B q else C p q) = if q : Q then B q else if p : P then A p else C p q := by grind
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
dite_dite_comm
null
ite_ite_comm (h : P → ¬Q) : (if P then a else if Q then b else c) = if Q then b else if P then a else c := dite_dite_comm P Q h
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_ite_comm
null
ite_prop_iff_or : (if P then Q else R) ↔ (P ∧ Q ∨ ¬P ∧ R) := by by_cases p : P <;> simp [p]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_prop_iff_or
null
dite_prop_iff_or {Q : P → Prop} {R : ¬P → Prop} : dite P Q R ↔ (∃ p, Q p) ∨ (∃ p, R p) := by by_cases h : P <;> simp [h, exists_prop_of_false, exists_prop_of_true]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
dite_prop_iff_or
null
ite_prop_iff_and : (if P then Q else R) ↔ ((P → Q) ∧ (¬P → R)) := by by_cases p : P <;> simp [p]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_prop_iff_and
null
dite_prop_iff_and {Q : P → Prop} {R : ¬P → Prop} : dite P Q R ↔ (∀ h, Q h) ∧ (∀ h, R h) := by by_cases h : P <;> simp [h, forall_prop_of_false, forall_prop_of_true]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
dite_prop_iff_and
null
if_ctx_congr (h_c : P ↔ Q) (h_t : Q → x = u) (h_e : ¬Q → y = v) : ite P x y = ite Q u v := ite_congr h_c.eq h_t h_e
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
if_ctx_congr
null
if_congr (h_c : P ↔ Q) (h_t : x = u) (h_e : y = v) : ite P x y = ite Q u v := if_ctx_congr h_c (fun _ ↦ h_t) (fun _ ↦ h_e)
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
if_congr
null
mem_dite {a : α} {s : p → β} {t : ¬p → β} : (a ∈ if h : p then s h else t h) ↔ (∀ h, a ∈ s h) ∧ (∀ h, a ∈ t h) := by by_cases h : p <;> simp [h]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
mem_dite
null
dite_mem {a : p → α} {b : ¬p → α} {s : β} : (if h : p then a h else b h) ∈ s ↔ (∀ h, a h ∈ s) ∧ (∀ h, b h ∈ s) := by by_cases h : p <;> simp [h]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
dite_mem
null
mem_ite {a : α} {s t : β} : (a ∈ if p then s else t) ↔ (p → a ∈ s) ∧ (¬p → a ∈ t) := mem_dite
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
mem_ite
null
ite_mem {a b : α} {s : β} : (if p then a else b) ∈ s ↔ (p → a ∈ s) ∧ (¬p → b ∈ s) := dite_mem
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
ite_mem
null
not_beq_of_ne {α : Type*} [BEq α] [LawfulBEq α] {a b : α} (ne : a ≠ b) : ¬(a == b) := fun h => ne (eq_of_beq h) alias beq_eq_decide := Bool.beq_eq_decide_eq @[simp] lemma beq_eq_beq {α β : Type*} [BEq α] [LawfulBEq α] [BEq β] [LawfulBEq β] {a₁ a₂ : α} {b₁ b₂ : β} : (a₁ == a₂) = (b₁ == b₂) ↔ (a₁ = a₂ ↔ b₁ = b₂) := by rw [Bool.eq_iff_iff]; simp @[ext]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
not_beq_of_ne
null
beq_ext {α : Type*} (inst1 : BEq α) (inst2 : BEq α) (h : ∀ x y, @BEq.beq _ inst1 x y = @BEq.beq _ inst2 x y) : inst1 = inst2 := by have ⟨beq1⟩ := inst1 congr funext x y exact h x y
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
beq_ext
null
lawful_beq_subsingleton {α : Type*} (inst1 : BEq α) (inst2 : BEq α) [@LawfulBEq α inst1] [@LawfulBEq α inst2] : inst1 = inst2 := by apply beq_ext intro x y classical simp only [beq_eq_decide]
theorem
Logic
[ "Mathlib.Tactic.Attr.Register", "Mathlib.Tactic.AdaptationNote", "Mathlib.Tactic.Basic", "Batteries.Logic", "Batteries.Tactic.Trans", "Batteries.Util.LibraryNote", "Mathlib.Data.Nat.Notation", "Mathlib.Data.Int.Notation" ]
Mathlib/Logic/Basic.lean
lawful_beq_subsingleton
null
Denumerable (α : Type*) extends Encodable α where /-- `decode` and `encode` are inverses. -/ decode_inv : ∀ n, ∃ a ∈ decode n, encode a = n open Finset Nat
class
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
Denumerable
A denumerable type is (constructively) bijective with `ℕ`. Typeclass equivalent of `α ≃ ℕ`.
decode_isSome (α) [Denumerable α] (n : ℕ) : (decode (α := α) n).isSome := Option.isSome_iff_exists.2 <| (decode_inv n).imp fun _ => And.left
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
decode_isSome
null
ofNat (α) [Denumerable α] (n : ℕ) : α := Option.get _ (decode_isSome α n) @[simp]
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofNat
Returns the `n`-th element of `α` indexed by the decoding.
decode_eq_ofNat (α) [Denumerable α] (n : ℕ) : decode (α := α) n = some (ofNat α n) := Option.eq_some_of_isSome _
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
decode_eq_ofNat
null
ofNat_of_decode {n b} (h : decode (α := α) n = some b) : ofNat (α := α) n = b := by simpa using h @[simp]
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofNat_of_decode
null
encode_ofNat (n) : encode (ofNat α n) = n := by obtain ⟨a, h, e⟩ := decode_inv (α := α) n rwa [ofNat_of_decode h] @[simp]
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
encode_ofNat
null
ofNat_encode (a) : ofNat α (encode a) = a := ofNat_of_decode (encodek _)
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofNat_encode
null
eqv (α) [Denumerable α] : α ≃ ℕ := ⟨encode, ofNat α, ofNat_encode, encode_ofNat⟩
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
eqv
A denumerable type is equivalent to `ℕ`.
mk' {α} (e : α ≃ ℕ) : Denumerable α where encode := e decode := some ∘ e.symm encodek _ := congr_arg some (e.symm_apply_apply _) decode_inv _ := ⟨_, rfl, e.apply_symm_apply _⟩
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
mk'
A type equivalent to `ℕ` is denumerable.
ofEquiv (α) {β} [Denumerable α] (e : β ≃ α) : Denumerable β := { Encodable.ofEquiv _ e with decode_inv := fun n => by simp [decode_ofEquiv, encode_ofEquiv] } @[simp]
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofEquiv
Denumerability is conserved by equivalences. This is transitivity of equivalence the denumerable way.
ofEquiv_ofNat (α) {β} [Denumerable α] (e : β ≃ α) (n) : @ofNat β (ofEquiv _ e) n = e.symm (ofNat α n) := by letI := ofEquiv _ e refine ofNat_of_decode ?_ rw [decode_ofEquiv e] simp
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofEquiv_ofNat
null
equiv₂ (α β) [Denumerable α] [Denumerable β] : α ≃ β := (eqv α).trans (eqv β).symm
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
equiv₂
All denumerable types are equivalent.
nat : Denumerable ℕ := ⟨fun _ => ⟨_, rfl, rfl⟩⟩ @[simp]
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
nat
null
ofNat_nat (n) : ofNat ℕ n = n := rfl
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofNat_nat
null
option : Denumerable (Option α) := ⟨fun n => by cases n with | zero => refine ⟨none, ?_, encode_none⟩ rw [decode_option_zero, Option.mem_def] | succ n => refine ⟨some (ofNat α n), ?_, ?_⟩ · rw [decode_option_succ, decode_eq_ofNat, Option.map_some, Option.mem_def] rw [encode_some, encode_ofNat]⟩
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
option
If `α` is denumerable, then so is `Option α`.
sum : Denumerable (α ⊕ β) := ⟨fun n => by suffices ∃ a ∈ @decodeSum α β _ _ n, encodeSum a = bit (bodd n) (div2 n) by simpa [bit_bodd_div2] simp only [decodeSum, boddDiv2_eq, decode_eq_ofNat, Option.map_some, Option.mem_def, Sum.exists] cases bodd n <;> simp [bit, encodeSum, Nat.two_mul]⟩
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
sum
If `α` and `β` are denumerable, then so is their sum.
sigma : Denumerable (Sigma γ) := ⟨fun n => by simp⟩ @[simp]
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
sigma
A denumerable collection of denumerable types is denumerable.
sigma_ofNat_val (n : ℕ) : ofNat (Sigma γ) n = ⟨ofNat α (unpair n).1, ofNat (γ _) (unpair n).2⟩ := Option.some.inj <| by rw [← decode_eq_ofNat, decode_sigma_val]; simp
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
sigma_ofNat_val
null
prod : Denumerable (α × β) := ofEquiv _ (Equiv.sigmaEquivProd α β).symm
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
prod
If `α` and `β` are denumerable, then so is their product.
prod_ofNat_val (n : ℕ) : ofNat (α × β) n = (ofNat α (unpair n).1, ofNat β (unpair n).2) := by simp @[simp]
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
prod_ofNat_val
null
prod_nat_ofNat : ofNat (ℕ × ℕ) = unpair := by funext; simp
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
prod_nat_ofNat
null
int : Denumerable ℤ := Denumerable.mk' Equiv.intEquivNat
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
int
null
pnat : Denumerable ℕ+ := Denumerable.mk' Equiv.pnatEquivNat
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
pnat
null
ulift : Denumerable (ULift α) := ofEquiv _ Equiv.ulift
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ulift
The lift of a denumerable type is denumerable.
plift : Denumerable (PLift α) := ofEquiv _ Equiv.plift
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
plift
The lift of a denumerable type is denumerable.
pair : α × α ≃ α := equiv₂ _ _
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
pair
If `α` is denumerable, then `α × α` and `α` are equivalent.
exists_succ (x : s) : ∃ n, (x : ℕ) + n + 1 ∈ s := by by_contra h have (a : ℕ) (ha : a ∈ s) : a < x + 1 := lt_of_not_ge fun hax => h ⟨a - (x + 1), by rwa [Nat.add_right_comm, Nat.add_sub_cancel' hax]⟩ classical exact Fintype.false ⟨(((Multiset.range (succ x)).filter (· ∈ s)).pmap (fun (y : ℕ) (hy : y ∈ s) => Subtype.mk y hy) (by simp [-Multiset.range_succ])).toFinset, by simpa [Subtype.ext_iff, Multiset.mem_filter, -Multiset.range_succ] ⟩
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
exists_succ
null
succ (x : s) : s := have h : ∃ m, (x : ℕ) + m + 1 ∈ s := exists_succ x ⟨↑x + Nat.find h + 1, Nat.find_spec h⟩
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
succ
Returns the next natural in a set, according to the usual ordering of `ℕ`.
succ_le_of_lt {x y : s} (h : y < x) : succ y ≤ x := have hx : ∃ m, (y : ℕ) + m + 1 ∈ s := exists_succ _ let ⟨k, hk⟩ := Nat.exists_eq_add_of_lt h have : Nat.find hx ≤ k := Nat.find_min' _ (hk ▸ x.2) show (y : ℕ) + Nat.find hx + 1 ≤ x by cutsat
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
succ_le_of_lt
null
le_succ_of_forall_lt_le {x y : s} (h : ∀ z < x, z ≤ y) : x ≤ succ y := have hx : ∃ m, (y : ℕ) + m + 1 ∈ s := exists_succ _ show (x : ℕ) ≤ (y : ℕ) + Nat.find hx + 1 from le_of_not_gt fun hxy => (h ⟨_, Nat.find_spec hx⟩ hxy).not_gt <| (by cutsat : (y : ℕ) < (y : ℕ) + Nat.find hx + 1)
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
le_succ_of_forall_lt_le
null
lt_succ_self (x : s) : x < succ x := calc (x : ℕ) ≤ (x + _) := le_add_right .. _ < (succ x) := Nat.lt_succ_self (x + _)
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
lt_succ_self
null
lt_succ_iff_le {x y : s} : x < succ y ↔ x ≤ y := ⟨fun h => le_of_not_gt fun h' => not_le_of_gt h (succ_le_of_lt h'), fun h => lt_of_le_of_lt h (lt_succ_self _)⟩
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
lt_succ_iff_le
null
ofNat (s : Set ℕ) [DecidablePred (· ∈ s)] [Infinite s] : ℕ → s | 0 => ⊥ | n + 1 => succ (ofNat s n)
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofNat
Returns the `n`-th element of a set, according to the usual ordering of `ℕ`.
ofNat_surjective : Surjective (ofNat s) | ⟨x, hx⟩ => by set t : List s := ((List.range x).filter fun y => y ∈ s).pmap (fun (y : ℕ) (hy : y ∈ s) => ⟨y, hy⟩) (by intro a ha; simpa using (List.mem_filter.mp ha).2) with ht have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by simp [List.mem_filter, Subtype.ext_iff, ht] cases hmax : List.maximum t with | bot => refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (a := (⊥ : s)) ?_)⟩ rwa [← List.maximum_eq_bot.1 hmax, hmt] | coe m => have wf : ↑m < x := by simpa using hmt.mp (List.maximum_mem hmax) rcases ofNat_surjective m with ⟨a, rfl⟩ refine ⟨a + 1, le_antisymm (succ_le_of_lt wf) ?_⟩ exact le_succ_of_forall_lt_le fun z hz => List.le_maximum_of_mem (hmt.2 hz) hmax termination_by n => n.val @[simp]
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofNat_surjective
null
ofNat_range : Set.range (ofNat s) = Set.univ := ofNat_surjective.range_eq @[simp]
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofNat_range
null
coe_comp_ofNat_range : Set.range ((↑) ∘ ofNat s : ℕ → ℕ) = s := by rw [Set.range_comp Subtype.val, ofNat_range, Set.image_univ, Subtype.range_coe]
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
coe_comp_ofNat_range
null
private toFunAux (x : s) : ℕ := (List.range x).countP (· ∈ s)
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
toFunAux
null
private toFunAux_eq {s : Set ℕ} [DecidablePred (· ∈ s)] (x : s) : toFunAux x = #{y ∈ Finset.range x | y ∈ s} := by rw [toFunAux, List.countP_eq_length_filter] rfl
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
toFunAux_eq
null
private right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n | 0 => by rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_notMem] rintro n hn rw [mem_filter, ofNat, mem_range] at hn exact bot_le.not_gt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1) | n + 1 => by have ih : toFunAux (ofNat s n) = n := right_inverse_aux n have h₁ : (ofNat s n : ℕ) ∉ {x ∈ range (ofNat s n) | x ∈ s} := by simp have h₂ : {x ∈ range (succ (ofNat s n)) | x ∈ s} = insert ↑(ofNat s n) {x ∈ range (ofNat s n) | x ∈ s} := by simp only [Finset.ext_iff, mem_insert, mem_range, mem_filter] exact fun m => ⟨fun h => by simp only [h.2, and_true] exact Or.symm (lt_or_eq_of_le ((@lt_succ_iff_le _ _ _ ⟨m, h.2⟩ _).1 h.1)), fun h => h.elim (fun h => h.symm ▸ ⟨lt_succ_self _, (ofNat s n).prop⟩) fun h => ⟨h.1.trans (lt_succ_self _), h.2⟩⟩ simp only [toFunAux_eq, ofNat] at ih ⊢ conv => rhs rw [← ih, ← card_insert_of_notMem h₁, ← h₂]
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
right_inverse_aux
null
denumerable (s : Set ℕ) [DecidablePred (· ∈ s)] [Infinite s] : Denumerable s := Denumerable.ofEquiv ℕ { toFun := toFunAux invFun := ofNat s left_inv := leftInverse_of_surjective_of_rightInverse ofNat_surjective right_inverse_aux right_inv := right_inverse_aux }
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
denumerable
Any infinite set of naturals is denumerable.
ofEncodableOfInfinite (α : Type*) [Encodable α] [Infinite α] : Denumerable α := by letI := @decidableRangeEncode α _ letI : Infinite (Set.range (@encode α _)) := Infinite.of_injective _ (Equiv.ofInjective _ encode_injective).injective letI := Nat.Subtype.denumerable (Set.range (@encode α _)) exact Denumerable.ofEquiv (Set.range (@encode α _)) (equivRangeEncode α)
def
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
ofEncodableOfInfinite
An infinite encodable type is denumerable.
nonempty_denumerable (α : Type*) [Countable α] [Infinite α] : Nonempty (Denumerable α) := (nonempty_encodable α).map fun h => @Denumerable.ofEncodableOfInfinite _ h _
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
nonempty_denumerable
See also `nonempty_encodable`, `nonempty_fintype`.
nonempty_denumerable_iff {α : Type*} : Nonempty (Denumerable α) ↔ Countable α ∧ Infinite α := ⟨fun ⟨_⟩ ↦ ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ ↦ nonempty_denumerable _⟩
theorem
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
nonempty_denumerable_iff
null
nonempty_equiv_of_countable [Countable α] [Infinite α] [Countable β] [Infinite β] : Nonempty (α ≃ β) := by cases nonempty_denumerable α cases nonempty_denumerable β exact ⟨(Denumerable.eqv _).trans (Denumerable.eqv _).symm⟩
instance
Logic
[ "Mathlib.Data.Fintype.EquivFin", "Mathlib.Data.List.MinMax", "Mathlib.Data.Nat.Order.Lemmas", "Mathlib.Logic.Encodable.Basic" ]
Mathlib/Logic/Denumerable.lean
nonempty_equiv_of_countable
null
ExistsUnique (p : α → Prop) := ∃ x, p x ∧ ∀ y, p y → y = x
def
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
ExistsUnique
For `p : α → Prop`, `ExistsUnique p` means that there exists a unique `x : α` with `p x`.
isExplicitBinderSingular (xs : TSyntax ``explicitBinders) : Bool := match xs with | `(explicitBinders| $_:binderIdent $[: $_]?) => true | `(explicitBinders| ($_:binderIdent : $_)) => true | _ => false open TSyntax.Compat in
def
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
isExplicitBinderSingular
Checks to see that `xs` has only one binder.
@[app_unexpander ExistsUnique] unexpandExistsUnique : Lean.PrettyPrinter.Unexpander | `($(_) fun $x:ident ↦ $b) => `(∃! $x:ident, $b) | `($(_) fun ($x:ident : $t) ↦ $b) => `(∃! $x:ident : $t, $b) | _ => throw ()
def
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
unexpandExistsUnique
`∃! x : α, p x` means that there exists a unique `x` in `α` such that `p x`. This is notation for `ExistsUnique (fun (x : α) ↦ p x)`. This notation does not allow multiple binders like `∃! (x : α) (y : β), p x y` as a shorthand for `∃! (x : α), ∃! (y : β), p x y` since it is liable to be misunderstood. Often, the intended meaning is instead `∃! q : α × β, p q.1 q.2`. -/ macro "∃!" xs:explicitBinders ", " b:term : term => do if !isExplicitBinderSingular xs then Macro.throwErrorAt xs "\ The `ExistsUnique` notation should not be used with more than one binder.\n\ \n\ The reason for this is that `∃! (x : α), ∃! (y : β), p x y` has a completely different \ meaning from `∃! q : α × β, p q.1 q.2`. \ To prevent confusion, this notation requires that you be explicit \ and use one with the correct interpretation." expandExplicitBinders ``ExistsUnique xs b /-- Pretty-printing for `ExistsUnique`, following the same pattern as pretty printing for `Exists`. However, it does *not* merge binders.
@[simp] existsUnique_eq' {a' : α} : ∃! a, a' = a := by simp only [ExistsUnique, and_self, forall_eq', exists_eq']
theorem
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
existsUnique_eq'
`∃! x ∈ s, p x` means `∃! x, x ∈ s ∧ p x`, which is to say that there exists a unique `x ∈ s` such that `p x`. Similarly, notations such as `∃! x ≤ n, p n` are supported, using any relation defined using the `binder_predicate` command. -/ syntax "∃! " binderIdent binderPred ", " term : term macro_rules | `(∃! $x:ident $p:binderPred, $b) => `(∃! $x:ident, satisfies_binder_pred% $x $p ∧ $b) | `(∃! _ $p:binderPred, $b) => `(∃! x, satisfies_binder_pred% x $p ∧ $b) end Mathlib.Notation -- @[intro] -- TODO theorem ExistsUnique.intro {p : α → Prop} (w : α) (h₁ : p w) (h₂ : ∀ y, p y → y = w) : ∃! x, p x := ⟨w, h₁, h₂⟩ theorem ExistsUnique.elim {p : α → Prop} {b : Prop} (h₂ : ∃! x, p x) (h₁ : ∀ x, p x → (∀ y, p y → y = x) → b) : b := Exists.elim h₂ (fun w hw ↦ h₁ w (And.left hw) (And.right hw)) theorem existsUnique_of_exists_of_unique {p : α → Prop} (hex : ∃ x, p x) (hunique : ∀ y₁ y₂, p y₁ → p y₂ → y₁ = y₂) : ∃! x, p x := Exists.elim hex (fun x px ↦ ExistsUnique.intro x px (fun y (h : p y) ↦ hunique y x h px)) theorem ExistsUnique.exists {p : α → Prop} : (∃! x, p x) → ∃ x, p x | ⟨x, h, _⟩ => ⟨x, h⟩ theorem ExistsUnique.unique {p : α → Prop} (h : ∃! x, p x) {y₁ y₂ : α} (py₁ : p y₁) (py₂ : p y₂) : y₁ = y₂ := let ⟨_, _, hy⟩ := h; (hy _ py₁).trans (hy _ py₂).symm -- TODO -- attribute [congr] forall_congr' -- attribute [congr] exists_congr' -- @[congr] theorem existsUnique_congr {p q : α → Prop} (h : ∀ a, p a ↔ q a) : (∃! a, p a) ↔ ∃! a, q a := exists_congr fun _ ↦ and_congr (h _) <| forall_congr' fun _ ↦ imp_congr_left (h _) @[simp] theorem existsUnique_iff_exists [Subsingleton α] {p : α → Prop} : (∃! x, p x) ↔ ∃ x, p x := ⟨fun h ↦ h.exists, Exists.imp fun x hx ↦ ⟨hx, fun y _ ↦ Subsingleton.elim y x⟩⟩ theorem existsUnique_const {b : Prop} (α : Sort*) [i : Nonempty α] [Subsingleton α] : (∃! _ : α, b) ↔ b := by simp @[simp] theorem existsUnique_eq {a' : α} : ∃! a, a = a' := by simp only [eq_comm, ExistsUnique, and_self, forall_eq', exists_eq'] /-- The difference with `existsUnique_eq` is that the equality is reversed.
existsUnique_prop {p q : Prop} : (∃! _ : p, q) ↔ p ∧ q := by simp @[simp] theorem existsUnique_false : ¬∃! _ : α, False := fun ⟨_, h, _⟩ ↦ h
theorem
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
existsUnique_prop
null
existsUnique_prop_of_true {p : Prop} {q : p → Prop} (h : p) : (∃! h' : p, q h') ↔ q h := @existsUnique_const (q h) p ⟨h⟩ _
theorem
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
existsUnique_prop_of_true
null
ExistsUnique.elim₂ {p : α → Sort*} [∀ x, Subsingleton (p x)] {q : ∀ (x) (_ : p x), Prop} {b : Prop} (h₂ : ∃! x, ∃! h : p x, q x h) (h₁ : ∀ (x) (h : p x), q x h → (∀ (y) (hy : p y), q y hy → y = x) → b) : b := by simp only [existsUnique_iff_exists] at h₂ apply h₂.elim exact fun x ⟨hxp, hxq⟩ H ↦ h₁ x hxp hxq fun y hyp hyq ↦ H y ⟨hyp, hyq⟩
theorem
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
ExistsUnique.elim₂
null
ExistsUnique.intro₂ {p : α → Sort*} [∀ x, Subsingleton (p x)] {q : ∀ (x : α) (_ : p x), Prop} (w : α) (hp : p w) (hq : q w hp) (H : ∀ (y) (hy : p y), q y hy → y = w) : ∃! x, ∃! hx : p x, q x hx := by simp only [existsUnique_iff_exists] exact ExistsUnique.intro w ⟨hp, hq⟩ fun y ⟨hyp, hyq⟩ ↦ H y hyp hyq
theorem
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
ExistsUnique.intro₂
null
ExistsUnique.exists₂ {p : α → Sort*} {q : ∀ (x : α) (_ : p x), Prop} (h : ∃! x, ∃! hx : p x, q x hx) : ∃ (x : _) (hx : p x), q x hx := h.exists.imp fun _ hx ↦ hx.exists
theorem
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
ExistsUnique.exists₂
null
ExistsUnique.unique₂ {p : α → Sort*} [∀ x, Subsingleton (p x)] {q : ∀ (x : α) (_ : p x), Prop} (h : ∃! x, ∃! hx : p x, q x hx) {y₁ y₂ : α} (hpy₁ : p y₁) (hqy₁ : q y₁ hpy₁) (hpy₂ : p y₂) (hqy₂ : q y₂ hpy₂) : y₁ = y₂ := by simp only [existsUnique_iff_exists] at h exact h.unique ⟨hpy₁, hqy₁⟩ ⟨hpy₂, hqy₂⟩
theorem
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
ExistsUnique.unique₂
null
List.decidableBExistsUnique {α : Type*} [DecidableEq α] (p : α → Prop) [DecidablePred p] : (l : List α) → Decidable (∃! x, x ∈ l ∧ p x) | [] => .isFalse <| by simp | x :: xs => if hx : p x then decidable_of_iff (∀ y ∈ xs, p y → x = y) (⟨fun h ↦ ⟨x, by grind⟩, fun ⟨z, h⟩ y hy hp ↦ (h.2 x ⟨mem_cons_self, hx⟩).trans (by grind)⟩) else have := List.decidableBExistsUnique p xs decidable_of_iff (∃! x, x ∈ xs ∧ p x) (by grind)
instance
Logic
[ "Mathlib.Tactic.TypeStar", "Batteries.Tactic.Alias" ]
Mathlib/Logic/ExistsUnique.lean
List.decidableBExistsUnique
This invokes the two `Decidable` arguments $O(n)$ times.
CutExpand (r : α → α → Prop) (s' s : Multiset α) : Prop := ∃ (t : Multiset α) (a : α), (∀ a' ∈ t, r a' a) ∧ s' + {a} = s + t variable {r : α → α → Prop}
def
Logic
[ "Mathlib.Data.Finsupp.Lex", "Mathlib.Data.Finsupp.Multiset", "Mathlib.Order.GameAdd" ]
Mathlib/Logic/Hydra.lean
CutExpand
The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a ∈ s` and adding back an arbitrary multiset `t` of heads such that all `a' ∈ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq α`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a ∈ s` because `s' + {a} = s + t` already guarantees `a ∈ s + t`, and if `r` is irreflexive then `a ∉ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive.
cutExpand_le_invImage_lex [DecidableEq α] [IsIrrefl α r] : CutExpand r ≤ InvImage (Finsupp.Lex (rᶜ ⊓ (· ≠ ·)) (· < ·)) toFinsupp := by rintro s t ⟨u, a, hr, he⟩ replace hr := fun a' ↦ mt (hr a') classical refine ⟨a, fun b h ↦ ?_, ?_⟩ <;> simp_rw [toFinsupp_apply] · apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he · apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he ▸ Nat.lt_succ_self _
theorem
Logic
[ "Mathlib.Data.Finsupp.Lex", "Mathlib.Data.Finsupp.Multiset", "Mathlib.Order.GameAdd" ]
Mathlib/Logic/Hydra.lean
cutExpand_le_invImage_lex
null
cutExpand_singleton {s x} (h : ∀ x' ∈ s, r x' x) : CutExpand r s {x} := ⟨s, x, h, add_comm s _⟩
theorem
Logic
[ "Mathlib.Data.Finsupp.Lex", "Mathlib.Data.Finsupp.Multiset", "Mathlib.Order.GameAdd" ]
Mathlib/Logic/Hydra.lean
cutExpand_singleton
null
cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h ↦ by rwa [mem_singleton.1 h]
theorem
Logic
[ "Mathlib.Data.Finsupp.Lex", "Mathlib.Data.Finsupp.Multiset", "Mathlib.Order.GameAdd" ]
Mathlib/Logic/Hydra.lean
cutExpand_singleton_singleton
null
cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) ↔ CutExpand r t u := exists₂_congr fun _ _ ↦ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff]
theorem
Logic
[ "Mathlib.Data.Finsupp.Lex", "Mathlib.Data.Finsupp.Multiset", "Mathlib.Order.GameAdd" ]
Mathlib/Logic/Hydra.lean
cutExpand_add_left
null
cutExpand_add_right {s' s} (t) : CutExpand r (s' + t) (s + t) ↔ CutExpand r s' s := by convert cutExpand_add_left t using 2 <;> apply add_comm
lemma
Logic
[ "Mathlib.Data.Finsupp.Lex", "Mathlib.Data.Finsupp.Multiset", "Mathlib.Order.GameAdd" ]
Mathlib/Logic/Hydra.lean
cutExpand_add_right
null
cutExpand_add_single {a' a : α} (s : Multiset α) (h : r a' a) : CutExpand r (s + {a'}) (s + {a}) := (cutExpand_add_left s).2 <| cutExpand_singleton_singleton h
theorem
Logic
[ "Mathlib.Data.Finsupp.Lex", "Mathlib.Data.Finsupp.Multiset", "Mathlib.Order.GameAdd" ]
Mathlib/Logic/Hydra.lean
cutExpand_add_single
null