Ask Your Question
1

how to turn off symbolic sum evaluation

asked 2013-11-04 03:15:35 -0600

F_Ranek gravatar image

updated 2017-04-10 21:55:45 -0600

tmonteil gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-11-04 10:28:36 -0600

tmonteil gravatar image

updated 2016-10-07 07:01:08 -0600

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-11-04 03:15:35 -0600

Seen: 329 times

Last updated: Oct 07 '16