Skip to content

Commit 01c017f

Browse files
Merge pull request #734 from AayushSabharwal/as/fix-substitute
fix: fix substituting identity of */+ ignores metadata
2 parents 6d1c325 + 06cfb70 commit 01c017f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/types.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,13 +847,13 @@ function basicsymbolic(f, args, stype, metadata)
847847
elseif all(x->symtype(x) <: Number, args)
848848
if f === (+)
849849
res = +(args...)
850-
if isadd(res) || isterm(res)
850+
if isadd(res) || (isterm(res) && operation(res) == (+))
851851
@set! res.metadata = metadata
852852
end
853853
res
854854
elseif f == (*)
855855
res = *(args...)
856-
if ismul(res) || isterm(res)
856+
if ismul(res) || (isterm(res) && operation(res) == (*))
857857
@set! res.metadata = metadata
858858
end
859859
res

test/basics.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,14 @@ end
418418
hash(var)
419419
@test hash(var) != hash(setproperties(var; exp = c))
420420
end
421+
422+
@testset "`substitute` handles identity of */+" begin
423+
@syms t x(t) y
424+
x = setmetadata(x(t), Int, 3)
425+
ex = x * y
426+
res = substitute(ex, Dict(y => 1))
427+
@test SymbolicUtils.isequal_with_metadata(res, x)
428+
ex = x + y
429+
res = substitute(ex, Dict(y => 0))
430+
@test SymbolicUtils.isequal_with_metadata(res, x)
431+
end

0 commit comments

Comments
 (0)