def total_degree(pols): """ Given in pols a list of string representations of polynomials, returns the product of the degrees of the polynomials, the so-called total degree which bounds the number of isolated solutions of the polynomial system. """ from phcpy.phcpy2c2 import py2c_syscon_total_degree from phcpy.interface import store_standard_system store_standard_system(pols) return py2c_syscon_total_degree()
def permute_standard_system(pols): """ Permutes the equations in the list of polynomials in pols with coefficients in standard double precision, along the permutation used in the mixed volume computation. """ from phcpy.phcpy2c2 import py2c_celcon_permute_standard_system from phcpy.interface import store_standard_system, load_standard_system store_standard_system(pols) py2c_celcon_permute_standard_system() return load_standard_system()
def standard_scale_system(pols): """ Applies equation and variable scaling in standard double precision to the polynomials in the list pols. On return is the list of scaled polynomials and the scaling coefficients. """ from phcpy.interface import store_standard_system, load_standard_system from phcpy.phcpy2c2 import py2c_scale_standard_system store_standard_system(pols) cffs = py2c_scale_standard_system(2) spol = load_standard_system() return (spol, cffs)
def standard_usolve(pol, mxi, eps): """ Applies the method of Durand-Kerner (aka Weierstrass) to the polynomial in the string pol, in standard double precision The maximum number of iterations is in mxi, the requirement on the accuracy in eps. """ from phcpy.phcpy2c2 import py2c_usolve_standard from phcpy.interface import store_standard_system, load_standard_solutions store_standard_system([pol]) nit = py2c_usolve_standard(mxi, eps) rts = load_standard_solutions() return (nit, rts)
def m_partition_bezout_number(pols, partition): """ There are as many m-homogeneous Bezout numbers as there are partitions of the set of unknowns of a polynomial system. Given in pols the string representations of a polynomial system in as many variables as equations, and a string representation of a partition of the set of unknowns, this function returns the m-homogeneous Bezout number corresponding to the given partition. """ from phcpy.phcpy2c2 import py2c_product_m_partition_Bezout_number from phcpy.interface import store_standard_system store_standard_system(pols) return py2c_product_m_partition_Bezout_number(len(partition), partition)
def newton_step(system, solutions, precision='d', decimals=100): """ Applies one Newton step to the solutions of the 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_system from interface import store_standard_solutions, load_standard_solutions store_standard_system(system) store_standard_solutions(len(system), solutions) from phcpy.phcpy2c2 import py2c_standard_Newton_step py2c_standard_Newton_step() result = load_standard_solutions() elif(precision == 'dd'): from interface import store_dobldobl_system from interface import store_dobldobl_solutions, load_dobldobl_solutions store_dobldobl_system(system) store_dobldobl_solutions(len(system), solutions) from phcpy.phcpy2c2 import py2c_dobldobl_Newton_step py2c_dobldobl_Newton_step() result = load_dobldobl_solutions() elif(precision == 'qd'): from interface import store_quaddobl_system from interface import store_quaddobl_solutions, load_quaddobl_solutions store_quaddobl_system(system) store_quaddobl_solutions(len(system), solutions) from phcpy.phcpy2c2 import py2c_quaddobl_Newton_step py2c_quaddobl_Newton_step() result = load_quaddobl_solutions() elif(precision == 'mp'): from interface import store_multprec_system from interface import store_multprec_solutions, load_multprec_solutions store_multprec_system(system, decimals) store_multprec_solutions(len(system), solutions) from phcpy.phcpy2c2 import py2c_multprec_Newton_step py2c_multprec_Newton_step(decimals) result = load_multprec_solutions() else: print 'wrong argument for precision' return None for sol in result: strsol = sol.split('\n') print strsol[-1] return result
def mixed_volume(pols, stable=False): """ Given in pols a list of string representations of polynomials, this function returns the mixed volume of the system. This is an interface to Algorithm 846: MixedVol of ACM TOMS, developed by Tangan Gao, T.Y. Li, Mengnien Wu, and Li Xing. If the option stable is set to True, then on return is a tuple containing the mixed volume and the stable mixed volume. The mixed volume counts the solutions with all their coordinates nonzero, the stable mixed volume counts all affine roots. Note that the stable mixed volume does not apply to systems with negative exponents. Incorrectly parsed strings will result in a negative value on return. """ from phcpy.phcpy2c2 import py2c_celcon_clear_container from phcpy.phcpy2c2 import py2c_mixed_volume from phcpy.interface import store_standard_system from phcpy.interface import store_standard_laurent_system py2c_celcon_clear_container() if stable: fail = store_standard_system(pols) else: fail = store_standard_laurent_system(pols) if(fail != 0): return -fail # a negative number is clearly wrong else: return py2c_mixed_volume(stable)
def m_homogeneous_bezout_number(pols): """ Given in pols a list of string representations of polynomials, in as many variables as the elements in the list, this function applies a heuristic to generate a partition of the set of unknowns to exploit the product structure of the system. On return are the m-homogeneous Bezout number and the partition of the set of unknowns. If the partition equals the entire set of unknowns, then the 1-homogeneous Bezout number equals the total degree of the system. """ from phcpy.phcpy2c2 import py2c_product_m_homogeneous_Bezout_number from phcpy.interface import store_standard_system store_standard_system(pols) result = py2c_product_m_homogeneous_Bezout_number() return result
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 phcpy.phcpy2c2 import py2c_standard_deflate from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_system(system) store_standard_solutions(len(system), solutions) py2c_standard_deflate() result = load_standard_solutions() return result
def total_degree_start_system(pols): """ Returns the system and solutions of the total degree start system for the polynomials represented by the strings in the list pols. """ from phcpy.phcpy2c2 import py2c_syscon_number_of_standard_polynomials from phcpy.phcpy2c2 import py2c_syscon_string_of_symbols from phcpy.phcpy2c2 import py2c_syscon_degree_of_standard_polynomial from phcpy.interface import store_standard_system store_standard_system(pols) dim = py2c_syscon_number_of_standard_polynomials() svars = py2c_syscon_string_of_symbols() nvars = svars.split(' ') degrees = [py2c_syscon_degree_of_standard_polynomial(k+1) \ for k in range(dim)] result = [] for ind in range(dim): result.append(nvars[ind]+'^'+str(degrees[ind])+' - 1;') return (result, solve(result))
def random_linear_product_system(pols, tosolve=True): """ Given in pols a list of string representations of polynomials, returns a random linear-product system based on a supporting set structure and its solutions as well (if tosolve). """ from phcpy.phcpy2c2 import py2c_product_supporting_set_structure from phcpy.phcpy2c2 import py2c_product_random_linear_product_system from phcpy.phcpy2c2 import py2c_product_solve_linear_product_system from phcpy.interface import store_standard_system, load_standard_system from phcpy.interface import load_standard_solutions store_standard_system(pols) py2c_product_supporting_set_structure() py2c_product_random_linear_product_system() result = load_standard_system() if not tosolve: return result py2c_product_solve_linear_product_system() sols = load_standard_solutions() return (result, sols)
def linear_product_root_count(pols, silent=False): """ Given in pols a list of string representations of polynomials, returns a linear-product root count based on a supporting set structure of the polynomials in pols. This root count is an upper bound for the number of isolated solutions. """ from phcpy.phcpy2c2 import py2c_product_supporting_set_structure from phcpy.phcpy2c2 import py2c_product_write_set_structure from phcpy.phcpy2c2 import py2c_product_linear_product_root_count from phcpy.interface import store_standard_system store_standard_system(pols) py2c_product_supporting_set_structure() if not silent: print 'a supporting set structure :' py2c_product_write_set_structure() root_count = py2c_product_linear_product_root_count() if not silent: print 'the root count :', root_count return root_count
def m_homogeneous_start_system(pols, partition): """ For an m-homogeneous Bezout number of a polynomial system defined by a partition of the set of unknowns, one can define a linear-product system that has exactly as many regular solutions as the Bezount number. This linear-product system can then be used as start system in a homotopy to compute all isolated solutions of any polynomial system with the same m-homogeneous structure. This function returns a linear-product start system with random coefficients and its solutions for the given polynomials in pols and the partition. """ from phcpy.phcpy2c2 import py2c_product_m_homogeneous_start_system from phcpy.phcpy2c2 import py2c_product_solve_linear_product_system from phcpy.interface import store_standard_system, load_standard_system from phcpy.interface import load_standard_solutions store_standard_system(pols) py2c_product_m_homogeneous_start_system(len(partition), partition) result = load_standard_system() py2c_product_solve_linear_product_system() sols = load_standard_solutions() return (result, sols)