Пример #1
0
def newton_laurent_step(system, solutions, precision='d', decimals=100):
    """
    Applies one Newton step to the solutions of the Laurent system.
    For each solution, prints its last line of diagnostics.
    Four levels of precision are supported:
    d  : standard double precision (1.1e-15 or 2^(-53)),
    dd : double double precision (4.9e-32 or 2^(-104)),
    qd : quad double precision (1.2e-63 or 2^(-209)).
    mp : arbitrary precision, where the number of decimal places
    in the working precision is determined by decimals.
    """
    dim = number_of_symbols(system)
    if (precision == 'd'):
        from phcpy.interface import store_standard_laurent_system
        from phcpy.interface import store_standard_solutions
        from phcpy.interface import load_standard_solutions
        store_standard_laurent_system(system, nbvar=dim)
        store_standard_solutions(dim, solutions)
        from phcpy.phcpy2c3 import py2c_standard_Newton_Laurent_step
        py2c_standard_Newton_Laurent_step()
        result = load_standard_solutions()
    elif (precision == 'dd'):
        from phcpy.interface import store_dobldobl_laurent_system
        from phcpy.interface import store_dobldobl_solutions
        from phcpy.interface import load_dobldobl_solutions
        store_dobldobl_laurent_system(system, nbvar=dim)
        store_dobldobl_solutions(dim, solutions)
        from phcpy.phcpy2c3 import py2c_dobldobl_Newton_Laurent_step
        py2c_dobldobl_Newton_Laurent_step()
        result = load_dobldobl_solutions()
    elif (precision == 'qd'):
        from phcpy.interface import store_quaddobl_laurent_system
        from phcpy.interface import store_quaddobl_solutions
        from phcpy.interface import load_quaddobl_solutions
        store_quaddobl_laurent_system(system, nbvar=dim)
        store_quaddobl_solutions(dim, solutions)
        from phcpy.phcpy2c3 import py2c_quaddobl_Newton_Laurent_step
        py2c_quaddobl_Newton_Laurent_step()
        result = load_quaddobl_solutions()
    elif (precision == 'mp'):
        from phcpy.interface import store_multprec_laurent_system
        from phcpy.interface import store_multprec_solutions
        from phcpy.interface import load_multprec_solutions
        store_multprec_laurent_system(system, decimals, nbvar=dim)
        store_multprec_solutions(dim, solutions)
        from phcpy.phcpy2c3 import py2c_multprec_Newton_Laurent_step
        py2c_multprec_Newton_Laurent_step(decimals)
        result = load_multprec_solutions()
    else:
        print('wrong argument for precision')
        return None
    for sol in result:
        strsol = sol.split('\n')
        print(strsol[-1])
    return result
Пример #2
0
def newton_laurent_step(system, solutions, precision='d', decimals=100):
    """
    Applies one Newton step to the solutions of the Laurent system.
    For each solution, prints its last line of diagnostics.
    Four levels of precision are supported:
    d  : standard double precision (1.1e-15 or 2^(-53)),
    dd : double double precision (4.9e-32 or 2^(-104)),
    qd : quad double precision (1.2e-63 or 2^(-209)).
    mp : arbitrary precision, where the number of decimal places
    in the working precision is determined by decimals.
    """
    if(precision == 'd'):
        from phcpy.interface import store_standard_laurent_system
        from phcpy.interface import store_standard_solutions
        from phcpy.interface import load_standard_solutions
        store_standard_laurent_system(system)
        store_standard_solutions(len(system), solutions)
        from phcpy.phcpy2c3 import py2c_standard_Newton_Laurent_step
        py2c_standard_Newton_Laurent_step()
        result = load_standard_solutions()
    elif(precision == 'dd'):
        from phcpy.interface import store_dobldobl_laurent_system
        from phcpy.interface import store_dobldobl_solutions
        from phcpy.interface import load_dobldobl_solutions
        store_dobldobl_laurent_system(system)
        store_dobldobl_solutions(len(system), solutions)
        from phcpy.phcpy2c3 import py2c_dobldobl_Newton_Laurent_step
        py2c_dobldobl_Newton_Laurent_step()
        result = load_dobldobl_solutions()
    elif(precision == 'qd'):
        from phcpy.interface import store_quaddobl_laurent_system
        from phcpy.interface import store_quaddobl_solutions
        from phcpy.interface import load_quaddobl_solutions
        store_quaddobl_laurent_system(system)
        store_quaddobl_solutions(len(system), solutions)
        from phcpy.phcpy2c3 import py2c_quaddobl_Newton_Laurent_step
        py2c_quaddobl_Newton_Laurent_step()
        result = load_quaddobl_solutions()
    elif(precision == 'mp'):
        from phcpy.interface import store_multprec_laurent_system
        from phcpy.interface import store_multprec_solutions
        from phcpy.interface import load_multprec_solutions
        store_multprec_laurent_system(system, decimals)
        store_multprec_solutions(len(system), solutions)
        from phcpy.phcpy2c3 import py2c_multprec_Newton_Laurent_step
        py2c_multprec_Newton_Laurent_step(decimals)
        result = load_multprec_solutions()
    else:
        print('wrong argument for precision')
        return None
    for sol in result:
        strsol = sol.split('\n')
        print(strsol[-1])
    return result
