strange behavior with sums

38 views
Skip to first unread message

Karl Schultheisz

unread,
Jun 23, 2014, 8:34:01 AM6/23/14
to sage-s...@googlegroups.com
I'm using Sage 6.2 on Arch Linux. I have posted before about sums being wrong, and I am happy to see that the community took action. Thanks! I have been seeing other errors that may or may not be related to those addressed in the link above.

I open a new Sage session (command line). The following code ought to return (e^x - 1)/x.

    sage: k = var('k')
    sage: sum(x^k/factorial(k+1),k,0,oo)
    1/4*sqrt(pi)*sqrt(x)*e^(1/2*x)


This looks similar to the sort of nonsense it was spitting out when misinterpreting Bessel functions from Maxima. In the same session, if I run the summation command again, the result is different.

    sage: sum(x^k/factorial(k+1),k,0,oo)
    sum(x^k/factorial(k + 1), k, 0, +Infinity)


And after this it will not simplify any sums, even ones it would have done correctly on the first try:

    sage: sum(x^k/factorial(k),k,0,oo)
    sum(x^k/factorial(k), k, 0, +Infinity)


Even a reset doesn't help. (As a side-note, the exit command doesn't survive reset.)

    sage: reset()
    sage: k = var('k')
    sage: sum(x^k/factorial(k),k,0,oo)
    sum(x^k/factorial(k), k, 0, +Infinity)

    sage: exit
    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    /opt/sage/local/lib/python2.7/site-packages/sage/all_cmdline.py in <module>()
    ----> 1 exit

    NameError: name 'exit' is not defined

Finite sums seem to be ok.

    sage: sum(x^k,k,0,3)
    x^3 + x^2 + x + 1
    sage: m = var('m')
    sage: sum(x^k,k,0,m)
    (x^(m + 1) - 1)/(x - 1)


Any help is greatly appreciated.

Dima Pasechnik

unread,
Jun 23, 2014, 8:38:46 AM6/23/14
to sage-s...@googlegroups.com
On 2014-06-23, Karl Schultheisz <art.l...@gmail.com> wrote:
> I'm using Sage 6.2 on Arch Linux. I have posted before about sums being
> wrong
><https://groups.google.com/d/msg/sage-support/IgC78rcdO7c/qTWzpA9f-P8J>,
> and I am happy to see that the community took action. Thanks! I have been
> seeing other errors that may or may not be related to those addressed in
> the link above.
>
> I open a new Sage session (command line). The following code ought to
> return (e^x - 1)/x.
>
> sage: k = var('k')
> sage: sum(x^k/factorial(k+1),k,0,oo)
> 1/4*sqrt(pi)*sqrt(x)*e^(1/2*x)
>
> This looks similar to the sort of nonsense it was spitting out when misinterpreting
> Bessel functions from Maxima <http://trac.sagemath.org/ticket/16224>. In
> the same session, if I run the summation command again, the result is

did you try applying the patch from #16224 ?

Karl Schultheisz

unread,
Jun 23, 2014, 8:46:37 AM6/23/14
to sage-s...@googlegroups.com
Sorry, I haven't. I don't know how.

Dima Pasechnik

unread,
Jun 23, 2014, 8:49:07 AM6/23/14
to sage-s...@googlegroups.com
On 2014-06-23, Dima Pasechnik <dim...@gmail.com> wrote:
> On 2014-06-23, Karl Schultheisz <art.l...@gmail.com> wrote:
>> I'm using Sage 6.2 on Arch Linux. I have posted before about sums being
>> wrong
>><https://groups.google.com/d/msg/sage-support/IgC78rcdO7c/qTWzpA9f-P8J>,
>> and I am happy to see that the community took action. Thanks! I have been
>> seeing other errors that may or may not be related to those addressed in
>> the link above.
>>
>> I open a new Sage session (command line). The following code ought to
>> return (e^x - 1)/x.
>>
>> sage: k = var('k')
>> sage: sum(x^k/factorial(k+1),k,0,oo)
>> 1/4*sqrt(pi)*sqrt(x)*e^(1/2*x)
>>
>> This looks similar to the sort of nonsense it was spitting out when misinterpreting
>> Bessel functions from Maxima <http://trac.sagemath.org/ticket/16224>. In
>> the same session, if I run the summation command again, the result is
>
> did you try applying the patch from #16224 ?

