-
Notifications
You must be signed in to change notification settings - Fork 156
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
Generate Taylor series #1298
Generate Taylor series #1298
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #1298 +/- ##
===========================================
+ Coverage 6.69% 78.04% +71.35%
===========================================
Files 47 50 +3
Lines 4618 4856 +238
===========================================
+ Hits 309 3790 +3481
+ Misses 4309 1066 -3243 ☔ View full report in Codecov by Sentry. |
One problem is that the coefficients come out as floats (I want them to be rationals) because of julia> @variables x
1-element Vector{Num}:
x
julia> y = expand_derivatives(Differential(x)(sin(x)) / 2)
(1//2)*cos(x)
julia> substitute(y, x => 0)
0.5 Using julia> substitute(y, x => 0, fold=false)
(1//2)*cos(0)
julia> substitute(y, x => 0, fold=true)
0.5 The issue is that e.g. |
This does seem like a good thing for Symbolics. @shashi do you know how to make substitute not convert to float? |
One (far from perfect) solution is to |
There is also TaylorSeries.jl, which could perhaps compose with Symbolics.jl. |
0728407
to
cfa315b
Compare
I have made quite a hefty rewrite of the perturbation example. My goal has been to significantly shorten it and better display the features of Symbolics.jl, and particularly the power of the new Taylor series functions. I hope I have not lost the spirit of the old tutorial. Please let me know if you want me to restore some of it. |
I would appreciate it if someone looks at this :) Suggestions are welcome! Particularly regarding how you think the public Taylor series interface should work, i.e. the current cc @karlwessel and #1292 and SciML/ModelingToolkit.jl#3098 |
I love to take a more closer look at this, but not before mid of next week. |
This is what makes evaluating the usefulness of this PR complicated for me.
What does TaylorSeries provide that wouldn't be easily doable using this PR?
What does Symbolics + this PR provide that wouldn't be easily doable with TaylorSeries?
In a perfect World:
In our world: Is it ok for them to just live happily side by side? If yes: is this really worth adding to Symbolics, or would it be enough to add a tutorial that shows how to expand a function as a Taylor series? |
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.
I am mixed about the changes. A lot of the explanations in the text have become much clearer, especially on describing perturbation theory and its advantages (for CAS and in general).
It also does a good job to show of the new implemented features for working with Taylor series.
However, since the previous version had to implement all of the taylor specific features by hand it was easier for me to understand the procedure and adapt it for my own problem. Now if one of the new library methods fails for my own specific problem I wouldn't really know what to do. That of course wouldn't be a problem if the new methods just work for everything.
I would suggest to split this PR into multiple steps/stages. In the first step introduce and implement easy to understand simple versions of the Taylor series methods in the perturbation example, specific to the perturbation example. In the next step see how those methods can be used or adapted to work for the example on perturbation theory for ODEs in ModelingToolkit. And last, if those methods have proven to work in the examples and maybe have been used to solve other perturbation problems (multivariate equations, PDEs, field equations) we can use that experience to decide how and where to add those methods to the Symbolics library or its ecosystem. |
Thanks for the feedback, I agree with many of your points. Maybe splitting the changes according to your 3 incremental stages would be the best approach.
Ideally, I agree it would be fantastic to compose with TaylorSeries.jl. That should work for series with numerical coefficients (e.g.
I can relate to this. But I think if Symbolics is to be a viable CAS, it is more important to have the expected convenience functions so every user does not have to reimplement them. It is also on the wanted feature list (#59). I must leave this as-is for now. It works and is "complete", but can surely be improved. If I get time, maybe I will get back at it. Anyone is welcome to take over, of course. |
The additional functionality is definitely a yes: yes people can build this functionality from pure Julia but of course that's the case because the library is all Julia. That's no reason to not improve the user experience. That doesn't mean we can't have tutorials of people doing this stuff by hand, but most people shouldn't need to. Let's get this rebased and tests passing. I think the only thing left is to potentially write out a few more steps in the perturbation tutorial. |
Alright I will try to do it in the near future. |
…n with automatic coefficients in tutorial
I rebased and incorporated some of @karlwessel's suggestions. Hopefully this reaches a balance point. I'm not 100% convinced the current |
Thanks for finalizing this! I wasn't aware this was on the wanted features list. |
Is something like this suited for Symbolics.jl?