(f, g)
return f.__radd__(g)
Add rational functions ``f`` and ``g``.
Add rational functions ``f`` and ``g``.
Add rational functions f and g .
def __add__(f, g):
        """Add rational functions ``f`` and ``g``. """
        field = f.field

        if not g:
            return f
        elif not f:
            return g
        elif isinstance(g, field.dtype):
            if f.denom == g.denom:
                return f.new(f.numer + g.numer, f.denom)
            else:
                return f.new(f.numer*g.denom + f.denom*g.numer, f.denom*g.denom)
        elif isinstance(g, field.ring.dtype):
            return f.new(f.numer + f.denom*g, f.denom)
        else:
            if isinstance(g, FracElement):
                if isinstance(field.domain, FractionField) and field.domain.field == g.field:
                    pass
                elif isinstance(g.field.domain, FractionField) and g.field.domain.field == field:
                    return g.__radd__(f)
                else:
                    return NotImplemented
            elif isinstance(g, PolyElement):
                if isinstance(field.domain, PolynomialRing) and field.domain.ring == g.ring:
                    pass
                else:
                    return g.__radd__(f)

        return f.__radd__(g)
def __add__ ( f , g ) : field = f . field if not g : return f elif not f : return g elif isinstance ( g , field . dtype ) : if f . denom == g . denom : return f . new ( f . numer + g . numer , f . denom ) else : return f . new ( f . numer * g . denom + f . denom * g . numer , f . denom * g . denom ) elif isinstance ( g , field . ring . dtype ) : return f . new ( f . numer + f . denom * g , f . denom ) else : if isinstance ( g , FracElement ) : if isinstance ( field . domain , FractionField ) and field . domain . field == g . field : pass elif isinstance ( g . field . domain , FractionField ) and g . field . domain . field == field : return g . __radd__ ( f ) else : return NotImplemented elif isinstance ( g , PolyElement ) : if isinstance ( field . domain , PolynomialRing ) and field . domain . ring == g . ring : pass else : return g . __radd__ ( f ) return f . __radd__ ( g )