Performing additional calculation of the result of a function

16 Views Asked by At

Say I want to perform a division on result of a function and I want that to be a part of the function. How can I do it, here is an example:

$f(n)=\begin{cases} n+1 & n\equiv 1\pmod2 \\ 7n & n\equiv 0\pmod2 \end{cases}$

Now instead of dividing each case like this by four:

$f(n)=\begin{cases} (n+1)/4 & n\equiv 1\pmod2 \\ (7n)/4 & n\equiv 0\pmod2 \end{cases}$

In programming languages one can just do $n/4$ after the calculations instead of doing it inside each clause.

I know one could make another function $g(n)=n/4$. And then $g(f(n))$. But is this the only way to do it, or are we confined to divide by $4$ inside each case. Thanks.