Opened 3 years ago
Closed 3 years ago
#22915 closed enhancement (wontfix)
Distribute symbolic sums over the terms of their first (sum) argument
Reported by:  charpent  Owned by:  

Priority:  minor  Milestone:  sageduplicate/invalid/wontfix 
Component:  symbolics  Keywords:  
Cc:  rws  Merged in:  
Authors:  Reviewers:  
Report Upstream:  N/A  Work issues:  
Branch:  u/charpent/expand_sum (Commits)  Commit:  19bd0bec91c8a10feb67c5f19e8a97baa9053163 
Dependencies:  Stopgaps: 
Description (last modified by )
Change History (14)
comment:1 Changed 3 years ago by
 Branch set to u/charpent/expand_sum
comment:2 Changed 3 years ago by
 Commit set to 19bd0bec91c8a10feb67c5f19e8a97baa9053163
Branch pushed to git repo; I updated commit sha1. New commits:
19bd0be  Documentation of the distribution of symbolic sums over sums.

comment:3 Changed 3 years ago by
 Component changed from PLEASE CHANGE to symbolics
 Status changed from new to needs_review
Passes ptestlong
with thye same problems as with 8.0.beta4 (see this post on sagerelease).
==> needs_review
. But again, this is functional, but largely perfectible.
comment:4 Changed 3 years ago by
 Cc rws added
 Description modified (diff)
comment:5 followups: ↓ 6 ↓ 7 Changed 3 years ago by
I would call this only if the expression contains sums, test it via e.g.:
sage: w=SR.wild() sage: ex = sum(x+x^2,x,1,n,hold=True) sage: ex.has(sum(w,x,1,m,hold=True)) False sage: ex.has(sum(w,x,1,n,hold=True)) True
Minor cosmetics would be to give ES a more descriptive name. Also you need spaces after commata, semicola, and around equal signs for convention. Finally please test if your documentation builds, the doctest spacing looks wrong. Oh and sums whos first argument is a sumn are
contains two typos.
comment:6 in reply to: ↑ 5 Changed 3 years ago by
comment:7 in reply to: ↑ 5 ; followup: ↓ 8 Changed 3 years ago by
 Status changed from needs_review to needs_work
