def find_subcircuit(circuit, subcircuit, start=0, end=0):
 if isinstance(circuit, Mul):
  circuit = circuit.args
 if isinstance(subcircuit, Mul):
  subcircuit = subcircuit.args
 if ((len(subcircuit) == 0) or (len(subcircuit) > len(circuit))):
  return (-1)
 if (end < 1):
  end = len(circuit)
 pos = start
 index = 0
 table = kmp_table(subcircuit)
 while ((pos + index) < end):
  if (subcircuit[index] == circuit[(pos + index)]):
   index = (index + 1)
  else:
   pos = ((pos + index) - table[index])
   index = (table[index] if (table[index] > (-1)) else 0)
  if (index == len(subcircuit)):
   return pos
 return (-1)

def find_subcircuit ( circuit , subcircuit , start = 0 , end = 0 ) : if isinstance ( circuit , Mul ) : circuit = circuit . args if isinstance ( subcircuit , Mul ) : subcircuit = subcircuit . args if ( ( len ( subcircuit ) == 0 ) or ( len ( subcircuit ) > len ( circuit ) ) ) : return ( - 1 ) if ( end < 1 ) : end = len ( circuit ) pos = start index = 0 table = kmp_table ( subcircuit ) while ( ( pos + index ) < end ) : if ( subcircuit [ index ] == circuit [ ( pos + index ) ] ) : index = ( index + 1 ) else : pos = ( ( pos + index ) - table [ index ] ) index = ( table [ index ] if ( table [ index ] > ( - 1 ) ) else 0 ) if ( index == len ( subcircuit ) ) : return pos return ( - 1 )
finds the subcircuit in circuit .