예제 #1
0
def test_track(silent=True, precision="d", decimals=80):
    """
    Tests the path tracking on a small random system.
    Two random trinomials are generated and random constants
    are added to ensure there are no singular solutions
    so we can use this generated system as a start system.
    The target system has the same monomial structure as
    the start system, but with random real coefficients.
    Because all coefficients are random, the number of
    paths tracked equals the mixed volume of the system.
    """
    from phcpy.solver import random_trinomials, real_random_trinomials
    from phcpy.solver import solve, mixed_volume, newton_step

    pols = random_trinomials()
    real_pols = real_random_trinomials(pols)
    from random import uniform as u

    qone = pols[0][:-1] + ("%+.17f" % u(-1, +1)) + ";"
    qtwo = pols[1][:-1] + ("%+.17f" % u(-1, +1)) + ";"
    rone = real_pols[0][:-1] + ("%+.17f" % u(-1, +1)) + ";"
    rtwo = real_pols[1][:-1] + ("%+.17f" % u(-1, +1)) + ";"
    start = [qone, qtwo]
    target = [rone, rtwo]
    start_sols = solve(start, silent)
    sols = track(target, start, start_sols, precision, decimals)
    mixvol = mixed_volume(target)
    print "mixed volume of the target is", mixvol
    print "number of solutions found :", len(sols)
    newton_step(target, sols, precision, decimals)
예제 #2
0
파일: solutions.py 프로젝트: cmplx/PHCpack
def test_class():
    """
    Tests the methods in the class Solution.
    """
    from phcpy import solver
    pols = solver.random_trinomials()
    sols = solver.solve(pols)
    print 'sols[0] :'
    print sols[0]
    s = Solution(sols[0])
    print 'the first solution :'
    print s
    print 'its coordinates :'
    print s.coordinates()
    print 'its variable names :'
    print s.variables()
    print 'its numerical values :'
    print s.numerals()
    print 'its diagnostics :'
    print s.diagnostics()
    print 'its continuation parameter :', s.timevalue()
    print 'its multiplicity :', s.multiplicity()
    print 'the dictionary :'
    print s.dictionary()
    mysol = Solution({'x': complex(1,2), 'y': complex(-7,0)})
    print('my solution :')
    print(mysol)
    (errtab, rcotab, restab) = condition_tables(sols)
    print('The frequency tables for err, rco, and res:')
    print(errtab)
    print(rcotab)
    print(restab)
예제 #3
0
def test_track(silent=True, precision='d', decimals=80):
    """
    Tests the path tracking on a small random system.
    Two random trinomials are generated and random constants
    are added to ensure there are no singular solutions
    so we can use this generated system as a start system.
    The target system has the same monomial structure as
    the start system, but with random real coefficients.
    Because all coefficients are random, the number of
    paths tracked equals the mixed volume of the system.
    """
    from phcpy.solver import random_trinomials, real_random_trinomials
    from phcpy.solver import solve, mixed_volume, newton_step
    pols = random_trinomials()
    real_pols = real_random_trinomials(pols)
    from random import uniform as u
    qone = pols[0][:-1] + ('%+.17f' % u(-1, +1)) + ';'
    qtwo = pols[1][:-1] + ('%+.17f' % u(-1, +1)) + ';'
    rone = real_pols[0][:-1] + ('%+.17f' % u(-1, +1)) + ';'
    rtwo = real_pols[1][:-1] + ('%+.17f' % u(-1, +1)) + ';'
    start = [qone, qtwo]
    target = [rone, rtwo]
    start_sols = solve(start, silent)
    sols = track(target, start, start_sols, precision, decimals)
    mixvol = mixed_volume(target)
    print 'mixed volume of the target is', mixvol
    print 'number of solutions found :', len(sols)
    newton_step(target, sols, precision, decimals)
예제 #4
0
def test():
    """
    Tests the methods in the class Polynomials.
    """
    pols = solver.random_trinomials()
    p = Polynomials(pols)
    print(p)
    print('the variables :', p.variables())
    s = p.solve()
    for sol in s:
        print(sol)
예제 #5
0
def main():
    """
    Launches one server and clients on the
    same computer.
    """
    clorsv = input("client or server ? (type c or s) ")
    if clorsv == 'c':
        client()
    else:
        from phcpy import solver
        if clorsv == 's':
            nbsys = eval(input('-> how many systems ? '))
            probs = [solver.random_trinomials() for i in range(0, nbsys)]
            nbclt = eval(input('-> how many clients ? '))
            start_server(probs, nbclt)
        else:
            print('sorry, expected c or s, please try again')
예제 #6
0
def main():
    """
    Launches one server and clients on the
    same computer.
    """
    clorsv = input("client or server ? (type c or s) ")
    if clorsv == 'c':
        client()
    else:
        from phcpy import solver
        if clorsv == 's':
            nbsys = eval(input('-> how many systems ? '))
            probs = [solver.random_trinomials() for i in range(0, nbsys)]
            nbclt = eval(input('-> how many clients ? '))
            start_server(probs, nbclt)
        else:
            print('sorry, expected c or s, please try again')
예제 #7
0
def test():
    """
    Generates a random trinomial system,
    solves it, converts the solutions,
    and then sums the multiplicities.
    """
    from phcpy import solver
    pols = solver.random_trinomials()
    sols = solver.solve(pols)
    dsols = [strsol2dict(sol) for sol in sols]
    mult = 0
    s0d = strsol2dict(sols[0])
    print('variables :', variables(s0d))
    print(evaluate(pols, s0d))
    for sol in dsols:
        mult = mult + sol['m']
    print('sum of multiplicities :', mult)
    print('sum of values at the solutions :')
    for sol in dsols:
        print(sum(evaluate(pols, sol)))
예제 #8
0
def test():
    """
    Generates a random trinomial system,
    solves it, converts the solutions,
    and then sums the multiplicities.
    """
    from phcpy import solver
    pols = solver.random_trinomials()
    sols = solver.solve(pols)
    dsols = [strsol2dict(sol) for sol in sols]
    mult = 0
    s0d = strsol2dict(sols[0])
    print('variables :', variables(s0d))
    print(evaluate(pols, s0d))
    for sol in dsols:
        mult = mult + sol['m']
    print('sum of multiplicities :', mult)
    print('sum of values at the solutions :')
    for sol in dsols:
        print(sum(evaluate(pols, sol)))