Skip to content

Commit ab41033

Browse files
committed
propagate constants after substitute
1 parent c5bc4bd commit ab41033

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/simplify.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@ substitute any subexpression that matches a key in `dict` with
5757
the corresponding value.
5858
"""
5959
function substitute(expr, dict)
60-
RuleSet([@rule ~x::(x->haskey(dict, x)) => dict[~x]])(expr)
60+
RuleSet([@rule ~x::(x->haskey(dict, x)) => dict[~x]])(expr) |> fold
61+
end
62+
63+
fold(x) = x
64+
function fold(t::Term)
65+
tt = map(fold, arguments(t))
66+
if !any(x->x isa Symbolic, tt)
67+
# evaluate it
68+
return operation(t)(tt...)
69+
else
70+
return Term{symtype(t)}(operation(t), tt)
71+
end
6172
end
6273

6374
### Predicates

0 commit comments

Comments
 (0)