Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 5f47daf

Browse files
committed
moved warning after some examples
1 parent 45fbd50 commit 5f47daf

File tree

3 files changed

+105
-99
lines changed

3 files changed

+105
-99
lines changed

src/sage/calculus/calculus.py

+35-33
Original file line numberDiff line numberDiff line change
@@ -435,39 +435,6 @@ def symbolic_sum(expression, v, a, b, algorithm='maxima'):
435435
Returns the symbolic sum `\sum_{v = a}^b expression` with respect
436436
to the variable `v` with endpoints `a` and `b`.
437437
438-
.. WARNING::
439-
440-
This function only works with symbolic expressions. To sum any
441-
other objects like list elements or function return values,
442-
please use python summation, see
443-
http://docs.python.org/2.7/library/functions.html#sum
444-
445-
In particular, this does not work::
446-
447-
sage: n = var('n')
448-
sage: list=[1,2,3,4,5]
449-
sage: sum(list[n],n,0,3)
450-
Traceback (most recent call last):
451-
...
452-
TypeError: unable to convert x (=n) to an integer
453-
454-
Use python sum() instead::
455-
456-
sage: sum(list[n] for n in range(4))
457-
10
458-
459-
Also, only a limited number of functions are recognized in symbolic sums::
460-
461-
sage: sum(valuation(n,2),n,1,5)
462-
Traceback (most recent call last):
463-
...
464-
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'valuation'
465-
466-
Again, use python sum()::
467-
468-
sage: sum(valuation(n+1,2) for n in range(5))
469-
3
470-
471438
INPUT:
472439
473440
- ``expression`` - a symbolic expression
@@ -501,6 +468,41 @@ def symbolic_sum(expression, v, a, b, algorithm='maxima'):
501468
sage: symbolic_sum(1/k^5, k, 1, oo)
502469
zeta(5)
503470
471+
.. WARNING::
472+
473+
This function only works with symbolic expressions. To sum any
474+
other objects like list elements or function return values,
475+
please use python summation, see
476+
http://docs.python.org/library/functions.html#sum
477+
478+
In particular, this does not work::
479+
480+
sage: n = var('n')
481+
sage: list=[1,2,3,4,5]
482+
sage: sum(list[n],n,0,3)
483+
Traceback (most recent call last):
484+
...
485+
TypeError: unable to convert x (=n) to an integer
486+
487+
Use python ``sum()`` instead::
488+
489+
sage: sum(list[n] for n in range(4))
490+
10
491+
492+
Also, only a limited number of functions are recognized in symbolic sums::
493+
494+
sage: sum(valuation(n,2),n,1,5)
495+
Traceback (most recent call last):
496+
...
497+
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'valuation'
498+
499+
Again, use python ``sum()``::
500+
501+
sage: sum(valuation(n+1,2) for n in range(5))
502+
3
503+
504+
(now back to the Sage ``sum`` examples)
505+
504506
A well known binomial identity::
505507
506508
sage: symbolic_sum(binomial(n,k), k, 0, n)

src/sage/misc/functional.py

