(p1, n, x, prec)
return p
return ``p1**n`` modulo ``O(x**prec)``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_pow
    >>> R, x = ring('x', QQ)
    >>> p = x + 1
    >>> rs_pow(p, 4, x, 3)
    6*x**2 + 4*x + 1
return ``p1**n`` modulo ``O(x**prec)``
return p1 ** n modulo O ( x ** prec )
def rs_pow(p1, n, x, prec):
    """
    return ``p1**n`` modulo ``O(x**prec)``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_pow
    >>> R, x = ring('x', QQ)
    >>> p = x + 1
    >>> rs_pow(p, 4, x, 3)
    6*x**2 + 4*x + 1
    """
    R = p1.ring
    p = R.zero
    if isinstance(n, Rational):
        raise NotImplementedError('to be implemented')

    n = as_int(n)
    if n == 0:
        if p1:
            return R(1)
        else:
            raise ValueError('0**0 is undefined')
    if n < 0:
        p1 = rs_pow(p1, -n, x, prec)
        return rs_series_inversion(p1, x, prec)
    if n == 1:
        return rs_trunc(p1, x, prec)
    if n == 2:
        return rs_square(p1, x, prec)
    if n == 3:
        p2 = rs_square(p1, x, prec)
        return rs_mul(p1, p2, x, prec)
    p = R(1)
    while 1:
        if n&1:
            p = rs_mul(p1, p, x, prec)
            n -= 1
            if not n:
                break
        p1 = rs_square(p1, x, prec)
        n = n // 2
    return p
def rs_pow ( p1 , n , x , prec ) : R = p1 . ring p = R . zero if isinstance ( n , Rational ) : raise NotImplementedError ( 'to be implemented' ) n = as_int ( n ) if n == 0 : if p1 : return R ( 1 ) else : raise ValueError ( '0**0 is undefined' ) if n < 0 : p1 = rs_pow ( p1 , - n , x , prec ) return rs_series_inversion ( p1 , x , prec ) if n == 1 : return rs_trunc ( p1 , x , prec ) if n == 2 : return rs_square ( p1 , x , prec ) if n == 3 : p2 = rs_square ( p1 , x , prec ) return rs_mul ( p1 , p2 , x , prec ) p = R ( 1 ) while 1 : if n & 1 : p = rs_mul ( p1 , p , x , prec ) n -= 1 if not n : break p1 = rs_square ( p1 , x , prec ) n = n // 2 return p