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

Feature Completeness Against SymPy #59

Open
1 of 23 tasks
ChrisRackauckas opened this issue Feb 27, 2021 · 25 comments
Open
1 of 23 tasks

Feature Completeness Against SymPy #59

ChrisRackauckas opened this issue Feb 27, 2021 · 25 comments

Comments

@ChrisRackauckas
Copy link
Member

ChrisRackauckas commented Feb 27, 2021

  • Polynomials
    • Factorization
    • Square-free decomposition
    • Grobner bases
    • Partial fraction decomposition
    • Resultants
    • Rootfinding
  • Calculus
    • Limits
    • Integration
    • Taylor series helper functions
  • Combinatorics
    • Permutations
    • Combinations
    • Partitions
    • Subsets
    • Permutation Groups
    • Prufer and Gray Codes
  • Diophantine equations
  • Difference operator
  • Geometry
  • Plot recipes on symbolic equations
  • Support for Distributions.jl, expected values and moments

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

Krastanov commented Mar 2, 2021

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

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

@ChrisRackauckas
Copy link
Member Author

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

@o314
Copy link

o314 commented Mar 11, 2021

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

@ChrisRackauckas
Copy link
Member Author

Those should be inherited from Julia?

@o314
Copy link

o314 commented Mar 11, 2021

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

  • Sympy allow the processing of mixed model of bool and non-bool input via a mix of booleanfunction and latticeop args
  • the assocop / latticeop divide in simpy could help to clarify the computative vs noncommutative cas
  • A lot of algo tend to crossover (buchberger, quine-mccluskey, maybe knuth–bendix)

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

@hdavid16
Copy link

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

@ChrisRackauckas
Copy link
Member Author

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

@hdavid16
Copy link

hdavid16 commented May 11, 2021

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

Seems like a great use case for this.

@AmplitudeGravity
Copy link

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

hdavid16 commented Feb 7, 2022

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

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

hdavid16 commented Feb 25, 2022

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

@AmplitudeGravity
Copy link

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

shashi commented Mar 30, 2022

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

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

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

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

abrombo commented May 15, 2023

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

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

abrombo commented May 16, 2023 via email

@utensil
Copy link

utensil commented May 17, 2023

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: pygae/GAlgebra.jl#10 .

@chakravala
Copy link

chakravala commented May 17, 2023

@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
Copy link

sylvaticus commented Nov 17, 2023

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 

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

No branches or pull requests