0

I came across the answer to solving a quadratic diophantine equation on this site by @Willjagy: General method for determining if $Ax^2 + Bx + C$ is square I wish to know how the four seed solutions were obtained. Is it by trial and error or was there some algorithm that was followed?

As an aside, is the process reversible? i.e. knowing integer solutions to $X^2-DY^2=k^2$ for some $k$, is it possible to find solutions to $X^2-DY^2=1$?

RTn
  • 299

2 Answers2

1

At some point I put in more print statements. Any solution (as a column vector) is taken to a new solution by multiplying by the matrix I call the "automorphism" matrix. The seed solutions are those, with positive $x,y$ in $x^2 - d y^2 = k,$ such that the inverse of the automorphism matrix takes the solution to one with $x$ or $y$ negative or zero. You definitely need to know the original Pell $x^2 - d y^2 = 1$ to accomplish this. I will post the program below this output. From what I can see, the only command used from my personal file form.h is the simple mp_Factored command, not really part of this algorithm.

======================================

jagy@phobeusjunior:~$  ./Pell_Target_Fundamental
  Automorphism matrix:  
    3   4
    2   3
  Automorphism backwards:  
    3   -4
    -2   3

  3^2 - 2 2^2 = 1

 w^2 - 2 v^2 = 119 =  7 17

Tue May 21 12:25:13 PDT 2019

w:  11  v:  1  SEED   KEEP +- 
w:  13  v:  5  SEED   KEEP +- 
w:  19  v:  11  SEED   BACK ONE STEP  13 ,  -5
w:  29  v:  19  SEED   BACK ONE STEP  11 ,  -1
w:  37  v:  25
w:  59  v:  41
w:  101  v:  71
w:  163  v:  115
w:  211  v:  149
w:  341  v:  241
w:  587  v:  415
w:  949  v:  671
w:  1229  v:  869
w:  1987  v:  1405
w:  3421  v:  2419
w:  5531  v:  3911
w:  7163  v:  5065
w:  11581  v:  8189
w:  19939  v:  14099
w:  32237  v:  22795
w:  41749  v:  29521
w:  67499  v:  47729
w:  116213  v:  82175
w:  187891  v:  132859
w:  243331  v:  172061
w:  393413  v:  278185
w:  677339  v:  478951
w:  1095109  v:  774359
w:  1418237  v:  1002845
w:  2292979  v:  1621381
w:  3947821  v:  2791531
w:  6382763  v:  4513295
w:  8266091  v:  5845009
w:  13364461  v:  9450101

Tue May 21 12:25:44 PDT 2019

 w^2 - 2 v^2 = 119 =  7 17

jagy@phobeusjunior:~$ 

======================================================

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <strstream>
#include <list>
#include <set>
#include <math.h>
#include <iomanip>
#include <string>
#include <algorithm>
#include <iterator>
#include <time.h>
#include <gmp.h>
#include <gmpxx.h>
#include "form.h"

using namespace std;

//   g++  -o Pell_Target_Fundamental Pell_Target_Fundamental.cc  -lgmp -lgmpxx


//  ./Pell_Target_Fundamental


int main()
{


   mpz_class target, d, t,s;

  d = 2;


  t =  3  ;
  s =  2  ;


cout << "  Automorphism matrix:  " << endl;
cout << "    " << t << "   " << d * s << endl;
cout << "    " << s << "   " << t << endl;


cout << "  Automorphism backwards:  " << endl;
cout << "    " << t << "   " << -d * s << endl;
cout << "    " << -s << "   " << t << endl;

  target =  119  ;

  int time_limit_in_seconds = 31;

  if ( t * t - d * s * s != 1 ) cout << " not 1 " << endl;
  else
  {
  cout  << endl << "  " << t << "^2 - " << d << " " << s << "^2 = " <<  t * t - d * s * s << endl ;
  cout  << endl << " w^2 - " << d << " v^2 = " << target << " = " << mp_Factored(target) << endl << endl;
   system("date");
   cout << endl;
  int printcount = 0;
  for(mpz_class y = 0; printcount < 61 && clock() < time_limit_in_seconds * CLOCKS_PER_SEC && y <= 1000000000; y++){
    mpz_class n = target + d * y * y;
    if ( n > 0 && mp_SquareQ(n ) )
    {
      ++printcount;
      mpz_class x;
      x =  mp_Sqrt( n);

       cout << "w:  " << x << "  v:  " << y ;
            if ( t * x - d * s * y <= 0 || -s * x + t * y <= 0)
            {
             cout << "  SEED ";
             if ( target < 0 && x * s <= (t -1) * y ) cout <<  "  KEEP +- ";
             else  if ( target > 0 && x * s >= (t +1) * y ) cout <<  "  KEEP +- ";
             else cout << "  BACK ONE STEP  " << t * x - d * s * y << " ,  " << -s * x + t * y ;  

            }


       cout << endl;
    } // square

  } // for y
   cout << endl;
   system("date");
    cout << endl  << " w^2 - " << d << " v^2 = " << target  << " = " << mp_Factored(target)  << endl << endl;

  } // else 1



    return 0 ;
}

