Reputation: 1
How does one add 3 variables and 3 equations using Python's SymPy? I tried using the documentation to SymPy, but it doesn't have any examples? One of the equations is to set a specific gcd.
Upvotes: 0
Views: 396
Reputation: 4329
SymPy cannot solve inhomogeneous ternary quadratic equations, so your equation must be transformed. So, your initial equation is
Let's introduce two new variables , and
. You can easily express the old variables as
, and
. Substitution of these formulas into the original equation gives after simplification
Multiply this equation by 4:
Now, because we can write the equation as
Let's introduce new variables
Then
and our equation becomes
Finally, this can be written as
That means, that a, b-2, and u-2 form a Pythagorian triple. The general solution for these is well known:
Now we need to return to our initial variables:
From the last equation we express u, substitute it to the first equation and use to get the full solution in terms of initial variables:
It must be noted, that due to the nature of the substitution which we made in order to solve the equation, not every possible combination of p and q will give a solution of the initial equation in integer numbers. We got some spurious non-integer solutions here. However, every integer solution of the initial equation can be obtained from these formulas with some values of k, p, and q.
We can easily check that these formulas indeed give a solution, by substitution these formulas into the original equation and simplification, for example on Wolfram Alpha:
Now, let's take into account the last set of inequalities: x>=y>=z. It's obvious, that in order for y to be larger or equal to z, the parameter q must be equal to zero. If we substitute q=0 into expressions for x, y, and z we obtain the same result
It's obvious, that from this expression we can can get all integer numbers. Consequently, the only solution to your equation which satisfies the inequalities is x = y = z for all integer values.
Upvotes: 1