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

Commit 40b09aa

Browse files
robertylewismergify[bot]
authored andcommitted
feat(*): small lemmas from the sensitivity formalization (#1352)
* feat(set_theory/cardinal): norm_cast attributes and extra lemma * feat(logic/basic): ne.symm_iff * feat(data/fin): succ_ne_zero * feat(data/bool): bxor_of_ne * feat(algebra/big_operators, data/fintype): {finset,fintype}.card_eq_sum_ones * feat(data/set): range_restrict * feat(data/finset): inter lemmas * Reid's corrections * fixes * fix cardinal power lemma * fixes * Update bool.lean
1 parent f442a41 commit 40b09aa

File tree

8 files changed

+51
-15
lines changed

8 files changed

+51
-15
lines changed

src/algebra/big_operators.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ lemma sum_range_id (n : ℕ) : (finset.range n).sum (λi, i) = (n * (n - 1)) / 2
642642
by rw [← sum_range_id_mul_two n, nat.mul_div_cancel]; exact dec_trivial
643643

644644
end gauss_sum
645+
646+
lemma card_eq_sum_ones (s : finset α) : s.card = s.sum (λ _, 1) :=
647+
by simp
648+
645649
end finset
646650

647651
section group

src/data/bool.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,6 @@ theorem eq_ff_of_bnot_eq_tt : ∀ {a : bool}, bnot a = tt → a = ff := dec_triv
115115

116116
@[simp] theorem bxor_left_comm : ∀ a b c, bxor a (bxor b c) = bxor b (bxor a c) := dec_trivial
117117

118+
lemma bxor_iff_ne : ∀ {x y : bool}, bxor x y = tt ↔ x ≠ y := dec_trivial
119+
118120
end bool

src/data/fin.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ by cases j; simp [fin.succ]
5858
protected theorem succ.inj (p : fin.succ a = fin.succ b) : a = b :=
5959
by cases a; cases b; exact eq_of_veq (nat.succ.inj (veq_of_eq p))
6060

61+
lemma succ_ne_zero {n} : ∀ k : fin n, fin.succ k ≠ 0
62+
| ⟨k, hk⟩ heq := nat.succ_ne_zero k $ (fin.ext_iff _ _).1 heq
63+
6164
@[simp] lemma pred_val (j : fin (n+1)) (h : j ≠ 0) : (j.pred h).val = j.val.pred :=
6265
by cases j; simp [fin.pred]
6366

src/data/finset.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,19 @@ by rw [inter_comm, singleton_inter_of_mem h]
401401
@[simp] theorem inter_singleton_of_not_mem {a : α} {s : finset α} (h : a ∉ s) : s ∩ ι a = ∅ :=
402402
by rw [inter_comm, singleton_inter_of_not_mem h]
403403

404+
lemma inter_subset_inter {x y s t : finset α} (h : x ⊆ y) (h' : s ⊆ t) : x ∩ s ⊆ y ∩ t :=
405+
begin
406+
intros a a_in,
407+
rw finset.mem_inter at a_in ⊢,
408+
exact ⟨h a_in.1, h' a_in.2
409+
end
410+
411+
lemma inter_subset_inter_right {x y s : finset α} (h : x ⊆ y) : x ∩ s ⊆ y ∩ s :=
412+
finset.inter_subset_inter h (finset.subset.refl _)
413+
414+
lemma inter_subset_inter_left {x y s : finset α} (h : x ⊆ y) : s ∩ x ⊆ s ∩ y :=
415+
finset.inter_subset_inter (finset.subset.refl _) h
416+
404417
/- lattice laws -/
405418

406419
instance : lattice (finset α) :=

src/data/fintype.lean

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,24 @@ theorem card_congr {α β} [fintype α] [fintype β] (f : α ≃ β) : card α =
161161
by rw ← of_equiv_card f; congr
162162

163163
theorem card_eq {α β} [F : fintype α] [G : fintype β] : card α = card β ↔ nonempty (α ≃ β) :=
164-
⟨λ h, ⟨by classical;
164+
⟨λ h, ⟨by classical;
165165
calc α ≃ fin (card α) : trunc.out (equiv_fin α)
166166
... ≃ fin (card β) : by rw h
167-
... ≃ β : (trunc.out (equiv_fin β)).symm⟩,
167+
... ≃ β : (trunc.out (equiv_fin β)).symm⟩,
168168
λ ⟨f⟩, card_congr f⟩
169169

170170
def of_subsingleton (a : α) [subsingleton α] : fintype α :=
171171
⟨finset.singleton a, λ b, finset.mem_singleton.2 (subsingleton.elim _ _)⟩
172172

173-
@[simp] theorem fintype.univ_of_subsingleton (a : α) [subsingleton α] :
173+
@[simp] theorem univ_of_subsingleton (a : α) [subsingleton α] :
174174
@univ _ (of_subsingleton a) = finset.singleton a := rfl
175175

176-
@[simp] theorem fintype.card_of_subsingleton (a : α) [subsingleton α] :
176+
@[simp] theorem card_of_subsingleton (a : α) [subsingleton α] :
177177
@fintype.card _ (of_subsingleton a) = 1 := rfl
178178

179+
lemma card_eq_sum_ones {α} [fintype α] : fintype.card α = (finset.univ : finset α).sum (λ _, 1) :=
180+
finset.card_eq_sum_ones _
181+
179182
end fintype
180183

181184
lemma finset.card_univ [fintype α] : (finset.univ : finset α).card = fintype.card α :=
@@ -436,20 +439,20 @@ instance finset.fintype [fintype α] : fintype (finset α) :=
436439
instance subtype.fintype [fintype α] (p : α → Prop) [decidable_pred p] : fintype {x // p x} :=
437440
set_fintype _
438441

439-
instance psigma.fintype {α : Type*} {β : α → Type*} [fintype α] [∀ a, fintype (β a)] :
440-
fintype (Σ' a, β a) :=
442+
instance psigma.fintype {α : Type*} {β : α → Type*} [fintype α] [∀ a, fintype (β a)] :
443+
fintype (Σ' a, β a) :=
441444
fintype.of_equiv _ (equiv.psigma_equiv_sigma _).symm
442445

443-
instance psigma.fintype_prop_left {α : Prop} {β : α → Type*} [∀ a, fintype (β a)] [decidable α] :
446+
instance psigma.fintype_prop_left {α : Prop} {β : α → Type*} [∀ a, fintype (β a)] [decidable α] :
444447
fintype (Σ' a, β a) :=
445-
if h : α then fintype.of_equiv (β h) ⟨λ x, ⟨h, x⟩, psigma.snd, λ _, rfl, λ ⟨_, _⟩, rfl⟩
448+
if h : α then fintype.of_equiv (β h) ⟨λ x, ⟨h, x⟩, psigma.snd, λ _, rfl, λ ⟨_, _⟩, rfl⟩
446449
else ⟨∅, λ x, h x.1
447450

448-
instance psigma.fintype_prop_right {α : Type*} {β : α → Prop} [fintype α] [∀ a, decidable (β a)] :
451+
instance psigma.fintype_prop_right {α : Type*} {β : α → Prop} [fintype α] [∀ a, decidable (β a)] :
449452
fintype (Σ' a, β a) :=
450453
fintype.of_equiv {a // β a} ⟨λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, rfl, λ ⟨x, y⟩, rfl⟩
451454

452-
instance psigma.fintype_prop_prop {α : Prop} {β : α → Prop} [decidable α] [∀ a, decidable (β a)] :
455+
instance psigma.fintype_prop_prop {α : Prop} {β : α → Prop} [decidable α] [∀ a, decidable (β a)] :
453456
fintype (Σ' a, β a) :=
454457
if h : ∃ a, β a then ⟨{⟨h.fst, h.snd⟩}, λ ⟨_, _⟩, by simp⟩ else ⟨∅, λ ⟨x, y⟩, h ⟨x, y⟩⟩
455458

src/data/set/function.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,8 @@ theorem bij_on_of_inv_on {g : β → α} {f : α → β} {a : set α} {b : set
292292
(h₂ : maps_to g b a) (h₃ : inv_on g f a b) : bij_on f a b :=
293293
⟨h₁, inj_on_of_left_inv_on h₃.left, surj_on_of_right_inv_on h₂ h₃.right⟩
294294

295+
lemma range_restrict {α : Type*} {β : Type*} (f : α → β) (p : set α) :
296+
range (restrict f p) = f '' (p : set α) :=
297+
by { ext x, simp [restrict], refl }
298+
295299
end set

src/logic/basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ assume ⟨h⟩, h.elim
7474
-- missing [symm] attribute for ne in core.
7575
attribute [symm] ne.symm
7676

77+
lemma ne_comm {α} {a b : α} : a ≠ b ↔ b ≠ a := ⟨ne.symm, ne.symm⟩
78+
7779
end miscellany
7880

7981
/-

src/set_theory/cardinal.lean

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ by rw [_root_.mul_comm b c];
212212
from (quotient.induction_on₃ a b c $ assume α β γ,
213213
quotient.sound ⟨equiv.arrow_arrow_equiv_prod_arrow γ β α⟩)
214214

215+
@[simp] lemma pow_cast_right (κ : cardinal.{u}) :
216+
∀ n : ℕ, (κ ^ (↑n : cardinal.{u})) = @has_pow.pow _ _ monoid.has_pow κ n
217+
| 0 := by simp
218+
| (_+1) := by rw [nat.cast_succ, power_add, power_one, _root_.mul_comm, pow_succ, pow_cast_right]
219+
215220
section order_properties
216221
open sum
217222

@@ -581,10 +586,10 @@ begin
581586
rw [cardinal.fintype_card, fintype.card_coe]
582587
end
583588

584-
@[simp] theorem nat_cast_pow {m n : ℕ} : (↑(pow m n) : cardinal) = m ^ n :=
589+
@[simp, elim_cast] theorem nat_cast_pow {m n : ℕ} : (↑(pow m n) : cardinal) = m ^ n :=
585590
by induction n; simp [nat.pow_succ, -_root_.add_comm, power_add, *]
586591

587-
@[simp] theorem nat_cast_le {m n : ℕ} : (m : cardinal) ≤ n ↔ m ≤ n :=
592+
@[simp, elim_cast] theorem nat_cast_le {m n : ℕ} : (m : cardinal) ≤ n ↔ m ≤ n :=
588593
by rw [← lift_mk_fin, ← lift_mk_fin, lift_le]; exact
589594
⟨λ ⟨⟨f, hf⟩⟩, begin
590595
have : _ = fintype.card _ := finset.card_image_of_injective finset.univ hf,
@@ -595,13 +600,13 @@ end,
595600
λ h, ⟨⟨λ i, ⟨i.1, lt_of_lt_of_le i.2 h⟩, λ a b h,
596601
have _, from fin.veq_of_eq h, fin.eq_of_veq this⟩⟩⟩
597602

598-
@[simp] theorem nat_cast_lt {m n : ℕ} : (m : cardinal) < n ↔ m < n :=
603+
@[simp, elim_cast] theorem nat_cast_lt {m n : ℕ} : (m : cardinal) < n ↔ m < n :=
599604
by simp [lt_iff_le_not_le, -not_le]
600605

601-
@[simp] theorem nat_cast_inj {m n : ℕ} : (m : cardinal) = n ↔ m = n :=
606+
@[simp, elim_cast] theorem nat_cast_inj {m n : ℕ} : (m : cardinal) = n ↔ m = n :=
602607
by simp [le_antisymm_iff]
603608

604-
@[simp] theorem nat_succ (n : ℕ) : succ n = n.succ :=
609+
@[simp, elim_cast] theorem nat_succ (n : ℕ) : succ n = n.succ :=
605610
le_antisymm (succ_le.2 $ nat_cast_lt.2 $ nat.lt_succ_self _) (add_one_le_succ _)
606611

607612
@[simp] theorem succ_zero : succ 0 = 1 :=

0 commit comments

Comments
 (0)