Skip to content

Commit fba101d

Browse files
Clean up indentation
1 parent 75e7b96 commit fba101d

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/simplify.jl

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@ const TREE_SHRINK_OPS = [*, +]
1616
function _simplify_constants(O,shorten_tree = true)
1717
# Tree shrinking
1818
if shorten_tree
19-
for cur_op in TREE_SHRINK_OPS
20-
if O.op == cur_op
21-
# Shrink tree
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-
keep_idxs = 1:length(O.args) .∉ (idxs,)
25-
args = Vector{Expression}[O.args[i].args for i in idxs]
26-
push!(args,O.args[keep_idxs])
27-
return Operation(O.op, vcat(args...))
28-
end
29-
# Collapse constants
30-
idxs = findall(is_constant, O.args)
31-
if length(idxs) > 1
32-
other_idxs = 1:length(O.args) .∉ (idxs,)
33-
if cur_op == (*)
34-
new_var = Constant(prod(get, O.args[idxs]))
35-
elseif cur_op == (+)
36-
new_var = Constant(sum(get, O.args[idxs]))
37-
end
38-
new_args = O.args[other_idxs]
39-
push!(new_args,new_var)
40-
if length(new_args) > 1
41-
return Operation(O.op,new_args)
42-
else
43-
return new_args[1]
44-
end
45-
end
19+
for cur_op in TREE_SHRINK_OPS
20+
if O.op == cur_op
21+
# Shrink tree
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+
keep_idxs = 1:length(O.args) .∉ (idxs,)
25+
args = Vector{Expression}[O.args[i].args for i in idxs]
26+
push!(args,O.args[keep_idxs])
27+
return Operation(O.op, vcat(args...))
28+
end
29+
# Collapse constants
30+
idxs = findall(is_constant, O.args)
31+
if length(idxs) > 1
32+
other_idxs = 1:length(O.args) .∉ (idxs,)
33+
if cur_op == (*)
34+
new_var = Constant(prod(get, O.args[idxs]))
35+
elseif cur_op == (+)
36+
new_var = Constant(sum(get, O.args[idxs]))
37+
end
38+
new_args = O.args[other_idxs]
39+
push!(new_args,new_var)
40+
if length(new_args) > 1
41+
return Operation(O.op,new_args)
42+
else
43+
return new_args[1]
44+
end
45+
end
46+
end
4647
end
47-
end
4848
end
4949

5050
if O.op == (*)

0 commit comments

Comments
 (0)