Ask Your Question

Revision history [back]

You can use IntegerListsLex for such things.

If you want to iterate over 20 variables $A_0,...,A_{19}$ such that $1 \leq A_i \leq 100$ and $A_{i+1}\leq A_i$ for every $i$, you can do:

sage: for A in IntegerListsLex(length=20, min_part=1, max_part=100, min_slope=0):
....:     do_what_tyou_need_with_A, you can use A[0], A[1], ...A[19], but also sum(A) or print(A)

That said, besides your question, you should also notice that the condition if sum(A)^(1/2) in ZZ and sum(A)^(1/3) in ZZ is valid for a very sparse set of integers, so you should first iterate over se possible sums, and them decompose those sums with IntegerListLex using the options min_sum=s and max_sum=s. As cubes are sparser than squares, you can iterate over an integer c, and set s as c^3 and see if if s^(1/2) in ZZ and for such s, look for A in IntegerListsLex(length=20, min_part=1, max_part=100, min_slope=0, min_sum=s, max_sum=s) which will avoid a lot of useless tuples.