For a given $n$, I would like to calculate a function $f_n$ recursively. Here is what I have:
(*for n=2 I have my functions already:*)
px2 = 1/2 (x3 (1 - x1) + x1 x2)
py2 = 1/2 (y2 (1 - y1) + y1 y3)
(*for n=3 I have:*)
px3 = px22[x3->2*px2]
py3 = py22[y3->2*py2]
(*for n=4 I have:*)
px4 = px222[x5->2*px3] (*increase the indexes of all variables in px2 function by 4 and insert 2*px3 wherever you see x5 in this new function*)
py4 = py222[y5->2*py3]
(*for n=5 I have:*)
px5 = px2222[x7->2*px4]
py5 = py2222[y7->2*py4]
etc.
so what is px22, px222 etc..? they are just px2 whose indexes are increased by the sum of the following 2s. For example:
px22=1/2 (x5 (1 - x3) + x3 x4)
px222=1/2 (x7 (1 - x5) + x5 x6)
etc.
Similarly,
py22 = 1/2 (y4 (1 - y3) + y3 y5)
py222 = 1/2 (y6 (1 - y5) + y5 y7)
py2222 = 1/2 (y8 (1 - y7) + y7 y9)
etc.
Example: for n=3
px3 = px22[x3->2*px2]
Since I know that
px22=1/2 (x5 (1 - x3) + x3 x4)
and
px2 = 1/2 (x3 (1 - x1) + x1 x2)
I just insert 2*px2 in px22, wherever I see x3 and I am done:
px22=1/2 (x5 (1 - ( (x3 (1 - x1) + x1 x2))) + ( (x3 (1 - x1) + x1 x2)) x4)
EDIT: I am trying to find the functions px3, px4..., py3, py4,... etc. using the given iterations in the question.
px2 and py2 functions are explicitly defined so they are already known. All the rest are unknown and can only be found iteratively. The main idea is to increase the indexes of all variables in px2 by two and then in this new function to put 2*px2 whereever I see the variable x3. So finally I get px3 but this function is now explicit. Namely it is (see above example):
px3[x1_,x2_,x3_,x4_,x5_]=1/2 (x5 (1 - ( (x3 (1 - x1) + x1 x2))) + ( (x3 (1 - x1) + x1 x2)) x4)
But before it was
px3 = px22[x3->2*px2]
I want mathematica to give me these explicit functions of px3,py3,px4,py4,.... which I can evaluate whenever x1,x2,x3,...are given.
How can Mathematica do this thing which I am doingy by hand automatically when I just give $n$?
Nest[ReplaceAll[x[k_] :> x[k + 2]], 1/2 (x[3] (1 - x[1]) + x[1] x[2]), 3]
for yourpx222
? $\endgroup$x3
withx[3]
in what I showed, because those are easier to manipulate. That can be converted intox3
, but it needs additional work. $\endgroup$