Note that on Sage 6.3.beta4, which contains the fix from #16224, I get
sage: sum(x^k/factorial(k+1),k,0,oo)
2*sqrt(pi)*sqrt(1/(pi*x))*e^(1/2*x)*sinh(1/2*x)/sqrt(x)

which is correct (up to a failure to get obvious simplifications)

Dima Pasechnik

unread,
Jun 23, 2014, 9:00:43 AM6/23/14
to sage-s...@googlegroups.com
On 2014-06-23, Karl Schultheisz <art.l...@gmail.com> wrote:
> Sorry, I haven't. I don't know how.
well, this is actually easy to fix, as no recompilation of Sage is
needed here: the only change is in src/sage/intefaces/maxima_lib.py

http://git.sagemath.org/sage.git/diff/src/sage/interfaces/maxima_lib.py?id=3e25c1357e6ecc551afe3e27633fdbbd01982708

if you have Sage installed locally, know how to use git then
you can get this patch applied and then run `sage -b`.

In case you do not know anything about git, you can still get a copy
of the updated file from here:
http://git.sagemath.org/sage.git/plain/src/sage/interfaces/maxima_lib.py

save it as SAGE_ROOT/src/sage/intefaces/maxima_lib.py
and then run `sage -b`.

HTH,
Dmitrii
>
> On Monday, June 23, 2014 8:38:46 AM UTC-4, Dima Pasechnik wrote:
>>

Dima Pasechnik

unread,
Jun 23, 2014, 9:10:09 AM6/23/14
to sage-s...@googlegroups.com
On 2014-06-23, Dima Pasechnik <dim...@gmail.com> wrote:
> On 2014-06-23, Karl Schultheisz <art.l...@gmail.com> wrote:
>> Sorry, I haven't. I don't know how.
> well, this is actually easy to fix, as no recompilation of Sage is
> needed here: the only change is in src/sage/intefaces/maxima_lib.py
>
> http://git.sagemath.org/sage.git/diff/src/sage/interfaces/maxima_lib.py?id=3e25c1357e6ecc551afe3e27633fdbbd01982708
>
> if you have Sage installed locally, know how to use git then
> you can get this patch applied and then run `sage -b`.
>
> In case you do not know anything about git, you can still get a copy
> of the updated file from here:
> http://git.sagemath.org/sage.git/plain/src/sage/interfaces/maxima_lib.py
oops, sorry, this will give you an only unpatched copy...
So you really need to get the patch somehow.

Karl Schultheisz

unread,
Jun 23, 2014, 9:45:01 AM6/23/14
to sage-s...@googlegroups.com
Thank you. It is obviously time that I learn to use git.

Karl Schultheisz

unread,
Jun 23, 2014, 11:42:25 AM6/23/14
to sage-s...@googlegroups.com
I have installed git and chosen my name and email address. What commands should I run to apply this patch? I have been reading the developer manual, but at this point I am not interested in contributing code to Sage. I just want to apply patches.


--
You received this message because you are subscribed to a topic in the Google Groups "sage-support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-support/7bPMqk_ORNo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-support...@googlegroups.com.
To post to this group, send email to sage-s...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Dima Pasechnik

unread,
Jun 23, 2014, 2:56:16 PM6/23/14
to sage-s...@googlegroups.com
On 2014-06-23, Karl Schultheisz <art.l...@gmail.com> wrote:
> I have installed git and chosen my name and email address. What commands
> should I run to apply this patch? I have been reading the developer manual,
> but at this point I am not interested in contributing code to Sage. I just
> want to apply patches.
this is basically "reviewing tickets".
Although you need a developer's access to follow typical recepies from
there. However, without the latter you are still OK.
What you can do is the following:
(from your SAGEROOT directory)

