-
Notifications
You must be signed in to change notification settings - Fork 1
/
newforms.cc
2778 lines (2537 loc) · 87.4 KB
/
newforms.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// newforms.cc
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <functional> // std::multiplies
#include <numeric> // std::multiplies
#include "looper.h"
#include "newforms.h"
#define MAXDEPTH 20 // maximum depth for splitting off eigenspaces
#define genus_class_triviality_bound 10 // if aP=0 for this number of
// good primes in a genus
// class then we assume that a
// newform is self-twist and
// all aP for P in this class
// are 0.
// This flag is only for use when updating the schema of the newforms
// files to include the BC and CM fields, so we can read in data files
// without these (but output files with them). When the data format
// conversion is complete, the flag can be removed and some lines
// removed below in the two places it is used.
//#define NO_BC_CM
// Notes on scaling:
//
// For a newform F (however normalised), the periods of F are the
// integrals of (the differential associated to) F along paths between
// Gamma_0(N)-equivalent cusps. These are all integral multiples of a
// minimal positive real period P. The map from integral homology to
// the associated period multiple takes gamma In H_1(-,Z) to
// n_F(gamma) = (integral of F over gamma)/P, and the image of this
// map is (by definiton) Z.
// Similarly the "cuspidal periods" of F are its integrals along all
// paths gamma between cusps, whether or not they are
// Gamma_0(N)-equivalent, and these are the integral multiples of a
// least positive real cuspidal period P'. Now P*Z is a subgroup of
// P'*Z, and its index c is called the "cuspidal factor", also equal
// to c=P/P'. Let n'_F(gamma) = (integral of F over gamma)/P' for gamma
// in H_1(-,Z; cusps).
// The map from gamma to n'_F(gamma) is modular and an eigenfunction
// for Hecke, so is a primitive basis vector for the associated dual
// eigenspace. Since we do linear algebra on the dual (by transposing
// Hecke matrices), we can compute this map, up to scaling, by simply
// taking the dot product of our dual basis vector v with the coords
// of gamma with respect to the homology basis. Regardless of whether
// our "freegens" generator the whole integral homology (w.r.t. cusps)
// or only a sublattice of finite index, i.e. whether denom1=1 or >1,
// this does not nmatter since the map n'_F is primitive, so to get
// the correct values (up to sign) we just have to divide out these
// dot products by their gcd.
// The map n'_F(gamma) is almost encoded in the matrix projcoord
// (created by calling make_projcoord()): its rows are indexed by
// edges modulo edge relations, so to get the value for the j'th
// newform on an edge (c:d)_t we find the edge number i =
// offset(t)+index(c,d)), use that to look up
// k=ER.coords(i)=ER.coords(index(c,d), t), and the value is
// sign(k)*projcoord[abs(k),j].
// For example n'_F({0,oo}) is obtained this way with (c,d,t)=(0,1,0).
// Now L(F,1) is the integral of F over {0,oo} (?times a normalising
// factor?), hence we obtain L(F,1)/P' = n'_F({0,oo}) (an integer).
// For L(F,1)/P we divide by the cuspidal factor for F, obtaining a
// rational. [P=c*P' so L/P = L/(c*P') = (L/P')/c.]
// A second way to compute L(F,1)/P' which only involves integral
// periods is to use a "Manin vector" mvp for some good prime p, which
// is the sum over x mod p of {0,x/p}, since (1+N(p)-a(p))*n'_F({0,oo})
// = n'_F(mvp), hence L/P' = n'_F(mvp)/(1+N(p)-a(p)).
// NB in the newform constructor we cannot use projcoord since that is
// only computed after all the newforms are found
// Sorting functions
// Compare two integers, using the natural order ...-2,-1,0,1,2,...
int less_ap(long a, long b)
{
return sign(a-b);
}
// Compare two integer vectors lexicographically, using less_ap():
int less_apvec(const vector<long>& v, const vector<long>& w)
{
auto vi=v.begin(), wi=w.begin();
while(vi!=v.end())
{
int s = less_ap(*vi++,*wi++);
if(s) return s;
}
return 0;
}
struct newform_eigs_comparer {
bool operator()(const newform& f, const newform& g)
{
return less_apvec(f.eigs,g.eigs)==-1;
}
}
less_newform_eigs;
struct newform_aplist_comparer {
bool operator()(const newform& f, const newform& g)
{
return less_apvec(f.aplist,g.aplist)==-1;
}
}
less_newform_lmfdb;
newform::newform(newforms* nfs, const vec& v, const vector<long>& eigs)
: eigs(eigs)
{
//cout<<"Constructing newform with eigs "<<eigs<<" and basis "<<v<<endl;
nf=nfs;
// convert basis vector from coords w.r.t. face-gens to coords
// w.r.t.edge-gens:
if(nf->hmod)
{ // we don't have a mod p mat*vec
mat vcol(dim(v),1);
vcol.setcol(1,v);
basis = reduce_modp(matmulmodp(nf->h1->FR.coord, vcol, nf->hmod).col(1), DEFAULT_MODULUS);
}
else
{
basis = (nf->h1->FR.coord)*v;
makeprimitive(basis); // this is now independent of h1's denom1
}
if (nf->verbose >1)
{
cout << "short newform basis = "<<v<<endl;
cout << "long newform basis = "<<basis<<endl;
}
// Find the ratio of the least period w.r.t. integral homology
// divided by the least period w.r.t. homology relative to cusps.
// this uses the vector v so must be done now
if(nf->characteristic)
{
cuspidalfactor=1;
}
else
{
cuspidalfactor = content((nf->h1->tkernbas)*v);
if(nf->verbose)
cout<<"cuspidalfactor = "<<cuspidalfactor<<endl;
}
genus_classes.resize(1,0);
genus_class_ideals.resize(1,Qideal(ONE));
genus_class_aP.resize(1,1);
fake = 0;
// to be set later
CMD = 0; // will be set to an unramified negative discriminant if self-twist
genus_classes_filled = 0; // will be set to 1 when all/half genus classes have a nonzero aP
cm = 1; // will be set to 0 or a negative square-free integer if CM
bc = 4; // will be set to 0 or a square-free integer if base-change or twist of b.c.
sfe = pdot = dp0 = lambdadot = matdot = 0;
genus_class_trivial_counter.resize(nf->nchi, 0);
possible_self_twists = nf->possible_self_twists; // may be cut down on computing aP later
}
// Fill in data for one newform. This assumes we have:
// cuspidalfactor
// and computes
// - L/P (uses cuspidalfactor)
// - dp0, pdot (uses nP0, aP0, mvp from newform class)
// - a,b,c,d,matdot (integration data) via find_matrix()
void newform::data_from_eigs()
{
// compute A-L eigenvalues now in odd class number, else they are
// computed in getap()
if (Quad::class_group_2_rank==0)
{
aqlist.resize(nf->badprimes.size());
std::transform(nf->badprimes.begin(), nf->badprimes.end(), aqlist.begin(),
[this] ( Quadprime& Q ) {return eigenvalueAtkinLehner(Q);});
sfe = std::accumulate(aqlist.begin(),aqlist.end(),-1,std::multiplies<long>());
}
// compute L/P as n_F({0,oo})
int pdot0 = abs(nf->zero_infinity[index]);
loverp = rational(pdot0, (Quad::nunits) * cuspidalfactor);
// compute L/P again using Manin vector
dp0 = 1 + (nf->nP0) - nf->aP0[index-1]; // aP0 is based at 0
pdot = abs(nf->mvp[index]);
rational loverp_mvp(pdot, dp0 * (Quad::nunits) * cuspidalfactor);
if (nf->characteristic>0)
return;
// Check they agree:
if (pdot != dp0*pdot0)
{
cout << "Inconsistent values for L/P computed two ways!"<<endl;
cout << "from {0,oo} directly: " << loverp <<endl;
cout << "pdot0 = "<<pdot0<<endl;
cout << "cuspidalfactor = "<<cuspidalfactor<<endl;
cout << "from Manin vector: " << loverp_mvp <<endl;
cout << "pdot = "<<pdot<<endl;
cout << "nP0 = "<<nf->nP0<<endl;
cout << "iP0 = "<<nf->iP0<<endl;
cout << "eigs (size "<<eigs.size()<<") = "<<eigs<<endl;
cout << "ap0 = "<<nf->aP0[index]<<endl;
cout << "dp0 = "<<dp0<<endl;
cout << "cuspidalfactor = "<<cuspidalfactor<<endl;
}
// find (a,b,c,d) such that cusp b/d is equivalent to 0 and the
// integral over {0,M(0)} = {0,b/d} with M = [a,b;N*c,d] is a
// nonzero multiple "matdot" of the period P.
// NB We do not currently use this, it should be further scaled
find_matrix();
}
// When a newform has been read from file, we have the aqlist and
// aplist but not the sequence of eigs in order. This is needed
// both for recovering the basis vector from the h1 (in case we want
// to compute more ap), and for computing oldform multiplcities.
void newform::eigs_from_data()
// recreate eigs list (in case we need to recover basis vector):
// start with unramified char eigs (all +1), then Tp eigs ap for
// good p
{
// cout<<"In eigs_from_data (level "<<ideal_label(nf->N)<<"), aplist = "<<aplist<<endl;
int ch(nf->characteristic);
if (ch == 0) // the first n2r eigs are all +1
eigs.resize(nf->n2r, +1);
else
eigs.resize(0, +1);
// Get a(P) or a(P^2) from the a(P) in aplist, for good P
auto pr=Quadprimes::list.begin();
auto api=aplist.begin();
while (((int)eigs.size() < nf->nap+nf->n2r) && (api!=aplist.end()))
{
Quadprime P = *pr;
INT normP = P.norm();
while ((P.divides(nf->N)) || (ch>0 && (normP%ch==0)))
{
// cout<<" - P = "<<ideal_label(P)<<": bad prime, skipping"<<endl;
++pr;
++api;
P = *pr;
normP = P.norm();
}
long ap = *api;
if (!P.has_square_class()) // then we need the eigenvalue of T(P^2)
{
ap = ap*ap - I2long(normP);
}
eigs.push_back(ap);
//cout<<" - P = "<<ideal_label(P)<<": eig = "<<ap<<endl;
++pr; ++api;
if (pr == Quadprimes::list.end())
break;
}
// cout<<" eigs_from_data produced eigs = "<<eigs<<endl;
fill_in_genus_class_data();
}
// When a newform has been read from file, when the class number is
// even,before computing more ap, we need to fill in the genus class
// data for each newform.
void newform::fill_in_genus_class_data()
{
genus_classes.resize(1,0);
genus_class_ideals.resize(1,Qideal(ONE));
genus_class_aP.resize(1,1);
// Now we fill the genus classes with known ideals and eigenvalues,
// one in each genus class:
int m2r = 0; // 2-rank of genus classes so far filled
int iP = -1; // index of old prime P begin looked at
int nap = aplist.size();
auto pr = Quadprimes::list.begin();
while((pr!=Quadprimes::list.end()) && (m2r<nf->n2r) && (iP<nap-1))
{
Quadprime P = *pr++;
iP++;
if (P.divides(nf->N))
continue;
long aP = aplist[iP];
if (aP==0)
continue;
long c = P.genus_class(1); // 1 means reduce mod Quad::class_group_2_rank
if (c==0)
continue;
// if (nf->verbose)
// cout<<"form #"<<i<<" has eigenvalue "<<aP<<" and genus class "<<c<<endl;
// See if we already have an eigenvalue for this genus class
auto ci = std::find(genus_classes.begin(), genus_classes.end(), c);
if (ci == genus_classes.end()) // then we do not
{
long oldsize = genus_classes.size();
genus_classes.resize(2*oldsize);
genus_class_ideals.resize(2*oldsize);
genus_class_aP.resize(2*oldsize);
for (int j = 0; j<oldsize; j++)
{
genus_classes[oldsize+j] = genus_classes[j]^c;
genus_class_ideals[oldsize+j] = genus_class_ideals[j]*P;
genus_class_aP[oldsize+j] = genus_class_aP[j]*aP;
}
m2r++;
}
} // loop on primes
if (nf->verbose>1)
{
cout<<"Finished filling in genus class data for form #"<<index<<endl;
cout<<"genus classes: "<<genus_classes<<endl;
cout<<"genus class ideals: "<<genus_class_ideals<<endl;
cout<<"genus class eigenvalues: "<<genus_class_aP<<endl;
}
}
// For M a *multiple* of this level N, make the list of eigs
// appropriate for the higher level, taking into account the primes
// P (if any) dividing M but not N. For such P we delete the a(P)
// from the sublist of T(P) eigenvalues.
vector<long> newform::oldform_eigs(Qideal& M)
{
assert (nf->N.divides(M));
eigs_from_data();
vector<long> M_eigs;
if (nf->verbose)
{
cout<<"Making oldform eigs at level "<<ideal_label(M)<<" from eigs at level "<<ideal_label(nf->N)<<endl;
cout<<" - input eigs: "<<eigs<<endl;
}
// insert eigs for central characters:
if (nf->characteristic == 0) // the first n2r eigs are all +1
M_eigs.resize(nf->n2r, +1);
auto ei = eigs.begin() + (nf->n2r);
for ( const auto& P : Quadprimes::list)
{
if (ei==eigs.end()) break;
if (!P.divides(nf->N))
{
if (!P.divides(M)) // else this T(P) eigenvalue is ignored
{
if (nf->verbose>1)
cout << " keeping eigenvalue "<<(*ei)<< " at "<<P<<endl;
M_eigs.push_back(*ei);
}
++ei;
}
}
if (nf->verbose)
{
cout<<" - output eigs: "<<M_eigs<<endl;
}
return M_eigs;
}
newform::newform(newforms* nfs, int ind,
const vector<int>& intdata, const vector<Quad>& Quaddata,
const vector<long>& aq, const vector<long>& ap)
{
nf=nfs;
index = ind;
Qideal N(nf->N);
int ch(nf->characteristic);
if (ch == 0)
{
sfe = intdata[0];
// cout<<"sfe from file = "<<sfe<<endl;
pdot = intdata[1];
dp0 = intdata[2];
loverp = rational(abs(pdot),dp0*(Quad::nunits));
cuspidalfactor = intdata[3];
lambda = Quaddata[0];
lambdadot = intdata[4];
a = Quaddata[1];
b = Quaddata[2];
c = Quaddata[3];
d = Quaddata[4];
matdot = intdata[5];
#ifndef NO_BC_CM
bc = intdata[6];
cm = intdata[7];
CMD = intdata[8];
#else
bc = 4; // will be set by calling base_change_code() to 0, or a
// square-free integer if base-change or twist of b.c.
cm = 1; // will be set by calling is_CM() to 0, or a a negative
// square-free integer if CM
CMD = intdata[6];
#endif
aqlist = aq;
// Recompute sign of functional equation = minus product of all A-L eigenvalues
int newsfe = std::accumulate(aqlist.begin(),aqlist.end(),-1,std::multiplies<long>());
if (newsfe!=sfe)
cout<<"Problem in data on file for level "<<ideal_label(N)<<": sfe = "<<sfe<<" and aqlist = "<<aqlist<<", but minus product of latter is "<<newsfe<<endl;
}
aplist = ap;
genus_classes.resize(1,0);
genus_class_ideals.resize(1,Qideal(ONE));
genus_class_aP.resize(1,1);
genus_class_trivial_counter.resize(nf->nchi, 0);
fake = 0;
// recreate eigs list (used to recover basis vector, and for oldclasses at higher levels):
eigs_from_data();
}
// find (a,b,c,d) such that cusp b/d is equivalent to 0 and the
// integral over {0,M(0)} = {0,b/d} with M = [a,b;N*c,d] is a
// nonzero multiple "matdot" of the period P.
void newform::find_matrix()
{
if(nf->verbose>1)
cout<<"computing integration matrix for newform "<<index<<"..."<<flush;
matdot=0;
Qideal N(nf->N);
for (Quadlooper dl(2, 1000, 1); dl.ok()&&!matdot; ++dl)
{ d=(Quad)dl;
Qideal D(d);
if (N.is_coprime_to(D))
{
vector<Quad> reslist = residues(d);
for( const auto& bi : reslist)
{
b = bi;
Qideal bN = b*N;
if (D.is_coprime_to(bN, a, c))
// found a candidate q=b/d: a+c=1 with d|a and b|c and c/b in N
{
c /= -b;
a /= d; // now a*d-b*c=1 with c in N
assert (a*d-b*c==Quad::one);
matdot = abs((nf->h1->chain(b,d, 1))[index]);
if (matdot)
break;
} // b coprime to d test
} // loop over b
} // d coprime to N test
} // loop over d
if(nf->verbose>1)
cout<<"M = ["<<a<<","<<b<<";"<<c<<","<<d<<"] with factor "<<matdot<<endl;
}
//#define DEBUG_BC
int newform::base_change_code(void)
{
if (bc==4) // not yet set
{
#ifdef DEBUG_BC
cout<<"bc not set, computing code..."<<endl;
#endif
bc = 0;
if (is_base_change())
{
#ifdef DEBUG_BC
cout<<" - form is bc..."<<flush;
#endif
bc = base_change_discriminant();
#ifdef DEBUG_BC
cout<<" with disc "<<bc<<endl;
#endif
}
else if (is_base_change_twist())
{
#ifdef DEBUG_BC
cout<<" - form is twist of bc..."<<flush;
#endif
bc = -base_change_twist_discriminant();
#ifdef DEBUG_BC
cout<<" with disc "<<-bc<<endl;
#endif
}
}
#ifdef DEBUG_BC
else
{
cout << "bc already set to "<<bc<<endl;
}
#endif
return bc;
}
int newform::is_base_change(void)
{
if(!(nf->N.is_Galois_stable()))
return 0;
auto ap = aplist.begin();
auto pr=Quadprimes::list.begin();
Qideal N(nf->N);
while(ap!=aplist.end() && pr!=Quadprimes::list.end())
{
long api = *ap++;
Quadprime p0 = *pr++;
#ifdef DEBUG_BC
cout<<"p="<<p0<<" has ap="<<api<<endl;
#endif
if(!p0.is_Galois_stable()) // this prime not inert or ramified
{
if (ap==aplist.end()) // the conjugate ap is not known
return 1;
long apj = *ap++;
Quadprime P1 = *pr++;
// skip if either divides level:
if(p0.divides(N))
continue;
if(P1.divides(N))
continue;
#ifdef DEBUG_BC
cout<<"Next prime "<<P1<<" has ap="<<apj<<endl;
#endif
if(api!=apj) // ap mismatch
{
#ifdef DEBUG_BC
cout<<"Mismatch -- not base-change"<<endl;
#endif
return 0;
}
}
}
#ifdef DEBUG_BC
cout<<"All OK -- base-change"<<endl;
#endif
return 1;
}
int newform::is_base_change_twist(void)
{
auto ap = aplist.begin();
auto pr=Quadprimes::list.begin();
Qideal N(nf->N);
while(ap!=aplist.end() && pr!=Quadprimes::list.end())
{
long api = *ap++;
Quadprime p0 = *pr++;
//cout<<"p="<<p0<<" has ap="<<api<<endl;
if(!p0.is_Galois_stable()) // this prime not inert or ramified
{
if (ap==aplist.end()) // the conjugate ap is not known
{
//cout<<"All OK -- base-change up to twist"<<endl;
return 1;
}
// read next (conjugate) prime and eigenvalue:
long apj = *ap++;
Quadprime P1 = *pr++;
// skip if either divides level:
if(p0.divides(N))
continue;
if(P1.divides(N))
continue;
// Check the ap agree up to sign:
if(abs(api)!=abs(apj)) // ap mismatch
{
//cout<<"Mismatch -- not base-change-twist"<<endl;
return 0;
}
}
}
//cout<<"All OK -- base-change up to twist"<<endl;
return 1;
}
// if form is base-change, find the d s.t. the bc has eigenvalues in Q(sqrt(d))
int newform::base_change_discriminant(void)
{
if (is_base_change()==0) return 0;
int bcd = 1;
Qideal N(nf->N);
auto api = aplist.begin();
auto pr=Quadprimes::list.begin();
while(api!=aplist.end() && pr!=Quadprimes::list.end())
{
long ap = *api++;
Quadprime P = *pr++;
if(!P.is_inert())
continue;
if(P.divides(N)) // this prime is bad
continue;
long dp = ap+2*P.prime();
//cout<<"p="<<p<<" has ap="<<ap<<", disc = "<<dp;
dp = squarefree_part(dp);
//cout<<" with squarefree part "<<dp<<endl;
if (dp==0) continue;
if (bcd==1) // first one
{
bcd = dp;
}
else
{
if (dp!=bcd) // mismatch: not possible?
{
cout<<"\nWarning from base_change_discriminant(): bcd="<<bcd<<", dp="<<dp<<"; returning 0"<<endl;
//cout<<"mismatch: bcd=0"<<endl;
return 0;
}
}
}
return bcd;
}
// if form is twist of base-change, find the d s.t. the bc has eigenvalues in Q(sqrt(d)), if any
//
// Method: for each split P, d will be the squarefree part of either
// 2*p+a_P or 2*p-a_P, for some choice of sign depending on P. So we
// return d if there is a choice of signs giving the same d for all
// split P, otherwise 0.
//#define DEBUG_BCTD
int newform::base_change_twist_discriminant(void)
{
if (is_base_change_twist()==0) return 0;
int cmd = is_CM();
if (cmd!=0)
{
int bcd = -squarefree_part((Quad::d)/cmd);
#ifdef DEBUG_BCTD
cout << "base change twist and CM("<<cmd<<") so bcd = "<<bcd<<endl;
#endif
return bcd;
}
int bcd1 = 0, bcd2 = 0; // flags that they have not yet been set
int n_candidates = 0;
Qideal N(nf->N);
auto api = aplist.begin();
auto pr=Quadprimes::list.begin();
Quadprime P;
long ap;
while(pr!=Quadprimes::list.end() && n_candidates !=1)
{
P = *pr++;
int use_P = P.is_inert() && !P.divides(N);
if (!use_P)
{
if (api!=aplist.end())
{
++api; // must increment even if though this P is not being used
}
continue;
}
if (api!=aplist.end())
{
ap = *api++; // must increment even if this P is not being used
#ifdef DEBUG_BCTD
cout<<" - using stored aP = "<<ap<<" for P = "<<P<<"..."<<endl;
#endif
}
else
{
nf->makebases(); // does nothing if already made
#ifdef DEBUG_BCTD
cout<<" - computing aP for P = "<<P<<"..."<<flush;
#endif
ap = eigenvalueHecke(P);
#ifdef DEBUG_BCTD
cout<<" done, aP = "<<ap<<" for P = "<<P<<"..."<<endl;
#endif
}
long dp1 = ap + 2*P.prime();
long dp2 = dp1 - 2*ap;
#ifdef DEBUG_BCTD
cout<<"P="<<P<<" has aP="<<ap<<", discs "<<dp1<<", "<<dp2;
#endif
dp1 = squarefree_part(dp1);
dp2 = squarefree_part(dp2);
#ifdef DEBUG_BCTD
cout<<" with squarefree parts "<<dp1<<", "<<dp2<<endl;
#endif
if (dp1*dp2==0) continue;
if (n_candidates==0) // first pair, store
{
bcd1 = dp1;
bcd2 = dp2;
n_candidates = (bcd1==bcd2? 1: 2);
#ifdef DEBUG_BCTD
cout<<" possible d: "<<bcd1<<", "<<bcd2<<"; "<<n_candidates<<" candidate(s)"<<endl;
#endif
}
else // see if only one is a repeat, if so it's the value we want
{
if ((bcd1!=-1)&&(dp1!=bcd1)&&(dp2!=bcd1)) // then bcd1 is bogus
{
#ifdef DEBUG_BCTD
cout<<" eliminating d="<<bcd1<<endl;
#endif
bcd1 = -1;
n_candidates = int(bcd2>0);
}
if ((bcd2!=-1)&&(dp1!=bcd2)&&(dp2!=bcd2)) // then bcd2 is bogus
{
#ifdef DEBUG_BCTD
cout<<" eliminating d="<<bcd2<<endl;
#endif
bcd2 = -1;
n_candidates = int(bcd1>0);
}
if ((bcd1==-1)&&(bcd2==-1)) // then we have no remaining candidates
{
#ifndef DEBUG_BCTD
if (nf->verbose)
#endif
cout<<"\nbase_change_twist_discriminant() finds no suitable d!"<<endl;
return 0;
}
// otherwise we still have at least one candidate, and continue
}
}
// At this point, we have a valid d if and only if exactly one of
// bcd1, bcd2 is positive (or both if they are equal)
if ((bcd1>0)&&(bcd2>0)&&(bcd1==bcd2))
{
#ifdef DEBUG_BCTD
cout<<" base_change_twist_discriminant() returns d = "<<bcd1<<endl;
#endif
return bcd1;
}
if ((bcd1>0)&&(bcd2<=0))
{
#ifdef DEBUG_BCTD
cout<<" base_change_twist_discriminant() returns d = "<<bcd1<<endl;
#endif
return bcd1;
}
if ((bcd2>0)&&(bcd1<=0))
{
#ifdef DEBUG_BCTD
cout<<" base_change_twist_discriminant() returns d = "<<bcd2<<endl;
#endif
return bcd2;
}
cout<<"\nWarning from base_change_twist_discriminant(): bcd1="<<bcd1<<", bcd2="<<bcd2<<"; returning 0"<<endl;
return 0;
}
// Test if form is CM, return 0 or the CM disc
int newform::is_CM(void)
{
if (cm==1) // not already set
{
auto api = aplist.begin();
auto pr=Quadprimes::list.begin();
while(api!=aplist.end() && pr!=Quadprimes::list.end())
{
long ap = *api++;
Quadprime P = *pr++;
if (ap==0) continue;
long dp = ap*ap-4*I2long(P.norm());
//cout<<"P="<<P<<" has aP="<<ap<<", disc = "<<dp;
if (dp==0) continue;
dp = squarefree_part(dp);
//cout<<" with squarefree part "<<dp<<endl;
if (cm==1) // first one
{
cm = dp;
//cout << "Setting cm to "<<cm<<endl;
continue;
}
if (dp!=cm) // mismatch: not CM
{
//cout<<"mismatch: CM=0"<<endl;
cm = 0;
break;
}
}
}
//cout << "Returning cm = "<<cm<<endl;
return cm;
}
// Return this twisted by the genus character associated to D
newform newform::twist(const INT& D)
{
newform f = *this; //copy constructor
if (D==ONE)
return f;
//cout<<"Twisting newform by discriminant "<<D<<endl;
//cout<<"aP before: "<<f.aplist<<endl;
// Twist the ap:
auto Pi = Quadprimes::list.begin();
auto aPi=f.aplist.begin();
for (;
aPi!=f.aplist.end();
++Pi, ++aPi)
(*aPi) *= Pi->genus_character(D);
//cout<<"aP after: "<<f.aplist<<endl;
// Twist the AL eigenvalues:
auto Qi = nf->badprimes.begin();
auto aQi=f.aqlist.begin();
for (;
aQi!=f.aqlist.end();
++Qi, ++aQi)
(*aQi) *= Qi->genus_character(D);
// Twist the sfe:
f.sfe *= nf->N.genus_character(D);
return f;
}
void newforms::makeh1plus(void)
{
if(!h1)
{
h1 = new homspace(N, /*plus*/ 1, /*verbose*/ 0, characteristic);
nfhmod=hmod = h1->h1hmod();
}
}
newforms::newforms(const Qideal& iN, int disp, long ch)
: N(iN), verbose(disp), n2r(Quad::class_group_2_rank), characteristic(ch), have_bases(0)
{
nchi = 1<<n2r;
level_is_square = N.is_square();
// nulist is a list of n2r ideals coprime to N whose classes generate the 2-torsion
if ((characteristic==0) && (n2r > 0))
{
nulist = make_nulist(N);
if (verbose>1)
cout<<"nulist: "<<nulist<<endl;
possible_self_twists = N.possible_unramified_twists();
if (verbose>1)
cout<<"possible unramified self twist discriminants at this level: "<<possible_self_twists<<endl;
}
// badprimes is a list of all primes Q|N
badprimes = N.factorization().sorted_primes();
nwq = 0; // prevents any W_Q being used for splitting
// goodprimes is a list of at least nap good primes (excluding those
// dividing characteristic if >0), includinge at least one principal
// one which has index iP0;
nap = MAXDEPTH;
goodprimes = make_goodprimes(N, nap, iP0, characteristic);
nap = goodprimes.size(); // it may be > original nap
if (nap!=MAXDEPTH && verbose)
cout<<" nap changed to "<<nap<<" since goodprimes = "<<goodprimes<<endl;
P0 = goodprimes[iP0];
nP0 = I2long(P0.norm());
// P0 is the smallest good principal prime: and iP0 its index (in
// plist, which starts with the bad primes and then the good
// primes in order). P0 must be principal since we have only
// implemented maninvector() for principal primes.
if (verbose>1)
{
cout << "good primes used: "<<goodprimes<<endl;
}
h1=0;
of=0;
nfhmod=0;
}
// instantiations of virtual functions required by the splitter_base class:
mat newforms::opmat(int i, int dual, int verb)
{
return h1->calcop(h1matop(i),dual,verb);
}
vec newforms::opmat_col(int i, int j, int verb)
{
return h1->calcop_col(h1matop(i),j, verb);
}
mat newforms::opmat_cols(int i, const vec& jlist, int verb)
{
return h1->calcop_cols(h1matop(i),jlist, verb);
}
mat newforms::opmat_restricted(int i, const subspace& s, int dual, int verb)
{
return h1->calcop_restricted(h1matop(i),s,dual,verb);
}
smat newforms::s_opmat(int i, int dual, int)
{
return h1->s_calcop(h1matop(i),0, dual, verbose);
}
smat newforms::s_opmat_cols(int i, const vec& jlist, int)
{
return h1->s_calcop_cols(h1matop(i),jlist, verbose);
}
smat newforms::s_opmat_restricted(int i, const ssubspace& s, int dual, int)
{
return h1->s_calcop_restricted(h1matop(i),s,dual,0);
}
//#define DEBUG_LAMBDA
void newforms::find_lambdas()
{
vector<int> gotlambda(n1ds);
int i, nfound=0;
#ifdef DEBUG_LAMBDA
if(verbose) cout<<"Looking for twisting primes.\n";
#endif
for (i=0; i<n1ds; i++)
if(nflist[i].pdot!=0)
{
#ifdef DEBUG_LAMBDA
if(verbose) cout<<"Newform "<<i<<": lambda=1 will do.\n";
#endif
nflist[i].lambda=Quad::one;
nflist[i].lambdadot=nflist[i].pdot;
gotlambda[i]=1;
nfound++;
}
else
{
nflist[i].lambda=Quad::zero; // indicates no lambda exists (yet)
nflist[i].lambdadot=0;
gotlambda[i]=0;
}
#ifdef DEBUG_LAMBDA
if(verbose)cout<<nfound<<" easy cases out of "<<n1ds<<endl;
#endif
if (level_is_square || !N.is_principal() || n2r>0)
{
return;
}
for( auto& L : Quadprimes::list)
{
if (nfound==n1ds) break;
if (L.divides(TWO)) continue;
if (L.divides(N)) continue;
if (!L.is_principal()) continue;
Quad lam = L.gen();
#ifdef DEBUG_LAMBDA
if(verbose)cout << "Testing lambda = " << L << " = ("<<lam<<"): principal, odd, good"<<endl;
#endif
vector<Quad> lamres = L.residues();
if(squaremod(fundunit,lam,lamres)==1)
{
#ifdef DEBUG_LAMBDA
if(verbose)cout<<"passed second test: fundamental unit is a square"<<endl;
#endif
// TODO: work out what to do here if N is not principal!
int chimod = squaremod(N.gen(),lam,lamres);
vector<int> chitab = makechitable(lam,lamres);
vec mvtw = h1->manintwist(lam,lamres,chitab, 1);
for(int j=0; (j<n1ds)&&(nfound<n1ds); j++)
{
if(gotlambda[j]==0)
{
#ifdef DEBUG_LAMBDA
if(verbose)cout<<"Newform # "<<j<<": ";
#endif
newform& nfj = nflist[j];
int ldot = abs(mvtw[j+1]); // j based at 0 but vec mvtw based at 1
if(ldot&&((chimod*nfj.sfe)==+1))
{
#ifdef DEBUG_LAMBDA
if(verbose)cout<<"Success! ";
#endif
nfj.loverp = rational(ldot, Quad::nunits * nfj.cuspidalfactor);
nfj.lambda = lam;
nfj.lambdadot = ldot;
gotlambda[j] = 1;
nfound++;
}
}
#ifdef DEBUG_LAMBDA
if(verbose)cout<<endl;
#endif
}
}
}
}