Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically unwrap and wrap Nums for rule application #1176

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading