#NEWLINE# def _minpoly_op_algebraic_element( op , ex1 , ex2 , x , dom , mp1 = None , mp2 = None ) : #NEWLINE# #INDENT# '\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    >>> from sympy import sqrt, Add, Mul, QQ\n    >>> from sympy.polys.numberfields import _minpoly_op_algebraic_element\n    >>> from sympy.abc import x, y\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.frac_field(y))\n    x**2*y**2 - 2*x*y - y**3 + 1\n\n    References\n    ==========\n\n    [1] http://en.wikipedia.org/wiki/Resultant\n    [2] I.M. Isaacs, Proc. Amer. Math. Soc. 25 (1970), 638\n    "Degrees of sums in a separable field extension".\n    ' #NEWLINE# y = Dummy ( str ( x ) ) #NEWLINE# if ( mp1 is None ) : #NEWLINE# #INDENT# mp1 = _minpoly_compose ( ex1 , x , dom ) #NEWLINE# #UNINDENT# if ( mp2 is None ) : #NEWLINE# #INDENT# mp2 = _minpoly_compose ( ex2 , y , dom ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mp2 = mp2 . subs ( { #NEWLINE# #INDENT# x : y , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( op is Add ) : #NEWLINE# #INDENT# if ( dom == QQ ) : #NEWLINE# #INDENT# ( R , X ) = ring ( 'X' , QQ ) #NEWLINE# p1 = R ( dict_from_expr ( mp1 ) [ 0 ] ) #NEWLINE# p2 = R ( dict_from_expr ( mp2 ) [ 0 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( ( p1 , p2 ) , _ ) = parallel_poly_from_expr ( ( mp1 , ( x - y ) ) , x , y ) #NEWLINE# r = p1 . compose ( p2 ) #NEWLINE# mp1a = r . as_expr ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( op is Mul ) : #NEWLINE# #INDENT# mp1a = _muly ( mp1 , x , y ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise NotImplementedError ( 'option not available' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( op is Mul ) or ( dom != QQ ) ) : #NEWLINE# #INDENT# r = resultant ( mp1a , mp2 , gens = [ y , x ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# r = rs_compose_add ( p1 , p2 ) #NEWLINE# r = expr_from_dict ( r . as_expr_dict ( ) , x ) #NEWLINE# #UNINDENT# deg1 = degree ( mp1 , x ) #NEWLINE# deg2 = degree ( mp2 , y ) #NEWLINE# if ( ( ( op is Mul ) and ( deg1 == 1 ) ) or ( deg2 == 1 ) ) : #NEWLINE# #INDENT# return r #NEWLINE# #UNINDENT# r = Poly ( r , x , domain = dom ) #NEWLINE# ( _ , factors ) = r . factor_list ( ) #NEWLINE# res = _choose_factor ( factors , x , op ( ex1 , ex2 ) , dom ) #NEWLINE# return res . as_expr ( )