'Computes the functional composition of ``f`` and ``g``.
Examples
>>> from sympy import Poly
>>> from sympy.abc import x
>>> Poly(x**2 + x, x).compose(Poly(x - 1, x))
Poly(x**2 - x, x, domain=\'ZZ\')'

def compose(f, g):

    (_, per, F, G) = f._unify(g)
    if hasattr(f.rep, 'compose'):
        result = F.compose(G)
    else:
        raise OperationNotSupported(f, 'compose')
    return per(result)