git fetch http://trac.sagemath.org/sage.git u/pbruin/16224-maxima_to_sage

you should see something like:

From http://trac.sagemath.org/sage
* branch u/pbruin/16224-maxima_to_sage -> FETCH_HEAD

Now we merge the stuff we just fetched:

git merge FETCH_HEAD

this will open up an editor to record the merge commit message; write
something there (normally it will already have some text to record).
After you saved this file you will see somthing like

Merge made by the 'recursive' strategy.
src/sage/interfaces/maxima_lib.py | 58
++++++++++++++++++++++++++++++++++------------------------
1 file changed, 34 insertions(+), 24 deletions(-)

OK, patch applied, finally run

./sage -b

HTH,
Dmitrii

Karl Schultheisz

unread,
Jun 23, 2014, 4:39:17 PM6/23/14
to sage-s...@googlegroups.com
Thanks for your help. I ran:

[...sage]$ git fetch http://trac.sagemath.org/sage.git u/pbruin/16224-maxima_to_sage
fatal: Not a git repository (or any of the parent directories): .git



Dima Pasechnik

unread,
Jun 23, 2014, 6:09:27 PM6/23/14
to sage-s...@googlegroups.com
On 2014-06-23, Karl Schultheisz <art.l...@gmail.com> wrote:
> Thanks for your help. I ran:
>
> [...sage]$ git fetch http://trac.sagemath.org/sage.git
> u/pbruin/16224-maxima_to_sage
> fatal: Not a git repository (or any of the parent directories): .git

this should be one command (on one line)

Karl Schultheisz

unread,
Jun 23, 2014, 6:17:29 PM6/23/14
to sage-s...@googlegroups.com
I agree. Not sure why it is formatted in the quotation as two lines, because I entered it as one line.


Karl Schultheisz

unread,
Jun 23, 2014, 6:19:38 PM6/23/14
to sage-s...@googlegroups.com
In Arch Linux, Sage installs to /opt/sage. I assume this is the SAGEROOT you refer to.

Dima Pasechnik

unread,
Jun 23, 2014, 6:22:54 PM6/23/14
to sage-s...@googlegroups.com
On 2014-06-23, Karl Schultheisz <art.l...@gmail.com> wrote:
> Thanks for your help. I ran:
>
> [...sage]$ git fetch http://trac.sagemath.org/sage.git
> u/pbruin/16224-maxima_to_sage
> fatal: Not a git repository (or any of the parent directories): .git

I see - you don't have a git repository, and you do need one!
The quick way to get the patch is as follows:
first do, in some other directory,

$ git clone http://trac.sagemath.org/sage.git

you'll see something like

Cloning into 'sage'...
remote: Counting objects: 267342, done.
remote: Compressing objects: 100% (47582/47582), done.
remote: Total 267342 (delta 192114), reused 264313 (delta 189133)
Receiving objects: 100% (267342/267342), 76.30 MiB | 20.59 MiB/s,
done.
Resolving deltas: 100% (192114/192114), done.

now you do

$ cd sage
$ git fetch http://trac.sagemath.org/sage.git u/pbruin/16224-maxima_to_sage
$ git merge FETCH_HEAD

(the last two steps were already explained)

now you copy the patched file in question
(src/sage/interfaces/maxima_lib.py) to your working Sage
install, go there, run 'sage -b'...

If you like to do this on a regular basis then certainly it's better
to have Sage compiled from the git repo you just created.

Dima Pasechnik

unread,
Jun 23, 2014, 6:30:13 PM6/23/14
to sage-s...@googlegroups.com
On 2014-06-23, Karl Schultheisz <art.l...@gmail.com> wrote:
> In Arch Linux, Sage installs to /opt/sage. I assume this is the SAGEROOT
> you refer to.

yes. (usually you will also have an environment variable called
SAGE_ROOT set to the location)

As well,iIf you start Sage and type at the prompt, you'll see something like:

sage: SAGE_ROOT
'/usr/local/src/sage/sage'
sage:

Reply all
Reply to author
Forward
0 new messages