Solution (source code)

= Solution

Assume first that the <topological group> is Hausdorff. This separation condition is necessary: an indiscrete group with two elements has the one-element <neighbourhood basis> consisting of the whole group, but its <topology> cannot come from a <metric>.

Translations are <homeomorphisms>, since multiplication by a fixed element is continuous and its inverse is multiplication by the inverse element. Inversion is likewise a <homeomorphism>. If $W$ is an <neighbourhood> of the <identity element>, continuity of the triple product at $(e,e,e)$ supplies <neighbourhoods> of the <identity element> $A,B,C$ with $ABC\subset W$. Their intersection with their inverses contains a symmetric open <neighbourhood> of the <identity element> $V$, and $V^3\subset W$. This proves the <neighbourhood> shrinking property needed below rather than assuming it.

Let $(B_n)$ be a countable <neighbourhood basis> at the <identity element>, choosing open representatives inside its members. Starting with $U_0=G$, recursively choose symmetric open <neighbourhoods> of the <identity element> such that
$$
U_n\subset B_n\cap U_{n-1},\qquad U_n^3\subset U_{n-1}\quad(n\ge1).
$$
They are still a basis. Their intersection is $\{e\}$: for $x\ne e$, the Hausdorff condition gives an <neighbourhood> of the <identity element> not containing $x$, and some $U_n$ lies inside it.

Here is the <dyadic product estimate for group neighbourhoods>. If $g_j\in U_{n_j}$ and $\sum_j2^{-n_j}\le2^{-n}$, then the ordered product lies in $U_{n-1}$, for $n\ge1$. Prove this by induction on the number of factors. A single factor has $n_j\ge n$ and hence belongs to $U_n\subset U_{n-1}$. For a longer word, choose the factor crossing the half-total-cost point. The words preceding and following it each have cost at most half the total, hence at most $2^{-n-1}$. The induction hypothesis puts both in $U_n$, and the middle factor also lies in $U_n$. Their threefold product is in $U_{n-1}$. Empty side words cause no problem because $e\in U_n$.

Give an edge from $x_{j-1}$ to $x_j$ cost $2^{-n_j}$ whenever $x_{j-1}^{-1}x_j\in U_{n_j}$, and define
$$
\boxed{d(x,y)=\inf\left\{\sum_{j=1}^m2^{-n_j}:x_0=x,\ x_m=y,\ x_{j-1}^{-1}x_j\in U_{n_j}\right\}}.
$$
Chains exist because $U_0=G$. Reversing a chain proves symmetry, concatenating chains proves the <triangle inequality>, and translating every vertex on the left leaves all edge differences unchanged. Thus $d$ is left invariant. The product estimate also gives
$$
d(x,y)<2^{-n-1}\ \Longrightarrow\ x^{-1}y\in U_n,
\qquad x^{-1}y\in U_n\ \Longrightarrow\ d(x,y)\le2^{-n}.
$$
The first implication follows by choosing a chain with total cost below the bound and applying the estimate with index $n+1$. If $d(x,y)=0$, the first implication puts $x^{-1}y$ in every $U_n$, so $x=y$. Hence $d$ is a genuine <left-invariant group metric>. These two inclusions show that its balls and the original <neighbourhoods> of the <identity element> refine one another; translations then show equality of the two <topologies> everywhere. More explicitly, every <metric> ball contains a sufficiently small translated $U_n$, and every open <neighbourhood> contains a sufficiently small <metric> ball. This proves the sufficient direction of the <Birkhoff-Kakutani theorem>.

Conversely, if a compatible <metric> exists, the balls $B_d(e,1/n)$ form a countable <neighbourhood basis> at the <identity element>. Invariance is not even needed for this direction. Thus, with the necessary Hausdorff convention, \b[a compatible left-invariant <metric> exists exactly when the <identity element> has a countable <neighbourhood basis>].

For the requested counterexample, take the <orientation-preserving affine group of the real line>, represented by $(a,b)$ with $a>0$ and product $(a,b)(a',b')=(aa',b+ab')$. Its <topology> is metrizable, for instance by the ordinary Euclidean distance in coordinates $(\log a,b)$, and the product and inverse are continuous. Let $D_a=(a,0)$ and $T_b=(1,b)$. Direct multiplication gives $D_aT_bD_a^{-1}=T_{ab}$. A compatible <bi-invariant group metric> would make every <conjugation> an <isometry> fixing $e$. Therefore
$$
d(e,T_{1/n})=d(e,D_nT_{1/n}D_n^{-1})=d(e,T_1)>0.
$$
But $T_{1/n}\to e$ in the group's <topology>, a contradiction. This is the <affine conjugation obstruction to a bi-invariant group metric>: the group is metrizable, and even admits a compatible left-invariant <metric>, but \b[admits no compatible <metric> invariant on both sides].