Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def standard_scale_solutions(nvar, sols, cffs):
"""
Scales the solutions in the list sols using the coefficients in cffs,
using standard double precision arithmetic.
The number of variables is given in the parameter nvar.
If the sols are the solution of the polynomials in the output of
standard_scale_system(pols), then the solutions on return will be
solutions of the original polynomials in the list pols.
"""
from interface import store_standard_solutions, load_standard_solutions
from phcpy2c import py2c_scale_standard_solutions
store_standard_solutions(nvar, sols)
py2c_scale_standard_solutions(len(cffs), str(cffs))
return load_standard_solutions()
def standard_deflate(system, solutions):
"""
The deflation method augments the given system with
derivatives to restore the quadratic convergence of
Newton's method at isolated singular solutions,
in standard double precision.
After application of deflation with default settings,
the new approximate solutions are returned.
"""
from phcpy2c import py2c_standard_deflate
from interface import store_standard_system
from interface import store_standard_solutions, load_standard_solutions
store_standard_system(system)
store_standard_solutions(len(system), solutions)
py2c_standard_deflate()
result = load_standard_solutions()
return result
def newton_laurent_step(system, solutions, precision='d', decimals=100):
"""
Applies one Newton step to the solutions of the Laurent system.
For each solution, prints its last line of diagnostics.
Four levels of precision are supported:
d : standard double precision (1.1e-15 or 2^(-53)),
dd : double double precision (4.9e-32 or 2^(-104)),
qd : quad double precision (1.2e-63 or 2^(-209)).
mp : arbitrary precision, where the number of decimal places
in the working precision is determined by decimals.
"""
if(precision == 'd'):
from interface import store_standard_laurent_system
from interface import store_standard_solutions, load_standard_solutions
store_standard_laurent_system(system)
store_standard_solutions(len(system), solutions)
from phcpy2c import py2c_standard_Newton_Laurent_step
py2c_standard_Newton_Laurent_step()
result = load_standard_solutions()
elif(precision == 'dd'):
from interface import store_dobldobl_laurent_system
from interface import store_dobldobl_solutions, load_dobldobl_solutions
store_dobldobl_laurent_system(system)
store_dobldobl_solutions(len(system), solutions)
from phcpy2c import py2c_dobldobl_Newton_Laurent_step
py2c_dobldobl_Newton_Laurent_step()
result = load_dobldobl_solutions()
elif(precision == 'qd'):
from interface import store_quaddobl_laurent_system
from interface import store_quaddobl_solutions, load_quaddobl_solutions
store_quaddobl_laurent_system(system)
store_quaddobl_solutions(len(system), solutions)
def drop_coordinate_from_solutions(sols, nbvar, svar):
"""
Removes the variable with symbol in the string svar
from the list sols of strings that represent solutions
in nbvar variables.
"""
from phcpy2c import py2c_syscon_clear_symbol_table
from phcpy2c import py2c_solcon_standard_drop_coordinate_by_name
from phcpy2c import py2c_syscon_remove_symbol_name
from interface import store_standard_solutions, load_standard_solutions
py2c_syscon_clear_symbol_table()
store_standard_solutions(nbvar, sols)
py2c_solcon_standard_drop_coordinate_by_name(len(svar), svar)
py2c_syscon_remove_symbol_name(len(svar), svar)
return load_standard_solutions()
def initialize_standard_solution(nvar, sol):
"""
A standard double precision path tracker with a generator is
initialized with a start solution sol in a number of
variables equal to the value of nvar.
"""
from phcpy2c import py2c_initialize_standard_solution
from interface import store_standard_solutions
store_standard_solutions(nvar, [sol])
return py2c_initialize_standard_solution(1)
from phcpy2c import py2c_solve_by_standard_homotopy_continuation
from phcpy2c import py2c_solcon_clear_standard_solutions
from phcpy2c import py2c_copy_standard_target_solutions_to_container
from interface import store_standard_system
from interface import store_standard_solutions, load_standard_solutions
store_standard_system(target)
py2c_copy_standard_container_to_target_system()
store_standard_system(start)
py2c_copy_standard_container_to_start_system()
# py2c_clear_standard_homotopy()
if(gamma == 0):
py2c_create_standard_homotopy()
else:
py2c_create_standard_homotopy_with_gamma(gamma.real, gamma.imag)
dim = len(start)
store_standard_solutions(dim, sols)
py2c_copy_standard_container_to_start_solutions()
py2c_solve_by_standard_homotopy_continuation(tasks)
py2c_solcon_clear_standard_solutions()
py2c_copy_standard_target_solutions_to_container()
return load_standard_solutions()
def standard_scale_solutions(nvar, sols, cffs):
"""
Scales the solutions in the list sols using the coefficients in cffs,
using standard double precision arithmetic.
The number of variables is given in the parameter nvar.
If the sols are the solution of the polynomials in the output of
standard_scale_system(pols), then the solutions on return will be
solutions of the original polynomials in the list pols.
"""
from interface import store_standard_solutions, load_standard_solutions
from phcpy2c import py2c_scale_standard_solutions
store_standard_solutions(nvar, sols)
py2c_scale_standard_solutions(len(cffs), str(cffs))
return load_standard_solutions()
from phcpy2c import py2c_factor_track_paths
from phcpy2c import py2c_factor_store_solutions
from phcpy2c import py2c_factor_restore_solutions
from phcpy2c import py2c_factor_new_slices
from phcpy2c import py2c_factor_swap_slices
from phcpy2c import py2c_factor_permutation_after_loop
from phcpy2c import py2c_factor_number_of_components
from phcpy2c import py2c_factor_update_decomposition
from phcpy2c import py2c_solcon_clear_standard_solutions
from interface import store_standard_solutions
print '... applying monodromy factorization ...'
py2c_factor_set_to_mute()
deg = len(esols)
nvar = len(embsys)
print 'dim =', dim
store_standard_solutions(nvar, esols)
py2c_factor_assign_labels(nvar, deg)
# py2c_solcon_write_solutions()
py2c_factor_initialize_sampler(dim)
nbloops = input('give the maximum number of loops : ')
py2c_factor_initialize_monodromy(nbloops, deg, dim)
py2c_factor_store_solutions()
print '... initializing the grid ...'
for i in range(1, 3):
py2c_factor_set_trace_slice(i)
py2c_factor_store_gammas(nvar)
py2c_factor_track_paths()
py2c_factor_store_solutions()
py2c_factor_restore_solutions()
py2c_factor_swap_slices()
for i in range(1, nbloops+1):
print '... starting loop %d ...' % i