@@ -4,6 +4,7 @@ import ..NodeModule: AbstractExpressionNode, constructorof, Node, copy_node, set
44import .. NodeUtilsModule: tree_mapreduce, is_node_constant
55import .. OperatorEnumModule: AbstractOperatorEnum
66import .. ValueInterfaceModule: is_valid
7+ import .. EvaluateModule: any_special_operators
78
89_una_op_kernel (f:: F , l:: T ) where {F,T} = f (l)
910_bin_op_kernel (f:: F , l:: T , r:: T ) where {F,T} = f (l, r)
@@ -19,6 +20,12 @@ combine_operators(tree::AbstractExpressionNode, ::AbstractOperatorEnum) = tree
1920# This is only defined for `Node` as it is not possible for, e.g.,
2021# `GraphNode`.
2122function combine_operators (tree:: Node{T} , operators:: AbstractOperatorEnum ) where {T}
23+ # Skip simplification if special operators are in use
24+ any_special_operators (operators) && return tree
25+ return _combine_operators (tree, operators)
26+ end
27+
28+ function _combine_operators (tree:: Node{T} , operators:: AbstractOperatorEnum ) where {T}
2229 # NOTE: (const (+*-) const) already accounted for. Call simplify_tree! before.
2330 # ((const + var) + const) => (const + var)
2431 # ((const * var) * const) => (const * var)
@@ -28,10 +35,10 @@ function combine_operators(tree::Node{T}, operators::AbstractOperatorEnum) where
2835 if tree. degree == 0
2936 return tree
3037 elseif tree. degree == 1
31- tree. l = combine_operators (tree. l, operators)
38+ tree. l = _combine_operators (tree. l, operators)
3239 elseif tree. degree == 2
33- tree. l = combine_operators (tree. l, operators)
34- tree. r = combine_operators (tree. r, operators)
40+ tree. l = _combine_operators (tree. l, operators)
41+ tree. r = _combine_operators (tree. r, operators)
3542 end
3643
3744 top_level_constant =
123130
124131# Simplify tree
125132function simplify_tree! (tree:: AbstractExpressionNode , operators:: AbstractOperatorEnum )
133+ # Skip simplification if special operators are in use
134+ if any_special_operators (operators)
135+ return tree
136+ end
137+
126138 return tree_mapreduce (
127139 identity, (p, c... ) -> combine_children! (operators, p, c... ), tree, typeof (tree);
128140 )
0 commit comments