Exemple #1
0
def store_standard_laurent_system(polsys, **nbvar):
    r"""
    Stores the Laurent polynomials represented by the list of
    strings in *polsys* into the container for systems
    with coefficients in standard double precision.
    If *nbvar* is omitted, then the system is assumed to be square.
    Otherwise, suppose the number of variables equals 2 and pols is the list
    of polynomials, then **store_standard_laurent_system(pols, nbvar=2)**
    stores the polynomials in pols in the standard Laurent systems container.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
        import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    py2c_syscon_clear_standard_Laurent_system()
    dim = len(polsys)
    fail = 0
    py2c_syscon_initialize_number_of_standard_Laurentials(dim)
    for cnt in range(0, dim):
        pol = polsys[cnt]
        nchar = len(pol)
        if len(nbvar) == 0:
            fail = py2c_syscon_store_standard_Laurential(
                nchar, dim, cnt + 1, pol)
        else:
            nvr = list(nbvar.values())[0]
            fail = py2c_syscon_store_standard_Laurential(
                nchar, nvr, cnt + 1, pol)
        if (fail != 0):
            break
    return fail
Exemple #2
0
def support(nvr, pol):
    r"""
    The support of a multivariate polynomial is a set of exponents
    of the monomials that appear with nonzero coefficient.
    Given in *nvr* the number of variables and in *pol* a string
    representation of a polynomial in *nvr* variables,
    returns the support of the polynomial as a list of tuples.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
    import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    py2c_syscon_clear_standard_Laurent_system()
    py2c_syscon_initialize_number_of_standard_Laurentials(nvr)
    nchar = len(pol)
    fail = py2c_syscon_store_standard_Laurential(nchar, nvr, 1, pol)
    if(fail != 0):
        return fail
    else:
        # from phcpy.phcpy2c3 import py2c_syscon_number_of_Laurent_terms
        from phcpy.phcpy2c3 import py2c_giftwrap_support_size
        from phcpy.phcpy2c3 import py2c_giftwrap_support_string
        from phcpy.phcpy2c3 import py2c_giftwrap_clear_support_string
        # ntm = py2c_syscon_number_of_Laurent_terms(1)
        # print 'number of terms : %d' % ntm
        size = py2c_giftwrap_support_size()
        # print 'size of support :', size
        supp = py2c_giftwrap_support_string(size)
        # print 'support string :', supp
        py2c_giftwrap_clear_support_string()
        result = eval(supp)
        return result
Exemple #3
0
def store_standard_laurent_system(polsys, **nbvar):
    r"""
    Stores the Laurent polynomials represented by the list of
    strings in *polsys* into the container for systems
    with coefficients in standard double precision.
    If *nbvar* is omitted, then the system is assumed to be square.
    Otherwise, suppose the number of variables equals 2 and pols is the list
    of polynomials, then **store_standard_laurent_system(pols, nbvar=2)**
    stores the polynomials in pols in the standard Laurent systems container.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
        import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    py2c_syscon_clear_standard_Laurent_system()
    dim = len(polsys)
    py2c_syscon_initialize_number_of_standard_Laurentials(dim)
    for cnt in range(0, dim):
        pol = polsys[cnt]
        nchar = len(pol)
        if len(nbvar) == 0:
            fail = py2c_syscon_store_standard_Laurential(nchar, dim, cnt+1, pol)
        else:
            nvr = list(nbvar.values())[0]
            fail = py2c_syscon_store_standard_Laurential(nchar, nvr, cnt+1, pol)
        if(fail != 0):
            break
    return fail
Exemple #4
0
def standard_solve(pols, silent=False, tasks=0):
    """
    Calls the blackbox solver.  On input in pols is a list of strings.
    By default, the solver will print to screen the computed root counts.
    To make the solver silent, set the flag silent to True.
    The number of tasks for multithreading is given by tasks.
    The solving happens in standard double precision arithmetic.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
    import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    from phcpy.phcpy2c3 import py2c_solcon_clear_standard_solutions
    from phcpy.phcpy2c3 import py2c_solve_Laurent_system
    from phcpy.interface import load_standard_solutions
    py2c_syscon_clear_standard_Laurent_system()
    py2c_solcon_clear_standard_solutions()
    dim = len(pols)
    py2c_syscon_initialize_number_of_standard_Laurentials(dim)
    for ind in range(0, dim):
        pol = pols[ind]
        nchar = len(pol)
        py2c_syscon_store_standard_Laurential(nchar, dim, ind+1, pol)
    py2c_solve_Laurent_system(silent, tasks)
    return load_standard_solutions()
