@@ -15,7 +15,7 @@ function _simplify_constants(O, shorten_tree = true)
15
15
# Tree shrinking
16
16
if shorten_tree && O. op ∈ AC_OPERATORS
17
17
# Flatten tree
18
- idxs = findall (x -> is_operation (x) && x. op == O. op, O. args)
18
+ idxs = findall (x -> is_operation (x) && x. op === O. op, O. args)
19
19
if ! isempty (idxs)
20
20
keep_idxs = eachindex (O. args) .∉ Ref (idxs)
21
21
args = Vector{Expression}[O. args[i]. args for i in idxs]
@@ -26,12 +26,12 @@ function _simplify_constants(O, shorten_tree = true)
26
26
# Collapse constants
27
27
idxs = findall (is_constant, O. args)
28
28
if length (idxs) > 1
29
- other_idxs = eachindex (O. args) .∉ (idxs,)
30
- new_var = Constant (mapreduce (get, O. op, O. args[idxs]))
31
- new_args = O. args[other_idxs]
32
- push! (new_args,new_var)
29
+ other_idxs = eachindex (O. args) .∉ Ref (idxs)
30
+ new_const = Constant (mapreduce (get, O. op, O. args[idxs]))
31
+ args = push! (O. args[other_idxs], new_const)
33
32
34
- return length (new_args) > 1 ? Operation (O. op, new_args) : first (new_args)
33
+ length (args) == 1 && return first (args)
34
+ return Operation (O. op, args)
35
35
end
36
36
end
37
37
@@ -67,7 +67,7 @@ function _simplify_constants(O, shorten_tree = true)
67
67
68
68
return O
69
69
end
70
- simplify_constants (x:: Variable ,y= false ) = x
71
- _simplify_constants (x:: Variable ,y= false ) = x
70
+ simplify_constants (x:: Variable , y= false ) = x
71
+ _simplify_constants (x:: Variable , y= false ) = x
72
72
73
73
export simplify_constants
0 commit comments