def promote(self, other): if isinstance(other, Rational): return other #if isinstance(other, Poly): # return other other = Poly.promote(other, self.base) other = Rational(self.base, other, self.base.one) return other
def __init__(self, base, p, q, vs=None): # f(x) == p(x) / q(x) # q(x)*f(x) == p(x) p = Poly.promote(p, base) q = Poly.promote(q, base) zero, one = base.zero, base.one if vs is None: vs = p.get_vars() + q.get_vars() vs = list(set(vs)) vs.sort() n = len(vs) #assert n>0 #print("Rational(%s, %s, %s)" % (p, q, vs)) fs = {} vzero = tuple((v,zero) for v in vs) top = p.substitute(vzero) bot = q.substitute(vzero) if bot == 0: fs = None else: #print("top=%s, bot=%s" % (top, bot)) f0 = top/bot #print("f0:", lstr(f0)) fs[(0,)*n] = f0 self.base = base self.p = p self.q = q self.fs = fs self.vzero = vzero self.vs = vs self.bot = bot