TITLE: Calculate the triangle index of the parent triangle.
QUESTION [7 upvotes]: I am not a mathematician so I try to explain the topic with an image.
Given is a subdivided triangle. I count the smallest triangles using an index starting at 1. I need a formula that calculates the index of the parent triangle.$$pindex = f(index)$$

$$f(1) = 1$$
$$f(2) = 1$$
$$f(3) = 1$$
$$f(4) = 1$$
$$f(5) = 2$$
$$f(6) = 3$$
This leads to the following integer sequence:
$$1,1,1,1,2,3,3,3,4,2,2,2,3,4,4,4,5,6,6,6,..$$
I did not find a formula at OEIS for this sequence. I am also curious about how to improve my question that it is more clear.
Update
Let's call the horizontal alignment of triangles a row. I can calculate the row index by the triangle index using this formula A000196:
$$r(i) = round(1 + 0.5 * (-3 + sqrt(i) + sqrt(1 + i)))$$
Let's call the offset of a triangle in a row the row offset. I can calculate this offset by the triangle index using this formula A071797:
$$o(i) =i - (floor(sqrt(i))^2$$
I have got the row and the offset in this row for triangle indices. I think I am close to a solution with this. Any ideas?

REPLY [2 votes]: We'll index starting with $0$, because everything's simpler that way. Note that any non-negative integer $n$ can be expressed thusly

$$n = 4 a^2 + 4 b + c \tag{$\star$}$$
  with integers $a$, $b$, $c$ such that
  $$0 \leq b \leq 2 a \quad\text{and}\quad 0 \leq c < 4$$

Simply take 
$$c := ( n \operatorname{mod} 4 ) \qquad a := \left\lfloor \;\frac12 \sqrt{n-c}\;\right\rfloor \qquad b := \frac14\left(n - 4 a^2 - c \right)$$
Now, we can represent each $n$ in the target figure with $a$, $b$, $c$ "coordinates". 

Here, "$a$" represents a particular pair of rows of numbers $n$ (or a single row of "parent triangles" $p$); "$b, c$" read left-to-right, with $c$ incrementing from $0$ to $3$, then "rolling over" to increment $b$. (In the diagram, the colors identify various $b$ blocks.) Importantly, $a^2$ is the number of parent triangles above row $a$; consequently, determining the index of a particular parent triangle reduces to studying $b$ and $c$ within an $a$ block.
The key observation from the coordinatized figure is that instances where $c = 0$ correspond to (upward- or downward-pointing) "tips" of the parent triangles. We see that

For upward-pointing tips, the parent triangle index (within the $a$ block) for $n$ is simply $2b$; for downward-pointing tips, the index is $2(b-a)-1$.
For "non-tip" $n$ (that is, when $c\neq 0$) in the upper row of an $a$ block, the parent index is $2b+1$; in the lower row, it's $2(b-a)$. 

After a while of staring and fiddling, the following formula emerges:

$$\text{parent triangle index} = a^2 + \left(\; 2 b + \operatorname{bool}\left(\;c \neq 0\;\right)\mod (2a+1)\;\right) \tag{$\star\star$}$$

where "$\operatorname{bool}(x)$" evaluates to $1$ or $0$, according as $x$ is true or false. (It's a little bit of a cheat, as it isn't "calculated" from $n$. I'll leave it as an exercise to the reader to algebraize that aspect of the formula.) 
The "mod $(2a+1)$" complication accommodates the pesky $b$ block that "wraps around" from the top row to the bottom of an $a$ block.
Let's sanity-check the formula:

In the top row of an $a$ block, excluding the wrap-around $b$ block, we have $b < a$, so that the $2a+1$ modding has no effect and $(\star\star)$ reduces to $$a^2 + 2 b + \operatorname{bool(\;c\neq 0\;)}$$ which is consistent with the "tip" and "non-tip" observations made above.
In the bottom row of an $a$ block, excluding the wrap-around $b$ block, we have $a < b \leq 2a$, so that $0 \leq 2(b - a)-1 \leq 2a-1$. Our "tip/non-tip" discussion tells us to expect a parent index of
$$a^2 + 2(b-a) - 1 + \operatorname{bool}(\;c\neq 0\;)$$ Since the expression after the $a^2$ never exceeds $2a$, modding by $2a+1$, again, has no effect. Moreover, adding $2a+1$ to the modded quantity has no effect, except to reduce the above to the form of $(\star\star)$.
In the wrap-around block, $a = b$. For $c = 0$ (the final $n$ in the top row), we expect a parent index offset from $a^2$ by $2 b$ (that is, $2a$); otherwise, the offset should be $0$. The bottom row formula in the previous bullet covers the latter case, but gives an offset of $-1$ for the former case. Here, though, adding $2a+1$ is more than a formality; it changes the $-1$ offset to $2a$, which we want, while not affecting the $0$ offset when it occurs. So, $(\star\star)$ is, once more, our result.