Skip to content

Commit 5db9e91

Browse files
committed
more tweaking
1 parent 4dc632c commit 5db9e91

File tree

7 files changed

+54
-47
lines changed

7 files changed

+54
-47
lines changed

libsrc/curvered.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -429,23 +429,22 @@ int CurveRed::ord_p_j_denom(const bigint& p) const
429429
int CurveRed::c_p(const bigint& p) const
430430
{
431431
auto ri = reduct_array.find(p);
432-
return (ri==reduct_array.end()? : (ri->second).c_p);
432+
return (ri==reduct_array.end()? 1 : (ri->second).c_p);
433433
}
434434

435435
vector<bigint> CurveRed::all_cp() const
436436
{
437-
vector<bigint> ans(reduct_array.size());
438-
std::transform(reduct_array.begin(), reduct_array.end(), ans.begin(),
439-
[] (const pair<bigint,Reduction_type>& x) {return bigint(x.second.c_p);});
440-
return ans;
437+
vector<bigint> allcp(reduct_array.size());
438+
auto cp = [] (const pair<bigint,Reduction_type>& x) {return bigint(x.second.c_p);};
439+
std::transform(reduct_array.begin(), reduct_array.end(), allcp.begin(), cp);
440+
return allcp;
441441
}
442442

443443
bigint CurveRed::prodcp() const
444444
{
445445
static const bigint one(1);
446446
vector<bigint> allcp = all_cp();
447-
return std::accumulate(allcp.begin(), allcp.end(), one,
448-
[](const bigint& c1, const bigint& c2) {return c1*c2;});
447+
return std::accumulate(allcp.begin(), allcp.end(), one, std::multiplies<>());
449448
}
450449

451450
// The local Tamagawa number. Use p=0 for reals
@@ -526,10 +525,9 @@ int CurveRed::LocalRootNumber(const bigint& p) const
526525

527526
int CurveRed::GlobalRootNumber() const
528527
{
529-
int ans=-1; // root number at the infinte place (which is real)
530-
for( const auto& ri : reduct_array)
531-
ans *= (ri.second).local_root_number;
532-
return ans;
528+
auto rn = [](const std::pair<bigint,Reduction_type>& ri){return (ri.second).local_root_number;};
529+
return std::transform_reduce(reduct_array.cbegin(), reduct_array.cend(),
530+
-1, std::multiplies<>(), rn);
533531
}
534532

535533
int kro(const bigint& d, const bigint& n);

libsrc/eclib/marith.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ class divisor_iterator {
292292

293293
// [n^e for 0 <= e <= maxexp]
294294
vector<bigint> powers(const bigint& n, int maxexp);
295+
// [n^e for e in exponents]
296+
vector<bigint> powers(const bigint& n, const vector<int>& exponents);
295297

296298
// Compute N from its factorization (lists of primes and exponents) --
297299
// (name taken from gp)

libsrc/marith.cc

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,8 +1184,8 @@ int is_nth_power(const bigint& x, int n)
11841184
if ((x<0) && (n%2==0))
11851185
return 0;
11861186
vector<bigint> plist = pdivs(x);
1187-
return std::all_of(plist.begin(), plist.end(),
1188-
[n,x](const bigint& p){return val(p,x)%n==0;});
1187+
auto local_condition = [n,x](const bigint& p){return val(p,x)%n==0;};
1188+
return std::all_of(plist.begin(), plist.end(), local_condition);
11891189
}
11901190

11911191
bigint prime_to_S_part(const bigint& x, const vector<bigint>& S)
@@ -1279,36 +1279,37 @@ vector<bigint> powers(const bigint& n, int maxexp)
12791279
bigint np(1);
12801280
npowers[0] = np;
12811281
int e = 0;
1282-
std::generate(npowers.begin()+1, npowers.end(),
1283-
[n, &np, &e](){np*=n; e++; return np;});
1282+
auto next_power = [n, &np, &e](){np*=n; e++; return np;};
1283+
std::generate(npowers.begin()+1, npowers.end(), next_power);
12841284
return npowers;
12851285
}
12861286

12871287
// [n^e for e in exponents]
12881288
vector<bigint> powers(const bigint& n, const vector<int>& exponents)
12891289
{
12901290
vector<bigint> npowers(exponents.size());
1291-
auto e = exponents.begin();
1292-
std::generate(npowers.begin(), npowers.end(),
1293-
[n, &e](){return pow(n, *e++);;});
1291+
auto npower = [n](int e){return pow(n,e);};
1292+
std::transform(exponents.cbegin(), exponents.cend(), npowers.begin(), npower);
12941293
return npowers;
12951294
}
12961295

