Beispiel #1
0
def quaddobl_laursys_solve(pols, topdim=-1, \
    filter=True, factor=True, tasks=0, verbose=True):
    """
    Runs the cascades of homotopies on the Laurent 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_laursys_solve
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_laursys_witset
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_laurent_system
    from phcpy.interface import load_quaddobl_laurent_system
    from phcpy.interface import load_quaddobl_solutions
    dim = number_of_symbols(pols)
    if (topdim == -1):
        topdim = dim - 1
    fail = store_quaddobl_laurent_system(pols, nbvar=dim)
    fail = py2c_quaddobl_laursys_solve(tasks,topdim, \
        int(filter),int(factor),int(verbose))
    witsols = []
    for soldim in range(0, topdim + 1):
        fail = py2c_copy_quaddobl_laursys_witset(soldim)
        witset = (load_quaddobl_laurent_system(), load_quaddobl_solutions())
        witsols.append(witset)
    return witsols
Beispiel #2
0
def quaddobl_laursys_solve(pols, topdim=-1, \
    filter=True, factor=True, tasks=0, verbose=True):
    """
    Runs the cascades of homotopies on the Laurent 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_laursys_solve
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_laursys_witset
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_laurent_system
    from phcpy.interface import load_quaddobl_laurent_system
    from phcpy.interface import load_quaddobl_solutions
    dim = number_of_symbols(pols)
    if(topdim == -1):
        topdim = dim - 1
    fail = store_quaddobl_laurent_system(pols, nbvar=dim)
    fail = py2c_quaddobl_laursys_solve(tasks,topdim, \
        int(filter),int(factor),int(verbose))
    witsols = []
    for soldim in range(0, topdim+1):
        fail = py2c_copy_quaddobl_laursys_witset(soldim)
        witset = (load_quaddobl_laurent_system(), load_quaddobl_solutions())
        witsols.append(witset)
    return witsols
Beispiel #3
0
def canonize(pols):
    from phcpy.solver import number_of_symbols
    from phcpy.polytopes import support
    dim = number_of_symbols(pols)
    
    supp = [[list(mon) for mon in support(dim,pol)] for pol in pols]
    print(supp)
    return GetUniqueString(CreateNautyString(MakeConstIntoVar(supp)))
Beispiel #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
Beispiel #5
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
Beispiel #6
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
Beispiel #7
0
def dobldobl_newton_series(pols, sols, idx=1, maxdeg=4, nbr=4, verbose=True):
    r"""
    Computes series in double 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_dobldobl_solutions
    from phcpy.interface import store_dobldobl_system, load_dobldobl_system
    from phcpy.phcpy2c2 import py2c_dobldobl_Newton_series as newton
    from phcpy.phcpy2c2 import py2c_syspool_dobldobl_size as poolsize
    from phcpy.phcpy2c2 import py2c_syspool_copy_to_dobldobl_container
    from phcpy.phcpy2c2 import py2c_syspool_dobldobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print "the polynomials :"
        for pol in pols:
            print pol
        print "Number of variables :", nbsym
    store_dobldobl_system(pols, nbvar=nbsym)
    store_dobldobl_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_dobldobl_container(k)
        sersol = load_dobldobl_system()
        result.append(substitute_symbol(sersol, idx))
    py2c_syspool_dobldobl_clear()
    return result
Beispiel #8
0
def dobldobl_newton_series(pols, sols, idx=1, nbr=4, verbose=True):
    r"""
    Computes series in double 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_dobldobl_solutions
    from phcpy.interface import store_dobldobl_system, load_dobldobl_system
    from phcpy.phcpy2c2 import py2c_dobldobl_Newton_series as newton
    from phcpy.phcpy2c2 import py2c_syspool_dobldobl_size as poolsize
    from phcpy.phcpy2c2 import py2c_syspool_copy_to_dobldobl_container
    from phcpy.phcpy2c2 import py2c_syspool_dobldobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print "the polynomials :"
        for pol in pols:
            print pol
        print "Number of variables :", nbsym
    store_dobldobl_system(pols, nbvar=nbsym)
    store_dobldobl_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_dobldobl_container(k)
        sersol = load_dobldobl_system()
        result.append(substitute_symbol(sersol, idx))
    py2c_syspool_dobldobl_clear()
    return result
