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

Commit fde3d78

Browse files
committed
chore(multiset): dedicated notation for multiset.cons (#4600)
1 parent 7368d71 commit fde3d78

30 files changed

+211
-207
lines changed

src/algebra/big_operators/basic.lean

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,11 +1089,11 @@ variables [decidable_eq α]
10891089
(∑ a in s.to_finset, s.count a) = s.card :=
10901090
multiset.induction_on s rfl
10911091
(assume a s ih,
1092-
calc (∑ x in to_finset (a :: s), count x (a :: s)) =
1093-
∑ x in to_finset (a :: s), ((if x = a then 1 else 0) + count x s) :
1092+
calc (∑ x in to_finset (a :: s), count x (a :: s)) =
1093+
∑ x in to_finset (a :: s), ((if x = a then 1 else 0) + count x s) :
10941094
finset.sum_congr rfl $ λ _ _, by split_ifs;
10951095
[simp only [h, count_cons_self, nat.one_add], simp only [count_cons_of_ne h, zero_add]]
1096-
... = card (a :: s) :
1096+
... = card (a :: s) :
10971097
begin
10981098
by_cases a ∈ s.to_finset,
10991099
{ have : ∑ x in s.to_finset, ite (x = a) 1 0 = ∑ x in {a}, ite (x = a) 1 0,
@@ -1112,11 +1112,11 @@ lemma count_sum' {s : finset β} {a : α} {f : β → multiset α} :
11121112
by { dunfold finset.sum, rw count_sum }
11131113

11141114
lemma to_finset_sum_count_smul_eq (s : multiset α) :
1115-
(∑ a in s.to_finset, s.count a •ℕ (a :: 0)) = s :=
1115+
(∑ a in s.to_finset, s.count a •ℕ (a :: 0)) = s :=
11161116
begin
11171117
apply ext', intro b,
11181118
rw count_sum',
1119-
have h : count b s = count b (count b s •ℕ (b :: 0)),
1119+
have h : count b s = count b (count b s •ℕ (b :: 0)),
11201120
{ rw [singleton_coe, count_smul, ← singleton_coe, count_singleton, mul_one] },
11211121
rw h, clear h,
11221122
apply finset.sum_eq_single b,
@@ -1128,9 +1128,9 @@ end
11281128
theorem exists_smul_of_dvd_count (s : multiset α) {k : ℕ} (h : ∀ (a : α), k ∣ multiset.count a s) :
11291129
∃ (u : multiset α), s = k •ℕ u :=
11301130
begin
1131-
use ∑ a in s.to_finset, (s.count a / k) •ℕ (a :: 0),
1132-
have h₂ : ∑ (x : α) in s.to_finset, k •ℕ (count x s / k •ℕ (x :: 0)) =
1133-
∑ (x : α) in s.to_finset, count x s •ℕ (x :: 0),
1131+
use ∑ a in s.to_finset, (s.count a / k) •ℕ (a :: 0),
1132+
have h₂ : ∑ (x : α) in s.to_finset, k •ℕ (count x s / k •ℕ (x :: 0)) =
1133+
∑ (x : α) in s.to_finset, count x s •ℕ (x :: 0),
11341134
{ refine congr_arg s.to_finset.sum _,
11351135
apply funext, intro x,
11361136
rw [← mul_nsmul, nat.mul_div_cancel' (h x)] },

src/data/dfinsupp.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,11 @@ begin
367367
{ left, rw H3, exact H1 },
368368
{ left, exact H3 } },
369369
right, exact H2 },
370-
have H3 : (⟦{to_fun := f, pre_support := i :: s, zero := H}⟧ : Π₀ i, β i)
370+
have H3 : (⟦{to_fun := f, pre_support := i :: s, zero := H}⟧ : Π₀ i, β i)
371371
= ⟦{to_fun := f, pre_support := s, zero := H2}⟧,
372372
{ exact quotient.sound (λ i, rfl) },
373373
rw H3, apply ih },
374-
have H2 : p (erase i ⟦{to_fun := f, pre_support := i :: s, zero := H}⟧),
374+
have H2 : p (erase i ⟦{to_fun := f, pre_support := i :: s, zero := H}⟧),
375375
{ dsimp only [erase, quotient.lift_on_beta],
376376
have H2 : ∀ j, j ∈ s ∨ ite (j = i) 0 (f j) = 0,
377377
{ intro j, cases H j with H2 H2,
@@ -380,11 +380,11 @@ begin
380380
{ left, exact H3 } },
381381
right, split_ifs; [refl, exact H2] },
382382
have H3 : (⟦{to_fun := λ (j : ι), ite (j = i) 0 (f j),
383-
pre_support := i :: s, zero := _}⟧ : Π₀ i, β i)
383+
pre_support := i :: s, zero := _}⟧ : Π₀ i, β i)
384384
= ⟦{to_fun := λ (j : ι), ite (j = i) 0 (f j), pre_support := s, zero := H2}⟧ :=
385385
quotient.sound (λ i, rfl),
386386
rw H3, apply ih },
387-
have H3 : single i _ + _ = (⟦{to_fun := f, pre_support := i :: s, zero := H}⟧ : Π₀ i, β i) :=
387+
have H3 : single i _ + _ = (⟦{to_fun := f, pre_support := i :: s, zero := H}⟧ : Π₀ i, β i) :=
388388
single_add_erase,
389389
rw ← H3,
390390
change p (single i (f i) + _),

