User:Chakravala nick

Amendments to the Chakravala Method for Solving Pell's Equation

Amendment 1 - Addition of Variable, f, to Vector

The current method uses a vector ( x_current, y_current, k_current) with k_current = x_current^2-Ny_current^2

I propose to use a new vector ( f_new, x_new, y_new, k_new) with:

f_new = gcd(x_current, N) x_new = x_current/gcd(x_current, N) y_new = y_current and k_new = f_new.x_new^2-N.y_new^2/f_new

The result of combining 2 vectors (f1, x1, y1, k1) and (f2, x2, y2, k2) is (1, f1x1f2x2+Ny1y2, f1x1y2+f2x2y1, f1f2k1k2)

Reduction of a vector is a 2-step process. The first step is the current reduction step ( f, x, y, k)->( f'=f, x'=x/gcd(x, y), y'=y/gcd(x, y), k'=k/gcd(x, y)^2) The second step is (f', x', y', k')->( f=f'.gcd( x', N/f'), x=x'/gcd( x', N/f'), y=y', k=k'/gcd( x', N/f')

The method for finding a starter vector and for finding a vector through the BIG M method now should search for the optimum by using all factors of N < sqrt(N) for f.

Sometimes after a combination and reduction f > N/f. To keep f < N/f it might be necessary to employ a transpose transformation. ( f, x, y, k) -> ( f_transpose = N/f, x_transpose = y, y_transpose = x, k_transpose = -k)

Amendment 2 - Direct Solutions When |k| is in {1, 2, 4} --- The current method would require that when k satisfies the condition above that the vector combine with itself (or sometimes - when |k| = 4 - the first vector encountered with |k|=4) until k=1.

In the following cases the solution can be obtained directly:

k=1 and f=1                           - x_solution = x                      , y_solution = y k=4 and f=1                            - x_solution = x(x^2-3)/2              , y_solution = y(x^2-1)/2
 * k| in { 1, 2} and not ( f=1 and k=1 ) - x_solution = (2fx^2-k)/|k|         , y_solution = 2xy/|k|
 * k| = 4 and f is even                 - x_solution = (fx^2-2sgn(k))^2/2-1   , y_solution = xy(fx^2-2sgn(k))/2
 * k| = 4 and f is odd and f > 1        - x_solution = fx^2(fx^2-3sgn(k))^2/2-1, y_solution = xy(fx^2-sgn(k))(fx^2-3sgn(k))/2

If N is of form f^2x^2±f, f^2x^2±2f or f^2x^2±4f. x_solution and y_solution can be obtained without looking for a starter by setting y to 1, k to -±1, -±2 or -±4 and solving. Example N=44 is 2^2.3^2+4.2, so f=2, x=3, y=1, k=-4 and x_solution = (fx^2-2sgn(k))^2/2-1  , y_solution = xy(fx^2-2sgn(k))/2. This method of solution would be done iteratively over k, f and x to determine appropriate N.

x_solution and y_solution can also be obtained without looking for a starter when N divides f1^2.x1^2 and f2^2.x2^2 in the ratio of ±f1:±f2, ±2f1:±f2 or ±4f1:±f2 ( where the 2 sides of the ratio are co-prime). Example 19 divides 1^2.5^2 and 1^2.4^2 in the ratio 2:1. This method is useful when general expressions for N are determined ( for 19 9n^2+8n+2 divides (3n+1)^2 and (3n+2)^2 in the ratio of 2:1. Combine ( 1, 3n+1, 1 -(2n+1)) and ( 1, 3n+2, 1, 2(2n+1)) => ( 1, 18n^2+17n+4, 6n+3, -2(2n+1)^2) => ( 1, 9n+4, 3, -2) => x_solution = (9n+4)^2/2+1, y_solution = 3(9n+4)...a general solution for N=9n^2+8n+2!

Amendment 3 - Before Resorting to Using BIG M, Search Previously Encountered Vectors for a Vector With Which to Combine --- With the current method, if |k| is not in { 1, 2, 4}, the only option is to employ the BIG M method to obtain a vector.

However, a previously encountered vector would be suitable for combining with the current vector, if:

1) it is not the current vector or its transpose; and

2)|k_prev.k_current| equals

i) 64 or 128 ( and mod( f_prev.x_prev.y_curr+f_curr.x_curr.y_prev, 4)=0); or	ii) 1, 2 or 4 times a prime squared; or	iii) 1, 2 or 4 times prime_1^2.prime_2 ( and there is a second previously encountered vector where |k| = prime_2 )

In light of this, if no direct solution is possible, one of a pair (or triplet for iii) of candidate vectors that satisfy one of the above conditions is a better starter vector than the one with lowest |k|.

Working Examples

N=28 (example of direct solution with |k|=4 and f is even)