Using If without if Say you have a broken if function ( in any language), and it doesn't work. Is there a mathematical formula you can input in that language that avoids using if. 
For example, 'Collatz Conjecture'

You need a script that says: '   If  <$ x mod 2 = 0$>  then $x = x/2$ else $x = 3x+1$    '

This would then be $f(x)=(\frac{x}2)((x+1)mod2)+(3x+1)(xmod2))$
But what about for more complex examples?
Like:


*

*for higher level of $n$ for $x mod n$?

*for scripts with three conditions to be met?

*for logical (AND, OR, NOT, XNOR, NAND) etc.  expressions?

*for irrational expressions?


How would I express this in a function $f(x)$? 
(Note that you also cannot use logical functions such as XNOR, AND, NAND, NOT etc. )
 A: Assuming your conditioned formulas won't throw an error if the condition doesn't hold (or does hold, for the else branch), as is the case for the formulas you cited if you are not going to overflow on the $3x$, then the following works:
$$(x\bmod 2)\cdot(3x+1) + (1-(x\bmod2))\cdot(x/2)$$
This is because if $x\bmod 2$ is not $0$, it is $1$.
In general, the trick is to find an expression that gives $1$ if the expression holds and $0$ otherwise. Note that as soon as you have $0$ and $1$ as logical values for subexpressions, you can do logical operations using arithmetics (note I'm using the Iverson bracket here, which gives $1$ if the expression in the brackets is true, and $0$ otherwise):
\begin{align}
[a \land b] &= [a][b]\\
[a \lor b] &= [a] + [b] - [a][b]\\
[\lnot a] &= 1-[a]
\end{align}
Then you simply multiply the then branch with $[condition]$ and the else branch with $[\lnot condition]$. If your function would throw an error if the branch is not taken, you also have to conditionally amend it so it doesn't in that case.
For example, take the function
$$f(x) = \begin{cases}
\frac{\sin x}{x} & x\ne 0\\
1 & x=0
\end{cases}$$
The first issue is to formulate a function that is $0$ if $x=0$ and $1$ otherwise. Well, we can do this combining the ceiling function with the absolute value function (two functions that are commonly provided by computer languages):
$$[x\ne 0] = \left\lceil\frac{\left|x\right|}{\left|x\right|+1}\right\rceil$$
This works as follows:


*

*If $x=0$, then the expression inside $\lceil\cdot\rceil$ is $0$ and therefore the ceiling function doesn't change it.

*Otherwise, the expression is a positive real number below $1$, which the ceiling function maps to $1$.
Note that this formula can also be used to implement other common conditions, e.g. $[a\ne b]$ (as $[a-b\ne0]$) or $[x>0]$ (as $[x+|x|\ne 0]$).
So now that you have an explicit formula for $[x\ne 0]$, you can use that to formulate the condition.However the naive approach
$$f(x)=[x=0]+[x\ne 0]\cdot \frac{\sin x}{x}$$
has the problem that it gives a division by zero for $x=0$; this is not what you want. However since in that case the result of the expression is thrown away anyway, you can just modify it in only that case. One possibility would be:
$$f(x) = [x=0] + [x\ne 0]\frac{\sin x}{x+[x=0]}$$
Where of course $[x=0] = [\lnot x\ne 0] = 1-[x\ne 0]$ and $[x\ne 0]$ is given by the formula above.
