A common thing in programming, a good example being JavaScript, is using ternary if statements to assign values to a variable.
For example:
const speed = time === 0 ? undefined : (distance / time);
Often times you can shorten code such as
if (condition) {
f('test', 5);
} else {
f('test', 6);
}
to just
f('test', condition ? 5 : 6);
by moving the conditional inside the function.
This seems pretty similar to something I remember from learning Calculus in college where you could move a $\lim$ inside if $f$ was continuous at some point.
From https://math.stackexchange.com/a/1519038/761845:
if function $f$ is continuous at $g$ and $\lim\limits_{x\to x_0} g(x)=g$ then:
$$\lim_{x\to x_0}f(g(x))=f\left(\lim_{x\to x_0} g(x)\right)$$
Is this just coincidence that these are similar looking or are the same mathematics at work?
If so, what are those mathematics?
It looks similar but not the same. Consider the order of operations here: $$ \texttt{f("test"${}^1$, condition${}^2$ ?${}^3$ 5${}^4$ : 6${}^4$)${}^5$} $$ We will process the string "test" first, then calculate the condition then check if it is true or false, then process either 5 or 6 and then take the function $f$ of the calculated arguments. If you analyze what happens with
ifexample, the order of operations will be the same. So what you have is an equivalent syntax (syntax sugar if you want) rather than a commutation of operations (like limit and some functions). A proper mathematical example of this is the precedence of operations: $$ b×c+a = a+b×c $$ The syntactic order of the symbols is different, but due to the precedence of $\times$ and $+$, both mean exactly the same.