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. """ dim = number_of_symbols(system) if (precision == 'd'): from phcpy.interface import store_standard_laurent_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_laurent_system(system, nbvar=dim) store_standard_solutions(dim, solutions) from phcpy.phcpy2c3 import py2c_standard_Newton_Laurent_step py2c_standard_Newton_Laurent_step() result = load_standard_solutions() elif (precision == 'dd'): from phcpy.interface import store_dobldobl_laurent_system from phcpy.interface import store_dobldobl_solutions from phcpy.interface import load_dobldobl_solutions store_dobldobl_laurent_system(system, nbvar=dim) store_dobldobl_solutions(dim, solutions) from phcpy.phcpy2c3 import py2c_dobldobl_Newton_Laurent_step py2c_dobldobl_Newton_Laurent_step() result = load_dobldobl_solutions() elif (precision == 'qd'): from phcpy.interface import store_quaddobl_laurent_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions store_quaddobl_laurent_system(system, nbvar=dim) store_quaddobl_solutions(dim, solutions) from phcpy.phcpy2c3 import py2c_quaddobl_Newton_Laurent_step py2c_quaddobl_Newton_Laurent_step() result = load_quaddobl_solutions() elif (precision == 'mp'): from phcpy.interface import store_multprec_laurent_system from phcpy.interface import store_multprec_solutions from phcpy.interface import load_multprec_solutions store_multprec_laurent_system(system, decimals, nbvar=dim) store_multprec_solutions(dim, solutions) from phcpy.phcpy2c3 import py2c_multprec_Newton_Laurent_step py2c_multprec_Newton_Laurent_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 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 phcpy.interface import store_standard_laurent_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_laurent_system(system) store_standard_solutions(len(system), solutions) from phcpy.phcpy2c3 import py2c_standard_Newton_Laurent_step py2c_standard_Newton_Laurent_step() result = load_standard_solutions() elif(precision == 'dd'): from phcpy.interface import store_dobldobl_laurent_system from phcpy.interface import store_dobldobl_solutions from phcpy.interface import load_dobldobl_solutions store_dobldobl_laurent_system(system) store_dobldobl_solutions(len(system), solutions) from phcpy.phcpy2c3 import py2c_dobldobl_Newton_Laurent_step py2c_dobldobl_Newton_Laurent_step() result = load_dobldobl_solutions() elif(precision == 'qd'): from phcpy.interface import store_quaddobl_laurent_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions store_quaddobl_laurent_system(system) store_quaddobl_solutions(len(system), solutions) from phcpy.phcpy2c3 import py2c_quaddobl_Newton_Laurent_step py2c_quaddobl_Newton_Laurent_step() result = load_quaddobl_solutions() elif(precision == 'mp'): from phcpy.interface import store_multprec_laurent_system from phcpy.interface import store_multprec_solutions from phcpy.interface import load_multprec_solutions store_multprec_laurent_system(system, decimals) store_multprec_solutions(len(system), solutions) from phcpy.phcpy2c3 import py2c_multprec_Newton_Laurent_step py2c_multprec_Newton_Laurent_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 standard_laursys_solve(pols, topdim=-1, \ filter=True, factor=True, tasks=0, verbose=True): """ Runs the cascades of homotopies on the Laurent polynomial system in pols in standard double precision. The default top dimension topdim is the number of variables in pols minus one. """ from phcpy.phcpy2c3 import py2c_standard_laursys_solve from phcpy.phcpy2c3 import py2c_copy_standard_laursys_witset from phcpy.solver import number_of_symbols from phcpy.interface import store_standard_laurent_system from phcpy.interface import load_standard_laurent_system from phcpy.interface import load_standard_solutions dim = number_of_symbols(pols) if(topdim == -1): topdim = dim - 1 fail = store_standard_laurent_system(pols, nbvar=dim) fail = py2c_standard_laursys_solve(tasks,topdim, \ int(filter),int(factor),int(verbose)) witsols = [] for soldim in range(0, topdim+1): fail = py2c_copy_standard_laursys_witset(soldim) witset = (load_standard_laurent_system(), load_standard_solutions()) witsols.append(witset) return witsols
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.phcpy2c3 import py2c_celcon_clear_container from phcpy.phcpy2c3 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 standard_laursys_solve(pols, topdim=-1, \ filter=True, factor=True, tasks=0, verbose=True): """ Runs the cascades of homotopies on the Laurent polynomial system in pols in standard double precision. The default top dimension topdim is the number of variables in pols minus one. """ from phcpy.phcpy2c3 import py2c_standard_laursys_solve from phcpy.phcpy2c3 import py2c_copy_standard_laursys_witset from phcpy.solver import number_of_symbols from phcpy.interface import store_standard_laurent_system from phcpy.interface import load_standard_laurent_system from phcpy.interface import load_standard_solutions dim = number_of_symbols(pols) if (topdim == -1): topdim = dim - 1 fail = store_standard_laurent_system(pols, nbvar=dim) fail = py2c_standard_laursys_solve(tasks,topdim, \ int(filter),int(factor),int(verbose)) witsols = [] for soldim in range(0, topdim + 1): fail = py2c_copy_standard_laursys_witset(soldim) witset = (load_standard_laurent_system(), load_standard_solutions()) witsols.append(witset) return witsols
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.phcpy2c3 import py2c_celcon_clear_container from phcpy.phcpy2c3 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)