Find the generating function for sequence $1,2,4,0,8,24,120,184,312,56,568,1592,...$ I'm having trouble finding a generating function for the sequence that has a closed form. The sequence can be deduced using two powers, with alternating negative and multiples of three as shown:
first term:
$1=1$
second term:
$2=1+2^{0}$
third term:
$4=1+2^{0}+2^{1}$
fourth term:
$0=1+2^{0}+2^{1}-2^{2}$
...
n-th term:
$n = 1+2^{0}+2^{1}-2^{2}+2^{3}+2^{4}+3(2^{5})+2^{6}+2^{7}-2^{8}+...$
Therefore, the -1 appears at every $4(mod6)$ term and the 3 appears at every $1(mod6)$ term greater than 1. 
So I can construct the n-th ($n>1$) term as follows:
$f(n) = 1+\sum_{i=2}^{n}2^{i-2}u(i)$ 
where
$u(i)=-1$, if $i\equiv4(mod6)$
$u(i)=3$, if $i\equiv1(mod6)$
$u(i)=1$, otherwise
Is there a way to get a closed form of the function $f(n)$?
 A: $f(n)=2^{n-1}-2^{\lfloor\frac {n}6\rfloor+5}+2^{6\lfloor\frac {n+3}6\rfloor+2},$ which only works for $n\ge 7$.
A: Begin by finding the generating function for the sequence $2^0, 2^1, -2^2, 2^3, 2^4, 3 \cdot 2^5, 2^6, 2^7, -2^8, \dots$. This is the sum of 
\begin{align}
  \frac{1}{1-2x} &= 2^0 + 2^1x + 2^2x^2 + 2^3x^3 + 2^4x^4 + 2^5x^5 + \dots \\
-2\cdot\frac{(2x)^2}{1-(2x)^6} &= -2 \cdot 2^2x^2 - 2 \cdot 2^8x^8 - 2\cdot 2^{14}x^{14} - \dots \\
+2\cdot\frac{(2x)^5}{1-(2x)^6} &= 2 \cdot 2^5 x^5 + 2\cdot 2^{11}x^{11} + 2\cdot 2^{17}x^{17} + \dots.
\end{align}
Call this $g(x)$.
Then $1 + x \cdot g(x)$ will add the $1$ term at the beginning, which doesn't follow the pattern. Finally, multiplying by $\frac{1}{1-x}$ to get $$\frac{1+x \cdot g(x)}{1-x}$$ will give the generating function for this sequence's partial sums, which is what you want.
A: Here is an idea:$$
-2^2 = 2^2-2\times 2^2$$ and $$3\times 2^5 = 2^5 + 2 \times 2^5.$$
So, for $n \ge 7$, we can split your sum as
$$f(n) = 1 + \sum_{i=0}^{n-2}2^i - 2\sum_{i=0}^{\lfloor\frac{n-4}{6}\rfloor}2^{6i+2} + 2\sum_{i=0}^{\lfloor\frac{n-7}{6}\rfloor}2^{6i+5}.$$
The last piece should be a matter of calculating these simpler sums.
