def is_reducible(circuit, nqubits, begin, end):
 current_circuit = ()
 for ndx in reversed(range(begin, end)):
  next_gate = circuit[ndx]
  current_circuit = ((next_gate,) + current_circuit)
  if is_scalar_matrix(current_circuit, nqubits, False):
   return True
 return False

def is_reducible ( circuit , nqubits , begin , end ) : current_circuit = ( ) for ndx in reversed ( range ( begin , end ) ) : next_gate = circuit [ ndx ] current_circuit = ( ( next_gate , ) + current_circuit ) if is_scalar_matrix ( current_circuit , nqubits , False ) : return True return False
determines if a circuit is reducible by checking if its subcircuits are scalar values .