Beispiel #9
0
def double_double_track(target, start, sols, gamma=0, tasks=0):
    r"""
    Does path tracking in double double precision.
    On input are a target system, a start system with solutions,
    optionally a (random) gamma constant and the number of tasks.
    The *target* is a list of strings representing the polynomials
    of the target system (which has to be solved).
    The *start* is a list of strings representing the polynomials
    of the start system with known solutions in sols.
    The *sols* is a list of strings representing start solutions.
    By default, a random *gamma* constant is generated,
    otherwise *gamma* must be a nonzero complex constant.
    The number of tasks in the multithreading is defined by *tasks*.
    The default zero value for *tasks* indicates no multithreading.
    On return are the string representations of the solutions
    computed at the end of the paths.
    """
    from phcpy.phcpy2c3 import py2c_copy_dobldobl_container_to_target_system
    from phcpy.phcpy2c3 import py2c_copy_dobldobl_container_to_start_system
    from phcpy.phcpy2c3 import py2c_copy_dobldobl_container_to_start_solutions
    from phcpy.phcpy2c3 import py2c_create_dobldobl_homotopy
    from phcpy.phcpy2c3 import py2c_create_dobldobl_homotopy_with_gamma
    from phcpy.phcpy2c3 import py2c_solve_by_dobldobl_homotopy_continuation
    from phcpy.phcpy2c3 import py2c_solcon_clear_dobldobl_solutions
    from phcpy.phcpy2c3 import py2c_copy_dobldobl_target_solutions_to_container
    from phcpy.interface import store_dobldobl_system
    from phcpy.interface import store_dobldobl_solutions
    from phcpy.interface import load_dobldobl_solutions
    from phcpy.solver import number_of_symbols
    dim = number_of_symbols(start)
    store_dobldobl_system(target, nbvar=dim)
    py2c_copy_dobldobl_container_to_target_system()
    store_dobldobl_system(start, nbvar=dim)
    py2c_copy_dobldobl_container_to_start_system()
    # py2c_clear_dobldobl_homotopy()
    if(gamma == 0):
        py2c_create_dobldobl_homotopy()
    else:
        py2c_create_dobldobl_homotopy_with_gamma(gamma.real, gamma.imag)
    # dim = len(start)
    store_dobldobl_solutions(dim, sols)
    py2c_copy_dobldobl_container_to_start_solutions()
    py2c_solve_by_dobldobl_homotopy_continuation(tasks)
    py2c_solcon_clear_dobldobl_solutions()
    py2c_copy_dobldobl_target_solutions_to_container()
    return load_dobldobl_solutions()
Beispiel #10
0
def quaddobl_set_homotopy(target, start, verbose=False):
    """
    Initializes the homotopy with the target and start system for a
    step-by-step run of the series-Pade tracker, in quad double precision.
    If verbose, then extra output is written.
    Returns the failure code of the homotopy initializer.
    """
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_target_system
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system
    from phcpy.interface import store_quaddobl_system
    from phcpy.solver import number_of_symbols
    dim = number_of_symbols(start)
    store_quaddobl_system(target, nbvar=dim)
    py2c_copy_quaddobl_container_to_target_system()
    store_quaddobl_system(start, nbvar=dim)
    py2c_copy_quaddobl_container_to_start_system()
    from phcpy.phcpy2c3 import py2c_padcon_quaddobl_initialize_homotopy
    return py2c_padcon_quaddobl_initialize_homotopy(int(verbose))
Beispiel #11
0
def run_tracker(start, sols, target, sol_num, gamma, min_step, max_step,
                num_steps):
    set_homotopy_continuation_gamma(gamma.real, gamma.imag)
    set_homotopy_continuation_parameter(5, min_step)
    set_homotopy_continuation_parameter(4, max_step)
    set_homotopy_continuation_parameter(12, num_steps)
    dim = number_of_symbols(start)
    result = [[], [], [], [], [], [], []]
    for i in range(dim):
        result[2].append([])
    standard_set_homotopy(target, start, False)
    idx = 0
    choice_sol = sol_num
    solution = sols[choice_sol - 1]
    idx = idx + 1
    standard_set_solution(dim, solution, False)
    solution = standard_get_solution(False)
    solution_dict = strsol2dict(solution)
    var_names = variables(solution_dict)
    var_names.sort()
    result[0].append(standard_t_value())
    result[1].append(standard_step_size())
    for i in range(len(var_names)):
        result[2][i].append(solution_dict[var_names[i]])
    result[3].append(standard_closest_pole())
    result[4].append(standard_pole_radius())
    result[5].append(standard_series_coefficients(dim))
    result[6].append(standard_pade_vector(dim))
    for i in range(num_steps):
        standard_predict_correct(False)
        solution = standard_get_solution(False)
        solution_dict = strsol2dict(solution)
        result[0].append(standard_t_value())
        result[1].append(standard_step_size())
        for j in range(len(var_names)):
            result[2][j].append(solution_dict[var_names[j]])
        result[3].append(standard_closest_pole())
        result[4].append(standard_pole_radius())
        result[5].append(standard_series_coefficients(dim))
        result[6].append(standard_pade_vector(dim))
    for i in range(len(result[2])):
        for j in range(len(result[2][i])):
            result[2][i][j] = (result[2][i][j].real, result[2][i][j].imag)
    return result
