(p, t, z)
return ans
(Hackish) way to convert an element p of K[t, 1/t] to K[t, z].

    In other words, z == 1/t will be a dummy variable that Poly can handle
    better.

    See issue 5131.

    Examples
    ========

    >>> from sympy import Symbol, random_poly
    >>> from sympy.integrals.risch import as_poly_1t
    >>> from sympy.abc import x, z

    >>> p1 = random_poly(x, 10, -10, 10)
    >>> p2 = random_poly(x, 10, -10, 10)
    >>> p = p1 + p2.subs(x, 1/x)
    >>> as_poly_1t(p, x, z).as_expr().subs(z, 1/x) == p
    True
(Hackish) way to convert an element p of K[t, 1/t] to K[t, z].
( Hackish ) way to convert an element p of K [ t 1 / t ] to K [ t z ] .
def as_poly_1t(p, t, z):
    """
    (Hackish) way to convert an element p of K[t, 1/t] to K[t, z].

    In other words, z == 1/t will be a dummy variable that Poly can handle
    better.

    See issue 5131.

    Examples
    ========

    >>> from sympy import Symbol, random_poly
    >>> from sympy.integrals.risch import as_poly_1t
    >>> from sympy.abc import x, z

    >>> p1 = random_poly(x, 10, -10, 10)
    >>> p2 = random_poly(x, 10, -10, 10)
    >>> p = p1 + p2.subs(x, 1/x)
    >>> as_poly_1t(p, x, z).as_expr().subs(z, 1/x) == p
    True
    """
    # TODO: Use this on the final result.  That way, we can avoid answers like
    # (...)*exp(-x).
    pa, pd = frac_in(p, t, cancel=True)
    if not pd.is_monomial:
        # XXX: Is there a better Poly exception that we could raise here?
        # Either way, if you see this (from the Risch Algorithm) it indicates
        # a bug.
        raise PolynomialError("%s is not an element of K[%s, 1/%s]." % (p, t, t))
    d = pd.degree(t)
    one_t_part = pa.slice(0, d + 1)
    r = pd.degree() - pa.degree()
    t_part = pa - one_t_part
    try:
        t_part = t_part.to_field().exquo(pd)
    except DomainError as e:
        # issue 4950
        raise NotImplementedError(e)
    # Compute the negative degree parts.
    one_t_part = Poly.from_list(reversed(one_t_part.rep.rep), *one_t_part.gens,
        domain=one_t_part.domain)
    if 0 < r < oo:
        one_t_part *= Poly(t**r, t)

    one_t_part = one_t_part.replace(t, z)  # z will be 1/t
    if pd.nth(d):
        one_t_part *= Poly(1/pd.nth(d), z, expand=False)
    ans = t_part.as_poly(t, z, expand=False) + one_t_part.as_poly(t, z,
        expand=False)

    return ans
def as_poly_1t ( p , t , z ) : # TODO: Use this on the final result.  That way, we can avoid answers like # (...)*exp(-x). pa , pd = frac_in ( p , t , cancel = True ) if not pd . is_monomial : # XXX: Is there a better Poly exception that we could raise here? # Either way, if you see this (from the Risch Algorithm) it indicates # a bug. raise PolynomialError ( "%s is not an element of K[%s, 1/%s]." % ( p , t , t ) ) d = pd . degree ( t ) one_t_part = pa . slice ( 0 , d + 1 ) r = pd . degree ( ) - pa . degree ( ) t_part = pa - one_t_part try : t_part = t_part . to_field ( ) . exquo ( pd ) except DomainError as e : # issue 4950 raise NotImplementedError ( e ) # Compute the negative degree parts. one_t_part = Poly . from_list ( reversed ( one_t_part . rep . rep ) , * one_t_part . gens , domain = one_t_part . domain ) if 0 < r < oo : one_t_part *= Poly ( t ** r , t ) one_t_part = one_t_part . replace ( t , z ) # z will be 1/t if pd . nth ( d ) : one_t_part *= Poly ( 1 / pd . nth ( d ) , z , expand = False ) ans = t_part . as_poly ( t , z , expand = False ) + one_t_part . as_poly ( t , z , expand = False ) return ans