Skip to content

Commit

Permalink
Automatically unwrap and wrap Nums for rule application (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Jun 23, 2024
1 parent 17ae756 commit e4c3281
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rewrite-helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ function filterchildren!(r::Any, y, acc)
end
end

(f::SymbolicUtils.Rule)(x::Num) = wrap(f(unwrap(x)))

module RewriteHelpers
import Symbolics: replacenode, hasnode, filterchildren, unwrap
export replacenode, hasnode, filterchildren, unwrap
Expand Down
6 changes: 6 additions & 0 deletions test/rewrite_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,9 @@ let
@test isequal(filterchildren(is_derivative, ex4), [D(Y), D(my_f(1,Z))])
end

# https://github.com/JuliaSymbolics/Symbolics.jl/issues/1175
let
@variables w z α::Real β::Real;
r3 = @rule ~x * +(~~ys) => sum(map(y-> ~x * y, ~~ys));
@test r3(2 * (w+w+α+β)) isa Num
end

0 comments on commit e4c3281

Please sign in to comment.