# 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

edit retag 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))

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

Sort by » oldest newest most voted

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

more

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))
False
sage: bool(Sequence_rec(4) < Sequence_rec(3))
False
sage: bool(Sequence_rec(4) == Sequence_rec(3))
False

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

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

( 2013-05-31 01:04:01 -0500 )edit

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?


more

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

( 2013-05-31 05:26:45 -0500 )edit

## Stats

Seen: 504 times

Last updated: May 31 '13