import os def coeffGenerator(deg=1): if deg==1: return[[1]] else: l=[] p=coeffGenerator(deg-1) for i in p: a=i+[1] b=i+[-1] l.append(a) l.append(b) return l def polyGenerator(deg=1): var('x') l=[] for p in coeffGenerator(deg): l.append(sum([b*x^a for (a,b) in enumerate(p)])) return l def numericalSolutionsWithSaves(deg=1,batch_sz=10000): path="polynomials"+str(deg) if os.path.isfile(path+".sobj") is False: polynomials=polyGenerator(deg) save(polynomials,path) polynomials=load(path) while len(polynomials)!=0: solutions=[] for p in polynomials[:batch_sz]: solutions.append([s[x].n(20) for s in solve(p, var('x'), solution_dict=True, to_polysolve=True) if x in s]) save(solutions,"deg"+str(deg)+""+str(floor(len(polynomials)/batch_sz))) polynomials=polynomials[batch_sz:] save(polynomials,path) numericalSolutionsWithSaves(22,50000)