Beispiel #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
Beispiel #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
Beispiel #3
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 #4
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 #5
0
def quaddobl_monodromy_breakup(embsys, esols, dim, \
    islaurent=0, verbose=True, nbloops=0):
    r"""
    Applies the monodromy breakup algorithm in quad double precision
    to factor the *dim*-dimensional algebraic set represented by the embedded
    system *embsys* and its solutions *esols*.
    If the embedded polynomial system is a Laurent system,
    then islaurent must equal one, the default is zero.
    If *verbose* is False, then no output is written.
    If *nbloops* equals zero, then the user is prompted to give
    the maximum number of loops.
    """
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_to_mute
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_to_verbose
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_assign_labels
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_monodromy
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_sampler
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_Laurent_sampler
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_trace_grid_diagnostics
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_trace_slice
    from phcpy.phcpy2c3 import py2c_factor_store_quaddobl_gammas
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_track_paths
    from phcpy.phcpy2c3 import py2c_factor_store_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_factor_restore_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_factor_new_quaddobl_slices
    from phcpy.phcpy2c3 import py2c_factor_swap_quaddobl_slices
    from phcpy.phcpy2c3 import py2c_factor_permutation_after_quaddobl_loop
    from phcpy.phcpy2c3 import py2c_factor_number_of_quaddobl_components
    from phcpy.phcpy2c3 import py2c_factor_update_quaddobl_decomposition
    from phcpy.phcpy2c3 import py2c_solcon_write_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import store_quaddobl_laurent_system
    if(verbose):
        print('... applying monodromy factorization with quad doubles ...')
        py2c_factor_set_quaddobl_to_verbose()
    else:
        py2c_factor_set_quaddobl_to_mute()
    deg = len(esols)
    nvar = len(embsys)
    if(verbose):
        print('dim =', dim)
    store_quaddobl_solutions(nvar, esols)
    if(islaurent == 1):
        store_quaddobl_laurent_system(embsys)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_Laurent_sampler(dim)
    else:
        store_quaddobl_system(embsys)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_sampler(dim)
    if(verbose):
        py2c_solcon_write_quaddobl_solutions()
    if(nbloops == 0):
        strnbloops = input('give the maximum number of loops : ')
        nbloops = int(strnbloops)
    py2c_factor_initialize_quaddobl_monodromy(nbloops, deg, dim)
    py2c_factor_store_quaddobl_solutions()
    if(verbose):
        print('... initializing the grid ...')
    for i in range(1, 3):
        py2c_factor_set_quaddobl_trace_slice(i)
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_factor_store_quaddobl_solutions()
        py2c_factor_restore_quaddobl_solutions()
        py2c_factor_swap_quaddobl_slices()
    (err, dis) = py2c_factor_quaddobl_trace_grid_diagnostics()
    if(verbose):
        print('The diagnostics of the trace grid :')
        print('  largest error on the samples :', err)
        print('  smallest distance between the samples :', dis)
    for i in range(1, nbloops+1):
        if(verbose):
            print('... starting loop %d ...' % i)
        py2c_factor_new_quaddobl_slices(dim, nvar)
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_solcon_clear_quaddobl_solutions()
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_factor_store_quaddobl_solutions()
        sprm = py2c_factor_permutation_after_quaddobl_loop(deg)
        if(verbose):
            perm = eval(sprm)
            print('the permutation :', perm)
        nb0 = py2c_factor_number_of_quaddobl_components()
        done = py2c_factor_update_quaddobl_decomposition(deg, len(sprm), sprm)
        nb1 = py2c_factor_number_of_quaddobl_components()
        if(verbose):
            print('number of factors : %d -> %d' % (nb0, nb1))
            deco = decomposition(deg, 'qd')
            print('decomposition :', deco)
        if(done == 1):
            break
        py2c_factor_restore_quaddobl_solutions()
Beispiel #6
0
def quaddobl_monodromy_breakup(embsys, esols, dim, \
    islaurent=0, verbose=True, nbloops=0):
    r"""
    Applies the monodromy breakup algorithm in quad double precision
    to factor the *dim*-dimensional algebraic set represented by the embedded
    system *embsys* and its solutions *esols*.
    If the embedded polynomial system is a Laurent system,
    then islaurent must equal one, the default is zero.
    If *verbose* is False, then no output is written.
    If *nbloops* equals zero, then the user is prompted to give
    the maximum number of loops.
    """
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_to_mute
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_to_verbose
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_assign_labels
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_monodromy
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_sampler
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_Laurent_sampler
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_trace_grid_diagnostics
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_trace_slice
    from phcpy.phcpy2c3 import py2c_factor_store_quaddobl_gammas
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_track_paths
    from phcpy.phcpy2c3 import py2c_factor_store_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_factor_restore_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_factor_new_quaddobl_slices
    from phcpy.phcpy2c3 import py2c_factor_swap_quaddobl_slices
    from phcpy.phcpy2c3 import py2c_factor_permutation_after_quaddobl_loop
    from phcpy.phcpy2c3 import py2c_factor_number_of_quaddobl_components
    from phcpy.phcpy2c3 import py2c_factor_update_quaddobl_decomposition
    from phcpy.phcpy2c3 import py2c_solcon_write_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import store_quaddobl_laurent_system
    if (verbose):
        print('... applying monodromy factorization with quad doubles ...')
        py2c_factor_set_quaddobl_to_verbose()
    else:
        py2c_factor_set_quaddobl_to_mute()
    deg = len(esols)
    nvar = len(embsys)
    if (verbose):
        print('dim =', dim)
    store_quaddobl_solutions(nvar, esols)
    if (islaurent == 1):
        store_quaddobl_laurent_system(embsys)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_Laurent_sampler(dim)
    else:
        store_quaddobl_system(embsys)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_sampler(dim)
    if (verbose):
        py2c_solcon_write_quaddobl_solutions()
    if (nbloops == 0):
        strnbloops = input('give the maximum number of loops : ')
        nbloops = int(strnbloops)
    py2c_factor_initialize_quaddobl_monodromy(nbloops, deg, dim)
    py2c_factor_store_quaddobl_solutions()
    if (verbose):
        print('... initializing the grid ...')
    for i in range(1, 3):
        py2c_factor_set_quaddobl_trace_slice(i)
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_factor_store_quaddobl_solutions()
        py2c_factor_restore_quaddobl_solutions()
        py2c_factor_swap_quaddobl_slices()
    (err, dis) = py2c_factor_quaddobl_trace_grid_diagnostics()
    if (verbose):
        print('The diagnostics of the trace grid :')
        print('  largest error on the samples :', err)
        print('  smallest distance between the samples :', dis)
    for i in range(1, nbloops + 1):
        if (verbose):
            print('... starting loop %d ...' % i)
        py2c_factor_new_quaddobl_slices(dim, nvar)
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_solcon_clear_quaddobl_solutions()
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_factor_store_quaddobl_solutions()
        sprm = py2c_factor_permutation_after_quaddobl_loop(deg)
        if (verbose):
            perm = eval(sprm)
            print('the permutation :', perm)
        nb0 = py2c_factor_number_of_quaddobl_components()
        done = py2c_factor_update_quaddobl_decomposition(deg, len(sprm), sprm)
        nb1 = py2c_factor_number_of_quaddobl_components()
        if (verbose):
            print('number of factors : %d -> %d' % (nb0, nb1))
            deco = decomposition(deg, 'qd')
            print('decomposition :', deco)
        if (done == 1):
            break
        py2c_factor_restore_quaddobl_solutions()