-
-
Notifications
You must be signed in to change notification settings - Fork 560
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
Implement a "distribute" method #22937
Comments
comment:1
Discussion opened onsage-devel |
Branch: u/charpent/distribute |
comment:3
First implementation :
Passes ==> New commits:
|
Commit: |
comment:4
Further verifications show that this does not work in all cases. Back to the old drawing board... |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:6
Passes
which passes when run standalone. ==> |
Dependencies: 17505 |
comment:7
Planning to implement the multiplicative case allowed by #17505. |
comment:8
Minor comment: Instead of using map(lambda t:treat_term(op, t, la), aa)
treat_term(op, t, la) for t in aa (with wrapping it as a list comprehension Addendum - I feel this is cleaner and IIRC, it is faster. |
Changed dependencies from 17505 to #17505 |
comment:9
Replying to @tscrim:
Indeed (my Lisp roots (and my age...) are showing).
I'll check that. But I'll submit first the "map" version (which works...), and re-submit the "comprehension" version afterwards if it makes a serious difference. BTW : other enhancements are possible. For example create a local (static) dictionary of distributable operators, whose values are functions processing the corresponding case of distribution (with possible generalizations/factorizations). I didn't feel the four special cases we treat in SR so fare were worth it, but if you have other ideas, you're welcome... Commit forthcoming. Review request after |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:11
It's about 3x slower to use
Also in Python2, I cannot comment so much about the operators as it is a little beyond my expertise. |
comment:12
This version passes I'll try Travis' version before marking the better version for review. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:20
Cosmetic (but important) changes to the documentation. Thank you, Travis.
|
comment:21
Replying to @tscrim: You are still listed as an author in the docstring (credit where credit is due...). |
comment:22
I shouldn't be because I just did some simple review changes (so please remove me). But thank you. :) Everything else looks good. |
comment:23
is the word "indiced" correct or it is "indexed"? (i'm not native english speaker though..) |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:25
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:27
RReplying to @tscrim:
Your suggestion to do without map() was a good one (and teached me something I tend to oversee : Python is not Lisp...).
If you insist...
So this last update (including indiced --> indexed) should be reviewed... New commits:
|
comment:28
Replying to @EmmanuelCharpentier:
I am always learning things from my reviewers too.
Thank you. I didn't really author code other than give suggestions, so I don't think I should be listed as an author. :) You will need to add a doctest in the dependency, but you don't have to merge it into this ticket explicitly (because it is a dependency and will be done by Volker in the develop branch). |
comment:29
Replying to @tscrim: [ Snip ... ]
This should wait Ralf's implementation of the externally-visible |
comment:30
Interesting. Both branches apply but mine has a hunk that fuses two hunks into one; yours has the first of the two so my hunk cannot be applied. I'll upload a branch where the two are separated. |
comment:32
Replying to @rwst:
Go ahead. Do you need me to do anything ? |
Changed branch from u/charpent/distribute to |
Changed commit from |
comment:34
WARNING You have used here "apply()" which is not python3-compatible. Please correct this ASAP in another ticket. Reference: www.diveintopython3.net/porting-code-to-python-3-with-2to3.html The Python 2 builtin apply() has been removed in Python 3 |
comment:35
Replying to @fchapoton:
Will do that, maybe over the coming week-end, but have to think about it I'm not much of a Python coder...).
Thanks for the suggestion.
H... right. |
comment:36
Do you want me to take care of that, and then be a reviewer ? Maybe this will be faster. |
comment:37
I created #23030 |
Motivation : some "obvious" transformations, sometimes helpful in routine calculations, cannot be obtained via the current methods. Some (elementary,
i. e. high-school- or undergrad-level) exemples : given the declarations :
the following equalities, true under no or mild conditions, cannot be deduced currently :
Similarly, if A, B and C are matrices over a suitable ring and of
suitable dimensions, the following equalities cannot be
straightforwardly obtained.
(Curiously,
(f(x)+g(x)).diff(x)
does returndiff(f(x),x)+diff(g(x),x)
(and a way to return to the originalexpression does not seem to exist currently)).
The ability to generate the right-hand form from the left-hand form of
these various examples is sometimes useful in (low-level)
examples. The examples (1) and/or (2) arise naturally when deriving the
maximum-likelihood estimators of the mean and variance of a given
distribution. The third one is often encountered in elementary calculus
exercises.
In all cases, an operator is "distributed" over another one :
(1) : symbolic_sum is distributed over addition.
(2) : symbolic product is distributed over multiplication.
(3) : integration is ditributed over addition.
(4) : trace is distributed over (matrix) addition.
(5) : determinant is distributed over (matrix) multiplication.
Implementing (1) as an extension of the
expand()
method ofExpression is tempting (see #22915). However, there are situations
where this expansion is not useful. So, creating a method for such
situations seems useful.
One should note that such "distributions" are not systematically
valid : we have a collection of special cases rather than a general
mechanism. So this method shoud either limit itself to a few
recognized cases or take keyword argument(s) specifying what should be
distributed over what.
Another design choice is to know if these distributions should be
recursive or run only on the top level of a given expression
(possibly controlled by another keyword argument).
The present ticket aims at implementing this method for
sage.symbolic.expression.Expression
, at least in cases (1) to (3) (case (2) needs an implementation of the symbolic products, see #17505). Further suggestions for other classes are welcome...Depends on #17505
Upstream: None of the above - read trac for reasoning.
CC: @rwst @tscrim
Component: symbolics
Author: Emmanuel Charpentier, Ralf Stephan
Branch:
7aee739
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/22937
The text was updated successfully, but these errors were encountered: