ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 15 Dec 2014 19:49:04 +0100Problem evaluating limit: assume doesn't work!https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/ Hi everyone,
I'm trying to evaluate the following limit in sage:
$$\lim_{N\to \infty}\frac{6N^k(N-1)^{1-k}}{(2N-1)(k+1)},$$
where $k\neq \pm1$. From [Wolfram-Alpha I know this is equal to $3/(1+k)$](http://www.wolframalpha.com/input/?i=limit+of+%286*N%5Ek*%28N-1%29%5E%281-k%29%29%2F%28%282*N-1%29*%28k%2B1%29%29+as+N+tends+to+infinity), but I was trying to get to that answer with sage with no progress. What I did to do it was the following:
sage: N = var('N')
sage: k = var('k')
sage: assume(k!=1)
sage: assume(k!=-1)
sage: limit((6*N^k*(N-1)^(1-k))/((2*N-1)*(k+1)),N=oo)
But I get the following error:
ValueError Traceback (most recent call last)
<ipython-input-7-bb63a0377d1b> in <module>()
----> 1 limit((Integer(6)*N**k*(N-Integer(1))**(Integer(1)-k))/((Integer(2)*N-Integer(1))*(k+Integer(1))),N=oo)
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in limit(ex, dir, taylor, algorithm, **argv)
1198 if algorithm == 'maxima':
1199 if dir is None:
-> 1200 l = maxima.sr_limit(ex, v, a)
1201 elif dir in ['plus', '+', 'right', 'above']:
1202 if dir == 'above':
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in sr_limit(self, expr, v, a, dir)
855 j = s.find('Is ')
856 s = s[j:]
--> 857 raise ValueError, "Computation failed since Maxima requested additional constraints; using the 'assume' command before limit evaluation *may* help (see `assume?` for more details)\n" + s
858 else:
859 raise error
ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before limit evaluation *may* help (see `assume?` for more details)
Is k-1.0 positive or negative?
In general it doesn't matter if $k$ is positive or negative, they converge to the same value. However, for the sake of completeness, let's first try to restrict $k$ to values between 0 and 1. So, I opened other sage session and did:
sage: N = var('N')
sage: k = var('k')
sage: assume(k>0,k<1)
sage: limit((6*N^k*(N-1)^(1-k))/((2*N-1)*(k+1)),N=oo)
But I got:
ValueError Traceback (most recent call last)
<ipython-input-4-bb63a0377d1b> in <module>()
----> 1 limit((Integer(6)*N**k*(N-Integer(1))**(Integer(1)-k))/((Integer(2)*N-Integer(1))*(k+Integer(1))),N=oo)
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in limit(ex, dir, taylor, algorithm, **argv)
1198 if algorithm == 'maxima':
1199 if dir is None:
-> 1200 l = maxima.sr_limit(ex, v, a)
1201 elif dir in ['plus', '+', 'right', 'above']:
1202 if dir == 'above':
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in sr_limit(self, expr, v, a, dir)
855 j = s.find('Is ')
856 s = s[j:]
--> 857 raise ValueError, "Computation failed since Maxima requested additional constraints; using the 'assume' command before limit evaluation *may* help (see `assume?` for more details)\n" + s
858 else:
859 raise error
ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before limit evaluation *may* help (see `assume?` for more details)
Is k an integer?
Trying to do `sage: assume(k,'real')` doesn't work, as I get the same error...how can I fix all this?
Thanks in advance!Mon, 15 Dec 2014 04:22:50 +0100https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/Answer by tmonteil for <div class="snippet"><p>Hi everyone,</p>
<p>I'm trying to evaluate the following limit in sage:</p>
<p>$$\lim_{N\to \infty}\frac{6N^k(N-1)^{1-k}}{(2N-1)(k+1)},$$</p>
<p>where $k\neq \pm1$. From <a href="http://www.wolframalpha.com/input/?i=limit+of+%286*N%5Ek*%28N-1%29%5E%281-k%29%29%2F%28%282*N-1%29*%28k%2B1%29%29+as+N+tends+to+infinity">Wolfram-Alpha I know this is equal to $3/(1+k)$</a>, but I was trying to get to that answer with sage with no progress. What I did to do it was the following:</p>
<pre><code>sage: N = var('N')
sage: k = var('k')
sage: assume(k!=1)
sage: assume(k!=-1)
sage: limit((6*N^k*(N-1)^(1-k))/((2*N-1)*(k+1)),N=oo)
</code></pre>
<p>But I get the following error:</p>
<pre><code>ValueError Traceback (most recent call last)
<ipython-input-7-bb63a0377d1b> in <module>()
----> 1 limit((Integer(6)*N**k*(N-Integer(1))**(Integer(1)-k))/((Integer(2)*N-Integer(1))*(k+Integer(1))),N=oo)
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in limit(ex, dir, taylor, algorithm, **argv)
1198 if algorithm == 'maxima':
1199 if dir is None:
-> 1200 l = maxima.sr_limit(ex, v, a)
1201 elif dir in ['plus', '+', 'right', 'above']:
1202 if dir == 'above':
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in sr_limit(self, expr, v, a, dir)
855 j = s.find('Is ')
856 s = s[j:]
--> 857 raise ValueError, "Computation failed since Maxima requested additional constraints; using the 'assume' command before limit evaluation *may* help (see `assume?` for more details)\n" + s
858 else:
859 raise error
ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before limit evaluation *may* help (see `assume?` for more details)
Is k-1.0 positive or negative?
</code></pre>
<p>In general it doesn't matter if $k$ is positive or negative, they converge to the same value. However, for the sake of completeness, let's first try to restrict $k$ to values between 0 and 1. So, I opened other sage session and did:</p>
<pre><code>sage: N = var('N')
sage: k = var('k')
sage: assume(k>0,k<1)
sage: limit((6*N^k*(N-1)^(1-k))/((2*N-1)*(k+1)),N=oo)
</code></pre>
<p>But I got:</p>
<pre><code>ValueError Traceback (most recent call last)
<ipython-input-4-bb63a0377d1b> in <module>()
----> 1 limit((Integer(6)*N**k*(N-Integer(1))**(Integer(1)-k))/((Integer(2)*N-Integer(1))*(k+Integer(1))),N=oo)
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in limit(ex, dir, taylor, algorithm, **argv)
1198 if algorithm == 'maxima':
1199 if dir is None:
-> 1200 l = maxima.sr_limit(ex, v, a)
1201 elif dir in ['plus', '+', 'right', 'above']:
1202 if dir == 'above':
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in sr_limit(self, expr, v, a, dir)
855 j = s.find('Is ')
856 s = s[j:]
--> 857 raise ValueError, "Computation failed since Maxima requested additional constraints; using the 'assume' command before limit evaluation *may* help (see `assume?` for more details)\n" + s
858 else:
859 raise error
ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before limit evaluation *may* help (see `assume?` for more details)
Is k an integer?
</code></pre>
<p>Trying to do <code>sage: assume(k ...</code><span class="expander"> <a>(more)</a></span></p></div> https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?answer=25276#post-id-25276Assuming that k is real is much weaker than assuming that k is an integer. Also it seems that you need to simplify the expression first to let the computation work:
sage: N = var('N')
sage: k = var('k')
sage: assume(k-1>0)
sage: assume(k, 'integer')
sage: E = (6*N^k*(N-1)^(1-k))/((2*N-1)*(k+1))
sage: limit(E.full_simplify(),N=oo)
3/(k + 1)
Mon, 15 Dec 2014 10:58:40 +0100https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?answer=25276#post-id-25276Comment by nespinoza for <p>Assuming that k is real is much weaker than assuming that k is an integer. Also it seems that you need to simplify the expression first to let the computation work:</p>
<pre><code>sage: N = var('N')
sage: k = var('k')
sage: assume(k-1>0)
sage: assume(k, 'integer')
sage: E = (6*N^k*(N-1)^(1-k))/((2*N-1)*(k+1))
sage: limit(E.full_simplify(),N=oo)
3/(k + 1)
</code></pre>
https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?comment=25283#post-id-25283Ok, solution works with new version, but still think that imposing $k$ to be an integer is too much...Mon, 15 Dec 2014 19:49:04 +0100https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?comment=25283#post-id-25283Comment by kcrisman for <p>Assuming that k is real is much weaker than assuming that k is an integer. Also it seems that you need to simplify the expression first to let the computation work:</p>
<pre><code>sage: N = var('N')
sage: k = var('k')
sage: assume(k-1>0)
sage: assume(k, 'integer')
sage: E = (6*N^k*(N-1)^(1-k))/((2*N-1)*(k+1))
sage: limit(E.full_simplify(),N=oo)
3/(k + 1)
</code></pre>
https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?comment=25279#post-id-25279Yeah, Maxima's assumptions are notoriously weak. We can of course report something upstream if you can confirm with the most recent Sage.Mon, 15 Dec 2014 16:46:29 +0100https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?comment=25279#post-id-25279Comment by nespinoza for <p>Assuming that k is real is much weaker than assuming that k is an integer. Also it seems that you need to simplify the expression first to let the computation work:</p>
<pre><code>sage: N = var('N')
sage: k = var('k')
sage: assume(k-1>0)
sage: assume(k, 'integer')
sage: E = (6*N^k*(N-1)^(1-k))/((2*N-1)*(k+1))
sage: limit(E.full_simplify(),N=oo)
3/(k + 1)
</code></pre>
https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?comment=25278#post-id-25278Hi @tmonteil; thanks for your anwer. I understand that assuming that k is real is much weaker than assuming that k is an integer, but, as I implicitly showed, I'm using this for non-integers inclusive.
Also, I'm using Sage Version 6.1.1 (Release Date: 2014-02-04) and this doesn't work; it gives me the same error I showed, and asks me: "Is k-1 positive, negative, or zero?" (which is strange since I already defined it to be positive).Mon, 15 Dec 2014 13:44:04 +0100https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?comment=25278#post-id-25278Comment by nespinoza for <p>Assuming that k is real is much weaker than assuming that k is an integer. Also it seems that you need to simplify the expression first to let the computation work:</p>
<pre><code>sage: N = var('N')
sage: k = var('k')
sage: assume(k-1>0)
sage: assume(k, 'integer')
sage: E = (6*N^k*(N-1)^(1-k))/((2*N-1)*(k+1))
sage: limit(E.full_simplify(),N=oo)
3/(k + 1)
</code></pre>
https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?comment=25282#post-id-25282I'm trying to update my Sage version to try this but it won't let me; do you know if there's something going on with the trac server? I try: sage -upgrade, and it gives me:
Upgrading to the latest development version
fatal: unable to connect to trac.sagemath.org:
trac.sagemath.org[0: 128.208.178.249]: errno=Connection refusedMon, 15 Dec 2014 17:28:16 +0100https://ask.sagemath.org/question/25273/problem-evaluating-limit-assume-doesnt-work/?comment=25282#post-id-25282