(p1, p2)
return q
compute the composed sum ``prod(p2(x - beta) for beta root of p1)``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_compose_add
    >>> R, x = ring('x', QQ)
    >>> f = x**2 - 2
    >>> g = x**2 - 3
    >>> rs_compose_add(f, g)
    x**4 - 10*x**2 + 1

    References
    ==========

    A. Bostan, P. Flajolet, B. Salvy and E. Schost
    "Fast Computation with Two Algebraic Numbers",
    (2002) Research Report 4579, Institut
    National de Recherche en Informatique et en Automatique
compute the composed sum ``prod(p2(x - beta) for beta root of p1)``
compute the composed sum prod ( p2 ( x - beta ) for beta root of p1 )
def rs_compose_add(p1, p2):
    """
    compute the composed sum ``prod(p2(x - beta) for beta root of p1)``

    Examples
    ========

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.ring_series import rs_compose_add
    >>> R, x = ring('x', QQ)
    >>> f = x**2 - 2
    >>> g = x**2 - 3
    >>> rs_compose_add(f, g)
    x**4 - 10*x**2 + 1

    References
    ==========

    A. Bostan, P. Flajolet, B. Salvy and E. Schost
    "Fast Computation with Two Algebraic Numbers",
    (2002) Research Report 4579, Institut
    National de Recherche en Informatique et en Automatique
    """
    R = p1.ring
    x = R.gens[0]
    prec = p1.degree() * p2.degree() + 1
    np1 = rs_newton(p1, x, prec)
    np1e = rs_hadamard_exp(np1)
    np2 = rs_newton(p2, x, prec)
    np2e = rs_hadamard_exp(np2)
    np3e = rs_mul(np1e, np2e, x, prec)
    np3 = rs_hadamard_exp(np3e, True)
    np3a = (np3[(0,)] - np3)/x
    q = rs_integrate(np3a, x)
    q = rs_exp(q, x, prec)
    q = _invert_monoms(q)
    q = q.primitive()[1]
    dp = p1.degree() * p2.degree() - q.degree()
    # `dp` is the multiplicity of the zeroes of the resultant;
    # these zeroes are missed in this computation so they are put here.
    # if p1 and p2 are monic irreducible polynomials,
    # there are zeroes in the resultant
    # if and only if p1 = p2 ; in fact in that case p1 and p2 have a
    # root in common, so gcd(p1, p2) != 1; being p1 and p2 irreducible
    # this means p1 = p2
    if dp:
        q = q*x**dp
    return q
def rs_compose_add ( p1 , p2 ) : R = p1 . ring x = R . gens [ 0 ] prec = p1 . degree ( ) * p2 . degree ( ) + 1 np1 = rs_newton ( p1 , x , prec ) np1e = rs_hadamard_exp ( np1 ) np2 = rs_newton ( p2 , x , prec ) np2e = rs_hadamard_exp ( np2 ) np3e = rs_mul ( np1e , np2e , x , prec ) np3 = rs_hadamard_exp ( np3e , True ) np3a = ( np3 [ ( 0 , ) ] - np3 ) / x q = rs_integrate ( np3a , x ) q = rs_exp ( q , x , prec ) q = _invert_monoms ( q ) q = q . primitive ( ) [ 1 ] dp = p1 . degree ( ) * p2 . degree ( ) - q . degree ( ) # `dp` is the multiplicity of the zeroes of the resultant; # these zeroes are missed in this computation so they are put here. # if p1 and p2 are monic irreducible polynomials, # there are zeroes in the resultant # if and only if p1 = p2 ; in fact in that case p1 and p2 have a # root in common, so gcd(p1, p2) != 1; being p1 and p2 irreducible # this means p1 = p2 if dp : q = q * x ** dp return q