TITLE: How many different sums of parts of a vector
QUESTION [8 upvotes]: The following mathematical puzzle was given to me by a friend a while ago and I can't work out how to solve it. Does anyone have any ideas?
For a given vector $v \in \{-1,1\}^n$ we consider the following $n$ sums. $$S_j=\sum_{i=0}^j v_i - \sum_{i=j+1}^{n-1} v_i \text{ for } 0 \leq j \leq n-1.$$
For example if $v = (-1,1,1)$ then $S=(-3,-1,1).$
Now let $T_j = 1$ if $S_j>0$ and $0$ otherwise. So for our example vector $v$ we have that $T=(0,0,1)$
Considered over all $2^n$ possible vectors $v$, the question is how many different possible vectors $T$ are there?
I think if $n=2$ the answer is $3$, if $n=3$ the answer is $8$, if $n=4$ the answer is $11$, if $n=5$, the answer is $22$ and if $n=6$ the answer is $31$.

Posted to https://mathoverflow.net/questions/212389/how-many-different-sums-of-parts-of-a-vector where a possible answer has been given in the comments.

REPLY [2 votes]: Let $w=\sum_i v_i$ be the weight of $v$. The vector $S$ can be interpreted as a walk from $(0,-w)$ to $(n,w)$ with steps $(1,\pm2)$, in which the start point is not recorded.
The $T$ vector records whether the $y$ coordinate of the path is positive or not.
For example, the following figure illustrates the path for $v=(+---+++-++--+)$ whose $T$ vector is $1000001011101$, which we abbreviate as $1[1511311]$, recording the first term and the lengths of the runs.
$\qquad\qquad\qquad\qquad\qquad\qquad$ 
If a path strays above $4$ or below $-3$, then there's another path with the same $T$ vector that doesn't (as illustrated by the dotted line in the figure), so we can restrict our analysis to vectors whose weight is in the interval $[-3,4]$.
For each of these weights, the possible sequences of numbers in the abbreviated form of the $T$ vector are as follows. We use $\textsf{e}$ to denote an even number, $\textsf{o}$ to denote an odd number, and $(\textsf{oo})^\star$ to denote a sequence of zero or more pairs of odd numbers.
$$
\begin{array}{llll}
  w = \phantom{-}4 : & 0[\textsf{e}(\textsf{oo})^\star \textsf{e}] \\[3pt]
  w = \phantom{-}3 : & 0[\textsf{o}(\textsf{oo})^\star \textsf{e}] \\[3pt]
  w = \phantom{-}2 : & 0[\textsf{o}(\textsf{oo})^\star \textsf{o}] \\[3pt]
  w = \phantom{-}1 : & 0[\textsf{e}(\textsf{oo})^\star \textsf{o}] & \quad\text{or}\quad 1[\textsf{oo}(\textsf{oo})^\star \textsf{o}] & \quad\text{or}\quad 1[\textsf{o}] \\[3pt]
  w = \phantom{-}0 : & 1[\textsf{o}(\textsf{oo})^\star \textsf{o}] & \quad\text{or}\quad 0[\textsf{eo}(\textsf{oo})^\star \textsf{o}] & \quad\text{or}\quad 0[\textsf{e}] \\[3pt]
  w =           -1 : & 1[\textsf{e}(\textsf{oo})^\star \textsf{o}] & \quad\text{or}\quad 0[\textsf{oo}(\textsf{oo})^\star \textsf{o}] & \quad\text{or}\quad 0[\textsf{o}] \\[3pt]
  w =           -2 : & 1[\textsf{e}(\textsf{oo})^\star \textsf{e}] & \quad\text{or}\quad 0[\textsf{oo}(\textsf{oo})^\star \textsf{e}] & \quad\text{or}\quad 0[\textsf{e}] \\[3pt]
  w =           -3 : & 1[\textsf{o}(\textsf{oo})^\star \textsf{e}] 
\end{array}
$$
These sets of $T$ vectors are disjoint except for the two identical terms in the last column.
To enumerate, we use generating functions, remembering that the numbers in the abbreviated forms represent runs in the $T$ vectors.
Let $s(z)=1/(1-z)$ and $r(z)=zs(z)$ be the generating functions for possibly empty sequences and nonempty runs respectively. Then $e(z)=r(z^2)$ and 
$o(z)=zs(z^2)$ are the generating functions for nonempty even and odd length runs respectively.
The generating function for the number of distinct $T$ vectors is thus
$$
2r(z)^2s(o(z)^2) \:+\: 2r(z)o(z)^2s(o(z)^2) \:+\: r(z)+o(z)
\;=\;
\frac{2z+3z^2-z^4-2z^5-z^6}{1-4z^2+4z^4-z^6}
,
$$
where the first two summands come from the first and second columns in the table, noting that $e(z)+o(z)=r(z)$. 
This generating function is the same as that ‘guessed’ by Jay Pantone on MathOverflow.
Extracting coefficients gives the number of distinct $T$ vectors of length $n$; one way of expressing this is
$$
t_n \;=\; \left\{
            \begin{array}{ll}
              4f_n  - 1, & n\;\text{even}, \\[3pt]
              2f_n + 4f_{n-1}, & n\;\text{odd},
            \end{array}
          \right.
$$
where $f_n$ is the $n$th Fibonacci number ($f_0=0$, $f_1=1$).