-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Objects that know how to combine themselves #5040
Comments
Referenced issues: #4983 |
Referenced issues: #4959 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c3 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c4 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c5 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c6 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c7 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c8 |
Referenced issues: #6220 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c10 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c11 |
Referenced issues: #4590 |
See https://github.com/sympy/sympy/wiki/Canonicalization for some more discussion on this. Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c13 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c14 |
Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c15 |
It just occured to me that this same kind of idea could be applied to the printer. For example, at #1788 , we special case Function, Atom, and Operator in print_Pow, making everything else use parentheses. But what if some object wanted to define it's own power printing representation. What is needed is a way for it to consistently say, "object A should print like this when it contains me". Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c16 |
Sets know how to combine themselves with pairwise intersections and unions. It really does simplify the canonicalization process and greatly improves extension. See any ._intersect and ._union methods in sets as well as Union.reduce and Intersection.reduce Original comment: http://code.google.com/p/sympy/issues/detail?id=1941#c17 |
Is the |
Yes, that is currently the best method for doing this, although that API is still considered experimental, and I'm not yet convinced there isn't a more elegant way. |
There's a question if we can use multiple dispatch #14490. It's not straightforward because Add and Mul take an arbitrary number of arguments. |
I've found |
Yeah, we should remove _from_args from places outside of the core. See for instance #19083. The use of _from_args predates the processors, and it wasn't until recently that the processors were even used for anything useful (the matrix expressions), so we are still ironing out issues. I should also note there is a suggested extension of the API here #18769. |
@eric-wieser Also ping @asmeurer |
This is related to issue #5007 . When I met with Ondrej last summer, we worked on a core where
objects knew how to combine themselves with respect to Mul and Add. See the handler branch at http://github.com/certik/sympyx/ . The idea originally stemmed from issue #4435 , but we soon
discovered that it also simplifies the logic for things like O() (the order function), and oo, which
combine abnormally with respect to Mul and Add. This could also be useful for issue #5039 , so that
the units could tell Mul that they need to stay together without Mul explicitly having to know about
units. Right now, Mul.flatten is cluttered with code for handling all these things, and the only way
to handle additional classes is to either completely separate them from Basic (as with Poly), or to
add more special case code in Mul.flatten.
Anyway, if we ever rework the core as suggested in issue #5007 or elsewhere, we should also look
into doing this too.
Original issue for #5040: http://code.google.com/p/sympy/issues/detail?id=1941
Original author: https://code.google.com/u/asmeurer@gmail.com/
Referenced issues: #4435, #5039, #5007
The text was updated successfully, but these errors were encountered: