code: def supplement_a_subspace(M):
      r"""
      Extend a basis for a subspace to a basis for the whole space.
  
      Explanation
      ===========
  
      Given an $n \times r$ matrix *M* of rank $r$ (so $r \leq n$), this function
      computes an invertible $n \times n$ matrix $B$ such that the first $r$
      columns of $B$ equal *M*.
  
      This operation can be interpreted as a way of extending a basis for a
      subspace, to give a basis for the whole space.
  
      To be precise, suppose you have an $n$-dimensional vector space $V$, with
      basis $\{v_1, v_2, \ldots, v_n\}$, and an $r$-dimensional subspace $W$ of
      $V$, spanned by a basis $\{w_1, w_2, \ldots, w_r\}$, where the $w_j$ are
      given as linear combinations of the $v_i$. If the columns of *M* represent
      the $w_j$ as such linear combinations, then the columns of the matrix $B$
      computed by this function give a new basis $\{u_1, u_2, \ldots, u_n\}$ for
      $V$, again relative to the $\{v_i\}$ basis, and such that $u_j = w_j$
      for $1 \leq j \leq r$.
  
      Examples
      ========
  
      Note: The function works in terms of columns, so in these examples we
      print matrix transposes in order to make the columns easier to inspect.
  
      >>> from sympy.polys.matrices import DM
      >>> from sympy import QQ, FF
      >>> from sympy.polys.numberfields.utilities import supplement_a_subspace
      >>> M = DM([[1, 7, 0], [2, 3, 4]], QQ).transpose()
      >>> print(supplement_a_subspace(M).to_Matrix().transpose())
      Matrix([[1, 7, 0], [2, 3, 4], [1, 0, 0]])
  
      >>> M2 = M.convert_to(FF(7))
      >>> print(M2.to_Matrix().transpose())
      Matrix([[1, 0, 0], [2, 3, -3]])
      >>> print(supplement_a_subspace(M2).to_Matrix().transpose())
      Matrix([[1, 0, 0], [2, 3, -3], [0, 1, 0]])
  
      Parameters
      ==========
  
      M : :py:class:`~.DomainMatrix`
          The columns give the basis for the subspace.
  
      Returns
      =======
  
      :py:class:`~.DomainMatrix`
          This matrix is invertible and its first $r$ columns equal *M*.
  
      Raises
      ======
  
      DMRankError
          If *M* was not of maximal rank.
  
      References
      ==========
  
      .. [1] Cohen, H. *A Course in Computational Algebraic Number Theory*
         (See Sec. 2.3.2.)
  
      """
      n, r = M.shape
      # Let In be the n x n identity matrix.
      # Form the augmented matrix [M | In] and compute RREF.
      Maug = M.hstack(M.eye(n, M.domain))
      R, pivots = Maug.rref()
      if pivots[:r] != tuple(range(r)):
          raise DMRankError("M was not of maximal rank")
      # Let J be the n x r matrix equal to the first r columns of In.
      # Since M is of rank r, RREF reduces [M | In] to [J | A], where A is the product of
      # elementary matrices Ei corresp. to the row ops performed by RREF. Since the Ei are
      # invertible, so is A. Let B = A^(-1).
      A = R[:, r:]
      B = A.inv()
      # Then B is the desired matrix. It is invertible, since B^(-1) == A.
      # And A * [M | In] == [J | A]
      #  => A * M == J
      #  => M == B * J == the first r columns of B.
      return B
  
imports: from sympy.core.sympify import sympify
  from sympy.ntheory.factor_ import factorint
  from sympy.polys.domains.rationalfield import QQ
  from sympy.polys.domains.integerring import ZZ
  from sympy.polys.matrices.exceptions import DMRankError
  from sympy.polys.numberfields.minpoly import minpoly
  from sympy.printing.lambdarepr import IntervalPrinter
  from sympy.utilities.decorator import public
  from sympy.utilities.lambdify import lambdify
  from mpmath import mp
label_desc: Use image node_id 6 for calling a global function with example usage: supplement_a_subspace(M) and returns: B