code: def _dm_rref_choose_method_QQ(M, *, denominator=False):
      """Choose the fastest method for computing RREF over QQ."""
      # The same sorts of considerations apply here as in the case of ZZ. Here
      # though a new more significant consideration is what sort of denominators
      # we have and what to do with them so we focus on that.
  
      # First compute the density. This is the average number of non-zero entries
      # per row but only counting rows that have at least one non-zero entry
      # since RREF can ignore fully zero rows.
      density, _, ncols = _dm_row_density(M)
  
      # For sparse matrices use Gauss-Jordan elimination over QQ regardless.
      if density < min(5, ncols / 2):
          return "GJ"
  
      # Compare the bit-length of the lcm of the denominators to the bit length
      # of the numerators.
      #
      # The threshold here is empirical: we prefer rref over QQ if clearing
      # denominators would result in a numerator matrix having 5x the bit size of
      # the current numerators.
      numers, denoms = _dm_QQ_numers_denoms(M)
      numer_bits = max([n.bit_length() for n in numers], default=1)
  
      denom_lcm = ZZ.one
      for d in denoms:
          denom_lcm = ZZ.lcm(denom_lcm, d)
          if denom_lcm.bit_length() > 5 * numer_bits:
              return "GJ"
  
      # If we get here then the matrix is dense and the lcm of the denominators
      # is not too large compared to the numerators. For particularly small
      # denominators it is fastest just to clear them and use fraction-free
      # Gauss-Jordan over ZZ. With very small denominators this is a little
      # faster than using rref_den over QQ but there is an intermediate regime
      # where rref_den over QQ is significantly faster. The small denominator
      # case is probably very common because small fractions like 1/2 or 1/3 are
      # often seen in user inputs.
  
      if denom_lcm.bit_length() < 50:
          return "CD"
      else:
          return "FF"
  
file_path: sympy/sympy/polys/matrices/rref.py
imports: from sympy.polys.domains import ZZ
  from sympy.polys.matrices.sdm import SDM, sdm_irref, sdm_rref_den
  from sympy.polys.matrices.ddm import DDM
  from sympy.polys.matrices.dense import ddm_irref, ddm_irref_den
label_desc: Use image node_id 11 for calling a global function with example usage: _dm_rref_choose_method_QQ(M) and returns: str, str, str, str