@@ -2360,12 +2360,13 @@ variable [DecidableEq α]
2360
2360
2361
2361
/-- `count a s` is the multiplicity of `a` in `s`. -/
2362
2362
def count (a : α) : Multiset α → ℕ :=
2363
- countp (· = a )
2363
+ countp (a = · )
2364
2364
#align multiset.count Multiset.count
2365
2365
2366
2366
@[simp]
2367
- theorem coe_count (a : α) (l : List α) : count a (ofList l) = l.count a :=
2368
- coe_countp (· = a) l
2367
+ theorem coe_count (a : α) (l : List α) : count a (ofList l) = l.count a := by
2368
+ simp_rw [count, List.count, coe_countp (a = ·) l, @eq_comm _ a]
2369
+ rfl
2369
2370
#align multiset.coe_count Multiset.coe_count
2370
2371
2371
2372
@[simp, nolint simpNF] -- Porting note: simp can prove this at EOF, but not right now
@@ -2380,7 +2381,7 @@ theorem count_cons_self (a : α) (s : Multiset α) : count a (a ::ₘ s) = count
2380
2381
2381
2382
@[simp]
2382
2383
theorem count_cons_of_ne {a b : α} (h : a ≠ b) (s : Multiset α) : count a (b ::ₘ s) = count a s :=
2383
- countp_cons_of_neg _ $ h.symm
2384
+ countp_cons_of_neg _ $ h
2384
2385
#align multiset.count_cons_of_ne Multiset.count_cons_of_ne
2385
2386
2386
2387
theorem count_le_card (a : α) (s) : count a s ≤ card s :=
@@ -2396,9 +2397,8 @@ theorem count_le_count_cons (a b : α) (s : Multiset α) : count a s ≤ count a
2396
2397
#align multiset.count_le_count_cons Multiset.count_le_count_cons
2397
2398
2398
2399
theorem count_cons (a b : α) (s : Multiset α) :
2399
- count a (b ::ₘ s) = count a s + if a = b then 1 else 0 := by
2400
- refine' (countp_cons (· = a) _ _).trans _
2401
- simp only [@eq_comm _ a b]; rfl
2400
+ count a (b ::ₘ s) = count a s + if a = b then 1 else 0 :=
2401
+ countp_cons (a = ·) _ _
2402
2402
#align multiset.count_cons Multiset.count_cons
2403
2403
2404
2404
theorem count_singleton_self (a : α) : count a ({a} : Multiset α) = 1 :=
@@ -2417,7 +2417,7 @@ theorem count_add (a : α) : ∀ s t, count a (s + t) = count a s + count a t :=
2417
2417
2418
2418
/-- `count a`, the multiplicity of `a` in a multiset, promoted to an `AddMonoidHom`. -/
2419
2419
def countAddMonoidHom (a : α) : Multiset α →+ ℕ :=
2420
- countpAddMonoidHom (· = a )
2420
+ countpAddMonoidHom (a = · )
2421
2421
#align multiset.count_add_monoid_hom Multiset.countAddMonoidHom
2422
2422
2423
2423
@[simp]
@@ -2456,23 +2456,27 @@ theorem count_eq_card {a : α} {s} : count a s = card s ↔ ∀ x ∈ s, a = x :
2456
2456
#align multiset.count_eq_card Multiset.count_eq_card
2457
2457
2458
2458
@[simp]
2459
- theorem count_replicate_self (a : α) (n : ℕ) : count a (replicate n a) = n :=
2460
- List.count_replicate_self ..
2459
+ theorem count_replicate_self (a : α) (n : ℕ) : count a (replicate n a) = n := by
2460
+ convert List.count_replicate_self a n
2461
+ rw [←coe_count, coe_replicate]
2461
2462
#align multiset.count_replicate_self Multiset.count_replicate_self
2462
2463
2463
- theorem count_replicate (a b : α) (n : ℕ) : count a (replicate n b) = if a = b then n else 0 :=
2464
- List.count_replicate ..
2464
+ theorem count_replicate (a b : α) (n : ℕ) : count a (replicate n b) = if a = b then n else 0 := by
2465
+ convert List.count_replicate a b n
2466
+ rw [←coe_count, coe_replicate]
2465
2467
#align multiset.count_replicate Multiset.count_replicate
2466
2468
2467
2469
@[simp]
2468
2470
theorem count_erase_self (a : α) (s : Multiset α) : count a (erase s a) = count a s - 1 :=
2469
- Quotient.inductionOn s <| List.count_erase_self a
2471
+ Quotient.inductionOn s <| fun l => by
2472
+ convert List.count_erase_self a l <;> rw [←coe_count] <;> simp
2470
2473
#align multiset.count_erase_self Multiset.count_erase_self
2471
2474
2472
2475
@[simp]
2473
2476
theorem count_erase_of_ne {a b : α} (ab : a ≠ b) (s : Multiset α) :
2474
2477
count a (erase s b) = count a s :=
2475
- Quotient.inductionOn s <| List.count_erase_of_ne ab
2478
+ Quotient.inductionOn s <| fun l => by
2479
+ convert List.count_erase_of_ne ab l <;> rw [←coe_count] <;> simp
2476
2480
#align multiset.count_erase_of_ne Multiset.count_erase_of_ne
2477
2481
2478
2482
@[simp]
@@ -2499,13 +2503,18 @@ theorem count_inter (a : α) (s t : Multiset α) : count a (s ∩ t) = min (coun
2499
2503
2500
2504
theorem le_count_iff_replicate_le {a : α} {s : Multiset α} {n : ℕ} :
2501
2505
n ≤ count a s ↔ replicate n a ≤ s :=
2502
- Quot.inductionOn s fun _l => le_count_iff_replicate_sublist.trans replicate_le_coe.symm
2506
+ Quot.inductionOn s fun _l => by
2507
+ simp only [quot_mk_to_coe'', mem_coe, coe_count]
2508
+ exact le_count_iff_replicate_sublist.trans replicate_le_coe.symm
2503
2509
#align multiset.le_count_iff_replicate_le Multiset.le_count_iff_replicate_le
2504
2510
2505
2511
@[simp]
2506
2512
theorem count_filter_of_pos {p} [DecidablePred p] {a} {s : Multiset α} (h : p a) :
2507
2513
count a (filter p s) = count a s :=
2508
- Quot.inductionOn s fun _l => count_filter $ by simpa using h
2514
+ Quot.inductionOn s fun _l => by
2515
+ simp only [quot_mk_to_coe'', coe_filter, mem_coe, coe_count, decide_eq_true_eq]
2516
+ apply count_filter
2517
+ simpa using h
2509
2518
#align multiset.count_filter_of_pos Multiset.count_filter_of_pos
2510
2519
2511
2520
@[simp]
@@ -2523,7 +2532,9 @@ theorem count_filter {p} [DecidablePred p] {a} {s : Multiset α} :
2523
2532
#align multiset.count_filter Multiset.count_filter
2524
2533
2525
2534
theorem ext {s t : Multiset α} : s = t ↔ ∀ a, count a s = count a t :=
2526
- Quotient.inductionOn₂ s t fun _l₁ _l₂ => Quotient.eq.trans perm_iff_count
2535
+ Quotient.inductionOn₂ s t fun _l₁ _l₂ => Quotient.eq.trans <| by
2536
+ simp only [quot_mk_to_coe, coe_filter, mem_coe, coe_count, decide_eq_true_eq]
2537
+ apply perm_iff_count
2527
2538
#align multiset.ext Multiset.ext
2528
2539
2529
2540
@[ext]
@@ -2560,7 +2571,7 @@ the multiset -/
2560
2571
theorem count_map_eq_count [DecidableEq β] (f : α → β) (s : Multiset α)
2561
2572
(hf : Set.InjOn f { x : α | x ∈ s }) (x) (H : x ∈ s) : (s.map f).count (f x) = s.count x :=
2562
2573
by
2563
- suffices (filter (fun a : α => f a = f x ) s).count x = card (filter (fun a : α => f a = f x ) s)
2574
+ suffices (filter (fun a : α => f x = f a ) s).count x = card (filter (fun a : α => f x = f a ) s)
2564
2575
by
2565
2576
rw [count, countp_map, ← this]
2566
2577
exact count_filter_of_pos $ rfl
@@ -2591,7 +2602,9 @@ theorem attach_count_eq_count_coe (m : Multiset α) (a) : m.attach.count a = m.c
2591
2602
#align multiset.attach_count_eq_count_coe Multiset.attach_count_eq_count_coe
2592
2603
2593
2604
theorem filter_eq' (s : Multiset α) (b : α) : s.filter (· = b) = replicate (count b s) b :=
2594
- Quotient.inductionOn s <| fun l => congr_arg _ <| List.filter_eq' l b
2605
+ Quotient.inductionOn s <| fun l => by
2606
+ simp only [quot_mk_to_coe, coe_filter, mem_coe, coe_count]
2607
+ rw [List.filter_eq' l b, coe_replicate]
2595
2608
#align multiset.filter_eq' Multiset.filter_eq'
2596
2609
2597
2610
theorem filter_eq (s : Multiset α) (b : α) : s.filter (Eq b) = replicate (count b s) b := by
@@ -2646,7 +2659,7 @@ def mapEmbedding (f : α ↪ β) : Multiset α ↪o Multiset β :=
2646
2659
end Embedding
2647
2660
2648
2661
theorem count_eq_card_filter_eq [DecidableEq α] (s : Multiset α) (a : α) :
2649
- s.count a = card (s.filter (· = a )) := by rw [count, countp_eq_card_filter]
2662
+ s.count a = card (s.filter (a = · )) := by rw [count, countp_eq_card_filter]
2650
2663
#align multiset.count_eq_card_filter_eq Multiset.count_eq_card_filter_eq
2651
2664
2652
2665
/--
@@ -2663,7 +2676,7 @@ theorem map_count_True_eq_filter_card (s : Multiset α) (p : α → Prop) [Decid
2663
2676
simp only [count_eq_card_filter_eq, map_filter, card_map, Function.comp.left_id,
2664
2677
eq_true_eq_id, Function.comp]
2665
2678
congr; funext _
2666
- simp only [eq_iff_iff, iff_true ]
2679
+ simp only [eq_iff_iff, true_iff ]
2667
2680
#align multiset.map_count_true_eq_filter_card Multiset.map_count_True_eq_filter_card
2668
2681
2669
2682
/-! ### Lift a relation to `Multiset`s -/
0 commit comments