-
Notifications
You must be signed in to change notification settings - Fork 178
#1123 Fix mod derivative handling in Symbolics.jl (#1123) #1490
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
Conversation
test/runtests.jl
Outdated
| activate_sympy_env() | ||
| @safetestset "SymPy Test" begin include("sympy.jl") end | ||
| end | ||
| include("test_expand_derivatives.jl") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be in a test group, should just be in the standard core tests.
src/diff.jl
Outdated
|
|
||
| function expand_derivatives(n::Num, simplify=false; kwargs...) | ||
| wrap(expand_derivatives(value(n), simplify; kwargs...)) | ||
| n = walk(x -> x isa Float64 ? Rational(x) : x, value(n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rationalizing floating point numbers like 0.3 will lead to some unexpected results. Instead, we should probably just rationalize integers?
src/diff.jl
Outdated
|
|
||
| function expand_derivatives(n::Num, simplify=false; kwargs...) | ||
| wrap(expand_derivatives(value(n), simplify; kwargs...)) | ||
| n = walk(x -> x isa Float64 ? Rational(x) : x, value(n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| n = walk(x -> x isa Float64 ? Rational(x) : x, value(n)) | |
| n = walk(x -> x isa Int? Rational(x) : x, value(n)) |
Is this sufficient to fix the issue?
|
@ChrisRackauckas I’ve made the suggested changes. Could you please review my code? Additionally, I’d appreciate more suggestions to help solve this issue |
This PR addresses Issue #1123 by modifying the diff.jl file to add a custom derivative rule for the mod function in Symbolics.jl. The previous implementation didn’t handle mod well during symbolic differentiation, so we added this rule to improve its handling. We also updated runtests.jl to include tests for this change and created a new file test_expand_derivatives.jl to check its behavior. We’re not entirely sure if this is the best solution and would love suggestions on other possible methods to handle this more effectively.