code: def simplify_mul(tree):
      """
      Simplify a multiplication tree.
  
      Parameters
      ----------
      tree
          A multiplication tree (as output by `parse_mul_tree`).
  
      Returns
      -------
      object
          A multiplication tree computing the same output as `tree` but without
          useless multiplications by 1 nor -1 (identified by leaves of the form
          [False, None] or [True, None] respectively). Useless multiplications
          (with less than two inputs) are also removed from the tree.
  
      """
      neg, inputs = tree
      if isinstance(inputs, list):
          # Recurse through inputs.
          s_inputs = []
          for s_i in imap(simplify_mul, inputs):
              if s_i[1] is None:
                  # Multiplication by +/-1.
                  neg ^= s_i[0]
              else:
                  s_inputs.append(s_i)
          if not s_inputs:
              # The multiplication is empty.
              rval = [neg, None]
          elif len(s_inputs) == 1:
              # The multiplication has a single input.
              s_inputs[0][0] ^= neg
              rval = s_inputs[0]
          else:
              rval = [neg, s_inputs]
      else:
          rval = tree
      # print 'simplify_mul: %s -> %s' % (tree, rval)
      return rval
  
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 14 for calling a global function with example usage: simplify_mul(tree) and returns: rval