Skip to content

Commit 4dc632c

Browse files
committed
made more curve methods const by setting local root numbers on creation
1 parent 05ae7a6 commit 4dc632c

File tree

2 files changed

+41
-45
lines changed

2 files changed

+41
-45
lines changed

libsrc/curvered.cc

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,16 @@ CurveRed::CurveRed(const Curvedata& E)
326326
N = one;
327327
for( const auto& ri : reduct_array)
328328
N *= pow((ri.first), (ri.second).ord_p_N);
329+
for (auto p: the_bad_primes)
330+
setLocalRootNumber(p);
329331
return;
330332
} // end of Tate's algorithm
331333

332334
// Sort key for sorting lists of curves (LMFDB ordering):
333335
// (1) conductor
334336
// (2) list of ap for p < NP_SORT
335337
// (3) a1,a2,a3,4,a6
336-
vector<bigint> CurveRed::sort_key(const int NP_SORT)
338+
vector<bigint> CurveRed::sort_key(const int NP_SORT) const
337339
{
338340
vector<bigint> key;
339341
key.push_back(N);
@@ -350,7 +352,7 @@ vector<bigint> CurveRed::sort_key(const int NP_SORT)
350352

351353
// The local Tamagawa exponent -- same as Tamagawa number unless the
352354
// component group is (2,2). Use p=0 for reals
353-
bigint local_Tamagawa_exponent(CurveRed& c, const bigint& p)
355+
bigint local_Tamagawa_exponent(const CurveRed& c, const bigint& p)
354356
{
355357
static const bigint one(1), two(2), four(4);
356358
if (is_zero(p)) return bigint(c.conncomp);
@@ -406,39 +408,39 @@ vector<long> tamagawa_primes(const CurveRed& C, int real_too)
406408
// which is impossible without removing the "const" qualifier from the
407409
// CurveRed argument!
408410

409-
int CurveRed::ord_p_discr(const bigint& p)
411+
int CurveRed::ord_p_discr(const bigint& p) const
410412
{
411413
auto ri = reduct_array.find(p);
412414
return (ri==reduct_array.end()? 0 : (ri->second).ord_p_discr);
413415
}
414416

415-
int CurveRed::ord_p_N(const bigint& p)
417+
int CurveRed::ord_p_N(const bigint& p) const
416418
{
417419
auto ri = reduct_array.find(p);
418420
return (ri==reduct_array.end()? 0 : (ri->second).ord_p_N);
419421
}
420422

421-
int CurveRed::ord_p_j_denom(const bigint& p)
423+
int CurveRed::ord_p_j_denom(const bigint& p) const
422424
{
423425
auto ri = reduct_array.find(p);
424426
return (ri==reduct_array.end()? 0 : (ri->second).ord_p_j_denom);
425427
}
426428

427-
int CurveRed::c_p(const bigint& p)
429+
int CurveRed::c_p(const bigint& p) const
428430
{
429431
auto ri = reduct_array.find(p);
430432
return (ri==reduct_array.end()? : (ri->second).c_p);
431433
}
432434

433-
vector<bigint> CurveRed::all_cp()
435+
vector<bigint> CurveRed::all_cp() const
434436
{
435437
vector<bigint> ans(reduct_array.size());
436438
std::transform(reduct_array.begin(), reduct_array.end(), ans.begin(),
437439
[] (const pair<bigint,Reduction_type>& x) {return bigint(x.second.c_p);});
438440
return ans;
439441
}
440442

441-
bigint CurveRed::prodcp()
443+
bigint CurveRed::prodcp() const
442444
{
443445
static const bigint one(1);
444446
vector<bigint> allcp = all_cp();
@@ -447,13 +449,13 @@ bigint CurveRed::prodcp()
447449
}
448450

449451
// The local Tamagawa number. Use p=0 for reals
450-
bigint local_Tamagawa_number(CurveRed& c, const bigint& p)
452+
bigint local_Tamagawa_number(const CurveRed& c, const bigint& p)
451453
{
452454
return bigint(is_zero(p)? getconncomp(c): getc_p(c,p));
453455
}
454456

455457
// The global Tamagawa number, = product of local ones.
456-
bigint global_Tamagawa_number(CurveRed& c, int real_too)
458+
bigint global_Tamagawa_number(const CurveRed& c, int real_too)
457459
{
458460
return bigint(prodcp(c) * (real_too ? getconncomp(c) : 1));
459461
}
@@ -514,25 +516,19 @@ void CurveRed::display(ostream& os)
514516
// Reduction_type::local_root_number field, computing them if not
515517
// already set (i.e. field contains 0)
516518

517-
int CurveRed::LocalRootNumber(const bigint& p)
519+
int CurveRed::LocalRootNumber(const bigint& p) const
518520
{
519521
if(is_zero(p)) return -1; // the infinite prime
520522
auto ri = reduct_array.find(p);
521523
if(ri==reduct_array.end()) return 1; // good reduction case
522-
if((ri->second).local_root_number==0)
523-
setLocalRootNumber(p);
524524
return (ri->second).local_root_number;
525525
}
526526

527-
int CurveRed::GlobalRootNumber()
527+
int CurveRed::GlobalRootNumber() const
528528
{
529-
int ans=-1;
529+
int ans=-1; // root number at the infinte place (which is real)
530530
for( const auto& ri : reduct_array)
531-
{
532-
if((ri.second).local_root_number==0)
533-
setLocalRootNumber(ri.first);
534-
ans *= (ri.second).local_root_number;
535-
}
531+
ans *= (ri.second).local_root_number;
536532
return ans;
537533
}
538534

@@ -1041,7 +1037,7 @@ int CurveRed::neron(long p, int kod)
10411037

10421038
// Trace of Frobenius (via pari) if p good
10431039
// (or 0 for additive reduction, +1 for split multiplicative, -1 for nonsplit)
1044-
long CurveRed::ap(long p)
1040+
long CurveRed::ap(long p) const
10451041
{
10461042
bigint P(p);
10471043
int f = min(2, ord_p_N(P));
@@ -1058,7 +1054,7 @@ long CurveRed::ap(long p)
10581054

10591055
// Trace of Frobenius (via pari) if p good
10601056
// (or 0 for additive reduction, +1 for split multiplicative, -1 for nonsplit)
1061-
bigint CurveRed::ap(const bigint& p)
1057+
bigint CurveRed::ap(const bigint& p) const
10621058
{
10631059
if (is_long(p))
10641060
return bigint(ap(I2long(p)));

libsrc/eclib/curve.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ friend class IsogenyClass;
258258
// (1) conductor
259259
// (2) list of ap for good p < NP_SORT
260260
// (3) a1,a2,a3,4,a6
261-
vector<bigint> sort_key(const int NP_SORT=25);
262-
int operator<(CurveRed& E) {return sort_key()<E.sort_key();}
261+
vector<bigint> sort_key(const int NP_SORT=25) const;
262+
int operator<(const CurveRed& E) {return sort_key()<E.sort_key();}
263263
private:
264264
// functions for setting local root numbers:
265265
int neron(long p, int kod); // p = 2 or 3
@@ -273,14 +273,14 @@ friend class IsogenyClass;
273273
friend inline vector<bigint> getbad_primes(const CurveRed& c)
274274
{return c.the_bad_primes; }
275275
friend inline bigint getconductor(const CurveRed& c) {return c.N; }
276-
int ord_p_discr(const bigint& p);
277-
int ord_p_N(const bigint& p);
278-
int ord_p_j_denom(const bigint& p);
279-
int c_p(const bigint& p);
280-
vector<bigint> all_cp();
281-
bigint prodcp();
282-
int LocalRootNumber(const bigint& p);
283-
int GlobalRootNumber();
276+
int ord_p_discr(const bigint& p) const;
277+
int ord_p_N(const bigint& p) const;
278+
int ord_p_j_denom(const bigint& p) const;
279+
int c_p(const bigint& p) const;
280+
vector<bigint> all_cp() const;
281+
bigint prodcp() const;
282+
int LocalRootNumber(const bigint& p) const;
283+
int GlobalRootNumber() const;
284284

285285
friend Kodaira_code getKodaira_code(const CurveRed& c, const bigint& p);
286286
// the returned value casts as a character array; to use coded as int,
@@ -289,14 +289,14 @@ friend class IsogenyClass;
289289
// Trace of Frobenius (via pari if p is good for long p)
290290
// (or 0 for additive reduction, +1 for split multiplicative, -1 for nonsplit)
291291
// These are not constant methods as a call to LocalRootNumber may be needed.
292-
long ap(long p);
293-
bigint ap(const bigint& p);
292+
long ap(long p) const;
293+
bigint ap(const bigint& p) const;
294294

295295
// The local Tamagawa number. Use p=0 for reals
296-
friend bigint local_Tamagawa_number(CurveRed& c, const bigint& p);
296+
friend bigint local_Tamagawa_number(const CurveRed& c, const bigint& p);
297297
// The local Tamagawa exponent -- same as Tamagawa number unless the
298298
// component group is (2,2). Use p=0 for reals
299-
friend bigint local_Tamagawa_exponent(CurveRed& c, const bigint& p);
299+
friend bigint local_Tamagawa_exponent(const CurveRed& c, const bigint& p);
300300
// The global Tamagawa exponent, i.e. the lcm of the exponents of
301301
// the component groups at all bad primes (including infinity if
302302
// real_too is 1), which is the lcm of the local Tamagawa exponents.
@@ -315,17 +315,17 @@ friend class IsogenyClass;
315315
inline bigint Trace_Frob(CurveRed& c, const bigint& p) {return c.ap(p);}
316316
inline long Trace_Frob(CurveRed& c, const long& p) {return c.ap(p);}
317317

318-
inline int getord_p_discr(CurveRed& c, const bigint& p) {return c.ord_p_discr(p);}
319-
inline int getord_p_N(CurveRed& c, const bigint& p) {return c.ord_p_N(p);}
320-
inline int getord_p_j_denom(CurveRed& c, const bigint& p) {return c.ord_p_j_denom(p);}
321-
inline int getc_p(CurveRed& c, const bigint& p) {return c.c_p(p);}
322-
inline vector<bigint> all_cp(CurveRed& c) {return c.all_cp();}
323-
inline bigint prodcp(CurveRed& c) {return c.prodcp();}
324-
inline int LocalRootNumber(CurveRed& c, const bigint& p) {return c.LocalRootNumber(p);}
325-
inline int GlobalRootNumber(CurveRed& c) {return c.GlobalRootNumber();}
318+
inline int getord_p_discr(const CurveRed& c, const bigint& p) {return c.ord_p_discr(p);}
319+
inline int getord_p_N(const CurveRed& c, const bigint& p) {return c.ord_p_N(p);}
320+
inline int getord_p_j_denom(const CurveRed& c, const bigint& p) {return c.ord_p_j_denom(p);}
321+
inline int getc_p(const CurveRed& c, const bigint& p) {return c.c_p(p);}
322+
inline vector<bigint> all_cp(const CurveRed& c) {return c.all_cp();}
323+
inline bigint prodcp(const CurveRed& c) {return c.prodcp();}
324+
inline int LocalRootNumber(const CurveRed& c, const bigint& p) {return c.LocalRootNumber(p);}
325+
inline int GlobalRootNumber(const CurveRed& c) {return c.GlobalRootNumber();}
326326

327327
// The global Tamagawa number, = product of local ones.
328-
bigint global_Tamagawa_number(CurveRed& c, int real_too);
328+
bigint global_Tamagawa_number(const CurveRed& c, int real_too);
329329

330330
// Tamagawa primes: primes dividing any Tamagawa number
331331
vector<long> tamagawa_primes(const CurveRed& C, int real_too);

0 commit comments

Comments
 (0)