def generate_equivalent_ids(gate_seq, return_as_muls=False):
 if isinstance(gate_seq, Number):
  return {Integer(1)}
 elif isinstance(gate_seq, Mul):
  gate_seq = gate_seq.args
 eq_ids = set()
 gate_rules = generate_gate_rules(gate_seq)
 for rule in gate_rules:
  (l, r) = rule
  if (l == ()):
   eq_ids.add(r)
  elif (r == ()):
   eq_ids.add(l)
 if return_as_muls:
  convert_to_mul = (lambda id_seq: Mul(*id_seq))
  eq_ids = set(map(convert_to_mul, eq_ids))
 return eq_ids

def generate_equivalent_ids ( gate_seq , return_as_muls = False ) : if isinstance ( gate_seq , Number ) : return { Integer ( 1 ) } elif isinstance ( gate_seq , Mul ) : gate_seq = gate_seq . args eq_ids = set ( ) gate_rules = generate_gate_rules ( gate_seq ) for rule in gate_rules : ( l , r ) = rule if ( l == ( ) ) : eq_ids . add ( r ) elif ( r == ( ) ) : eq_ids . add ( l ) if return_as_muls : convert_to_mul = ( lambda id_seq : Mul ( * id_seq ) ) eq_ids = set ( map ( convert_to_mul , eq_ids ) ) return eq_ids
returns a set of equivalent gate identities .