The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V30. Combinatorics

Mathlib.Combinatorics.Enumerative.Composition

167 declarations. Mathlib docs · Source

Compositions

A composition of a natural number n is a decomposition n = i₀ + ... + i_{k-1} of n into a sum of positive integers. Combinatorially, it corresponds to a decomposition of {0, ..., n-1} into non-empty blocks of consecutive integers, where the iⱼ are the lengths of the blocks. This notion is closely related to that of a partition of n, but in a composition of n the order of the iⱼs matters.

We implement two different structures covering these two viewpoints on compositions. The first one, made of a list of positive integers summing to n, is the main one and is called Composition n. The second one is useful for combinatorial arguments (for instance to show that the number of compositions of n is 2^(n-1)). It is given by a subset of {0, ..., n} containing 0 and n, where the elements of the subset (other than n) correspond to the leftmost points of each block. The main API is built on Composition n, and we provide an equivalence between the two types.

Main functions

  • c : Composition n is a structure, made of a list of integers which are all positive and add up to n.
  • composition_card states that the cardinality of Composition n is exactly 2^(n-1), which is proved by constructing an equiv with CompositionAsSet n (see below), which is itself in bijection with the subsets of Fin (n-1) (this holds even for n = 0, where - is nat subtraction).

Let c : Composition n be a composition of n. Then

  • c.blocks is the list of blocks in c.

  • c.length is the number of blocks in the composition.

  • c.blocksFun : Fin c.length → ℕ is the realization of c.blocks as a function on Fin c.length. This is the main object when using compositions to understand the composition of analytic functions.

  • c.sizeUpTo : ℕ → ℕ is the sum of the size of the blocks up to i.;

  • c.embedding i : Fin (c.blocksFun i) → Fin n is the increasing embedding of the i-th block in Fin n;

  • c.index j, for j : Fin n, is the index of the block containing j.

  • Composition.ones n is the composition of n made of ones, i.e., [1, ..., 1].

  • Composition.single n (hn : 0 < n) is the composition of n made of a single block of size n.

Compositions can also be used to split lists. Let l be a list of length n and c a composition of n.

  • l.splitWrtComposition c is a list of lists, made of the slices of l corresponding to the blocks of c.
  • join_splitWrtComposition states that splitting a list and then joining it gives back the original list.
  • splitWrtComposition_join states that joining a list of lists, and then splitting it back according to the right composition, gives back the original list of lists.

We turn to the second viewpoint on compositions, that we realize as a finset of Fin (n+1). c : CompositionAsSet n is a structure made of a finset of Fin (n+1) called c.boundaries and proofs that it contains 0 and n. (Taking a finset of Fin n containing 0 would not make sense in the edge case n = 0, while the previous description works in all cases). The elements of this set (other than n) correspond to leftmost points of blocks. Thus, there is an equiv between Composition n and CompositionAsSet n. We only construct basic API on CompositionAsSet (notably c.length and c.blocks) to be able to construct this equiv, called compositionEquiv n. Since there is a straightforward equiv between CompositionAsSet n and finsets of {1, ..., n-1} (obtained by removing 0 and n from a CompositionAsSet and called compositionAsSetEquiv n), we deduce that CompositionAsSet n and Composition n are both fintypes of cardinality 2^(n - 1) (see compositionAsSet_card and composition_card).

Implementation notes

The main motivation for this structure and its API is in the construction of the composition of formal multilinear series, and the proof that the composition of analytic functions is analytic.

The representation of a composition as a list is very handy as lists are very flexible and already have a well-developed API.

Tags

Composition, partition

References

https://en.wikipedia.org/wiki/Composition_(combinatorics)

Compositions

A composition of an integer n is a decomposition n = i₀ + ... + i_{k-1} of n into a sum of positive integers.

The composition Composition.ones

The composition Composition.single

Splitting a list

Given a list of length n and a composition c of n, one can split l into c.length sublists of respective lengths c.blocksFun 0, ..., c.blocksFun (c.length-1). This is inverse to the join operation.

Compositions as sets

Combinatorial viewpoints on compositions, seen as finite subsets of Fin (n+1) containing 0 and n, where the points of the set (other than n) correspond to the leftmost points of each block.

Equivalence between compositions and compositions as sets

In this section, we explain how to go back and forth between a Composition and a CompositionAsSet, by showing that their blocks and length and boundaries correspond to each other, and construct an equivalence between them called compositionEquiv.

theorem Composition.mk.congr_simp E1 #

∀ {n : ℕ} (blocks blocks_1 : List ℕ) (e_blocks : blocks = blocks_1) (blocks_pos : ∀ {i : ℕ}, i ∈ blocks → 0 < i)
  (blocks_sum : blocks.sum = n),
  { blocks := blocks, blocks_pos := blocks_pos, blocks_sum := blocks_sum } =
    { blocks := blocks_1, blocks_pos := ⋯, blocks_sum := ⋯ }

theorem Composition.single.congr_simp E1 #

∀ (n : ℕ) (h : 0 < n), Composition.single n h = Composition.single n h

