Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit bedb810

Browse files
urkudmergify[bot]
andauthored
feat(*): a few more theorems about unique and subsingleton (#2230)
* feat(*): a few more theorems about `unique` and `subsingleton` * Fix compile, fix two non-terminate `simp`s * Update src/topology/metric_space/antilipschitz.lean This lemma will go to another PR Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 1eae0be commit bedb810

File tree

5 files changed

+56
-13
lines changed

5 files changed

+56
-13
lines changed

src/data/equiv/basic.lean

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ protected theorem bijective (f : α ≃ β) : bijective f :=
7373
@[simp] lemma range_eq_univ {α : Type*} {β : Type*} (e : α ≃ β) : set.range e = set.univ :=
7474
set.eq_univ_of_forall e.surjective
7575

76-
protected theorem subsingleton (e : α ≃ β) : ∀ [subsingleton β], subsingleton α
77-
| ⟨H⟩ := ⟨λ a b, e.injective (H _ _)⟩
76+
protected theorem subsingleton (e : α ≃ β) [subsingleton β] : subsingleton α :=
77+
e.injective.comap_subsingleton
7878

7979
protected def decidable_eq (e : α ≃ β) [H : decidable_eq β] : decidable_eq α
8080
| a b := decidable_of_iff _ e.injective.eq_iff
@@ -136,8 +136,7 @@ theorem right_inverse_symm (f : equiv α β) : function.right_inverse f.symm f :
136136

137137
def equiv_congr {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) :=
138138
⟨ λac, (ab.symm.trans ac).trans cd, λbd, ab.trans $ bd.trans $ cd.symm,
139-
assume ac, begin simp [trans_assoc], rw [← trans_assoc], simp end,
140-
assume ac, begin simp [trans_assoc], rw [← trans_assoc], simp end, ⟩
139+
assume ac, by { ext x, simp }, assume ac, by { ext x, simp } ⟩
141140

142141
def perm_congr {α : Type*} {β : Type*} (e : α ≃ β) : perm α ≃ perm β :=
143142
equiv_congr e e
@@ -560,7 +559,7 @@ def inhabited_of_equiv [inhabited β] (e : α ≃ β) : inhabited α :=
560559
⟨e.symm (default _)⟩
561560

562561
def unique_of_equiv (e : α ≃ β) (h : unique β) : unique α :=
563-
unique.of_surjective e.symm.surjective
562+
e.symm.surjective.unique
564563

565564
def unique_congr (e : α ≃ β) : unique α ≃ unique β :=
566565
{ to_fun := e.symm.unique_of_equiv,

src/data/set/basic.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,9 @@ lemma subsingleton.eq_empty_or_singleton (hs : s.subsingleton) :
12631263
s = ∅ ∨ ∃ x, s = {x} :=
12641264
s.eq_empty_or_nonempty.elim or.inl (λ ⟨x, hx⟩, or.inr ⟨x, hs.eq_singleton_of_mem hx⟩)
12651265

1266+
lemma subsingleton_univ [subsingleton α] : (univ : set α).subsingleton :=
1267+
λ x hx y hy, subsingleton.elim x y
1268+
12661269
theorem univ_eq_true_false : univ = ({true, false} : set Prop) :=
12671270
eq.symm $ eq_univ_of_forall $ classical.cases (by simp) (by simp)
12681271

@@ -1699,3 +1702,16 @@ ext $ λ ⟨x, hx⟩ , by simp [inclusion]
16991702
end inclusion
17001703

17011704
end set
1705+
1706+
namespace subsingleton
1707+
1708+
variables {α : Type*} [subsingleton α]
1709+
1710+
lemma eq_univ_of_nonempty {s : set α} : s.nonempty → s = univ :=
1711+
λ ⟨x, hx⟩, eq_univ_of_forall $ λ y, subsingleton.elim x y ▸ hx
1712+
1713+
@[elab_as_eliminator]
1714+
lemma set_cases {p : set α → Prop} (h0 : p ∅) (h1 : p univ) (s) : p s :=
1715+
s.eq_empty_or_nonempty.elim (λ h, h.symm ▸ h0) $ λ h, (eq_univ_of_nonempty h).symm ▸ h1
1716+
1717+
end subsingleton

src/logic/unique.lean

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,32 @@ protected lemma subsingleton_unique' : ∀ (h₁ h₂ : unique α), h₁ = h₂
5353
instance subsingleton_unique : subsingleton (unique α) :=
5454
⟨unique.subsingleton_unique'⟩
5555

56-
def of_surjective {f : α → β} (hf : surjective f) [unique α] : unique β :=
56+
end unique
57+
58+
namespace function
59+
60+
variable {f : α → β}
61+
62+
/-- If the domain of a surjective function is a singleton,
63+
then the codomain is a singleton as well. -/
64+
def surjective.unique (hf : surjective f) [unique α] : unique β :=
5765
{ default := f (default _),
58-
uniq := λ b,
59-
begin
60-
cases hf b with a ha,
61-
subst ha,
62-
exact congr_arg f (eq_default a)
63-
end }
66+
uniq := λ b, let ⟨a, ha⟩ := hf b in ha ▸ congr_arg f (unique.eq_default _) }
6467

65-
end unique
68+
/-- If the codomain of an injective function is a subsingleton, then the domain
69+
is a subsingleton as well. -/
70+
lemma injective.comap_subsingleton (hf : injective f) [subsingleton β] :
71+
subsingleton α :=
72+
⟨λ x y, hf $ subsingleton.elim _ _⟩
73+
74+
end function
75+
76+
lemma nonempty_unique_or_exists_ne (x : α) : nonempty (unique α) ∨ ∃ y, y ≠ x :=
77+
classical.by_cases or.inr
78+
(λ h, or.inl ⟨{ default := x,
79+
uniq := λ y, classical.by_contradiction $ λ hy, h ⟨y, hy⟩ }⟩)
80+
81+
lemma subsingleton_or_exists_ne (x : α) : subsingleton α ∨ ∃ y, y ≠ x :=
82+
(nonempty_unique_or_exists_ne x).elim
83+
(λ ⟨h⟩, or.inl $ @unique.subsingleton _ h)
84+
or.inr

src/topology/basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ by_cases
134134
lemma is_open_and : is_open {a | p₁ a} → is_open {a | p₂ a} → is_open {a | p₁ a ∧ p₂ a} :=
135135
is_open_inter
136136

137+
@[simp] lemma subsingleton.is_open [subsingleton α] (s : set α) : is_open s :=
138+
subsingleton.set_cases is_open_empty is_open_univ s
139+
137140
/-- A set is closed if its complement is open -/
138141
def is_closed (s : set α) : Prop := is_open (-s)
139142

@@ -188,6 +191,9 @@ by rw [this]; exact is_closed_union (is_closed_compl_iff.mpr hp) hq
188191
lemma is_open_neg : is_closed {a | p a} → is_open {a | ¬ p a} :=
189192
is_open_compl_iff.mpr
190193

194+
@[simp] lemma subsingleton.is_closed [subsingleton α] (s : set α) : is_closed s :=
195+
subsingleton.set_cases is_closed_empty is_closed_univ s
196+
191197
/-- The interior of a set `s` is the largest open subset of `s`. -/
192198
def interior (s : set α) : set α := ⋃₀ {t | is_open t ∧ t ⊆ s}
193199

src/topology/metric_space/antilipschitz.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ begin
9696
rwa mul_comm } }
9797
end
9898

99+
lemma of_subsingleton [subsingleton α] {K : ℝ≥0} : antilipschitz_with K f :=
100+
λ x y, by simp only [subsingleton.elim x y, edist_self, zero_le]
101+
99102
end antilipschitz_with
100103

101104
lemma lipschitz_with.to_inverse [emetric_space α] [emetric_space β] {K : ℝ≥0} {f : α → β}

0 commit comments

Comments
 (0)