Пример #3
0
def multprec_usolve(pol, mxi, eps, decimals):
    """
    Applies the method of Durand-Kerner (aka Weierstrass)
    to the polynomial in the string pol, in arbitrary multiprecision,
    the number of decimal places in the precision is in decimals.
    The maximum number of iterations is in mxi,
    the requirement on the accuracy in eps.
    """
    from phcpy.phcpy2c3 import py2c_usolve_multprec
    from phcpy.interface import store_multprec_system, load_multprec_solutions
    store_multprec_system([pol], decimals)
    nit = py2c_usolve_multprec(decimals, mxi, eps)
    rts = load_multprec_solutions()
    return (nit, rts)
Пример #4
0
def multprec_usolve(pol, mxi, eps, decimals):
    """
    Applies the method of Durand-Kerner (aka Weierstrass)
    to the polynomial in the string pol, in arbitrary multiprecision,
    the number of decimal places in the precision is in decimals.
    The maximum number of iterations is in mxi,
    the requirement on the accuracy in eps.
    """
    from phcpy.phcpy2c3 import py2c_usolve_multprec
    from phcpy.interface import store_multprec_system, load_multprec_solutions
    store_multprec_system([pol], decimals)
    nit = py2c_usolve_multprec(decimals, mxi, eps)
    rts = load_multprec_solutions()
    return (nit, rts)
Пример #5
0
def multiprecision_track(target, start, sols, gamma=0, decimals=80):
    """
    Does path tracking with multiprecision.
    On input are a target system, a start system with solutions,
    and optionally a (random) gamma constant.
    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 decimal places in the working precision is
    given by the value of decimals.
    On return are the string representations of the solutions
    computed at the end of the paths.
    """
    from phcpy.phcpy2c2 import py2c_copy_multprec_container_to_target_system
    from phcpy.phcpy2c2 import py2c_copy_multprec_container_to_start_system
    from phcpy.phcpy2c2 import py2c_copy_multprec_container_to_start_solutions
    from phcpy.phcpy2c2 import py2c_create_multprec_homotopy
    from phcpy.phcpy2c2 import py2c_create_multprec_homotopy_with_gamma
    from phcpy.phcpy2c2 import py2c_solve_by_multprec_homotopy_continuation
    from phcpy.phcpy2c2 import py2c_solcon_clear_multprec_solutions
    from phcpy.phcpy2c2 import py2c_copy_multprec_target_solutions_to_container
    from phcpy.interface import store_multprec_system
    from phcpy.interface import store_multprec_solutions
    from phcpy.interface import load_multprec_solutions

    store_multprec_system(target, decimals)
    py2c_copy_multprec_container_to_target_system()
    store_multprec_system(start, decimals)
    py2c_copy_multprec_container_to_start_system()
    # py2c_clear_multprec_homotopy()
    if gamma == 0:
        py2c_create_multprec_homotopy()
    else:
        py2c_create_multprec_homotopy_with_gamma(gamma.real, gamma.imag)
    dim = len(start)
    store_multprec_solutions(dim, sols)
    py2c_copy_multprec_container_to_start_solutions()
    py2c_solve_by_multprec_homotopy_continuation(decimals)
    py2c_solcon_clear_multprec_solutions()
    py2c_copy_multprec_target_solutions_to_container()
    return load_multprec_solutions()
