'Cancel common factors in a rational function ``f/g``.
Examples
>>> from sympy import Poly
>>> from sympy.abc import x
>>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x))
(1, Poly(2*x + 2, x, domain=\'ZZ\'), Poly(x - 1, x, domain=\'ZZ\'))
>>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x), include=True)
(Poly(2*x + 2, x, domain=\'ZZ\'), Poly(x - 1, x, domain=\'ZZ\'))'

def cancel(f, g, include=False):

    (dom, per, F, G) = f._unify(g)
    if hasattr(F, 'cancel'):
        result = F.cancel(G, include=include)
    else:
        raise OperationNotSupported(f, 'cancel')
    if (not include):
        if dom.has_assoc_Ring:
            dom = dom.get_ring()
        (cp, cq, p, q) = result
        cp = dom.to_sympy(cp)
        cq = dom.to_sympy(cq)
        return ((cp / cq), per(p), per(q))
    else:
        return tuple(map(per, result))
