Example #1
0
def genus2_lookup_equation(f):
    if not has_magma():
        return None
    f.replace(" ", "")
    # TODO allow other variables, if so, fix the error message accordingly
    R = PolynomialRing(QQ, 'x')
    if ("x" in f and "," in f) or "],[" in f:
        if "],[" in f:
            e = f.split("],[")
            f = [
                R(literal_eval(e[0][1:] + "]")),
                R(literal_eval("[" + e[1][0:-1]))
            ]
        else:
            e = f.split(",")
            f = [R(str(e[0][1:])), R(str(e[1][0:-1]))]
    else:
        f = R(str(f))
    try:
        C = magma.HyperellipticCurve(f)
        g2 = magma.G2Invariants(C)
    except TypeError:
        return None
    g2 = str([str(i) for i in g2]).replace(" ", "")
    for r in db.g2c_curves.search({'g2_inv': g2}):
        eqn = literal_eval(r['eqn'])
        D = magma.HyperellipticCurve(R(eqn[0]), R(eqn[1]))
        # there is recursive bug in sage
        if str(magma.IsIsomorphic(C, D)) == 'true':
            return r['label']
    return None
Example #2
0
def genus2_lookup_equation(input_str):
    # retuns:
    # label, C_str
    # None, C_str when it couldn't find it in the DB
    # "", input_str when it fails to parse
    # 0, C_str when it fails to start magma
    R = PolynomialRing(QQ, "x")
    y = PolynomialRing(R, "y").gen()

    def read_list_coeffs(elt):
        if not elt:
            return R(0)
        else:
            return R([int(c) for c in elt.split(",")])

    if ZLLIST_RE.fullmatch(input_str):
        input_str = input_str.strip('[').strip(']')
        fg = [read_list_coeffs(elt) for elt in input_str.split('],[')]
    elif ZLIST_RE.fullmatch(input_str):
        input_str = input_str.strip('[').strip(']')
        fg = [read_list_coeffs(input_str), R(0)]
    else:
        input_str = input_str.strip('[').strip(']')
        fg = [R(list(coeff_to_poly(elt))) for elt in input_str.split(",")]
    if len(fg) == 1:
        fg.append(R(0))

    C_str_latex = fr"\({latex(y**2 + y*fg[1])} = {latex(fg[0])}\)"
    try:
        C = magma.HyperellipticCurve(fg)
        g2 = magma.G2Invariants(C)
    except TypeError:
        raise ValueError(f'{C_str_latex} invalid genus 2 curve')
    g2 = str([str(i) for i in g2]).replace(" ", "")
    for r in db.g2c_curves.search({"g2_inv": g2}):
        eqn = literal_eval(r["eqn"])
        fgD = [R(eqn[0]), R(eqn[1])]
        D = magma.HyperellipticCurve(fgD)
        # there is recursive bug in sage
        if str(magma.IsIsomorphic(C, D)) == "true":
            if fgD != fg:
                flash_info(f"The requested genus 2 curve {C_str_latex} is isomorphic to the one below, but uses a different defining polynomial.")
            return r["label"], ""
    return None, C_str_latex
Example #3
0
def mHyperellipticCurve(f, h):
    return magma.HyperellipticCurve(magma(f), magma(h))