'Compute ``f**(-1)`` mod ``x**n``.
Examples
>>> from sympy import Poly
>>> from sympy.abc import x
>>> Poly(1, x).revert(2)
Poly(1, x, domain=\'ZZ\')
>>> Poly(1 + x, x).revert(1)
Poly(1, x, domain=\'ZZ\')
>>> Poly(x**2 - 1, x).revert(1)
Traceback (most recent call last):
NotReversible: only unity is reversible in a ring
>>> Poly(1/x, x).revert(1)
Traceback (most recent call last):
PolynomialError: 1/x contains an element of the generators set'

def revert(f, n):

    if hasattr(f.rep, 'revert'):
        result = f.rep.revert(int(n))
    else:
        raise OperationNotSupported(f, 'revert')
    return f.per(result)
