Example #1
0
def do_import(ll):
    dim,det,level,gram,density,hermite,minimum,kissing,shortest,aut,theta_series,class_number,genus_reps,name,comments = ll
    mykeys = ['dim','det','level','gram','density','hermite', 'minimum','kissing','shortest','aut','theta_series','class_number','genus_reps','name','comments']
    data = {}
    for j in range(len(mykeys)):
        data[mykeys[j]] = ll[j]
	
    blabel = base_label(data['dim'],data['det'],data['level'], data['class_number'])
    data['base_label'] = blabel
    data['index'] = label_lookup(blabel)
    label= last_label(blabel, data['index'])
    data['label'] = label
 
    lattice = lat.find_one({'label': label})

    if lattice is None:
        print "new lattice"
        print "***********"
        print "check for isometries..."
        A=data['gram'];
        n=len(A[0])
        d=matrix(A).determinant()
        result=[B for B in lat.find({'dim': int(n), 'det' : int(d)}) if isom(A, B['gram'])]
        if len(result)>0:
            print "... the lattice with base label "+ blabel + " is isometric to " + str(result[0]['gram'])
            print "***********"
        else:
            lattice = data
    else:
        print "lattice already in the database"
        lattice.update(data)
    if saving:
        lat.update({'label': label} , {"$set": lattice}, upsert=True)
Example #2
0
def lattice_search_isometric(res, info, query):
    """
    We check for isometric lattices if the user enters a valid gram matrix
    but not one stored in the database

    This may become slow in the future: at the moment we compare against
    a list of stored matrices with same dimension and determinant
    (just compare with respect to dimension is slow)
    """
    if info['number'] == 0 and info.get('gram'):
        A = query['gram']
        n = len(A[0])
        d = matrix(A).determinant()
        for gram in db.lat_lattices.search({'dim': n, 'det': int(d)}, 'gram'):
            if isom(A, gram):
                query['gram'] = gram
                proj = lattice_search_projection
                count = parse_count(info)
                start = parse_start(info)
                res = db.lat_lattices.search(query, proj, limit=count, offset=start, info=info)
                break

    for v in res:
        v['min'] = v.pop('minimum')
    return res
Example #3
0
def do_import(ll):
    dim,det,level,gram,density,hermite,minimum,kissing,shortest,aut,theta_series,class_number,genus_reps,name,comments = ll
    mykeys = ['dim','det','level','gram','density','hermite', 'minimum','kissing','shortest','aut','theta_series','class_number','genus_reps','name','comments']
    data = {}
    for j in range(len(mykeys)):
        data[mykeys[j]] = ll[j]

    blabel = base_label(data['dim'],data['det'],data['level'], data['class_number'])
    data['base_label'] = blabel
    data['index'] = label_lookup(blabel)
    label= last_label(blabel, data['index'])
    data['label'] = label
 
    lattice = lat.find_one({'label': label})

    if lattice is None:
        print("new lattice")
        print("***********")
        print("check for isometries...")
        A=data['gram'];
        n=len(A[0])
        d=matrix(A).determinant()
        result=[B for B in lat.find({'dim': int(n), 'det' : int(d)}) if isom(A, B['gram'])]
        if len(result)>0:
            print("... the lattice with base label "+ blabel + " is isometric to " + str(result[0]['gram']))
            print("***********")
        else:
            lattice = data
    else:
        print("lattice already in the database")
        lattice.update(data)
    if saving:
        lat.update({'label': label} , {"$set": lattice}, upsert=True)
Example #4
0
File: main.py Project: LMFDB/lmfdb
def lattice_search_isometric(res, info, query):
    """
    We check for isometric lattices if the user enters a valid gram matrix
    but not one stored in the database

    This may become slow in the future: at the moment we compare against
    a list of stored matrices with same dimension and determinant
    (just compare with respect to dimension is slow)
    """
    if info['number'] == 0 and info.get('gram'):
        A = query['gram']
        n = len(A[0])
        d = matrix(A).determinant()
        for gram in db.lat_lattices.search({'dim': n, 'det': int(d)}, 'gram'):
            if isom(A, gram):
                query['gram'] = gram
                proj = lattice_search_projection
                count = parse_count(info)
                start = parse_start(info)
                res = db.lat_lattices.search(query, proj, limit=count, offset=start, info=info)
                break

    for v in res:
        v['min'] = v.pop('minimum')
    return res
Example #5
0
def add_lattice_nf(ll):
    n_field, gram_input = ll
    gram_input = [[int(i) for i in l] for l in gram_input]

    R = PolynomialRing(QQ, 'x')
    nf_label = poly_to_field_label(R(n_field))

    lattice = l1.find_one({'gram': gram_input})
    if lattice is None:
        n = len(gram_input[0])
        d = matrix(gram_input).determinant()
        result = [
            B for B in l1.find({
                'dim': int(n),
                'det': int(d)
            }) if isom(gram_input, B['gram'])
        ]
        if len(result) == 1:
            lat_label = result[0]['label']
            is_lat_in = "yes"
        elif len(result) > 1:
            print "... need to be checked ..."
            print "***********"
        else:
            lat_label = "new"
            is_lat_in = gram_input
    else:
        lat_label = lattice['label']
        is_lat_in = "yes"

    try:
        lab = nf_label + lat_label
    except:
        print nf_label, lat_label
        print "fail"

    res = l2.find_one({'label': lab})
    if res is None:
        print "new data"
        if saving:
            l2.insert_one({
                'nf_label': nf_label,
                'lat_label': lat_label,
                'is_lat_in': is_lat_in,
                'label': lab
            })
    else:
        print "data already in the database"
