Collections of tuples of naturals with the same sum #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
This file generalizes list.nat.antidiagonal n, multiset.nat.antidiagonal n, and
finset.nat.antidiagonal n from the pair of elements x : ℕ × ℕ such that n = x.1 + x.2, to
the sequence of elements x : fin k → ℕ such that n = ∑ i, x i.
Main definitions #
Main results #
-
antidiagonal_tuple 2 nis analogous toantidiagonal n:
Implementation notes #
While we could implement this by filtering (fintype.pi_finset $ λ _, range (n + 1)) or similar,
this implementation would be much slower.
In the future, we could consider generalizing finset.nat.antidiagonal_tuple further to
support finitely-supported functions, as is done with cut in
archive/100-theorems-list/45_partition.lean.
Lists #
list.antidiagonal_tuple k n is a list of all k-tuples which sum to n.
This list contains no duplicates (list.nat.nodup_antidiagonal_tuple), and is sorted
lexicographically (list.nat.antidiagonal_tuple_pairwise_pi_lex), starting with ![0, ..., n]
and ending with ![n, ..., 0].
#eval antidiagonal_tuple 3 2
-- [![0, 0, 2], ![0, 1, 1], ![0, 2, 0], ![1, 0, 1], ![1, 1, 0], ![2, 0, 0]]
Equations
- list.nat.antidiagonal_tuple (k + 1) n = (list.nat.antidiagonal n).bind (λ (ni : ℕ × ℕ), list.map (λ (x : fin k → ℕ), fin.cons ni.fst x) (list.nat.antidiagonal_tuple k ni.snd))
- list.nat.antidiagonal_tuple 0 (n + 1) = list.nil
- list.nat.antidiagonal_tuple 0 0 = [matrix.vec_empty]
The antidiagonal of n does not contain duplicate entries.
Multisets #
multiset.antidiagonal_tuple k n is a multiset of k-tuples summing to n
Equations
Finsets #
finset.antidiagonal_tuple k n is a finset of k-tuples summing to n
Equations
- finset.nat.antidiagonal_tuple k n = {val := multiset.nat.antidiagonal_tuple k n, nodup := _}
The disjoint union of antidiagonal tuples Σ n, antidiagonal_tuple k n is equivalent to the
k-tuple fin k → ℕ. This is such an equivalence, obtained by mapping (n, x) to x.
This is the tuple version of finset.nat.sigma_antidiagonal_equiv_prod.