1 | initial version |
It is not really a Sage question but a programming question. If your numbers were only 0 and 1, you could have tried an exhaustive search (using for example itertools.product([0,1], repeat=20)
. But testing 10^20 cases is impossible, so you need to inspect your equations to reduce the set of possiblities. For example, x5-x2=3
tells you that x5
can be deduced from x2
(so you will not have to iterate over it) and that x2
is between 0 and 6 ; x1*x2=18
tells you that x2
can be deduced from x1
(so you will not have to iterate over it either) and x1
can only take the values 2, 3, 6, 9.
You can also try to solve your system symbolically and see how many parameters are free, but you should be aware that it is not very reliable:
sage: var('x1 x2 x3 x4')
(x1, x2, x3, x4)
sage: solve([x1*x2==18, x4-x2==4], x1,x2,x3,x4)
[[x1 == 18/r1, x2 == r1, x3 == r2, x4 == r1 + 4]]