def from_FractionField(K1, a, K0): """ Convert a fraction field element to another fraction field. Examples ======== >>> from sympy.polys.polyclasses import DMF >>> from sympy.polys.domains import ZZ, QQ >>> from sympy.abc import x >>> f = DMF(([ZZ(1), ZZ(2)], [ZZ(1), ZZ(1)]), ZZ) >>> QQx = QQ.frac_field(x) >>> ZZx = ZZ.frac_field(x) >>> QQx.from_FractionField(f, ZZx) (x + 2)/(x + 1) """ if K1.gens == K0.gens: if K1.dom == K0.dom: return a else: return K1((a.numer().convert(K1.dom).rep, a.denom().convert(K1.dom).rep)) elif set(K0.gens).issubset(K1.gens): nmonoms, ncoeffs = _dict_reorder(a.numer().to_dict(), K0.gens, K1.gens) dmonoms, dcoeffs = _dict_reorder(a.denom().to_dict(), K0.gens, K1.gens) if K1.dom != K0.dom: ncoeffs = [ K1.dom.convert(c, K0.dom) for c in ncoeffs ] dcoeffs = [ K1.dom.convert(c, K0.dom) for c in dcoeffs ] return K1((dict(zip(nmonoms, ncoeffs)), dict(zip(dmonoms, dcoeffs))))
def set_ring(self, new_ring): if self.ring == new_ring: return self elif self.ring.symbols != new_ring.symbols: terms = zip(*_dict_reorder(self, self.ring.symbols, new_ring.symbols)) return new_ring.from_terms(terms) else: return new_ring.from_dict(self)
def from_GlobalPolynomialRing(K1, a, K0): """Convert a `DMP` object to `dtype`. """ if K1.gens == K0.gens: if K1.dom == K0.dom: return K1(a.rep) # set the correct ring else: return K1(a.convert(K1.dom).rep) else: monoms, coeffs = _dict_reorder(a.to_dict(), K0.gens, K1.gens) if K1.dom != K0.dom: coeffs = [ K1.dom.convert(c, K0.dom) for c in coeffs ] return K1(dict(zip(monoms, coeffs)))
def from_PolynomialRing(K1, a, K0): """Convert a ``PolyElement`` object to ``dtype``. """ if K1.gens == K0.symbols: if K1.dom == K0.dom: return K1(dict(a)) # set the correct ring else: convert_dom = lambda c: K1.dom.convert_from(c, K0.dom) return K1({m: convert_dom(c) for m, c in a.items()}) else: monoms, coeffs = _dict_reorder(a.to_dict(), K0.symbols, K1.gens) if K1.dom != K0.dom: coeffs = [ K1.dom.convert(c, K0.dom) for c in coeffs ] return K1(dict(zip(monoms, coeffs)))