Ask Your Question

Compare elements of a recursive defined sequence

asked 2013-05-29 04:02:26 -0500

KurtM gravatar image

updated 2014-03-30 09:13:45 -0500

tmonteil gravatar image

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(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:

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!


edit retag flag offensive close merge delete


Thanks 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))

KurtM gravatar imageKurtM ( 2013-05-30 21:12:39 -0500 )edit

3 answers

Sort by » oldest newest most voted

answered 2013-05-29 05:32:32 -0500

tmonteil gravatar image

updated 2013-05-29 05:55:23 -0500

The 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)

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.

edit flag offensive delete link more

answered 2013-05-30 21:51:45 -0500

If 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))
sage: bool(Sequence_rec(4) < Sequence_rec(3))
sage: bool(Sequence_rec(4) == Sequence_rec(3))
edit flag offensive delete link more


Thank 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".

KurtM gravatar imageKurtM ( 2013-05-30 22:04:28 -0500 )edit

There 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.

vdelecroix gravatar imagevdelecroix ( 2013-05-31 01:04:01 -0500 )edit

answered 2013-05-31 01:11:36 -0500

tmonteil gravatar image

More 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 for more information about this, which was unfortunately rejected, preventing Sage to deal with "proved True", "proved False", "Unable to prove".

edit flag offensive delete link more


Actually, I would prefer an even better alternative for trueness of an expression: either True, or False here is a counterexample or Unknown.

vdelecroix gravatar imagevdelecroix ( 2013-05-31 05:26:45 -0500 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2013-05-29 04:02:26 -0500

Seen: 433 times

Last updated: May 31 '13