def quaddobl_real_sweep(pols, sols, par='s', start=0.0, target=1.0): r""" A real sweep homotopy is a family of n equations in n+1 variables, where one of the variables is the artificial parameter s which moves from 0.0 to 1.0. The last equation can then be of the form (1 - s)*(lambda - L[0]) + s*(lambda - L[1]) = 0 so that, at s = 0, the natural parameter lambda has the value L[0], and at s = 1, the natural parameter lambda has the value L[1]. Thus: as s moves from 0 to 1, lambda goes from L[0] to L[1]. All solutions in the list *sols* must have then the value L[0] for the variable lambda. The sweep stops when the target value for s is reached or when a singular solution is encountered. Computations happen in quad double precision. """ from phcpy.interface import store_quaddobl_solutions as storesols from phcpy.interface import store_quaddobl_system as storesys nvar = len(pols) + 1 storesys(pols, nbvar=nvar) storesols(nvar, sols) print 'done storing system and solutions ...' from phcpy.interface import load_quaddobl_solutions as loadsols from phcpy.phcpy2c2 \ import py2c_sweep_define_parameters_symbolically as define from phcpy.phcpy2c2 \ import py2c_sweep_set_quaddobl_start as set_start from phcpy.phcpy2c2 \ import py2c_sweep_set_quaddobl_target as set_target (nbq, nbp) = (len(pols), 1) pars = [par] parnames = ' '.join(pars) nbc = len(parnames) print 'defining the parameters ...' define(nbq, nvar, nbp, nbc, parnames) set_start(nbp, str([start, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])) set_target(nbp, str([target, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])) from phcpy.phcpy2c2 import py2c_sweep_quaddobl_real_run as run run() result = loadsols() return result
def dobldobl_diagonal_homotopy(dim1, sys1, esols1, dim2, sys2, esols2): r""" Defines a diagonal homotopy to intersect the witness sets defined by (*sys1*, *esols1*) and (*sys2*, *esols2*), respectively of dimensions *dim1* and *dim2*. The systems *sys1* and *sys2* are assumed to be square and with as many slack variables as the dimension of the solution sets. The data is stored in double double precision. """ from phcpy.interface import store_dobldobl_system as storesys from phcpy.interface import store_dobldobl_solutions as storesols from phcpy.phcpy2c2 import py2c_copy_dobldobl_container_to_target_system from phcpy.phcpy2c2 import py2c_copy_dobldobl_container_to_target_solutions from phcpy.phcpy2c2 import py2c_copy_dobldobl_container_to_start_system from phcpy.phcpy2c2 import py2c_copy_dobldobl_container_to_start_solutions from phcpy.phcpy2c2 import py2c_dobldobl_diagonal_homotopy from phcpy.phcpy2c2 import py2c_syscon_number_of_symbols from phcpy.phcpy2c2 import py2c_syscon_string_of_symbols from phcpy.phcpy2c2 import py2c_diagonal_symbols_doubler storesys(sys1) symbols = py2c_syscon_string_of_symbols() nbsymbs = py2c_syscon_number_of_symbols() print 'number of symbols :', nbsymbs print 'names of variables :', symbols storesols(len(sys1), esols1) if(dim1 >= dim2): py2c_copy_dobldobl_container_to_target_system() py2c_copy_dobldobl_container_to_target_solutions() else: py2c_copy_dobldobl_container_to_start_system() py2c_copy_dobldobl_container_to_start_solutions() storesys(sys2) storesols(len(sys2), esols2) if(dim1 >= dim2): py2c_copy_dobldobl_container_to_start_system() py2c_copy_dobldobl_container_to_start_solutions() else: py2c_copy_dobldobl_container_to_target_system() py2c_copy_dobldobl_container_to_target_solutions() if(dim1 >= dim2): py2c_dobldobl_diagonal_homotopy(dim1, dim2) else: py2c_dobldobl_diagonal_homotopy(dim2, dim1) py2c_diagonal_symbols_doubler(nbsymbs-dim1, dim1, len(symbols), symbols)
def quaddobl_real_sweep(pols, sols, par='s', start=0.0, target=1.0): """ A real sweep homotopy is a family of n equations in n+1 variables, where one of the variables is the artificial parameter s which moves from 0.0 to 1.0. The last equation can then be of the form (1 - s)*(lambda - L[0]) + s*(lambda - L[1]) = 0 so that, at s = 0, the natural parameter lambda has the value L[0], and at s = 1, the natural parameter lambda has the value L[1]. Thus: as s moves from 0 to 1, lambda goes from L[0] to L[1]. All solutions in the list sols must have then the value L[0] for the variable lambda. The sweep stops when the target value for s is reached or when a singular solution is encountered. Computations happen in quad double precision. """ from phcpy.interface import store_quaddobl_solutions as storesols from phcpy.interface import store_quaddobl_system as storesys nvar = len(pols) + 1 storesys(pols, nbvar=nvar) storesols(nvar, sols) print('done storing system and solutions ...') from phcpy.interface import load_quaddobl_solutions as loadsols from phcpy.phcpy2c3 \ import py2c_sweep_define_parameters_symbolically as define from phcpy.phcpy2c3 \ import py2c_sweep_set_quaddobl_start as set_start from phcpy.phcpy2c3 \ import py2c_sweep_set_quaddobl_target as set_target (nbq, nbp) = (len(pols), 1) pars = [par] parnames = ' '.join(pars) nbc = len(parnames) print('defining the parameters ...') define(nbq, nvar, nbp, nbc, parnames) set_start(nbp, str([start, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])) set_target(nbp, str([target, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])) from phcpy.phcpy2c3 import py2c_sweep_quaddobl_real_run as run run() result = loadsols() return result
def quaddobl_complex_sweep(pols, sols, nvar, pars, start, target): r""" For the polynomials in the list of strings *pols* and the solutions in *sols* for the values in the list *start*, a sweep through the parameter space will be performed in quad double precision to the target values of the parameters in the list *target*. The number of variables in the polynomials and the solutions must be the same and be equal to the value of *nvar*. The list of symbols in *pars* contains the names of the variables in the polynomials *pols* that serve as parameters. The size of the lists *pars*, *start*, and *target* must be same. """ from phcpy.interface import store_quaddobl_solutions as storesols from phcpy.interface import store_quaddobl_system as storesys storesys(pols, nbvar=nvar) storesols(nvar, sols) from phcpy.interface import load_quaddobl_solutions as loadsols from phcpy.phcpy2c2 \ import py2c_sweep_define_parameters_symbolically as define from phcpy.phcpy2c2 \ import py2c_sweep_set_quaddobl_start as set_start from phcpy.phcpy2c2 \ import py2c_sweep_set_quaddobl_target as set_target from phcpy.phcpy2c2 import py2c_sweep_quaddobl_complex_run as run (nbq, nbp) = (len(pols), len(pars)) parnames = ' '.join(pars) nbc = len(parnames) define(nbq, nvar, nbp, nbc, parnames) print 'setting the start and the target ...' set_start(nbp, str(start)) set_target(nbp, str(target)) print 'calling run in quad double precision ...' run(0, 0.0, 0.0) result = loadsols() return result
def quaddobl_complex_sweep(pols, sols, nvar, pars, start, target): """ For the polynomials in the list of strings pols and the solutions in sols for the values in the list start, a sweep through the parameter space will be performed in quad double precision to the target values of the parameters in the list target. The number of variables in the polynomials and the solutions must be the same and be equal to the value of nvar. The list of symbols in pars contains the names of the variables in the polynomials pols that serve as parameters. The size of the lists pars, start, and target must be same. """ from phcpy.interface import store_quaddobl_solutions as storesols from phcpy.interface import store_quaddobl_system as storesys storesys(pols, nbvar=nvar) storesols(nvar, sols) from phcpy.interface import load_quaddobl_solutions as loadsols from phcpy.phcpy2c3 \ import py2c_sweep_define_parameters_symbolically as define from phcpy.phcpy2c3 \ import py2c_sweep_set_quaddobl_start as set_start from phcpy.phcpy2c3 \ import py2c_sweep_set_quaddobl_target as set_target from phcpy.phcpy2c3 import py2c_sweep_quaddobl_complex_run as run (nbq, nbp) = (len(pols), len(pars)) parnames = ' '.join(pars) nbc = len(parnames) define(nbq, nvar, nbp, nbc, parnames) print('setting the start and the target ...') set_start(nbp, str(start)) set_target(nbp, str(target)) print('calling run in quad double precision ...') run(0, 0.0, 0.0) result = loadsols() return result
def standard_complex_sweep(pols, sols, nvar, pars, start, target): r""" For the polynomials in the list of strings *pols* and the solutions in *sols* for the values in the list *start*, a sweep through the parameter space will be performed in standard double precision to the target values of the parameters in the list *target*. The number of variables in the polynomials and the solutions must be the same and be equal to the value of *nvar*. The list of symbols in *pars* contains the names of the variables in the polynomials *pols* that serve as parameters. The size of the lists *pars*, *start*, and *target* must be same. """ from phcpy.interface import store_standard_solutions as storesols from phcpy.interface import store_standard_system as storesys storesys(pols, nbvar=nvar) storesols(nvar, sols) from phcpy.interface import load_standard_solutions as loadsols from phcpy.phcpy2c2 \ import py2c_sweep_define_parameters_symbolically as define from phcpy.phcpy2c2 \ import py2c_sweep_set_standard_start as set_start from phcpy.phcpy2c2 \ import py2c_sweep_set_standard_target as set_target from phcpy.phcpy2c2 import py2c_sweep_standard_complex_run as run (nbq, nbp) = (len(pols), len(pars)) parnames = ' '.join(pars) nbc = len(parnames) define(nbq, nvar, nbp, nbc, parnames) print 'setting the start and the target ...' set_start(nbp, str(start)) set_target(nbp, str(target)) print 'calling run in standard double precision ...' run(0, 0.0, 0.0) result = loadsols() return result
def standard_complex_sweep(pols, sols, nvar, pars, start, target): """ For the polynomials in the list of strings pols and the solutions in sols for the values in the list start, a sweep through the parameter space will be performed in standard double precision to the target values of the parameters in the list target. The number of variables in the polynomials and the solutions must be the same and be equal to the value of nvar. The list of symbols in pars contains the names of the variables in the polynomials pols that serve as parameters. The size of the lists pars, start, and target must be same. """ from phcpy.interface import store_standard_solutions as storesols from phcpy.interface import store_standard_system as storesys storesys(pols, nbvar=nvar) storesols(nvar, sols) from phcpy.interface import load_standard_solutions as loadsols from phcpy.phcpy2c3 \ import py2c_sweep_define_parameters_symbolically as define from phcpy.phcpy2c3 \ import py2c_sweep_set_standard_start as set_start from phcpy.phcpy2c3 \ import py2c_sweep_set_standard_target as set_target from phcpy.phcpy2c3 import py2c_sweep_standard_complex_run as run (nbq, nbp) = (len(pols), len(pars)) parnames = ' '.join(pars) nbc = len(parnames) define(nbq, nvar, nbp, nbc, parnames) print('setting the start and the target ...') set_start(nbp, str(start)) set_target(nbp, str(target)) print('calling run in standard double precision ...') run(0, 0.0, 0.0) result = loadsols() return result
def quaddobl_diagonal_solver(dim, dm1, sys1, sols1, dm2, sys2, sols2, \ tasks=0, verbose=True): r""" Runs the diagonal homotopies in quad double precision to intersect two witness sets stored in (*sys1*, *sols1*) and (*sys2*, *sols2*), of respective dimensions *dm1* and *dm2*. The ambient dimension equals *dim*. Multitasking is available, and is activated by the *tasks* parameter. Returns the last system in the cascade and its solutions. If *verbose*, then the solver runs in interactive mode, printing intermediate results to screen and prompting the user to continue. """ from phcpy.phcpy2c2 import py2c_quaddobl_collapse_diagonal from phcpy.interface import store_quaddobl_solutions as storesols from phcpy.interface import load_quaddobl_solutions as loadsols from phcpy.interface import load_quaddobl_system as loadsys from phcpy.phcpy2c2 import py2c_extrinsic_top_diagonal_dimension from phcpy.solutions import filter_vanishing from phcpy.sets import drop_coordinate_from_quaddobl_solutions from phcpy.sets import drop_variable_from_quaddobl_polynomials from phcpy.cascades import quad_double_cascade_step topdim = py2c_extrinsic_top_diagonal_dimension(dim + dm1, dim + dm2, dm1, dm2) kdm = len(sys1) - dm1 topdiagdim = top_diagonal_dimension(kdm, dm1, dm2) if verbose: print 'the top dimension :', topdim, 'dim :', dim print 'number of slack variables at the top :', topdiagdim quaddobl_diagonal_homotopy(dm1, sys1, sols1, dm2, sys2, sols2) if verbose: print 'defining the start solutions' quaddobl_diagonal_cascade_solutions(dm1, dm2) if verbose: print 'starting the diagonal cascade' (topsys, startsols) = quaddobl_start_diagonal_cascade() if verbose: print 'the system solved in the start of the cascade :' for pol in topsys: print pol print 'the solutions after starting the diagonal cascade :' for sol in startsols: print sol raw_input('hit enter to continue') for k in range(topdiagdim, 0, -1): endsols = quad_double_cascade_step(k, topsys, startsols) if verbose: print 'after running cascade step %d :' % k for sol in endsols: print sol endsolsf1 = filter_vanishing(endsols, 1.0e-8) if verbose: print 'computed', len(endsolsf1), 'solutions' raw_input('hit enter to continue') slack = 'zz' + str(k) nbvar = len(topsys) endsolsf2 = drop_coordinate_from_quaddobl_solutions\ (endsolsf1, nbvar, slack) if verbose: print 'after dropping the slack coordinate from the solutions :' for sol in endsolsf2: print sol raw_input('hit enter to continue') nextsys = drop_variable_from_quaddobl_polynomials(topsys, slack) if verbose: print 'after dropping the variable', slack, 'from the system :' for pol in nextsys: print pol (topsys, startsols) = (nextsys[:-1], endsolsf2) storesols(len(topsys), startsols) # py2c_quaddobl_collapse_diagonal(topdim - 2*dim, 0) py2c_quaddobl_collapse_diagonal(0, 0) result = (loadsys(), loadsols()) return result
def quaddobl_diagonal_solver(dim, dm1, sys1, sols1, dm2, sys2, sols2, \ tasks=0, verbose=True): r""" Runs the diagonal homotopies in quad double precision to intersect two witness sets stored in (*sys1*, *sols1*) and (*sys2*, *sols2*), of respective dimensions *dm1* and *dm2*. The ambient dimension equals *dim*. Multitasking is available, and is activated by the *tasks* parameter. Returns the last system in the cascade and its solutions. If *verbose*, then the solver runs in interactive mode, printing intermediate results to screen and prompting the user to continue. """ from phcpy.phcpy2c2 import py2c_quaddobl_collapse_diagonal from phcpy.interface import store_quaddobl_solutions as storesols from phcpy.interface import load_quaddobl_solutions as loadsols from phcpy.interface import load_quaddobl_system as loadsys from phcpy.phcpy2c2 import py2c_extrinsic_top_diagonal_dimension from phcpy.solutions import filter_vanishing from phcpy.sets import drop_coordinate_from_quaddobl_solutions from phcpy.sets import drop_variable_from_quaddobl_polynomials from phcpy.cascades import quad_double_cascade_step topdim = py2c_extrinsic_top_diagonal_dimension(dim+dm1, dim+dm2, dm1, dm2) kdm = len(sys1) - dm1 topdiagdim = top_diagonal_dimension(kdm, dm1, dm2) if verbose: print 'the top dimension :', topdim, 'dim :', dim print 'number of slack variables at the top :', topdiagdim quaddobl_diagonal_homotopy(dm1, sys1, sols1, dm2, sys2, sols2) if verbose: print 'defining the start solutions' quaddobl_diagonal_cascade_solutions(dm1, dm2) if verbose: print 'starting the diagonal cascade' (topsys, startsols) = quaddobl_start_diagonal_cascade() if verbose: print 'the system solved in the start of the cascade :' for pol in topsys: print pol print 'the solutions after starting the diagonal cascade :' for sol in startsols: print sol raw_input('hit enter to continue') for k in range(topdiagdim, 0, -1): endsols = quad_double_cascade_step(k, topsys, startsols) if verbose: print 'after running cascade step %d :' % k for sol in endsols: print sol endsolsf1 = filter_vanishing(endsols, 1.0e-8) if verbose: print 'computed', len(endsolsf1), 'solutions' raw_input('hit enter to continue') slack = 'zz' + str(k) nbvar = len(topsys) endsolsf2 = drop_coordinate_from_quaddobl_solutions\ (endsolsf1, nbvar, slack) if verbose: print 'after dropping the slack coordinate from the solutions :' for sol in endsolsf2: print sol raw_input('hit enter to continue') nextsys = drop_variable_from_quaddobl_polynomials(topsys, slack) if verbose: print 'after dropping the variable', slack, 'from the system :' for pol in nextsys: print pol (topsys, startsols) = (nextsys[:-1], endsolsf2) storesols(len(topsys), startsols) # py2c_quaddobl_collapse_diagonal(topdim - 2*dim, 0) py2c_quaddobl_collapse_diagonal(0, 0) result = (loadsys(), loadsols()) return result