'Efficiently evaluate the functional transformation ``q**n * f(p/q)``.
Examples
>>> from sympy import Poly
>>> from sympy.abc import x
>>> Poly(x**2 - 2*x + 1, x).transform(Poly(x + 1, x), Poly(x - 1, x))
Poly(4, x, domain=\'ZZ\')'

def transform(f, p, q):

    (P, Q) = p.unify(q)
    (F, P) = f.unify(P)
    (F, Q) = F.unify(Q)
    if hasattr(F.rep, 'transform'):
        result = F.rep.transform(P.rep, Q.rep)
    else:
        raise OperationNotSupported(F, 'transform')
    return F.per(result)
