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
|
// FILE MODDATA.CC: Implementation of member functions for class moddata
//////////////////////////////////////////////////////////////////////////
//
// Copyright 1990-2012 John Cremona
//
// This file is part of the eclib package.
//
// eclib is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
//
// eclib is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// along with eclib; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
//
//////////////////////////////////////////////////////////////////////////
#include <eclib/moddata.h>
#include <iostream>
level::level(long n, long neigs)
{
//cout<<"Creating a class level with n = " << n << endl;
modulus=n;
plist=pdivs(n); npdivs=plist.size();
dlist=posdivs(n); ndivs=dlist.size();
nap=neigs;
primelist=plist;
primevar pr; long p; p0=0;
while(primelist.size()<(unsigned)nap)
{
p=pr;
if (ndivides(p,modulus))
{
if(p0==0) p0=p;
primelist.push_back(p);
}
pr++;
}
sqfac=1;
for(long ip=0; ip<npdivs; ip++)
{
p = plist[ip];
if(::divides(p*p,n)) sqfac*=p;
}
long rootn=(long)(sqrt((double)n)+0.1); // rounded down
squarelevel=(n==rootn*rootn);
}
long bezout_x(long aa, long bb, long& xx)
{long a,b,c,x,oldx,newx,q;
oldx = 1; x = 0; a = aa; b = bb;
while (b!=0)
{ q = a/b;
c = a - q*b; a = b; b = c;
newx = oldx - q*x; oldx = x; x = newx;
}
if (a<0) {xx=-oldx; return(-a);}
else {xx= oldx; return( a);}
}
moddata::moddata(long n) :level(n)
{
// cout << "In constructor moddata::moddata.\n";
long i,p,x,d,nd,nnoninv;
phi=psi=modulus;
for(i=0; i<npdivs; i++)
{ p = plist[i];
phi -= phi/p;
psi += psi/p;
}
nsymb = psi;
nsymb1 = 2*modulus-phi;
nsymb2 = nsymb-nsymb1;
invlist.resize(modulus); //codes
noninvlist.resize(modulus-phi); //list of non-units
noninvdlist.resize(modulus-phi); //list of divisors for each nonunit
gcdtable.resize(modulus); //list of gcds mod N
unitdivlist.resize(modulus); //list of units s.t. u*res | N
nnoninv=0;
for (i=0; i<modulus; i++) //set up codes
{ d = bezout_x(i,modulus,x);
gcdtable[i]=d;
if (d==1) {unitdivlist[i] = invlist[i] = reduce(x); }
else
{invlist[i]=-nnoninv;
noninvlist[nnoninv]=i;
noninvdlist[nnoninv]=-1;
if (d<modulus)
{
for (nd=0; (nd<ndivs)&&(dlist[nd]!=d); nd++) ;
noninvdlist[nnoninv]=nd;
}
nnoninv++;
if(::gcd(x,modulus)!=1) // adjust x so coprime to N
{
long m=modulus/d, mm, mpower, mmold,u,v;
mpower=mm=m; mmold=1;
while(mm!=mmold)
{
mpower=xmodmul(m,mpower,modulus);
mmold=mm;
mm=::gcd(mpower,modulus);
}
bezout(mm,modulus/mm,u,v);
// Must be careful of overflow!
x = (x*v)%mm;
x = (x*(modulus/mm))%modulus;
x = (x+(u*mm))%modulus;
}
unitdivlist[i]=x;
#if(0)
//Check:
if(::gcd(x,modulus)!=1)
{
cout<<"Error: unitdivlist["<<i<<"] = "<<x<<" is not coprime to "<<modulus<<endl;
abort();
}
if(((i*x-d)%modulus)!=0)
{
cout<<"Error: unitdivlist["<<i<<"] = "<<x<<" is wrong"<<endl;
abort();
}
#endif
}
}
if (ndivs>0) {dstarts.reserve(ndivs);}
}
void moddata::display() const
{
cout << "Level = " << modulus << "\n";
cout << "Number of symbols = " << nsymb << "\n";
cout << ndivs << " non-trivial divisors: " << dlist << endl;
cout << npdivs << " prime divisors: " << plist << endl;
cout << "invlist: " << invlist << endl;
cout << "noninvlist: " << noninvlist << endl;
cout << "noninvdlist: " << noninvdlist << endl;
cout << "gcdtable: " << gcdtable << endl;
cout << "unitdivlist: " << unitdivlist << endl;
}
string of_filename(long n, char c)
{
stringstream s;
s << getenv("OF_DIR");
if (s.str().empty()) {s.clear(); s<<nf_filename(n,c);}
else { s << "/" << c << n; }
return s.str();
}
string nf_filename(long n, char c)
{
stringstream s;
s << getenv("NF_DIR");
if (s.str().empty()) {s.clear(); s<<"./newforms";}
s << "/" << c << n;
return s.str();
}
|