+35-33
Original file line numberDiff line numberDiff line change
@@ -542,39 +542,6 @@ def symbolic_sum(expression, *args, **kwds):
542542
Returns the symbolic sum `\sum_{v = a}^b expression` with respect
543543
to the variable `v` with endpoints `a` and `b`.
544544
545-
.. WARNING::
546-
547-
This function only works with symbolic expressions. To sum any
548-
other objects like list elements or function return values,
549-
please use python summation, see
550-
http://docs.python.org/2.7/library/functions.html#sum
551-
552-
In particular, this does not work::
553-
554-
sage: n = var('n')
555-
sage: list=[1,2,3,4,5]
556-
sage: sum(list[n],n,0,3)
557-
Traceback (most recent call last):
558-
...
559-
TypeError: unable to convert x (=n) to an integer
560-
561-
Use python sum() instead::
562-
563-
sage: sum(list[n] for n in range(4))
564-
10
565-
566-
Also, only a limited number of functions are recognized in symbolic sums::
567-
568-
sage: sum(valuation(n,2),n,1,5)
569-
Traceback (most recent call last):
570-
...
571-
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'valuation'
572-
573-
Again, use python sum()::
574-
575-
sage: sum(valuation(n+1,2) for n in range(5))
576-
3
577-
578545
INPUT:
579546
580547
- ``expression`` - a symbolic expression
@@ -606,6 +573,41 @@ def symbolic_sum(expression, *args, **kwds):
606573
sage: sum(1/k^5, k, 1, oo)
607574
zeta(5)
608575
576+
.. WARNING::
577+
578+
This function only works with symbolic expressions. To sum any
579+
other objects like list elements or function return values,
580+
please use python summation, see
581+
http://docs.python.org/library/functions.html#sum
582+
583+
In particular, this does not work::
584+
585+
sage: n = var('n')
586+
sage: list=[1,2,3,4,5]
587+
sage: sum(list[n],n,0,3)
588+
Traceback (most recent call last):
589+
...
590+
TypeError: unable to convert x (=n) to an integer
591+
592+
Use python ``sum()`` instead::
593+
594+
sage: sum(list[n] for n in range(4))
595+
10
596+
597+
Also, only a limited number of functions are recognized in symbolic sums::
598+
599+
sage: sum(valuation(n,2),n,1,5)
600+
Traceback (most recent call last):
601+
...
602+
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'valuation'
603+
604+
Again, use python ``sum()``::
605+
606+
sage: sum(valuation(n+1,2) for n in range(5))
607+
3
608+
609+
(now back to the Sage ``sum`` examples)
610+
609611
A well known binomial identity::
610612
611613
sage: sum(binomial(n,k), k, 0, n)

src/sage/symbolic/expression.pyx

+35-33
Original file line numberDiff line numberDiff line change
@@ -9752,39 +9752,6 @@ cdef class Expression(CommutativeRingElement):
97529752
with respect to the variable `v` with endpoints
97539753
`a` and `b`.
97549754
9755-
.. WARNING::
9756-
9757-
This function only works with symbolic expressions. To sum any
9758-
other objects like list elements or function return values,
9759-
please use python summation, see
9760-
http://docs.python.org/2.7/library/functions.html#sum
9761-
9762-
In particular, this does not work::
9763-
9764-
sage: n = var('n')
9765-
sage: list=[1,2,3,4,5]
9766-
sage: sum(list[n],n,0,3)
9767-
Traceback (most recent call last):
9768-
...
9769-
TypeError: unable to convert x (=n) to an integer
9770-
9771-
Use python sum() instead::
9772-
9773-
sage: sum(list[n] for n in range(4))
9774-
10
9775-
9776-
Also, only a limited number of functions are recognized in symbolic sums::
9777-
9778-
sage: sum(valuation(n,2),n,1,5)
9779-
Traceback (most recent call last):
9780-
...
9781-
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'valuation'
9782-
9783-
Again, use python sum()::
9784-
9785-
sage: sum(valuation(n+1,2) for n in range(5))
9786-
3
9787-
97889755
INPUT:
97899756
97909757
- ``v`` - a variable or variable name
@@ -9820,6 +9787,41 @@ cdef class Expression(CommutativeRingElement):
98209787
sage: (1/k^5).sum(k, 1, oo)
98219788
zeta(5)
98229789
9790+
.. WARNING::
9791+
9792+
This function only works with symbolic expressions. To sum any
9793+
other objects like list elements or function return values,
9794+
please use python summation, see
9795+
http://docs.python.org/library/functions.html#sum
9796+
9797+
In particular, this does not work::
9798+
9799+
sage: n = var('n')
9800+
sage: list=[1,2,3,4,5]
9801+
sage: sum(list[n],n,0,3)
9802+
Traceback (most recent call last):
9803+
...
9804+
TypeError: unable to convert x (=n) to an integer
9805+
9806+
Use python ``sum()`` instead::
9807+
9808+
sage: sum(list[n] for n in range(4))
9809+
10
9810+
9811+
Also, only a limited number of functions are recognized in symbolic sums::
9812+
9813+
sage: sum(valuation(n,2),n,1,5)
9814+
Traceback (most recent call last):
9815+
...
9816+
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'valuation'
9817+
9818+
Again, use python ``sum()``::
9819+
9820+
sage: sum(valuation(n+1,2) for n in range(5))
9821+
3
9822+
9823+
(now back to the Sage ``sum`` examples)
9824+
98239825
A well known binomial identity::
98249826
98259827
sage: assume(n>=0)

0 commit comments

Comments
 (0)