Documentation

Mathlib.Combinatorics.Enumerative.Partition.Basic

Partitions #

A partition of a natural number n is a way of writing n as a sum of positive integers, where the order does not matter: two sums that differ only in the order of their summands are considered the same partition. This notion is closely related to that of a composition of n, but in a composition of n the order does matter. A summand of the partition is called a part.

Main functions #

Implementation details #

The main motivation for this structure and its API is to show Euler's partition theorem, and 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

References #

https://en.wikipedia.org/wiki/Partition_(number_theory)

structure Nat.Partition (n : โ„•) :

A partition of n is a multiset of positive integers summing to n.

  • parts : Multiset โ„•

    positive integers summing to n

  • parts_pos {i : โ„•} : i โˆˆ self.parts โ†’ 0 < i

    proof that the parts are positive

  • parts_sum : self.parts.sum = n

    proof that the parts sum to n

Instances For
    theorem Nat.Partition.ext {n : โ„•} {x y : n.Partition} (parts : x.parts = y.parts) :
    x = y
    theorem Nat.Partition.ext_iff {n : โ„•} {x y : n.Partition} :
    x = y โ†” x.parts = y.parts
    def Nat.instDecidableEqPartition.decEq {nโœ : โ„•} (xโœ xโœยน : nโœ.Partition) :
    Decidable (xโœ = xโœยน)
    Instances For
      @[implicit_reducible]
      instance Nat.instDecidableEqPartition {nโœ : โ„•} :
      DecidableEq nโœ.Partition
      theorem Nat.Partition.le_of_mem_parts {n : โ„•} {p : n.Partition} {m : โ„•} (h : m โˆˆ p.parts) :

      A composition induces a partition (just convert the list to a multiset).

      Instances For
        @[simp]
        theorem Nat.Partition.ofComposition_parts (n : โ„•) (c : Composition n) :
        (ofComposition n c).parts = โ†‘c.blocks
        theorem Nat.Partition.ofComposition_surj {n : โ„•} :
        Function.Surjective (ofComposition n)
        def Nat.Partition.ofSums (n : โ„•) (l : Multiset โ„•) (hl : l.sum = n) :

        Given a multiset which sums to n, construct a partition of n with the same multiset, but without the zeros.

        Instances For
          @[simp]
          theorem Nat.Partition.ofSums_parts (n : โ„•) (l : Multiset โ„•) (hl : l.sum = n) :
          (ofSums n l hl).parts = Multiset.filter (fun (x : โ„•) => x โ‰  0) l

          A Multiset โ„• induces a partition on its sum.

          Instances For
            @[simp]
            theorem Nat.Partition.ofMultiset_parts (l : Multiset โ„•) :
            (ofMultiset l).parts = Multiset.filter (fun (x : โ„•) => ยฌx = 0) l
            def Nat.Partition.ofSym {n : โ„•} {ฯƒ : Type u_1} (s : Sym ฯƒ n) [DecidableEq ฯƒ] :

            An element s of Sym ฯƒ n induces a partition given by its multiplicities.

            Instances For
              @[simp]
              theorem Nat.Partition.ofSym_map {n : โ„•} {ฯƒ : Type u_1} {ฯ„ : Type u_2} [DecidableEq ฯƒ] [DecidableEq ฯ„] (e : ฯƒ โ‰ƒ ฯ„) (s : Sym ฯƒ n) :
              ofSym (Sym.map (โ‡‘e) s) = ofSym s
              def Nat.Partition.ofSymShapeEquiv {n : โ„•} {ฯƒ : Type u_1} {ฯ„ : Type u_2} [DecidableEq ฯƒ] [DecidableEq ฯ„] (ฮผ : n.Partition) (e : ฯƒ โ‰ƒ ฯ„) :
              { x : Sym ฯƒ n // ofSym x = ฮผ } โ‰ƒ { x : Sym ฯ„ n // ofSym x = ฮผ }

              An equivalence between ฯƒ and ฯ„ induces an equivalence between the subtypes of Sym ฯƒ n and Sym ฯ„ n corresponding to a given partition.

              Instances For
                def Nat.Partition.toFinsuppAntidiag {n : โ„•} (p : n.Partition) :
                โ„• โ†’โ‚€ โ„•

                Convert a Partition n to a member of (Finset.Icc 1 n).finsuppAntidiag n (see Nat.Partition.toFinsuppAntidiag_mem_finsuppAntidiag for the proof). p.toFinsuppAntidiag i is defined as i times the number of occurrence of i in p.

                Instances For
                  def Nat.Partition.indiscrete (n : โ„•) :

                  The partition of exactly one part.

                  Instances For
                    @[implicit_reducible]
                    instance Nat.Partition.instInhabited {n : โ„•} :
                    Inhabited n.Partition
                    @[simp]
                    theorem Nat.Partition.indiscrete_parts {n : โ„•} (hn : n โ‰  0) :
                    (indiscrete n).parts = {n}
                    @[simp]
                    theorem Nat.Partition.ofSym_one {ฯƒ : Type u_1} [DecidableEq ฯƒ] (s : Sym ฯƒ 1) :
                    theorem Nat.Partition.count_ofSums_of_ne_zero {n : โ„•} {l : Multiset โ„•} (hl : l.sum = n) {i : โ„•} (hi : i โ‰  0) :

                    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. (For i = 0, Partition.non_zero combined with Multiset.count_eq_zero_of_notMem gives that this is 0 instead.)

                    theorem Nat.Partition.count_ofSums_zero {n : โ„•} {l : Multiset โ„•} (hl : l.sum = n) :
                    Multiset.count 0 (ofSums n l hl).parts = 0
                    @[implicit_reducible]
                    instance Nat.Partition.instFintype (n : โ„•) :

                    Show there are finitely many partitions by considering the surjection from compositions to partitions.

                    def Nat.Partition.restricted (n : โ„•) (p : โ„• โ†’ Prop) [DecidablePred p] :

                    The finset of those partitions in which every part satisfies a certain condition.

                    Instances For

                      The finset of those partitions in which every part is used less than m times.

                      Instances For
                        def Nat.Partition.odds (n : โ„•) :

                        The finset of those partitions in which every part is odd.

                        Instances For

                          The finset of those partitions in which each part is used at most once.

                          Instances For

                            The finset of those partitions in which every part is odd and used at most once.

                            Instances For