def is_neg(var):
 apply = var.owner
 if (not apply):
  return None
 if (apply.op == tensor.neg):
  return apply.inputs[0]
 if ((apply.op == tensor.mul) and (len(apply.inputs) >= 2)):
  for (idx, mul_input) in enumerate(apply.inputs):
   try:
    constant = opt.get_scalar_constant_value(mul_input)
    is_minus_1 = numpy.allclose(constant, (-1))
   except NotScalarConstantError:
    is_minus_1 = False
   if is_minus_1:
    if (len(apply.inputs) == 2):
     return apply.inputs[(1 - idx)]
    else:
     return tensor.mul(*(apply.inputs[0:idx] + apply.inputs[(idx + 1):]))
 return None

def is_neg ( var ) : apply = var . owner if ( not apply ) : return None if ( apply . op == tensor . neg ) : return apply . inputs [ 0 ] if ( ( apply . op == tensor . mul ) and ( len ( apply . inputs ) >= 2 ) ) : for ( idx , mul_input ) in enumerate ( apply . inputs ) : try : constant = opt . get_scalar_constant_value ( mul_input ) is_minus_1 = numpy . allclose ( constant , ( - 1 ) ) except NotScalarConstantError : is_minus_1 = False if is_minus_1 : if ( len ( apply . inputs ) == 2 ) : return apply . inputs [ ( 1 - idx ) ] else : return tensor . mul ( * ( apply . inputs [ 0 : idx ] + apply . inputs [ ( idx + 1 ) : ] ) ) return None
match a variable with the -x pattern .