combinatorics.partitionMathlib.Combinatorics.Partition

This file has been ported!

Changes since the initial port

The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.

Changes in mathlib3

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(last sync)

Changes in mathlib3port

mathlib3
mathlib3port
Diff
@@ -3,7 +3,7 @@ Copyright (c) 2020 Bhavik Mehta. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Bhavik Mehta
 -/
-import Combinatorics.Composition
+import Combinatorics.Enumerative.Composition
 import Data.Nat.Parity
 import Tactic.ApplyFun
 
Diff
@@ -71,7 +71,7 @@ def ofComposition (n : ℕ) (c : Composition n) : Partition n
     where
   parts := c.blocks
   parts_pos i hi := c.blocks_pos hi
-  parts_sum := by rw [Multiset.coe_sum, c.blocks_sum]
+  parts_sum := by rw [Multiset.sum_coe, c.blocks_sum]
 #align nat.partition.of_composition Nat.Partition.ofComposition
 -/
 
@@ -97,7 +97,7 @@ def ofSums (n : ℕ) (l : Multiset ℕ) (hl : l.Sum = n) : Partition n
   parts_pos i hi := Nat.pos_of_ne_zero <| by apply of_mem_filter hi
   parts_sum := by
     have lt : l.filter (· = 0) + l.filter (· ≠ 0) = l := filter_add_not _ l
-    apply_fun Multiset.sum at lt 
+    apply_fun Multiset.sum at lt
     have lz : (l.filter (· = 0)).Sum = 0 :=
       by
       rw [Multiset.sum_eq_zero_iff]
Diff
@@ -113,15 +113,15 @@ def ofMultiset (l : Multiset ℕ) : Partition l.Sum :=
 #align nat.partition.of_multiset Nat.Partition.ofMultiset
 -/
 
-#print Nat.Partition.indiscretePartition /-
+#print Nat.Partition.indiscrete /-
 /-- The partition of exactly one part. -/
-def indiscretePartition (n : ℕ) : Partition n :=
+def indiscrete (n : ℕ) : Partition n :=
   ofSums n {n} rfl
-#align nat.partition.indiscrete_partition Nat.Partition.indiscretePartition
+#align nat.partition.indiscrete_partition Nat.Partition.indiscrete
 -/
 
 instance {n : ℕ} : Inhabited (Partition n) :=
-  ⟨indiscretePartition n⟩
+  ⟨indiscrete n⟩
 
 #print Nat.Partition.count_ofSums_of_ne_zero /-
 /-- The number of times a positive integer `i` appears in the partition `of_sums n l hl` is the same
Diff
@@ -3,9 +3,9 @@ Copyright (c) 2020 Bhavik Mehta. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Bhavik Mehta
 -/
-import Mathbin.Combinatorics.Composition
-import Mathbin.Data.Nat.Parity
-import Mathbin.Tactic.ApplyFun
+import Combinatorics.Composition
+import Data.Nat.Parity
+import Tactic.ApplyFun
 
 #align_import combinatorics.partition from "leanprover-community/mathlib"@"1ead22342e1a078bd44744ace999f85756555d35"
 
Diff
@@ -2,16 +2,13 @@
 Copyright (c) 2020 Bhavik Mehta. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Bhavik Mehta
-
-! This file was ported from Lean 3 source module combinatorics.partition
-! leanprover-community/mathlib commit 1ead22342e1a078bd44744ace999f85756555d35
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathbin.Combinatorics.Composition
 import Mathbin.Data.Nat.Parity
 import Mathbin.Tactic.ApplyFun
 
+#align_import combinatorics.partition from "leanprover-community/mathlib"@"1ead22342e1a078bd44744ace999f85756555d35"
+
 /-!
 # Partitions
 
Diff
@@ -126,6 +126,7 @@ def indiscretePartition (n : ℕ) : Partition n :=
 instance {n : ℕ} : Inhabited (Partition n) :=
   ⟨indiscretePartition n⟩
 
