Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/lattices/lattice_nf.py
1127 views
1
# -*- coding: utf-8 -*-
2
r""" Make database lattices and number fields
3
4
Note: This code can be run on all files in any order. Even if you
5
rerun this code on previously entered files, it should have no affect.
6
This code checks if the entry exists, if so returns that and updates
7
with new information. If the entry does not exist then it creates it
8
and returns that.
9
10
"""
11
12
import os
13
import os.path
14
15
from sage.all import QQ, PolynomialRing, matrix
16
from lmfdb.lattice.isom import isom
17
from lmfdb.number_fields.number_field import poly_to_field_label
18
19
20
from pymongo.mongo_client import MongoClient
21
C= MongoClient(port=37010)
22
import yaml
23
pw_dict = yaml.load(open(os.path.join(os.getcwd(), "passwords.yaml")))
24
username = pw_dict['data']['username']
25
password = pw_dict['data']['password']
26
C['Lattices'].authenticate('editor', password)
27
l1 = C.Lattices.lat
28
l2 = C.Lattices.lat_nf
29
30
saving = True
31
32
33
## Main importing function
34
35
def add_lattice_nf(ll):
36
n_field,gram_input = ll
37
gram_input=[[int(i) for i in l] for l in gram_input]
38
39
R = PolynomialRing(QQ, 'x')
40
nf_label = poly_to_field_label(R(n_field))
41
42
lattice = l1.find_one({'gram': gram_input })
43
if lattice is None:
44
n=len(gram_input[0])
45
d=matrix(gram_input).determinant()
46
result=[B for B in l1.find({'dim': int(n), 'det' : int(d)}) if isom(gram_input, B['gram'])]
47
if len(result)==1:
48
lat_label =result[0]['label']
49
is_lat_in = "yes"
50
elif len(result)>1:
51
print("... need to be checked ...")
52
print("***********")
53
else :
54
lat_label = "new"
55
is_lat_in = gram_input
56
else:
57
lat_label=lattice['label']
58
is_lat_in = "yes"
59
60
try:
61
lab=nf_label+lat_label
62
except Exception:
63
print(nf_label, lat_label)
64
print("fail")
65
66
res=l2.find_one({'label': lab })
67
if res is None:
68
print("new data")
69
if saving:
70
l2.insert_one({'nf_label': nf_label, 'lat_label': lat_label, 'is_lat_in' : is_lat_in, 'label': lab})
71
else:
72
print("data already in the database")
73
74