A mathematical function for counting forwards then backwards Is there a mathematical function for counting forwards then backwards though a number range. e.g.

Range of 0-10

The number 7 would equal 7

The number 11 would equal 9

The number 23 would equal 3

So the numbers are counting all the way to the upper limit then counting back down and then back up again and so on.

I come across this requirement a lot in programming and was wondering if there was a typical math formula/function for calculating this?
Yes, just use the cyclic group by first building a representation matrix of its generating element : a circulant matrix

$${\bf C} = \left[\begin{array}{cccccc}0&amp;1&amp;0&amp;0&amp;0&amp;0\\0&amp;0&amp;1&amp;0&amp;0&amp;0\\0&amp;0&amp;0&amp;1&amp;0&amp;0\\0&amp;0&amp;0&amp;0&amp;1&amp;0\\0&amp;0&amp;0&amp;0&amp;0&amp;1\\1&amp;
0&amp;0&amp;0&amp;0&amp;0\end{array}\right]$$

Now let first number be represented by ${\bf v} = [1,0,0,0,0,0]^T$. Then next number is $\bf Cv$, third number is ${\bf C}^2 \bf v$ and so on. Finally assign the value for each position to a column vector $w$. For your example you will want $w_1 = w_N$, $w_2 = w_{N-1}$ and so on, and the value of number at position $k$ of your sequence will be the scalar product:

$${\bf w}^T {\bf C}^k {\bf v}$$

It will be more general than sines and arcsines as you can prescribe any sequence of numbers in $\bf w$.

An example of ${\bf w} = [1,2,3,3,2,1]^T$ will give 1,2,3,3,2,1 in that order if you increase $k=0,1,2,3,4,5$, so you can explicitly enter the numbers you want to have in the sequence into the vector.

If you want to be even fancier/advanced you can construct ${\bf w}^T$ using the following:

$${\bf w}^T = [1,2,3]\left[\begin{array}{cccccc}1&amp;0&amp;0&amp;0&amp;0&amp;1\\0&amp;1&amp;0&amp;0&amp;1&amp;0\\0&amp;0&amp;1&amp;1&amp;0&amp;0\end{array}\right]$$

In general the matrix will be an identity followed by a "opposite diagonal" matrix filled with ones.
The parent function of your function is a triangle wave. Indeed, we have

$$P(x) = \frac{2a}\pi \arcsin\big(\sin\big(\frac{2 \pi}p x\big) \big)$$

So let $a = 10$ and $p = 40$, then take the absolute value to get your function:

$$f(x) = \Big|\frac{20}\pi \arcsin\big(\sin\big(\frac{\pi}{20} x\big) \big)\Big|$$ where $|x|$ is the absolute value of $x$.