def __init__(self, polynomials, variables): """ A class that takes two lists, a list of polynomials and list of variables. Returns the Dixon matrix of the multivariate system. Parameters ---------- polynomials : list of polynomials A list of m n-degree polynomials variables: list A list of all n variables """ self.polynomials = polynomials self.variables = variables self.n = len(self.variables) self.m = len(self.polynomials) a = IndexedBase("alpha") # A list of n alpha variables (the replacing variables) self.dummy_variables = [a[i] for i in range(self.n)] # A list of the d_max of each variable. self.max_degrees = [ total_degree(poly, *self.variables) for poly in self.polynomials ]
def __init__(self, polynomials, variables): """ A class that takes two lists, a list of polynomials and list of variables. Returns the Dixon matrix of the multivariate system. Parameters ---------- polynomials : list of polynomials A list of m n-degree polynomials variables: list A list of all n variables """ self.polynomials = polynomials self.variables = variables self.n = len(self.variables) self.m = len(self.polynomials) a = IndexedBase("alpha") # A list of n alpha variables (the replacing variables) self.dummy_variables = [a[i] for i in range(self.n)] # A list of the d_max of each variable. self.max_degrees = [total_degree(poly, *self.variables) for poly in self.polynomials]
def get_reduced_nonreduced(self): r""" Returns ------- reduced: list A list of the reduced monomials non_reduced: list A list of the monomials that are not reduced Definition. --------- A polynomial is said to be reduced in x_i, if its degree (the maximum degree of its monomials) in x_i is less than d_i. A polynomial that is reduced in all variables but one is said simply to be reduced. """ divisible = [] for m in self.monomial_set: temp = [] for i, v in enumerate(self.variables): temp.append(bool(total_degree(m, v) >= self.degrees[i])) divisible.append(temp) reduced = [i for i, r in enumerate(divisible) if sum(r) < self.n - 1] non_reduced = [ i for i, r in enumerate(divisible) if sum(r) >= self.n - 1 ] return reduced, non_reduced
def get_reduced_nonreduced(self): r""" Returns ------- reduced: list A list of the reduced monomials non_reduced: list A list of the monomials that are not reduced Definition. --------- A polynomial is said to be reduced in x_i, if its degree (the maximum degree of its monomials) in x_i is less than d_i. A polynomial that is reduced in all variables but one is said simply to be reduced. """ divisible = [] for m in self.monomial_set: temp = [] for i, v in enumerate(self.variables): temp.append(bool(total_degree(m, v) >= self.degrees[i])) divisible.append(temp) reduced = [i for i, r in enumerate(divisible) if sum(r) < self.n - 1] non_reduced = [i for i, r in enumerate(divisible) if sum(r) >= self.n -1] return reduced, non_reduced
def enum_ipolys(xs, max_degree, max_summands, max_coeff, max_ipolys): """ Enumerates _some_ irreducible polynomials upto degree `max_degree`. Args: - xs (list of sympy symbols): the variables composing the monomials - max_degree (int): the maximum degree of the monomials - max_summands (int): the maximum number of summands in a polynomial - max_coeff (int): the maximum coefficient magnitude of a monomial - max_ipolys (int): the maximum number of irreducible polynomials to generate Returns: - stats (dict): statistics of the generation process - ipolys (dict): maps (degree, def_nneg) to a set of irreducible polynomials """ stats = collections.defaultdict(int) ipolys = collections.defaultdict(set) for ums in util.flatten([itertools.combinations(enum_umonomials(xs, max_degree), n_summands) for n_summands in range(1, max_summands+1)]): d_poly = max([sp.total_degree(um) for um in ums]) for cs in itertools.product(*([list(range(-max_coeff, 0) ) + list(range(1, max_coeff + 1))] * len(ums))): if all([c < 0 for c in cs]) or functools.reduce(math.gcd, cs) != 1: continue poly = sum([c * um for c, um in zip(cs, ums)]) for ipoly in util.compute_ifactors(poly): d_ipoly = sp.total_degree(ipoly) def_nneg = not util.contains_negation(ipoly) if ipoly in ipolys[(d_ipoly, def_nneg)]: stats['n_dups_%d' % d_ipoly] += 1 else: stats['n_new_%d' % d_ipoly] += 1 ipolys[(d_ipoly, def_nneg)].add(ipoly) stats['n_ipolys'] += 1 if stats['n_ipolys'] > 0 and stats['n_ipolys'] % 1000 == 0: print(dict(stats)) if max_ipolys is not None and stats['n_ipolys'] >= max_ipolys: return stats, ipolys return stats, ipolys
def __init__(self, polynomials, variables): """ Parameters ---------- variables: list A list of all n variables polynomials : list of sympy polynomials A list of m n-degree polynomials """ self.polynomials = polynomials self.variables = variables self.n = len(variables) # A list of the d_max of each variable. self.degrees = [total_degree(poly, *self.variables) for poly in self.polynomials] self.degree_m = self._get_degree_m() self.monomials_size = self.get_size()
def __init__(self, polynomials, variables): """ Parameters ---------- variables: list A list of all n variables polynomials : list of sympy polynomials A list of m n-degree polynomials """ self.polynomials = polynomials self.variables = variables self.n = len(variables) # A list of the d_max of each variable. self.degrees = [ total_degree(poly, *self.variables) for poly in self.polynomials ] self.degree_m = self._get_degree_m() self.monomials_size = self.get_size()
def reduce_direct_solve(self): # Look for equations which are linear in some variable for eq in self.eqs: for x in [ x for x in eq.free_symbols.difference(self.S_vars) if eq.degree(x) == 1 ]: # See if we can directly solve for x r = eq.subs(x, 0) q = (eq - r) / x if sp.total_degree(q) != 0: continue # Solve for x and remove x from X_vars x_value = -r / q self.X_vars = self.X_vars.copy() self.X_vars.remove(x) self.eqs = [ to_poly(f.subs(x, x_value), self.X_vars) for f in self.eqs if f != eq ] self.op_eqs = [ to_poly(f.subs(x, x_value), self.X_vars) for f in self.op_eqs ] return True else: return False