# how to turn off symbolic sum evaluation

I made some symbolic manipulation and finally... I want to save a 'sum()' in a input form (a evaluated version is horrible big). It is possible to turn off the sum evaluation in SAGE?

edit retag close merge delete

Sort by » oldest newest most voted

The problem is that, unlike some other symbolic operators, the symbolic sum does not accept the hold parameter:

sage: var('k n')
(k, n)
sage: sum(binomial(n,k),k,1,n, hold=True)
TypeError: symbolic_sum() got an unexpected keyword argument 'hold'


So, we have to look at the source code and figure out how to simulate one. It is not straightforward, but here is a possible solution:

sage: from sage.interfaces.maxima_lib import max_to_sr, sr_to_max, maxima_eval, max_ratsimp, max_sum, max_simplify_sum
unsimplified_sum = lambda args : max_to_sr(maxima_eval([[max_ratsimp],([max_sum],[sr_to_max(SR(a)) for a in args])]))
sage: further_simplify = lambda f : max_to_sr(maxima_eval([[max_ratsimp],[[max_simplify_sum],sr_to_max(f)]]))


Then, you can do:

sage: var('k n')
(k, n)
sage: s = unsimplified_sum((binomial(n, k), k, 1, n)) ; s
sum(binomial(n, k), k, 1, n)
sage: further_simplify(s)
2^n - 1


Or:

sage: s = unsimplified_sum((k^2,k,1,n)) ; s
sum(k^2, k, 1, n)
sage: further_simplify(s)
1/3*n^3 + 1/2*n^2 + 1/6*n


EDIT

This issue might be fixed by trac ticket 21645.

more