JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.36k stars 151 forks source link

Feature Completeness Against SymPy #59

Open ChrisRackauckas opened 3 years ago

ChrisRackauckas commented 3 years ago

Note that representation and symbolic solving of systems like ODEs, along with physics is left as the domain for ModelingToolkit.jl. Cryptography is out of scope.

┆Issue is synchronized with this Trello card by Unito

Krastanov commented 3 years ago

I would suggest adding an assumption/refine system to this list as well:

image image

Edit: and the opposite direction image image

Edit: Actually, SymbolicUtils might be a better home for assumptions and refine?

dpsanders commented 3 years ago

Symbolic solution of nonlinear equations seems to be missing from the list.

ChrisRackauckas commented 3 years ago

That's kind of overlapping with ModelingToolkit, though we may want functionality here and then make symbolic_solve(::NonlinearSystem just use it.

o314 commented 3 years ago

AFAIK The logic and relational parts of sympy are not mentioned. Is this intentional or an omission ?

ChrisRackauckas commented 3 years ago

Those should be inherited from Julia?

o314 commented 3 years ago

That's clearly done in Julia if we consider the -hacky- reimpl of multidispatch in Simpy

However, I was thinking about their support of boolean algebra with

For the relational part, please note its two meanings

  1. Relational as a (chained) combo of equality and/or comparison in language engineering
  2. Relational as a mapping in discrete math

Sympy has some support for both

(1) can help to bring piecewise functions, linear programming into declarative symbolic modeling

(2) can help to reconciliate computational vs declarative def of function. there may be some static dispatch optimization good to catch there

More generally

My 2cts good if some maths guys can have a review before anything serious

hdavid16 commented 3 years ago

Support for Boolean algebra (DNF, CNF, etc) would be great to have. Could come be useful for logical constraints in a JuMP extension.

ChrisRackauckas commented 3 years ago

Indeed, the JuMP extension piece is the OptimizationSystem in ModelingToolkit.jl, but it does need some Symbolics love to finish it.

hdavid16 commented 3 years ago