Exemple #5
0
def support(nvr, pol):
    r"""
    The support of a multivariate polynomial is a set of exponents
    of the monomials that appear with nonzero coefficient.
    Given in *nvr* the number of variables and in *pol* a string
    representation of a polynomial in *nvr* variables,
    returns the support of the polynomial as a list of tuples.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
    import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    py2c_syscon_clear_standard_Laurent_system()
    py2c_syscon_initialize_number_of_standard_Laurentials(nvr)
    nchar = len(pol)
    fail = py2c_syscon_store_standard_Laurential(nchar, nvr, 1, pol)
    if (fail != 0):
        return fail
    else:
        # from phcpy.phcpy2c3 import py2c_syscon_number_of_Laurent_terms
        from phcpy.phcpy2c3 import py2c_giftwrap_support_size
        from phcpy.phcpy2c3 import py2c_giftwrap_support_string
        from phcpy.phcpy2c3 import py2c_giftwrap_clear_support_string
        # ntm = py2c_syscon_number_of_Laurent_terms(1)
        # print 'number of terms : %d' % ntm
        size = py2c_giftwrap_support_size()
        # print 'size of support :', size
        supp = py2c_giftwrap_support_string(size)
        # print 'support string :', supp
        py2c_giftwrap_clear_support_string()
        result = eval(supp)
        return result
Exemple #6
0
def standard_solve(pols, silent=False, tasks=0):
    """
    Calls the blackbox solver.  On input in pols is a list of strings.
    By default, the solver will print to screen the computed root counts.
    To make the solver silent, set the flag silent to True.
    The number of tasks for multithreading is given by tasks.
    The solving happens in standard double precision arithmetic.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
    import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    from phcpy.phcpy2c3 import py2c_solcon_clear_standard_solutions
    from phcpy.phcpy2c3 import py2c_solve_Laurent_system
    from phcpy.interface import load_standard_solutions
    py2c_syscon_clear_standard_Laurent_system()
    py2c_solcon_clear_standard_solutions()
    dim = len(pols)
    py2c_syscon_initialize_number_of_standard_Laurentials(dim)
    for ind in range(0, dim):
        pol = pols[ind]
        nchar = len(pol)
        py2c_syscon_store_standard_Laurential(nchar, dim, ind + 1, pol)
    py2c_solve_Laurent_system(silent, tasks)
    return load_standard_solutions()
Exemple #7
0
def store_laurent_system(nbvar, pols):
    r"""
    Given in *pols* a list of string representing Laurent polynomials
    into the systems container.  The number of variables equals *nbvar*.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
        import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    py2c_syscon_clear_standard_Laurent_system()
    nbequ = len(pols)
    py2c_syscon_initialize_number_of_standard_Laurentials(nbequ)
    for ind in range(0, nbequ):
        pol = pols[ind]
        # print 'storing' , pol
        nbchar = len(pol)
        py2c_syscon_store_standard_Laurential(nbchar, nbvar, ind+1, pol)
Exemple #8
0
def store_laurent_system(nbvar, pols):
    r"""
    Given in *pols* a list of string representing Laurent polynomials
    into the systems container.  The number of variables equals *nbvar*.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
        import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    py2c_syscon_clear_standard_Laurent_system()
    nbequ = len(pols)
    py2c_syscon_initialize_number_of_standard_Laurentials(nbequ)
    for ind in range(0, nbequ):
        pol = pols[ind]
        # print 'storing' , pol
        nbchar = len(pol)
        py2c_syscon_store_standard_Laurential(nbchar, nbvar, ind + 1, pol)
