# Holzer reduction and some modifications

Hi All, This week I managed to implement Holzer’s reduction and change the behaviour of DE module a little bit. First let’s take a look at Holzer’s reduction.

##### Holzer Reduction

Holzer reduction is concerned with reducing solutions of the quadratic ternary nonrmal equation . The Holzer’s theorem says that if the above equation is solvable there is always a solution such that . The algorithm for this is explained in [1]. Below is a rough sketch. Before applying the algorithm we have to make square free and we assume that positive and is negative(We can always select in such a way that this is the case). Suppose there is a solution that is not Holzer reduced.

- If is even set and let be any solution to the equation .
- If is odd, c is odd let and let be any solution to the equation .
- Let be the nearest integer to .
- Then the following expressions for gives a solution such that .

Continuing this manner one would find a solution such that .

##### Some changes to DE module

I made some changes to the structure of DE module too. Now every type of equation returns a tuple ordered according to the sorted order of variable names used in the equation. Quadratic ternary forms and linear equations returns only one tuple, the parametric solution, and quadratic binary equation returns a set of tuples. This format may be changed in future. The most important change I did to the DE module is that, now before solving any given equation, DE module checks whether that can be factored and If so, solves those factors separately. For example, given the equation , it will solve and separately and combine those results. Also I managed to implement a general method for testing that would check whether the solutions returned by various methods satisfy the original equation. So I hope to get rid of the other redundant methods like check_ternary_quadratic(), solution_ok_quadratic() in the test file. A thank should go to Aaron for proposing such a methodology.

##### Future work

Pernici has pointed out that some of the solution methodologies in quadratic binary form can be improved so that they take less time. He also has done a great job in implementing the solutions for quadratic congruence . I hope to use those results when his PR gets merged into master. He proposed a method due to cornacchia to improve the speed of the solutions but after a little surveying, I found that implementing solutions for can be used to improve the speed. Current algorithms for solving binary quadratic equation employs a general solving method so it miss out some speed enhancements for the special case . My plan is if can be converted to the form , then solve it using methods for that, otherwise apply the general method. I found a good reference [2] for this. A huge thank should go to Pernici for pointing out the improvements.

##### References

[1] Efficient Solution of Rational Conices, J. E. Cremona and D. Rusin, Mathematics of Computation, Volume 00, Number 0.

[2] Binary Quadratic Forms: An Algorithmic Approach, J. Buchmann and U. Vollmer, Springer-Verlag, Berlin, Heidelberg, 2007.

- Posted in: GSoC-2013-SymPy
- Tagged: Binary quadratic forms, Diophantine Equations, Holzer reduction, SymPy

For k = uy0 – vx0 to have a solution, doesn’t gcd(x0, y0) need to divide k?

Sorry Aaron for the late reply.

Suppose there is a solution (x_0, y_0, z_0) to the equation ax**2 + by**2 + cz**2 = 0. We can assume that gcd(x_0, y_0, z_0) = 1. (Otherwise we divide by the gcd). Given this, we can prove that gcd(x_0, y_0) should equal 1.

Suppose gcd(x_0, y_0) = d > 1, since ax_0**2 + by_0**2 + cz_0**2 = 0, d**2 divides cz_0**2, so gcd(cz_0**2, d) > 1. This implies gcd(c, d**2) > 1 or/and gcd(z_0**2, d**2) > 1. Since abc is square free, so is c and this forces gcd(z_0**2, d**2) to be grater than 1, which consequently implies gcd(z_0, d) > 1. So we have, gcd(x_0, y_0, z_0) > 1, which is a contradiction. So gcd(x_0, y_0) = 1.

Thanks (you have a typo in there that tripped me up for a bit: it should say “gcd(cz_0**2, d**2) > 1” I think.

So my next question is, how do you ensure that abc is squarefree with a, b > 0 and c < 0? I guess the answer to the second part is obvious, because one of a, b, c must have a different sign or else (0, 0, 0) would be the only solution, so by a multiplication by -1 and/or rearrangement of variables you can get it to that form.

But say you have x**2 + 2*y**2 – 2*z**2 = 0 (a = 1, b = 2, c = -2). Then abc = -4 is not squarefree, but (0, 1, 1) is a nontrivial solution, so it definitely is solvable.

Hi Aaron, I don’t see a reply option to your last comment so I post this separately.

Yes, that should be . It’s a typo. Sorry for that.

Given an input equation of the form , we can construct a new equation such that are square free and pairwise prime. We should apply this procedure when solving since .

If then we divide all the coefficients by .

Now Suppose any of the coefficients is not square free, say for some and square free. Instead of solving the original equation we solve and reconstruct the solutions for the original equation. We should do the same thing for and . Since 1, 2, -2 are all square free in your example we don’t need to carry out this step.

Now lets assume we have an equation with the coefficients being square free. Suppose any two of the coefficients, say and are not pairwise prime, i.e . So we have with and (Since ). Since we get that, . Since we should have . Now suppose where is square free, we can conclude that . Let . Substituting in the original equation we get, . By simplifying we end with . Now we do the same if either or . We solve the equation we get after going through these procedures instead of the original equation and recover the solutions for the original equation after that.

Suppose . we have so i.e . Since is square free, this is not possible. So we should have . Also we know that . Using these two facts we get . Similarly we can see that . So our process for making two coefficients pairwise prime does not affect the gcd of other coefficient pairs.

In your example, , we can conclude that . So we set and we get the new equation . Now this meets our requirements so we solve this and reconstruct the solutions for the original. In Diophantine module, I implemented methods, `square_factor()`, `pairwise_prime()` and `reconstruct()` to carry out this whole process.

Phew, that was a long answer.

Thanks for your responses. For your future examples, it might be informative to take a concrete example and work through it as you go along.