-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP1N.cc
313 lines (297 loc) · 8.05 KB
/
P1N.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
// FILE P1N.CC: implementation of class for P^1(O_K/N) for an arbitrary ideal N
#include <iostream>
#include "P1N.h"
// utilities for a standard bijection between [0,1,...,n-1] and the
// product of [0,1,...,n_i-1] where n is the product of the n_i
long merge_indices(const vector<long>& nlist, const vector<long>& klist)
// return ((k1*n2+k2)*n3+k3)*n4+k4 (etc.)
// NB n1 is not used except implicitly
{
long tot=0;
auto n=nlist.begin()+1, k=klist.begin();
while (n!=nlist.end())
{
tot += *k++;
tot *= *n++;
}
tot += *k;
return tot;
}
vector<long> split_indices(const vector<long>& nlist, long k)
{
long tot=k;
auto n=nlist.rbegin();
vector<long> klist;
while (n!=nlist.rend())
{
std::ldiv_t qr = ldiv(tot, *n++);
tot = qr.quot;
klist.push_back(qr.rem);
}
std::reverse(klist.begin(), klist.end());
return klist;
}
P1N::P1N(const Qideal& I)
: N(I)
{
Factorization F = N.factorization(); // factorization is cached in N
np = F.size();
nrm = I2long(N.norm());
phi = psi = 1;
for (int i=0; i<np; i++)
{
long normp = I2long(F.prime(i).norm());
long e = F.exponent(i);
phi *= (normp-1);
psi *= (normp+1);
e--;
while (e--)
{
phi *= normp;
psi *= normp;
}
}
switch (np) {
case 0:
{
break; // nothing left to do
}
case 1:
{
residue_codes.reserve(nrm);
noninvertible_residue_indices.reserve(nrm-phi);
for(long i=0; i<nrm; i++)
{
Quad r = N.resnum(i), s;
if (N.is_coprime_to(r, s)) // r invertible with r*s = 1 (N)
{
residue_codes.push_back(N.numres(s));
}
else // r not invertible
{
residue_codes.push_back(-noninvertible_residue_indices.size());
noninvertible_residue_indices.push_back(i);
}
}
// cout << "P1N constructor, prime power case" << endl;
// cout << "Residues: " << N.residues() << endl;
// cout << "residue_codes: " << residue_codes << endl;
// cout << "noninvertible_residue_indices: " << noninvertible_residue_indices << endl;
break;
}
default: // not a prime power
{
P1PP.reserve(np);
psilist.reserve(np);
for (int i=0; i<np; i++)
{
P1N P1PPi(F.prime_power(i));
P1PP.push_back(P1PPi);
psilist.push_back(P1PPi.psi);
}
}
}
}
void P1N::make_symb(long i, Quad& c, Quad& d) // the i'th (c:d) symbol
{
if (np==0) // at level (1), the only symbol is (0:1), lifting to the identity matrix
{
c = Quad::zero;
d = Quad::one;
return;
}
if (np==1)
{
assert (i>=0);
assert (i<psi);
if (i<nrm)
{
c = N.resnum(i);
d = Quad::one;
}
else
{
c = Quad::one;
d = N.resnum(noninvertible_residue_indices[i-nrm]);
}
return;
}
// not a prime power, use CRT
vector<long> ilist = split_indices(i);
vector<Quad> clist, dlist;
clist.reserve(np);
dlist.reserve(np);
Quad ck, dk;
for (int k=0; k<np; k++)
{
P1PP[k].make_symb(ilist[k], ck, dk);
clist.push_back(ck);
dlist.push_back(dk);
}
c = N.factorization().solve_CRT(clist);
d = N.factorization().solve_CRT(dlist);
reduce(c, d);
return;
}
void P1N::reduce(Quad& c, Quad& d) // simplify c,d without changing (c:d)
{
// cout<<"Reducing (c:d)=("<<c<<":"<<d<<") mod "<<N<<"..."<<endl;
Quad u;
if (N.is_coprime_to(d,u)) // scale to (c:1)
{
c = N.reduce(c*u);
d = Quad::one;
// cout<<" -- returning ("<<c<<":"<<d<<")"<<endl;
return;
}
if (N.is_coprime_to(c,u)) // scale to (1:d)
{
d = N.reduce(d*u);
c = Quad::one;
// cout<<" -- returning ("<<c<<":"<<d<<")"<<endl;
return;
}
// divide by gcd(c,d) if it is principal
u = quadgcd(c,d); // if (c,d) is principal this is a generator, else 0
if (u.norm()>1)
{
c /= u;
d /= u;
// cout<<" -- after dividing by "<<u<<": ("<<c<<":"<<d<<")"<<endl;
}
else // at least divide out by the gcd of the contents
{
INT g = gcd(c.content(), d.content());
if (g>1)
{
c /= g;
d /= g;
// cout<<" -- after dividing by "<<u<<": ("<<c<<":"<<d<<")"<<endl;
}
}
return;
}
long P1N::index(const Quad& c, const Quad& d) // index i of (c:d)
{
if (np==0) return 0;
if (np==1)
{
// cout<<"Finding index of ("<<c<<":"<<d<<") mod "<<N<<"..."<<endl;
long t = residue_codes[N.numres(d)];
if (t>0) // d is invertible
return N.numres(c*N.resnum(t));
// now d is not invertible so c must be
t = residue_codes[N.numres(c)];
assert (t>0);
t = residue_codes[N.numres(d*N.resnum(t))];
assert (t<=0);
return nrm - t;
}
// general case, np>1 so not a prime power
vector<long> ilist;
ilist.reserve(np);
for (int i=0; i<np; i++)
ilist.push_back(P1PP[i].index(c,d));
return merge_indices(ilist);
}
// each M in GL2 permutes the (c:d) symbols by right multiplcation:
long P1N::apply(const mat22& M, long i)
{
if (M.is_scalar()) return i;
if (np==0) return 0;
if (np==1) // works in general but much simpler in this case (no CRT in constructing c,d)
{
Quad c, d;
make_symb(i, c, d);
M.apply_right(c,d);
return index(c,d);
}
// general case, np>1 so not a prime power
vector<long> jlist, ilist = split_indices(i);
jlist.reserve(np);
for (int k=0; k<np; k++)
jlist.push_back(P1PP[k].apply(M,ilist[k]));
return merge_indices(jlist);
}
// return a matrix [a, b; c, d] with det=1 and (c:d)= i'th symbol in P^1(N)
mat22 P1N::lift_to_SL2(long ind)
{
Quad c, d;
make_symb(ind, c, d); // this is reduced, in particular is (c:1) or (1:d) if possible
mat22 M = ::lift_to_SL2(N, c, d);
assert (M.is_unimodular());
assert (index(M.entry(1,0), M.entry(1,1))==ind);
return M;
}
// return a matrix [a, b; c, d] with det=1, c in M and (c:d) equal to
// the i'th symbol (requires M,N coprime). (u,v) should satisfy u+v=1
// with u in N, v in M.
mat22 P1N::lift_to_Gamma_0(long i, const Qideal& M, const Quad& u, const Quad& v)
{
Quad c, d;
make_symb(i, c, d); // this is reduced, in particular is (c:1) or (1:d) if possible
Qideal MN = M*N;
mat22 G = ::lift_to_Gamma_0(MN, c, d, u, v);
assert (G.is_unimodular());
assert (index(G.entry(1,0), G.entry(1,1))==i);
assert (M.contains(G.entry(1,0)));
return G;
}
// test functions
void P1N::check(int verbose) // checks indexing
{
if (verbose)
{
cout << "Testing P1(N) for N = " << N << ": ";
cout << "psi(N) = "<<psi<<endl;
}
long i;
Quad c, d;
for (i=0; i<psi; i++)
{
make_symb(i, c, d);
long j = index(c, d);
if (verbose)
{
cout << i << " --> ("<<c<<":"<<d << ") --> " << j << endl;
assert(i==j);
}
else
{
if (i!=j)
{
cout << i << " --> ("<<c<<":"<<d << ") --> " << j << endl;
}
}
}
}
void P1N::check_lifts(int verbose) // checks lifts to SL2 and Gamma_0(P) for a P coprime to N
{
long i;
Quad c, d, u, v;
Quadprime P = *std::find_if(Quadprimes::list.begin(), Quadprimes::list.end(),
[this](const Quadprime& Q) {return !Q.divides(N);});
// the first prime not dividing the level
P.is_coprime_to(N, u, v); // ignore return value (which is 1)
if (verbose)
{
cout << "Testing lifts from P1(N) to SL(2,O_K) and to Gamma_0(P) for N = " << N << " and P= "<<P<<":\n";
}
for (i=0; i<psi; i++)
{
make_symb(i, c, d);
mat22 M = lift_to_SL2(i);
if (verbose)
{
cout << i << " --> ("<<c<<":"<<d << ") lifts to " << M;
}
M = lift_to_Gamma_0(i, P, u, v);
if (verbose)
{
cout << " --> "<< M << " (in Gamma_0(P))" << endl;
}
// NB The lift_to_SL2() method already tests these assertions:
// assert(M.is_unimodular());
// assert (i==index(M.entry(1,0), M.entry(1,1)));
}
}