Skip to content

Commit 701fd9b

Browse files
committed
Bring back to_symbolic to allow MTK to work without change
This reverts commit a725bbb.
1 parent d726cae commit 701fd9b

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/api.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function simplify(x;
2626
Fixpoint(rewriter)
2727
end
2828

29-
PassThrough(f)(x)
29+
PassThrough(f)(to_symbolic(x))
3030
end
3131

3232
Base.@deprecate simplify(x, ctx; kwargs...) simplify(x; rewriter=ctx, kwargs...)
@@ -40,8 +40,8 @@ the corresponding value.
4040
function substitute(expr, dict; fold=true)
4141
rs = Prewalk(PassThrough(@rule ~x::(x->haskey(dict, x)) => dict[~x]))
4242
if fold
43-
rs(expr) |> SymbolicUtils.fold
43+
rs(to_symbolic(expr)) |> SymbolicUtils.fold
4444
else
45-
rs(expr)
45+
rs(to_symbolic(expr))
4646
end
4747
end

src/types.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,21 @@ Base.isequal(x::Symbolic, y::Symbolic) = false
6767
Convert `x` to a `Symbolic` type, using the `istree`, `operation`, `arguments`,
6868
and optionally `symtype` if available.
6969
"""
70-
function to_symbolic end
71-
Base.@deprecate to_symbolic(x) x
70+
to_symbolic(x::Symbolic) = x
71+
72+
function to_symbolic(x)
73+
if !istree(x)
74+
return x
75+
end
76+
77+
op = to_symbolic(operation(x))
78+
79+
if symtype(x) === Any
80+
Term(op, map(to_symbolic, arguments(x)))
81+
else
82+
Term{symtype(x)}(op, map(to_symbolic, arguments(x)))
83+
end
84+
end
7285

7386
Base.one( s::Symbolic) = one( symtype(s))
7487

test/interface.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ end
1515

1616
ex = 1 + (:x - 2)
1717

18-
@test simplify(ex) == ex # Not simplified because symtype Any
18+
SymbolicUtils.to_symbolic(ex::Expr) = ex
1919

20-
SymbolicUtils.symtype(::Expr) = Real
20+
@test simplify(ex) == ex
2121

22+
SymbolicUtils.symtype(::Expr) = Real
2223
@test simplify(ex) == -1 + :x
2324
@test simplify(:a * (:b + -1 * :c) + -1 * (:b * :a + -1 * :c * :a), polynorm=true) == 0

0 commit comments

Comments
 (0)