code: def to_number_field(extension, theta=None, *, gen=None, alias=None):
      r"""
      Express one algebraic number in the field generated by another.
  
      Explanation
      ===========
  
      Given two algebraic numbers $\eta, \theta$, this function either expresses
      $\eta$ as an element of $\mathbb{Q}(\theta)$, or else raises an exception
      if $\eta \not\in \mathbb{Q}(\theta)$.
  
      This function is essentially just a convenience, utilizing
      :py:func:`~.field_isomorphism` (our solution of the Subfield Problem) to
      solve this, the Field Membership Problem.
  
      As an additional convenience, this function allows you to pass a list of
      algebraic numbers $\alpha_1, \alpha_2, \ldots, \alpha_n$ instead of $\eta$.
      It then computes $\eta$ for you, as a solution of the Primitive Element
      Problem, using :py:func:`~.primitive_element` on the list of $\alpha_i$.
  
      Examples
      ========
  
      >>> from sympy import sqrt, to_number_field
      >>> eta = sqrt(2)
      >>> theta = sqrt(2) + sqrt(3)
      >>> a = to_number_field(eta, theta)
      >>> print(type(a))
      <class 'sympy.core.numbers.AlgebraicNumber'>
      >>> a.root
      sqrt(2) + sqrt(3)
      >>> print(a)
      sqrt(2)
      >>> a.coeffs()
      [1/2, 0, -9/2, 0]
  
      We get an :py:class:`~.AlgebraicNumber`, whose ``.root`` is $\theta$, whose
      value is $\eta$, and whose ``.coeffs()`` show how to write $\eta$ as a
      $\mathbb{Q}$-linear combination in falling powers of $\theta$.
  
      Parameters
      ==========
  
      extension : :py:class:`~.Expr` or list of :py:class:`~.Expr`
          Either the algebraic number that is to be expressed in the other field,
          or else a list of algebraic numbers, a primitive element for which is
          to be expressed in the other field.
      theta : :py:class:`~.Expr`, None, optional (default=None)
          If an :py:class:`~.Expr` representing an algebraic number, behavior is
          as described under **Explanation**. If ``None``, then this function
          reduces to a shorthand for calling :py:func:`~.primitive_element` on
          ``extension`` and turning the computed primitive element into an
          :py:class:`~.AlgebraicNumber`.
      gen : :py:class:`~.Symbol`, None, optional (default=None)
          If provided, this will be used as the generator symbol for the minimal
          polynomial in the returned :py:class:`~.AlgebraicNumber`.
      alias : str, :py:class:`~.Symbol`, None, optional (default=None)
          If provided, this will be used as the alias symbol for the returned
          :py:class:`~.AlgebraicNumber`.
  
      Returns
      =======
  
      AlgebraicNumber
          Belonging to $\mathbb{Q}(\theta)$ and equaling $\eta$.
  
      Raises
      ======
  
      IsomorphismFailed
          If $\eta \not\in \mathbb{Q}(\theta)$.
  
      See Also
      ========
  
      field_isomorphism
      primitive_element
  
      """
      if hasattr(extension, "__iter__"):
          extension = list(extension)
      else:
          extension = [extension]
  
      if len(extension) == 1 and isinstance(extension[0], tuple):
          return AlgebraicNumber(extension[0], alias=alias)
  
      minpoly, coeffs = primitive_element(extension, gen, polys=True)
      root = sum([coeff * ext for coeff, ext in zip(coeffs, extension)])
  
      if theta is None:
          return AlgebraicNumber((minpoly, root), alias=alias)
      else:
          theta = sympify(theta)
  
          if not theta.is_AlgebraicNumber:
              theta = AlgebraicNumber(theta, gen=gen, alias=alias)
  
          coeffs = field_isomorphism(root, theta)
  
          if coeffs is not None:
              return AlgebraicNumber(theta, coeffs, alias=alias)
          else:
              raise IsomorphismFailed(
                  "%s is not in a subfield of %s" % (root, theta.root)
              )
  
imports: from sympy.core.add import Add
  from sympy.core.numbers import AlgebraicNumber
  from sympy.core.singleton import S
  from sympy.core.symbol import Dummy
  from sympy.core.sympify import sympify, _sympify
  from sympy.ntheory import sieve
  from sympy.polys.densetools import dup_eval
  from sympy.polys.domains import QQ
  from sympy.polys.numberfields.minpoly import _choose_factor, minimal_polynomial
  from sympy.polys.polyerrors import IsomorphismFailed
  from sympy.polys.polytools import Poly, PurePoly, factor_list
  from sympy.utilities import public
  from mpmath import MPContext
label_desc: Use image node_id 8 for calling a global function with example usage: to_number_field(extension, theta) and returns: AlgebraicNumber, AlgebraicNumber, AlgebraicNumber