<s>[INST] 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)$?
 [/INST] 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.
</s>