Skip to content

Symbolic sums should evaluate #15346

Closed
Closed
@kcrisman

Description

@kcrisman

This ask.sagemath question points out that

sage: k,n = var('k,n')
sage: f(x,k) = sum((2/n)*(sin(n*x)*(-1)^(n+1)), n, 1, k)
sage: f(x,2)
-2*sum((-1)^n*sin(n*x)/n, n, 1, 2)

while

sage: f(x)=(2/n)*(sin(n*x)*(-1)^(n+1))
sage: sum(f, n, 1, 2) #using summation function
-sin(2*x) + 2*sin(x)

User twch found this workaround

sage: var('n')
sage: def g(x,k):
sage:    return sum((2/n)*(sin(n*x)*(-1)^(n+1)), n, 1, k)
sage: print g(x,2)
-sin(2*x) + 2*sin(x)

but I agree with him/her that we should look into how to fix this.

The essential problem is that when Maxima does not simplify a sum, we don't have any mechanism (currently) to get it to "just print out all the numbers". Which of course may not be very nice when k is big, but presumably should be allowed to be done by users.


By the way, the way to do this in Maxima is as follows:


(%i1) f: -2*'sum((-1)^n*sin(n*x)/n,n,1,2);
                                2
                               ====       n
                               \     (- 1)  sin(n x)
(%o1)                      - 2  >    ---------------
                               /            n
                               ====
                               n = 1

(%i8) f, nouns;
                                 sin(2 x)
(%o8)                       - 2 (-------- - sin(x))
                                    2

so setting nouns:true just for this would work, but I can never figure out how to do this from within Sage - see #10955.

Possibly related: #9424

See also

CC: @orlitzky

Component: symbolics

Author: Ralf Stephan

Branch/Commit: 3ee8c6d

Reviewer: Karl-Dieter Crisman

Issue created by migration from https://trac.sagemath.org/ticket/15346

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions