Trying to solve the Diophantine equation (or variation?) using Solve
in order to generate some chemical formulas. I need to generate all possible solutions. The code is following:
mx1 = 1007825; mx2 = 12000000; mx3 = 14003074; mx4 = 15994915; mx5 = 18998403;
mx6 = 30973762; mx7 = 31972071; mx8 = 34968853; mx9 = 78918338; mx10 = 126904468;
up = 722126458;
dn = 722120458;
x1max = 70; x2max = 125; x3max = 25; x4max = 27; x5max = 10; x6max = \
0; x7max = 0; x8max = 0; x9max = 0; x10max = 0;
Solve[{dn <=
mx1*x1 + mx2*x2 + mx3*x3 + mx4*x4 + mx5*x5 + mx6*x6 + mx7*x7 +
mx8*x8 + mx9*x9 + mx10*x10 <= up, x1max >= x1 >= 0,
x2max >= x2 >= 10, x3max >= x3 >= 0, x4max >= x4 >= 0,
x5max >= x5 >= 0, x6max >= x6 >= 0, x7max >= x7 >= 0,
x8max >= x8 >= 0, x9max >= x9 >= 0, x10max >= x10 >= 0}, {x1, x2,
x3, x4, x5, x6, x7, x8, x9, x10}, Integers]; // AbsoluteTiming
{0.2670152, Null}
As I am increasing number of variables time increase.
Addition of x6max=10 - time=2.15s; x7max=9 - time=32.34s
with addition of x8max=8
, x9max=8
and x10max=2
timing is ??
I am looking for suggestions how to speed up the process. One to several seconds time frame would be great.
Reduce
and FindInstance
perform roughly similar. Brute forcing doesn’t work effectively either.
Tried to work out solution in different way; like generating 2 sets (e.g. for x1
to x5
and x6
to x6
) with all possible combinations, sorting them (decreasing/increasing order) and than sum elements. It doesn’t perform fast either considering 1 million element tables.
FrobeniusSolve
instead ofSolve
when one deals with diophantine equations. See this answer Finding the number of solutions to a diophantine equation for encouragement. This might be another one How to find lattice points on a line segment? $\endgroup$