# Recurrence formula evaluating with speacial counting of subscripts

Hoping to check some recurrance relationship like this

$$a_1 = x$$ and $$a_2 = y$$, with

$$a_{2n+1} = a_{2n} a_{2n-1}$$

and

$$a_{2n+2} = a_{2n+1} + 4$$

Tried

a[1] = x;
a[2] = y;
a[2*n + 1] := a[2*n]*a[2*n - 1];
a[2*n + 2] := a[2*n + 1] + 4
Table[a[n],{n,1,10}]


and

RecurrenceTable[
{a[2 n + 1] == a[2 n]*a[2 n - 1],
a[2 n + 2] == a[2 n + 1] + 4,
a[1] == x,
a[2] == y
},
a, {n, 1, 10}]


Neither works. How should I deal with the sub-index problem? Or am I defining it wrong?

I just hope to get the same result as

a[1] = x;
a[2] = y;
Do[
a[2*n + 1] = a[2*n]*a[2*n - 1];
a[2*n + 2] = a[2*n + 1] + 4;,
{n, 1, 10}
]
Table[a[n] // Expand, {n, 1, 10}]


{x, y, x y, 4 + x y, 4 x y + x^2 y^2, 4 + 4 x y + x^2 y^2, 16 x y + 20 x^2 y^2 + 8 x^3 y^3 + x^4 y^4, 4 + 16 x y + 20 x^2 y^2 + 8 x^3 y^3 + x^4 y^4, 64 x y + 336 x^2 y^2 + 672 x^3 y^3 + 660 x^4 y^4 + 352 x^5 y^5 + 104 x^6 y^6 + 16 x^7 y^7 + x^8 y^8, 4 + 64 x y + 336 x^2 y^2 + 672 x^3 y^3 + 660 x^4 y^4 + 352 x^5 y^5 + 104 x^6 y^6 + 16 x^7 y^7 + x^8 y^8}

• Method-1
Clear["Global*"];
a[1] = x;
a[2] = y;
a[n_?OddQ] := a[n - 1] a[n - 2];
a[n_?EvenQ] := a[n - 1] + 4;
Table[a[i], {i, 1, 10}]//Expand

• Method-2:

Since the initial condition a[2]==y,a[1]==x may not satisfies the recurrence condition a[2n+2]==a[2n+1]+4, so we have to ignore a[1] and start from a[2]==y. That is if we set a[2n+1] be α[n] and set a[2n] be β[n], then the result should be {x,β[1],α[1],β[2],α[2],β[3],α[3],...},RecurrenceTable work now.

Clear["Global*"];
s = RecurrenceTable[{α[
n] == β[n]*α[n - 1], β[
n + 1] == α[n] + 4, α[1] == x*y, β[1] ==
y}, {β[n], α[n]}, {n, 1, 4}] // Flatten // Expand
Join[{x}, s]