Skip to content

Commit

Permalink
more use of STL vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCremona committed Mar 5, 2024
1 parent 4a84d07 commit e66e9a4
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 935 deletions.
9 changes: 4 additions & 5 deletions libsrc/conic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,9 @@ void testmodsqrt()
cout << "Enter a modulus m: ";
cin >> m; mm=m;
vector<bigint> plist=pdivs(mm);
int* flag = new int[m];
for(i=0; i<m; i++) flag[i]=0;
vector<int> flag(m,0);
for(i=0; i<=m/2; i++) flag[(i*i)%m]=1;
for(i=0; i<m; i++)
for(i=0; i<m; i++)
{
a=i; // cout<<"a = "<<a;

Expand All @@ -600,12 +599,12 @@ void testmodsqrt()
if((x*x-a)%mm==0) cout<<" --checks.";
else cout << "--WRONG!";
}
else
else
{
cout << "\tNo solution";
}
#endif
if(res!=flag[i])
if(res!=flag[i])
{
cout << "WRONG ANSWER for a="<<a<<endl;
ok=0;
Expand Down
7 changes: 3 additions & 4 deletions libsrc/cperiods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void eiperiods(bigcomplex e1, bigcomplex e2, bigcomplex e3,

//#define DEBUG_CUBIC

bigcomplex* solve_nonsingular_cubic(const bigint& c1, const bigint& c2, const bigint& c3)
vector<bigcomplex> solve_nonsingular_cubic(const bigint& c1, const bigint& c2, const bigint& c3)
//Returns an array of 3 complex roots.
{
#ifdef DEBUG_CUBIC
Expand All @@ -120,7 +120,7 @@ bigcomplex* solve_nonsingular_cubic(const bigint& c1, const bigint& c2, const bi
bigint p3= 3*c2 - c1*c1;
bigint q = c1*(2*sqr(c1)-9*c2)+27*c3;
bigfloat rq=I2bigfloat(q), rp3=I2bigfloat(p3);
bigcomplex *roots = new bigcomplex[3];
vector<bigcomplex> roots(3);
long i;

#ifdef DEBUG_CUBIC
Expand Down Expand Up @@ -233,7 +233,7 @@ void getei(const Curvedata& E, bigcomplex& e1, bigcomplex& e2, bigcomplex& e3)
#ifdef DEBUG
cout<<"Solving monic cubic with coeffs "<<b2<<","<<(8*b4)<<","<<16*b6<<endl;
#endif
bigcomplex* ei = solve_nonsingular_cubic(b2,8*b4,16*b6);
vector<bigcomplex> ei = solve_nonsingular_cubic(b2,8*b4,16*b6);
#ifdef DEBUG
cout<<"ei = "<<ei[0]<<","<<ei[1]<<","<<ei[2]<<endl;
#endif
Expand All @@ -243,7 +243,6 @@ void getei(const Curvedata& E, bigcomplex& e1, bigcomplex& e2, bigcomplex& e3)
cout<<"After rescaling,\n";
cout<<"ei = "<<e1<<","<<e2<<","<<e3<<endl;
#endif
delete [] ei;
}

Cperiods::Cperiods(const Curvedata& E)
Expand Down
4 changes: 2 additions & 2 deletions libsrc/eclib/cperiods.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class Cperiods {
vector<bigcomplex> ellztopoint(const bigcomplex& z, const bigcomplex& a1, const bigcomplex& a2, const bigcomplex& a3);
}; // end of class Cperiods def'n

bigcomplex* solve_nonsingular_cubic(const bigint& c1, const bigint& c2, const bigint& c3); //Returns an array
// Gets the 3 2-division points given the coefficients
vector<bigcomplex> solve_nonsingular_cubic(const bigint& c1, const bigint& c2, const bigint& c3);
// Gets the 3 2-division points given the coefficients
void getei(const Curvedata& E, bigcomplex& e1, bigcomplex& e2, bigcomplex& e3);
// Reorders 3 complex nos so real parts are decreasing
void reorder1(bigcomplex& a, bigcomplex& b, bigcomplex& c);
Expand Down
1 change: 0 additions & 1 deletion libsrc/eclib/htconst.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ inline double height_constant(const Curvedata& CD)
}
double egr_height_constant(const Curvedata& CD);

bigfloat lower_height_bound_alt(const Curvedata& CD);
bigfloat lower_height_bound_search(const Curvedata& CD, const bigfloat& reg);
bigfloat Gamma_n(long n); // Gamma(n) = (n-1)!
bigfloat Gamma_n_plus_half(long n); // Gamma(n+1/2) = (2n)!sqrt(pi) / (4^n*n!)
Expand Down
13 changes: 5 additions & 8 deletions libsrc/eclib/mglobsol.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,19 @@ class quartic_sieve : public point_processor {
int verbose, easy, use_stoll;
long ulim;
int num_aux;
long* auxs;
int** xgood_mod_aux;
int** squares;
long* umod;
long nwprimes; long* wprimes; long* uprimes;
vector<long> auxs, umod, wprimes, uprimes;
vector<vector<int>> xgood_mod_aux, squares;
long nwprimes;
long npoints, maxnpoints;
int process(const bigint& x, const bigint& y, const bigint& z)
{pu=x; pv=y; pw=z; npoints++;
//cout<<"[x,y,z]=["<<x<<","<<y<<","<<z<<"]\n";
{pu=x; pv=y; pw=z; npoints++;
//cout<<"[x,y,z]=["<<x<<","<<y<<","<<z<<"]\n";
return (npoints>=maxnpoints);
}
// (x,y,z) as returned by ms's sieve; the point is (x/z,y/z^2)
public:
quartic_sieve(void) {;}
quartic_sieve(quartic * gg, int moduli_option=2, int verb=0);
~quartic_sieve();
long search(double h_lim, long maxnpts=1, int posxonly=0);
long stoll_search(double h_lim, int posxonly=0);
long search_range(int lower, bigfloat lower_bound,
Expand Down
2 changes: 1 addition & 1 deletion libsrc/eclib/mlocsol.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int locallysoluble(const bigint& a, const bigint& c, const bigint& e,

/* Samir Siksek's Local Solubility Test for odd p */

int local_sol(const bigint& p,bigint *c, int verbose=0);
int local_sol(const bigint& p, vector<bigint> c, int verbose=0);

// Checks for solublility in Qp
int new_qpsoluble(const quartic& g, const bigint& p, int verbose=0);
Expand Down
35 changes: 12 additions & 23 deletions libsrc/eclib/quadratic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,16 @@

class quadratic {
friend class unimod;
private:
bigint * coeffs; // will always have length 3
// init just allocates memory
void init();
private:
vector<bigint> coeffs;
public:
void set(long a, long b, long c)
{coeffs[0]=a; coeffs[1]=b; coeffs[2]=c;}
void set(const bigint& a, const bigint& b, const bigint& c)
{coeffs[0]=a; coeffs[1]=b; coeffs[2]=c;}
void set(const bigint* q)
{coeffs[0]=q[0]; coeffs[1]=q[1]; coeffs[2]=q[2];}
void set(const quadratic& q)
{coeffs[0]=q.coeffs[0]; coeffs[1]=q.coeffs[1]; coeffs[2]=q.coeffs[2];}
quadratic() {init(); set(0,0,0);}
~quadratic();
quadratic(const bigint& a, const bigint& b, const bigint& c) {init(); set(a,b,c);}
quadratic(long a, long b, long c) {init(); set(a,b,c);}
quadratic(const bigint* q) {init(); set(q);}
quadratic(const quadratic& q) {init(); set(q);}
void operator=(const quadratic& q) {set(q);}
void set(const bigint& a, const bigint& b, const bigint& c) {coeffs = {a, b, c};}
quadratic() { bigint zero(0); coeffs={zero,zero,zero};}
quadratic(const bigint& a, const bigint& b, const bigint& c) {coeffs = {a, b, c};}
quadratic(long a, long b, long c) {coeffs = {BIGINT(a), BIGINT(b), BIGINT(c)};}
quadratic(const bigint* q) {coeffs = {q[0], q[1], q[2]};}
quadratic(const quadratic& q) {coeffs = q.coeffs;}
void operator=(const quadratic& q) {coeffs = q.coeffs;}
bigint eval(const bigint& x, const bigint& z) const
{return coeffs[0]*sqr(x) + coeffs[1]*x*z + coeffs[2]*sqr(z);}
bigint operator()(const bigint& x, const bigint& z) const
Expand All @@ -59,10 +49,9 @@ class quadratic {
{return coeffs[0]*sqr(x) + coeffs[1]*x + coeffs[2];}
bigint operator()(const bigint& x) const
{return coeffs[0]*sqr(x) + coeffs[1]*x + coeffs[2];}
bigint coeff(int i);
bigint operator[](int i) const;
void set_coeff(int i, const bigint& a)
{if((i>=0)&&(i<=2)) coeffs[i]=a;}
bigint coeff(int i) const {return coeffs[i];}
bigint operator[](int i) const {return coeffs[i];}
void set_coeff(int i, const bigint& a) {if((i>=0)&&(i<=2)) coeffs[i]=a;}
friend bigint resultant(const quadratic& q1, const quadratic& q2);
bigint disc() const {return sqr(coeffs[1])-4*coeffs[0]*coeffs[2];}
void output(ostream& os=cout) const
Expand Down
Loading

0 comments on commit e66e9a4

Please sign in to comment.