Skip to content

Commit 0971c63

Browse files
committed
Overload missing interface similarterm
Fix #699
1 parent f25c9be commit 0971c63

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/context_dsl.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ isparameter(::Sym{<:Parameter}) = true
66
isparameter(::Sym{<:FnType{<:Any, <:Parameter}}) = true
77

88
SymbolicUtils.symtype(s::Symbolic{Parameter{T}}) where T = T
9+
SymbolicUtils.similarterm(t::Term{T}, f, args) where {T<:Parameter} = Term{T}(f, args)
910

1011
Base.convert(::Type{Num}, x::Symbolic{Parameter{T}}) where {T<:Number} = Num(x)
1112

test/simplify.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ d3 = Differential(x)(d2)
3232

3333
@test ModelingToolkit.substitute(2x + y == 1, Dict(x => 0.0, y => 0.0)) === false
3434
@test ModelingToolkit.substitute(2x + y == 1, Dict(x => 0.0, y => 1.0)) === true
35+
36+
# 699
37+
using SymbolicUtils: to_symbolic, substitute
38+
@parameters t a(t) b(t)
39+
40+
# back and forth substitution does not work for parameters with dependencies
41+
term = to_symbolic(a)
42+
term2 = substitute(term, a=>b)
43+
@test term2 isa Term{ModelingToolkit.Parameter{Real}}
44+
@test isequal(term2, b)
45+
term3 = substitute(term2, b=>a)
46+
@test term3 isa Term{ModelingToolkit.Parameter{Real}}
47+
@test isequal(term3, a)

0 commit comments

Comments
 (0)