src/data/finmap.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ lift_on s (λ t, ⟦insert a b t⟧) $
314314
insert a b ⟦s⟧ = ⟦s.insert a b⟧ := by simp [insert]
315315

316316
theorem insert_entries_of_neg {a : α} {b : β a} {s : finmap β} : a ∉ s →
317-
(insert a b s).entries = ⟨a, b⟩ :: s.entries :=
317+
(insert a b s).entries = ⟨a, b⟩ :: s.entries :=
318318
induction_on s $ λ s h,
319319
by simp [insert_entries_of_neg (mt mem_to_finmap.1 h)]
320320

src/data/finset/basic.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ This differs from `insert a ∅` in that it does not require a `decidable_eq` in
220220
-/
221221
instance : has_singleton α (finset α) := ⟨λ a, ⟨{a}, nodup_singleton a⟩⟩
222222

223-
@[simp] theorem singleton_val (a : α) : ({a} : finset α).1 = a :: 0 := rfl
223+
@[simp] theorem singleton_val (a : α) : ({a} : finset α).1 = a :: 0 := rfl
224224

225225
@[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : finset α) ↔ b = a := mem_singleton
226226

@@ -264,15 +264,15 @@ singleton_subset_set_iff
264264
`insert a s` when it is defined, but unlike `insert a s` it does not require `decidable_eq α`,
265265
and the union is guaranteed to be disjoint. -/
266266
def cons {α} (a : α) (s : finset α) (h : a ∉ s) : finset α :=
267-
⟨a :: s.1, multiset.nodup_cons.2 ⟨h, s.2⟩⟩
267+
⟨a :: s.1, multiset.nodup_cons.2 ⟨h, s.2⟩⟩
268268

269269
@[simp] theorem mem_cons {α a s h b} : b ∈ @cons α a s h ↔ b = a ∨ b ∈ s :=
270270
by rcases s with ⟨⟨s⟩⟩; apply list.mem_cons_iff
271271

272-
@[simp] theorem cons_val {a : α} {s : finset α} (h : a ∉ s) : (cons a s h).1 = a :: s.1 := rfl
272+
@[simp] theorem cons_val {a : α} {s : finset α} (h : a ∉ s) : (cons a s h).1 = a :: s.1 := rfl
273273

274-
@[simp] theorem mk_cons {a : α} {s : multiset α} (h : (a :: s).nodup) :
275-
(⟨a :: s, h⟩ : finset α) = cons a ⟨s, (multiset.nodup_cons.1 h).2⟩ (multiset.nodup_cons.1 h).1 :=
274+
@[simp] theorem mk_cons {a : α} {s : multiset α} (h : (a :: s).nodup) :
275+
(⟨a :: s, h⟩ : finset α) = cons a ⟨s, (multiset.nodup_cons.1 h).2⟩ (multiset.nodup_cons.1 h).1 :=
276276
rfl
277277

278278
@[simp] theorem nonempty_cons {a : α} {s : finset α} (h : a ∉ s) : (cons a s h).nonempty :=
@@ -305,10 +305,10 @@ theorem insert_def (a : α) (s : finset α) : insert a s = ⟨_, nodup_ndinsert
305305

306306
@[simp] theorem insert_val (a : α) (s : finset α) : (insert a s).1 = ndinsert a s.1 := rfl
307307

308-
theorem insert_val' (a : α) (s : finset α) : (insert a s).1 = erase_dup (a :: s.1) :=
308+
theorem insert_val' (a : α) (s : finset α) : (insert a s).1 = erase_dup (a :: s.1) :=
309309
by rw [erase_dup_cons, erase_dup_eq_self]; refl
310310

311-
theorem insert_val_of_not_mem {a : α} {s : finset α} (h : a ∉ s) : (insert a s).1 = a :: s.1 :=
311+
theorem insert_val_of_not_mem {a : α} {s : finset α} (h : a ∉ s) : (insert a s).1 = a :: s.1 :=
312312
by rw [insert_val, ndinsert_of_not_mem h]
313313

