I am trying to solve a problem from the IPSC http://ipsc.ksp.sk/2001/real/problems/f.html It basically asks to compute the following recursion.
P(x) = 1 for 0<=x<4
P(x) = P(x-1) + P(x-pi) for 4<=x,
where pi = 3.1415926535... In this problem, you are asked to compute P(x) for a given x.
How to reach to a formula in this case.Maybe some how matrix exponentiation can be used?
@John no P(4-pi) is defined as 1 in the task description. You misunderstood the question. @user103260 4 different approaches:
Characteristic polynomial: x^n = x^(n-1) + x^(n-pi). Since the solution of the equation does not depend on n you could store the solution for the function up to some precision. Then follow the normal procedure to compute your solution, based on the two roots you will find.
An other way would be to consider the terms separately. Basically you have two sequences, one operates on the natural numbers and one operates on the numbers, shifted by pi. But you will never end up with something like sqrt(2) (Assuming x is a natural number). Define the remaining term of pi, when you subtract 3 as p = pi - 3 = 0.141... You can start writing down the first values as:
$$ P(4) = P(3) + P(4-\pi) = 1 + 1 = 2 \\ P(5-p) = P(4-p) + P(5-p-\pi) = 2\\ P(5) = P(4) + P(5-\pi) = P(4) + 1 = 3 \\ P(6-p) = P(5-p) + P(6-p-\pi) = P(5-p) + P(6-\pi+3-\pi) = 3 $$
But since you do only get linear combinations of p and pi you will never end up with something crazy. Therefore it might be worthwhile to try dynamic programming. I will also edit this post, if I come up with something clever :)
While you are waiting for other answers, could you maybe just compute the first 10 numbers and show them?