Elements in the lattice An
Sorry in advance if this is not the right place to ask this simple question.
As it is usual, An=(a1,…,an+1)∈Zn+1:a1+⋯+an+1=0. Now we define the norm ∥(a1,…,an+1)∥:=∑i:ai>0ai. I would like an algorithm with input (n,k), that returns all elements in An with norm equal to k.
For example, if n=1 then (k,−k) and (−k,k) are all the elements in A1 with norm equal to k.
For n=2 and k=2, we have (2,0,−2),(2,−1,−1),(2,−2,0),(1,1,−2),(1,−2,1),(0,2,−2),(0,−2,2),(−1,2,−1),(−1,−1,2),(−2,2,0),(−2,0,2).
I think you are looking for the integer partitions of k of length n+1. Have a look at the iterator
Partitions(k,length=n+1)
.Perhaps
Compositions(k, length=n+1)
would be closer to what you want.None of them works since the vectors may have zero and negative coordinates.
Sorry, misread your question. Here's some facts
So, a sketch of algorithm to generate one such vector would be :
To iterate over all such vectors, you can use Sage's
Compositions
andPermutations
.