theorem CompositionAsSet.mk.inj E1 #

∀ {n : ℕ} {boundaries : Finset (Fin n.succ)} {zero_mem : 0 ∈ boundaries} {getLast_mem : Fin.last n ∈ boundaries}
  {boundaries_1 : Finset (Fin n.succ)} {zero_mem_1 : 0 ∈ boundaries_1} {getLast_mem_1 : Fin.last n ∈ boundaries_1},
  { boundaries := boundaries, zero_mem := zero_mem, getLast_mem := getLast_mem } =
      { boundaries := boundaries_1, zero_mem := zero_mem_1, getLast_mem := getLast_mem_1 } →
    boundaries = boundaries_1

theorem CompositionAsSet.mk.congr_simp E1 #

∀ {n : ℕ} (boundaries boundaries_1 : Finset (Fin n.succ)) (e_boundaries : boundaries = boundaries_1)
  (zero_mem : 0 ∈ boundaries) (getLast_mem : Fin.last n ∈ boundaries),
  { boundaries := boundaries, zero_mem := zero_mem, getLast_mem := getLast_mem } =
    { boundaries := boundaries_1, zero_mem := ⋯, getLast_mem := ⋯ }

theorem List.splitWrtCompositionAux.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : List α × List α → Sort u_2) (x : List α × List α) (h_1 : (l₁ l₂ : List α) → motive (l₁, l₂))
  (l₁ l₂ : List α),
  x = (l₁, l₂) →
    (match x with
      | (l₁, l₂) => h_1 l₁ l₂) ≍
      h_1 l₁ l₂

theorem CompositionAsSet.mk.injEq E0 #

∀ {n : ℕ} (boundaries : Finset (Fin n.succ)) (zero_mem : 0 ∈ boundaries) (getLast_mem : Fin.last n ∈ boundaries)
  (boundaries_1 : Finset (Fin n.succ)) (zero_mem_1 : 0 ∈ boundaries_1) (getLast_mem_1 : Fin.last n ∈ boundaries_1),
  ({ boundaries := boundaries, zero_mem := zero_mem, getLast_mem := getLast_mem } =
      { boundaries := boundaries_1, zero_mem := zero_mem_1, getLast_mem := getLast_mem_1 }) =
    (boundaries = boundaries_1)

def Composition.ctorIdx E1 #

{n : ℕ} → Composition n → ℕ

theorem List.splitWrtCompositionAux.match_3.congr_eq_2 E1 #

∀ {α : Type u_1} (motive : List α → List ℕ → Sort u_2) (x : List α) (x_1 : List ℕ) (h_1 : (x : List α) → motive x [])
  (h_2 : (l : List α) → (n : ℕ) → (ns : List ℕ) → motive l (n :: ns)) (l : List α) (n : ℕ) (ns : List ℕ),
  x = l →
    x_1 = n :: ns →
      (match x, x_1 with
        | x, [] => h_1 x
        | l, n :: ns => h_2 l n ns) ≍
        h_2 l n ns

theorem List.splitWrtCompositionAux.match_3.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : List α → List ℕ → Sort u_2) (x : List α) (x_1 : List ℕ) (h_1 : (x : List α) → motive x [])
  (h_2 : (l : List α) → (n : ℕ) → (ns : List ℕ) → motive l (n :: ns)) (x_2 : List α),
  x = x_2 →
    x_1 = [] →
      (match x, x_1 with
        | x, [] => h_1 x
        | l, n :: ns => h_2 l n ns) ≍
        h_1 x_2

theorem Composition.mk.inj E1 #

∀ {n : ℕ} {blocks : List ℕ} {blocks_pos : ∀ {i : ℕ}, i ∈ blocks → 0 < i} {blocks_sum : blocks.sum = n}
  {blocks_1 : List ℕ} {blocks_pos_1 : ∀ {i : ℕ}, i ∈ blocks_1 → 0 < i} {blocks_sum_1 : blocks_1.sum = n},
  { blocks := blocks, blocks_pos := blocks_pos, blocks_sum := blocks_sum } =
      { blocks := blocks_1, blocks_pos := blocks_pos_1, blocks_sum := blocks_sum_1 } →
    blocks = blocks_1

def CompositionAsSet.ctorIdx E1 #

{n : ℕ} → CompositionAsSet n → ℕ

theorem Composition.cast.congr_simp E1 #

∀ {n m : ℕ} (c c_1 : Composition m), c = c_1 → ∀ (hmn : m = n), c.cast hmn = c_1.cast hmn

theorem Composition.mk.injEq E0 #

∀ {n : ℕ} (blocks : List ℕ) (blocks_pos : ∀ {i : ℕ}, i ∈ blocks → 0 < i) (blocks_sum : blocks.sum = n)
  (blocks_1 : List ℕ) (blocks_pos_1 : ∀ {i : ℕ}, i ∈ blocks_1 → 0 < i) (blocks_sum_1 : blocks_1.sum = n),
  ({ blocks := blocks, blocks_pos := blocks_pos, blocks_sum := blocks_sum } =
      { blocks := blocks_1, blocks_pos := blocks_pos_1, blocks_sum := blocks_sum_1 }) =
    (blocks = blocks_1)

