code: def _sparse_mux(sel, vals):
      
      items = list(vals.values())
      if len(vals) <= 1:
          if len(vals) == 0:
              raise pyrtl.PyrtlError("Needs at least one parameter for val")
          return items[0]
  
      if len(sel) == 1:
          try:
              false_result = vals[0]
              true_result = vals[1]
          except KeyError:
              raise pyrtl.PyrtlError("Failed to retrieve values for smartmux. "
                                     "The length of sel might be wrong")
      else:
          half = 2**(len(sel) - 1)
  
          first_dict = {indx: wire for indx, wire in vals.items() if indx < half}
          second_dict = {indx-half: wire for indx, wire in vals.items() if indx >= half}
          if not len(first_dict):
              return sparse_mux(sel[:-1], second_dict)
          if not len(second_dict):
              return sparse_mux(sel[:-1], first_dict)
  
          false_result = sparse_mux(sel[:-1], first_dict)
          true_result = sparse_mux(sel[:-1], second_dict)
      if _is_equivelent(false_result, true_result):
          return true_result
      return pyrtl.select(sel[-1], falsecase=false_result, truecase=true_result)
docs: Mux that avoids instantiating unnecessary mux_2s when possible.
  
      :param WireVector sel: Select wire, determines what is selected on a given cycle
      :param {int: WireVector} vals: dictionary to store the values that are
      :return: Wirevector that signifies the change
  
      This mux supports not having a full specification. indices that are not
      specified are treated as Don't Cares