Ejemplo n.º 1
0
def quaddobl_start_diagonal_cascade(gamma=0, tasks=0):
    r"""
    Does the path tracking to start a diagonal cascade in quad double
    precision.  For this to work, the functions quaddobl_diagonal_homotopy
    and quaddobl_diagonal_cascade_solutions must be executed successfully.
    If *gamma* equals 0 on input, then a random *gamma* constant is generated,
    otherwise, the given complex *gamma* will be used in the homotopy.
    Multitasking is available, and is activated by the *tasks* parameter.
    Returns the target (system and its corresponding) solutions.
    """
    from phcpy.phcpy2c2 import py2c_create_quaddobl_homotopy
    from phcpy.phcpy2c2 import py2c_create_quaddobl_homotopy_with_gamma
    from phcpy.phcpy2c2 import py2c_solve_by_quaddobl_homotopy_continuation
    from phcpy.phcpy2c2 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.phcpy2c2 import py2c_syscon_clear_quaddobl_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_target_solutions_to_container
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_target_system_to_container
    from phcpy.interface import load_quaddobl_solutions
    from phcpy.interface import load_quaddobl_system
    if(gamma == 0):
        py2c_create_quaddobl_homotopy()
    else:
        py2c_create_quaddobl_homotopy_with_gamma(gamma.real, gamma.imag)
    py2c_solve_by_quaddobl_homotopy_continuation(tasks)
    py2c_solcon_clear_quaddobl_solutions()
    py2c_syscon_clear_quaddobl_system()
    py2c_copy_quaddobl_target_solutions_to_container()
    # from phcpy.phcpy2c2 import py2c_write_quaddobl_target_system
    # print 'the quaddobl target system :'
    # py2c_write_quaddobl_target_system()
    py2c_copy_quaddobl_target_system_to_container()
    tsys = load_quaddobl_system()
    sols = load_quaddobl_solutions()
    return (tsys, sols)
Ejemplo n.º 2
0
def quaddobl_start_diagonal_cascade(gamma=0, tasks=0):
    r"""
    Does the path tracking to start a diagonal cascade in quad double
    precision.  For this to work, the functions quaddobl_diagonal_homotopy
    and quaddobl_diagonal_cascade_solutions must be executed successfully.
    If *gamma* equals 0 on input, then a random *gamma* constant is generated,
    otherwise, the given complex *gamma* will be used in the homotopy.
    Multitasking is available, and is activated by the *tasks* parameter.
    Returns the target (system and its corresponding) solutions.
    """
    from phcpy.phcpy2c2 import py2c_create_quaddobl_homotopy
    from phcpy.phcpy2c2 import py2c_create_quaddobl_homotopy_with_gamma
    from phcpy.phcpy2c2 import py2c_solve_by_quaddobl_homotopy_continuation
    from phcpy.phcpy2c2 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.phcpy2c2 import py2c_syscon_clear_quaddobl_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_target_solutions_to_container
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_target_system_to_container
    from phcpy.interface import load_quaddobl_solutions
    from phcpy.interface import load_quaddobl_system
    if (gamma == 0):
        py2c_create_quaddobl_homotopy()
    else:
        py2c_create_quaddobl_homotopy_with_gamma(gamma.real, gamma.imag)
    py2c_solve_by_quaddobl_homotopy_continuation(tasks)
    py2c_solcon_clear_quaddobl_solutions()
    py2c_syscon_clear_quaddobl_system()
    py2c_copy_quaddobl_target_solutions_to_container()
    # from phcpy.phcpy2c2 import py2c_write_quaddobl_target_system
    # print 'the quaddobl target system :'
    # py2c_write_quaddobl_target_system()
    py2c_copy_quaddobl_target_system_to_container()
    tsys = load_quaddobl_system()
    sols = load_quaddobl_solutions()
    return (tsys, sols)
