Opened 4 years ago

Closed 2 years ago

#11990 closed task (fixed)

infinite sums that are infinite produce errors

Reported by: dkrenn Owned by: burcin
Priority: trivial Milestone: sage-6.3
Component: calculus Keywords: infinite sums, infinite, maxima
Cc: kcrisman Merged in:
Authors: Peter Bruin Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: b95820a (Commits) Commit: b95820a6e73023196e480cb6329122f6aa86dd51
Dependencies: #13364 Stopgaps:

Description (last modified by kcrisman)

Look at the following code:

sage: m = var('m')
sage: sum(m, m, 0, oo)
Traceback (most recent call last):
...
ValueError: Computation failed since Maxima requested additional
constraints; using the 'assume' command before summation *may* help
(example of legal syntax is 'assume(m>0)', see `assume?` for more 
details)
Is  m  positive or zero?

But inside the sum, it should be clear what m is. Using one of or both of the commands

sage: assume(m>=0) 
sage: assume(m, 'integer')

does not change the result. Execution of

sage: maxima.sum(m, m, 0, oo)

results in the same (except that a TypeError is thrown).

A different behaviour brings the following example

sage: m = var('m')
sage: sum(2^m, m, 0, oo)
Traceback (most recent call last):
...
ValueError: Sum is divergent.

Whereas

sage: maxima.sum(2^m, m, 0, oo)
inf

Change History (21)

comment:1 Changed 4 years ago by kcrisman

  • Cc kcrisman added
  • Description modified (diff)

Short story is that there are many things like this in Maxima. See #3732, for example. This is a good ticket, but to be fair, it is nearly impossible to guarantee that these interactions will never happen - the Maxima devs would rightly point out that figuring out when all forms will be equivalent is not decidable in polynomial time or something like that.

I'm moving the other one to #11987, as it's almost certainly the same problem.

comment:2 Changed 4 years ago by kcrisman

  • Description modified (diff)