12971296
// Compute N from its factorization (lists of primes and exponents) --
12981297
// (name taken from gp)
12991298
bigint factorback(const vector<bigint>&PP, const vector<int>& EE)
13001299
{
1300+
static const bigint one(1);
1301+
auto power = [](const bigint& p, int e){return pow(p,e);};
13011302
return std::transform_reduce(PP.cbegin(), PP.cend(), EE.cbegin(),
1302-
bigint(1), // initial value
1303-
std::multiplies<>(), // how to combine terms,
1304-
[](const bigint& p, int e){return pow(p,e);} // how to form terms
1305-
);
1303+
one, // initial value
1304+
std::multiplies<>(), // how to combine terms,
1305+
power); // how to form terms
13061306
}
13071307

13081308
// Maximum conductor for a given list of primes
13091309
bigint MaxN(const vector<bigint>&PP)
13101310
{
1311-
bigint N(1);
1311+
static const bigint one(1);
1312+
bigint N(one);
13121313
std::for_each(PP.cbegin(), PP.cend(),
13131314
[&N](const bigint& p){N *= pow(p, (p==2?8:p==3?5:2));});
13141315
return N;
@@ -1325,8 +1326,8 @@ bigint radical(const bigint& N)
13251326
vector<bigint> multiply_list(const bigint& a, const vector<bigint>& L)
13261327
{
13271328
vector<bigint> aL(L.size());
1328-
std::transform(L.begin(), L.end(), aL.begin(),
1329-
[a](const bigint& x){return a*x;});
1329+
auto times_a = [a](const bigint& x){return a*x;};
1330+
std::transform(L.begin(), L.end(), aL.begin(), times_a);
13301331
return aL;
13311332
}
13321333

@@ -1354,7 +1355,8 @@ vector<bigint> multiply_list_by_powers(const bigint& p, const vector<int>& expon
13541355
vector<bigint> bigintify(const vector<long>& L)
13551356
{
13561357
vector<bigint> LL(L.size());
1357-
std::transform(L.cbegin(), L.cend(), LL.begin(), [](long x){return bigint(x);});
1358+
auto long2big = [](long x){return bigint(x);};
1359+
std::transform(L.cbegin(), L.cend(), LL.begin(), long2big);
13581360
return LL;
13591361
}
13601362

tests/mptest.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ int main()
109109
cout << "\nTesting list multiplication functions\n";
110110
vector<bigint> powers_of_2 = powers(bigint(2), 10);
111111
cout << "Powers of 2 up to 2^10: " << powers_of_2 << endl;
112+
// vector<int> odds = {1,3,5,7,9};
113+
vector<bigint> odd_powers_of_2 = powers(bigint(2), {1,3,5,7,9});
114+
cout << "Odd powers of 2 up to 2^10: " << odd_powers_of_2 << endl;
112115

113116
vector<bigint> L = bigintify({1,2,3,4,5});
114117
cout << "L = " << L << endl;
@@ -169,9 +172,9 @@ int main()
169172
cout << "m = " << m << endl;
170173
vector<bigint> plist=pdivs(m);
171174
cout << "m has " << plist.size() << " prime divisors: " << plist << endl;
172-
vector<int> ee = valuations(m, plist);
173-
cout << "with exponents " << ee << endl;
174-
bigint m2 = factorback(plist, ee);
175+
vector<int> vals = valuations(m, plist);
176+
cout << "with exponents " << vals << endl;
177+
bigint m2 = factorback(plist, vals);
175178
cout << "factorback recovers " << m2 << " (should be " << m << ")" << endl;
176179

177180
vector<bigint> dlist=alldivs(m,plist);

tests/out_no_ntl/mptest.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ testing find function for the list [ 1 -1 2 -2 4 -4 3 -3 6 -6 12 -12 5 -5 10 -10
3737

3838
Testing list multiplication functions
3939
Powers of 2 up to 2^10: [ 1 2 4 8 16 32 64 128 256 512 1024 ]
40+
Odd powers of 2 up to 2^10: [ 2 8 32 128 512 ]
4041
L = [ 1 2 3 4 5 ]
4142
3*L = [ 3 6 9 12 15 ]
4243
L2 = [ 1 10 100 ]

tests/out_ntl/mptest.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ testing find function for the list [ 1 -1 2 -2 4 -4 3 -3 6 -6 12 -12 5 -5 10 -10
3737

3838
Testing list multiplication functions
3939
Powers of 2 up to 2^10: [ 1 2 4 8 16 32 64 128 256 512 1024 ]
40+
Odd powers of 2 up to 2^10: [ 2 8 32 128 512 ]
4041
L = [ 1 2 3 4 5 ]
4142
3*L = [ 3 6 9 12 15 ]
4243
L2 = [ 1 10 100 ]

tests/tegros.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ int main(void)
5656
vector<CurveRed> egr_S23_0 = egros_from_j_0(S23);
5757
std::sort(egr_S23_0.begin(), egr_S23_0.end());
5858
cout << egr_S23_0.size()<< " curves with j=0 and good reduction outside "<<S23<<" (should be 72):\n";
59-
for (auto E: egr_S23_0) cout<<(Curve)E<<" conductor "<<E.conductor()<<" sort key "<<E.sort_key()<<endl;
59+
for (auto E1: egr_S23_0) cout<<(Curve)E1<<" conductor "<<E1.conductor()<<" sort key "<<E1.sort_key()<<endl;
6060
cout<<endl;
6161

6262
vector<CurveRed> egr_S23_1728 = egros_from_j_1728(S23);
6363
std::sort(egr_S23_1728.begin(), egr_S23_1728.end());
6464
cout << egr_S23_1728.size()<< " curves with j=1728 and good reduction outside "<<S23<<" (should be 32):\n";
65-
for (auto E: egr_S23_1728) cout<<(Curve)E<<" conductor "<<E.conductor()<<" sort key "<<E.sort_key()<<endl;
65+
for (auto E1: egr_S23_1728) cout<<(Curve)E1<<" conductor "<<E1.conductor()<<" sort key "<<E1.sort_key()<<endl;
6666
cout<<endl;
6767

6868
cout << "Elliptic curves with conductor a power of 11, from their known j-invariants" << endl;
@@ -75,18 +75,18 @@ int main(void)
7575
bigrational(bigint(-24729001))
7676
};
7777
vector<CurveRed> egr_11;
78-
for (auto j: j11)
78+
for (auto ji: j11)
7979
{
80-
auto EE = egros_from_j(j, S11);
81-
cout << EE.size() << " curves with j = " << j << ":";
82-
for ( auto E: EE) cout << " " << (Curve)E;
80+
auto EE = egros_from_j(ji, S11);
81+
cout << EE.size() << " curves with j = " << ji << ":";
82+
for ( auto E1: EE) cout << " " << (Curve)E1;
8383
cout << endl;
8484
egr_11.insert(egr_11.end(), EE.cbegin(), EE.cend());
8585
}
8686
std::sort(egr_11.begin(), egr_11.end());
8787
cout<<"Sorted list:\n";
88-
for (auto E: egr_11)
89-
cout << "conductor " << E.conductor() << "\t" << (Curve)E << "\tj = " << j_invariant(E) << endl;
88+
for (auto E1: egr_11)
89+
cout << "conductor " << E1.conductor() << "\t" << (Curve)E1 << "\tj = " << j_invariant(E1) << endl;
9090
cout << endl;
9191

9292
vector<bigint> N_j_0, N_j_1728;
@@ -100,27 +100,27 @@ int main(void)
100100
{
101101
N_j_0.push_back(N);
102102
auto EE = egros_from_j_0(S);
103-
for (auto E: EE)
104-
if (E.conductor()==N)
105-
E_j_0.push_back(E);
103+
for (auto E1: EE)
104+
if (E1.conductor()==N)
105+
E_j_0.push_back(E1);
106106
}
107107
if (is_N_possible_j_1728(N, S))
108108
{
109109
N_j_1728.push_back(N);
110110
auto EE = egros_from_j_1728(S);
111-
for (auto E: EE)
112-
if (E.conductor()==N)
113-
E_j_1728.push_back(E);
111+
for (auto E1: EE)
112+
if (E1.conductor()==N)
113+
E_j_1728.push_back(E1);
114114
}
115115
}
116116
cout << "Possible conductors <= 100 of curves with j=0: " << N_j_0 << endl;
117117
cout << "Actual conductors and curves:\n";
118-
for (auto E: E_j_0)
119-
cout << E.conductor() << "\t" << (Curve)E << endl;
118+
for (auto E1: E_j_0)
119+
cout << E1.conductor() << "\t" << (Curve)E1 << endl;
120120
cout << "Possible conductors < 100 of curves with j=1728: " << N_j_1728 << endl;
121121
cout << "Actual conductors and curves:\n";
122-
for (auto E: E_j_1728)
123-
cout << E.conductor() << "\t" << (Curve)E << endl;
122+
for (auto E1: E_j_1728)
123+
cout << E1.conductor() << "\t" << (Curve)E1 << endl;
124124

125125
return 0;
126126
}

0 commit comments

Comments
 (0)