Collections of tuples of naturals with the same sum #
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 #
-
antidiagonalTuple 2 n
is analogous toantidiagonal n
:
Implementation notes #
While we could implement this by filtering (Fintype.PiFinset fun _ ↦ range (n + 1))
or similar,
this implementation would be much slower.
In the future, we could consider generalizing Finset.Nat.antidiagonalTuple
further to
support finitely-supported functions, as is done with cut
in
archive/100-theorems-list/45_partition.lean
.
Lists #
List.antidiagonalTuple k n
is a list of all k
-tuples which sum to n
.
This list contains no duplicates (List.Nat.nodup_antidiagonalTuple
), and is sorted
lexicographically (List.Nat.antidiagonalTuple_pairwise_pi_lex
), starting with ![0, ..., n]
and ending with ![n, ..., 0]
.
#eval antidiagonalTuple 3 2
-- [![0, 0, 2], ![0, 1, 1], ![0, 2, 0], ![1, 0, 1], ![1, 1, 0], ![2, 0, 0]]
Equations
- List.Nat.antidiagonalTuple 0 0 = [![]]
- List.Nat.antidiagonalTuple 0 (Nat.succ n) = []
- List.Nat.antidiagonalTuple (Nat.succ k) x = List.bind (List.Nat.antidiagonal x) fun (ni : ℕ × ℕ) => List.map (fun (x : Fin k → ℕ) => Fin.cons ni.1 x) (List.Nat.antidiagonalTuple k ni.2)
Instances For
The antidiagonal of n
does not contain duplicate entries.
Multisets #
Finsets #
Finset.Nat.antidiagonalTuple k n
is a finset of k
-tuples summing to n
Equations
- Finset.Nat.antidiagonalTuple k n = { val := Multiset.Nat.antidiagonalTuple k n, nodup := (_ : Multiset.Nodup (Multiset.Nat.antidiagonalTuple k n)) }
Instances For
The disjoint union of antidiagonal tuples Σ n, antidiagonalTuple 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.sigmaAntidiagonalEquivProd
.
Equations
- One or more equations did not get rendered due to their size.