structure Composition E1 #

ℕ → Type

A composition of n is a list of positive integers summing to n.

theorem Composition.ext E1 #

∀ {n : ℕ} {x y : Composition n}, x.blocks = y.blocks → x = y

theorem Composition.ext_iff E0 #

∀ {n : ℕ} {x y : Composition n}, x = y ↔ x.blocks = y.blocks

ctor Composition.mk E0 #

{n : ℕ} → (blocks : List ℕ) → (∀ {i : ℕ}, i ∈ blocks → 0 < i) → blocks.sum = n → Composition n

abbrev Composition.blocks E1 #

{n : ℕ} → Composition n → List ℕ

List of positive integers summing to n

theorem Composition.blocks_pos E1 #

∀ {n : ℕ} (self : Composition n) {i : ℕ}, i ∈ self.blocks → 0 < i

Proof of positivity for blocks

theorem Composition.blocks_sum E0 #

∀ {n : ℕ} (self : Composition n), self.blocks.sum = n

Proof that blocks sums to n

def instDecidableEqComposition.decEq E1 #

{n : ℕ} → (x x_1 : Composition n) → Decidable (x = x_1)

instance instDecidableEqComposition E0 #

{n : ℕ} → DecidableEq (Composition n)

structure CompositionAsSet E1 #

ℕ → Type

Combinatorial viewpoint on a composition of n, by seeing it as non-empty blocks of consecutive integers in {0, ..., n-1}. We register every block by its left end-point, yielding a finset containing 0. As this does not make sense for n = 0, we add n to this finset, and get a finset of {0, ..., n} containing 0 and n. This is the data in the structure CompositionAsSet n.

theorem CompositionAsSet.ext_iff E0 #

∀ {n : ℕ} {x y : CompositionAsSet n}, x = y ↔ x.boundaries = y.boundaries

theorem CompositionAsSet.ext E1 #

∀ {n : ℕ} {x y : CompositionAsSet n}, x.boundaries = y.boundaries → x = y

ctor CompositionAsSet.mk E0 #

{n : ℕ} → (boundaries : Finset (Fin n.succ)) → 0 ∈ boundaries → Fin.last n ∈ boundaries → CompositionAsSet n

abbrev CompositionAsSet.boundaries E1 #

{n : ℕ} → CompositionAsSet n → Finset (Fin n.succ)

Combinatorial viewpoint on a composition of n as consecutive integers {0, ..., n-1}

theorem CompositionAsSet.zero_mem E0 #

∀ {n : ℕ} (self : CompositionAsSet n), 0 ∈ self.boundaries

Proof that 0 is a member of boundaries

theorem CompositionAsSet.getLast_mem E0 #

∀ {n : ℕ} (self : CompositionAsSet n), Fin.last n ∈ self.boundaries

Last element of the composition

def instDecidableEqCompositionAsSet.decEq E1 #

{n : ℕ} → (x x_1 : CompositionAsSet n) → Decidable (x = x_1)

instance instDecidableEqCompositionAsSet E0 #

{n : ℕ} → DecidableEq (CompositionAsSet n)

instance instInhabitedCompositionAsSet E0 #

{n : ℕ} → Inhabited (CompositionAsSet n)

instance Composition.instToString E0 #

(n : ℕ) → ToString (Composition n)

abbrev Composition.length E1 #

{n : ℕ} → Composition n → ℕ

The length of a composition, i.e., the number of blocks in the composition.

theorem Composition.blocks_length E1 #

∀ {n : ℕ} (c : Composition n), c.blocks.length = c.length

def Composition.blocksFun E1 #

{n : ℕ} → (c : Composition n) → Fin c.length → ℕ

The blocks of a composition, seen as a function on Fin c.length. When composing analytic functions using compositions, this is the main player.

theorem Composition.ofFn_blocksFun E0 #

∀ {n : ℕ} (c : Composition n), List.ofFn c.blocksFun = c.blocks

theorem Composition.sum_blocksFun E0 #

∀ {n : ℕ} (c : Composition n), ∑ i, c.blocksFun i = n

theorem Composition.blocksFun_mem_blocks E0 #

∀ {n : ℕ} (c : Composition n) (i : Fin c.length), c.blocksFun i ∈ c.blocks

theorem Composition.one_le_blocks E1 #

∀ {n : ℕ} (c : Composition n) {i : ℕ}, i ∈ c.blocks → 1 ≤ i

theorem Composition.blocks_le E1 #

∀ {n : ℕ} (c : Composition n) {i : ℕ}, i ∈ c.blocks → i ≤ n

theorem Composition.one_le_blocks' E0 #

∀ {n : ℕ} (c : Composition n) {i : ℕ} (h : i < c.length), 1 ≤ c.blocks[i]

theorem Composition.blocks_pos' E0 #

