in lattices/Zn_lattice.py [0:0]
def sum_of_sq(total, v, n):
"""find all positive integer vectors of size n:
- whose squared elements sum to total
- maximium value is v
"""
if total < 0:
return []
elif total == 0:
return [[0] * n]
elif n == 1:
while v * v > total:
v -= 1
if v * v == total:
return [[v]]
else:
return []
else:
res = []
for vi in range(v, -1, -1):
res += [[vi] + vv for vv in
sum_of_sq(total - vi * vi, vi, n - 1)]
return res