Esempio n. 1
0
def quad_double_cascade_step(dim, embsys, esols, tasks=0):
    r"""
    Given in *embsys* an embedded polynomial system and
    solutions with nonzero slack variables in *esols*, does one step 
    in the homotopy cascade, with quad double precision arithmetic.
    The dimension of the solution set represented by *embsys*
    and *esols* is the value of *dim*.
    The number of tasks in multithreaded path tracking is given by *tasks*.
    The default zero value of *tasks* indicates no multithreading.
    The list on return contains witness points on
    lower dimensional solution components.
    """
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_solutions
    from phcpy.phcpy2c3 import py2c_quaddobl_cascade_homotopy
    from phcpy.phcpy2c3 import py2c_solve_by_quaddobl_homotopy_continuation
    from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_copy_quaddobl_target_solutions_to_container
    from phcpy.interface import store_quaddobl_witness_set
    from phcpy.interface import load_quaddobl_solutions
    store_quaddobl_witness_set(len(embsys), dim, embsys, esols)
    py2c_copy_quaddobl_container_to_start_system()
    py2c_copy_quaddobl_container_to_start_solutions()
    py2c_quaddobl_cascade_homotopy()
    py2c_solve_by_quaddobl_homotopy_continuation(tasks)
    py2c_solcon_clear_quaddobl_solutions()
    py2c_copy_quaddobl_target_solutions_to_container()
    return load_quaddobl_solutions()
Esempio n. 2
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 d-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.phcpy2c2 import py2c_factor_set_quaddobl_to_mute
    from phcpy.phcpy2c2 import py2c_factor_set_quaddobl_to_verbose
    from phcpy.phcpy2c2 import py2c_factor_quaddobl_assign_labels
    from phcpy.phcpy2c2 import py2c_factor_initialize_quaddobl_monodromy
    from phcpy.phcpy2c2 import py2c_factor_initialize_quaddobl_sampler
    from phcpy.phcpy2c2 import py2c_factor_initialize_quaddobl_Laurent_sampler
    from phcpy.phcpy2c2 import py2c_factor_quaddobl_trace_grid_diagnostics
    from phcpy.phcpy2c2 import py2c_factor_set_quaddobl_trace_slice
    from phcpy.phcpy2c2 import py2c_factor_store_quaddobl_gammas
    from phcpy.phcpy2c2 import py2c_factor_quaddobl_track_paths
    from phcpy.phcpy2c2 import py2c_factor_store_quaddobl_solutions
    from phcpy.phcpy2c2 import py2c_factor_restore_quaddobl_solutions
    from phcpy.phcpy2c2 import py2c_factor_new_quaddobl_slices
    from phcpy.phcpy2c2 import py2c_factor_swap_quaddobl_slices
    from phcpy.phcpy2c2 import py2c_factor_permutation_after_quaddobl_loop
    from phcpy.phcpy2c2 import py2c_factor_number_of_quaddobl_components
    from phcpy.phcpy2c2 import py2c_factor_update_quaddobl_decomposition
    from phcpy.phcpy2c2 import py2c_solcon_write_quaddobl_solutions
    from phcpy.phcpy2c2 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.interface import store_quaddobl_witness_set
    from phcpy.interface import store_quaddobl_laurent_witness_set
    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
    if (islaurent == 1):
        store_quaddobl_laurent_witness_set(nvar, dim, embsys, esols)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_Laurent_sampler(dim)
    else:
        store_quaddobl_witness_set(nvar, dim, embsys, esols)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_sampler(dim)
    if (verbose):
        py2c_solcon_write_quaddobl_solutions()
    if (nbloops == 0):
        strnbloops = raw_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(islarent)
        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()