Hi everyone,I have written a draft for a SymPEP (SymPy enhancement proposal) to include MatchPy as a dependency of SymPy.
Once SymPy depends on the MatchPy library, the bindings to MatchPy can be moved into SymPy's core.MatchPy provides a much more powerful pattern matcher than the current one implemented in SymPy's core. In particular:
- it can match multiple patterns at the same time and very efficiently (SymPy's matcher can only process one pattern at a time),
- it can generate a decision tree in Python out of multiple patterns (SymEngine has an implementation to generate a C++ decision tree out of the same patterns).
Feel free to join the discussion either here or on the [SymPEP Pull Request](https://github.com/sympy/SymPEPs/pull/3)
I agree that pattern matching is a crucial part of a CAS and should really be the core of SymPy. If I was redesigning SymPy from scratch then everything would be built on top of a pattern-matching engine and almost all of the logic from the myriad Basic subclasses would just be written as pattern rules. My equivalent of SymEngine would just be a C implementation of the pattern-matching engine rather than a repeat of the object-oriented design of SymPy.
I also agree that matchpy looks like a good implementation of pattern-matching and it makes sense for it to be usable with SymPy. What the SymPEP does not address though is what benefit is gained for users by making matchpy a non-optional dependency. The examples shown look like somewhat specialised usage for which an interested user could just choose to install matchpy.
RUBI would be a good motivation but as far as I can tell RUBI does not yet work. Actually I would prefer it if RUBI was already in a separate package from SymPy - it should not have been merged until it was at least partially working. The rubi_tests folder is included for all users and includes e.g. the sympy/integrals/rubi/rubi_tests/tests/test_trinomials.py file which wastes at least 1.5MB disk space for every single SymPy user for precisely zero benefit (these tests should clearly be in a separate repo). I don't see how making matchpy a non-optional dependency would make it any easier to improve RUBI since anyone who wants to work on it can just install matchpy. In fact if RUBI was not in the main SymPy repo then it could have a hard dependency on matchpy.
I think SymPy has resisted the pressure to bloat extremely well. The last time I downloaded a version of Mathematica it was something over 3GB in size! I am all in favour of not adding stuff that isn't needed just because large 'disks' are so common. Irrelevant code also makes it harder to explore the SymPy source.
David
I agree that pattern matching is a crucial part of a CAS and should really be the core of SymPy. If I was redesigning SymPy from scratch then everything would be built on top of a pattern-matching engine and almost all of the logic from the myriad Basic subclasses would just be written as pattern rules. My equivalent of SymEngine would just be a C implementation of the pattern-matching engine rather than a repeat of the object-oriented design of SymPy.
I also agree that matchpy looks like a good implementation of pattern-matching and it makes sense for it to be usable with SymPy. What the SymPEP does not address though is what benefit is gained for users by making matchpy a non-optional dependency. The examples shown look like somewhat specialised usage for which an interested user could just choose to install matchpy.
RUBI would be a good motivation but as far as I can tell RUBI does not yet work. Actually I would prefer it if RUBI was already in a separate package from SymPy - it should not have been merged until it was at least partially working. The rubi_tests folder is included for all users and includes e.g. the sympy/integrals/rubi/rubi_tests/tests/test_trinomials.py file which wastes at least 1.5MB disk space for every single SymPy user for precisely zero benefit (these tests should clearly be in a separate repo). I don't see how making matchpy a non-optional dependency would make it any easier to improve RUBI since anyone who wants to work on it can just install matchpy. In fact if RUBI was not in the main SymPy repo then it could have a hard dependency on matchpy.
The cost of making matchpy a non-optional dependency would be felt by downstream distributors of SymPy who would then have an additional dependency to include. It would also be felt by all users of SymPy with longer install time, more disk space etc. If a user does not use any of it's features then this cost comes with no benefit.
I am not saying this to disagree with the proposal but that there needs to be a clear rationale for making matchpy a hard dependency and the SymPEP does not address this at all. The SymPEP should also clearly spell out what the downsides of the proposal are.
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/003f5fd9-8137-40eb-a8a6-ca2378a08ccan%40googlegroups.com.
Since we are bringing up SymPEPs again, it would be helpful to agree
on the actual SymPEP process itself. There hasn't been much discussion
on https://github.com/sympy/SymPEPs/pull/2 for a while.
I was also hoping we could have a general PEP about dependencies and
conditions for when something should be added as a hard or optional
dependency.
Although the matchpy gives of AC1-matching capability as far as I'm aware, I just have a question that if is it really general enough.
I'm aware that general equational matching could be an undecidable problem,
and hence there are lots of matchers or unifiers that handles some domain-specific E-matching problems
(for other cases like boolean algebra, distributivity, or some other combinations of equational identities)
and that have to be implemented separately (even there can be some distinguish for one-to-one and many matching because of efficiency)
I think we should relax our stringent no dependency stance for pure python dependencies. Pure python dependency management is essentially solved now for the python ecosystem with the various package managers. This dependency would also be pulled into the sympy organization, so we will have just as much control to maintain it as code in sympy's codebase.
Francesco is a long time valued contributor and if he wants/needs matchpy to help him make sympy better, then we should enable him to do that. Putting up a wall here likely only creates frustration and demotivation. There is likely more value in unleashing Francesco's matchpy improvements to sympy than any devalue adding a dependency to sympy creates.
Jason--On Wed, Oct 6, 2021 at 9:38 AM Francesco Bonazzi <franz....@gmail.com> wrote:--On Tuesday, October 5, 2021 at 2:07:06 p.m. UTC+2 Oscar wrote:I agree that pattern matching is a crucial part of a CAS and should really be the core of SymPy. If I was redesigning SymPy from scratch then everything would be built on top of a pattern-matching engine and almost all of the logic from the myriad Basic subclasses would just be written as pattern rules. My equivalent of SymEngine would just be a C implementation of the pattern-matching engine rather than a repeat of the object-oriented design of SymPy.SymPy can still be modified in order to use a pattern matcher.Also, MatchPy has been partly translated into C++ inside the SymEngine project:I also agree that matchpy looks like a good implementation of pattern-matching and it makes sense for it to be usable with SymPy. What the SymPEP does not address though is what benefit is gained for users by making matchpy a non-optional dependency. The examples shown look like somewhat specialised usage for which an interested user could just choose to install matchpy.The benefits are mostly for SymPy development. You can start defining replacement rules to implement new algorithms.RUBI would be a good motivation but as far as I can tell RUBI does not yet work. Actually I would prefer it if RUBI was already in a separate package from SymPy - it should not have been merged until it was at least partially working. The rubi_tests folder is included for all users and includes e.g. the sympy/integrals/rubi/rubi_tests/tests/test_trinomials.py file which wastes at least 1.5MB disk space for every single SymPy user for precisely zero benefit (these tests should clearly be in a separate repo). I don't see how making matchpy a non-optional dependency would make it any easier to improve RUBI since anyone who wants to work on it can just install matchpy. In fact if RUBI was not in the main SymPy repo then it could have a hard dependency on matchpy.This can be done.The cost of making matchpy a non-optional dependency would be felt by downstream distributors of SymPy who would then have an additional dependency to include. It would also be felt by all users of SymPy with longer install time, more disk space etc. If a user does not use any of it's features then this cost comes with no benefit.Consider that it's pretty common now for libraries to depend on other libraries. An alternative would be to copy the MatchPy project as a subfolder inside SymPy (as it has been done for the multipledispatch module).I am not saying this to disagree with the proposal but that there needs to be a clear rationale for making matchpy a hard dependency and the SymPEP does not address this at all. The SymPEP should also clearly spell out what the downsides of the proposal are.The major downside is probably that MatchPy has not been extensively tested with SymPy. There is a risk factor in relying on a new library.
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/003f5fd9-8137-40eb-a8a6-ca2378a08ccan%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAP7f1AhfqzVwWoqbZosP_uXoM%2BJkw9z5LuvAtXKi0feb5zg8vQ%40mail.gmail.com.
It would be curious if we could rewrite SymPy's core using MatchPy. I mean, there have been some development with a lot of code developed to properly handle the subclassing (or .kind property, that has been introduced now) the Add and Mul classes, especially their flattening algorithm. Multiple dispatch was an initial idea, but it's not quite optimal to use.I would like to point out that all of these issues are practically solved if we use MatchPy. The pattern matcher does not just dispatch on the types of the expressions, but also on the expression substructure.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/61ab2404-c9f7-4eaf-9255-b790d89a298fn%40googlegroups.com.
My approach would be to make a new library that redefines the core of SymPy itself and that uses matchpy or equivalent. Then if that library could be made compatible with SymPy through a mechanism like sympify then it would be possible to work incrementally on it until it was relatively complete. The new library could be unencumbered by backwards compatibility constraints and could fix the known design flaws by having first-class functions, exp as pow, no automatic evaluation, kinds and kind checking built in, match-based assumptions, better handling of singular cases in basic manipulation, ...