diff --git a/libsrc/arith.cc b/libsrc/arith.cc index cab9414..3b819d7 100644 --- a/libsrc/arith.cc +++ b/libsrc/arith.cc @@ -117,7 +117,7 @@ long primeclass::number(long n) } if(!ok) { - cout<<"Not enough primes in primeclass.number("< primeclass::getfirst (long n) /* returns list of first n primes */ } if(!ok) { - cout<<"Not enough primes in primeclass.getfirst("< posdivs(long a, const vector& plist) // cout << plist.size() << " primes: " < dlist(1,1); // cout << "Divisor 0 = 1" << endl; - vector::const_iterator pr = plist.begin(); - while(pr!=plist.end()) + for (const auto& p : plist) { - p=*pr++; e = val(p,a); + e = val(p,a); dlist.resize((e+1)*dlist.size()); for (j=0; j alldivs(long a, const vector& plist) long j,k,p,e,nd = 2; vector dlist(1,1); // cout << "Divisor 0 = 1" << endl; dlist.push_back(-1); // cout << "Divisor 1 = -1" << endl; - vector::const_iterator pr = plist.begin(); - while(pr!=plist.end()) + for (const auto& p : plist) { - p = *pr++; e = val(p,a); + e = val(p,a); dlist.resize((e+1)*dlist.size()); for (j=0; j sqdivs(long a, const vector& plist) { long j,k,p,e,nd = 1; vector dlist(1,1); - vector::const_iterator pr = plist.begin(); - while(pr!=plist.end()) + for (const auto& p : plist) { - p = *pr++; e = val(p,a)/2; + e = val(p,a)/2; dlist.resize((e+1)*dlist.size()); for (j=0; j sqfreedivs(long a, const vector& plist) { long j,k,p,e,nd = 1; vector dlist(1,1); - vector::const_iterator pr = plist.begin(); - while(pr!=plist.end()) + for (const auto& p : plist) { - p = *pr++; e = 1; + e = 1; dlist.resize((e+1)*dlist.size()); for (j=0; jplist = pdivs(n); - for(unsigned int i=0; i1) return 0; + auto plist = pdivs(n); + for( const auto p : plist) + if (val(p,n)>1) + return 0; return 1; } int is_valid_conductor(long n) { - long m=n, p, e; + if (n<11) return 0; + long m=n, e; e=0; while(!(m&1)) {e++; m>>=1;} if(e>8) return 0; e=0; while(!(m%3)) {e++; m/=3;} if(e>5) return 0; - vectorplist = pdivs(m); - for(unsigned int i=0; i2) return 0; + if (val(p,m)>2) + return 0; } - return 1; -} - - - - -// The following is no longer used - -long old_kronecker(long d, long n) -{ long ans=0; long m=n, d4=d%4; if(d4<0)d4+=4; - if ((gcd(d,n)==1) && ((d4==0)||(d4==1))) - { ans=1; - while (!(m%4)) m/=4; - if (!(m%2)) {m/=2; ans*=((d-1)%8 ? -1 : 1);} - ans *= legendre(d,m); - } - return ans; + return 1; } /* END OF FILE */ diff --git a/libsrc/conic.cc b/libsrc/conic.cc index e27203a..ba0f39b 100644 --- a/libsrc/conic.cc +++ b/libsrc/conic.cc @@ -60,19 +60,8 @@ int solve_conic(const bigint& a, const bigint& b, const bigint& c, const bigint& bigint& x, bigint& y, bigint& z, int method) { vector factorbase = pdivs(2*d); - // cout<<"factorbase(1) = "<::const_iterator pr; - pr=clist.begin(); - while(pr!=clist.end()) - { - p=*pr++; - if(p==two) continue; - if(legendre(mab,p)!=1) - { -// cout<<"testlocsol fails legendre(mab,p) with " -// <<"(a,b,p)=("<& plist, const bigint& m) + { + return !std::any_of(plist.begin(), plist.end(), + [m](const auto& p) + { + return (p>2) && (legendre(m,p)!=1); + } + ); + }; + return test(clist, -a*b) && test(alist, -b*c) && test(blist, -a*c); return 1; -} +} -int testlocsol(const bigint& a, const vector& alist, +int testlocsol(const bigint& a, const vector& alist, const bigint& b, const vector& blist) // tests if ax^2+by^2=z^2 is soluble, where a, b are // square-free, their prime factors being in alist and blist. @@ -589,20 +544,17 @@ int testlocsol(const bigint& a, const vector& alist, vector a0list, b0list, clist; long sa=sign(a), sb=sign(b); - if((sa<0)&&(sb<0)) + if((sa<0)&&(sb<0)) { // cout<<"testlocsol("<::const_iterator pr; - pr=alist.begin(); - while(pr!=alist.end()) + + for (const auto& p : alist) { - p=*pr++; - if(div(p,b)) + if(div(p,b)) { c*=p; clist.push_back(p); } @@ -611,26 +563,16 @@ int testlocsol(const bigint& a, const vector& alist, a0*=p; a0list.push_back(p); } } - pr=blist.begin(); - while(pr!=blist.end()) + for (const auto& p : blist) { - p=*pr++; - if(!div(p,c)) {b0*=p; b0list.push_back(p);} - } - -#if(0) - if((a!=-a0*c)||(b!=-b0*c)||(abs(c)!=gcd(a,b))) - { - cout<<"Error: (a,b)=("<::const_iterator pp=plist.begin(); pp!=plist.end(); pp++) + for( const auto& p : plist) { - bigint p=*pp; #ifdef DEBUG_Q_INPUT cout<<"p = "< new_bad_primes; - vector::iterator pr = the_bad_primes.begin(); - while(pr!=the_bad_primes.end()) + for (const auto& p : the_bad_primes) { - bigint p=*pr++; - if(div(p,discr)) new_bad_primes.push_back(p); + if(div(p,discr)) + new_bad_primes.push_back(p); } the_bad_primes=new_bad_primes; } @@ -314,7 +312,6 @@ void Curvedata::output(ostream& os) const else os<<"#torsion not yet computed"<= 0.0) - return (pow(x, third) ) ; - else - return( - pow(-x, third) ); -} - -void sort(bigfloat roots[3] ) -{ - bigfloat x0, x1, x2, temp ; - x0 = roots[0] ; x1 = roots[1] ; x2 = roots[2] ; - if (x0 > x1) { temp = x0; x0 = x1 ; x1 = temp ; } /* now x0 < x1 */ - if (x1 > x2) { temp = x1; x1 = x2 ; x2 = temp ; } /* now x1 < x2, x0 < x2 */ - if (x0 > x1) { temp = x0; x0 = x1 ; x1 = temp ; } /* now x0 < x1 < x2 */ - roots[0] = x0 ; roots[1] = x1; roots[2] = x2 ; -} - -CurvedataExtra::CurvedataExtra(const Curvedata& c) -: Curvedata(c) -{ - if ( isnull() ) {roots[0]=roots[1]=roots[2]=period=0; return; } - bigfloat fb2 = I2bigfloat(b2); - bigfloat fc6 = I2bigfloat(c6); - bigfloat fdiscr = I2bigfloat(discr); - if (conncomp == 1) { - bigfloat sqdisc = 24.0 * sqrt(-3.0 * fdiscr) ; - roots[2] = ( -fb2 + cuberoot(fc6 - sqdisc) + - cuberoot(fc6 + sqdisc) ) / 12.0 ; - } else { - bigfloat theta = atan2( 24.0 * sqrt(3.0*fdiscr), fc6) ; - bigfloat fc4 = I2bigfloat(c4); - bigfloat sqc4 = sqrt( fc4 ) ; - roots[0] = (-fb2 + 2.0 * sqc4 * cos( theta/3.0 )) / 12.0 ; - roots[1] = (-fb2 + 2.0 * sqc4 * cos( (theta+2.0*Pi())/3.0)) / 12.0; - roots[2] = (-fb2 + 2.0 * sqc4 * cos( (theta+4.0*Pi())/3.0)) / 12.0; - sort(roots) ; - } - // note that roots[2] (the THIRD one!) is always the largest root - // now compute the period - bigfloat a, b ; // parameters to feed to agm() - if (conncomp == 2){ - a = sqrt(roots[2] - roots[0]) ; - b = sqrt(roots[2] - roots[1]) ; - } else { - bigfloat fb4 = I2bigfloat(b4); // bigfloat version of b4 - bigfloat fp = sqrt( fb4/2.0 + roots[2] * (fb2/2.0 + 3.0 * roots[2]) ); - // f', where f is the cubic - a = 2.0 * sqrt( fp ) ; - b = sqrt( 3.0 * roots[2] + fb2/4.0 + 2.0 * fp ) ; - } - period = (2.0 * Pi() / agm(a, b) ); -} - -void CurvedataExtra::output(ostream& os) const -{ - Curvedata::output(os); - if(conncomp == 1) - os << "The real two-division point is " << roots[2] << endl ; - else - if(conncomp == 2) - os << "The real two-division points are " - << roots[0] << ", " << roots[1] << ", "<< roots[2] << endl ; - os << "The real period is " << period << endl; -} -#endif diff --git a/libsrc/curvered.cc b/libsrc/curvered.cc index a7875de..dafbfbc 100644 --- a/libsrc/curvered.cc +++ b/libsrc/curvered.cc @@ -115,7 +115,7 @@ void CurveRed::operator=(const CurveRed& E) conncomp=E.conncomp; ntorsion=E.ntorsion; reduct_array = E.reduct_array; - N=E.N; + N=E.N; } CurveRed::CurveRed(const Curvedata& E) @@ -136,10 +136,9 @@ CurveRed::CurveRed(const Curvedata& E) // Because the curve is minimal, Tate's algorithm reduce-loop is not needed //cout<<"Running Tate's algorithm"<::const_iterator pi= the_bad_primes.begin(); - while(pi!=the_bad_primes.end()) + + for (const auto& p : the_bad_primes) { - p = *pi++; ord_p_discr = val(p,discr); ord_p_j = ord_p_discr - 3*val(p,c4); if (ord_p_j < 0) ord_p_j = 0; @@ -166,7 +165,7 @@ CurveRed::CurveRed(const Curvedata& E) r = mod(r,p); t = mod(t,p); C.transform(r,zero,t); - + // test for Types In, II, III, IV if ( ndiv(p,c4) ) {temp=-C.a2; @@ -301,7 +300,7 @@ CurveRed::CurveRed(const Curvedata& E) reduct_array[p] = Reduction_type (ord_p_discr, ord_p_discr - 6, ord_p_j, 5, c_p); break; } - + // change coords so that p^3|C.a3, p^5|C.a6 if ( pdiv2 ) t = -p*p*root(a6t,2,p); else t = p*p*mod(-a3t*halfmodp, p); @@ -325,11 +324,8 @@ CurveRed::CurveRed(const Curvedata& E) }; // end switch } // end primes for-loop N = BIGINT(1); - map::const_iterator ri; - for(ri = reduct_array.begin(); ri!=reduct_array.end(); ri++) - { - N *= pow((ri->first), (ri->second).ord_p_N); - } + for( const auto& ri : reduct_array) + N *= pow((ri.first), (ri.second).ord_p_N); return; } // end of Tate's algorithm @@ -338,7 +334,7 @@ CurveRed::CurveRed(const Curvedata& E) bigint local_Tamagawa_exponent(CurveRed& c, const bigint& p) { if (is_zero(p)) return BIGINT(c.conncomp); - map::const_iterator ri = c.reduct_array.find(p); + auto ri = c.reduct_array.find(p); if (ri == c.reduct_array.end()) return BIGINT(1); Reduction_type info = ri->second; @@ -362,9 +358,9 @@ bigint global_Tamagawa_exponent(CurveRed& c, int real_too) const bigint two = BIGINT(2); bigint ans = ((real_too && (c.conncomp==2))? two: one); - for(map::const_iterator ri = c.reduct_array.begin(); ri!=c.reduct_array.end(); ri++) + for( const auto& ri : c.reduct_array) { - Reduction_type info = ri->second; + Reduction_type info = ri.second; int code = info.Kcode.code; int ep = (code%20==1? 2: info.c_p); // Type I*m, m even: [2,2] ans = lcm(ans,BIGINT(ep)); @@ -377,8 +373,8 @@ vector tamagawa_primes(CurveRed& C, int real_too) { vector T = pdivs(global_Tamagawa_exponent(C, real_too)); vector t; - for(vector::const_iterator ti = T.begin(); ti!=T.end(); ++ti) - t.push_back(I2long(*ti)); + for( const auto& ti : T) + t.push_back(I2long(ti)); return t; } @@ -393,28 +389,28 @@ vector tamagawa_primes(CurveRed& C, int real_too) int getord_p_discr(const CurveRed& c, const bigint& p) { - map::const_iterator ri = c.reduct_array.find(p); + auto ri = c.reduct_array.find(p); if(ri==c.reduct_array.end()) return 0; return (ri->second).ord_p_discr; } int getord_p_N(const CurveRed& c, const bigint& p) { - map::const_iterator ri = c.reduct_array.find(p); + auto ri = c.reduct_array.find(p); if(ri==c.reduct_array.end()) return 0; return (ri->second).ord_p_N; } int getord_p_j_denom(const CurveRed& c, const bigint& p) { - map::const_iterator ri = c.reduct_array.find(p); + auto ri = c.reduct_array.find(p); if(ri==c.reduct_array.end()) return 0; return (ri->second).ord_p_j_denom; } int getc_p(const CurveRed& c, const bigint& p) { - map::const_iterator ri = c.reduct_array.find(p); + auto ri = c.reduct_array.find(p); if(ri==c.reduct_array.end()) return 1; return (ri->second).c_p; } @@ -422,11 +418,8 @@ int getc_p(const CurveRed& c, const bigint& p) bigint prodcp(const CurveRed& c) { bigint ans = BIGINT(1); - map::const_iterator ri; - for(ri = c.reduct_array.begin(); ri!=c.reduct_array.end(); ri++) - { - ans *= (ri->second).c_p; - } + for( const auto& ri : c.reduct_array) + ans *= (ri.second).c_p; return ans; } @@ -444,7 +437,7 @@ bigint global_Tamagawa_number(CurveRed& c, int real_too) Kodaira_code getKodaira_code(const CurveRed& c, const bigint& p) { - map::const_iterator ri = c.reduct_array.find(p); + auto ri = c.reduct_array.find(p); if(ri==c.reduct_array.end()) return Kodaira_code(); return (ri->second).Kcode; } @@ -474,12 +467,11 @@ void CurveRed::display(ostream& os) os << "Global Root Number = " << GlobalRootNumber(*this) << endl; os << "Reduction type at bad primes:\n"; os <<"p\tord(d)\tord(N)\tord(j)\tKodaira\tc_p\troot_number\n"; - map::const_iterator ri; - for(ri = reduct_array.begin(); ri!=reduct_array.end(); ri++) + for( const auto& ri : reduct_array) { - if((ri->second).local_root_number==0) - setLocalRootNumber(ri->first); - os << (ri->first) << "\t" << (ri->second) << endl; + if((ri.second).local_root_number==0) + setLocalRootNumber(ri.first); + os << (ri.first) << "\t" << (ri.second) << endl; } } @@ -503,9 +495,9 @@ void CurveRed::display(ostream& os) int LocalRootNumber(CurveRed& c, const bigint& p) { if(is_zero(p)) return -1; // the infinite prime - map::const_iterator ri = c.reduct_array.find(p); + auto ri = c.reduct_array.find(p); if(ri==c.reduct_array.end()) return 1; // good reduction case - if((ri->second).local_root_number==0) + if((ri->second).local_root_number==0) c.setLocalRootNumber(p); return (ri->second).local_root_number; } @@ -513,12 +505,11 @@ int LocalRootNumber(CurveRed& c, const bigint& p) int GlobalRootNumber(CurveRed& c) { int ans=-1; - map::const_iterator ri; - for(ri = c.reduct_array.begin(); ri!=c.reduct_array.end(); ri++) + for( const auto& ri : c.reduct_array) { - if((ri->second).local_root_number==0) - c.setLocalRootNumber(ri->first); - ans *= (ri->second).local_root_number; + if((ri.second).local_root_number==0) + c.setLocalRootNumber(ri.first); + ans *= (ri.second).local_root_number; } return ans; } @@ -537,7 +528,7 @@ int kro_3(long x); // kronecker(x,3) void CurveRed::setLocalRootNumber2() { static const bigint two = BIGINT(2); - map::iterator ri = reduct_array.find(two); + auto ri = reduct_array.find(two); if(ri==reduct_array.end()) return; Reduction_type& info = ri->second; int kod = PariKodairaCode(info.Kcode); @@ -734,7 +725,7 @@ void CurveRed::setLocalRootNumber2() void CurveRed::setLocalRootNumber3() { static const bigint three = BIGINT(3); - map::iterator ri = reduct_array.find(three); + auto ri = reduct_array.find(three); if(ri==reduct_array.end()) return; Reduction_type& info = ri->second; int kod = PariKodairaCode(info.Kcode); @@ -841,7 +832,7 @@ void CurveRed::setLocalRootNumber3() void CurveRed::setLocalRootNumber_not_2_or_3(const bigint& p) { - map::iterator ri = reduct_array.find(p); + auto ri = reduct_array.find(p); if(ri==reduct_array.end()) return; Reduction_type& info = ri->second; if (info.ord_p_N == 1) diff --git a/libsrc/curvesort.cc b/libsrc/curvesort.cc index 38fec8a..a8302fb 100644 --- a/libsrc/curvesort.cc +++ b/libsrc/curvesort.cc @@ -267,9 +267,8 @@ int booknumber(int level, int form) // permutes numbers starting from 1 int codeletter_to_int(string code) // i counts from 0! { int n=0; - string::iterator c; - for (c=code.begin(); c pdivs(long); /* list of prime divisors */ vector posdivs(long, const vector& plist); // all positive divisors inline vector posdivs(long n) { - const vector& plist = pdivs(n); - return posdivs(n,plist); + return posdivs(n, pdivs(n)); } vector alldivs(long, const vector& plist); // absolutely all divisors inline vector alldivs(long n) { - const vector& plist = pdivs(n); - return alldivs(n,plist); + return alldivs(n, pdivs(n)); } vector sqdivs(long, const vector& plist); // divisors whose square divides inline vector sqdivs(long n) { - const vector& plist = pdivs(n); - return sqdivs(n,plist); + return sqdivs(n, pdivs(n)); } vector sqfreedivs(long, const vector& plist); // square-free divisors inline vector sqfreedivs(long n) { - const vector& plist = pdivs(n); - return sqfreedivs(n,plist); + return sqfreedivs(n, pdivs(n)); } diff --git a/libsrc/elog.cc b/libsrc/elog.cc index 5a131ac..c652a9f 100644 --- a/libsrc/elog.cc +++ b/libsrc/elog.cc @@ -308,13 +308,11 @@ vector division_points_by2(Curvedata& E, const Point& P) cout<<"Possible x-coordinates:"< ans; - for(vector::const_iterator x=xans.begin(); x!=xans.end(); x++) + for( const auto & x : xans) { - vector x_points = points_from_x(E,*x); - for(vector::const_iterator Qi=x_points.begin(); - Qi!=x_points.end(); Qi++) + vector x_points = points_from_x(E,x); + for( const auto& Q : x_points) { - Point Q = *Qi; if(2*Q==P) // as it might = -P { #ifdef DEBUG_DIVBY2 diff --git a/libsrc/fixc6.cc b/libsrc/fixc6.cc index 95bd08c..1706b67 100644 --- a/libsrc/fixc6.cc +++ b/libsrc/fixc6.cc @@ -57,11 +57,11 @@ fixc6::fixc6() void fixc6::operator()(long N, int i, bigint& c4, bigint& c6) { pair key(N,i+1); - map,bigint>::const_iterator j = fixc6table.find(key); + auto j = fixc6table.find(key); if(j!=fixc6table.end()) c6=j->second; - j = fixc4table.find(key); + j = fixc4table.find(key); if(j!=fixc4table.end()) c4=j->second; - return; + return; } map< pair, bigint > fixc6::fixc6table; diff --git a/libsrc/gf.cc b/libsrc/gf.cc index ff4a530..7aa0920 100644 --- a/libsrc/gf.cc +++ b/libsrc/gf.cc @@ -26,17 +26,17 @@ map ZZ_pContextCache; galois_field::galois_field(void) //dummy - :q(to_ZZ(2)) + :q(to_ZZ(2)) { // cout<<"In galois_field constructor, calling default ZZ_p::init(2)"<& plist #ifdef DEBUG_HILBERT cout<<"Passed local condition at infinity..."<::const_iterator pr = plist.begin(); - while(pr!=plist.end()) + for (const auto& badp : plist) { - badp=*pr++; #ifdef DEBUG_HILBERT cout<<"Testing local condition at "<1) // Compute the number of cusps long maxncusps =0, dd, pp, nc; - vector::const_iterator d,p; - for(d=(dlist).begin();d!=(dlist).end();d++) + for( const auto& d : dlist) { - dd = *d; - nc = ::gcd(dd,modulus/dd); - for(p=plist.begin();p!=plist.end();p++) // computing phi(dd) + nc = ::gcd(dd,modulus/d); + for( const auto& p : plist) // computing phi(dd) { - pp = *p; - if ((nc%pp)==0) - nc = nc*(pp-1)/pp; + if ((nc%p)==0) + nc = nc*(p-1)/p; } maxncusps += nc; - } + } if (verbose) cout << "Number of cusps is "<0) ans[i] = v*coord_vecs[j]; diff --git a/libsrc/htconst.cc b/libsrc/htconst.cc index 5577ffb..2a5ea63 100644 --- a/libsrc/htconst.cc +++ b/libsrc/htconst.cc @@ -107,22 +107,21 @@ double cps_bound(const Curvedata& CD) #endif CurveRed CR(CD); vector plist = getbad_primes((Curvedata&)CD); - for(unsigned int i=0; i=rts[0]); - else - ans = ((x>=rts[0]) && (x<=rts[1])) || (x>=rts[2]); + else + ans = ((x>=rts[0]) && (x<=rts[1])) || (x>=rts[2]); if(debug) cout<<"\t returns "< rts, int debug) vector reals_in_interval ( vector& v, const vector rts) { vector vr; - vector::iterator vi = v.begin(); bigfloat x; - while(vi!=v.end()) - { - if(is_real(*vi)) - { - x=(*vi).real(); - if(interval_test(x,rts,1)) vr.push_back(x); - } - vi++; - } + for( const auto& vi : v) + if(is_real(vi)) + { + bigfloat x=vi.real(); + if(interval_test(x,rts,1)) + vr.push_back(x); + } return vr; } @@ -1083,15 +1065,13 @@ vector reals_in_interval ( vector& v, const vector& S, const vector& C) { bigfloat x; - vector::const_iterator Ci = C.begin(); - while(Ci!=C.end()) + for (const auto& Ci : C) { - if(is_real(*Ci)) + if(is_real(Ci)) { - x = (*Ci).real(); + x = Ci.real(); if((x<=1)&&(x>=-1)) S.insert(x); } - Ci++; } } @@ -1423,12 +1403,12 @@ void Interval::intersect(const Interval& I) vector intersect(const vector& L1, const vector& L2) { vector ans; - vector::const_iterator I, J; - for(I=L1.begin(); I!=L1.end(); I++) - for(J=L2.begin(); J!=L2.end(); J++) + for( const auto& I : L1) + for( const auto& J : L2) { - Interval K = intersect(*I,*J); - if(!K.is_empty()) ans.push_back(K); + Interval K = intersect(I,J); + if(!K.is_empty()) + ans.push_back(K); } return ans; } @@ -1459,15 +1439,14 @@ void Interval01::intersect(const Interval01& I) empty=(lh>rh); } -vector intersect(const vector& L1, +vector intersect(const vector& L1, const vector& L2) { vector ans; - vector::const_iterator I, J; - for(I=L1.begin(); I!=L1.end(); I++) - for(J=L2.begin(); J!=L2.end(); J++) + for( const auto& I : L1) + for( const auto& J : L2) { - Interval01 K = intersect(*I,*J); + Interval01 K = intersect(I,J); if(!K.is_empty()) ans.push_back(K); } return ans; @@ -1554,11 +1533,9 @@ CurveHeightConst::CurveHeightConst(CurveRed& CR) long CurveHeightConst::e_p(long p) { - map::iterator pe = ann.find(p); + auto pe = ann.find(p); if (pe!=ann.end()) - { - return pe->second; - } + return pe->second; long e = exponent(*this,p); ann[p] = e; return e; @@ -1566,7 +1543,7 @@ long CurveHeightConst::e_p(long p) bigfloat CurveHeightConst::D(long n) // D_E(n) in the paper { - map::iterator DEn = DE.find(n); + auto DEn = DE.find(n); if (DEn!=DE.end()) { #ifdef debugLB @@ -1832,12 +1809,12 @@ vector CurveHeightConst::solveLEQ(long n, const bigfloat& B) ans.push_back(Interval(e3,xlist[0])); for(int i=1; i CurveHeightConst::solveLEQ(long n, const bigfloat& B) vector CurveHeightConst::solveGEQ(long n, const bigfloat& B) { vector ans; - if(B <= e3) + if(B <= e3) { ans.push_back(Interval(e3)); // i.e.[e3,infty] return ans; @@ -1858,14 +1835,14 @@ vector CurveHeightConst::solveGEQ(long n, const bigfloat& B) for(i=1; i plist = getbad_primes(CR); - vector::iterator pvar = plist.begin(); - while(pvar!=plist.end()) - if(getord_p_N(CR,*pvar++)>1) return 0; + for (const auto& p : plist) + if(getord_p_N(CR,p)>1) return 0; return ans; } @@ -271,33 +270,29 @@ void IsogenyClass::process(long i) // process i'th curve CurveRed thisc = curves[i]; if (verb) cout << "Working on curve " << i+1 << ": " << (Curve)thisc << endl; Cperiods pers(thisc); - vector::iterator lvar=llist.begin(); - long il=0, ell, n; - while(lvar!=llist.end()) + long il=0, n; + for (const auto& ell : llist) { - ell = *lvar++; if (verb) cout << "trying l = " << ell << "..." << flush; vector lisogcurves = lisog(thisc,pers,ell,verb); if (verb) cout << lisogcurves.size() << " isogenous curves found." << endl; - if(i==0) + if(i==0) { // cout<<"setting lworks["<::iterator oldCi=curves.begin(); - while(oldCi!=curves.end()) - { - if ((Curve)newc==(Curve)(*oldCi++)) + for (const auto& oldCi : curves) + { + if ((Curve)newc==(Curve)(oldCi)) { isnew=0; matset(i,j,ell); @@ -305,7 +300,7 @@ void IsogenyClass::process(long i) // process i'th curve } j++; } - if (isnew) + if (isnew) { curves.push_back(newc); fromlist.push_back(i); @@ -351,12 +346,14 @@ void IsogenyClass::displaycurves(ostream& os)const { os << endl << ncurves << " curve(s) in the isogeny class"<0) os << " is "<< isoglist[i]<<"-isogenous to curve "<1) + os << " is "<< isoglist[i-1]<<"-isogenous to curve "<::const_iterator pi; - pi=C.the_bad_primes.begin(); + auto pi=C.the_bad_primes.begin(); while(pi!=C.the_bad_primes.end()) os << C.reduct_array[*pi++].ord_p_discr << sep; pi=C.the_bad_primes.begin(); while(pi!=C.the_bad_primes.end()) os << C.reduct_array[*pi++].ord_p_j_denom << sep; diff --git a/libsrc/lambda.cc b/libsrc/lambda.cc index a2ba6a1..2751fbb 100644 --- a/libsrc/lambda.cc +++ b/libsrc/lambda.cc @@ -80,10 +80,8 @@ vector lambda_bad(const CurveRed& C, long& nlambda, int verbose) bigint discr = getdiscr(C); vector plist = getbad_primes(C); long i, j, nl, nnl; - vector::const_iterator pr=plist.begin(); - while(pr!=plist.end()) + for (const auto& p : plist) { - bigint p = *pr++; if (ndiv(p*p,discr)) { if(verbose) @@ -167,10 +165,9 @@ int make_point_from_x(Curvedata* CD, const bigfloat& x, long maxdd, Point* P) int make_point_from_x_and_ht(Curvedata* CD, vector lambdas, const bigfloat& xp, const bigfloat& ht, Point* P) { bigfloat rh = realheight(xp,CD); - vector::const_iterator lam = lambdas.begin(); - while(lam!=lambdas.end()) + for (const auto& lam : lambdas) { - bigfloat logd = (ht-rh-(*lam++))/2; + bigfloat logd = (ht-rh-(lam))/2; bigfloat approxd = exp(logd); bigint xa, xd2, xd = Iround(approxd); if(xd>0) diff --git a/libsrc/marith.cc b/libsrc/marith.cc index 7724391..6fe544f 100644 --- a/libsrc/marith.cc +++ b/libsrc/marith.cc @@ -241,17 +241,16 @@ int sqrt_mod_m(bigint& x, const bigint& a, const bigint& m, const vector bigint mm, p, xp, q; int e; x=0; mm=1; - for(vector::const_iterator pr = mpdivs.begin(); pr!=mpdivs.end(); pr++) + for( const auto& p : mpdivs) { - p=*pr; e = val(p,m); if(e==0) continue; - if(p==2) + if(p==2) {if(!sqrt_mod_2_power(xp,a,e)) return 0;} else {if(!sqrt_mod_p_power(xp,a,p,e)) return 0;} q=pow(p,e); - if(pr==mpdivs.begin()) + if(p==mpdivs.front()) x=xp; else x=chrem(x,xp,mm,q); @@ -270,10 +269,9 @@ int modsqrt(const bigint& a, const vector& bplist, bigint& x) { // Assumes b square-free, primes factors in bplist bigint u, v, p, amodp, xmodp, m; - int res=1; x=0; m=1; - for(vector::const_iterator pr = bplist.begin(); res&&(pr!=bplist.end()); pr++) + x=0; m=1; + for( const auto& p : bplist) { - p=*pr; if(p==2) { xmodp=odd(a); @@ -362,11 +360,10 @@ vector pdivs_use_factorbase(bigint& n, const std::set factor_bas { vector plist; if(n<2) return plist; - std::set::const_iterator pri = factor_base.begin(); - while((n>1)&&(pri!=factor_base.end())) + for (const auto& p : factor_base) { - bigint p=*pri++; - if(divide_out(n,p)) + if (n==1) break; + if(divide_out(n,p)) plist.push_back(p); } return plist; @@ -466,9 +463,8 @@ factor(const bigint& n, int proof=1) oss< plist = read_vec_from_string(factor(oss.str())); if(proof) - for(vector::const_iterator pi=plist.begin(); pi!=plist.end(); pi++) + for( const auto& p : plist) { - bigint p =*pi; if(!is_prime(p)) { cout<<"WARNING: pari's factor() returned p="<

posdivs(const bigint& number, const vector& plist) int e, nu = 1; int nd=nu; vector elist; elist.reserve(np); - vector::const_iterator pr = plist.begin(); - while(pr!=plist.end()) + for (const auto& p : plist) { - e=val(*pr++,number); + e=val(p,number); elist.push_back(e); nd*=(1+e); } @@ -562,12 +557,10 @@ vector posdivs(const bigint& number, const vector& plist) // cout<<"In posdivs (1) : dlist = "<getdisc()<<":\n"; // cout << dlist << endl; } - bigint d; - vector::const_iterator dvar; - for (dvar=dlist.begin(); dvar!=dlist.end() && (!ans); dvar++) + for ( const auto& d : dlist) { - d = *dvar; bigfloat rscale = sqrt(abs(I2bigfloat(d)/det)); bigfloat rscaler = floor(rscale+0.5); if(abs(rscale-rscaler)<0.001) @@ -275,16 +220,17 @@ int rootsequiv(const quartic* q1, const quartic* q2, int i, const vector cout<<"rscale = "<geta(),q1->getb(),q1->getcc(),q1->getd(),q1->gete(), + if (testd(q1->geta(),q1->getb(),q1->getcc(),q1->getd(),q1->gete(), q2->geta(),q2->getb(),q2->getcc(),q2->getd(),q2->gete(), - d,al,be,ga,de,info); + d,al,be,ga,de,info)) + return 1; } } } - return ans ; + return 0; } // of rootsequiv() - - + + int equiv(const quartic* q1, const quartic* q2, const vector& dlist, int info) { bigint iiq1 = q1->getI(), jjq1 = q1->getJ(), discq1 = q1->getdisc(); @@ -307,8 +253,8 @@ int equiv(const quartic* q1, const quartic* q2, const vector& dlist, int if(info) {if(!ans) cout << "Not "; cout<<"equiv\n";} return ans; } - else - { + else + { if (info) {cout << "equiv failed on first test!\n"; cout << "First has I="<& v, const vector& w, int old=0); int less_apvec(const vector& v, const vector& w, int old) { - vector::const_iterator vi=v.begin(), wi=w.begin(); - while(vi!=v.end()) + auto wi=w.begin(); + for ( const auto& vi : v) { - int s = less_ap(*vi++,*wi++,old); + int s = less_ap(vi,*wi++,old); if(s) return s; } return 0; @@ -94,25 +94,24 @@ vector eiglist(const newform& f, int oldorder) vector eigs; primevar pr; long N = (f.nf)->modulus; - vector::const_iterator aqi=f.aqlist.begin(); - vector::const_iterator api=f.aplist.begin(); - vector::iterator eigsi; + auto aqi=f.aqlist.begin(); + auto api=f.aplist.begin(); if(oldorder) { eigs.resize(f.aplist.size()); - eigsi=eigs.begin(); - while(aqi!=f.aqlist.end()) + auto eigsi=eigs.begin(); + while(aqi!=f.aqlist.end()) *eigsi++ = *aqi++; while(api!=f.aplist.end()) { - if(ndivides(pr,N)) *eigsi++ = *api; + if(ndivides(pr,N)) *eigsi++ = *api; api++; pr++; } } else { eigs=f.aplist; // copy; now adjust the aq: - eigsi=eigs.begin(); + auto eigsi=eigs.begin(); while((aqi!=f.aqlist.end())&&(eigsi!=eigs.end())) { if(::divides(pr.value(),N)) *eigsi = (*aqi++); @@ -254,16 +253,17 @@ void newform::fixup_eigs() { long denom = nf->h1->h1denom(); aqlist.resize(nf->npdivs); - vector::iterator api=aplist.begin(), pi=nf->plist.begin(); - vector::iterator aqi=aqlist.begin(); + auto api=aplist.begin(); + auto pi=nf->plist.begin(); + auto aqi=aqlist.begin(); primevar pr; long q, i; long n = nf->modulus; while((api!=aplist.end())&&(aqi!=aqlist.end())) { q=pr.value(); pr++; - if(::divides(q,n)) + if(::divides(q,n)) { - *aqi++=*api; + *aqi++=*api; *api=(::divides(q*q,n)? 0: -*api); pi++; } @@ -274,9 +274,9 @@ void newform::fixup_eigs() long piv; ssubspace espace; if(sign==-1) - espace=make1d(bminus,piv); + espace=make1d(bminus,piv); else - espace=make1d(bplus,piv); + espace=make1d(bplus,piv); piv*=denom; while(aqi!=aqlist.end()) // compute missing aq { @@ -289,7 +289,7 @@ void newform::fixup_eigs() } } if(nf->verbose) cout<<"aqlist = "<::iterator api=aplist.begin(); - vector::iterator aqi=aqlist.begin(); +{ + auto api=aplist.begin(); + auto aqi=aqlist.begin(); primevar pr; long n = nf->modulus; while((api!=aplist.end())&&(aqi!=aqlist.end())) { - if(::divides(pr.value(),n)) *api=*aqi++; + if(::divides(pr.value(),n)) *api=*aqi++; api++; pr++; } @@ -315,14 +315,14 @@ void newform::unfix_eigs() // After recovering eigenbases, we need to replace the ap for bad p void newform::refix_eigs() -{ - vector::iterator api=aplist.begin(); +{ + auto api=aplist.begin(); primevar pr; long n = nf->modulus, np = nf->npdivs, ip=0, q; while((api!=aplist.end())&&(ip::const_iterator api=aplist.begin(); + primevar pr; + auto api = aplist.begin(); while(pr.value()!=nf->p0) {pr++; api++;} ap0=*api; np0 = 1 + (nf->p0) - ap0; @@ -364,13 +364,13 @@ void newform::find_bsd_ratio() if(denomplus>1) { if(::divides(denomplus,dp0)) dp0/=denomplus; - else + else cout<<"newform constructor error: dp0 not divisible by denomplus!" - <verbose) + loverp = rational(dp0,np0); + if(nf->verbose) { cout<<"pdot = "<::const_iterator vi = nf->mvlplusvecs.find(l); + auto vi = nf->mvlplusvecs.find(l); if(vi==nf->mvlplusvecs.end()) mplus = (nf->mvlplusvecs[l]=nf->h1->manintwist(l))*bplus; else @@ -535,16 +535,16 @@ void newform::find_twisting_primes() if((denomplus>1)&&(mplus!=0)) { if(::divides(denomplus,mplus)) mplus/=denomplus; - else + else cout<<"Warning in newform constructor: mplus not divisible by denomplus!" - <::const_iterator vi = nf->mvlminusvecs.find(l); + auto vi = nf->mvlminusvecs.find(l); if(vi==nf->mvlminusvecs.end()) mminus = (nf->mvlminusvecs[l]=nf->h1->manintwist(l))*bminus; else @@ -1550,7 +1550,7 @@ vector aqlist(vector aplist, long N) { long iq=0, p, naq = pdivs(N).size(); //cout << "Setting aq of size "<::const_iterator api = aplist.begin(); + auto api = aplist.begin(); vector aq(naq); for(primevar pr; (iq newforms::apvec(long p) // computes a[p] for each newform //cout<<"Computing images of M-symbols"< newforms::showcurves(vector forms, int verbose, string filename bigfloat rperiod; bigint a1,a2,a3,a4,a6, N; vector badcurves; // will hold the indices of forms for which we fail to find a curve - vector::const_iterator inf; // will iterate through the forms to be used - for(inf=forms.begin(); inf!=forms.end(); inf++) + for( const auto& inf : forms) { if(verbose) - cout<<"\n"<<"Form number "<<*inf+1<<"\n"; - else cout<<(*inf+1)<<" "; + cout<<"\n"<<"Form number "< newforms::showcurves(vector forms, int verbose, string filename if(N!=modulus) { cout<<"No curve found"< newforms::showcurves(vector forms, int verbose, string filename C.getai(a1,a2,a3,a4,a6); curve_out<<"["<::const_iterator d; - for(d=(N->dlist).begin();d!=(N->dlist).end();d++) + for (const auto& M : N->dlist) { - long M=*d; if(M<11) continue; if(M==(N->modulus)) continue; getoldclasses(M,verbose); @@ -170,36 +168,32 @@ void oldforms::getoldclasses(long d, int verbose) long m = n/d; long k=0, xmult, mult, j, beta; vector betalist; // =new long[N->npdivs]; - vector::const_iterator qj=(N->plist).begin(); - while(qj!=(N->plist).end()) + for (const auto& qj : N->plist) { - beta=val(*qj++,m); + beta=val(qj,m); if(beta>0) k++; betalist.push_back(beta); } if(verbose>1) cout<<"betas: "< nextoldformap(nap); - vector::iterator betai; - vector::const_iterator aqj; primevar pr; long iform, c, ip, p, aq; int bit; for(iform=0; iform& aqlist=olddata.nflist[iform].aqlist; nextoldformap = olddata.nflist[iform].aplist; - if(verbose>1) + if(verbose>1) { cout<<"form #"<<(iform+1)<<": "<<"aqlist="< resort_aplist(const level* iN, long i, j, p, ip = iN->npdivs; for(i=0; i::const_iterator pi = find(iN->plist.begin(),iN->plist.end(),p); + auto pi = find(iN->plist.begin(),iN->plist.end(),p); if(pi==iN->plist.end()) // then p is good { aplist.push_back( apl[ip++]); @@ -180,9 +180,9 @@ void summer::use2357(long n, long an) { am2357=am235*a7p_cache[i7]; use(m2357,am2357); - } - } - } + } + } + } } } diff --git a/libsrc/points.cc b/libsrc/points.cc index 5398cc0..967ff46 100644 --- a/libsrc/points.cc +++ b/libsrc/points.cc @@ -246,27 +246,13 @@ int Point::isvalid() const // P on its curve ? if((sign(X)==0)&&(sign(Y)==0)&&(sign(Z)==0)) return 0; // Point at infinity is on a curve if((sign(X)==0)&&(sign(Z)==0)) return 1 ; - else{ - // should calculate - // y^2 +a1 x y + a3 y - // and - // x^3 + a2 x^2 + a4 x + a6 - // where - // x = X/Z, y = Y/Z - // and verify equality. - // - // In homogeneous coordinates: - // - // Lhs = Y^2 Z + a1 XYZ + a3 YZ^2 = (YZ) *(Y + a1 X + a3 Z) - // - // - // Rhs = X^3 +a2 X^2 Z + a4 X Z^2 + a6 Z^3 - // - bigint A1,A2,A3,A4,A6; E->getai(A1,A2,A3,A4,A6); - const bigint& Lhs = Y*Z*(Y + A1*X + A3*Z) ; - const bigint& Rhs = A6*pow(Z,3) + X*(A4*Z*Z + X*(A2*Z + X)) ; - return Lhs == Rhs ; - } + else + { + bigint A1,A2,A3,A4,A6; E->getai(A1,A2,A3,A4,A6); + const bigint& Lhs = Y*Z*(Y + A1*X + A3*Z) ; + const bigint& Rhs = A6*pow(Z,3) + X*(A4*Z*Z + X*(A2*Z + X)) ; + return Lhs == Rhs ; + } } // Find all points with a given rational x-coordinate: @@ -387,17 +373,11 @@ vector two_torsion(Curvedata& E, int exact) b2=a2; b4=a4; b6=a6; } vector xlist = Introotscubic(b2,b4,b6); - int n, n2tors = xlist.size(); - - // If there are 3 points of order 2, we order them for consistency: - if(n2tors==3) sort(xlist.begin(),xlist.end()); - vector two_tors; if (!exact) two_tors.push_back(Point(E)) ; // zero point - for(n=0; n three_torsion(Curvedata& E, int exact) vector three_tors; if (!exact) three_tors.push_back(Point(E)) ; // zero point - for(unsigned int n=0; n m_torsion(Curvedata& E, long m, int exact) #endif // accumulate the points with each x-coorindate: - for(auto xi = xs.begin(); xi!=xs.end(); ++xi) + for( const auto& xi : xs) { - vector Ps = points_from_x(E, *xi); + vector Ps = points_from_x(E, xi); #ifdef DEBUG_TORSION - cout<<" x = "<<(*xi)<< " gives points "< torsion_points(Curvedata& E) // Now we have structure C2xCn for n = 4, 6, or 8 // Find a point of order 2 not in the second factor and add it in - Point T1 = cycle[exponent/2], T2 = two_tors[0]; - for( auto Ti=two_tors.begin()+1; Ti!=two_tors.end(); ++Ti) - { - T2 = *Ti; - if (T2 != T1) - break; - } + Point T1 = cycle[exponent/2]; + auto Ti = std::find_if_not(two_tors.begin()+1, two_tors.end(), [T1]( const auto& T ){return T==T1;}); + Point T2 = *Ti; vector all_torsion = cycle; - for( auto Pi=cycle.begin(); Pi!=cycle.end(); ++Pi) - { - all_torsion.push_back(T2+*Pi); - } + for( auto P : cycle) + all_torsion.push_back(T2+P); + ::sort(all_torsion.begin(), all_torsion.end(), Point_cmp); return all_torsion; } @@ -616,16 +589,14 @@ vector Point::division_points(int m) // list of Q s.t. n*Q=this #endif vector ans; vector Qs; - Point Q; if (is_torsion()) { Qs = torsion_points(*E); #ifdef DEBUG_DIVISION_POINTS cout << "Testing all torsion points " << Qs << endl; #endif - for (vector::iterator Qi = Qs.begin(); Qi!=Qs.end(); Qi++) + for ( const auto& Q : Qs) { - Q = *Qi; #ifdef DEBUG_DIVISION_POINTS cout << " Q = "<::iterator xQi = xQs.begin(); xQi!=xQs.end(); xQi++) + for( const auto& xQ : xQs) { - Qs = points_from_x(*E, *xQi); + Qs = points_from_x(*E, xQ); // will have length 0 or 2 since non-torsion, and we only want // exctly one when there two so, must check which works if (Qs.size()>0) { - Q = Qs[0]; + Point Q = Qs[0]; if (m*Q == *this) { ans.push_back(Q); @@ -738,11 +711,11 @@ int Point::has_good_reduction(const vector& plist, bigint& p0, int check p0 = BIGINT(0); return 0; } - for(vector::const_iterator pi = plist.begin(); pi!=plist.end(); ++pi) + for( const auto& p : plist) { - if(!has_good_reduction(*pi)) + if(!has_good_reduction(p)) { - p0 = *pi; + p0 = p; return 0; } } diff --git a/libsrc/pointsmod.cc b/libsrc/pointsmod.cc index 6ca5d51..a46de34 100644 --- a/libsrc/pointsmod.cc +++ b/libsrc/pointsmod.cc @@ -558,7 +558,7 @@ bigint my_bg_algorithm(const pointmodq& PP, // look in table to see if H2= i*P for a suitable i - map::iterator HTi = HT.find(LiftGF(H2.get_x())); + auto HTi = HT.find(LiftGF(H2.get_x())); if(HTi!=HT.end()) { i = HTi->second; @@ -580,12 +580,11 @@ bigint my_bg_algorithm(const pointmodq& PP, bigint my_order_point(const pointmodq& P, const bigint& mult) { vector plist = pdivs(mult); - unsigned int i; bigint m, p, ans = BIGINT(1); + bigint ans = BIGINT(1); if(P.is_zero()) return ans; - for(i=0; i introots(const ZPoly& f) vector ans; if (ratroots.size()==0) return ans; - for(vector::iterator ri=ratroots.begin(); ri!=ratroots.end(); ri++) - { - bigrational r = *ri; - if (den(r)==1) - ans.push_back(num(r)); - } + for( const auto& r : ratroots) + if (den(r)==1) + ans.push_back(num(r)); sort(ans.begin(), ans.end()); return ans; } diff --git a/libsrc/saturate.cc b/libsrc/saturate.cc index 7e60a01..a83ca5a 100644 --- a/libsrc/saturate.cc +++ b/libsrc/saturate.cc @@ -136,27 +136,13 @@ void saturator::nextq() // First just check the order of E mod q, skip this q if not a multiple of p - map::iterator Eqoi = Emodq_order.find(q); bigint order_mod_q; + auto Eqoi = Emodq_order.find(q); if(Eqoi==Emodq_order.end()) { if(verbose>2) cout<<"Computing order mod q = "<2) - cout<<"q="<2) cout<<"Setting order mod "<::iterator Eqi = Emodq.find(q); + auto Eqi = Emodq.find(q); if(Eqi==Emodq.end()) { if(verbose>2) cout<<"Initializing q = "<& unsat, long& index, { if (verbose) cout << "Tamagawa index primes are " << tam_primes << endl; - for (vector::iterator pi = tam_primes.begin(); pi!=tam_primes.end(); pi++) + for ( const auto& p : tam_primes) { - p = *pi; if ((p > ib) && ((sat_bd==-1) || (p <= sat_bd))) { if (verbose) @@ -513,22 +498,14 @@ int saturator::saturate(vector& unsat, long& index, void saturator::show_q_tally() { cout << "Summary of auxiliary primes used" <::iterator qcount; cout << "Number of q used: " << q_tally.size() << endl; cout << "Maximum q used: " << maxq << " (used for p="<first; - c = qcount->second; - if (c) - cout << q << "\t" << c <& Plist) { - vector::const_iterator P=Plist.begin(); - while(P!=Plist.end()) + for ( const auto& P : Plist) { - if(verbose) cout<<"Processing point "<<*P<::const_iterator vi=v.entries.begin(); - vi!=v.entries.end(); vi++) + for( const auto& vi : v.entries) { - *coli++ = vi->first; - *vali++ = vi->second; + *coli++ = vi.first; + *vali++ = vi.second; } // check @@ -580,56 +579,34 @@ vec operator* (smat& m, const vec& v) svec operator* ( const svec& v, const smat& A ) { svec prod(A.ncols()); - if( v.d != A.nrows() ) - { - cerr << "incompatible sizes in v*A\n"; - cerr << "Dimensions "<::const_iterator vi; - for(vi=v.entries.begin(); vi!=v.entries.end(); vi++) - prod += (vi->second)*(A.row(vi->first)); - } - return prod; -} - -#if(0) -svec mult_mod_p( const svec& v, const smat& A, const scalar& p ) -{ - svec prod(A.ncols()); - if( v.d != A.nrows() ) - { - cerr << "incompatible sizes in v*A\n"; - cerr << "Dimensions "<::const_iterator vi; - for(vi=v.entries.begin(); vi!=v.entries.end(); vi++) - prod.add_scalar_times_mod_p(A.row(vi->first), vi->second,p); + for( const auto& vi : v.entries) + prod += (vi.second)*(A.row(vi.first)); } return prod; } -#else - svec mult_mod_p( const svec& v, const smat& A, const scalar& p ) { vec prod(A.ncols()); if( v.d != A.nrows() ) { - cerr << "incompatible sizes in v*A\n"; - cerr << "Dimensions "<::const_iterator vi; - for(vi=v.entries.begin(); vi!=v.entries.end(); vi++) + for( const auto& vi : v.entries) { // prod.add_scalar_times_mod_p(A.row(vi->first), vi->second,p); - int i = (vi->first)-1; // the row of A to use (from 0) - scalar c = vi->second; // the coefficient tomultiply it by + int i = (vi.first)-1; // the row of A to use (from 0) + scalar c = vi.second; // the coefficient to multiply it by int d = A.col[i][0]; // #nonzero entries in this row int *posi = A.col[i] +1; // pointer to array of columns scalar *values = A.val[i]; // pointer to array of values @@ -639,7 +616,7 @@ svec mult_mod_p( const svec& v, const smat& A, const scalar& p ) } return svec(prod); } -#endif + svec mult_mod_p( const smat& A, const svec& v, const scalar& p ) { diff --git a/libsrc/smat_elim.cc b/libsrc/smat_elim.cc index df65b7b..b7a3575 100644 --- a/libsrc/smat_elim.cc +++ b/libsrc/smat_elim.cc @@ -1273,17 +1273,14 @@ void smat_elim::step5dense() return; } mat dmat(nrr, nrc); - map::const_iterator vi; - vector::const_iterator rci; for (i=0; ifirst)) j++; - dmat.set(i+1,j+1,vi->second); + while (remaining_cols[j]<(vi.first)) j++; + dmat.set(i+1,j+1,vi.second); } } diff --git a/libsrc/svec.cc b/libsrc/svec.cc index a38029b..e68c3c1 100644 --- a/libsrc/svec.cc +++ b/libsrc/svec.cc @@ -45,56 +45,47 @@ svec::svec (int dim, scalar* a) // conversion constructor vec svec::as_vec( ) const { vec v(d); // initializes to 0 - for(map::const_iterator wi=entries.begin(); - wi!=entries.end(); wi++) - v[wi->first] = wi->second; + for (const auto& wi : entries) + v[wi.first] = wi.second; return v; } scalar svec::elem(int i) const // returns i'th entry { - map::const_iterator vi = entries.find(i); + auto vi = entries.find(i); if(vi==entries.end()) return 0; return vi->second; } -void svec::set(int i, scalar a) +void svec::set(int i, scalar a) { if(a) entries[i]=a; -#if(0) // - else // a==0 so kill the i'entry if it is there - { - map::iterator vi = entries.find(i); - if(vi!=entries.end()) entries.erase(vi); - } -#endif } void svec::erase(int i) { - map::iterator vi = entries.find(i); - if(vi==entries.end()) + auto vi = entries.find(i); + if(vi==entries.end()) { cerr<<"Error in svec::erase(): cannot delete missing entry #"<::const_iterator wi=w.entries.begin(); - map::iterator vi=entries.begin(); + auto wi=w.entries.begin(); + auto vi=entries.begin(); while(wi!=w.entries.end()) { if(vi==entries.end()) @@ -164,17 +155,17 @@ svec& svec::operator+=(const svec& w) { entries[wi->first]=wi->second; wi++; - } + } } else { - if((vi->first)<(wi->first)) {vi++;} + if((vi->first)<(wi->first)) {vi++;} else - if((wi->first)<(vi->first)) + if((wi->first)<(vi->first)) { entries[wi->first]=wi->second; wi++; - } + } else { scalar sum = (vi->second) + (wi->second); @@ -194,8 +185,8 @@ svec& svec::operator-=(const svec& w) cerr << "Incompatible svecs in svec::operator-=()"<::const_iterator wi=w.entries.begin(); - map::iterator vi=entries.begin(); + auto wi=w.entries.begin(); + auto vi=entries.begin(); while(wi!=w.entries.end()) { if(vi==entries.end()) @@ -204,17 +195,17 @@ svec& svec::operator-=(const svec& w) { entries[wi->first]=-wi->second; wi++; - } + } } else { - if((vi->first)<(wi->first)) {vi++;} + if((vi->first)<(wi->first)) {vi++;} else - if((wi->first)<(vi->first)) + if((wi->first)<(vi->first)) { entries[wi->first]=-wi->second; wi++; - } + } else { scalar diff = (vi->second) - (wi->second); @@ -235,8 +226,8 @@ svec& svec::add_scalar_times(const svec& w, scalar a) return *this; } if(a==0) return *this; - map::const_iterator wi=w.entries.begin(); - map::iterator vi=entries.begin(); + auto wi=w.entries.begin(); + auto vi=entries.begin(); while(wi!=w.entries.end()) { if(vi==entries.end()) @@ -245,17 +236,17 @@ svec& svec::add_scalar_times(const svec& w, scalar a) { entries[wi->first]=a*(wi->second); wi++; - } + } } else { - if((vi->first)<(wi->first)) {vi++;} + if((vi->first)<(wi->first)) {vi++;} else - if((wi->first)<(vi->first)) + if((wi->first)<(vi->first)) { entries[wi->first]=a*(wi->second); wi++; - } + } else { scalar sum = (vi->second) + a* (wi->second); @@ -271,21 +262,27 @@ svec& svec::add_scalar_times(const svec& w, scalar a) svec& svec::operator*=(scalar scal) { // if(scal==0) cout<<"Attempt to multiply svec by 0\n"<::iterator vi=entries.begin(); - vi != entries.end(); vi++) - (vi->second)*=scal; + for ( auto& vi : entries) + (vi.second)*=scal; return *this; } void svec::reduce_mod_p(const scalar& p) { scalar a; - map::iterator vi, vi2; - for( vi=entries.begin(); vi != entries.end(); ) + auto vi = entries.begin(); + while( vi != entries.end() ) { a = mod(vi->second,p); - if(a) {(vi->second)=a; vi++;} - else {vi2=vi; vi++; entries.erase(vi2->first);} + if(a) + { + (vi->second)=a; + vi++; + } + else + { + vi = entries.erase(vi); + } } } @@ -293,9 +290,8 @@ svec& svec::mult_by_scalar_mod_p(scalar scal, const scalar& p) { // if(xmod(scal,p)==0) cout<<"Attempt to multiply svec by 0\n"<::iterator vi=entries.begin(); - vi != entries.end(); vi++) - (vi->second)=xmodmul(vi->second,scal,p); + for( auto& vi : entries) + (vi.second)=xmodmul(vi.second,scal,p); return *this; } @@ -307,8 +303,8 @@ svec& svec::add_scalar_times_mod_p(const svec& w, scalar a, const scalar& p) return *this; } if(a==0) return *this; - map::const_iterator wi=w.entries.begin(); - map::iterator vi=entries.begin(); + auto wi=w.entries.begin(); + auto vi=entries.begin(); while(wi!=w.entries.end()) { if(vi==entries.end()) @@ -317,17 +313,17 @@ svec& svec::add_scalar_times_mod_p(const svec& w, scalar a, const scalar& p) { entries[wi->first]=xmodmul(a,(wi->second),p); wi++; - } + } } else { - if((vi->first)<(wi->first)) {vi++;} + if((vi->first)<(wi->first)) {vi++;} else - if((wi->first)<(vi->first)) + if((wi->first)<(vi->first)) { entries[wi->first]=xmodmul(a,(wi->second),p); wi++; - } + } else { scalar sum = xmod((vi->second) + xmodmul(a, (wi->second),p),p); @@ -352,8 +348,8 @@ svec& svec::add_scalar_times_mod_p(const svec& w, scalar a, std::set& ons, return *this; } if(a==0) return *this; - map::const_iterator wi=w.entries.begin(); - map::iterator vi=entries.begin(); + auto wi=w.entries.begin(); + auto vi=entries.begin(); while(wi!=w.entries.end()) { if(vi==entries.end()) @@ -363,18 +359,18 @@ svec& svec::add_scalar_times_mod_p(const svec& w, scalar a, std::set& ons, entries[wi->first]=xmodmul(a,(wi->second),p); ons.insert(wi->first); wi++; - } + } } else { - if((vi->first)<(wi->first)) {vi++;} + if((vi->first)<(wi->first)) {vi++;} else - if((wi->first)<(vi->first)) + if((wi->first)<(vi->first)) { entries[wi->first]=xmodmul(a,(wi->second),p); ons.insert(wi->first); wi++; - } + } else { scalar sum = xmod((vi->second) + xmodmul(a, (wi->second),p),p); @@ -395,8 +391,8 @@ svec& svec::add_mod_p(const svec& w, const scalar& p) cerr << "Incompatible svecs in svec::add_scalar_times()"<::const_iterator wi=w.entries.begin(); - map::iterator vi=entries.begin(); + auto wi=w.entries.begin(); + auto vi=entries.begin(); while(wi!=w.entries.end()) { if(vi==entries.end()) @@ -405,7 +401,7 @@ svec& svec::add_mod_p(const svec& w, const scalar& p) { entries[wi->first]=wi->second; wi++; - } + } } else { @@ -435,8 +431,8 @@ svec& svec::sub_mod_p(const svec& w, const scalar& p) cerr << "Incompatible svecs in svec::add_scalar_times()"<::const_iterator wi=w.entries.begin(); - map::iterator vi=entries.begin(); + auto wi=w.entries.begin(); + auto vi=entries.begin(); while(wi!=w.entries.end()) { if(vi==entries.end()) @@ -445,17 +441,17 @@ svec& svec::sub_mod_p(const svec& w, const scalar& p) { entries[wi->first]=-(wi->second); wi++; - } + } } else { - if((vi->first)<(wi->first)) {vi++;} + if((vi->first)<(wi->first)) {vi++;} else - if((wi->first)<(vi->first)) + if((wi->first)<(vi->first)) { entries[wi->first]=-(wi->second); wi++; - } + } else { scalar sum = xmod((vi->second) - (wi->second),p); @@ -470,13 +466,12 @@ svec& svec::sub_mod_p(const svec& w, const scalar& p) svec& svec::operator/=(scalar scal) { - if(scal==0) + if(scal==0) { cerr<<"Attempt to divide svec by 0"<::iterator vi=entries.begin(); - vi != entries.end(); vi++) - (vi->second)/=scal; + for( auto& vi : entries) + (vi.second)/=scal; return *this; } @@ -485,11 +480,10 @@ svec& svec::operator/=(scalar scal) int eqmodp(const svec& v1, const svec& v2, const scalar& p) { if(v1.d!=v2.d) return 0; - map::const_iterator vi; - for(vi=v1.entries.begin(); vi!=v1.entries.end(); vi++) - if(xmod((vi->second)-(v2.elem(vi->first)),p)!=0) return 0; - for(vi=v2.entries.begin(); vi!=v2.entries.end(); vi++) - if(xmod((vi->second)-(v1.elem(vi->first)),p)!=0) return 0; + for( const auto& vi : v1.entries) + if(xmod((vi.second)-(v2.elem(vi.first)),p)!=0) return 0; + for( const auto& vi : v2.entries) + if(xmod((vi.second)-(v1.elem(vi.first)),p)!=0) return 0; return true; } @@ -502,9 +496,8 @@ int operator==(const svec& v1, const vec& v2) ostream& operator << (ostream& s, const svec& v) { - map::const_iterator vi; s<<"["; - for(vi=v.entries.begin(); vi!=v.entries.end(); vi++) + for(auto vi=v.entries.begin(); vi!=v.entries.end(); vi++) { if(vi!=v.entries.begin()) s<<","; s << "("<first<<":"<second<<")"; @@ -517,7 +510,7 @@ scalar operator*(const svec& v, const svec& w) //dot prod { scalar ans=0; if((v.entries.size()==0)||(w.entries.size()==0)) return ans; - map::const_iterator vi=v.entries.begin(), wi=w.entries.begin(); + auto vi=v.entries.begin(), wi=w.entries.begin(); while((vi!=v.entries.end())&&(wi!=w.entries.end())) { if((vi->first)<(wi->first)) {vi++;} else @@ -534,18 +527,16 @@ scalar operator*(const svec& v, const vec& w) //dot prod { scalar ans=0; if((v.entries.size()==0)) return ans; - map::const_iterator vi; - for(vi=v.entries.begin(); vi!=v.entries.end(); vi++) - ans+=(vi->second)* w[vi->first]; + for( const auto& vi : v.entries) + ans+=(vi.second)* w[vi.first]; return ans; } scalar dotmodp(const svec& v, const vec& w, scalar pr) { scalar ans=0; - map::const_iterator vi; - for(vi=v.entries.begin(); vi!=v.entries.end(); vi++) - ans=xmod(ans+xmodmul(vi->second,w[vi->first],pr),pr); + for( const auto& vi : v.entries) + ans=xmod(ans+xmodmul(vi.second,w[vi.first],pr),pr); return ans; } @@ -553,7 +544,7 @@ scalar dotmodp(const svec& v, const svec& w, scalar pr) { scalar ans=0; if((v.entries.size()==0)||(w.entries.size()==0)) return ans; - map::const_iterator vi=v.entries.begin(), wi=w.entries.begin(); + auto vi=v.entries.begin(), wi=w.entries.begin(); while((vi!=v.entries.end())&&(wi!=w.entries.end())) { if((vi->first)<(wi->first)) {vi++;} else @@ -569,9 +560,12 @@ scalar dotmodp(const svec& v, const svec& w, scalar pr) scalar content(const svec& v) { scalar ans=0; - map::const_iterator vi; - for(vi=v.entries.begin(); (ans!=1)&&(vi!=v.entries.end()); vi++) - ans=gcd(ans,vi->second); + for( const auto & vi : v.entries) + { + ans=gcd(ans,vi.second); + if (ans==1) + break; + } return ans; } diff --git a/libsrc/symb.cc b/libsrc/symb.cc index dcd5db2..e158629 100644 --- a/libsrc/symb.cc +++ b/libsrc/symb.cc @@ -108,23 +108,13 @@ void symblist::add(const symb& s, long start) } } -/* -long symblist::index(const symb& s, long start) const -{ - long i,ans; - for (i=start,ans=-1; ((i,long>::const_iterator - j = hashtable.find(pair(c,d)); - if(j==hashtable.end()) + long c = ss.cee(), d=ss.dee(); + auto j = hashtable.find(pair(c,d)); + if(j==hashtable.end()) return -1; // cout<<" is "<second<second; diff --git a/libsrc/timer.cc b/libsrc/timer.cc index b4addf4..68ef5b0 100644 --- a/libsrc/timer.cc +++ b/libsrc/timer.cc @@ -172,13 +172,9 @@ void timer::stop( string name ) { * Stop all timers. */ void timer::stopAll() { - timers::iterator it; - // TODO Check if timer is active via flags - - for( it = times_.begin(); it != times_.end(); it++ ) { - stop( it -> first ); - } + for ( const auto& t : times_) + stop(t.first); } /** @@ -226,11 +222,8 @@ void timer::show( int nline, string name, int idx1, int idx2 ) { * Loop through all timers, and write out. */ void timer::showAll( int nline ) { - timers::iterator it; - - for( it = times_.begin(); it != times_.end(); it++ ) { - show( nline, it -> first ); - } + for (const auto& t : times_) + show( nline, t.first ); } /** @@ -248,11 +241,8 @@ void timer::clear( string name ) { * Removes all times from all subtimers. */ void timer::clearAll() { - timers::iterator it; - - for( it = times_.begin(); it != times_.end(); it++ ) { - clear( it -> first ); - } + for (const auto& t : times_) + clear( t.first ); } /** @@ -261,13 +251,9 @@ void timer::clearAll() { * List names of all available timers */ void timer::list() { - timers::iterator it; - string message; - - for( it = times_.begin(); it != times_.end(); it++ ) { - message += it -> first + " "; - } + for (const auto& t : times_) + message += t.first + " "; message += "\n"; s_ -> write( message.c_str(), message.size() ); @@ -290,14 +276,9 @@ int timer::count( string name ) { * Return total time of a given timer. */ double timer::total( string name ) { - // Cache size of vector - vector::size_type size = times_[name].size(); double total = 0; - - for( int i = 0; i < (int)size; i++ ) { - total += times_[name][i]; - } - + for ( const auto& t : times_[name]) + total += t; return total; } @@ -307,10 +288,7 @@ double timer::total( string name ) { * Return average time of a given timer. */ double timer::average( string name ) { - // Cache size of vector - vector::size_type size = times_[name].size(); - - return total( name ) / size; + return total( name ) / times_[name].size(); } /** diff --git a/libsrc/xsplit.cc b/libsrc/xsplit.cc index 7df057a..fba7087 100644 --- a/libsrc/xsplit.cc +++ b/libsrc/xsplit.cc @@ -552,7 +552,7 @@ void form_finder::find( ff_data &data ) { // The recursive part: vector t_eigs = h->eigrange(depth); - vector::const_iterator apvar = t_eigs.begin(); + auto apvar = t_eigs.begin(); stringstream t_eigs_ss; std::copy(t_eigs.begin(),t_eigs.end(),ostream_iterator(t_eigs_ss," ")); diff --git a/libsrc/xsplit_data.cc b/libsrc/xsplit_data.cc index 3eaa46a..b8302e2 100644 --- a/libsrc/xsplit_data.cc +++ b/libsrc/xsplit_data.cc @@ -179,14 +179,8 @@ ff_data* ff_data::child( long eig ) { * Returns number of completed children for current node. */ int ff_data::numCompleteChildren() { - int completeCount = 0; - - vector< childstatus >::iterator it; - for( it = completedChildren_.begin(); it != completedChildren_.end(); it++ ) { - if( *it != NOT_COMPLETE ) completeCount++; - } - - return completeCount; + return std::count_if(completedChildren_.begin(), completedChildren_.end(), + [](childstatus s) {return s!=NOT_COMPLETE;}); } /**