Nice to see the optimization systems in ModelToolkit.jl. If we had good support for symbolic algebra we could use it to reformulate of Boolean logic constraints into algebraic mixed integer constraints for discrete optimization inside of JuMP. We'd convert Boolean constraints into their conjunctive normal form and then into MIP constraints for mathematical programming. GAMS has this capability and it'd be great to bring it over to JuMP (https://www.gams.com/latest/docs/UG_EMP_DisjunctiveProgramming.html)

ChrisRackauckas commented 3 years ago

Seems like a great use case for this.

AmplitudeGravity commented 2 years ago

Do you want to add "Asymptotic solutions of differential equation, Asymptotic Expansion of Integral" in Symbolics? And something like Pattern selection and replacement (Cases[], Replace[] in Mathematica) also very useful in practice. It would be nice to see them in Symbolics.

hdavid16 commented 2 years ago

And something like Pattern selection and replacement (Cases[], Replace[] in Mathematica) also very useful in practice. It would be nice to see them in Symbolics.

Symbolics currently has substitute for replacement: see Docs

AmplitudeGravity commented 2 years ago

Let me state the question exactly:

@variables t α σ(..) β[1:2]
@variables w(..) x(t) y z(t, α, x)
expr = β[1]* x + y^α + σ(3) * (z - t) - β[2] * w(t - 1)

A example of the Pattern replacement is to replace all β variables with some values

can I do something as following?

substitute(expr, β[i_]=> 10*i)

The output should be

10* x + y^α + σ(3) * (z - t) -20* w(t - 1)

hdavid16 commented 2 years ago

Yes, you can: substitute(expr, Dict(β[i] => 10*i for i in 1:2))

AmplitudeGravity commented 2 years ago

very nice! I also tested other functions in Symbolics.jl, looks very cool! Although temporary it seems very slow comparing with SymEngine.jl , like "expand" and "substitute" function, I believe the developers will solve that in near future.

shashi commented 2 years ago
substitute(expr, β[i_]=> 10*i)

This is actually a good,idea, we can have substitute(expr, r) become an alias for Postwalk(PassThrough(f))(expr) so you can use substitute(expr, @rule β[~x] => 10 * ~x).

@YingboMa what do you think?

tgross35 commented 2 years ago

Is there any interest in a separate tracking issue for feature completeness vs. MatLab symbolic toolbox, or adding some of those things to this issue? SymPy covers many of the functions, but MatLab has more features for at least a handful of things. It seems like the vision for Julia is to lie somewhere between the two languages in terms of capability, so maybe no harm to add anything missing to a "someday" goal.

MatLab symbolic full list of their features is here https://www.mathworks.com/help/symbolic/mathematics.html.

One specific thing I'd advocate for as far as steering is good interoperability with ControlSystems. An example is that it should be easy to symbolically take the laplace transform of a function, then directly draw a Nyquist/pz/bode plot (or even draw the plots directly from the time domain representation). This example is a bit contreived as it relies more on ControlSystems adding functionality than Symbolics, and is completely blocked by the integration feature on this list anyway. But in general, this harmony is something very nice about Matlab that is nonexistant (to my knowledge) in python.

tgross35 commented 2 years ago

Also, a question - how does/should JuliaSymbolics interoperate with JuliaMath? The Polynomials and Combinatorics check a lot of the items off of this list already.

ChrisRackauckas commented 2 years ago

Also, a question - how does/should JuliaSymbolics interoperate with JuliaMath? The Polynomials and Combinatorics check a lot of the items off of this list already.

As much as possible. There's no need to rewrite what we can just use. In fact, we use Polynomials.jl all of the time already.

One specific thing I'd advocate for as far as steering is good interoperability with ControlSystems. An example is that it should be easy to symbolically take the laplace transform of a function, then directly draw a Nyquist/pz/bode plot (or even draw the plots directly from the time domain representation). This example is a bit contreived as it relies more on ControlSystems adding functionality than Symbolics, and is completely blocked by the integration feature on this list anyway. But in general, this harmony is something very nice about Matlab that is nonexistant (to my knowledge) in python.

That's already happening. In fact, given our heritage of being based around SciML stuff, controls has been one of the big reasons for having this library and one of the big feature drivers.

Is there any interest in a separate tracking issue for feature completeness vs. MatLab symbolic toolbox, or adding some of those things to this issue? SymPy covers many of the functions, but MatLab has more features for at least a handful of things. It seems like the vision for Julia is to lie somewhere between the two languages in terms of capability, so maybe no harm to add anything missing to a "someday" goal.

Indeed if there's anything in this list that SymPy doesn't have, it would be nice to list that.

abrombo commented 1 year ago

I am the original author of galgebra which implements Geometric Algebra in python using sympy to perform the scalar algebra symbolics -

https://galgebra.readthedocs.io/en/latest/

I am exploring writing a similar package in Julia. What I could use to get started are examples of non-commutative symbols. Can you point me in the right direction. I have installed the Symbolics and SymbolicUtils packages.

leonandonayre commented 1 year ago

I am the original author of galgebra which implements Geometric Algebra in python using sympy to perform the scalar algebra symbolics -

https://galgebra.readthedocs.io/en/latest/

I am exploring writing a similar package in Julia. What I could use to get started are examples of non-commutative symbols. Can you point me in the right direction. I have installed the Symbolics and SymbolicUtils packages.

Is this useful for you? https://github.com/serenity4/SymbolicGA.jl

abrombo commented 1 year ago

One of the things galgebra could do was have a fully populated metric tensor (not limited to orthogonal systems).  Is that implemented in SymbolicGA.jl?

On 5/15/23 6:00 PM, Luis Alberto León Andonayre wrote:

I am the original author of galgebra which implements Geometric
Algebra in python using sympy to perform the scalar algebra
symbolics -

https://galgebra.readthedocs.io/en/latest/

I am exploring writing a similar package in Julia. What I could
use to get started are examples of non-commutative symbols. Can
you point me in the right direction. I have installed the
Symbolics and SymbolicUtils packages.

Is this useful for you? https://github.com/serenity4/SymbolicGA.jl

— Reply to this email directly, view it on GitHub https://github.com/JuliaSymbolics/Symbolics.jl/issues/59#issuecomment-1548664148, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN3TFRGO6ATQYILA7QHJD2TXGKRQVANCNFSM4YJ66AJA. You are receiving this because you commented.Message ID: @.***>

utensil commented 1 year ago

One of the things galgebra could do was have a fully populated metric tensor (not limited to orthogonal systems).  Is that implemented in SymbolicGA.jl?

Unfortunately, no, it supports only Euclidean or pseudo-Euclidean spaces (by design, it seems).

When I started https://github.com/pygae/GAlgebra.jl back in 2019, I intended to write a galgebra equivalent in pure Julia, in a progressive porting approach by first relying on the python version, and gradually implement them all in Julia. I evaluated a bit but symbolic features in Julia was far from complete per the need to implement galgebra which covers not only general-metric GA but also Geometric Calculus. These features are still quite unique in GA community although there're so many new GA libraries as they have different focuses. The situation is quite different now, I can compile a separate Feature Completeness list for your reference when I have some time. I believe most of the hacks and boilerplate in galgebra can be greatly simplified.

We can continue the discussion here: https://github.com/pygae/GAlgebra.jl/issues/10 .

chakravala commented 1 year ago

@abrombo the next version 0.9 of Grassmann.jl will support the fully general metric tensor symbolically, this is the main remanining final feature before the final release of v1.0 Grassmann.jl is released, I also have my own implementation of symbolic polynomial algebra implemented on top of FieldAlgebra.jl which is used in my Similitude.jl package. After Grassmann.jl v1.0 is released, it will be able to handle fully metric tensor symbolically as well. Grassmann.jl is commonly accepted as the best foundation for geometric algebra in Julia.

If we take a look at the GitHub stars of Julia algebra packages, Grassmann.jl is part of the central tree of it:

https://anvaka.github.io/map-of-github/#11.34/27.099/-10.6268

Screenshot_2023-05-16_20-19-41

Despite the fact that the official Julia community ignores me, pretends I don't exist, and even bans me, yet Grassmann.jl is part of the central branch of computer algebra packages in the Julia language.

sylvaticus commented 10 months ago

I think it should be added to this list the algebraic resolution of differential equations, e.g.:

julia> using SymPy
julia> @syms x
(x,)
julia> y = sympy.Function("y")
PyObject y
julia> result = dsolve(sympy.Derivative(y(x), x) -  2*y(x)/x)
           2
y(x) = C₁⋅x 
StarlightScribe commented 2 months ago

Where do contributors coordinate on these? I don't see any projects or discussions.

ChrisRackauckas commented 2 months ago

There are lots of random discussions mostly focused on single subtopics. Many discussions on Slack and Zulip.