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

feat: make ia_solve modular #1348

Merged
merged 9 commits into from
Nov 6, 2024

Conversation

AayushSabharwal
Copy link
Contributor

This attempts to:

  • Allow ia_solve to handle any function that implements the inverse interface instead of hardcoding a list.
  • Allow ia_solve to handle periodic functions that are not sin, cos or tan.
  • Toggle on and off certain behavior in ia_solve (specifically, the way it handles periodic functions and complex roots)

@n0rbed I would really appreciate your review on this

@codecov-commenter
Copy link

codecov-commenter commented Nov 5, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 79.24528% with 11 lines in your changes missing coverage. Please review.

Project coverage is 78.93%. Comparing base (3e31a75) to head (1d71dd4).
Report is 56 commits behind head on master.

Files with missing lines Patch % Lines
src/solver/ia_helpers.jl 50.00% 8 Missing ⚠️
src/inverse.jl 33.33% 2 Missing ⚠️
src/solver/ia_main.jl 97.05% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #1348       +/-   ##
===========================================
+ Coverage    6.69%   78.93%   +72.23%     
===========================================
  Files          47       50        +3     
  Lines        4618     4860      +242     
===========================================
+ Hits          309     3836     +3527     
+ Misses       4309     1024     -3285     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +212 to +218
@eval fundamental_period(::typeof($fn)) = 360.0
end

fundamental_period(::typeof(cospi)) = 2.0

for fn in [tand, cotd]
@eval fundamental_period(::typeof($fn)) = 180.0
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason that these are floats? any downsides for making them ints? curious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning was that due to how BasicSymbolic works, calling fundamental_period will always be dynamic dispatch but if all the return types are Float64, Julia should be able to infer that.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, thanks

src/solver/ia_main.jl Outdated Show resolved Hide resolved
test/solver.jl Outdated
Comment on lines 476 to 480
expr = sec(x ^ 2 + 4x + 4) ^ 3 - 3
roots = ia_solve(expr, x)
@test length(roots) == 6 # 2 quadratic roots * 3 roots from cbrt(3)
roots = ia_solve(expr, x; complex_roots = false)
@test length(roots) == 2
Copy link
Member

Choose a reason for hiding this comment

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

if you have the time, maybe also check that these roots' numerical values also holds by evaluating them and comparing them to the known answer from mathematica/matlab.

Copy link
Member

Choose a reason for hiding this comment

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

the tests under this too

@n0rbed
Copy link
Member

n0rbed commented Nov 5, 2024

This is really good! i like it; if you get bored of your work in ia_solve now you can maybe try fixing this

julia> Symbolics.ia_solve(-2a + c + 1 / c, c)
┌ Warning: This expression cannot be solved with the methods available to ia_solve. Try a numerical method instead.
└ @ Symbolics ~/code/julia/Symbolics.jl/src/solver/ia_main.jl:27
ERROR: MethodError: no method matching iterate(::Nothing)

image

@n0rbed
Copy link
Member

n0rbed commented Nov 6, 2024

@ChrisRackauckas this is good to merge

@n0rbed n0rbed merged commit 8c518c2 into JuliaSymbolics:master Nov 6, 2024
11 of 12 checks passed
@AayushSabharwal AayushSabharwal deleted the as/ia-solve-inverses branch November 7, 2024 05:42
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.

4 participants