code: def replace_leaf(arg, leaves, new_leaves, op, neg):
      """
      Attempt to replace a leaf of a multiplication tree.
  
      We search for a leaf in `leaves` whose argument is `arg`, and if we find
      one, we remove it from `leaves` and add to `new_leaves` a leaf with
      argument `arg` and variable `op(arg)`.
  
      Parameters
      ----------
      arg
          The argument of the leaf we are looking for.
      leaves
          List of leaves to look into. Each leaf should be a pair
          (x, l) with `x` the argument of the Op found in the leaf, and `l` the
          actual leaf as found in a multiplication tree output by `parse_mul_tree`
          (i.e. a pair [boolean, variable]).
      new_leaves
          If a replacement occurred, then the leaf is removed from `leaves`
          and added to the list `new_leaves` (after being modified by `op`).
      op
          A function that, when applied to `arg`, returns the Variable
          we want to replace the original leaf variable with.
      neg : bool
          If True, then the boolean value associated to the leaf should
          be swapped. If False, then this value should remain unchanged.
  
      Returns
      -------
      bool
          True if a replacement occurred, or False otherwise.
  
      """
      for idx, x in enumerate(leaves):
          if x[0] == arg:
              x[1][0] ^= neg
              x[1][1] = op(arg)
              leaves.pop(idx)
              new_leaves.append(x)
              return True
      return False
  
imports: from __future__ import absolute_import, print_function, division
  import warnings
  import numpy
  import theano
  from theano import config, gof, printing, scalar
  from theano.compat import imap
  from theano.printing import pprint
  from theano.tensor import basic
  from theano.tensor import elemwise, opt, NotScalarConstantError
  from theano.tensor.type import values_eq_approx_remove_inf
  from theano.gof.opt import copy_stack_trace
label_desc: Use image node_id 13 for calling a global function with example usage: replace_leaf(arg, leaves, new_leaves, op, neg) and returns: False, True