Replying to rws:
I would call this only if the expression contains sums, test it via e.g.:
sage: w=SR.wild() sage: ex = sum(x+x^2,x,1,n,hold=True) sage: ex.has(sum(w,x,1,m,hold=True)) False sage: ex.has(sum(w,x,1,n,hold=True)) True
Indeed. But isn't that more expensive than directly testing for the operator being sum (and recurse) ?
Minor cosmetics would be to give ES a more descriptive name.
Will do (maybe : see below). But that's only an internal subfunction.
Also you need spaces after commata, semicola, and around equal signs for convention.
OK. (I'm probably the worst typist in the world...).
Finally please test if your documentation builds, the doctest spacing looks wrong. Oh and
sums whos first argument is a sumn are
contains two typos.
Indeed...
But I'm beginning to have misgivings. "Distribute symbolic sums over sums" isn't lthe only case where this might be useful. We have also :
 Distribute symbolic products over products (when we have symbolic products...).
 Distribute sums (symbolic and add_vararg) over derivation (I currently get nonsense, BTW...)
 Ditto for integration.
and I may forget other "obvious" cases which are not obvious to me...
I'm starting to think that we may need a distribute
method (with possibly optional arguments allowing to specify what should distributed over what), rather than (over)extending the expand
method.
What do you think ? I'm setting this ticket to needs_work
while expecting your comments
comment:8 in reply to: ↑ 7 ; followup: ↓ 9 Changed 3 years ago by
Replying to charpent:
I'm starting to think that we may need a
distribute
method (with possibly optional arguments allowing to specify what should distributed over what), rather than (over)extending theexpand
method.
I don't object.
comment:9 in reply to: ↑ 8 Changed 3 years ago by
Replying to rws:
Replying to charpent:
I'm starting to think that we may need a
distribute
method (with possibly optional arguments allowing to specify what should distributed over what), rather than (over)extending theexpand
method.I don't object.
Created #22937. I'll make an inital proposal there (not quite soon, alas...). I'll also post something on sagedevel
.
comment:10 followup: ↓ 12 Changed 3 years ago by
For what it's worth, Maxima has declare(foo, additive)
(also outative
and linear
) which seems to have the desired effect. E.g.
(%i2) 'sum(f(i) + g(i), i,1,n); (%o2) 'sum(g(i)+f(i),i,1,n) (%i3) declare(nounify(sum), additive) $ (%i4) 'sum(f(i) + g(i), i,1,n); (%o4) 'sum(g(i),i,1,n)+'sum(f(i),i,1,n)
That's handled by the global simplifier, so it's all or nothing  you can't expand one expression and not another. Dunno if that's an issue. Also, this action is purely formal  if it's an infinite sum, the simplifier happily plows ahead without testing convergence.
There is also a more general mechanism for distributing operators and functions over other operators and functions, via the symbol property DISTRIBUTE_OVER. This is used to distribute some functions over lists, matrices, and equations. The declaration has to be in Lisp, e.g. :lisp (setf (get 'mfoo 'distribute_over) '(mbar mbaz mquux))
which says that operator MFOO distributes over MBAR, MBAZ, and MQUUX. Again the general simplifier puts that declaration into effect.
Anyway, hope that sheds some light.
comment:11 followup: ↓ 13 Changed 3 years ago by
Please take take ASAP of the apply/python3 issue introduced in #22937.
comment:12 in reply to: ↑ 10 Changed 3 years ago by
Dear Robert,
Sorry, I didn't see your (quite enlightening) answer until right now (tywo weeks later).
I've implemented (part of) what I want in #22937. But I'll consider comparing tgis implementation with changing the relevant properties onthefly to the same effect.
Anyway, the present ticket is abandoned. I just forgot to close it.
Replying to robert_dodier:
For what it's worth, Maxima has
declare(foo, additive)
(alsooutative
andlinear
) which seems to have the desired effect. E.g.(%i2) 'sum(f(i) + g(i), i,1,n); (%o2) 'sum(g(i)+f(i),i,1,n) (%i3) declare(nounify(sum), additive) $ (%i4) 'sum(f(i) + g(i), i,1,n); (%o4) 'sum(g(i),i,1,n)+'sum(f(i),i,1,n)That's handled by the global simplifier, so it's all or nothing  you can't expand one expression and not another. Dunno if that's an issue. Also, this action is purely formal  if it's an infinite sum, the simplifier happily plows ahead without testing convergence.
There is also a more general mechanism for distributing operators and functions over other operators and functions, via the symbol property DISTRIBUTE_OVER. This is used to distribute some functions over lists, matrices, and equations. The declaration has to be in Lisp, e.g.
:lisp (setf (get 'mfoo 'distribute_over) '(mbar mbaz mquux))
which says that operator MFOO distributes over MBAR, MBAZ, and MQUUX. Again the general simplifier puts that declaration into effect.Anyway, hope that sheds some light.
comment:13 in reply to: ↑ 11 Changed 3 years ago by
 Description modified (diff)
 Milestone changed from sage8.0 to sageduplicate/invalid/wontfix
 Status changed from needs_work to positive_review
comment:14 Changed 3 years ago by
 Resolution set to wontfix
 Status changed from positive_review to closed
Closing tickets in the sageduplicate/invalid/wontfix module with positive_review (i.e. someone has confirmed they should be closed).
This first implementation follows the guidelines suggested by Ralf Stephan. It is probably highly perfectible :
expand()
method/function, with edault value being either True or False (to be discussed).expand()
method essentially dispatches the work to the components of theExpression
, This specialized expansion could (should ?) take place as a method ofFunction_sum
, but I'm currently unablke on how to do this (this is my first ever attempt to work on the Sage symbolics in the library).Suggestions, criticisms, even lazzi are welcome as long as they are constructive...
I'm not marking this as
needs_review
, since the documentation remains to be written. I may push a documentation patch and mark itneeds_review
soon.