Skip to content

Conversation

@savaliyabhargav
Copy link

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.

test/runtests.jl Outdated
activate_sympy_env()
@safetestset "SymPy Test" begin include("sympy.jl") end
end
include("test_expand_derivatives.jl")
Copy link
Member

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))
Copy link
Member

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

@savaliyabhargav
Copy link
Author

@ChrisRackauckas I’ve made the suggested changes. Could you please review my code? Additionally, I’d appreciate more suggestions to help solve this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants