Exemple #1
0
def embed_and_cascade(pols, topdim):
    """
    Computes and solves an embedding at top dimension topdim
    of the Laurent polynomials in pols, before running one
    step in the cascade homotopy.
    Returns the embedded system, the three generic points,
    and the filtered solutions at the end of the cascade.
    """
    from phcpy.sets import laurent_ismember_filter
    from phcpy.cascades import laurent_top_cascade, laurent_cascade_filter
    (embpols, sols0, sols1) \
        = laurent_top_cascade(len(pols), topdim, pols, 1.0e-08)
    for sol in sols1:
        print(sol)
    input('hit enter to continue')
    print('... running cascade step ...')
    (embdown, sols2) = laurent_cascade_filter(1, embpols, sols1, 1.0e-8)
    filtsols2 = laurent_ismember_filter(embpols, sols0, 1, sols2)
    print('... after running the cascade ...')
    for sol in filtsols2:
        print(sol)
    print('found %d isolated solutions' % len(filtsols2))
    return (embpols, sols0, sols1)
Exemple #2
0
def embed_and_cascade(pols, topdim):
    """
    Computes and solves an embedding at top dimension topdim
    of the Laurent polynomials in pols, before running one
    step in the cascade homotopy.
    Returns the embedded system, the three generic points,
    and the filtered solutions at the end of the cascade.
    """
    from phcpy.sets import laurent_ismember_filter
    from phcpy.cascades import laurent_top_cascade, laurent_cascade_filter
    (embpols, sols0, sols1) \
        = laurent_top_cascade(len(pols), topdim, pols, 1.0e-08)
    for sol in sols1:
        print sol
    raw_input('hit enter to continue')
    print '... running cascade step ...'
    (embdown, sols2) = laurent_cascade_filter(1, embpols, sols1, 1.0e-8)
    filtsols2 = laurent_ismember_filter(embpols, sols0, 1, sols2)
    print '... after running the cascade ...'
    for sol in filtsols2:
        print sol
    print 'found %d isolated solutions' % len(filtsols2)
    raw_input('hit enter to continue')
    return (embpols, sols0, sols1)
Exemple #3
0
def run_cascade(nvr, dim, pols, islaurent=False, \
    tol=1.0e-8, evatol=1.0e-6, memtol=1.0e-6, \
    tasks=0, prc='d', verbose=True):
    r"""
    Runs a cascade on the polynomials *pols*,
    in the number of variables equal to *nvr*,
    starting at the top dimension *dim*.
    If islaurent, then the polynomials in *pols* may have negative exponents.
    Returns a dictionary with as keys the dimensions
    and as values the tuples with the embedded systems
    and the corresponding generic points.
    Three tolerance parameters have default values on input:
    *tol* is used to decide which slack variables are zero,
    *evatol* is the tolerance on the residual to filter junk points,
    *memtol* is the tolerance for the homotopy membership test.
    The number of tasks is given by *tasks* (0 for no multitasking)
    and the default precision is double.  Other supported values
    for *prc* are 'dd' for double double and 'qd' for quad double.
    If *verbose*, then a summary of the filtering is printed.
    """
    from phcpy.sets import ismember_filter, laurent_ismember_filter
    from phcpy.cascades import top_cascade, laurent_top_cascade
    from phcpy.cascades import cascade_filter, laurent_cascade_filter
    lowdim = max(0, nvr - len(pols))  # lower bound on the dimension
    result = {}
    if islaurent:
        (topemb, topsols, nonsols) \
            = laurent_top_cascade(nvr, dim, pols, tol, tasks, prc, verbose)
    else:
        (topemb, topsols, nonsols) \
            = top_cascade(nvr, dim, pols, tol, tasks, prc, verbose)
    result[dim] = (topemb, topsols)
    for idx in range(dim, lowdim, -1):
        emb = result[idx][0]
        if (idx == 1):
            if islaurent:
                (embp, sols) = laurent_cascade_filter\
                    (idx, emb, nonsols, tol, tasks, prc, verbose)
            else:
                (embp, sols) = cascade_filter\
                    (idx, emb, nonsols, tol, tasks, prc, verbose)
        else:
            if islaurent:
                (embp, sols, nonsols) = laurent_cascade_filter\
                    (idx, emb, nonsols, tol, tasks, prc, verbose)
            else:
                (embp, sols, nonsols) = cascade_filter\
                    (idx, emb, nonsols, tol, tasks, prc, verbose)
        dims = result.keys()
        dims.sort(reverse=True)
        for dim in dims:
            (epols, esols) = result[dim]
            if islaurent:
                sols = laurent_ismember_filter(epols, esols, dim, sols, \
                                               evatol, memtol, False, prc)
            else:
                sols = ismember_filter(epols, esols, dim, sols, \
                                       evatol, memtol, False, prc)
            if verbose:
                print 'number of generic points after filtering :', len(sols)
        result[idx - 1] = (embp, sols)
    return result