//   g++  -o Pell_Target_Fundamental Pell_Target_Fundamental.cc  -lgmp -lgmpxx


//  ./Pell_Target_Fundamental

==================================================

Will Jagy
  • 139,541
  • Thank you. But I am still confused. Can one of the solutions be found by the determinant of the isomorphism or the backwards isomorphism matrix? Or is it by mere observation you deduce $x=11,y=\pm1$ and $x=13,y=\pm5$? Sorry, I do not have 'C'. So can you please give the algorithm for the seed solution as such? Thanks a lot again for your patience! Also, as I asked, is the process reversible to find the solutions for Pell's equation with residue '1'? – RTn May 21 '19 at 19:45
  • @RTn the first thing you need to do is solve $x^2 - d y^2=1.$ This is very fast by continued fractions, and there are lots of methods that are equivalent to the continued fraction method. My versions are all in C++ – Will Jagy May 21 '19 at 19:59
  • Yes, I got to that point. I have solutions for $x^2-dy^2=1$ by Chakravala algorithm. But then from that how do I derive the seed solutions for the $x^2-dy^2=k$? What is the algorithm for that, my I know? – RTn May 21 '19 at 20:03
  • 1
    @RTn I just have the computer loop, take $y$ from $0$ to $1000000,$ but stop after about 60 seconds on the clock. Then whenever $k + d y^2$ is a square, find the positive integer $x = \sqrt{k + d y^2}$ and print an answer. If $k <0$ we start $y$ large enough that $k + d y^2 \geq 0$ – Will Jagy May 21 '19 at 20:08
1

as long as $|k|$ is not too large, you can find everything for $ax^2 + bxy + c y^2 = k$ with Conway's diagram. I have drawn and posted many:

http://math.stackexchange.com/questions/81917/another-quadratic-diophantine-equation-how-do-i-proceed/144794#144794

http://math.stackexchange.com/questions/228356/how-to-find-solutions-of-x2-3y2-2/228405#228405

http://math.stackexchange.com/questions/342284/generate-solutions-of-quadratic-diophantine-equation/345128#345128

http://math.stackexchange.com/questions/487051/why-cant-the-alpertron-solve-this-pell-like-equation/487063#487063

http://math.stackexchange.com/questions/512621/finding-all-solutions-of-the-pell-type-equation-x2-5y2-4/512649#512649

http://math.stackexchange.com/questions/680972/if-m-n-in-mathbb-z-2-satisfies-3m2m-4n2n-then-m-n-is-a-perfect-square/686351#686351

http://math.stackexchange.com/questions/739752/how-to-solve-binary-form-ax2bxycy2-m-for-integer-and-rational-x-y/739765#739765 :::: 69 55

http://math.stackexchange.com/questions/742181/find-all-integer-solutions-for-the-equation-5x2-y2-4/756972#756972

http://math.stackexchange.com/questions/822503/positive-integer-n-such-that-2n1-3n1-are-both-perfect-squares/822517#822517

http://math.stackexchange.com/questions/1078450/maps-of-primitive-vectors-and-conways-river-has-anyone-built-this-in-sage/1078979#1078979

http://math.stackexchange.com/questions/1091310/infinitely-many-systems-of-23-consecutive-integers/1093382#1093382

http://math.stackexchange.com/questions/1132187/solve-the-following-equation-for-x-and-y/1132347#1132347 <1,-1,-1>

http://math.stackexchange.com/questions/1132799/finding-integers-of-the-form-3x2-xy-5y2-where-x-and-y-are-integers

http://math.stackexchange.com/questions/1221178/small-integral-representation-as-x2-2y2-in-pells-equation/1221280#1221280

http://math.stackexchange.com/questions/1404023/solving-the-equation-x2-7y2-3-over-integers/1404126#1404126

http://math.stackexchange.com/questions/1599211/solutions-to-diophantine-equations/1600010#1600010

http://math.stackexchange.com/questions/1667323/how-to-prove-that-the-roots-of-this-equation-are-integers/1667380#1667380

http://math.stackexchange.com/questions/1719280/does-the-pell-like-equation-x2-dy2-k-have-a-simple-recursion-like-x2-dy2

http://math.stackexchange.com/questions/1737385/if-d1-is-a-squarefree-integer-show-that-x2-dy2-c-gives-some-bounds-i/1737824#1737824 "seeds"

http://math.stackexchange.com/questions/1772594/find-all-natural-numbers-n-such-that-21n2-20-is-a-perfect-square/1773319#1773319

Is there a simple proof that if $(b-a)(b+a) = ab - 1$, then $a, b$ must be Fibonacci numbers? 1,1,-1; 1,11

To find all integral solutions of $3x^2 - 4y^2 = 11$

Will Jagy
  • 139,541