Ejemplo n.º 3
0
def quaddobl_littlewood_richardson_homotopies(
    ndim, kdim, brackets, verbose=True, vrfcnd=False, minrep=True, tosqr=False, outputfilename=""
):
    r"""
    In n-dimensional space we consider k-dimensional planes,
    subject to intersection conditions represented by brackets.
    The parameters *ndim* and *kdim* give values for n and k respectively.
    The parameter brackets is a list of brackets.  A bracket is a list
    of as many natural numbers (in the range 1..*ndim*) as *kdim*.
    The Littlewood-Richardson homotopies compute k-planes that
    meet the flags at spaces of dimensions prescribed by the brackets,
    in quad double precision.  Four options are passed as Booleans:

    *verbose*: for adding extra output during computations,

    *vrfcnd*: for extra diagnostic verification of Schubert conditions,

    *minrep*: for a minimial representation of the problem formulation,

    *tosqr*: to square the overdetermined systems.

    On return is a 4-tuple.  The first item of the tuple is the
    formal root count, sharp for general flags, then as second
    item the coordinates of the flags.  The coordinates of the
    flags are stored row wise in a list of real and imaginary parts.
    The third and fourth item of the tuple on return are respectively
    the polynomial system that has been solved and its solutions.
    The length of the list of solution should match the root count.
    """
    from phcpy.phcpy2c2 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.phcpy2c2 import py2c_schubert_quaddobl_littlewood_richardson_homotopies as qdlrhom
    from phcpy.interface import load_quaddobl_solutions, load_quaddobl_system

    py2c_solcon_clear_quaddobl_solutions()
    nbc = len(brackets)
    cds = ""
    for bracket in brackets:
        for num in bracket:
            cds = cds + " " + str(num)
    # print 'the condition string :', cds
    (roco, sflags) = qdlrhom(
        ndim,
        kdim,
        nbc,
        len(cds),
        cds,
        int(verbose),
        int(vrfcnd),
        int(minrep),
        int(tosqr),
        len(outputfilename),
        outputfilename,
    )
    rflags = eval(sflags)
    flgs = []
    for k in range(len(rflags) / 8):
        flgs.append(complex(rflags[2 * k], rflags[2 * k + 4]))
    fsys = load_quaddobl_system()
    sols = load_quaddobl_solutions()
    return (roco, flgs, fsys, sols)
Ejemplo n.º 4
0
def quaddobl_pade_approximants(pols, sols, idx=1, numdeg=2, dendeg=2, \
    nbr=4, verbose=True):
    r"""
    Computes Pade approximants based on the series in quad double 
    precision for the polynomials in *pols*, where the leading 
    coefficients of the series are the solutions in *sols*.
    On entry are the following seven parameters:

    *pols*: a list of string representations of polynomials,

    *sols*: a list of solutions of the polynomials in *pols*,

    *idx*: index of the series parameter, by default equals 1,

    *numdeg*: the degree of the numerator,

    *dendeg*: the degree of the denominator,

    *nbr*: number of steps with Newton's method,

    *verbose*: whether to write intermediate output to screen or not.

    On return is a list of lists of strings.  Each lists of strings
    represents the series solution for the variables in the list *pols*.
    """
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c3 \
        import py2c_quaddobl_Pade_approximant as Pade_approximants
    from phcpy.phcpy2c3 import py2c_syspool_quaddobl_size as poolsize
    from phcpy.phcpy2c3 import py2c_syspool_copy_to_quaddobl_container
    from phcpy.phcpy2c3 import py2c_syspool_quaddobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print("the polynomials :")
        for pol in pols:
            print(pol)
        print("Number of variables :", nbsym)
    store_quaddobl_system(pols, nbvar=nbsym)
    store_quaddobl_solutions(nbsym, sols)
    fail = Pade_approximants(idx, numdeg, dendeg, nbr, int(verbose))
    size = (-1 if fail else poolsize())
    if verbose:
        if size == -1:
            print("An error occurred in the Pade constructor.")
        else:
            print("Computed %d Pade approximants." % size)
    result = []
    for k in range(1, size + 1):
        py2c_syspool_copy_to_quaddobl_container(k)
        sersol = load_quaddobl_system()
        substsersol = substitute_symbol(sersol, idx)
        result.append(make_fractions(substsersol))
    py2c_syspool_quaddobl_clear()
    return result
