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
==================================================