314314
@[simp] theorem mem_insert {a b : α} {s : finset α} : a ∈ insert b s ↔ a = b ∨ a ∈ s := mem_ndinsert
@@ -373,7 +373,7 @@ protected theorem induction {α : Type*} {p : finset α → Prop} [decidable_eq
373373
(h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s
374374
| ⟨s, nd⟩ := multiset.induction_on s (λ _, h₁) (λ a s IH nd, begin
375375
cases nodup_cons.1 nd with m nd',
376-
rw [← (eq_of_veq _ : insert a (finset.mk s _) = ⟨a::s, nd⟩)],
376+
rw [← (eq_of_veq _ : insert a (finset.mk s _) = ⟨a ::ₘ s, nd⟩)],
377377
{ exact h₂ (by exact m) (IH nd') },
378378
{ rw [insert_val, ndinsert_of_not_mem m] }
379379
end) nd
@@ -1215,7 +1215,7 @@ mem_erase_dup
12151215
rfl
12161216

12171217
@[simp] lemma to_finset_cons (a : α) (s : multiset α) :
1218-
to_finset (a :: s) = insert a (to_finset s) :=
1218+
to_finset (a :: s) = insert a (to_finset s) :=
12191219
finset.eq_of_veq erase_dup_cons
12201220

12211221
@[simp] lemma to_finset_add (s t : multiset α) :

src/data/finset/pi.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ assume e₁ e₂ eq,
7474
begin
7575
apply eq_of_veq,
7676
rw ← multiset.erase_dup_eq_self.2 (pi (insert a s) t).2,
77-
refine (λ s' (h : s' = a :: s.1), (_ : erase_dup (multiset.pi s' (λ a, (t a).1)) =
77+
refine (λ s' (h : s' = a :: s.1), (_ : erase_dup (multiset.pi s' (λ a, (t a).1)) =
7878
erase_dup ((t a).1.bind $ λ b,
7979
erase_dup $ (multiset.pi s.1 (λ (a : α), (t a).val)).map $
8080
λ f a' h', multiset.pi.cons s.1 a b f a' (h ▸ h')))) _ (insert_val_of_not_mem ha),

src/data/finsupp/basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,8 +1320,8 @@ end
13201320
calc f.to_multiset.count a = f.sum (λx n, (n •ℕ {x} : multiset α).count a) :
13211321
(f.support.sum_hom $ multiset.count a).symm
13221322
... = f.sum (λx n, n * ({x} : multiset α).count a) : by simp only [multiset.count_smul]
1323-
... = f.sum (λx n, n * (x :: 0 : multiset α).count a) : rfl
1324-
... = f a * (a :: 0 : multiset α).count a : sum_eq_single _
1323+
... = f.sum (λx n, n * (x :: 0 : multiset α).count a) : rfl
1324+
... = f a * (a :: 0 : multiset α).count a : sum_eq_single _
13251325
(λ a' _ H, by simp only [multiset.count_cons_of_ne (ne.symm H), multiset.count_zero, mul_zero])
13261326
(λ H, by simp only [not_mem_support_iff.1 H, zero_mul])
13271327
... = f a : by simp only [multiset.count_singleton, mul_one]

src/data/fintype/basic.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ instance : fintype punit := fintype.of_subsingleton punit.star
387387

388388
@[simp] theorem fintype.card_punit : fintype.card punit = 1 := rfl
389389

390-
instance : fintype bool := ⟨⟨tt::ff::0, by simp⟩, λ x, by cases x; simp⟩
390+
instance : fintype bool := ⟨⟨tt ::ₘ ff ::ₘ 0, by simp⟩, λ x, by cases x; simp⟩
391391

392392
@[simp] theorem fintype.univ_bool : @univ bool _ = {tt, ff} := rfl
393393

@@ -408,7 +408,7 @@ by classical; exact fintype.of_injective units.val units.ext
408408
/-- Given a finset on `α`, lift it to being a finset on `option α`
409409
using `option.some` and then insert `option.none`. -/
410410
def finset.insert_none (s : finset α) : finset (option α) :=
411-
⟨none :: s.1.map some, multiset.nodup_cons.2
411+
⟨none :: s.1.map some, multiset.nodup_cons.2
412412
by simp, multiset.nodup_map (λ a b, option.some.inj) s.2⟩⟩
413413

414414
@[simp] theorem finset.mem_insert_none {s : finset α} : ∀ {o : option α},
@@ -660,7 +660,7 @@ instance plift.fintype (p : Prop) [decidable p] : fintype (plift p) :=
660660
if h : p then {⟨h⟩} else ∅, λ ⟨h⟩, by simp [h]⟩
661661

662662
instance Prop.fintype : fintype Prop :=
663-
⟨⟨true::false::0, by simp [true_ne_false]⟩,
663+
⟨⟨true ::ₘ false ::ₘ 0, by simp [true_ne_false]⟩,
664664
classical.cases (by simp) (by simp)⟩
665665

666666
instance subtype.fintype (p : α → Prop) [decidable_pred p] [fintype α] : fintype {x // p x} :=

src/data/multiset/antidiagonal.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ by simp [powerset_aux']
5353
quotient.induction_on s $ λ l,
5454
by simp [powerset_aux']
5555

56-
@[simp] theorem antidiagonal_zero : @antidiagonal α 0 = (0, 0)::0 := rfl
56+
@[simp] theorem antidiagonal_zero : @antidiagonal α 0 = (0, 0) ::ₘ 0 := rfl
5757

58-
@[simp] theorem antidiagonal_cons (a : α) (s) : antidiagonal (a::s) =
58+
@[simp] theorem antidiagonal_cons (a : α) (s) : antidiagonal (a ::ₘ s) =
5959
map (prod.map id (cons a)) (antidiagonal s) +
6060
map (prod.map (cons a) id) (antidiagonal s) :=
6161
quotient.induction_on s $ λ l, begin

0 commit comments

Comments
 (0)