Exemple #4
0
def run_cascade(nvr, dim, pols, islaurent=False, \
    tol=1.0e-8, rcotol=1.0e-6, evatol=1.0e-6, memtol=1.0e-6, \
    tasks=0, prc='d', verbose=True):
    r"""
    Runs a cascade on the polynomials *pols*,
    in the number of variables equal to *nvr*,
    starting at the top dimension *dim*.
    If islaurent, then the polynomials in *pols* may have negative exponents.
    Returns a dictionary with as keys the dimensions
    and as values the tuples with the embedded systems
    and the corresponding generic points.
    Four tolerance parameters have default values on input:
    *tol* is used to decide which slack variables are zero,
    *rcotol* is the tolerance on the estimated inverse condition number,
    *evatol* is the tolerance on the residual to filter junk points,
    *memtol* is the tolerance for the homotopy membership test.
    The number of tasks is given by *tasks* (0 for no multitasking)
    and the default precision is double.  Other supported values
    for *prc* are 'dd' for double double and 'qd' for quad double.
    If *verbose*, then a summary of the filtering is printed.
    """
    from phcpy.sets import ismember_filter, laurent_ismember_filter
    from phcpy.cascades import top_cascade, laurent_top_cascade
    from phcpy.cascades import cascade_filter, laurent_cascade_filter
    lowdim = max(0, nvr-len(pols)) # lower bound on the dimension
    result = {}
    if islaurent:
        (topemb, topsols, nonsols) \
            = laurent_top_cascade(nvr, dim, pols, tol, tasks, prc, verbose)
    else:
        (topemb, topsols, nonsols) \
            = top_cascade(nvr, dim, pols, tol, tasks, prc, verbose)
    result[dim] = (topemb, topsols)
    for idx in range(dim, lowdim, -1):
        emb = result[idx][0]
        if(idx == 1):
            if islaurent:
                (embp, sols) = laurent_cascade_filter\
                    (idx, emb, nonsols, tol, tasks, prc, verbose)
            else:
                (embp, sols) = cascade_filter\
                    (idx, emb, nonsols, tol, tasks, prc, verbose)
        else:
            if islaurent:
                (embp, sols, nonsols) = laurent_cascade_filter\
                    (idx, emb, nonsols, tol, tasks, prc, verbose)
            else:
                (embp, sols, nonsols) = cascade_filter\
                    (idx, emb, nonsols, tol, tasks, prc, verbose)
        dims = result.keys()
        dims.sort(reverse=True)
        for dim in dims:
            (epols, esols) = result[dim]
            if islaurent:
                sols = laurent_ismember_filter\
                          (epols, esols, dim, sols, \
                           rcotol, evatol, memtol, False, prc)
            else:
                sols = ismember_filter(epols, esols, dim, sols, \
                                       rcotol, evatol, memtol, False, prc)
            if verbose:
                print 'number of generic points after filtering :', len(sols)
        result[idx-1] = (embp, sols)
    return result