Extension of metric definition to two sets The standard definition of a metric, is a function $d: X\times X \to \mathbb{R}$. 
What is a sensible/common extension of a metric/pseudometric to $\tilde d: X\times Y \to \mathbb{R}$, i.e. distance between elements of different sets? 
 A: This was a fun question to play around with. If $f_X:X\to Z$ and $f_Y:Y\to Z$ are functions, then you could define the "metric" $d:X\times Y\to\mathbb{R}$ by:
$$d(x,y) = d_Z(f_X(x),f_Y(y))$$
for any metric $d_Z:Z\times Z\to\mathbb{R}$. Then, as $d_Z$ is a metric, we have for all $x\in X$ and $y,z\in Z$:


*

*$d(x,y) = d_Z(f_X(x),f_Y(y))\geq 0.$

*Note that $d(x,y)=0$ is equivalent to $d_Z(f_X(x),f_Y(y))=0$ which is equivalent to $f_X(x)=f_Y(y)$.   


It's slightly more difficult to create an analogous triangle inequality, since what you want is: $d(x,z)\leq d(x,y)+d(y,z)$, but what is $d(y,z)$? This is a problem since we are giving the $X$ argument a $Y$ value. Maybe you could require:
$$d(x,z)\leq d(x,y)+d(x',z),$$
where $x'\in X$ is any element such that $f_X(x')=f_Y(y)$. Since this needs to hold for all $y\in Y$, you need for all $y\in Y$ the existence of an $x'\in X$ such that $f_X(x')=f_Y(y)$. A similar statement needs to hold for all $x\in X$ as well. This puts a restriction on the types of functions allowed in this idea. Lastly, you need:
$$d(x,y) = d(y,x).$$
Again, we are swapping the arguments here. Just as above, maybe you could say for all $(x,y)\in X\times Y$ there needs to exist elements $(x',y')\in X\times Y$ such that
$$d(x,y) = d(x',y'),$$
where $f_X(x')=f_Y(y)$ and $f_X(x)=f_Y(y')$. So as you can see getting this idea to mimic a metric puts a lot of restrictions on what is allowed. I believe that the usual metric space definition pops out of this with $X=Y$ and the choice of $id_X = f_X=f_Y$. If you find any other constructions, I'd enjoy seeing them! 
A: From a mathematical point of view:
Note that if $X\neq Y$ you will have trouble to check the conditions $\tilde d(x,x)=0$ and $\tilde d(x,y)=\tilde d(y,x)$...
Of course if $X\subset Y$ or $Y\subset X$ you might consider $\tilde d$ as the restriction of a metric but I'm not sure that it is was you are asking.
From an intuitive point of view:
We should keep in mind that a metric defines the distance between two objects, so if they are not living in the same space (which collects objects of the same nature), the distance between them is, IMHO, meaningless.
A: I think the most obvious definition is that $d(x,y)$ is a restriction of a metric on $X\cup Y$ to $X\times Y$. Let's look what properties of $d(x,y)$  we can derive from that.
In the following I assume for simplicity that $X\cap Y=\emptyset$.
Let's look at the metric axioms, and what follows:

*

*$d(x,y)\ge 0$ with equality if and only if $x=y$.
Since $X$ and $Y$ are assumed disjunct, this reduces simply to $d(x,y)>0$.


*$d(x,y)=d(y,x)$.
This obviously makes no sense on $X\times Y$ (however it may be used when deriving conditions).


*$d(x,y) \le d(x,z) + d(z,y)$.
Clearly, this cannot be used directly either, since both $z\in X$ and $z\in y$ would give an out-of-domain argument to one of the functions on the right hand side.
However, one can derive relations which also make sense for the restricted version. One obvious possibility is to extend the triangle inequality to three terms, and use symmetry to change the order of the middle term:
$$d(x,y) \le d(x,y') + d(x',y') + d(x',y)$$
Now we have an inequality that follows from the metric axioms, but which can also defined on $X\times Y$ directly, where $x,x'\in X$ and $y,y'\in Y$.
We also need to encode the restriction $d(x,x')>0$ for $x\ne x'$. Again, the triangle inequality helps us:
$$d(x,y) + d(x',y) \ge d(x,x') > 0$$
and therefore we must have
$$\inf_{y\in Y} \left(d(x,y) + d(x',y) \right) > 0.$$
Of course the same must be true also for $y,y'$.
So let's tentatively define:

A two-set metric on the disjunct sets $X$ and $Y$ is a function $d: X\times Y\to \mathbb R$ fulfilling the following axioms:

*

*$d(x,y) > 0$ for all $x\in X$ and $y\in Y$.

*$d(x,y) \le d(x,y') + d(x',y') + d(x',y)$ for all $x,x'\in X$ and $y,y'\in Y$.

*$\inf_{y\in Y}\left(d(x,y) + d(x',y)\right) > 0$ for all $x\ne x'\in X$.

*$\inf_{x\in X}\left(d(x,y) + d(x,y')\right) > 0$ for all $y\ne y'\in Y$.


Clearly every function that is a restriction of a metric on $X\cup Y$ fulfils those axioms. However is the reverse also true?
Well, let's try: We define $D:(X\cup Y)\times (X\cup Y)\to \mathbb R$ as follows:

*

*If $a\in X$ and $b\in Y$, $D(a,b) = d(a,b)$.

*If $a\in Y$ and $b\in X$, $D(a,b) = d(b,a)$.

*If $a\ne b\in X$, $D(a,b) = \inf_{y\in Y} \left(d(a,y)+d(b,y)\right)$.

*If $a\ne b\in Y$, $D(a,b) = \inf_{x\in X} \left(d(x,a)+d(x,b)\right)$.

*If $a=b$, $D(a,b)=0$.

Now let's see if $D$ is a metric.
Clearly $D(a,b) \ge 0$, with equality if and only if $a=b$. Also by definition, $D(a,b)=D(b,a)$. So what remains to prove is the triangle inequality,
$$D(a,b) \le D(a,c) + D(c,b).$$
If $a,b\in X$ and $c\in Y$, or $a,b\in Y$ and $c\in X$, this follows directly from the definition of $D$. If $a\in X$ and $b\in Y$, it follows from the definition together with the tree-term inequality (part 2 of the definition). Remains the case when all three are in the same set. I expect that also to work out, but I'm now too lazy to check.
