Tools to help make a stepping equation with a delay on the x axis Context (Not important, feel free to skip ahead to the question):
I was interested (and thus started to investigate) in a vaccination proposition/question (https://youtu.be/M-jqf6i5OLc?t=990) regarding how long it would take to vaccinate people with the new AZ vaccine if we could only vaccinate 1 million per week and you had to wait 4 weeks until the second dose could be administered to the same patient. The following data denotes how long first doses take to be administered. Here's a fun/funny picture of my working out (nothing too complex, but cool to think about nonetheless)

*

*Choice A: (give 1 million doses per week and forget about second doses)

*Choice B: (give 1 million doses per week and then administer the second dose after 4 weeks)

*Logistical problem: Only 1 million doses can be given per week


Question:
Here's the aforementioned data:
| X (weeks) | Y (doses in millions) |
|-|-|-|
|0|0|
|1|1|
|2|2|
|3|3|
|4|4|
|5|4|
|6|4|
|7|4|
|8|4|
|9|5|
|10|6|
|11|7|
|12|8|
|13|8|
|14|8|
|15|8|
|16|8|
It draws the following graph:

What kind of tricks are there to creating equations for steps of this kind. You can imagine that the pattern continues on as it does.
 A: The most common (and in many ways, the most preferable) way to do this is with a piecewise-defined function. We can express it as
$$y = \begin{cases}x - 4k, &\quad 8k \le x < 8k + 4, k \in \Bbb Z\\
4k+4, &\quad 8k+4 \le x < 8k+8, k \in \Bbb Z\end{cases}$$
By introducing the greatest integer function ($\lfloor z \rfloor$ is the greatest integer $\le z$), we can replace $k$ with $\left\lfloor \frac x8\right\rfloor$ to get
$$y = \begin{cases}x - 4\left\lfloor \dfrac x8\right\rfloor, &\quad x - 8\left\lfloor \dfrac x8\right\rfloor <4\\4\left\lfloor \dfrac x8\right\rfloor+4, &\quad x - 8\left\lfloor \dfrac x8\right\rfloor \ge4\end{cases}$$
This particular function has some symmetries that allow a simpler expression. If you move $\frac x2$ outside the bracket, you get
$$y = \dfrac x2 + \begin{cases}\dfrac x2 - 4\left\lfloor \dfrac x8\right\rfloor, &\quad x - 8\left\lfloor \dfrac x8\right\rfloor <4\\4\left\lfloor \dfrac x8\right\rfloor+4-\dfrac x2, &\quad x - 8\left\lfloor \dfrac x8\right\rfloor \ge4\end{cases}$$
which can be modified to
$$y = \dfrac x2 + \begin{cases}\dfrac x2 - 4\left\lfloor \dfrac {x+4}8\right\rfloor, &\quad x - 8\left\lfloor \dfrac {x+4}8\right\rfloor > 0\\4\left\lfloor \dfrac {x+4}8\right\rfloor-\dfrac x2, &\quad x - 8\left\lfloor \dfrac {x+4}8\right\rfloor \le 0\end{cases}$$
Or just $$y = \dfrac x2 + \left|\dfrac x2 - 4\left\lfloor \dfrac {x+4}8\right\rfloor\right|$$
While the last looks cleaner, it is only because the "piecewise" part was hidden in a pre-defined piecewise function, the absolute value. In general it is possible to use absolute value expressions to convert any piecewise defined expression to a single formula. However, this is usually not advisable. When given such an absolute value expression, it will usually be quite long. And even for this short equation, it is not clear from looking at it how this function will behave. The piecewise versions are all easier to interpret, particularly the first, which is clearly rising at slope $1$ for the first half of an interval of length $8$, and constant for the second half.
The second version is more straightforward to compute, since computer languages always come with a greatest integer (a.k.a "floor") function, and the piecewise part can be programmed with an if statement.
