Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/artin_representations/old-import_art_nf.py
1128 views
1
#!/usr/local/bin/sage -python
2
3
import sys, os
4
import re
5
import json
6
from sage.all import ZZ
7
8
# find lmfdb and the top of the tree
9
mypath = os.path.realpath(__file__)
10
while os.path.basename(mypath) != 'lmfdb':
11
mypath = os.path.dirname(mypath)
12
# now move up one more time...
13
sys.path.append(mypath)
14
15
from lmfdb import db
16
17
rep=db.artin_reps
18
nfgal=db.artin_field_data
19
20
count = 0
21
old = 0
22
23
#utilities
24
25
# turn poly coefs into a string
26
def makels(li):
27
li2 = [str(x) for x in li]
28
return ','.join(li2)
29
30
# turn a conductor into a sortable string
31
# this uses length 4 prefix
32
def make_cond_key(D):
33
D1 = int(D.log(10))
34
return '%04d%s'%(D1,str(D))
35
36
maxint = (2**63)-1
37
38
def int_or_string(a):
39
if abs(a)< maxint:
40
return a
41
return str(a)
42
43
def fix_local_factors(gconj):
44
gconj['LocalFactors'] = [ [ [int_or_string(a) for a in b ] for b in c] for c in gconj['LocalFactors']]
45
return gconj
46
47
# Main programs
48
49
outrecs = []
50
51
def artrepload(l):
52
global count
53
global old
54
global outrecs
55
ar1 = rep.lucky({'Baselabel': l['Baselabel']})
56
if ar1 is not None:
57
old += 1
58
if (count+old) % 100==0:
59
print("%s new, %s old" %(str(count),str(old)))
60
return
61
l['Conductor'] = ZZ(l['Conductor'])
62
l['GaloisConjugates'] = [fix_local_factors(z) for z in l['GaloisConjugates']]
63
# Extract containing representation from the label
64
cont = l['Baselabel'].split('.')[2]
65
l['Container'] = cont
66
for s in ['BadPrimes', 'HardPrimes']:
67
l[s] = [int(z) for z in l[s]]
68
l['Galn'] = l['Galois_nt'][0]
69
l['Galt'] = l['Galois_nt'][1]
70
del l['Galois_nt']
71
l['GalConjSigns'] = [z['Sign'] for z in l['GaloisConjugates']]
72
#print str(l)
73
count +=1
74
outrecs.append(l)
75
if (count+old) % 100==0:
76
print("%s new, %s old" %(str(count),str(old)))
77
return
78
79
def nfgalload(l):
80
global count
81
global old
82
global outrecs
83
ff = nfgal.lucky({'Polynomial': l['Polynomial']})
84
if ff is not None:
85
old += 1
86
if (count+old) % 100==0:
87
print("%s new, %s old" %(str(count),str(old)))
88
return
89
90
artreps=l['ArtinReps']
91
artreps=[{'Baselabel': z[0][0], 'GalConj': z[0][1], 'CharacterField': z[1],
92
'Character': z[2]} for z in artreps]
93
l['ArtinReps']=artreps
94
l['Size'] = int(l['Size'])
95
outrecs.append(l)
96
count +=1
97
if (count+old) % 100==0:
98
print("%s new, %s old" %(str(count),str(old)))
99
return
100
101
102
# processing file names
103
for path in sys.argv[1:]:
104
print(path)
105
count = 0
106
old = 0
107
filename = os.path.basename(path)
108
fn = open(path)
109
if re.match(r'^nfgal', filename):
110
case = 'nfgal'
111
if re.match(r'^art', filename):
112
case = 'art rep'
113
for line in fn.readlines():
114
line = line.strip()
115
if re.match(r'\S',line):
116
l = json.loads(line)
117
if case == 'nfgal':
118
nfgalload(l)
119
if case == 'art rep':
120
artrepload(l)
121
if outrecs:
122
if case == 'nfgal':
123
nfgal.insert_many(outrecs)
124
if case == 'art rep':
125
rep.insert_many(outrecs)
126
print("%s new, %s old" %(str(count),str(old)))
127
fn.close()
128
129
130