Upon further reflection, what are we seeking for in the second example (which has absolutely nothing to do with #11987, since it really does diverge, my apologies!)? I think that Sage just agrees to raise errors for divergent integrals and sums, not infinity, so the behavior is correct from that point of view.

Otherwise this is another example of #3732, unfortunately.

comment:3 Changed 3 years ago by burcin

I don't see what the expected behavior here is. Do you want sum() to return infinity instead of raising a ValueError with the message Sum is divergent.?

Note that if you state that the variable is positive, the first example also raises an error:

sage: n = var('n')
sage: assume(n>0)
sage: sum(n, n, 0, infinity)
...
ValueError: Sum is divergent.

comment:4 Changed 3 years ago by kcrisman

Burcin, if you agree with me on this (that raising an error is appropriate), then perhaps this should be closed as wontfix? Or should we change all sums and integrals which really do "diverge monotonically to infinity" (as opposed to some other kind of divergence) to return oo?

comment:5 follow-up: Changed 3 years ago by dkrenn

If we know that a sum diverge monotonically to infinity, then the output should say that, i.e. should be oo.

The reason I open the ticket is, that all sums above have the same behavior, but the output is always different, which should not be.

And, I don't see (from a user point of view) any reason, that in

sum(m, m, 0, oo)

Sage asks "Is m positive or zero?" and in

sum(2^m, m, 0, oo)

not.

comment:6 in reply to: ↑ 5 ; follow-up: Changed 3 years ago by kcrisman

If we know that a sum diverge monotonically to infinity, then the output should say that, i.e. should be oo.

Well, that is the question.

The reason I open the ticket is, that all sums above have the same behavior, but the output is always different, which should not be.

Well, maxima.sum is not really applicable, because that is a Maxima element. That's sort of like complaining that mpmath returns mpf numbers - you aren't asking for a Sage element. So it still sort of reverts to the big question.

And, I don't see (from a user point of view) any reason, that in

sum(m, m, 0, oo)

Sage asks "Is m positive or zero?" and in

I'll note that now Sage (via Maxima) asks "Is m positive, negative, or zero?"

sum(2^m, m, 0, oo)

not.

Right, as I said in comment:1, there are lots of things like this in Maxima (extra interactions). We can report it upstream, but it may be that the algorithm they use just has to ask this.

It sounds like you're motivated on this one, and certainly it would be great to get the right error and not the question.

(%i6) load(simplify_sum);
(%o6) /Users/.../sage-5.2/local/share/maxima/5.26.0/share/c\
ontrib/solve_rec/simplify_sum.mac
(%i7) simplify_sum(sum(m,m,0,inf));
Is  m  positive, negative, or zero?
(%i3) assume(m>0);
(%o3)                               [m > 0]
(%i4) simplify_sum(sum(m,m,0,inf));

sum: sum is divergent.
#0: simplify_sum(expr='sum(m,m,0,inf))
 -- an error. To debug this try: debugmode(true);

You could ask about this on the Maxima list or report it on their tracker! Incidentally,

sage: var('m')
m
sage: assume(m>0)
sage: sum(m,m,0,oo)

ValueError: Sum is divergent.

so something must have changed in the meantime.

comment:7 in reply to: ↑ 6 ; follow-up: Changed 3 years ago by burcin

  • Reviewers set to Burcin Erocal
  • Status changed from new to needs_review

Replying to kcrisman:

The reason I open the ticket is, that all sums above have the same behavior, but the output is always different, which should not be.

Well, maxima.sum is not really applicable, because that is a Maxima element. That's sort of like complaining that mpmath returns mpf numbers - you aren't asking for a Sage element. So it still sort of reverts to the big question.

Exactly. The behavior of the sum() function in Sage is consistent. maxima.sum() is just a wrapper to call Maxima. That is also consistent with Maxima behavior.

The expression sum(m, m, 0, oo) is divergent if m != 0 and 0 if m=0. So the best we can do without the assumption Maxima is asking for is to leave it unevaluated.

On the question of shall we raise an error or return oo: Leaving aside the problem that it is usually not that easy to decide which type of infinity to return, I would like to get an error as soon as a divergent sum is encountered. If this expression was part of a larger one, and we decide that its divergent after a substitution, there isn't much point in carrying on evaluating the expression.

In Sage there is one exception to this rule, we return different types of infinity from special functions if you hit a pole. For example gamma(-1) -> Infinity. This is compatible with MMA, although it contradicts Maple or GiNaC. This allows us to do (1/gamma(n)).subs(n=-1) -> 0 instead of raising an error. Compared to what goes on when evaluating sum(), gamma() is a fundamental operation. This convenience to avoid special casing potential poles of gamma() is well worth the bug hunting after a complex expression ends up evaluating to oo.

Since we already have a ticket about handling interactive prompts from Maxima, I suggest we close this ticket.

comment:8 in reply to: ↑ 7 Changed 3 years ago by kcrisman

Exactly. The behavior of the sum() function in Sage is consistent. maxima.sum() is just a wrapper to call Maxima. That is also consistent with Maxima behavior.

Yes.

The expression sum(m, m, 0, oo) is divergent if m != 0 and 0 if m=0. So the best we can do without the assumption Maxima is asking for is to leave it unevaluated.

Well, I don't know about this. In some sense, this should be a "dummy variable" in which case the sum is clearly 0+1+2+... but for consistency perhaps this is okay in our case. Otherwise I do agree with dkrenn that sum(2^m, m, 0, oo) should also be asking a question. But this would be an upstream issue, more or less.

On the question of shall we raise an error or return oo: Leaving aside the problem that it is usually not that easy to decide which type of infinity to return, I would like to get an error as soon as a divergent sum is encountered. If this expression was part of a larger one, and we decide that its divergent after a substitution, there isn't much point in carrying on evaluating the expression.
Since we already have a ticket about handling interactive prompts from Maxima, I suggest we close this ticket.

I guess I would be interested in whether Maxima considers the discrepancy between sum(2^m, m, 0, oo) and sum(m, m, 0, oo) behavior is a bug. After all, m should really be a dummy variable! I've actually sent an email and so request to not close this ticket, since this is a (slightly) different issue than the overall issue of Maxima giving interactive prompts. After all, Maxima's integrate(m,m,0,inf) doesn't ask such a question, but says it's divergent.

comment:9 Changed 3 years ago by kcrisman

  • Report Upstream changed from N/A to Reported upstream. No feedback yet.
  • Status changed from needs_review to needs_info

comment:10 Changed 3 years ago by robert_dodier

I've pushed 07a0c810eade (to Maxima Git repo) which changes the behavior of ev(sum(m, m, 0, inf), simpsum=true) so that it immediately reports "sum is divergent" without asking about the sign of m. I believe this clears up the superfluous asksign which Sage bumped into.

This change will appear in the next version (5.29) of Maxima, which is scheduled for early December 2012.

comment:11 Changed 3 years ago by kcrisman

  • Report Upstream changed from Reported upstream. No feedback yet. to Fixed upstream, but not in a stable release.
  • Reviewers Burcin Erocal deleted
  • Status changed from needs_info to needs_review

Great! Can you put a link to that here, Robert? I'm having trouble getting a link to that change set when I browse the Sourceforge git thing - probably just not familiar with the interface, my apologies.

comment:13 Changed 3 years ago by kcrisman

  • Dependencies set to #13364
  • Status changed from needs_review to needs_work

This should get fixed whenever we upgrade to upstream, which is now 5.29.1. I'm putting 'needs work' for that and of course making a patch to check that this works now.

comment:14 Changed 3 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:15 Changed 2 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:16 Changed 2 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:17 Changed 2 years ago by pbruin

  • Report Upstream changed from Fixed upstream, but not in a stable release. to N/A

Since this has now been fixed, all we need to do is to add a doctest.

comment:18 Changed 2 years ago by pbruin

  • Authors set to Peter Bruin
  • Branch set to u/pbruin/11990-divergent_sum_error
  • Commit set to 73e180573040b85cbcc86ff18bd4fba1fe2fc836
  • Priority changed from major to trivial
  • Status changed from needs_work to needs_review
  • Type changed from defect to task

comment:19 Changed 2 years ago by git

  • Commit changed from 73e180573040b85cbcc86ff18bd4fba1fe2fc836 to b95820a6e73023196e480cb6329122f6aa86dd51

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

b95820aTrac 11990: doctest for divergent sum error

comment:20 Changed 2 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

LGTM

comment:21 Changed 2 years ago by vbraun

  • Branch changed from u/pbruin/11990-divergent_sum_error to b95820a6e73023196e480cb6329122f6aa86dd51
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.