(49/50) Pellian Equations
|
12-26-2023, 08:38 PM
(This post was last modified: 12-26-2023 08:43 PM by John Keith.)
Post: #1
|
|||
|
|||
(49/50) Pellian Equations
The first program listed here finds the basic solution to the Pellian equations
x^2 - d*y^2 = 1 or x^2 - d*y^2 = -1. To solve for the negative equation, enter d as a negative number. For d to be a valid argument for the negative equation, the repeating part of the continued fraction for the square root of d must be of odd length. See A031396 and A003814. If d is a square or if d is negative but not a valid argument, the trivial solution {1 0} is returned. This program is inspired by a program by Bob Pulluard in Datafile V19N1, available on the HHC thumb drive and from Jake Schwartz's PPC Archive. This program uses a completely different algorithm based on convergents to the square root of d. It is larger but at least 10 times as fast. The program requires the LongFloat Library because the computations can require very high precision, up to thousands of digits. The maximum size of d is limited by the amount of available memory, or the patience of the user. The largest value that I have solved for is 1026061, which requires over 7 hours on the physical 50g. The x value returned is a 2555 digit number. See A033316 for values of d whose solutions are increasingly large. Some notes on the theory of operation: The basis of the program is the observation that solutions of the Pellian equation for d are a subset of the convergents to the square root of d. After determining that d is neither a square (invalid argument) nor 1 plus a square (x = floor(sqrt(d)), y = 1), LongFloat functions are used to generate a list of the repeating part of the continued fraction for the square root d. If the length of the repeating part is odd, there is a solution for the negative equation. This solution can be found in about half the time of the solution for the positive equation, so this is done, and the positive solution is computed from the negative solution if required. The main loop of the program computes the convergents from the terms of the continued fraction, and tests them until a solution is found. This is similar to my recent Convergents program here. If the negative solution was computed and the positive solution wanted, the former is converted to the latter. Code:
The second program returns a list of solutions to the Pellian equation. It assumes the existence of a variable called PELIAN containing the program above. Given integers d on level 2 and n on level 1, returns list of the first n solutions for x^2 - d*y^2 = 1 if d is positive, or x^2 - d*y^2 = -1 if d is negative. Once the basic solution is found by PELIAN, the subsequent solutions can be computed by a simple recurrence. Therefor the program is very fast, although large values of d and/or n will quickly overflow memory. If d is a square or if d is negative but not a valid argument, a list of n copies of the trivial solution {1 0} is returned. Code:
|
|||
12-27-2023, 06:30 AM
Post: #2
|
|||
|
|||
RE: (49/50) Pellian Equations
Here a SYS version for 49G/50g, only deals with the +1 case.
49G (1.19-6) takes 124 s to process 1026061 correctly. Code: pell |
|||
12-27-2023, 12:56 PM
(This post was last modified: 12-27-2023 09:24 PM by Albert Chan.)
Post: #3
|
|||
|
|||
RE: (49/50) Pellian Equations
(12-26-2023 08:38 PM)John Keith Wrote: If the negative solution was computed and (x² − d*y²) = -1 (x² − d*y²)² = 1 (x² + d*y²)² − d*(2xy)² = 1 Some number theory book prefer solution (x,y) in the form z = x + y*√d z * conj(z) = -1 z² * conj(z²) = 1 z² = (x + y*√d)² = (x² + d*y²) + (2xy)*√d |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)