Ejemplo n.º 5
0
def permute_quaddobl_system(pols):
    """
    Permutes the equations in the list of polynomials in pols
    with coefficients in quad double precision,
    along the permutation used in the mixed volume computation.
    """
    from phcpy.phcpy2c3 import py2c_celcon_permute_quaddobl_system
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    store_quaddobl_system(pols)
    py2c_celcon_permute_quaddobl_system()
    return load_quaddobl_system()
Ejemplo n.º 6
0
def permute_quaddobl_system(pols):
    """
    Permutes the equations in the list of polynomials in pols
    with coefficients in quad double precision,
    along the permutation used in the mixed volume computation.
    """
    from phcpy.phcpy2c3 import py2c_celcon_permute_quaddobl_system
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    store_quaddobl_system(pols)
    py2c_celcon_permute_quaddobl_system()
    return load_quaddobl_system()
Ejemplo n.º 7
0
def quaddobl_scale_system(pols):
    """
    Applies equation and variable scaling in quad double precision
    to the polynomials in the list pols.
    On return is the list of scaled polynomials and the scaling coefficients.
    """
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c3 import py2c_scale_quaddobl_system
    store_quaddobl_system(pols)
    cffs = py2c_scale_quaddobl_system(2)
    spol = load_quaddobl_system()
    return (spol, cffs)
Ejemplo n.º 8
0
def quaddobl_scale_system(pols):
    """
    Applies equation and variable scaling in quad double precision
    to the polynomials in the list pols.
    On return is the list of scaled polynomials and the scaling coefficients.
    """
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c3 import py2c_scale_quaddobl_system
    store_quaddobl_system(pols)
    cffs = py2c_scale_quaddobl_system(2)
    spol = load_quaddobl_system()
    return (spol, cffs)
Ejemplo n.º 9
0
def quaddobl_newton_power_series(pols, lser, idx=1, nbr=4, verbose=True):
    r"""
    Computes series in quad double precision for the polynomials
    in *pols*, where the leading terms are given in the list *lser*.
    On entry are the following five parameters:

    *pols*: a list of string representations of polynomials,

    *lser*: a list of polynomials in the series parameter (e.g.: t),
    for use as start terms in Newton's method,

    *idx*: index of the series parameter, by default equals 1,

    *nbr*: number of steps with Newton's method,

    *verbose*: whether to write intermediate output to screen or not.

    On return is a list of lists of strings.  Each lists of strings
    represents the series solution for the variables in the list *pols*.
    """
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c3 import py2c_quaddobl_Newton_power_series as newton
    from phcpy.phcpy2c3 import py2c_syspool_quaddobl_init
    from phcpy.phcpy2c3 import py2c_syspool_quaddobl_create
    from phcpy.phcpy2c3 import py2c_syspool_quaddobl_size as poolsize
    from phcpy.phcpy2c3 import py2c_syspool_copy_to_quaddobl_container
    from phcpy.phcpy2c3 import py2c_syspool_quaddobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print("the polynomials :")
        for pol in pols:
            print(pol)
        print("Number of variables :", nbsym)
    store_quaddobl_system(lser, nbvar=1)
    py2c_syspool_quaddobl_init(1)
    py2c_syspool_quaddobl_create(1)
    store_quaddobl_system(pols, nbvar=nbsym)
    fail = newton(idx, nbr, int(verbose))
    size = (-1 if fail else poolsize())
    if verbose:
        if size == -1:
            print("An error occurred in the execution of Newton's method.")
        else:
            print("Computed one series solution.")
    py2c_syspool_copy_to_quaddobl_container(1)
    result = load_quaddobl_system()
    result = substitute_symbol(result, idx)
    py2c_syspool_quaddobl_clear()
    return result