Пример #6
0
def multiprecision_track(target, start, sols, gamma=0, decimals=80):
    """
    Does path tracking with multiprecision.
    On input are a target system, a start system with solutions,
    and optionally a (random) gamma constant.
    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 decimal places in the working precision is
    given by the value of decimals.
    On return are the string representations of the solutions
    computed at the end of the paths.
    """
    from phcpy.phcpy2c2 import py2c_copy_multprec_container_to_target_system
    from phcpy.phcpy2c2 import py2c_copy_multprec_container_to_start_system
    from phcpy.phcpy2c2 import py2c_copy_multprec_container_to_start_solutions
    from phcpy.phcpy2c2 import py2c_create_multprec_homotopy
    from phcpy.phcpy2c2 import py2c_create_multprec_homotopy_with_gamma
    from phcpy.phcpy2c2 import py2c_solve_by_multprec_homotopy_continuation
    from phcpy.phcpy2c2 import py2c_solcon_clear_multprec_solutions
    from phcpy.phcpy2c2 import py2c_copy_multprec_target_solutions_to_container
    from phcpy.interface import store_multprec_system
    from phcpy.interface import store_multprec_solutions
    from phcpy.interface import load_multprec_solutions
    store_multprec_system(target, decimals)
    py2c_copy_multprec_container_to_target_system()
    store_multprec_system(start, decimals)
    py2c_copy_multprec_container_to_start_system()
    # py2c_clear_multprec_homotopy()
    if(gamma == 0):
        py2c_create_multprec_homotopy()
    else:
        py2c_create_multprec_homotopy_with_gamma(gamma.real, gamma.imag)
    dim = len(start)
    store_multprec_solutions(dim, sols)
    py2c_copy_multprec_container_to_start_solutions()
    py2c_solve_by_multprec_homotopy_continuation(decimals)
    py2c_solcon_clear_multprec_solutions()
    py2c_copy_multprec_target_solutions_to_container()
    return load_multprec_solutions()
Пример #7
0
def newton_steps(system, solutions, accuracy=8, maxsteps=4, maxprec=256):
    """
    Runs a sequence of variable precision Newton steps to approximate
    solutions accurate up to a specified number of decimal places.
    In addition to the system and solutions, there are three parameters:
    accuracy : number of decimal places wanted to be accurate,
    maxsteps : maximum number of Newton steps,
    maxprec : maximum number of decimal places in the precision used
    to estimate the condition numbers.
    """
    from phcpy.phcpy2c3 import py2c_varbprec_Newton_Laurent_steps as vmpnewt
    from phcpy.interface import store_multprec_solutions
    from phcpy.interface import load_multprec_solutions
    dim = len(system)
    store_multprec_solutions(dim, solutions)
    pols = ""
    for polynomial in system:
        pols = pols + polynomial
    vmpnewt(dim, accuracy, maxsteps, maxprec, len(pols), pols)
    result = load_multprec_solutions()
    return result
Пример #8
0
def newton_steps(system, solutions, accuracy=8, maxsteps=4, maxprec=256):
    """
    Runs a sequence of variable precision Newton steps to approximate
    solutions accurate up to a specified number of decimal places.
    In addition to the system and solutions, there are three parameters:
    accuracy : number of decimal places wanted to be accurate,
    maxsteps : maximum number of Newton steps,
    maxprec : maximum number of decimal places in the precision used
    to estimate the condition numbers.
    """
    from phcpy.phcpy2c3 import py2c_varbprec_Newton_Laurent_steps as vmpnewt
    from phcpy.interface import store_multprec_solutions
    from phcpy.interface import load_multprec_solutions
    dim = len(system)
    store_multprec_solutions(dim, solutions)
    pols = ""
    for polynomial in system:
        pols = pols + polynomial
    vmpnewt(dim, accuracy, maxsteps, maxprec, len(pols), pols)
    result = load_multprec_solutions()
    return result