a simple doubt in graph theory I was trying to find the distance between two vertices in the $Lexicographic\ Product$ of graphs. To find the distance between two vertices  $(x_1, x_2, . . . , x_k)$and $(y_1, y_2, . . . , y_k)$ a formula is given as follows.....
$d(x,y) := \begin{cases}
 d_{G_i}(x_i, y_i)   & \text{if $d_{G_{l}}(x_l) = 0$ for all $1\leq l<i$}\\
 \min\{d_{G}(x_i, y_i), 2\} & \text{if $d_{G_{l}}(x_l) \neq 0$ for all $1\leq l<i$}              
\end{cases}$ 
where $i$ is the smallest index such that $x_i$$\neq$$y_i$ and $d_{G_{l}}(x_l)$ denotes the degree of $x_l$ in $G_l$.
I am taking the reference of my post doubt about basic definiton. AND understanding the basic definiton
While calculating the distance after drawing the graph, I am getting  $distance$ as $3$,  between $(a,x,1)$  and $(d,y,2)$ but acc. to above formula its coming out to be $2$.
I am so confused. Please correct me where I am going wrong. Thanks a lot for help.
note: I am considering that no graph has isolated vertex.
 A: The problem is that your expression for $d(x,y)$ isn’t quite right. 

Added: It actually is right; I just misread it. I’ll match it up with mine below. It’s for the case in which $x\ne y$, so my first clause is unnecessary. My second clause is the special case of its first clause with $i=1$. My third clause is its second clause. And my fourth clause covers the rest of its first clause, i.e., the case of $1<i\le k$. This is easy to check so long as you remember that a vertex is isolated if and only if its degree is $0$.

Let $G=G_1\circ\ldots\circ G_n$, and let $x=\langle x_1,\dots,x_n\rangle$ and $y=\langle y_1,\dots,y_n\rangle$ be vertices of $G$. If $x_1\ne y_1$, $d(x,y)=d_{G_1}(x_1,y_1)$. 
Now suppose that $1<m\le n$, $x_m\ne y_m$, and $x_k=y_k$ for $1\le k<m$: $x$ and $y$ agree on the first $m-1$ coordinates and disagree on the $m$-th coordinate. It’s not hard to see that $d(x,y)$ cannot be any larger than $d_{G_m}(x_m,y_m)$. However, it can be smaller. Suppose that there is some $k$ with $1\le k<m$ such that $G_k$ has a vertex $v$ adjacent to $x_k$; then in $G$ the vertices $x$ and $y$ are both adjacent to the vertex $z=\langle x_1,\dots,x_{k-1},v,x_{k+1},\dots,x_n\rangle$. To see this, note that $x$ and $y$ both first disagree with $z$ in the $k$-th coordinate, and $x_k=y_k$ is adjacent to $v$ in $G_k$, so $x$ and $y$ are adjacent to $z$ in $G$. In this case, therefore, $d(x,y)=2$, even if $d_{G_m}(x_m,y_m)>2$.
The remaining possibility is that there is an index $m$ as in the previous paragraph, but each of the vertices $x_1,\dots,x_{m-1}$ is isolated; i.e., for each $k$ with $1\le k<m$, the vertex $x_k$ has no neighbor in $G_k$. In this case $d(x,y)=d_{G_m}(x_m,y_m)$.
Thus,
$$d(x,y)=\begin{cases}
0,&\text{if }x=y\\
d_{G_1}(x_1,y_1),&\text{if }x_1\ne y_1\\
\min\{d_{G_m}(x_m,y_m),2\},&\text{if there is an }m>1\text{ such that }x_m\ne y_m\\
&\text{and }x_k=y_k\text{ for }1\le k<m\\
&\text{and }x_k\text{ is not isolated in }G_k\text{ for some }k\\
&\text{with }1\le k<m\\
d_{G_m}(x_m,y_m),&\text{if there is an }m>1\text{ such that }x_m\ne y_m\\
&\text{and }x_k=y_k\text{ for }1\le k<m\\
&\text{and }x_k\text{ is isolated in }G_k\text{ for all }k\text{ with}\\
&1\le k<m\;.
\end{cases}\tag{1}$$
Let $p=\langle a,x,1\rangle$ and $q=\langle d,y,2\rangle$ be the two vertices of interest in $P_4\circ K_2\circ K_2$, where the three component graphs are realized as shown below:
     o---o---o---o      o---o      o---o  
     a   b   c   d      x   y      1   2

Call these three graphs $G_1,G_2$, and $G_3$ respectively.
Now $a\ne d$ in the first coordinates of $p$ and $q$, so $d(p,q)$ is calculated by the second clause of $(1)$ as $d(p,q)=d_{G_1}(a,d)=3$.
