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

Commit 1571290

Browse files
committed
feat(logic/is_empty): add some simp lemmas and unique instances (#7832)
There are a handful of lemmas about `(h : ¬nonempty a)` that if restated in terms of `[is_empty a]` become suitable for `simp` or as `instance`s. This adjusts some of those lemmas.
1 parent 3d2e5ac commit 1571290

File tree

10 files changed

+61
-21
lines changed

10 files changed

+61
-21
lines changed

src/data/finset/basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ classical.by_cases or.inl (λ h, or.inr (nonempty_of_ne_empty h))
366366
(s : set α) = ∅ ↔ s = ∅ :=
367367
by rw [← coe_empty, coe_inj]
368368

369+
/-- A `finset` for an empty type is empty. -/
370+
lemma eq_empty_of_is_empty [is_empty α] (s : finset α) : s = ∅ :=
371+
finset.eq_empty_of_forall_not_mem is_empty_elim
372+
369373
/-- A `finset` for an empty type is empty. -/
370374
lemma eq_empty_of_not_nonempty (h : ¬ nonempty α) (s : finset α) : s = ∅ :=
371375
finset.eq_empty_of_forall_not_mem $ λ x, false.elim $ not_nonempty_iff_imp_false.1 h x

src/data/matrix/basic.lean

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ lemma map_smul [has_scalar R α] [has_scalar R β] (f : α →[R] β) (r : R)
114114
(M : matrix m n α) : (r • M).map f = r • (M.map f) :=
115115
by { ext, simp, }
116116

117-
lemma subsingleton_of_empty_left (hm : ¬ nonempty m) : subsingleton (matrix m n α) :=
118-
⟨λ M N, by { ext, contrapose! hm, use i }⟩
117+
-- TODO[gh-6025]: make this an instance once safe to do so
118+
lemma subsingleton_of_empty_left [is_empty m] : subsingleton (matrix m n α) :=
119+
⟨λ M N, by { ext, exact is_empty_elim i }⟩
119120

120-
lemma subsingleton_of_empty_right (hn : ¬ nonempty n) : subsingleton (matrix m n α) :=
121-
⟨λ M N, by { ext, contrapose! hn, use j }⟩
121+
-- TODO[gh-6025]: make this an instance once safe to do so
122+
lemma subsingleton_of_empty_right [is_empty n] : subsingleton (matrix m n α) :=
123+
⟨λ M N, by { ext, exact is_empty_elim j }⟩
122124

123125
end matrix
124126

src/data/matrix/dmatrix.lean

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ lemma map_sub [∀ i j, add_group (α i j)] {β : m → n → Type w} [∀ i j,
104104
(M - N).map (λ i j, @f i j) = M.map (λ i j, @f i j) - N.map (λ i j, @f i j) :=
105105
by { ext, simp }
106106

107-
lemma subsingleton_of_empty_left (hm : ¬ nonempty m) : subsingleton (dmatrix m n α) :=
108-
⟨λ M N, by { ext, contrapose! hm, use i }⟩
107+
-- TODO[gh-6025]: make this an instance once safe to do so
108+
lemma subsingleton_of_empty_left [is_empty m] : subsingleton (dmatrix m n α) :=
109+
⟨λ M N, by { ext, exact is_empty_elim i }⟩
109110

110-
lemma subsingleton_of_empty_right (hn : ¬ nonempty n) : subsingleton (dmatrix m n α) :=
111-
⟨λ M N, by { ext, contrapose! hn, use j }⟩
111+
-- TODO[gh-6025]: make this an instance once safe to do so
112+
lemma subsingleton_of_empty_right [is_empty n] : subsingleton (dmatrix m n α) :=
113+
⟨λ M N, by { ext, exact is_empty_elim j }⟩
112114

113115
end dmatrix
114116

src/data/set/basic.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,14 @@ theorem eq_empty_of_subset_empty {s : set α} : s ⊆ ∅ → s = ∅ := subset_
375375
theorem eq_empty_of_not_nonempty (h : ¬nonempty α) (s : set α) : s = ∅ :=
376376
eq_empty_of_subset_empty $ λ x hx, h ⟨x⟩
377377

378+
theorem eq_empty_of_is_empty [is_empty α] (s : set α) : s = ∅ :=
379+
eq_empty_of_subset_empty $ λ x hx, is_empty_elim x
380+
381+
/-- There is exactly one set of a type that is empty. -/
382+
-- TODO[gh-6025]: make this an instance once safe to do so
383+
def unique_empty [is_empty α] : unique (set α) :=
384+
{ default := ∅, uniq := eq_empty_of_is_empty }
385+
378386
lemma not_nonempty_iff_eq_empty {s : set α} : ¬s.nonempty ↔ s = ∅ :=
379387
by simp only [set.nonempty, eq_empty_iff_forall_not_mem, not_exists]
380388

src/linear_algebra/char_poly/coeff.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,8 @@ end
182182
@[simp] lemma finite_field.char_poly_pow_card {K : Type*} [field K] [fintype K] (M : matrix n n K) :
183183
char_poly (M ^ (fintype.card K)) = char_poly M :=
184184
begin
185-
by_cases hn : nonempty n,
186-
{ haveI := hn,
187-
cases char_p.exists K with p hp, letI := hp,
185+
casesI (is_empty_or_nonempty n).symm,
186+
{ cases char_p.exists K with p hp, letI := hp,
188187
rcases finite_field.card K p with ⟨⟨k, kpos⟩, ⟨hp, hk⟩⟩,
189188
haveI : fact p.prime := ⟨hp⟩,
190189
dsimp at hk, rw hk at *,
@@ -193,12 +192,13 @@ begin
193192
rw ← finite_field.expand_card,
194193
unfold char_poly, rw [alg_hom.map_det, ← is_monoid_hom.map_pow],
195194
apply congr_arg det,
196-
apply mat_poly_equiv.injective, swap, { apply_instance },
197-
rw [← mat_poly_equiv.coe_alg_hom, alg_hom.map_pow, mat_poly_equiv.coe_alg_hom,
198-
mat_poly_equiv_char_matrix, hk, sub_pow_char_pow_of_commute, ← C_pow],
195+
refine mat_poly_equiv.injective _,
196+
rw [alg_equiv.map_pow, mat_poly_equiv_char_matrix, hk, sub_pow_char_pow_of_commute, ← C_pow],
199197
{ exact (id (mat_poly_equiv_eq_X_pow_sub_C (p ^ k) M) : _) },
200198
{ exact (C M).commute_X } },
201-
{ apply congr_arg, apply @subsingleton.elim _ (subsingleton_of_empty_left hn) _ _, },
199+
{ -- TODO[gh-6025]: remove this `haveI` once `subsingleton_of_empty_right` is a global instance
200+
haveI : subsingleton (matrix n n K) := matrix.subsingleton_of_empty_right,
201+
exact congr_arg _ (subsingleton.elim _ _), },
202202
end
203203

204204
@[simp] lemma zmod.char_poly_pow_card (M : matrix n n (zmod p)) :

src/logic/embedding.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ protected noncomputable def equiv_of_surjective {α β} (f : α ↪ β) (hf : su
9898
α ≃ β :=
9999
equiv.of_bijective f ⟨f.injective, hf⟩
100100

101+
/-- There is always an embedding from an empty type. --/
102+
protected def of_is_empty {α β} [is_empty α] : α ↪ β :=
103+
⟨is_empty_elim, is_empty_elim⟩
104+
101105
protected def of_not_nonempty {α β} (hα : ¬ nonempty α) : α ↪ β :=
102106
⟨λa, (hα ⟨a⟩).elim, assume a, (hα ⟨a⟩).elim⟩
103107

src/logic/is_empty.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ instance [is_empty α] [is_empty β] : is_empty (psum α β) :=
4444
⟨λ x, psum.rec is_empty.false is_empty.false x⟩
4545
instance {α β} [is_empty α] [is_empty β] : is_empty (α ⊕ β) :=
4646
⟨λ x, sum.rec is_empty.false is_empty.false x⟩
47+
/-- subtypes of an empty type are empty -/
48+
instance [is_empty α] (p : α → Prop) : is_empty (subtype p) :=
49+
⟨λ x, is_empty.false x.1
50+
/-- subtypes by an all-false predicate are false. -/
51+
lemma subtype.is_empty_of_false {p : α → Prop} (hp : ∀ a, ¬(p a)) : is_empty (subtype p) :=
52+
⟨λ x, hp _ x.2
53+
/-- subtypes by false are false. -/
54+
instance subtype.is_empty_false : is_empty {a : α // false} :=
55+
subtype.is_empty_of_false (λ a, id)
4756

4857
/- Test that `pi.is_empty` finds this instance. -/
4958
example [h : nonempty α] [is_empty β] : is_empty (α → β) := by apply_instance

src/order/filter/basic.lean

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,16 +533,25 @@ nonempty_of_exists $ nonempty_of_mem_sets (univ_mem_sets : univ ∈ f)
533533
lemma compl_not_mem_sets {f : filter α} {s : set α} [ne_bot f] (h : s ∈ f) : sᶜ ∉ f :=
534534
λ hsc, (nonempty_of_mem_sets (inter_mem_sets h hsc)).ne_empty $ inter_compl_self s
535535

536+
lemma filter_eq_bot_of_is_empty [is_empty α] (f : filter α) : f = ⊥ :=
537+
empty_in_sets_eq_bot.mp $ univ_mem_sets' is_empty_elim
538+
536539
lemma filter_eq_bot_of_not_nonempty (f : filter α) (ne : ¬ nonempty α) : f = ⊥ :=
537540
empty_in_sets_eq_bot.mp $ univ_mem_sets' $ assume x, false.elim (ne ⟨x⟩)
538541

542+
/-- There is exactly one filter on an empty type. --/
543+
-- TODO[gh-6025]: make this globally an instance once safe to do so
544+
local attribute [instance]
545+
protected def unique [is_empty α] : unique (filter α) :=
546+
{ default := ⊥, uniq := filter_eq_bot_of_is_empty }
547+
539548
lemma forall_sets_nonempty_iff_ne_bot {f : filter α} :
540549
(∀ (s : set α), s ∈ f → s.nonempty) ↔ ne_bot f :=
541550
⟨λ h, ⟨λ hf, empty_not_nonempty (h ∅ $ hf.symm ▸ mem_bot_sets)⟩, @nonempty_of_mem_sets _ _⟩
542551

543552
lemma nontrivial_iff_nonempty : nontrivial (filter α) ↔ nonempty α :=
544553
⟨λ ⟨⟨f, g, hfg⟩⟩, by_contra $
545-
λ h, hfg $ (filter_eq_bot_of_not_nonempty f h).trans (filter_eq_bot_of_not_nonempty g h).symm,
554+
λ h, hfg $ by haveI : is_empty α := not_nonempty_iff.1 h; exact subsingleton.elim _ _,
546555
λ ⟨x⟩, ⟨⟨⊤, ⊥, ne_bot.ne $ forall_sets_nonempty_iff_ne_bot.1 $ λ s hs,
547556
by rwa [mem_top_sets.1 hs, ← nonempty_iff_univ_nonempty]⟩⟩⟩
548557

src/set_theory/cardinal.lean

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,14 @@ instance : has_zero cardinal.{u} := ⟨⟦pempty⟧⟩
140140

141141
instance : inhabited cardinal.{u} := ⟨0
142142

143+
@[simp]
144+
lemma eq_zero_of_is_empty {α : Type u} [is_empty α] : mk α = 0 :=
145+
quotient.sound ⟨equiv.equiv_pempty α⟩
146+
143147
lemma eq_zero_iff_is_empty {α : Type u} : mk α = 0 ↔ is_empty α :=
144148
⟨λ e, let ⟨h⟩ := quotient.exact e in
145149
equiv.equiv_empty_equiv α $ h.trans equiv.empty_equiv_pempty.symm,
146-
λ h, by exactI quotient.sound ⟨equiv.equiv_pempty α⟩
150+
@eq_zero_of_is_empty _
147151

148152
theorem ne_zero_iff_nonempty {α : Type u} : mk α ≠ 0 ↔ nonempty α :=
149153
(not_iff_not.2 eq_zero_iff_is_empty).trans not_is_empty_iff
@@ -280,7 +284,7 @@ section order_properties
280284
open sum
281285

282286
protected theorem zero_le : ∀(a : cardinal), 0 ≤ a :=
283-
by rintro ⟨α⟩; exact ⟨embedding.of_not_nonempty $ λ ⟨a⟩, a.elim
287+
by rintro ⟨α⟩; exact ⟨embedding.of_is_empty
284288

285289
protected theorem add_le_add : ∀{a b c d : cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d :=
286290
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.sum_map e₂⟩

src/set_theory/ordinal.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,7 @@ quotient.sound ⟨⟨empty_equiv_pempty.symm, λ _ _, iff.rfl⟩⟩
736736
@[simp] theorem card_zero : card 0 = 0 := rfl
737737

738738
protected theorem zero_le (o : ordinal) : 0 ≤ o :=
739-
induction_on o $ λ α r _,
740-
⟨⟨⟨embedding.of_not_nonempty $ λ ⟨a⟩, a.elim,
741-
λ a, a.elim⟩, λ a, a.elim⟩⟩
739+
induction_on o $ λ α r _, ⟨⟨⟨embedding.of_is_empty, is_empty_elim⟩, is_empty_elim⟩⟩
742740

743741
@[simp] protected theorem le_zero {o : ordinal} : o ≤ 0 ↔ o = 0 :=
744742
by simp only [le_antisymm_iff, ordinal.zero_le, and_true]

0 commit comments

Comments
 (0)