def initialTerms(poly, positivesOnly=False): """ Return a list of (*gamma,c)* pairs giving the first terms of each Puiseux solution of :py:data:`poly`. """ #hull = lowerHull(poly.support()) hull = ploty(poly.support(), 'hi') if len(hull) == 1: return [] slopes = [] for i in xrange(len(hull) - 1): slopes.append(slp(hull[i], hull[i + 1])) slope_vertices = { } # dictionary with slope:[list of vertices on that edge] for slope in slopes: slope_vertices[slope] = [] slope_vertices[slopes[0]].append(hull[0][0]) oldSlope = slopes[0] for i in xrange(1, len(hull)): slope_vertices[oldSlope].append(hull[i][0]) if (i < len(hull) - 1) and slopes[i] != oldSlope: oldSlope = slopes[i] slope_vertices[oldSlope].append(hull[i][0]) slope_roots = {} for slope in slope_vertices.keys(): if positivesOnly and slope >= 0: continue deg = max(slope_vertices[slope]) toAdd = [] for i in xrange(deg + 1): toAdd.append(0) slope_roots[slope] = toAdd for i in slope_vertices[slope]: slope_roots[slope][i] = poly.internal[i].LC() slope_roots[slope].reverse() for key in slope_roots.keys(): while slope_roots[key][-1] == 0: #don't care about coeffs that are 0 slope_roots[key].pop() toAdd = [] for x in np.roots(slope_roots[key]): toAdd.append(complex(x)) slope_roots[key] = toAdd toReturn = [] for slope in slope_roots.keys(): for coeff in slope_roots[slope]: toReturn.append((-slope, coeff)) ############################ # Removing duplicates toReturn2 = [] for item in toReturn: if item not in toReturn2: toReturn2.append(item) ############################ return toReturn2
def initialTerms(poly,positivesOnly=False): """ Return a list of (*gamma,c)* pairs giving the first terms of each Puiseux solution of :py:data:`poly`. """ #hull = lowerHull(poly.support()) hull = ploty(poly.support(),'hi') if len(hull)==1: return [] slopes = [] for i in xrange(len(hull)-1): slopes.append(slp(hull[i],hull[i+1])) slope_vertices = {} # dictionary with slope:[list of vertices on that edge] for slope in slopes: slope_vertices[slope] = [] slope_vertices[slopes[0]].append(hull[0][0]) oldSlope = slopes[0] for i in xrange(1,len(hull)): slope_vertices[oldSlope].append(hull[i][0]) if (i<len(hull)-1) and slopes[i]!=oldSlope: oldSlope = slopes[i] slope_vertices[oldSlope].append(hull[i][0]) slope_roots = {} for slope in slope_vertices.keys(): if positivesOnly and slope>=0: continue deg = max(slope_vertices[slope]) toAdd = [] for i in xrange(deg+1): toAdd.append(0) slope_roots[slope] = toAdd for i in slope_vertices[slope]: slope_roots[slope][i] = poly.internal[i].LC() slope_roots[slope].reverse() for key in slope_roots.keys(): while slope_roots[key][-1]==0: #don't care about coeffs that are 0 slope_roots[key].pop() toAdd = [] for x in np.roots(slope_roots[key]): toAdd.append(complex(x)) slope_roots[key] = toAdd toReturn = [] for slope in slope_roots.keys(): for coeff in slope_roots[slope]: toReturn.append((-slope,coeff)) ############################ # Removing duplicates toReturn2 = [] for item in toReturn: if item not in toReturn2: toReturn2.append(item) ############################ return toReturn2
def initialTerms(poly,positivesOnly=False): """ Return a list of (gamma,c) pairs giving the first terms of each Puiseux solution of poly. """ hull = lowerHull(poly.support()) slopes = [slp(hull[i],hull[i+1]) for i in xrange(len(hull)-1)] # dictionary with slope:[list of vertices on that edge] slope_vertices = {slope:[] for slope in slopes} slope_vertices[slopes[0]].append(hull[0][0]) oldSlope = slopes[0] for i in xrange(1,len(hull)): slope_vertices[oldSlope].append(hull[i][0]) if (i<len(hull)-1) and slopes[i]!=oldSlope: oldSlope = slopes[i] slope_vertices[oldSlope].append(hull[i][0]) slope_roots = {} for slope in slope_vertices: if positivesOnly and slope>=0: continue deg = max(slope_vertices[slope]) slope_roots[slope] = [0 for i in xrange(deg+1)] for i in slope_vertices[slope]: slope_roots[slope][i] = poly.internal[i].LC() slope_roots[slope].reverse() for key in slope_roots: while slope_roots[key][-1]==0: #don't care about coeffs that are 0 slope_roots[key].pop() slope_roots[key]=[complex(x) for x in np.roots(slope_roots[key])] toReturn = [] for slope in slope_roots: for coeff in slope_roots[slope]: toReturn.append((-slope,coeff)) ######################### # Removing duplicates toReturn2 = [] for item in toReturn: if item not in toReturn2: toReturn2.append(item) ######################### return toReturn2
def initialTerms(poly, positivesOnly=False): """ Return a list of (gamma,c) pairs giving the first terms of each Puiseux solution of poly. """ hull = lowerHull(poly.support()) slopes = [slp(hull[i], hull[i + 1]) for i in xrange(len(hull) - 1)] # dictionary with slope:[list of vertices on that edge] slope_vertices = {slope: [] for slope in slopes} slope_vertices[slopes[0]].append(hull[0][0]) oldSlope = slopes[0] for i in xrange(1, len(hull)): slope_vertices[oldSlope].append(hull[i][0]) if (i < len(hull) - 1) and slopes[i] != oldSlope: oldSlope = slopes[i] slope_vertices[oldSlope].append(hull[i][0]) slope_roots = {} for slope in slope_vertices: if positivesOnly and slope >= 0: continue deg = max(slope_vertices[slope]) slope_roots[slope] = [0 for i in xrange(deg + 1)] for i in slope_vertices[slope]: slope_roots[slope][i] = poly.internal[i].LC() slope_roots[slope].reverse() for key in slope_roots: while slope_roots[key][-1] == 0: #don't care about coeffs that are 0 slope_roots[key].pop() slope_roots[key] = [complex(x) for x in np.roots(slope_roots[key])] toReturn = [] for slope in slope_roots: for coeff in slope_roots[slope]: toReturn.append((-slope, coeff)) ######################### # Removing duplicates toReturn2 = [] for item in toReturn: if item not in toReturn2: toReturn2.append(item) ######################### return toReturn2