def equivalent(term1, term2, subs=None):
 head_type = type(term1)
 if (type(term2) != head_type):
  return False
 elif (head_type not in (tuple, list)):
  try:
   return ((term1 is term2) or (term1 == term2))
  except:
   return False
 pot1 = preorder_traversal(term1)
 pot2 = preorder_traversal(term2)
 subs = ({} if (subs is None) else subs)
 for (t1, t2) in zip_longest(pot1, pot2, fillvalue=END):
  if ((t1 is END) or (t2 is END)):
   return False
  elif (ishashable(t2) and (t2 in subs)):
   val = subs[t2]
  else:
   val = t2
  try:
   if ((t1 is not t2) and (t1 != val)):
    return False
  except:
   return False
 return True

def equivalent ( term1 , term2 , subs = None ) : head_type = type ( term1 ) if ( type ( term2 ) != head_type ) : return False elif ( head_type not in ( tuple , list ) ) : try : return ( ( term1 is term2 ) or ( term1 == term2 ) ) except : return False pot1 = preorder_traversal ( term1 ) pot2 = preorder_traversal ( term2 ) subs = ( { } if ( subs is None ) else subs ) for ( t1 , t2 ) in zip_longest ( pot1 , pot2 , fillvalue = END ) : if ( ( t1 is END ) or ( t2 is END ) ) : return False elif ( ishashable ( t2 ) and ( t2 in subs ) ) : val = subs [ t2 ] else : val = t2 try : if ( ( t1 is not t2 ) and ( t1 != val ) ) : return False except : return False return True
determine if two terms are equivalent .