Example #6
0
def add_lattice_nf(ll):
    n_field,gram_input = ll
    gram_input=[[int(i) for i in l] for l in gram_input] 

    R = PolynomialRing(QQ, 'x');
    nf_label = poly_to_field_label(R(n_field))

    lattice = l1.find_one({'gram': gram_input })
    if lattice is None:
        n=len(gram_input[0])
        d=matrix(gram_input).determinant()
        result=[B for B in l1.find({'dim': int(n), 'det' : int(d)}) if isom(gram_input, B['gram'])]
        if len(result)==1:
            lat_label =result[0]['label']
            is_lat_in = "yes"
        elif len(result)>1:
            print "... need to be checked ..."
            print "***********"
        else :
            lat_label = "new"
            is_lat_in = gram_input
    else:
       lat_label=lattice['label']
       is_lat_in = "yes"
    
    try:
        lab=nf_label+lat_label
    except:
        print nf_label, lat_label
        print "fail"
            
    res=l2.find_one({'label': lab })
    if res is None:
        print "new data"
        if saving:
            l2.insert_one({'nf_label': nf_label, 'lat_label': lat_label, 'is_lat_in' : is_lat_in, 'label': lab})
    else:
        print "data already in the database"
Example #7
0
def lattice_search(**args):
    info = to_dict(args)  # what has been entered in the search boxes

    if 'download' in info:
        return download_search(info)

    if 'label' in info and info.get('label'):
        return lattice_by_label_or_name(info.get('label'))

    query = {}
    try:
        for field, name in (('dim','Dimension'),('det','Determinant'),('level',None),
                            ('minimum','Minimal vector length'), ('class_number',None), ('aut','Group order')):
            parse_ints(info, query, field, name)
        # Check if length of gram is triangular
        gram = info.get('gram')
        if gram and not (9 + 8*ZZ(gram.count(','))).is_square():
            flash(Markup("Error: <span style='color:black'>%s</span> is not a valid input for Gram matrix.  It must be a list of integer vectors of triangular length, such as [1,2,3]." % (gram)),"error")
            raise ValueError
        parse_list(info, query, 'gram', process=vect_to_sym)
    except ValueError as err:
        info['err'] = str(err)
        return search_input_error(info)

    count = parse_count(info,50)
    start = parse_start(info)

    info['query'] = dict(query)
    res = lattice_db().find(query).sort([('dim', ASC), ('det', ASC), ('level', ASC), ('class_number', ASC), ('label', ASC), ('minimum', ASC), ('aut', ASC)]).skip(start).limit(count)
    nres = res.count()

    # here we are checking for isometric lattices if the user enters a valid gram matrix but not one stored in the database_names, this may become slow in the future: at the moment we compare against list of stored matrices with same dimension and determinant (just compare with respect to dimension is slow)

    if nres==0 and info.get('gram'):
        A=query['gram'];
        n=len(A[0])
        d=matrix(A).determinant()
        result=[B for B in lattice_db().find({'dim': int(n), 'det' : int(d)}) if isom(A, B['gram'])]
        if len(result)>0:
            result=result[0]['gram']
            query_gram={ 'gram' : result }
            query.update(query_gram)
            res = lattice_db().find(query)
            nres = res.count()

    if(start >= nres):
        start -= (1 + (start - nres) / count) * count
    if(start < 0):
        start = 0

    info['number'] = nres
    info['start'] = int(start)
    info['more'] = int(start + count < nres)
    if nres == 1:
        info['report'] = 'unique match'
    else:
        if nres == 0:
            info['report'] = 'no matches'
        else:
            if nres > count or start != 0:
                info['report'] = 'displaying matches %s-%s of %s' % (start + 1, min(nres, start + count), nres)
            else:
                info['report'] = 'displaying all %s matches' % nres

    res_clean = []
    for v in res:
        v_clean = {}
        v_clean['label']=v['label']
        v_clean['dim']=v['dim']
        v_clean['det']=v['det']
        v_clean['level']=v['level']
        v_clean['class_number']=v['class_number']
        v_clean['min']=v['minimum']
        v_clean['aut']=v['aut']

        res_clean.append(v_clean)

    info['lattices'] = res_clean

    t = 'Integral Lattices Search Results'
    bread = [('Lattices', url_for(".lattice_render_webpage")),('Search Results', ' ')]
    properties = []
    return render_template("lattice-search.html", info=info, title=t, properties=properties, bread=bread, learnmore=learnmore_list())