Elements in the lattice $A_n$
Sorry in advance if this is not the right place to ask this simple question.
As it is usual, $A_n ={ (a_1,\dots,a_{n+1}) \in\mathbb Z^{n+1}:a_1+\dots+a_{n+1}=0}$. Now we define the norm $$ \|(a_1,\dots,a_{n+1})\|:= \sum_{i:a_i>0} a_i. $$ I would like an algorithm with input $(n,k)$, that returns all elements in $A_n$ with norm equal to $k$.
For example, if $n=1$ then $(k,-k)$ and $(-k,k)$ are all the elements in $A_1$ 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
.