Beispiel #12
0
def quad_double_track(target, start, sols, gamma=0, tasks=0):
    """
    Does path tracking with quad double precision.
    On input are a target system, a start system with solutions,
    optionally a (random) gamma constant and the number of tasks.
    The target is a list of strings representing the polynomials
    of the target system (which has to be solved).
    The start is a list of strings representing the polynomials
    of the start system with known solutions in sols.
    The sols is a list of strings representing start solutions.
    By default, a random gamma constant is generated,
    otherwise gamma must be a nonzero complex constant.
    On return are the string representations of the solutions
    computed at the end of the paths.
    """
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_target_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_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_copy_quaddobl_target_solutions_to_container
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import load_quaddobl_solutions
    from phcpy.solver import number_of_symbols

    dim = number_of_symbols(start)
    store_quaddobl_system(target, nbvar=dim)
    py2c_copy_quaddobl_container_to_target_system()
    store_quaddobl_system(start, nbvar=dim)
    py2c_copy_quaddobl_container_to_start_system()
    # py2c_clear_quaddobl_homotopy()
    if gamma == 0:
        py2c_create_quaddobl_homotopy()
    else:
        py2c_create_quaddobl_homotopy_with_gamma(gamma.real, gamma.imag)
    store_quaddobl_solutions(dim, sols)
    py2c_copy_quaddobl_container_to_start_solutions()
    py2c_solve_by_quaddobl_homotopy_continuation(tasks)
    py2c_solcon_clear_quaddobl_solutions()
    py2c_copy_quaddobl_target_solutions_to_container()
    return load_quaddobl_solutions()
Beispiel #13
0
def double_double_track(target, start, sols, gamma=0, tasks=0):
    """
    Does path tracking in double double precision.
    On input are a target system, a start system with solutions,
    optionally a (random) gamma constant and the number of tasks.
    The target is a list of strings representing the polynomials
    of the target system (which has to be solved).
    The start is a list of strings representing the polynomials
    of the start system with known solutions in sols.
    The sols is a list of strings representing start solutions.
    By default, a random gamma constant is generated,
    otherwise gamma must be a nonzero complex constant.
    On return are the string representations of the solutions
    computed at the end of the paths.
    """
    from phcpy.phcpy2c3 import py2c_copy_dobldobl_container_to_target_system
    from phcpy.phcpy2c3 import py2c_copy_dobldobl_container_to_start_system
    from phcpy.phcpy2c3 import py2c_copy_dobldobl_container_to_start_solutions
    from phcpy.phcpy2c3 import py2c_create_dobldobl_homotopy
    from phcpy.phcpy2c3 import py2c_create_dobldobl_homotopy_with_gamma
    from phcpy.phcpy2c3 import py2c_solve_by_dobldobl_homotopy_continuation
    from phcpy.phcpy2c3 import py2c_solcon_clear_dobldobl_solutions
    from phcpy.phcpy2c3 import py2c_copy_dobldobl_target_solutions_to_container
    from phcpy.interface import store_dobldobl_system
    from phcpy.interface import store_dobldobl_solutions
    from phcpy.interface import load_dobldobl_solutions
    from phcpy.solver import number_of_symbols
    dim = number_of_symbols(start)
    store_dobldobl_system(target, nbvar=dim)
    py2c_copy_dobldobl_container_to_target_system()
    store_dobldobl_system(start, nbvar=dim)
    py2c_copy_dobldobl_container_to_start_system()
    # py2c_clear_dobldobl_homotopy()
    if (gamma == 0):
        py2c_create_dobldobl_homotopy()
    else:
        py2c_create_dobldobl_homotopy_with_gamma(gamma.real, gamma.imag)
    # dim = len(start)
    store_dobldobl_solutions(dim, sols)
    py2c_copy_dobldobl_container_to_start_solutions()
    py2c_solve_by_dobldobl_homotopy_continuation(tasks)
    py2c_solcon_clear_dobldobl_solutions()
    py2c_copy_dobldobl_target_solutions_to_container()
    return load_dobldobl_solutions()
