ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 31 May 2013 05:26:45 -0500Compare elements of a recursive defined sequencehttp://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/I define the recursive sequence as:
A, b, c = var('A, b, c')
def Sequence_rec(k):
x = 0
for i in range(1,k+1):
x = x + (A - x)/((c-i+2)^b)
return x
For the parameters the assumptions are:
assume(A>0,c>0,b>0)
assume(c, 'integer')
I'm interested in the elements of Sequence_rec(k) with k<=c. The following relation has to be true for the defined sequence considering the given assumptions:
assume(c>2)
bool(Sequence_rec(4) > Sequence_rec(3))
But Sage computes it is false! The following plot shows the difference is positive:
plot((Sequence_rec(4) - Sequence_rec(3))(A=1,c=3),b,(0,100))
How can I force Sage to compare the elements of the sequence `bool(Sequence_rec(n+1) > Sequence_rec(n)) = true` for any positive integer n correctly? Thank you for your advice!
Kurt
Wed, 29 May 2013 04:02:26 -0500http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/Comment by KurtM for <p>I define the recursive sequence as:</p>
<pre><code>A, b, c = var('A, b, c')
def Sequence_rec(k):
x = 0
for i in range(1,k+1):
x = x + (A - x)/((c-i+2)^b)
return x
</code></pre>
<p>For the parameters the assumptions are:</p>
<pre><code>assume(A>0,c>0,b>0)
assume(c, 'integer')
</code></pre>
<p>I'm interested in the elements of Sequence_rec(k) with k<=c. The following relation has to be true for the defined sequence considering the given assumptions:</p>
<pre><code>assume(c>2)
bool(Sequence_rec(4) > Sequence_rec(3))
</code></pre>
<p>But Sage computes it is false! The following plot shows the difference is positive:</p>
<pre><code>plot((Sequence_rec(4) - Sequence_rec(3))(A=1,c=3),b,(0,100))
</code></pre>
<p>How can I force Sage to compare the elements of the sequence <code>bool(Sequence_rec(n+1) > Sequence_rec(n)) = true</code> for any positive integer n correctly? Thank you for your advice! </p>
<p>Kurt</p>
http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?comment=17610#post-id-17610Thanks for your reply. I forgot to mention that c and k are defined as integers and k<=c. In this case it must be Sequence_rec(n+1) > Sequence_rec(n). I use the elements of the sequence for further calculations. What is the reason Sage is not able to compare symbolic expressions: bool(Sequence_rec(3) > Sequence_rec(2))? It works for: bool(Sequence_rec(2) > Sequence_rec(1))Thu, 30 May 2013 21:12:39 -0500http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?comment=17610#post-id-17610Answer by tmonteil for <p>I define the recursive sequence as:</p>
<pre><code>A, b, c = var('A, b, c')
def Sequence_rec(k):
x = 0
for i in range(1,k+1):
x = x + (A - x)/((c-i+2)^b)
return x
</code></pre>
<p>For the parameters the assumptions are:</p>
<pre><code>assume(A>0,c>0,b>0)
assume(c, 'integer')
</code></pre>
<p>I'm interested in the elements of Sequence_rec(k) with k<=c. The following relation has to be true for the defined sequence considering the given assumptions:</p>
<pre><code>assume(c>2)
bool(Sequence_rec(4) > Sequence_rec(3))
</code></pre>
<p>But Sage computes it is false! The following plot shows the difference is positive:</p>
<pre><code>plot((Sequence_rec(4) - Sequence_rec(3))(A=1,c=3),b,(0,100))
</code></pre>
<p>How can I force Sage to compare the elements of the sequence <code>bool(Sequence_rec(n+1) > Sequence_rec(n)) = true</code> for any positive integer n correctly? Thank you for your advice! </p>
<p>Kurt</p>
http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?answer=14984#post-id-14984The simple reason is that your conjecture is False. Try with:
A = 1
b = 2
c = 1/2
All those numbers are strictly positive, but you will get:
sage: Sequence_rec(3) - Sequence_rec(2)
-20/3
Note also that the denominator can vanish along the loop when ``i=c+2``, which may be another cause of trouble (you will have a lot of poles). By the way, even if the sequence was indeed increasing, Sage will not be able to give an answer for all `n` together (it does not understands loops symbolically). Moreover, you could even imagine to encode undecidable problems in the iteration of such formulas.
Wed, 29 May 2013 05:32:32 -0500http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?answer=14984#post-id-14984Answer by vdelecroix for <p>I define the recursive sequence as:</p>
<pre><code>A, b, c = var('A, b, c')
def Sequence_rec(k):
x = 0
for i in range(1,k+1):
x = x + (A - x)/((c-i+2)^b)
return x
</code></pre>
<p>For the parameters the assumptions are:</p>
<pre><code>assume(A>0,c>0,b>0)
assume(c, 'integer')
</code></pre>
<p>I'm interested in the elements of Sequence_rec(k) with k<=c. The following relation has to be true for the defined sequence considering the given assumptions:</p>
<pre><code>assume(c>2)
bool(Sequence_rec(4) > Sequence_rec(3))
</code></pre>
<p>But Sage computes it is false! The following plot shows the difference is positive:</p>
<pre><code>plot((Sequence_rec(4) - Sequence_rec(3))(A=1,c=3),b,(0,100))
</code></pre>
<p>How can I force Sage to compare the elements of the sequence <code>bool(Sequence_rec(n+1) > Sequence_rec(n)) = true</code> for any positive integer n correctly? Thank you for your advice! </p>
<p>Kurt</p>
http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?answer=14994#post-id-14994If you expect an answer you should tell Sage what are your assumptions (ie in the case you mention `assume(c > 2)`). Nevertheless, assuming your intution is correct, you can not rely on the output of `bool(my_expression)` as
sage: assume(c > 3)
sage: bool(Sequence_rec(4) > Sequence_rec(3))
False
sage: bool(Sequence_rec(4) < Sequence_rec(3))
False
sage: bool(Sequence_rec(4) == Sequence_rec(3))
False
Thu, 30 May 2013 21:51:45 -0500http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?answer=14994#post-id-14994Comment by KurtM for <p>If you expect an answer you should tell Sage what are your assumptions (ie in the case you mention <code>assume(c > 2)</code>). Nevertheless, assuming your intution is correct, you can not rely on the output of <code>bool(my_expression)</code> as</p>
<pre><code>sage: assume(c > 3)
sage: bool(Sequence_rec(4) > Sequence_rec(3))
False
sage: bool(Sequence_rec(4) < Sequence_rec(3))
False
sage: bool(Sequence_rec(4) == Sequence_rec(3))
False
</code></pre>
http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?comment=17609#post-id-17609Thank you. As far as I know, the command bool(my_expression) evaluates the relation of the symbolic expressions. In this case I do not understand why it is not evaluated according to my "intuition".Thu, 30 May 2013 22:04:28 -0500http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?comment=17609#post-id-17609Comment by vdelecroix for <p>If you expect an answer you should tell Sage what are your assumptions (ie in the case you mention <code>assume(c > 2)</code>). Nevertheless, assuming your intution is correct, you can not rely on the output of <code>bool(my_expression)</code> as</p>
<pre><code>sage: assume(c > 3)
sage: bool(Sequence_rec(4) > Sequence_rec(3))
False
sage: bool(Sequence_rec(4) < Sequence_rec(3))
False
sage: bool(Sequence_rec(4) == Sequence_rec(3))
False
</code></pre>
http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?comment=17605#post-id-17605There is no general algorithm to answer the question "f(x) > 0 ?". In your particular case, everything is polynomial so you can do something but not with symbolic expressions.Fri, 31 May 2013 01:04:01 -0500http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?comment=17605#post-id-17605Answer by tmonteil for <p>I define the recursive sequence as:</p>
<pre><code>A, b, c = var('A, b, c')
def Sequence_rec(k):
x = 0
for i in range(1,k+1):
x = x + (A - x)/((c-i+2)^b)
return x
</code></pre>
<p>For the parameters the assumptions are:</p>
<pre><code>assume(A>0,c>0,b>0)
assume(c, 'integer')
</code></pre>
<p>I'm interested in the elements of Sequence_rec(k) with k<=c. The following relation has to be true for the defined sequence considering the given assumptions:</p>
<pre><code>assume(c>2)
bool(Sequence_rec(4) > Sequence_rec(3))
</code></pre>
<p>But Sage computes it is false! The following plot shows the difference is positive:</p>
<pre><code>plot((Sequence_rec(4) - Sequence_rec(3))(A=1,c=3),b,(0,100))
</code></pre>
<p>How can I force Sage to compare the elements of the sequence <code>bool(Sequence_rec(n+1) > Sequence_rec(n)) = true</code> for any positive integer n correctly? Thank you for your advice! </p>
<p>Kurt</p>
http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?answer=14995#post-id-14995More generally, if you ask for a boolean, you should know that Sage is not able to answer `Unknown`, hence it will usually answer `False` when it is not able to prove that answer is `True`, which is not what mathematicians usually expect.
Actually, there exists an `Unknown` truth value in Sage but then python will not be able to deal correctly with boolean operations, see
sage: Unknown?
and [PEP 335](http://www.python.org/dev/peps/pep-0335/) for more information about this, which was unfortunately rejected, preventing Sage to deal with "proved True", "proved False", "Unable to prove".
Fri, 31 May 2013 01:11:36 -0500http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?answer=14995#post-id-14995Comment by vdelecroix for <p>More generally, if you ask for a boolean, you should know that Sage is not able to answer <code>Unknown</code>, hence it will usually answer <code>False</code> when it is not able to prove that answer is <code>True</code>, which is not what mathematicians usually expect.</p>
<p>Actually, there exists an <code>Unknown</code> truth value in Sage but then python will not be able to deal correctly with boolean operations, see</p>
<pre><code>sage: Unknown?
</code></pre>
<p>and <a href="http://www.python.org/dev/peps/pep-0335/">PEP 335</a> for more information about this, which was unfortunately rejected, preventing Sage to deal with "proved True", "proved False", "Unable to prove".</p>
http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?comment=17594#post-id-17594Actually, I would prefer an even better alternative for trueness of an expression: either True, or False here is a counterexample or Unknown.Fri, 31 May 2013 05:26:45 -0500http://ask.sagemath.org/question/10163/compare-elements-of-a-recursive-defined-sequence/?comment=17594#post-id-17594