Ejemplo n.º 10
0
def quaddobl_newton_series(pols, sols, idx=1, maxdeg=4, nbr=4, verbose=True):
    r"""
    Computes series in quad double precision for the polynomials
    in *pols*, where the leading coefficients are the solutions in *sols*.
    On entry are the following five parameters:

    *pols*: a list of string representations of polynomials,

    *sols*: a list of solutions of the polynomials in *pols*,

    *idx*: index of the series parameter, by default equals 1,

    *maxdeg*: maximal degree of the series,

    *nbr*: number of steps with Newton's method,

    *verbose*: whether to write intermediate output to screen or not.

    On return is a list of lists of strings.  Each lists of strings
    represents the series solution for the variables in the list *pols*.
    """
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c2 import py2c_quaddobl_Newton_series as newton
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_size as poolsize
    from phcpy.phcpy2c2 import py2c_syspool_copy_to_quaddobl_container
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print "the polynomials :"
        for pol in pols:
            print pol
        print "Number of variables :", nbsym
    store_quaddobl_system(pols, nbvar=nbsym)
    store_quaddobl_solutions(nbsym, sols)
    fail = newton(idx, maxdeg, nbr, int(verbose))
    size = (-1 if fail else poolsize())
    if verbose:
        if size == -1:
            print "An error occurred in the execution of Newton's method."
        else:
            print "Computed %d series solutions." % size
    result = []
    for k in range(1, size+1):
        py2c_syspool_copy_to_quaddobl_container(k)
        sersol = load_quaddobl_system()
        result.append(substitute_symbol(sersol, idx))
    py2c_syspool_quaddobl_clear()
    return result
Ejemplo n.º 11
0
def quaddobl_newton_power_series(pols, lser, idx=1, nbr=4, verbose=True):
    r"""
    Computes series in quad double precision for the polynomials
    in *pols*, where the leading terms are given in the list *lser*.
    On entry are the following five parameters:

    *pols*: a list of string representations of polynomials,

    *lser*: a list of polynomials in the series parameter (e.g.: t),
    for use as start terms in Newton's method,

    *idx*: index of the series parameter, by default equals 1,

    *nbr*: number of steps with Newton's method,

    *verbose*: whether to write intermediate output to screen or not.

    On return is a list of lists of strings.  Each lists of strings
    represents the series solution for the variables in the list *pols*.
    """
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c2 import py2c_quaddobl_Newton_power_series as newton
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_init
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_create
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_size as poolsize
    from phcpy.phcpy2c2 import py2c_syspool_copy_to_quaddobl_container
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print "the polynomials :"
        for pol in pols:
            print pol
        print "Number of variables :", nbsym
    store_quaddobl_system(lser, nbvar=1)
    py2c_syspool_quaddobl_init(1);
    py2c_syspool_quaddobl_create(1);
    store_quaddobl_system(pols, nbvar=nbsym)
    fail = newton(idx, nbr, int(verbose))
    size = (-1 if fail else poolsize())
    if verbose:
        if size == -1:
            print "An error occurred in the execution of Newton's method."
        else:
            print "Computed one series solution."
    py2c_syspool_copy_to_quaddobl_container(1)
    result = load_quaddobl_system()
    result = substitute_symbol(result, idx)
    py2c_syspool_quaddobl_clear()
    return result
