Looking for an approach to mathematical notation wherein the universe is divided into disjoint worlds. Is there a rigorous approach to mathematical notation wherein the "universe" is divided into disjoint "worlds," and the meaning of notation is world-dependent? This would solve a few pesky problems. Ultimately, I'm not looking for a hand-waivy solution, but rather something that is near computer readable.
Here's three examples of pesky issues I'd like solved in a rigorous manner. Note that many of the following issues only arise if we use a set-theoretic foundations, because in such a foundations everything is a set. However, I believe that similar issues would arise in any foundations.


*

*If $f$ and $g$ are functions mapping $X \rightarrow Y$ and $*$ is a binary operation on $Y$, I would want $f * g$ to equal $x \mapsto f(x)*g(x)$. So for example, the expression $f \cup g$ should equal $x \mapsto f(x) \cup g(x)$. Of course, if $f$ and $g$ are viewed as sets of ordered pairs, then $f \cup g$ already has a meaning, so we get a conflict. This conflict goes away if we view functions as existing in a different "world" to sets, so that the same notation can mean different things.

*If $X$ and $Y$ are random variables, I would want $(X,Y)$ to denote the random variable $\omega \mapsto (X(\omega),Y(\omega))$. However, $(X,Y)$ already has a meaning (its an ordered pair), and thus we get a conflict. One possible solution would be to view $X$ and $Y$ as belonging to a world where $(*,*)$ is defined differently to normal.

*It is common to write $f(X)$ as shorthand for $\{f(x)\,|\,x \in X\}$. However, if natural numbers are constructed in the manner of Von Neumann, then for example $2 = \{0,1\}$, thus $f(2)=\{f(x) \,|\,x \in 2\}=\{f(x) \,|\,x \in \{0,1\}\}=\{f(0),f(1)\}$, which is probably not what the writer meant by $f(2)$. To avoid this, natural numbers should be viewed as living in a world that is disjoint from the world of sets (that is, a natural number should not be identified with its Von Neumann encoding).


So to reiterate, I'm looking for an approach to mathematical notation wherein the universe is divided into disjoint worlds and notation is world-dependent.
EDIT: Caveman in his answer suggests that the simply-typed lambda calculus solves the problem. If anyone knows of a gentle introduction to this field, please leave a comment.
 A: All three questions are purely about the conventions of mathematical notation; there is no need for creative mathematical metaphysics to resolve them. The first two examples you give show that it is not generally possible to extend notation in any way that one might find convenient, without bumping into already established conflicting interpretations. The solution is usually just to modify the notation so that confusion does not arise. Alternatively (and questionably) the old notation can be used anyway, and the reader specifically warned that it is not to be understood by its prior undesired interpretation. The third example points out an established abuse of notation that is already problematic. However, the abuse is so entrenched that anyone who introduced a new notational device to avoid the conflict would be regarded as pedantic, unless the mathematical context was one where both the set $X$ and its elements were in the domain of the function. 
A: This might not be what you're looking for, but one idea is to have each axiomatic system formalized in black be its own "world". Then you can have a very bland, formal algebra in red that operates over all the black objects, where x=y iff the axiomatic system guaranteeing x is the axiomatic system guaranteeing y, and x=y in that system. I think you can build considerably from there though. The "axiomatic systems formalized in black" could be different branches of known math, instead of pure abstractum, allowing you to get rid of the two-color thing for your purposes.
A: Higher-order functions might be useful here. Let $\DeclareMathOperator{\merge}{\mathbin{\&}}$
$$ \mathsf{fork} : (a \rightarrow b_1, a \rightarrow b_2) \rightarrow a \rightarrow (b_1, b_2) $$
$$ \mathsf{fork} \; (f, g) \; x = (f \; x, g \; x) $$
Your second example is $\mathsf{fork} \; (f, g)$. Your first example is $\cup \circ \mathsf{fork} \; (X, Y)$.
For your third example, use either the bracket notation $f[X]$ or the star notation $f_*(X)$.

If you want something even more general, you can use the flip operator
$$ \mathsf{flip} : (n \rightarrow a \rightarrow b) \rightarrow (a \rightarrow n \rightarrow b) $$
$$ \mathsf{flip} \; x \; y \; z = x \; z \; y $$
By seeing a length-$n$ tuple of elements of $b$ as a function $n \rightarrow b$, you get
\begin{align}
    \mathsf{flip} \; (f_1, f_2, f_3, \dots) \; x
    &= (f_1 \; x, f_2 \; x, f_3 \; x, \dots)
\end{align}
