code: def local_exp_over_1_plus_exp(node):
      """
      exp(x)/(1+exp(x)) -> sigm(x)
      c/(1+exp(x)) -> c*sigm(-x)
  
      """
      # this optimization should be done for numerical stability
      # so we don't care to check client counts
      if node.op == tensor.true_div:
          # find all the exp() terms in the numerator
          num, denom = node.inputs
          num_exp_x, num_rest, num_neg = partition_num_or_denom(
              num, is_exp
          )
          denom_1pexp, denom_rest, denom_neg = partition_num_or_denom(
              denom, is_1pexp
          )
  
          sigmoids = []
          for t in denom_1pexp:
              if t in num_exp_x:
                  # case: exp(x) /(1+exp(x))
                  sigmoids.append(sigmoid(t))
                  del num_exp_x[num_exp_x.index(t)]
              else:
                  # case: 1/(1+exp(x))
                  sigmoids.append(sigmoid(-t))
              copy_stack_trace(node.outputs[0], sigmoids[-1])
  
          if not sigmoids:  # we didn't find any.  abort
              return
          # put the new numerator together
          new_num = (
              sigmoids + [tensor.exp(t) for t in num_exp_x] + num_rest
          )
          if len(new_num) == 1:
              new_num = new_num[0]
          else:
              new_num = tensor.mul(*new_num)
  
          if num_neg ^ denom_neg:
              new_num = -new_num
  
          copy_stack_trace(num, new_num)
  
          if len(denom_rest) == 0:
              return [new_num]
          elif len(denom_rest) == 1:
              out = new_num / denom_rest[0]
          else:
              out = new_num / tensor.mul(*denom_rest)
  
          copy_stack_trace(node.outputs[0], out)
          return [out]
  
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 11 for calling a global function with example usage: local_exp_over_1_plus_exp(node) and returns: list, list