Ejemplo n.º 12
0
def quaddobl_littlewood_richardson_homotopies(ndim, kdim, brackets, \
    verbose=True, vrfcnd=False, minrep=True, tosqr=False, outputfilename=''):
    r"""
    In n-dimensional space we consider k-dimensional planes,
    subject to intersection conditions represented by brackets.
    The parameters *ndim* and *kdim* give values for n and k respectively.
    The parameter *brackets* is a list of brackets.  A bracket is a list
    of as many natural numbers (in the range 1..ndim) as kdim.
    The Littlewood-Richardson homotopies compute k-planes that
    meet the flags at spaces of dimensions prescribed by the brackets,
    in quad double precision.  Four options are passed as Booleans:

    *verbose*: for adding extra output during computations,

    *vrfcnd*: for extra diagnostic verification of Schubert conditions,

    *minrep*: for a minimial representation of the problem formulation,

    *tosqr*: to square the overdetermined systems.

    On return is a 4-tuple.  The first item of the tuple is the
    formal root count, sharp for general flags, then as second
    item the coordinates of the flags.  The coordinates of the
    flags are stored row wise in a list of real and imaginary parts.
    The third and fourth item of the tuple on return are respectively
    the polynomial system that has been solved and its solutions.
    The length of the list of solution should match the root count.
    """
    from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.phcpy2c3 \
       import py2c_schubert_quaddobl_littlewood_richardson_homotopies \
       as qdlrhom
    from phcpy.interface import load_quaddobl_solutions, load_quaddobl_system
    py2c_solcon_clear_quaddobl_solutions()
    nbc = len(brackets)
    cds = ''
    for bracket in brackets:
        for num in bracket:
            cds = cds + ' ' + str(num)
    # print 'the condition string :', cds
    (roco, sflags) = qdlrhom(ndim, kdim, nbc, len(cds), cds, \
        int(verbose), int(vrfcnd), int(minrep), int(tosqr), \
        len(outputfilename), outputfilename)
    rflags = eval(sflags)
    flgs = []
    for k in range(len(rflags)//8):
        flgs.append(complex(rflags[2*k], rflags[2*k+4]))
    fsys = load_quaddobl_system()
    sols = load_quaddobl_solutions()
    return (roco, flgs, fsys, sols)
Ejemplo n.º 13
0
def quaddobl_newton_series(pols, sols, idx=1, nbr=4, verbose=True):
    r"""
    Computes series in quad double precision for the polynomials
    in *pols*, where the leading coefficients are the solutions in *sols*.
    On entry are the following five parameters:

    *pols*: a list of string representations of polynomials,

    *sols*: a list of solutions of the polynomials in *pols*,

    *idx*: index of the series parameter, by default equals 1,

    *nbr*: number of steps with Newton's method,

    *verbose*: whether to write intermediate output to screen or not.

    On return is a list of lists of strings.  Each lists of strings
    represents the series solution for the variables in the list *pols*.
    """
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c2 import py2c_quaddobl_Newton_series as newton
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_size as poolsize
    from phcpy.phcpy2c2 import py2c_syspool_copy_to_quaddobl_container
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print "the polynomials :"
        for pol in pols:
            print pol
        print "Number of variables :", nbsym
    store_quaddobl_system(pols, nbvar=nbsym)
    store_quaddobl_solutions(nbsym, sols)
    fail = newton(idx, nbr, int(verbose))
    size = (-1 if fail else poolsize())
    if verbose:
        if size == -1:
            print "An error occurred in the execution of Newton's method."
        else:
            print "Computed %d series solutions." % size
    result = []
    for k in range(1, size+1):
        py2c_syspool_copy_to_quaddobl_container(k)
        sersol = load_quaddobl_system()
        result.append(substitute_symbol(sersol, idx))
    py2c_syspool_quaddobl_clear()
    return result
Ejemplo n.º 14
0
def quaddobl_littlewood_richardson_homotopies(ndim, kdim, brackets, \
    verbose=True, vrfcnd=False, outputfilename='/tmp/output'):
    """
    In n-dimensional space we consider k-dimensional planes,
    subject to intersection conditions represented by brackets.
    The parameters ndim and kdim give values for n and k respectively.
    The parameter brackets is a list of brackets.  A bracket is a list
    of as many natural numbers (in the range 1..ndim) as kdim.
    The Littlewood-Richardson homotopies compute k-planes that
    meet the flags at spaces of dimensions prescribed by the brackets,
    in quad double precision.
    On return is a 4-tuple.  The first item of the tuple is the
    formal root count, sharp for general flags, then as second
    item the coordinates of the flags.  The coordinates of the
    flags are stored row wise in a list of real and imaginary parts.
    The third and fourth item of the tuple on return are respectively
    the polynomial system that has been solved and its solutions.
    The length of the list of solution should match the root count.
    """
    from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.phcpy2c3 \
       import py2c_schubert_quaddobl_littlewood_richardson_homotopies \
       as qdlrhom
    from phcpy.interface import load_quaddobl_solutions, load_quaddobl_system
    py2c_solcon_clear_quaddobl_solutions()
    nbc = len(brackets)
    cds = ''
    for bracket in brackets:
        for num in bracket:
            cds = cds + ' ' + str(num)
    # print 'the condition string :', cds
    (roco, sflags) = qdlrhom(ndim, kdim, nbc, len(cds), cds, int(verbose), \
        int(vrfcnd), len(outputfilename), outputfilename)
    rflags = eval(sflags)
    flgs = []
    for k in range(len(rflags)/8):
        flgs.append(complex(rflags[2*k], rflags[2*k+4]))
    fsys = load_quaddobl_system()
    sols = load_quaddobl_solutions()
    return (roco, flgs, fsys, sols)
Ejemplo n.º 15
0
def quaddobl_random_coefficient_system(silent=False):
    """
    Runs the polyhedral homotopies and returns a random coefficient
    system based on the contents of the cell container,
    in quad double precision arithmetic.
    For this to work, the mixed_volume function must be called first.
    """
    from phcpy.phcpy2c3 import py2c_celcon_quaddobl_random_coefficient_system
    from phcpy.phcpy2c3 import py2c_celcon_copy_into_quaddobl_systems_container
    from phcpy.phcpy2c3 import py2c_celcon_quaddobl_polyhedral_homotopy
    from phcpy.phcpy2c3 import py2c_celcon_number_of_cells
    from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_celcon_solve_quaddobl_start_system
    from phcpy.phcpy2c3 import py2c_celcon_track_quaddobl_solution_path
    from phcpy.phcpy2c3 \
        import py2c_celcon_copy_target_quaddobl_solution_to_container
    from phcpy.interface import load_quaddobl_system, load_quaddobl_solutions
    py2c_celcon_quaddobl_random_coefficient_system()
    py2c_celcon_copy_into_quaddobl_systems_container()
    # py2c_syscon_write_dobldobl_system()
    result = load_quaddobl_system()
    # print result
    py2c_celcon_quaddobl_polyhedral_homotopy()
    nbcells = py2c_celcon_number_of_cells()
    py2c_solcon_clear_quaddobl_solutions()
    for cell in range(1, nbcells+1):
        mixvol = py2c_celcon_solve_quaddobl_start_system(cell)
        if not silent:
            print('system %d has %d solutions' % (cell, mixvol))
        for j in range(1, mixvol+1):
            if not silent:
                print('-> tracking path %d out of %d' % (j, mixvol))
            py2c_celcon_track_quaddobl_solution_path(cell, j, 0)
            py2c_celcon_copy_target_quaddobl_solution_to_container(cell, j)
    sols = load_quaddobl_solutions()
    # print sols
    # newton_step(result, sols)
    return (result, sols)
Ejemplo n.º 16
0
def quaddobl_random_coefficient_system(silent=False):
    """
    Runs the polyhedral homotopies and returns a random coefficient
    system based on the contents of the cell container,
    in quad double precision arithmetic.
    For this to work, the mixed_volume function must be called first.
    """
    from phcpy.phcpy2c3 import py2c_celcon_quaddobl_random_coefficient_system
    from phcpy.phcpy2c3 import py2c_celcon_copy_into_quaddobl_systems_container
    from phcpy.phcpy2c3 import py2c_celcon_quaddobl_polyhedral_homotopy
    from phcpy.phcpy2c3 import py2c_celcon_number_of_cells
    from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_celcon_solve_quaddobl_start_system
    from phcpy.phcpy2c3 import py2c_celcon_track_quaddobl_solution_path
    from phcpy.phcpy2c3 \
        import py2c_celcon_copy_target_quaddobl_solution_to_container
    from phcpy.interface import load_quaddobl_system, load_quaddobl_solutions
    py2c_celcon_quaddobl_random_coefficient_system()
    py2c_celcon_copy_into_quaddobl_systems_container()
    # py2c_syscon_write_dobldobl_system()
    result = load_quaddobl_system()
    # print result
    py2c_celcon_quaddobl_polyhedral_homotopy()
    nbcells = py2c_celcon_number_of_cells()
    py2c_solcon_clear_quaddobl_solutions()
    for cell in range(1, nbcells + 1):
        mixvol = py2c_celcon_solve_quaddobl_start_system(cell)
        if not silent:
            print('system %d has %d solutions' % (cell, mixvol))
        for j in range(1, mixvol + 1):
            if not silent:
                print('-> tracking path %d out of %d' % (j, mixvol))
            py2c_celcon_track_quaddobl_solution_path(cell, j, 0)
            py2c_celcon_copy_target_quaddobl_solution_to_container(cell, j)
    sols = load_quaddobl_solutions()
    # print sols
    # newton_step(result, sols)
    return (result, sols)
Ejemplo n.º 17
0
def quaddobl_polysys_solve(pols, topdim=-1, \
    filter=True, factor=True, tasks=0, verbose=True):
    """
    Runs the cascades of homotopies on the polynomial system in pols
    in quad double precision.  The default top dimension topdim
    is the number of variables in pols minus one.
    """
    from phcpy.phcpy2c3 import py2c_quaddobl_polysys_solve
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_polysys_witset
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import load_quaddobl_system, load_quaddobl_solutions
    dim = number_of_symbols(pols)
    if (topdim == -1):
        topdim = dim - 1
    fail = store_quaddobl_system(pols, nbvar=dim)
    fail = py2c_quaddobl_polysys_solve(tasks,topdim, \
        int(filter),int(factor),int(verbose))
    witsols = []
    for soldim in range(0, topdim + 1):
        fail = py2c_copy_quaddobl_polysys_witset(soldim)
        witset = (load_quaddobl_system(), load_quaddobl_solutions())
        witsols.append(witset)
    return witsols
Ejemplo n.º 18
0
def quaddobl_polysys_solve(pols, topdim=-1, \
    filter=True, factor=True, tasks=0, verbose=True):
    """
    Runs the cascades of homotopies on the polynomial system in pols
    in quad double precision.  The default top dimension topdim
    is the number of variables in pols minus one.
    """
    from phcpy.phcpy2c3 import py2c_quaddobl_polysys_solve
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_polysys_witset
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import load_quaddobl_system, load_quaddobl_solutions
    dim = number_of_symbols(pols)
    if(topdim == -1):
        topdim = dim - 1
    fail = store_quaddobl_system(pols, nbvar=dim)
    fail = py2c_quaddobl_polysys_solve(tasks,topdim, \
        int(filter),int(factor),int(verbose))
    witsols = []
    for soldim in range(0, topdim+1):
        fail = py2c_copy_quaddobl_polysys_witset(soldim)
        witset = (load_quaddobl_system(), load_quaddobl_solutions())
        witsols.append(witset)
    return witsols
Ejemplo n.º 19
0
def quaddobl_newton_power_series(pols, lser, idx=1, maxdeg=4, nbr=4, \
    checkin=True, verbose=True):
    r"""
    Computes series in quad double precision for the polynomials
    in *pols*, where the leading terms are given in the list *lser*.
    On entry are the following five parameters:

    *pols*: a list of string representations of polynomials,

    *lser*: a list of polynomials in the series parameter (e.g.: t),
    for use as start terms in Newton's method,

    *idx*: index of the series parameter, by default equals 1,

    *maxdeg*: maximal degree of the series,
 
    *nbr*: number of steps with Newton's method,

    *checkin*: checks whether the number of symbols in pols matches
    the length of the list lser if idx == 0, or is one less than 
    the length of the list lser if idx != 0.  If the conditions are
    not satisfied, then an error message is printed and lser is returned.

    *verbose*: whether to write intermediate output to screen or not.

    On return is a list of lists of strings.  Each lists of strings
    represents the series solution for the variables in the list *pols*.
    """
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c2 import py2c_quaddobl_Newton_power_series as newton
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_init
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_create
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_size as poolsize
    from phcpy.phcpy2c2 import py2c_syspool_copy_to_quaddobl_container
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print "the polynomials :"
        for pol in pols:
            print pol
        print "Number of variables :", nbsym
    if checkin:
        if not checkin_newton_power_series(nbsym, lser, idx):
            return lser
    store_quaddobl_system(lser, nbvar=1)
    py2c_syspool_quaddobl_init(1);
    py2c_syspool_quaddobl_create(1);
    store_quaddobl_system(pols, nbvar=nbsym)
    fail = newton(idx, maxdeg, nbr, int(verbose))
    size = (-1 if fail else poolsize())
    if verbose:
        if size == -1:
            print "An error occurred in the execution of Newton's method."
        else:
            print "Computed one series solution."
    py2c_syspool_copy_to_quaddobl_container(1)
    result = load_quaddobl_system()
    result = substitute_symbol(result, idx)
    py2c_syspool_quaddobl_clear()
    return result