+#print Nat.Partition.count_ofSums_of_ne_zero /-
 /-- The number of times a positive integer `i` appears in the partition `of_sums n l hl` is the same
 as the number of times it appears in the multiset `l`.
 (For `i = 0`, `partition.non_zero` combined with `multiset.count_eq_zero_of_not_mem` gives that
@@ -135,11 +136,14 @@ theorem count_ofSums_of_ne_zero {n : ℕ} {l : Multiset ℕ} (hl : l.Sum = n) {i
     (ofSums n l hl).parts.count i = l.count i :=
   count_filter_of_pos hi
 #align nat.partition.count_of_sums_of_ne_zero Nat.Partition.count_ofSums_of_ne_zero
+-/
 
+#print Nat.Partition.count_ofSums_zero /-
 theorem count_ofSums_zero {n : ℕ} {l : Multiset ℕ} (hl : l.Sum = n) :
     (ofSums n l hl).parts.count 0 = 0 :=
   count_filter_of_neg fun h => h rfl
 #align nat.partition.count_of_sums_zero Nat.Partition.count_ofSums_zero
+-/
 
 /-- Show there are finitely many partitions by considering the surjection from compositions to
 partitions.
Diff
@@ -100,7 +100,7 @@ def ofSums (n : ℕ) (l : Multiset ℕ) (hl : l.Sum = n) : Partition n
   parts_pos i hi := Nat.pos_of_ne_zero <| by apply of_mem_filter hi
   parts_sum := by
     have lt : l.filter (· = 0) + l.filter (· ≠ 0) = l := filter_add_not _ l
-    apply_fun Multiset.sum  at lt 
+    apply_fun Multiset.sum at lt 
     have lz : (l.filter (· = 0)).Sum = 0 :=
       by
       rw [Multiset.sum_eq_zero_iff]
Diff
@@ -100,7 +100,7 @@ def ofSums (n : ℕ) (l : Multiset ℕ) (hl : l.Sum = n) : Partition n
   parts_pos i hi := Nat.pos_of_ne_zero <| by apply of_mem_filter hi
   parts_sum := by
     have lt : l.filter (· = 0) + l.filter (· ≠ 0) = l := filter_add_not _ l
-    apply_fun Multiset.sum  at lt
+    apply_fun Multiset.sum  at lt 
     have lz : (l.filter (· = 0)).Sum = 0 :=
       by
       rw [Multiset.sum_eq_zero_iff]
Diff
@@ -51,7 +51,7 @@ variable {α : Type _}
 
 open Multiset
 
-open BigOperators
+open scoped BigOperators
 
 namespace Nat
 
Diff
@@ -126,12 +126,6 @@ def indiscretePartition (n : ℕ) : Partition n :=
 instance {n : ℕ} : Inhabited (Partition n) :=
   ⟨indiscretePartition n⟩
 
-/- warning: nat.partition.count_of_sums_of_ne_zero -> Nat.Partition.count_ofSums_of_ne_zero is a dubious translation:
-lean 3 declaration is
-  forall {n : Nat} {l : Multiset.{0} Nat} (hl : Eq.{1} Nat (Multiset.sum.{0} Nat Nat.addCommMonoid l) n) {i : Nat}, (Ne.{1} Nat i (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} Nat (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) i (Nat.Partition.parts n (Nat.Partition.ofSums n l hl))) (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) i l))
-but is expected to have type
-  forall {n : Nat} {l : Multiset.{0} Nat} (hl : Eq.{1} Nat (Multiset.sum.{0} Nat Nat.addCommMonoid l) n) {i : Nat}, (Ne.{1} Nat i (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} Nat (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) i (Nat.Partition.parts n (Nat.Partition.ofSums n l hl))) (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) i l))
-Case conversion may be inaccurate. Consider using '#align nat.partition.count_of_sums_of_ne_zero Nat.Partition.count_ofSums_of_ne_zeroₓ'. -/
 /-- The number of times a positive integer `i` appears in the partition `of_sums n l hl` is the same
 as the number of times it appears in the multiset `l`.
 (For `i = 0`, `partition.non_zero` combined with `multiset.count_eq_zero_of_not_mem` gives that
@@ -142,12 +136,6 @@ theorem count_ofSums_of_ne_zero {n : ℕ} {l : Multiset ℕ} (hl : l.Sum = n) {i
   count_filter_of_pos hi
 #align nat.partition.count_of_sums_of_ne_zero Nat.Partition.count_ofSums_of_ne_zero
 
-/- warning: nat.partition.count_of_sums_zero -> Nat.Partition.count_ofSums_zero is a dubious translation:
-lean 3 declaration is
-  forall {n : Nat} {l : Multiset.{0} Nat} (hl : Eq.{1} Nat (Multiset.sum.{0} Nat Nat.addCommMonoid l) n), Eq.{1} Nat (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Nat.Partition.parts n (Nat.Partition.ofSums n l hl))) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))
-but is expected to have type
-  forall {n : Nat} {l : Multiset.{0} Nat} (hl : Eq.{1} Nat (Multiset.sum.{0} Nat Nat.addCommMonoid l) n), Eq.{1} Nat (Multiset.count.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Nat.Partition.parts n (Nat.Partition.ofSums n l hl))) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))
-Case conversion may be inaccurate. Consider using '#align nat.partition.count_of_sums_zero Nat.Partition.count_ofSums_zeroₓ'. -/
 theorem count_ofSums_zero {n : ℕ} {l : Multiset ℕ} (hl : l.Sum = n) :
     (ofSums n l hl).parts.count 0 = 0 :=
   count_filter_of_neg fun h => h rfl

