예제 #1
0
def test_cascade():
    """
    Does one cascade step on simple example.
    In the top embedding we first find the 2-dimensional
    solution set x = 1.  In the cascade step we compute
    the three witness points on the twisted cubic.
    """
    from phcpy.solver import solve
    from phcpy.sets import embed
    from phcpy.sets import drop_variable_from_standard_polynomials
    from phcpy.sets import drop_coordinate_from_standard_solutions
    pols = ['(x - 1)*(y-x^2);', \
            '(x - 1)*(z-x^3);', \
            '(x^2 - 1)*(y-x^2);' ]
    print pols
    (embpols, sols0, sols1) = top_cascade(3, 2, pols, 1.0e-8)
    print 'the embedded system :'
    print embpols
    print 'the generic points :'
    for sol in sols0:
        print sol
    raw_input('hit enter to continue...')
    print 'solutions with nonzero slack variables :'
    for sol in sols1:
        print sol
    raw_input('hit enter to continue...')
    print '... running cascade step ...'
    (wp1, ws0, ws1) = cascade_filter(2, embpols, sols1, 1.0e-8)
    print 'the 1-dimensional embedding :'
    for pol in wp1:
        print pol
    print 'the candidate generic points :'
    for sol in ws0:
        print sol
예제 #2
0
def test_cascade():
    """
    Does one cascade step on simple example.
    In the top embedding we first find the 2-dimensional
    solution set x = 1.  In the cascade step we compute
    the three witness points on the twisted cubic.
    """
    from phcpy.solver import solve
    from phcpy.sets import embed
    from phcpy.sets import drop_variable_from_standard_polynomials
    from phcpy.sets import drop_coordinate_from_standard_solutions
    pols = ['(x - 1)*(y-x^2);', \
            '(x - 1)*(z-x^3);', \
            '(x^2 - 1)*(y-x^2);' ]
    print pols
    (embpols, sols0, sols1) = top_cascade(3, 2, pols, 1.0e-8)
    print 'the embedded system :'
    print embpols
    print 'the generic points :'
    for sol in sols0:
        print sol
    raw_input('hit enter to continue...')
    print 'solutions with nonzero slack variables :'
    for sol in sols1:
        print sol
    raw_input('hit enter to continue...')
    print '... running cascade step ...'
    (wp1, ws0, ws1) = cascade_filter(2, embpols, sols1, 1.0e-8)
    print 'the 1-dimensional embedding :'
    for pol in wp1:
        print pol
    print 'the candidate generic points :'
    for sol in ws0:
        print sol
예제 #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
예제 #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
예제 #5
0
"""
Illustrative example for a numerical irreducible decomposition.
This python3 script illustrates a two-stage cascade to compute candidate
generic points on all components, on all dimensions of the solution set.
"""
pols = ['(x^2 + y^2 + z^2 - 1)*(y - x^2)*(x - 0.5);', \
        '(x^2 + y^2 + z^2 - 1)*(z - x^3)*(y - 0.5);', \
        '(x^2 + y^2 + z^2 - 1)*(z - x*y)*(z - 0.5);']
from phcpy.cascades import top_cascade, cascade_filter
(topemb, topsols0, topsols1) = top_cascade(3, 2, pols, 1.0e-8)
print('generic points on the two dimensional surface :')
for sol in topsols0:
    print(sol)
input('hit enter to continue')
(lvl1emb, lvl1sols0, lvl1sols1) = cascade_filter(2, topemb, topsols1, 1.0e-8)
print('candidate generic points at level 1 :')
for sol in lvl1sols0:
    print(sol)
from phcpy.sets import ismember_filter
fil1sols0 = ismember_filter(topemb, topsols0, 2, lvl1sols0)
print('number of points before filtering :', len(lvl1sols0))
print('number of points after filtering :', len(fil1sols0))
input('hit enter to continue')
print('the filtered witness points at dimension 1 :')
for sol in fil1sols0:
    print(sol)
input('hit enter to continue')
(lvl0emb, lvl2sols) = cascade_filter(1, lvl1emb, lvl1sols1, 1.0e-8)
(lvl0emb, lvl2sols) = cascade_filter(1, lvl1emb, lvl1sols1, 1.0e-8)
fil0sols = ismember_filter(topemb, topsols0, 2, lvl2sols)
print('number of points before filtering :', len(lvl2sols))