def _convertToMonicNf(nf, timeout):

    pariStr = "PRIVATEconvertToMonicNf = nfinit(%s, 3)" % nf.printMagma()
    print pariStr
    print timeout
    r       = pari.pari_eval(pariStr, timeout = timeout)
    nf      = Polynomial.parseFromMagma(
        pari.pari_eval("PRIVATEconvertToMonicNf[1].pol", timeout = timeout))
    newExpressionForX = Polynomial.parseFromMagma(
        pari.pari_eval("PRIVATEconvertToMonicNf[2].pol", timeout = timeout))

    return nf, newExpressionForX
Пример #2
0
def parse_primary_decomposition(s_with_backslash):
    """
    >>> p = parse_primary_decomposition(_magma_sample)
    >>> len(p)
    1
    >>> p = p[0]
    >>> len(p)
    3
    >>> str(p[0])
    '- 1 + c_01_0'
    >>> str(p[1])
    '1 + c_02_0 + t'
    >>> str(p[2])
    '1 + t + t^2'
    """

    s = re.search(
        "PRIMARY=DECOMPOSITION=BEGINS=HERE\s*"
        "("
        "\[\s*"
        "(([^\]]*\[[^\]]*\],?\s*)*)"
        "\]\s*"
        ")+"
        "PRIMARY=DECOMPOSITION=ENDS=HERE",
        s_with_backslash,re.DOTALL)

    if not s:
        raise Exception, "Invalid Primary Decomposition"

    s_with_backslash = s.group(2)
    
    s = processEndOfLineBackslashes(s_with_backslash)

    components = re.findall(
        "Ideal of Polynomial ring.*?"
        "Dimension (\d+).*?"
        "(Size of variety over algebraically closed field: (\d+).*?)?"
        "Groebner basis:\s*"
        "\[([^\]]*)\]",
        s)

    def parseNumberOfPoints(s):
        if s == '':
            return None
        else:
            return int(s)

    components= [
        PrimeIdeal(
            [ Polynomial.parseFromMagma(p) for p in polys.split(',') ],
            dimension = int(dimension), 
            numberOfPoints = parseNumberOfPoints(numberOfPoints))
        for dimension, tmp, numberOfPoints, polys in components]

    return components
def _solveExactlyOverNumberField(univariatePoly, nf, timeout):
    
    variable = univariatePoly.variables()[0]

    def convertXtoY(p):
        return p.substitute({'x' : Polynomial.fromVariableName('y')})

    univariatePoly = univariatePoly.convertCoefficients(convertXtoY)
    univariatePoly = univariatePoly.substitute(
        { variable : Polynomial.constantPolynomial(
            Polynomial.fromVariableName('x'))})

    if not nf:
        assert univariatePoly.isConstant()
        newSolution       = Polynomial.fromVariableName('x')
        newNf             = univariatePoly.getConstant()
        newExpressionForX = Polynomial.constantPolynomial(0)
    else:
        nf = convertXtoY(nf)

        pariStr = "PRIAVTEsEONF = rnfequation(nfinit(%s), %s, 1)" % (
            nf, univariatePoly)

        print pariStr
        print timeout
        r = pari.pari_eval(pariStr, timeout = timeout)
        # print r

        newNf              = Polynomial.parseFromMagma(pari.pari_eval(
                "PRIAVTEsEONF[1]", timeout = timeout))
        newExpressionForX  = Polynomial.parseFromMagma(pari.pari_eval(
                "PRIAVTEsEONF[2].pol", timeout = timeout))
        factor             = int(pari.pari_eval(
                "PRIAVTEsEONF[3]", timeout = timeout))
        newSolution = (
            Polynomial.fromVariableName('x')
            - Polynomial.constantPolynomial(factor) * newExpressionForX)

    return newSolution, newNf, newExpressionForX
def process_file(trig_file):

    d,in_filename = tempfile.mkstemp()

    tmp_in_file = open(in_filename, 'wb')
    tmp_in_file.write("r f %s\n" % trig_file)
    tmp_in_file.write("set precision 15\n")
    tmp_in_file.write("set digits_printed 120 f\n")
    tmp_in_file.write("print solution_type\n")
    tmp_in_file.write("print volume\n")
    #tmp_in_file.write("print complex_volume\n")
    tmp_in_file.write("quit\n")
    tmp_in_file.close()

    l = subprocess.Popen("ulimit -t 1; snap <" + in_filename, shell=True, stdout = subprocess.PIPE)
    s = l.stdout.read()

    if not ("solution type: geometric" in s or "solution type: nongeometric" in s):
        return None

    try:
        os.unlink(in_filename)
    except:
        pass

    d,in_filename = tempfile.mkstemp()
    tmp_in_file = open(in_filename, 'wb')
    tmp_in_file.write("r f %s\n" % trig_file)
    tmp_in_file.write("set degree 7\n")
    tmp_in_file.write("set precision 15\n")
    tmp_in_file.write("set digits_printed 120 f\n")
    tmp_in_file.write("compute invariant_trace_field\n")
    tmp_in_file.write("quit\n")
    tmp_in_file.close()

    l = subprocess.Popen("ulimit -t 20; snap <" + in_filename, shell=True, stdout = subprocess.PIPE)
    s2 = l.stdout.read()

    try:
        os.unlink(in_filename)
    except:
        pass

    r = re.search("Complex volume: (.*)",s)

    rcvol = '"-"'
    icvol = '"-"'

    if r:
        cvol = number(r.group(1))
        rcvol = str(cvol.real())
        icvol = str(cvol.imag())

    r = re.search("Volume is: (.*)", s)

    if r:
        rcvol = r.group(1)

    f = re.search("Invariant trace field: (.*) \[",s2)
    fp = '-'
    fdeg = '-'

    if f:
        fp = f.group(1)
        fdeg = str(Polynomial.parseFromMagma(fp).degree())

    
    if re.search(r"\(-?\d+,-?\d+\)", trig_file):
        if "(0,0)" in trig_file: # manifold is cusped if there is an unfilled cusped
            oc = "cusped"
        else:
            oc = "closed"
    else:
        oc = "cusped"

    t = read_triangulation_from_file(trig_file)

    return ('"%s",%s,%d,%s,%s,"%s",%s'
            % (trig_file.split('/')[-1].replace('.trig',''),
               oc,
               t.num_tets,
               rcvol, icvol, fp, fdeg))