Beispiel #14
0
def quaddobl_set_parameter_homotopy(hom, idx, verbose=False):
    """
    Initializes the homotopy with the polynomials in hom for a
    step-by-step run of the series-Pade tracker, in quad double precision.
    The value idx gives the index of the continuation parameter
    and is the index of one of the variables in the homotopy hom.
    If verbose, then extra output is written.
    Returns the failure code of the homotopy initializer.
    """
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_target_system
    from phcpy.interface import store_quaddobl_system
    from phcpy.solver import number_of_symbols
    dim = number_of_symbols(hom)
    store_quaddobl_system(hom, nbvar=dim)
    py2c_copy_quaddobl_container_to_target_system()
    from phcpy.phcpy2c3  \
        import py2c_padcon_quaddobl_initialize_parameter_homotopy
    vrb = int(verbose)
    return py2c_padcon_quaddobl_initialize_parameter_homotopy(idx, vrb)
Beispiel #15
0
def quaddobl_next_track(target, start, sols, verbose=False):
    """
    Runs the series-Pade tracker step by step in quad double precision.
    On input are a target system and a start system with solutions.
    The *target* is a list of strings representing the polynomials
    of the target system (which has to be solved).
    The *start* is a list of strings representing the polynomials
    of the start system, with known solutions in *sols*.
    The *sols* is a list of strings representing start solutions.
    The function is interactive, prompting the user each time
    before performing the next predictor-corrector step.
    If verbose, then extra output is written.
    On return are the string representations of the solutions
    computed at the end of the paths.
    """
    from phcpy.solver import number_of_symbols
    result = []
    dim = number_of_symbols(start)
    quaddobl_set_homotopy(target, start, verbose)
    idx = 0
    for sol in sols:
        idx = idx + 1
        quaddobl_set_solution(dim, sol, verbose)
        while (True):
            answer = input('next predictor-corrector step ? (y/n) ')
            if (answer != 'y'):
                result.append(sol)
                break
            else:
                quaddobl_predict_correct(verbose)
                sol = quaddobl_get_solution(verbose)
                print(sol)
                (tval, step) = (quaddobl_t_value(), quaddobl_step_size())
                frp = quaddobl_pole_radius()
                print("t : %.3e, step : %.3e, frp : %.3e" % (tval, step, frp))
                cfp = quaddobl_closest_pole()
                print("closest pole : ", cfp)
                print('the series:', quaddobl_series_coefficients(dim))
                print('Pade vector:', quaddobl_pade_vector(dim))
                print('poles:', quaddobl_poles(dim))
    return result
Beispiel #16
0
def quaddobl_track(target, start, sols, filename="", verbose=False):
    """
    Wraps the tracker for Pade continuation in quad double precision.
    On input are a target system, a start system with solutions,
    optionally: a string *filename* and the *verbose* flag.
    The *target* is a list of strings representing the polynomials
    of the target system (which has to be solved).
    The *start* is a list of strings representing the polynomials
    of the start system, with known solutions in *sols*.
    The *sols* is a list of strings representing start solutions.
    On return are the string representations of the solutions
    computed at the end of the paths.
    """
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_target_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_solutions
    from phcpy.phcpy2c2 import py2c_create_quaddobl_homotopy_with_gamma
    from phcpy.phcpy2c2 import py2c_clear_quaddobl_homotopy
    from phcpy.phcpy2c2 import py2c_clear_quaddobl_operations_data
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import load_quaddobl_solutions
    from phcpy.solver import number_of_symbols
    from phcpy.phcpy2c2 import py2c_padcon_quaddobl_track
    dim = number_of_symbols(start)
    store_quaddobl_system(target, nbvar=dim)
    py2c_copy_quaddobl_container_to_target_system()
    store_quaddobl_system(start, nbvar=dim)
    py2c_copy_quaddobl_container_to_start_system()
    (regamma, imgamma) = get_homotopy_continuation_parameter(1)
    store_quaddobl_solutions(dim, sols)
    py2c_copy_quaddobl_container_to_start_solutions()
    (regamma, imgamma) = get_homotopy_continuation_parameter(1)
    py2c_create_quaddobl_homotopy_with_gamma(regamma, imgamma)
    nbc = len(filename)
    fail = py2c_padcon_quaddobl_track(nbc, filename, int(verbose))
    # py2c_clear_quaddobl_homotopy()
    # py2c_clear_quaddobl_operations_data()
    return load_quaddobl_solutions()
Beispiel #17
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