∀ {n : ℕ} (c : Composition n) (i : ℕ) (h : i < c.length), 0 < c.blocks[i]

theorem Composition.one_le_blocksFun E0 #

∀ {n : ℕ} (c : Composition n) (i : Fin c.length), 1 ≤ c.blocksFun i

theorem Composition.blocksFun_le E0 #

∀ {n : ℕ} (c : Composition n) (i : Fin c.length), c.blocksFun i ≤ n

theorem Composition.length_le E0 #

∀ {n : ℕ} (c : Composition n), c.length ≤ n

theorem Composition.blocks_eq_nil E0 #

∀ {n : ℕ} (c : Composition n), c.blocks = [] ↔ n = 0

theorem Composition.length_eq_zero E1 #

∀ {n : ℕ} (c : Composition n), c.length = 0 ↔ n = 0

theorem Composition.length_pos_iff E0 #

∀ {n : ℕ} (c : Composition n), 0 < c.length ↔ 0 < n

theorem Composition.length_pos_of_pos E1 #

∀ {n : ℕ} (c : Composition n), 0 < n → 0 < c.length

Alias of the reverse direction of Composition.length_pos_iff.

def Composition.sizeUpTo E1 #

{n : ℕ} → Composition n → ℕ → ℕ

The sum of the sizes of the blocks in a composition up to i.

theorem Composition.sizeUpTo_zero E0 #

∀ {n : ℕ} (c : Composition n), c.sizeUpTo 0 = 0

theorem Composition.sizeUpTo_ofLength_le E1 #

∀ {n : ℕ} (c : Composition n) (i : ℕ), c.length ≤ i → c.sizeUpTo i = n

theorem Composition.sizeUpTo_length E0 #

∀ {n : ℕ} (c : Composition n), c.sizeUpTo c.length = n

theorem Composition.sizeUpTo_le E1 #

∀ {n : ℕ} (c : Composition n) (i : ℕ), c.sizeUpTo i ≤ n

theorem Composition.sizeUpTo_succ E1 #

∀ {n : ℕ} (c : Composition n) {i : ℕ} (h : i < c.length), c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks[i]

theorem Composition.sizeUpTo_succ' E1 #

∀ {n : ℕ} (c : Composition n) (i : Fin c.length), c.sizeUpTo (↑i + 1) = c.sizeUpTo ↑i + c.blocksFun i

theorem Composition.sizeUpTo_strict_mono E1 #

∀ {n : ℕ} (c : Composition n) {i : ℕ}, i < c.length → c.sizeUpTo i < c.sizeUpTo (i + 1)

theorem Composition.monotone_sizeUpTo E1 #

∀ {n : ℕ} (c : Composition n), Monotone c.sizeUpTo

def Composition.boundary E1 #

{n : ℕ} → (c : Composition n) → Fin (c.length + 1) ↪o Fin (n + 1)

The i-th boundary of a composition, i.e., the leftmost point of the i-th block. We include a virtual point at the right of the last block, to make for a nice equiv with CompositionAsSet n.

theorem Composition.boundary_zero E0 #

∀ {n : ℕ} (c : Composition n), c.boundary 0 = 0

theorem Composition.boundary_last E0 #

∀ {n : ℕ} (c : Composition n), c.boundary (Fin.last c.length) = Fin.last n

def Composition.boundaries E1 #

{n : ℕ} → Composition n → Finset (Fin (n + 1))

The boundaries of a composition, i.e., the leftmost point of all the blocks. We include a virtual point at the right of the last block, to make for a nice equiv with CompositionAsSet n.

theorem Composition.card_boundaries_eq_succ_length E1 #

∀ {n : ℕ} (c : Composition n), c.boundaries.card = c.length + 1

def Composition.toCompositionAsSet E1 #

{n : ℕ} → Composition n → CompositionAsSet n

To c : Composition n, one can associate a CompositionAsSet n by registering the leftmost point of each block, and adding a virtual point at the right of the last block.

theorem Composition.orderEmbOfFin_boundaries E1 #

∀ {n : ℕ} (c : Composition n), c.boundaries.orderEmbOfFin ⋯ = c.boundary

The canonical increasing bijection between Fin (c.length + 1) and c.boundaries is exactly c.boundary.

def Composition.embedding E1 #

{n : ℕ} → (c : Composition n) → (i : Fin c.length) → Fin (c.blocksFun i) ↪o Fin n

Embedding the i-th block of a composition (identified with Fin (c.blocksFun i)) into Fin n at the relevant position.

theorem Composition.coe_embedding E0 #

∀ {n : ℕ} (c : Composition n) (i : Fin c.length) (j : Fin (c.blocksFun i)), ↑((c.embedding i) j) = c.sizeUpTo ↑i + ↑j

theorem Composition.index_exists E1 #

∀ {n : ℕ} (c : Composition n) {j : ℕ}, j < n → ∃ i, j < c.sizeUpTo (i + 1) ∧ i < c.length

index_exists asserts there is some i with j < c.sizeUpTo (i+1). In the next definition index we use Nat.find to produce the minimal such index.

