code: def debug(rule, file=None):
      """Print out before and after expressions each time rule is used"""
      if file is None:
          file = stdout
  
      def debug_rl(*args, **kwargs):
          expr = args[0]
          result = rule(*args, **kwargs)
          if result != expr:
              file.write("Rule: %s\n" % rule.__name__)
              file.write("In:   %s\nOut:  %s\n\n" % (expr, result))
          return result
  
      return debug_rl
  
file_path: sympy/sympy/strategies/core.py
imports: from __future__ import annotations
  from collections.abc import Callable, Mapping
  from typing import TypeVar
  from sys import stdout
label_desc: Use image node_id 6 for calling a global function with example usage: debug(rule, file) and returns: debug_rl, result