Exemple #9
0
def test_standard_polyhedral_homotopy():
    """
    Test on jumpstarting a polyhedral homotopy
    in standard precision.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_system
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.trackers import track
    py2c_syscon_clear_standard_system()
    py2c_syscon_clear_standard_Laurent_system()
    qrt = random_trinomials()
    mixvol = mixed_volume(qrt)
    print('the mixed volume is', mixvol)
    (rqs, rsols) = random_coefficient_system()
    print('found %d solutions' % len(rsols))
    newton_step(rqs, rsols)
    print('tracking to target...')
    pqr = permute_standard_system(qrt)
    qsols = track(pqr, rqs, rsols)
    newton_step(qrt, qsols)
Exemple #10
0
def store_standard_laurent_system(polsys):
    """
    Stores the Laurent polynomials represented by the list of
    strings in polsys into the container for systems
    with coefficients in standard double precision.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
        import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    py2c_syscon_clear_standard_Laurent_system()
    dim = len(polsys)
    py2c_syscon_initialize_number_of_standard_Laurentials(dim)
    for cnt in range(0, dim):
        pol = polsys[cnt]
        nchar = len(pol)
        fail = py2c_syscon_store_standard_Laurential(nchar, dim, cnt+1, pol)
        if(fail != 0):
            break
    return fail
Exemple #11
0
def test_standard_polyhedral_homotopy():
    """
    Test on jumpstarting a polyhedral homotopy
    in standard precision.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_system
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.trackers import track
    py2c_syscon_clear_standard_system()
    py2c_syscon_clear_standard_Laurent_system()
    qrt = random_trinomials()
    mixvol = mixed_volume(qrt)
    print('the mixed volume is', mixvol)
    (rqs, rsols) = random_coefficient_system()
    print('found %d solutions' % len(rsols))
    newton_step(rqs, rsols)
    print('tracking to target...')
    pqr = permute_standard_system(qrt)
    qsols = track(pqr, rqs, rsols)
    newton_step(qrt, qsols)
Exemple #12
0
def initial_form(pols, normal):
    r"""
    Returns the initial form of the polynomials in *pols*
    with respect to the inner normal with coordinates in *normal*.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
    import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    from phcpy.phcpy2c3 import py2c_syscon_load_standard_Laurential
    from phcpy.phcpy2c3 import py2c_giftwrap_initial_form
    py2c_syscon_clear_standard_Laurent_system()
    dim = max(len(pols), len(normal))
    py2c_syscon_initialize_number_of_standard_Laurentials(dim)
    for i in range(len(pols)):
        nchar = len(pols[i])
        fail = py2c_syscon_store_standard_Laurential(nchar, dim, i+1, pols[i])
    strnrm = str(tuple(normal))
    fail = py2c_giftwrap_initial_form(len(normal), len(strnrm), strnrm)
    result = []
    for i in range(len(pols)):
        result.append(py2c_syscon_load_standard_Laurential(i+1))
    return result
Exemple #13
0
def initial_form(pols, normal):
    r"""
    Returns the initial form of the polynomials in *pols*
    with respect to the inner normal with coordinates in *normal*.
    """
    from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system
    from phcpy.phcpy2c3 \
    import py2c_syscon_initialize_number_of_standard_Laurentials
    from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential
    from phcpy.phcpy2c3 import py2c_syscon_load_standard_Laurential
    from phcpy.phcpy2c3 import py2c_giftwrap_initial_form
    py2c_syscon_clear_standard_Laurent_system()
    dim = max(len(pols), len(normal))
    py2c_syscon_initialize_number_of_standard_Laurentials(dim)
    for i in range(len(pols)):
        nchar = len(pols[i])
        fail = py2c_syscon_store_standard_Laurential(nchar, dim, i + 1,
                                                     pols[i])
    strnrm = str(tuple(normal))
    fail = py2c_giftwrap_initial_form(len(normal), len(strnrm), strnrm)
    result = []
    for i in range(len(pols)):
        result.append(py2c_syscon_load_standard_Laurential(i + 1))
    return result