def Composition.index E1 #

{n : ℕ} → (c : Composition n) → Fin n → Fin c.length

c.index j is the index of the block in the composition c containing j.

theorem Composition.lt_sizeUpTo_index_succ E1 #

∀ {n : ℕ} (c : Composition n) (j : Fin n), ↑j < c.sizeUpTo ↑(c.index j).succ

theorem Composition.sizeUpTo_index_le E1 #

∀ {n : ℕ} (c : Composition n) (j : Fin n), c.sizeUpTo ↑(c.index j) ≤ ↑j

def Composition.invEmbedding E1 #

{n : ℕ} → (c : Composition n) → (j : Fin n) → Fin (c.blocksFun (c.index j))

Mapping an element j of Fin n to the element in the block containing it, identified with Fin (c.blocksFun (c.index j)) through the canonical increasing bijection.

theorem Composition.coe_invEmbedding E0 #

∀ {n : ℕ} (c : Composition n) (j : Fin n), ↑(c.invEmbedding j) = ↑j - c.sizeUpTo ↑(c.index j)

theorem Composition.embedding_comp_inv E0 #

∀ {n : ℕ} (c : Composition n) (j : Fin n), (c.embedding (c.index j)) (c.invEmbedding j) = j

theorem Composition.mem_range_embedding_iff E0 #

∀ {n : ℕ} (c : Composition n) {j : Fin n} {i : Fin c.length},
  j ∈ Set.range ⇑(c.embedding i) ↔ c.sizeUpTo ↑i ≤ ↑j ∧ ↑j < c.sizeUpTo (↑i).succ

theorem Composition.disjoint_range E1 #

∀ {n : ℕ} (c : Composition n) {i₁ i₂ : Fin c.length},
  i₁ ≠ i₂ → Disjoint (Set.range ⇑(c.embedding i₁)) (Set.range ⇑(c.embedding i₂))

The embeddings of different blocks of a composition are disjoint.

theorem Composition.mem_range_embedding E0 #

∀ {n : ℕ} (c : Composition n) (j : Fin n), j ∈ Set.range ⇑(c.embedding (c.index j))

theorem Composition.mem_range_embedding_iff' E0 #

∀ {n : ℕ} (c : Composition n) {j : Fin n} {i : Fin c.length}, j ∈ Set.range ⇑(c.embedding i) ↔ i = c.index j

theorem Composition.index_embedding E0 #

∀ {n : ℕ} (c : Composition n) (i : Fin c.length) (j : Fin (c.blocksFun i)), c.index ((c.embedding i) j) = i

theorem Composition.invEmbedding_comp E1 #

∀ {n : ℕ} (c : Composition n) (i : Fin c.length) (j : Fin (c.blocksFun i)), ↑(c.invEmbedding ((c.embedding i) j)) = ↑j

def Composition.blocksFinEquiv E1 #

{n : ℕ} → (c : Composition n) → (i : Fin c.length) × Fin (c.blocksFun i) ≃ Fin n

Equivalence between the disjoint union of the blocks (each of them seen as Fin (c.blocksFun i)) with Fin n.

theorem Composition.blocksFun_congr E1 #

∀ {n₁ n₂ : ℕ} (c₁ : Composition n₁) (c₂ : Composition n₂) (i₁ : Fin c₁.length) (i₂ : Fin c₂.length),
  n₁ = n₂ → c₁.blocks = c₂.blocks → ↑i₁ = ↑i₂ → c₁.blocksFun i₁ = c₂.blocksFun i₂

theorem Composition.sigma_eq_iff_blocks_eq E0 #