Changes in mathlib4

mathlib3
mathlib4
move(Combinatorics/Enumerative): Create folder (#11666)

Move Catalan, Composition, DoubleCounting, Partition to a new folder Combinatorics.Enumerative.

Diff
@@ -3,7 +3,7 @@ Copyright (c) 2020 Bhavik Mehta. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Bhavik Mehta
 -/
-import Mathlib.Combinatorics.Composition
+import Mathlib.Combinatorics.Enumerative.Composition
 import Mathlib.Data.Nat.Parity
 import Mathlib.Tactic.ApplyFun
 
chore: Rename lemmas about the coercion List → Multiset (#11099)

These did not respect the naming convention by having the coe as a prefix instead of a suffix, or vice-versa. Also add a bunch of norm_cast

Diff
@@ -74,7 +74,7 @@ instance decidableEqPartition {n : ℕ} : DecidableEq (Partition n) :=
 def ofComposition (n : ℕ) (c : Composition n) : Partition n where
   parts := c.blocks
   parts_pos hi := c.blocks_pos hi
-  parts_sum := by rw [Multiset.coe_sum, c.blocks_sum]
+  parts_sum := by rw [Multiset.sum_coe, c.blocks_sum]
 #align nat.partition.of_composition Nat.Partition.ofComposition
 
 theorem ofComposition_surj {n : ℕ} : Function.Surjective (ofComposition n) := by
chore: change from plural to singular in porting notes (#10761)
Diff
@@ -59,7 +59,7 @@ structure Partition (n : ℕ) where
   parts_pos : ∀ {i}, i ∈ parts → 0 < i
   /-- proof that the `parts` sum to `n`-/
   parts_sum : parts.sum = n
-  -- porting notes: chokes on `parts_pos`
+  -- Porting note: chokes on `parts_pos`
   --deriving DecidableEq
 #align nat.partition Nat.Partition
 
chore(*): drop $/<| before fun (#9361)

Subset of #9319

Diff
@@ -112,7 +112,7 @@ instance {n : ℕ} : Inhabited (Partition n) := ⟨indiscrete n⟩
   simp [indiscrete, filter_eq_self, hn]
 
 @[simp] lemma partition_zero_parts (p : Partition 0) : p.parts = 0 :=
-  eq_zero_of_forall_not_mem <| fun _ h => (p.parts_pos h).ne' <| sum_eq_zero_iff.1 p.parts_sum _ h
+  eq_zero_of_forall_not_mem fun _ h => (p.parts_pos h).ne' <| sum_eq_zero_iff.1 p.parts_sum _ h
 
 instance UniquePartitionZero : Unique (Partition 0) where
   uniq _ := Partition.ext _ _ <| by simp
chore: tidy various files (#8880)
Diff
@@ -108,7 +108,7 @@ def indiscrete (n : ℕ) : Partition n := ofSums n {n} rfl
 
 instance {n : ℕ} : Inhabited (Partition n) := ⟨indiscrete n⟩
 
-@[simp] lemma indiscretePartition_parts {n : ℕ} (hn : n ≠ 0) : (indiscrete n).parts = {n} := by
+@[simp] lemma indiscrete_parts {n : ℕ} (hn : n ≠ 0) : (indiscrete n).parts = {n} := by
   simp [indiscrete, filter_eq_self, hn]
 
 @[simp] lemma partition_zero_parts (p : Partition 0) : p.parts = 0 :=
chore: space after (#8178)

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -94,7 +94,7 @@ def ofSums (n : ℕ) (l : Multiset ℕ) (hl : l.sum = n) : Partition n where
   parts_pos hi := (of_mem_filter hi).bot_lt
   parts_sum := by
     have lz : (l.filter (· = 0)).sum = 0 := by simp [sum_eq_zero_iff]
-    rwa [←filter_add_not (· = 0) l, sum_add, lz, zero_add] at hl
+    rwa [← filter_add_not (· = 0) l, sum_add, lz, zero_add] at hl
 #align nat.partition.of_sums Nat.Partition.ofSums
 
 /-- A `Multiset ℕ` induces a partition on its sum. -/
chore(Combinatorics): golf and cleanup partitions (#8517)

Co-authored-by: Bhavik Mehta <bm489@cam.ac.uk>

Diff
@@ -31,6 +31,10 @@ related results.
 The representation of a partition as a multiset is very handy as multisets are very flexible and
 already have a well-developed API.
 
+## TODO
+
+Link this to Young diagrams.
+
 ## Tags
 
 Partition
@@ -40,11 +44,6 @@ Partition
 <https://en.wikipedia.org/wiki/Partition_(number_theory)>
 -/
 
-set_option autoImplicit true
-
-
-variable {α : Type*}
-
 open Multiset
 
 open BigOperators
@@ -66,22 +65,22 @@ structure Partition (n : ℕ) where
 
 namespace Partition
 
-instance decidableEqParition : DecidableEq (Partition n)
-  | p, q => by simp [Partition.ext_iff]; exact decidableEq p.parts q.parts
+-- TODO: This should be automatically derived, see lean4#2914
+instance decidableEqPartition {n : ℕ} : DecidableEq (Partition n) :=
+  fun _ _ => decidable_of_iff' _ <| Partition.ext_iff _ _
 
 /-- A composition induces a partition (just convert the list to a multiset). -/
-def ofComposition (n : ℕ) (c : Composition n) : Partition n
-    where
+@[simps]
+def ofComposition (n : ℕ) (c : Composition n) : Partition n where
   parts := c.blocks
-  parts_pos {i} hi := c.blocks_pos hi
+  parts_pos hi := c.blocks_pos hi
   parts_sum := by rw [Multiset.coe_sum, c.blocks_sum]
 #align nat.partition.of_composition Nat.Partition.ofComposition
 
 theorem ofComposition_surj {n : ℕ} : Function.Surjective (ofComposition n) := by
   rintro ⟨b, hb₁, hb₂⟩
   rcases Quotient.exists_rep b with ⟨b, rfl⟩
-  refine' ⟨⟨b, fun {i} hi => hb₁ hi, _⟩, Partition.ext _ _ rfl⟩
-  simpa using hb₂
+  exact ⟨⟨b, hb₁, by simpa using hb₂⟩, Partition.ext _ _ rfl⟩
 #align nat.partition.of_composition_surj Nat.Partition.ofComposition_surj
 
 -- The argument `n` is kept explicit here since it is useful in tactic mode proofs to generate the
@@ -89,31 +88,43 @@ theorem ofComposition_surj {n : ℕ} : Function.Surjective (ofComposition n) :=
 /-- Given a multiset which sums to `n`, construct a partition of `n` with the same multiset, but
 without the zeros.
 -/
-def ofSums (n : ℕ) (l : Multiset ℕ) (hl : l.sum = n) : Partition n
-    where
+@[simps]
+def ofSums (n : ℕ) (l : Multiset ℕ) (hl : l.sum = n) : Partition n where
   parts := l.filter (· ≠ 0)
-  parts_pos {i} hi := Nat.pos_of_ne_zero <| by apply of_mem_filter hi
+  parts_pos hi := (of_mem_filter hi).bot_lt
   parts_sum := by
-    have lt : l.filter (· = 0) + l.filter (· ≠ 0) = l := filter_add_not _ l
-    apply_fun Multiset.sum at lt
-    have lz : (l.filter (· = 0)).sum = 0 := by
-      rw [Multiset.sum_eq_zero_iff]
-      simp
-    rwa [sum_add (filter (fun x => x = 0) l) (filter (fun x => ¬x = 0) l),lz,hl, zero_add] at lt
+    have lz : (l.filter (· = 0)).sum = 0 := by simp [sum_eq_zero_iff]
+    rwa [←filter_add_not (· = 0) l, sum_add, lz, zero_add] at hl
 #align nat.partition.of_sums Nat.Partition.ofSums
 
 /-- A `Multiset ℕ` induces a partition on its sum. -/
-def ofMultiset (l : Multiset ℕ) : Partition l.sum :=
-  ofSums _ l rfl
+@[simps!]
+def ofMultiset (l : Multiset ℕ) : Partition l.sum := ofSums _ l rfl
 #align nat.partition.of_multiset Nat.Partition.ofMultiset
 
 /-- The partition of exactly one part. -/
-def indiscretePartition (n : ℕ) : Partition n :=
-  ofSums n {n} rfl
-#align nat.partition.indiscrete_partition Nat.Partition.indiscretePartition
+def indiscrete (n : ℕ) : Partition n := ofSums n {n} rfl
+#align nat.partition.indiscrete_partition Nat.Partition.indiscrete
+
+instance {n : ℕ} : Inhabited (Partition n) := ⟨indiscrete n⟩
+
+@[simp] lemma indiscretePartition_parts {n : ℕ} (hn : n ≠ 0) : (indiscrete n).parts = {n} := by
+  simp [indiscrete, filter_eq_self, hn]
+
+@[simp] lemma partition_zero_parts (p : Partition 0) : p.parts = 0 :=
+  eq_zero_of_forall_not_mem <| fun _ h => (p.parts_pos h).ne' <| sum_eq_zero_iff.1 p.parts_sum _ h
+
+instance UniquePartitionZero : Unique (Partition 0) where
+  uniq _ := Partition.ext _ _ <| by simp
+
+@[simp] lemma partition_one_parts (p : Partition 1) : p.parts = {1} := by
+  have h : p.parts = replicate (card p.parts) 1 := eq_replicate_card.2 fun x hx =>
+    ((le_sum_of_mem hx).trans_eq p.parts_sum).antisymm (p.parts_pos hx)
+  have h' : card p.parts = 1 := by simpa using (congrArg sum h.symm).trans p.parts_sum
+  rw [h, h', replicate_one]
 
-instance {n : ℕ} : Inhabited (Partition n) :=
-  ⟨indiscretePartition n⟩
+instance UniquePartitionOne : Unique (Partition 1) where
+  uniq _ := Partition.ext _ _ <| by simp
 
 /-- The number of times a positive integer `i` appears in the partition `ofSums n l hl` is the same
 as the number of times it appears in the multiset `l`.
style: add missing spaces around colons (#8293)

This is not exhaustive

Diff
@@ -66,7 +66,7 @@ structure Partition (n : ℕ) where
 
 namespace Partition
 
-instance decidableEqParition: DecidableEq (Partition n)
+instance decidableEqParition : DecidableEq (Partition n)
   | p, q => by simp [Partition.ext_iff]; exact decidableEq p.parts q.parts
 
 /-- A composition induces a partition (just convert the list to a multiset). -/
fix: disable autoImplicit globally (#6528)

Autoimplicits are highly controversial and also defeat the performance-improving work in #6474.

The intent of this PR is to make autoImplicit opt-in on a per-file basis, by disabling it in the lakefile and enabling it again with set_option autoImplicit true in the few files that rely on it.

That also keeps this PR small, as opposed to attempting to "fix" files to not need it any more.

I claim that many of the uses of autoImplicit in these files are accidental; situations such as:

  • Assuming variables are in scope, but pasting the lemma in the wrong section
  • Pasting in a lemma from a scratch file without checking to see if the variable names are consistent with the rest of the file
  • Making a copy-paste error between lemmas and forgetting to add an explicit arguments.

Having set_option autoImplicit false as the default prevents these types of mistake being made in the 90% of files where autoImplicits are not used at all, and causes them to be caught by CI during review.

I think there were various points during the port where we encouraged porters to delete the universes u v lines; I think having autoparams for universe variables only would cover a lot of the cases we actually use them, while avoiding any real shortcomings.

A Zulip poll (after combining overlapping votes accordingly) was in favor of this change with 5:5:18 as the no:dontcare:yes vote ratio.

While this PR was being reviewed, a handful of files gained some more likely-accidental autoImplicits. In these places, set_option autoImplicit true has been placed locally within a section, rather than at the top of the file.

Diff
@@ -40,6 +40,8 @@ Partition
 <https://en.wikipedia.org/wiki/Partition_(number_theory)>
 -/
 
+set_option autoImplicit true
+
 
 variable {α : Type*}
 
chore: banish Type _ and Sort _ (#6499)

We remove all possible occurences of Type _ and Sort _ in favor of Type* and Sort*.

This has nice performance benefits.

Diff
@@ -41,7 +41,7 @@ Partition
 -/
 
 
-variable {α : Type _}
+variable {α : Type*}
 
 open Multiset
 
chore: script to replace headers with #align_import statements (#5979)

Open in Gitpod

Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -2,16 +2,13 @@
 Copyright (c) 2020 Bhavik Mehta. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Bhavik Mehta
-
-! This file was ported from Lean 3 source module combinatorics.partition
-! leanprover-community/mathlib commit dc6c365e751e34d100e80fe6e314c3c3e0fd2988
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathlib.Combinatorics.Composition
 import Mathlib.Data.Nat.Parity
 import Mathlib.Tactic.ApplyFun
 
+#align_import combinatorics.partition from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988"
+
 /-!
 # Partitions
 
chore: clean up spacing around at and goals (#5387)

Changes are of the form

  • some_tactic at h⊢ -> some_tactic at h ⊢
  • some_tactic at h -> some_tactic at h
Diff
@@ -96,7 +96,7 @@ def ofSums (n : ℕ) (l : Multiset ℕ) (hl : l.sum = n) : Partition n
   parts_pos {i} hi := Nat.pos_of_ne_zero <| by apply of_mem_filter hi
   parts_sum := by
     have lt : l.filter (· = 0) + l.filter (· ≠ 0) = l := filter_add_not _ l
-    apply_fun Multiset.sum  at lt
+    apply_fun Multiset.sum at lt
     have lz : (l.filter (· = 0)).sum = 0 := by
       rw [Multiset.sum_eq_zero_iff]
       simp
chore: bye-bye, solo bys! (#3825)

This PR puts, with one exception, every single remaining by that lies all by itself on its own line to the previous line, thus matching the current behaviour of start-port.sh. The exception is when the by begins the second or later argument to a tuple or anonymous constructor; see https://github.com/leanprover-community/mathlib4/pull/3825#discussion_r1186702599.

Essentially this is s/\n *by$/ by/g, but with manual editing to satisfy the linter's max-100-char-line requirement. The Python style linter is also modified to catch these "isolated bys".

Diff
@@ -97,8 +97,7 @@ def ofSums (n : ℕ) (l : Multiset ℕ) (hl : l.sum = n) : Partition n
   parts_sum := by
     have lt : l.filter (· = 0) + l.filter (· ≠ 0) = l := filter_add_not _ l
     apply_fun Multiset.sum  at lt
-    have lz : (l.filter (· = 0)).sum = 0 :=
-      by
+    have lz : (l.filter (· = 0)).sum = 0 := by
       rw [Multiset.sum_eq_zero_iff]
       simp
     rwa [sum_add (filter (fun x => x = 0) l) (filter (fun x => ¬x = 0) l),lz,hl, zero_add] at lt
feat Port/Combinatorics.Partition (#2264)

port of combinatorics.partition

Dependencies 7 + 258

259 files ported (97.4%)
108830 lines ported (97.3%)
Show graph

The unported dependencies are