def _minpoly_op_algebraic_element(op, ex1, ex2, x, dom, mp1=None, mp2=None):
    '\n    Return the minimal polynomial for ``op(ex1, ex2)``.\n\n    Parameters\n    ==========\n\n    op : operation ``Add`` or ``Mul``\n    ex1, ex2 : expressions for the algebraic elements\n    x : indeterminate of the polynomials\n    dom: ground domain\n    mp1, mp2 : minimal polynomials for ``ex1`` and ``ex2`` or None\n\n    Examples\n    ========\n\n    >>> p1 = sqrt(sqrt(2) + 1)\n    >>> p2 = sqrt(sqrt(2) - 1)\n    >>> _minpoly_op_algebraic_element(Mul, p1, p2, x, QQ)\n    x - 1\n    >>> q1 = sqrt(y)\n    >>> q2 = 1 / y\n    >>> _minpoly_op_algebraic_element(Add, q1, q2, x, QQ.inject(y).field)\n    x**2*y**2 - 2*x*y - y**3 + 1\n\n    References\n    ==========\n\n    * https://en.wikipedia.org/wiki/Resultant\n    * I.M. Isaacs, Proc. Amer. Math. Soc. 25 (1970), 638\n      "Degrees of sums in a separable field extension".\n\n    '
    y = Dummy(str(x))
    if (mp1 is None):
        mp1 = _minpoly_compose(ex1, x, dom)
    if (mp2 is None):
        mp2 = _minpoly_compose(ex2, y, dom)
    else:
        mp2 = mp2.subs({x: y})
    if (op is Add):
        ((p1, p2), _) = parallel_poly_from_expr((mp1, (x - y)), x, y)
        r = p1.compose(p2)
        mp1a = r.as_expr()
    elif (op is Mul):
        mp1a = _muly(mp1, x, y)
    else:
        raise NotImplementedError('option not available')
    r = resultant(mp1a, mp2, gens=[y, x])
    deg1 = degree(mp1, x)
    deg2 = degree(mp2, y)
    if (((op is Mul) and (deg1 == 1)) or (deg2 == 1)):
        return r
    r = r.as_poly(x, domain=dom)
    (_, factors) = r.factor_list()
    res = _choose_factor(factors, x, op(ex1, ex2), dom)
    return res.as_expr()
Return the minimal polynomial for ``op(ex1, ex2)``.

Parameters
==========

op : operation ``Add`` or ``Mul``
ex1, ex2 : expressions for the algebraic elements
x : indeterminate of the polynomials
dom: ground domain
mp1, mp2 : minimal polynomials for ``ex1`` and ``ex2`` or None

Examples
========

>>> p1 = sqrt(sqrt(2) + 1)
>>> p2 = sqrt(sqrt(2) - 1)
>>> _minpoly_op_algebraic_element(Mul, p1, p2, x, QQ)
x - 1
>>> q1 = sqrt(y)
>>> q2 = 1 / y
>>> _minpoly_op_algebraic_element(Add, q1, q2, x, QQ.inject(y).field)
x**2*y**2 - 2*x*y - y**3 + 1

References
==========

* https://en.wikipedia.org/wiki/Resultant
* I.M. Isaacs, Proc. Amer. Math. Soc. 25 (1970), 638
  "Degrees of sums in a separable field extension".
def _minpoly_op_algebraic_element(op, ex1, ex2, x, dom, mp1=None, mp2=None):
    '\n    Return the minimal polynomial for ``op(ex1, ex2)``.\n\n    Parameters\n    ==========\n\n    op : operation ``Add`` or ``Mul``\n    ex1, ex2 : expressions for the algebraic elements\n    x : indeterminate of the polynomials\n    dom: ground domain\n    mp1, mp2 : minimal polynomials for ``ex1`` and ``ex2`` or None\n\n    Examples\n    ========\n\n    >>> p1 = sqrt(sqrt(2) + 1)\n    >>> p2 = sqrt(sqrt(2) - 1)\n    >>> _minpoly_op_algebraic_element(Mul, p1, p2, x, QQ)\n    x - 1\n    >>> q1 = sqrt(y)\n    >>> q2 = 1 / y\n    >>> _minpoly_op_algebraic_element(Add, q1, q2, x, QQ.inject(y).field)\n    x**2*y**2 - 2*x*y - y**3 + 1\n\n    References\n    ==========\n\n    * https://en.wikipedia.org/wiki/Resultant\n    * I.M. Isaacs, Proc. Amer. Math. Soc. 25 (1970), 638\n      "Degrees of sums in a separable field extension".\n\n    '
    y = Dummy(str(x))
    if (mp1 is None):
        mp1 = _minpoly_compose(ex1, x, dom)
    if (mp2 is None):
        mp2 = _minpoly_compose(ex2, y, dom)
    else:
        mp2 = mp2.subs({x: y})
    if (op is Add):
        ((p1, p2), _) = parallel_poly_from_expr((mp1, (x - y)), x, y)
        r = p1.compose(p2)
        mp1a = r.as_expr()
    elif (op is Mul):
        mp1a = _muly(mp1, x, y)
    else:
        raise NotImplementedError('option not available')
    r = resultant(mp1a, mp2, gens=[y, x])
    deg1 = degree(mp1, x)
    deg2 = degree(mp2, y)
    if (((op is Mul) and (deg1 == 1)) or (deg2 == 1)):
        return r
    r = r.as_poly(x, domain=dom)
    (_, factors) = r.factor_list()
    res = _choose_factor(factors, x, op(ex1, ex2), dom)
    return res.as_expr()