@@ -16,7 +16,7 @@ function _simplify_constants(O)
16
16
# If any variable is `Constant(0)`, zero the whole thing
17
17
# If any variable is `Constant(1)`, remove that `Constant(1)` unless
18
18
# they are all `Constant(1)`, in which case simplify to a single variable
19
- if any (x-> typeof (x)<: Variable && isequal (x,Constant (0 )),O. args)
19
+ if any (x-> typeof (x)<: Variable && ( isequal (x,Constant (0 )) || isequal (x, Constant ( - 0 ) )),O. args)
20
20
return Constant (0 )
21
21
elseif any (x-> typeof (x)<: Variable && isequal (x,Constant (1 )),O. args)
22
22
idxs = find (x-> typeof (x)<: Variable && isequal (x,Constant (1 )),O. args)
@@ -31,9 +31,9 @@ function _simplify_constants(O)
31
31
else
32
32
return O
33
33
end
34
- elseif Symbol (O. op) == :+ && any (x-> typeof (x)<: Variable && isequal (x,Constant (0 )),O. args)
34
+ elseif Symbol (O. op) == :+ && any (x-> typeof (x)<: Variable && ( isequal (x,Constant (0 )) || isequal (x, Constant ( - 0 ) )),O. args)
35
35
# If there are Constant(0)s in a big `+` expression, get rid of them
36
- idxs = find (x-> typeof (x)<: Variable && isequal (x,Constant (0 )),O. args)
36
+ idxs = find (x-> typeof (x)<: Variable && ( isequal (x,Constant (0 )) || isequal (x, Constant ( - 0 ) )),O. args)
37
37
_O = Operation (O. op,O. args[1 : length (O. args) .∉ (idxs,)])
38
38
if isempty (_O. args)
39
39
return Constant (0 )
@@ -42,6 +42,8 @@ function _simplify_constants(O)
42
42
else
43
43
return O
44
44
end
45
+ elseif O. op == identity
46
+ return O. args[1 ]
45
47
else
46
48
return O
47
49
end
0 commit comments