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

Commit 3ee8c6d

Browse files
committed
Additional example
1 parent c2de94a commit 3ee8c6d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/sage/symbolic/expression.pyx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8759,6 +8759,25 @@ cdef class Expression(CommutativeRingElement):
87598759
-2*sum((-1)^n*sin(n*x)/n, n, 1, 2)
87608760
sage: f(x,2).expand_sum()
87618761
-sin(2*x) + 2*sin(x)
8762+
8763+
We can use this to do floating-point approximation as well::
8764+
8765+
sage: (k,n) = var('k,n')
8766+
sage: f(n)=sum(sqrt(abs(-k*k+n)),k,1,n)
8767+
sage: f(n=8)
8768+
sum(sqrt(abs(-k^2 + 8)), k, 1, 8)
8769+
sage: f(8).expand_sum()
8770+
sqrt(41) + sqrt(17) + 2*sqrt(14) + 3*sqrt(7) + 2*sqrt(2) + 3
8771+
sage: f(8).expand_sum().n()
8772+
31.7752256945384
8773+
8774+
See :trac:`9424` for making the following no longer raise
8775+
an error::
8776+
8777+
sage: f(8).n()
8778+
Traceback (most recent call last):
8779+
...
8780+
TypeError: cannot evaluate symbolic expression numerically
87628781
"""
87638782
return self.parent()(self._maxima_().simplify_sum())
87648783

0 commit comments

Comments
 (0)