@@ -4,35 +4,35 @@ function simplify_constants(O::Operation,shorten_tree = true)
4
4
while _O != O_last
5
5
O_last = _O
6
6
_O = _simplify_constants (_O,shorten_tree)
7
- if typeof (_O) <: Operation
7
+ if is_operation (_O)
8
8
_O = Operation (_O. op,simplify_constants .(_O. args,shorten_tree))
9
9
end
10
10
end
11
11
_O
12
12
end
13
13
14
- const TREE_SHRINK_OPS = [: * ,: + ]
14
+ const TREE_SHRINK_OPS = [* , + ]
15
15
16
16
function _simplify_constants (O,shorten_tree = true )
17
17
# Tree shrinking
18
18
if shorten_tree
19
19
for cur_op in TREE_SHRINK_OPS
20
- if Symbol ( O. op) == cur_op
20
+ if O. op == cur_op
21
21
# Shrink tree
22
- if any (x-> typeof (x)<: Operation && Symbol ( x. op) == cur_op , O. args)
23
- idxs = findall (x-> typeof (x)<: Operation && Symbol ( x. op) == cur_op,O. args)
22
+ if any (x -> is_operation (x) && x. op == cur_op, O. args)
23
+ idxs = findall (x -> is_operation (x) && x. op == cur_op, O. args)
24
24
keep_idxs = 1 : length (O. args) .∉ (idxs,)
25
25
args = Vector{Expression}[O. args[i]. args for i in idxs]
26
26
push! (args,O. args[keep_idxs])
27
- return Operation (O. op,vcat (args... ))
27
+ return Operation (O. op, vcat (args... ))
28
28
end
29
29
# Collapse constants
30
30
idxs = findall (is_constant, O. args)
31
31
if length (idxs) > 1
32
32
other_idxs = 1 : length (O. args) .∉ (idxs,)
33
- if cur_op == : *
33
+ if cur_op == ( * )
34
34
new_var = Constant (prod (get, O. args[idxs]))
35
- elseif cur_op == : +
35
+ elseif cur_op == ( + )
36
36
new_var = Constant (sum (get, O. args[idxs]))
37
37
end
38
38
new_args = O. args[other_idxs]
@@ -47,7 +47,7 @@ function _simplify_constants(O,shorten_tree = true)
47
47
end
48
48
end
49
49
50
- if Symbol ( O. op) == : *
50
+ if O. op == ( * )
51
51
# If any variable is `Constant(0)`, zero the whole thing
52
52
# If any variable is `Constant(1)`, remove that `Constant(1)` unless
53
53
# they are all `Constant(1)`, in which case simplify to a single variable
@@ -66,7 +66,7 @@ function _simplify_constants(O,shorten_tree = true)
66
66
else
67
67
return O
68
68
end
69
- elseif Symbol ( O. op) == : + && any (iszero, O. args)
69
+ elseif O. op == ( + ) && any (iszero, O. args)
70
70
# If there are Constant(0)s in a big `+` expression, get rid of them
71
71
idxs = findall (iszero, O. args)
72
72
_O = Operation (O. op,O. args[1 : length (O. args) .∉ (idxs,)])
@@ -79,7 +79,7 @@ function _simplify_constants(O,shorten_tree = true)
79
79
end
80
80
elseif O. op == identity
81
81
return O. args[1 ]
82
- elseif Symbol ( O. op) == : - && length (O. args) == 1
82
+ elseif O. op == ( - ) && length (O. args) == 1
83
83
return Operation (* ,Expression[- 1 ,O. args[1 ]])
84
84
else
85
85
return O
0 commit comments