code: def _get_binary_replacement(first, second, cls):
      
      expr = ProtoExpr([first, second], {})
      if LOG:
          logger = logging.getLogger('QNET.create')
      for key, rule in cls._binary_rules.items():
          pat, replacement = rule
          match_dict = match_pattern(pat, expr)
          if match_dict:
              try:
                  replaced = replacement(**match_dict)
                  if LOG:
                      logger.debug(
                          "%sRule %s.%s: (%s, %s) -> %s", ("  " * (LEVEL)),
                          cls.__name__, key, expr.args, expr.kwargs, replaced)
                  return replaced
              except CannotSimplify:
                  if LOG_NO_MATCH:
                      logger.debug(
                          "%sRule %s.%s: no match: CannotSimplify",
                          ("  " * (LEVEL)), cls.__name__, key)
                  continue
          else:
              if LOG_NO_MATCH:
                  logger.debug(
                      "%sRule %s.%s: no match: %s", ("  " * (LEVEL)),
                      cls.__name__, key, match_dict.reason)
      return None
docs: Helper function for match_replace_binary