∀ {c c' : (n : ℕ) × Composition n}, c = c' ↔ c.snd.blocks = c'.snd.blocks

Two compositions (possibly of different integers) coincide if and only if they have the same sequence of blocks.

theorem Composition.prod_prod_apply_embedding E1 #

∀ {n : ℕ} {A : Type u_1} [inst : CommMonoid A] (a : Fin n → A) (x : Composition n),
  ∏ i, ∏ j, a ((x.embedding i) j) = ∏ i, a i

theorem Composition.sum_sum_apply_embedding E1 #

∀ {n : ℕ} {A : Type u_1} [inst : AddCommMonoid A] (a : Fin n → A) (x : Composition n),
  ∑ i, ∑ j, a ((x.embedding i) j) = ∑ i, a i

def Composition.ones E1 #

(n : ℕ) → Composition n

The composition made of blocks all of size 1.

instance Composition.instInhabited E0 #

{n : ℕ} → Inhabited (Composition n)

theorem Composition.ones_length E0 #

∀ (n : ℕ), (Composition.ones n).length = n

theorem Composition.ones_blocks E0 #

∀ (n : ℕ), (Composition.ones n).blocks = List.replicate n 1

theorem Composition.ones_blocksFun E0 #

∀ (n : ℕ) (i : Fin (Composition.ones n).length), (Composition.ones n).blocksFun i = 1

theorem Composition.ones_sizeUpTo E0 #

∀ (n i : ℕ), (Composition.ones n).sizeUpTo i = min i n

theorem Composition.ones_embedding E0 #

∀ {n : ℕ} (i : Fin (Composition.ones n).length) (h : 0 < (Composition.ones n).blocksFun i),
  ((Composition.ones n).embedding i) ⟨0, h⟩ = ⟨↑i, ⋯⟩

theorem Composition.ne_ones_iff E0 #

∀ {n : ℕ} {c : Composition n}, c ≠ Composition.ones n ↔ ∃ i ∈ c.blocks, 1 < i

def Composition.single E1 #

(n : ℕ) → 0 < n → Composition n

The composition made of a single block of size n.

theorem Composition.single_length E0 #

∀ {n : ℕ} (h : 0 < n), (Composition.single n h).length = 1

theorem Composition.single_blocks E0 #

∀ {n : ℕ} (h : 0 < n), (Composition.single n h).blocks = [n]

theorem Composition.single_blocksFun E0 #

∀ {n : ℕ} (h : 0 < n) (i : Fin (Composition.single n h).length), (Composition.single n h).blocksFun i = n

theorem Composition.single_embedding E0 #

∀ {n : ℕ} (h : 0 < n) (i : Fin n), ((Composition.single n h).embedding 0) i = i

theorem Composition.ne_single_iff E0 #

∀ {n : ℕ} (hn : 0 < n) {c : Composition n}, c ≠ Composition.single n hn ↔ ∀ (i : Fin c.length), c.blocksFun i < n

def Composition.cast E1 #

{n m : ℕ} → Composition m → m = n → Composition n

Change n in (c : Composition n) to a propositionally equal value.

theorem Composition.cast_blocks E0 #

∀ {n m : ℕ} (c : Composition m) (hmn : m = n), (c.cast hmn).blocks = c.blocks

theorem Composition.cast_rfl E0 #

∀ {n : ℕ} (c : Composition n), c.cast ⋯ = c

theorem Composition.cast_heq E1 #

∀ {n m : ℕ} (c : Composition m) (hmn : m = n), c.cast hmn ≍ c

theorem Composition.cast_eq_cast E1 #

∀ {n m : ℕ} (c : Composition m) (hmn : m = n), c.cast hmn = cast ⋯ c

def Composition.append E1 #

{n m : ℕ} → Composition m → Composition n → Composition (m + n)

Append two compositions to get a composition of the sum of numbers.

theorem Composition.append_blocks E0 #

∀ {n m : ℕ} (c₁ : Composition m) (c₂ : Composition n), (c₁.append c₂).blocks = c₁.blocks ++ c₂.blocks

def Composition.reverse E1 #

{n : ℕ} → Composition n → Composition n

Reverse the order of blocks in a composition.

theorem Composition.reverse_blocks E0 #

∀ {n : ℕ} (c : Composition n), c.reverse.blocks = c.blocks.reverse

theorem Composition.reverse_reverse E0 #

∀ {n : ℕ} (c : Composition n), c.reverse.reverse = c

theorem Composition.reverse_involutive E1 #

∀ {n : ℕ}, Function.Involutive Composition.reverse

theorem Composition.reverse_bijective E1 #

∀ {n : ℕ}, Function.Bijective Composition.reverse

theorem Composition.reverse_injective E1 #

∀ {n : ℕ}, Function.Injective Composition.reverse

theorem Composition.reverse_surjective E1 #

∀ {n : ℕ}, Function.Surjective Composition.reverse

theorem Composition.reverse_inj E0 #

∀ {n : ℕ} {c₁ c₂ : Composition n}, c₁.reverse = c₂.reverse ↔ c₁ = c₂

theorem Composition.reverse_ones E0 #

∀ {n : ℕ}, (Composition.ones n).reverse = Composition.ones n

theorem Composition.reverse_single E0 #

∀ {n : ℕ} (hn : 0 < n), (Composition.single n hn).reverse = Composition.single n hn

theorem Composition.reverse_eq_ones E0 #

∀ {n : ℕ} {c : Composition n}, c.reverse = Composition.ones n ↔ c = Composition.ones n

theorem Composition.reverse_eq_single E0 #

∀ {n : ℕ} {hn : 0 < n} {c : Composition n}, c.reverse = Composition.single n hn ↔ c = Composition.single n hn

theorem Composition.reverse_append E1 #

∀ {n m : ℕ} (c₁ : Composition m) (c₂ : Composition n), (c₁.append c₂).reverse = (c₂.reverse.append c₁.reverse).cast ⋯

def Composition.recOnSingleAppend E1 #

{motive : (n : ℕ) → Composition n → Sort u_1} →
  {n : ℕ} →
    (c : Composition n) →
      motive 0 (Composition.ones 0) →
        ((k n : ℕ) → (c : Composition n) → motive n c → motive (k + 1 + n) ((Composition.single (k + 1) ⋯).append c)) →
          motive n c

Induction (recursion) principle on c : Composition _ that corresponds to the usual induction on the list of blocks of c.

def Composition.recOnAppendSingle E1 #

{motive : (n : ℕ) → Composition n → Sort u_1} →
  {n : ℕ} →
    (c : Composition n) →
      motive 0 (Composition.ones 0) →
        ((k n : ℕ) →
            (c : Composition n) → motive n c → motive (n + (k + 1)) (c.append (Composition.single (k + 1) ⋯))) →
          motive n c

Induction (recursion) principle on c : Composition _ that corresponds to the reverse induction on the list of blocks of c.

def List.splitWrtCompositionAux E0 #

{α : Type u_1} → List α → List ℕ → List (List α)

Auxiliary for List.splitWrtComposition.

def List.splitWrtComposition E1 #

{n : ℕ} → {α : Type u_1} → List α → Composition n → List (List α)

Given a list of length n and a composition [i₁, ..., iₖ] of n, split l into a list of k lists corresponding to the blocks of the composition, of respective lengths i₁, ..., iₖ. This makes sense mostly when n = l.length, but this is not necessary for the definition.

theorem List.splitWrtCompositionAux_cons E1 #

∀ {α : Type u_1} (l : List α) (n : ℕ) (ns : List ℕ),
  l.splitWrtCompositionAux (n :: ns) = List.take n l :: (List.drop n l).splitWrtCompositionAux ns

theorem List.length_splitWrtCompositionAux E0 #

∀ {α : Type u_1} (l : List α) (ns : List ℕ), (l.splitWrtCompositionAux ns).length = ns.length

theorem List.length_splitWrtComposition E0 #

∀ {n : ℕ} {α : Type u_1} (l : List α) (c : Composition n), (l.splitWrtComposition c).length = c.length

When one splits a list along a composition c, the number of sublists thus created is c.length.

theorem List.map_length_splitWrtCompositionAux E0 #

∀ {α : Type u_1} {ns : List ℕ} {l : List α}, ns.sum ≤ l.length → List.map List.length (l.splitWrtCompositionAux ns) = ns

theorem List.map_length_splitWrtComposition E0 #

∀ {α : Type u_1} (l : List α) (c : Composition l.length), List.map List.length (l.splitWrtComposition c) = c.blocks

When one splits a list along a composition c, the lengths of the sublists thus created are given by the block sizes in c.

theorem List.length_pos_of_mem_splitWrtComposition E1 #

∀ {α : Type u_1} {l l' : List α} {c : Composition l.length}, l' ∈ l.splitWrtComposition c → 0 < l'.length

theorem List.sum_take_map_length_splitWrtComposition E1 #

∀ {α : Type u_1} (l : List α) (c : Composition l.length) (i : ℕ),
  (List.take i (List.map List.length (l.splitWrtComposition c))).sum = c.sizeUpTo i

theorem List.getElem_splitWrtCompositionAux E0 #

∀ {α : Type u_1} (l : List α) (ns : List ℕ) {i : ℕ} (hi : i < (l.splitWrtCompositionAux ns).length),
  (l.splitWrtCompositionAux ns)[i] = List.drop (List.take i ns).sum (List.take (List.take (i + 1) ns).sum l)

theorem List.getElem_splitWrtComposition' E1 #

∀ {n : ℕ} {α : Type u_1} (l : List α) (c : Composition n) {i : ℕ} (hi : i < (l.splitWrtComposition c).length),
  (l.splitWrtComposition c)[i] = List.drop (c.sizeUpTo i) (List.take (c.sizeUpTo (i + 1)) l)

The i-th sublist in the splitting of a list l along a composition c, is the slice of l between the indices c.sizeUpTo i and c.sizeUpTo (i+1), i.e., the indices in the i-th block of the composition.

theorem List.getElem_splitWrtComposition E1 #

∀ {n : ℕ} {α : Type u_1} (l : List α) (c : Composition n) (i : ℕ) (h : i < (l.splitWrtComposition c).length),
  (l.splitWrtComposition c)[i] = List.drop (c.sizeUpTo i) (List.take (c.sizeUpTo (i + 1)) l)

theorem List.flatten_splitWrtCompositionAux E0 #

∀ {α : Type u_1} {ns : List ℕ} {l : List α}, ns.sum = l.length → (l.splitWrtCompositionAux ns).flatten = l

theorem List.flatten_splitWrtComposition E0 #

∀ {α : Type u_1} (l : List α) (c : Composition l.length), (l.splitWrtComposition c).flatten = l

If one splits a list along a composition, and then flattens the sublists, one gets back the original list.

theorem List.splitWrtComposition_flatten E0 #

∀ {α : Type u_1} (L : List (List α)) (c : Composition L.flatten.length),
  List.map List.length L = c.blocks → L.flatten.splitWrtComposition c = L

If one joins a list of lists and then splits the flattening along the right composition, one gets back the original list of lists.

def compositionAsSetEquiv E1 #

(n : ℕ) → CompositionAsSet n ≃ Finset (Fin (n - 1))

Bijection between compositions of n and subsets of {0, ..., n-2}, defined by considering the restriction of the subset to {1, ..., n-1} and shifting to the left by one.

instance compositionAsSetFintype E0 #

(n : ℕ) → Fintype (CompositionAsSet n)

theorem compositionAsSet_card E1 #

∀ (n : ℕ), Fintype.card (CompositionAsSet n) = 2 ^ (n - 1)

theorem CompositionAsSet.boundaries_nonempty E1 #

∀ {n : ℕ} (c : CompositionAsSet n), c.boundaries.Nonempty

theorem CompositionAsSet.card_boundaries_pos E1 #

∀ {n : ℕ} (c : CompositionAsSet n), 0 < c.boundaries.card

def CompositionAsSet.length E1 #

{n : ℕ} → CompositionAsSet n → ℕ

Number of blocks in a CompositionAsSet.

theorem CompositionAsSet.card_boundaries_eq_succ_length E1 #

∀ {n : ℕ} (c : CompositionAsSet n), c.boundaries.card = c.length + 1

theorem CompositionAsSet.length_lt_card_boundaries E1 #

∀ {n : ℕ} (c : CompositionAsSet n), c.length < c.boundaries.card

theorem CompositionAsSet.lt_length E1 #

∀ {n : ℕ} (c : CompositionAsSet n) (i : Fin c.length), ↑i + 1 < c.boundaries.card

theorem CompositionAsSet.lt_length' E1 #

∀ {n : ℕ} (c : CompositionAsSet n) (i : Fin c.length), ↑i < c.boundaries.card

def CompositionAsSet.boundary E1 #

{n : ℕ} → (c : CompositionAsSet n) → Fin c.boundaries.card ↪o Fin (n + 1)

Canonical increasing bijection from Fin c.boundaries.card to c.boundaries.

theorem CompositionAsSet.boundary_zero E0 #

∀ {n : ℕ} (c : CompositionAsSet n), c.boundary ⟨0, ⋯⟩ = 0

theorem CompositionAsSet.boundary_length E0 #

∀ {n : ℕ} (c : CompositionAsSet n), c.boundary ⟨c.length, ⋯⟩ = Fin.last n

def CompositionAsSet.blocksFun E1 #

{n : ℕ} → (c : CompositionAsSet n) → Fin c.length → ℕ

Size of the i-th block in a CompositionAsSet, seen as a function on Fin c.length.

theorem CompositionAsSet.blocksFun_pos E1 #

∀ {n : ℕ} (c : CompositionAsSet n) (i : Fin c.length), 0 < c.blocksFun i

def CompositionAsSet.blocks E1 #

{n : ℕ} → CompositionAsSet n → List ℕ

List of the sizes of the blocks in a CompositionAsSet.

theorem CompositionAsSet.blocks_length E0 #

∀ {n : ℕ} (c : CompositionAsSet n), c.blocks.length = c.length

theorem CompositionAsSet.blocks_partial_sum E1 #

∀ {n : ℕ} (c : CompositionAsSet n) {i : ℕ} (h : i < c.boundaries.card),
  (List.take i c.blocks).sum = ↑(c.boundary ⟨i, h⟩)

theorem CompositionAsSet.mem_boundaries_iff_exists_blocks_sum_take_eq E0 #

∀ {n : ℕ} (c : CompositionAsSet n) {j : Fin (n + 1)},
  j ∈ c.boundaries ↔ ∃ i < c.boundaries.card, (List.take i c.blocks).sum = ↑j

theorem CompositionAsSet.blocks_sum E1 #

∀ {n : ℕ} (c : CompositionAsSet n), c.blocks.sum = n

def CompositionAsSet.toComposition E1 #

{n : ℕ} → CompositionAsSet n → Composition n

Associating a Composition n to a CompositionAsSet n, by registering the sizes of the blocks as a list of positive integers.

theorem Composition.toCompositionAsSet_length E0 #

∀ {n : ℕ} (c : Composition n), c.toCompositionAsSet.length = c.length

theorem CompositionAsSet.toComposition_length E0 #

∀ {n : ℕ} (c : CompositionAsSet n), c.toComposition.length = c.length

theorem Composition.toCompositionAsSet_blocks E0 #

∀ {n : ℕ} (c : Composition n), c.toCompositionAsSet.blocks = c.blocks

theorem CompositionAsSet.toComposition_blocks E0 #

∀ {n : ℕ} (c : CompositionAsSet n), c.toComposition.blocks = c.blocks

theorem CompositionAsSet.toComposition_boundaries E0 #

∀ {n : ℕ} (c : CompositionAsSet n), c.toComposition.boundaries = c.boundaries

theorem Composition.toCompositionAsSet_boundaries E0 #

∀ {n : ℕ} (c : Composition n), c.toCompositionAsSet.boundaries = c.boundaries

def compositionEquiv E1 #

(n : ℕ) → Composition n ≃ CompositionAsSet n

Equivalence between Composition n and CompositionAsSet n.

instance compositionFintype E0 #

(n : ℕ) → Fintype (Composition n)

theorem composition_card E1 #

∀ (n : ℕ), Fintype.card (Composition n) = 2 ^ (n - 1)