Symbolics.jl
Symbolics.jl copied to clipboard
[request] support for symbolic integration
something like:
@variables t
D = Differential(t)
z = t
julia> expand_integral(∫(z))
0.5(t^2) or 1//2(t^2)
also a question is handling the new constant, should you define a new parameter?
┆Issue is synchronized with this Trello card by Unito
As a note, it's never good to have unicode in the public facing API. So it would be good to encode that as integral
, and if the user is so inclined they should they can do const ∫ = integral
. I think doing it like this and defining it similar to Differential
is a good idea.
The best way to get this started is to setup an import https://rulebasedintegration.org/ into the SymbolicUtils rules system. We can then augment it with a deep learning approach https://github.com/SciML/NeuralPDE.jl/issues/44 which generates a ton of test cases and trains on them.
Alternatively, there is of course the Risch algorithm, which—to my knowledge—is the gold standard for symbolic integration, however it's limited to elementary functions.
As another drawback: it's famous for having a description of over 100 pages...
RUBI looks very promising. But which data set to use as starting point? What about: https://github.com/sympy/sympy/tree/master/sympy/integrals/rubi/rules
The official test suits are only available in:
- Axiom syntax
- Maple syntax
- Mathematica syntax
- Maxima syntax
But Python looks easier to me ...
Just started to look at the first rule, second form for integrands of the form (a + b x) m.
Program code:
Int[x_^m_.,x_Symbol] :=
x^(m+1)/(m+1) /;
FreeQ[m,x] && NeQ[m,-1]
So perhaps the first thing we need is an implementation of FreeQ in Julia? Documentation: https://reference.wolfram.com/language/ref/FreeQ.html
Any idea how to do that?
I created the (nearly empty) package https://github.com/ufechner7/Rubi.jl
The input I need from the Symbolics.jl developers is how to define the integrator interface.
I think if we setup Rubi rulesets it would make sense for them to live in Symbolics.jl or JuliaSymbolics? I don't quite see the maintenance structure of having it separate: that looks a little odd but if you want to setup the rules parsing like that, that's cool.
Alternatively, there is of course the Risch algorithm, which—to my knowledge—is the gold standard for symbolic integration, however it's limited to elementary functions.
Setting up the ability to call into https://github.com/nsmith5/Maxima.jl for risch
could be interesting.
Using Maxima is definitely possible, but I think that somewhat goes against "[...] that is directly extendable in the same language as the users."
I'm not familiar with the structure of the Maxima project, but it seems to 'only' be about 1100 lines of terse, mostly undocumented lisp code (https://sourceforge.net/p/maxima/code/ci/master/tree/src/risch.lisp), which might for instance be doable as a Summer of Code project? There's also a couple of subsets of the Risch algorithm which cover most of the more basic cases.
Either way, integration—however fundamental it is to a CAS system—is a though problem. Overall a CAS is a massive undertaking, but also one of the first things I was looking for when I started using Julia, so I'm very hopeful this project gets the attention and contributions it deserves and needs. 🙂
I wouldn't require it as a dependency. It's like https://github.com/JuliaSymbolics/SymbolicSAT.jl . We can make the integral
syntax for specifying an integral equation exist generically, but allow other packages to add a function that performs the integration with a different backend. That is one way to quickly boost the functionality, and will let us benchmark how accurate our stuff is too when we get to implementing it.
Of course it is massive amount of work required to complete this but what is the state of the integration functionality at the moment, is there any roadmap for it ?
@jakubMitura14 none in the repo yet but @ufechner7 made https://github.com/ufechner7/Rubi.jl and @miguelraz made https://github.com/miguelraz/Rubin.jl
I'm not sure how far along these are yet though, may be good starting places if you'd like to help though
Both of those are empty code repos:
https://github.com/miguelraz/Rubin.jl/blob/master/src/Rubin.jl
https://github.com/ufechner7/Rubi.jl/blob/main/src/Rubi.jl
It's a bad case of cookie licking.
https://communitymgt.fandom.com/wiki/Cookie_Licking
Nobody has worked on this, so this is wide open for anyone to work on.
@ChrisRackauckas I believe @miguelraz's repo is pretty much active and ongoing, it's just that a lot of the preliminary work is just parsing the rules.
I see a function "Integral", will we see it working soon?
help?> Symbolics.Integral
No documentation found.
Symbolics.Integral is of type UnionAll.
Summary
≡≡≡≡≡≡≡≡≡
struct UnionAll <: Type{T}
Fields
≡≡≡≡≡≡≡≡
var :: TypeVar
body :: Any
Supertype Hierarchy
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
UnionAll <: Type{T} <: Any
I had a little weekend project to see what is possible with MathLink.jl
. I have managed to parse most of the rules to @rule integrate(...)
. The project is available here: https://github.com/fgerick/SymbolicRubi.jl with the parsing in the gen
folder.
There's a tiny example that the rules do work in theory, but most of the functions defined by Rubi (or Mathematica) are not translated. This is obviously needed and probably the most tedious part. Also, for the steps afterwards, I do not have the expertise to continue without guidance. I'm happy to keep working on this, but maybe someone can already say if this is useful or if there is a better approach to this?
Cheers
EDIT: for some reason the x86 tests fail for the simple comparison. not sure why...