{'fraction_non_alphanumeric': 0.07215901395096844, 'fraction_numerical': 0.009464309901124204, 'mean_word_length': 3.277592699884125, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
On the Topology of Metric Spaces definable in o-minimal expansions of fields

We study the topology of metric spaces which are definable in o-minimal expansions of ordered fields. We show that a definable metric space either contains an infinite definable discrete set or is definably homeomorphic to a definable set equipped with its euclidean topology. This implies that a separable metric space which is definable in an o-minimal expansion of the real field is definably homeomorphic to a definable set equipped with its euclidean topology. We show that almost every point in a definable metric space has a neighborhood which is definably homeomorphic to an open definable subset of euclidean space.


Introduction
Throughout this paper R = (R, +, ×, , . . .) is an o-minimal expansion of a field. By "definable" we mean "R-definable, possibly with parameters from R". We let e be the usual euclidean metric on R k and refer to (R k , e) as "euclidean space". The euclidean topology on a definable Z ⊆ R k is the topology induced by e. A definable metric space is a pair (X, d) consisting of a definable set X ⊆ R k and a definable R-valued metric d on X. That is, d is a definable function X 2 → R > such that for all x, y, z ∈ X: 1. d(x, y) = 0 if and only if x = y.

d(x, z) d(x, y) + d(y, z).
A definable psuedometric is a pair (X, d) which satisfies (2) and (3) but not necessarily (1). We associate a definable metric space (X/ ∼, d ′ ) to a definable psuedometric where x ∼ x ′ if and only if d(x, x ′ ) = 0. As o-minimal expansions of fields admit elimination of imaginaries the quotient X/ ∼ may be realized as a definable set.
The main results of this paper are the following basic dichotomy, Theorem 7.1 below: Theorem: Let (X, d) be a definable metric space. Exactly one of the following holds: 1. There is an infinite definable A ⊆ X such that (A, d) is discrete.
2. There is a definable Z ⊆ R k and a definable homeomorphism (X, d) → (Z, e).

below,
Theorem: Let (X, d) be a definable metric space. There is a d-open dense subset U ⊆ X such that every p ∈ U has a d-open neighborhood U such that (U, d) is definably homeomorphic to an open subset of euclidean space. and the following characterization of topological dimension, Theorem 9.5 below.
Theorem: Suppose that R expands the real field and that (X, d) is a definable metric space. The topological dimension of (X, d) is the maximal l for which there is a definable continuous injection ([0, 1] l , e) → (X, d).
Note that the previous theorem implies that the topological dimension of a definable metric space is no greater then the o-minimal dimension of the underlying definable set. The next two sections are devoted to examples of definable metric spaces. We give two kinds of examples. In Section 3 we give examples of definable metric spaces associated to definable families of sets and functions. In Section 4 we give examples of definable metric spaces which are topologically unlike definable sets. The present paper is a somewhat modified portion of the authors thesis. The author thanks his advisor Matthias Aschenbrenner for support and for greatly improving the author's writing. The mistakes and deficiencies which remain are of course the authors.

Basic Definitions and Notation
We denote the o-minimal dimension of a definable set X by dim(X). We say that a property holds for all 0 < t ≪ 1 if there is a δ > 0 such that the property holds for all 0 < t < δ. Given a function f : A → B we let Graph(f ) ⊆ A × B be the graph of f . Throughout, R > is the set of positive elements of R and R is the set of nonnegative elements of R. Let X be a definable set. We say that a definable A ⊆ X is almost all of X if dim(X \ A) < dim(X). We say that a property holds almost everywhere on X if the property holds on a definable subset of X which is almost all of X.
Let X be a topological space. Given a set A ⊆ X we let cl(A) be the closure of A, let int(A) be the interior of A, and ∂(A) := cl(A) \ A be the frontier of A. Let (X, d) and (X ′ , d ′ ) be definable metric spaces. Given a definable A ⊆ X we let Proof: We show that d H (A t , A 0 ) → 0 as t → 0 + . Suppose otherwise. Then there is a δ ∈ R > such that d H (A t , A 0 ) > δ when t is sufficiently small. Then one of the following must hold: (1) If 0 < t ≪ 1 then there is a x ∈ A 0 such that x − y > δ for all y ∈ A t .
(2) If 0 < t ≪ 1 then there is a y ∈ A t such that y − x > δ for all x ∈ A 0 .
Suppose that (1) holds. After replacing δ with a smaller element of R > if necessary and applying definable choice we let γ be a path in A 0 such that: γ(t) − y > δ for all 0 < t < δ, y ∈ A t .
As A 0 is a closed subset of [0, 1] k , γ must have a limit γ 0 in A 0 as t → 0 + . If γ(t) − γ 0 < δ 2 then the triangle inequality implies that if 0 < t < δ then γ 0 − y > δ 2 holds for all y ∈ A t . As γ 0 lies in the closure of A there is a y ∈ A such that y − γ 0 < δ 2 . Then y ∈ A t for 0 < t < δ 2 . This gives a contradiction. A similar argument produces a contradiction from (2).

Tame Expansions
We make use of the theory of tame pairs of o-minimal structures. We recall the necessary ingredients here. We assume that the language of R contains a symbol for every definable function R → R. This ensures that R admits quantifier elimination. Let K = (K, +, ×, . . .) be an elementary extension of R. If for every b ∈ K the set {a ∈ R : a b} has a supremum in R ∪ {−∞, ∞} then we say that K is tame extension of R and we say that R is a tame substructure of K. We assume that all tame extension are nontrivial extensions, so as not to consider R to be a tame elementary extension of itself. If K is a tame elementary extension of R then we define a standard part map st : K ∪ {−∞, ∞} → R ∪ {−∞, ∞} by st(b) = sup{a ∈ R : a < b}.
The study of tame extensions began with the following theorem [MS94]: Theorem 2.4 (Marker-Steinhorn) The following are equivalent: 1. K is a tame extension of R, 2. Every type over R realized in K is definable over R.
There are two particularly important kinds of tame extensions with which we are concerned. First, if R expands the ordered field of real numbers than every elementary extension of R is tame. Second, let ζ be a positive element of an elementary extension of R which is less then every positive element of R. Then R(ζ), the prime model over ζ, is a tame elementary extension of R. Indeed, as R admits definable Skolem functions, every element of R(ζ) is of the form f * (ζ) for some R-definable function f : R > → R and in this case: . A tame pair is the expansion of K by a predicate defining R, denoted by (K, R). The theory of tame pairs is complete: Theorem 2.5 (van den Dries -Lewenberg) Let K, K ′ be tame extensions of R. Then (K, R) and (K ′ , R) are elementarily equivalent.
Recall that the convex hull of a subfield of an ordered field is a subring, and that any convex subring of an ordered field is a valuation subring. We say that a convex subring O ⊆ K is T-convex if it is the convex hull of a tame substructure of K. For the remainder of this section O is the convex hull of R in K. The expansion of K by a predicate defining O is called a T-convex structure and denoted (K, O). Let m be the maximal ideal of O and let Γ be the value group of the associated valuation. It follows from the definition of a tame expansion that b − st(b) ∈ m for all b ∈ O. We therefore identify the residue field of (K, O) with R and the residue map with st.
Theorem 2.6 (van den Dries -Lewenberg) The structure (K, O) admits elimination of quantifiers and is universally axiomatizable.
The following corollary is proven in [Dri97]. The proof uses the Marker-Steinhorn theorem.

Uniform Limits
Following [Dri05] we apply stable embeddedness to show definibility of pointwise and uniform limits of definable families of functions. We use this to construct the definable completion of a definable metric space in Section 6. Lemma 2.8 Let A ⊆ R k be definable and let F = {f x : x ∈ R l } be a definable family of functions A → R. There is a definable family G of functions A → R such that a function g : A → R is an element of G if and only if there is a path γ in R l such that g is the pointwise limit of f γ(t) as t → 0 + .
If R expands the real field then G is the set of pointwise limits of sequences of elements of F . This is essentially proven by van den Dries in [Dri05], however, he only worked over the reals. We only sketch the proof.
Proof: [Sketch] Let R * = (R * , +, ×, , . . .) be a tame elementary extension of R. We consider the tame pair (R * , R). Stable embeddedness implies that there is an R-definable family G = {g x : x ∈ B} of functions A → R such that a function g : A → R is an element of G if and only if for some α ∈ (R * ) l we have: The completeness of the theory of tame pairs implies that G does not depend on the choice of R * . Suppose R * = R(ζ) is the prime model over a positive infinitesimal element ζ of an elementary extension of R. Then the elements of G are functions of the form st f * γ * (ζ) : A → R for R-definable paths γ in R l . For any path γ in R l : Suppose that R expands the real field. Then every element of G is a pointwise limit of a sequence of the form {f γ( 1 i ) } i∈N for a path γ in R l . We show that every pointwise limit of a sequence of elements of F is an element of G. Let U be a nonprincipal ultrafilter on N and let R U = (R U , +, ×, . . .) be the ultrapower of R with respect to U. Let {α(i)} i∈N be a sequence of elements of R l such that {f α(i) } i∈N pointwise converges as i → ∞. We let α be the element of (R U ) l corresponding to the sequence {α i } i∈N .
In Proposition 6.2 we use the following corollary to construct the definable completion of a definable metric space.

Corollary 2.9
There is a definable family G ′ of functions A → R such that a function g is an element of G ′ if and only if it is a uniform limit of a family {f γ(t) } t∈R > as t → 0 + for some definable γ : R > → R l . If R expands the ordered field of reals then G ′ is the set of uniform limits of sequences of elements of F .

Proof: [Sketch]
We let G ′ be the set of g ∈ G such that for every ǫ ∈ R > there is an x ∈ R l such that g − f x ∞ ǫ. It is easy to check that this works.

Examples: Metrics Associated To Definable Families
In this section we describe definable metric spaces associated to definable families of functions and sets.

Metrics Associated To Definable Families of Functions
Let F = {f x : x ∈ R l } be a definable family of functions R k → R. If each element of F is bounded then we put a uniform pseudometric d ∞ on R l by declaring: If every element of F is C r with bounded rth derivative then is a definable pseudometric on R l . Thomas considered definable metric spaces of this form in [Tho12].

Examples constructed using the CLR-volume Theorem
Let µ m be the m-dimensional Lebesgue measure on R k . Comte, Lion and Rolin proved the following proposition in [CR00].
This implies that if f : is an R an,exp -definable pseudometric on R l .

Definable Metrics with Noneuclidean Topology
In this section R is an expansion of the real field. We give examples of definable metric spaces which are not homeomorphic to any definable set equipped with its euclidean topology. The trivial example is any infinite definable set X equipped with the discrete metric d disc given by declaring d disc (x, x ′ ) = 1 whenever x = x ′ . We now give an example of a definable metric space which is not locally contractible. Let d be the metric on [0, 1] given by d(x, y) = 0 when x = y and d(x, y) = max{x, y} otherwise. It is clear that d is symmetric and reflective. The ultrametric triangle inequality holds as: max{x, y} max{max{x, z}, max{y, z}} = max{d(x, z), d(y, z)} for all x, y, z ∈ X.
Every point in [0, 1] is isolated except for 0, which is in the closure of (0, 1). This metric space is not locally contractible at 0.

Metric Spaces Associated to Definable Simplicial Complexes
We assume that the reader is familiar with simplicial complexes. Our source is the classic [Spa66]. An abstract simplicial complex V = (V, C) is a set V of vertices together with a collection C of finite subsets of V such that: 1. Every singleton subset of V is an element of C, 2. Every subset of an element of C is an element of C.
We say that V is finite-dimensional if there is an N ∈ N such that every element of C has cardinality at most N. We only consider finite-dimensional simplicial complices. We say that V is locally finite if every element of C intersects only finitely many elements of C.
A definable abstract simplicial complex is a definable set V together with a definable family C = {C x : x ∈ R l } of finite subsets of V such that (V, C) is an abstract simplicial complex. We associate a topological space |V| to an abstract simplicial complex V called the geometric realization of V. If V is locally finite then the construction we give is equivalent to any other construction of the geometric realization that the reader may have seen. We let |V| be the set of functions α : V → [0, 1] such that: {v ∈ V : α(v) = 0} ∈ C and v∈V α(v) = 1.
We put a metric d V on |V| by declaring: The following fact is clear: This construction produces interesting definable metric spaces.

Cayley Graphs
Let G be a finitely generated group. We say that G is definably representable if there is a free action of G by definable functions on a definable set A. Any finitely generated subgroup of Gl n (R) is definably representable. Suppose that G is a finitely generated group with a fixed symmetric set of generators S = {g 1 , . . . , g n }. Let G A be a free action of G on a definable set A. We define the Cayley graph of this action. This depends on the choice of S. We consider the elements of S as functions A → A. The Cayley graph of G A is the graph G with vertex set A and edge set Then G is a definable graph, and the geometric realization of G is a definable metric space. As a graph, G is the disjoint union of continuum many copies of the usual Cayley graph of G. In this manner we construct definable metric spaces with unexpected properties.
is a homeomorphism then τ induces a non Lebesgue measurable map. We let: Let λ ∈ (0, 1) be an irrational number. Let θ : [0, 1] → [0, 1] be given by θ(t) = t + λ when t + λ ∈ [0, 1] and g(t) = t + λ − 1 otherwise. Consider the action of (Z, +) on [0, 1] generated by θ. Let G be the Cayley graph of this action and let (X ′ , d ′ ) be the geometric realization of G. As a topological space, (X ′ , d ′ ) is the disjoint union of continuum many copies of (R, e), so (X ′ , d ′ ) is homeomorphic to (X, d). We put an equivalence relation ∼ on X ′ by declaring x ∼ y when x and y lie in the same connected component of (X ′ , d ′ ). Recall that [0, 1] is the set of vertices of G. Two elements of [0, 1] are ∼-equivalent if and only if they lie in the same orbit of the action of (Z, +). The restriction of ∼ is essentially the Vitali equivalence relation. Suppose that h : (X ′ , d ′ ) → (X, d) is a homeomorphism. Two elements x, y ∈ X are in the same connected component of (X, d) if and only if h(x) and h(y) lie in the same connected component of (X, d). Let τ : [0, 1] → R be the restriction of π • h to [0, 1]. If x, y ∈ [0, 1] then x ∼ y holds if and only if τ (x) = τ (y). It is well-known that such a map τ : [0, 1] → R cannot be Lebesgue measurable.
is definably connected if ∅ and Y are the only definable clopen subsets of Y . Let (X ′ , d ′ ) be the definable metric space constructed in the previous example. We show that (X ′ , d ′ ) is definably connected. This gives an example of a definably connected metric space which is not connected. Suppose that A 1 , A 2 ⊆ X ′ are disjoint nonempty clopen definable subsets of X. Fixing p 1 ∈ A 1 , p 2 ∈ A 2 we let B 1 , B 2 ⊆ [0, 1] be the set of vertices which lie in the connected component of p 1 , p 2 , respectively. As B 1 and B 2 are orbits of the action of (Z, +) on [0, 1], both B 1 and B 2 are dense in ([0, 1], e). As B 1 and B 2 are definable this implies B 1 ∩ B 2 = ∅, contradiction.
In the next example we use a simple topological fact. We leave the proof to the reader.
Fact 4.4 Let G 1 , G 2 be graphs where every vertex has degree at least 3. If the geometric realizations |G 1 | and |G 2 | are homeomorphic then G 1 and G 2 are isomorphic as graphs.

Example 4.5 (Sketch)
We show that the Trivialization Theorem does not hold for definable families of metric spaces. We construct a definable family of metric spaces which contains infinitely many elements up to homeomorphism. Let S = {x ∈ R 2 : x = 1}, let U(1) be the group of rotations of S and let τ be the reflection across the x-axis. If σ ∈ U(1) then {σ, τ } generate a definable action of a dihedral group D σ on S. The group D σ is finite if and only if σ is a rational rotation. Note that the Cayley graph of this action is 3-regular. Given σ ∈ U(1) we let X σ be the geometric realization of the Cayley graph of this action. Then {X σ : σ ∈ U(1)} is a semialgebraic family of metric spaces. Every connected component of X σ is homeomorphic to the geometric realization of the Cayley graph of D σ . Suppose that σ, η ∈ U(1) and that h : X σ → X η is a homeomorphism. Then h maps connected components to connected components and thus induces a homeomorpism between the geometric realizations of the Cayley graphs of D σ and D η . Fact 4.4 implies that the Calyey graphs of D σ and D η are isomorphic as graphs. Thus, if σ and η are rational rotations such that |D σ | = |D η | then X σ is not homeomorphic to X η . So the family {X σ : σ ∈ U(1)} contains infinitely many pairwise non-homeomorphic elements.

Definable Completeness And Compactness
In this section we construct the definable completion of a definable metric space. We show that definable completeness is equivalent to completeness over expansions of the real field. Over expansions of the real field the definable completion agrees with the usual completion. The notion of definable completeness was first studied in the context of definable metrics on definable families of functions by Thomas [Tho12]. We also introduce a notion of definable compactness and show that over an expansion of the real field, definable compactness is equivalent to compactness. Throughout this chapter (X, d) and (X ′ , d ′ ) are definable metric spaces. A path γ in X is Cauchy if for every ǫ > 0 there is a δ > 0 such that if 0 < t, t ′ < δ then d(γ(t), γ(t ′ )) < ǫ. An application of the triangle inequality proves that converging paths are Cauchy. A path γ in X is said to be bounded if the image of R > under γ is a bounded subset of (X, d). If the metric is not clear from context we will say that γ d-converges. A definable metric space is definably complete if every Cauchy path in it converges.
A definable metric space is definably compact if every path in it converges. A definable metric space is definably proper if every bounded path in it converges. A definably proper metric space is definably compact if and only if it is bounded. A closed subset of a definably proper definable metric space endowed with the induced metric is definably proper and a definably proper space is definably complete.

Basic Facts
The following are equivalent: 1. h is continuous.
2. If γ is a path in (X, d) which converges to x ∈ X then h • γ converges to h(x).
Proof: It is quite obvious that (i) implies (ii). We prove the other implication. Suppose that h is not continuous at x ∈ X and let h(x) = x ′ . There exists a δ > 0 such that for is locally definably compact if and only if A is locally closed.
Proof: We only prove the first claim as the proofs of the other two claims are very similar and the idea is familiar from metric space topology. Suppose that (X, d) is definably complete and that A is closed. Every Cauchy path in A has a limit in X, and as A is closed the limit must be an element of A. Conversely, suppose that A is not closed. Let p be a frontier point of A. Applying definable choice we let γ be a path in A such that d(γ(t), p) < t holds for all t > 0. Then γ is Cauchy with limit p / ∈ A. So (A, d) is not definably complete.
is definably compact, and let f : (X, d) → (R, e) be definable and continuous. Then f has a maximum and a minimum.
As (X, d) is definably compact γ must converge to some point z. Continuity of f implies f (z) = r. This implies that r < ∞.
Lemma 5.4 A product of two definably compact metric spaces is definably compact.
Proof: One of the following holds: We assume that (ii) holds and derive a contradiction. Suppose ǫ > 0 is such that if 0 < t < ǫ then there do not exist x, y ∈ X such that d(x, y) = t. Then if x, y ∈ X and d(x, y) < ǫ then x = y, so (X, d) is discrete. As X is infinite there is an injective path γ : R > → X. As (X, d) is discrete, γ does not have a limit as t → 0 + , contradiction.
definably compact then f is uniformly continuous. If (X, d) is definably compact and f is bijective then f is a uniform equivalence and hence a homeomorphism.
Proof: Let f : (X, d) → (X ′ , d ′ ) be a definable continuous map and suppose that (X, d) is definably compact. The proposition follows immediately in the case that X is finite, so we suppose that X is infinite. For t ∈ R > let ) so to show that f is uniformly continuous it suffices to show that lim t→0 + g(t) = 0. Suppose otherwise towards a contradiction. There are paths γ 1 , We now suppose in addition that f is a bijection and show that f is a uniform equivalence. Let h : (0, ǫ) → R be the definable function given by The next lemma is used in a crucial way to prove Theorem 7.1.
Lemma 5.7 Let (Y, d) be a definably compact metric space. Let X be a definably compact subset of euclidean space which admits a definable continuous surjection (X, e) → (Y, d).
Then there is a definable set X ′ and a definable homeomorphism (X ′ , e) → (Y, d).
Proof: Let h : (X, e) → (Y, d) be a definable continuous surjection. Let E ⊆ X 2 be the kernel of h, i.e., the equivalence relation We endow the set-theoretic quotient X/E with the quotient topology. Continuity of h implies that E is a closed, and hence definably compact, subset of X 2 . We apply 2.15 of [Dri98] to obtain a definable set X ′ and a definable continuous map p : X → X ′ such that the kernel of p is E and the induced bijection p E : X/E → (X ′ , e) is a homeomorphism. As p is continuous, (X ′ , e) is definably compact. Let h E : (X ′ , e) → (Y, d) be the map induced by h.
Then h E is a continuous bijection between definably compact metric spaces. Proposition 5.6 implies that h E is a homeomorphism.
We now prove two lemmas about extending definable functions: is definably complete. Let A ⊆ X be definable and dense and let f : (A, d) → (X ′ , d ′ ) be a uniformly continuous definable function. Then f admits a unique extension to a uniformly continuous definable function (X, d) → (X ′ , d ′ ).
Proof: We construct an extension; it is clear from the construction that the extension is unique. Let g : R > → R > be a definable continuous function such that lim t→0 + g(t) = 0 and As ψ x is Cauchy this inequality implies that f • ψ x is Cauchy. Definable completeness of (X ′ , d ′ ) implies that f • ψ x converges. Therefore, for any x ∈ X we may letf (x) be the limit of f • ψ x in (X ′ , d ′ ). A computation shows thatf is uniformly continuous: The proof of Lemma 5.8 also shows the following: Lemma 5.9 Suppose (X, d) and (X ′ , d ′ ) are definably complete. Let A ⊆ X be definable and dense. Suppose that f : A → X ′ is a distance preserving function. Then f admits a unique extension to a distance preserving definable function (X, d) → (X ′ , d ′ ).
Immediately from this we have:

The Definable Completion
We construct the definable completion of a definable metric space. Our construction is an application of the following fact: Then the metric space associated to (B, d ∞ ) is definably complete. If R expands the ordered field of reals then the metric space associated to (B, d ∞ ) is complete.
Recall that G consists of those functions A → R which are uniform limits of families of the form {f γ(t) } t∈R > as t → 0 + for paths γ in R l .
Proof: We show that the metric space associated to (B, d ∞ ) is definably complete. Fix a Cauchy path γ : R > → (B, d ∞ ). As γ is Cauchy, f γ(t) uniformly converges as t → 0 + . Let g 0 : A → R be the uniform limit of g γ(t) as t → 0 + . Applying definable choice we let ψ : B × R > → R l be a definable function such that: The triangle inequality implies: Thus f ψ (γ(t), t) uniformly converges to g 0 as t → 0 + . Thus g 0 is an element of G. If R is an expansion of the ordered field of real numbers then a similar argument with sequences in place of paths shows that the metric space associated to (B, d ∞ ) is complete.
For our definable metric space (X, d) we construct a definably complete metric space ( X, d) and a distance preserving definable map (X, d) → ( X, d) with dense image. It follows from Lemma 5.8 that the definable completion is left adjoint to the forgetful functor from the category of definably complete metric spaces and uniformly continuous definable maps to the category of all definable metric spaces and and uniformly continuous definable maps. It follows from Lemma 5.10 that the definable completion is unique up to definable isometry.
Proposition 6.2 There is a definably complete metric space ( X, d) and a definable isometry (X, d) → ( X, d) with dense image. Any uniformly continuous definable map (X, d) → (X, d ′ ) admits a unique extension to a uniformly continuous definable map between the definable completions ( X, d) → ( X ′ , d ′ ).
Proof: We construct the definable completion. We use the Kuratowski Embedding. Fix a basepoint p ∈ X. For x ∈ X let d x : X → R be given by d x (y) = d(x, y). For each x ∈ X consider the definable function τ x : We show that τ x − τ y ∞ = d(x, y) for all x, y ∈ X. Fix x, y ∈ X.
As y). Applying Corollary 2.9 let G = {g x : X → R : x ∈ B} be a definable family of functions whose elements are the uniform limit points of the family {τ x : x ∈ X}. For a, b ∈ B let d(a, b) = g a − g b ∞ . Let ( X, d) be the metric space associated to the pseudometric space (B, d). In Fact 6.1 we observed that ( X, d) is definably complete. The natural map X → X is clearly injective, distance-preserving and has dense image. The second claim follows from Lemma 5.8. Corollary 6.3 Suppose that R expands the orderered field of reals. Then every definably complete metric space is complete.
Proof: Fact 6.1 implies that the definable completion of any definable metric space is complete. Lemma 5.10 implies that a definably complete metric space is isometric to its definable completion.
We now prove the analogue of Corollary 6.3 for definably compact spaces. We need two simple lemmas. We let U be a nonprincipal ultrafilter on the natural numbers and let R * = (R U , +, ×, ...) be the corresponding ultrapower of R. Given a sequence of elements {x i } i∈N of some R-definable set A we let [x i ] be the corresponding element of A * . Lemma 6.4 Suppose that R expands the ordered field of reals. Let {x i } i∈N be a sequence of elements of X and y ∈ X be such that st d * ([x i ], y) = 0. Then there is a subsequence of {x i } i∈N which converges to y.
Proof: Let ǫ ∈ R > . As d * ([x i ], y) < ǫ we see that d(x i , y) < ǫ for U-many i. So for every such ǫ there is an i ∈ N such that d(x i , y) < ǫ. There is a subsequence of {x i } i∈N which converges to y. Proof: st d * (γ(ζ), y) = lim t→0 + d(γ(t), y). Proposition 6.6 Suppose R expands the ordered field of reals. Then every definably compact metric space is compact.
Proof: It is clear that a compact definable metric space is definably compact. Let (X, d) be a definably compact metric space. Consider the following sentence in the language of tame pairs: Θ = (∀x ∈ X * )(∃y ∈ X)[st d * (x, y) = 0].
As (X, d) is definably compact, Lemma 6.5 implies that (R(ζ), R) |= Θ. As the theory of tame pairs is complete (R U , R) |= Θ. By Lemma 6.4 every sequence in X admits a converging subsequence. Thus (X, d) is compact.
The next lemma will be used in the proof of Proposition 7.19 below to embed certain definable metric spaces in definably compact metric spaces.
Lemma 6.7 Let {A x : x ∈ R l } be a definable family of subsets of [0, 1] k . Let d be the pseudometric on R l given by d(x, y) = d H (A x , A y ) for all x, y ∈ R l . Then the definable completion of the definable metric space associated to (R l , d) is definably compact.
Proof: Let (B, d) be the definable metric space associated to (R l , d) and let π : R l → B be the quotient map. Let ( B, d) be the definable completion of (B, d). We show that an arbitrary path γ : R > → B converges. Applying definable choice let γ ′ : R > → B be a path such that d(γ ′ (t), γ(t)) t for all t ∈ R > .
It is enough to show that γ ′ converges. Let η : R > → R l be a path such that π • η = γ ′ . Let D ⊆ R k be the set of p such that (0, p) is in the closure of Lemma 2.3 implies that A η(t) converges to D in the Hausdorff metric as t → 0 + . It follows that γ ′ has a limit in B.

Main Proof
In this section (X, d) is a definable metric space. The main goal of this section is to prove the following: Theorem 7.1 Exactly one of the following holds: 2. There is a definable set Z and a definable homeomorphism The proof splits into two parts. First we show that every definably separable metric space is definably homeomorphic to a subspace of a definably compact metric space and then we show that every definably compact metric space is homeomorpic to a definable set equipped with its euclidean topology. We embedd definably separable spaces in definably compact metric spaces by studying the pseudometric d H on X given by declaring d H (x, y) to be the Hausdorff distance between Graph(d x ) and Graph(d y ), where we set d x (z) = d(x, z). If X is a bounded subset of euclidean space and (X, d) is a bounded metric space then d H is a psueodmetric on X and the completion of the metric space associated to (X, d H ) is definably compact. We show that every definably separable metric space is definably isometric to a definable metric space (X, d) for which d H is a metric and id : (X, d) → (X, d H ) is a homeomorphism. This entails showing that any definably separable metric space (X, d) admits a partition into definable sets on which the d-topology agrees with the metric topology.
After constructing the embedding we use the aforementioned piecewise result and Aschenbrenner and Thamrongtanyalak's definable Micheal Selection Theorem to show that every definably compact metric space is a definable continuous image of a definably compact set. An application of Lemma 5.7 then shows that every definably compact metric space is homeomorphic to a definably compact set.
Along the way we prove some general facts about the topology of definable metric spaces. As a consequence we show that if R expands the real field then the topological dimension of (X, d) is the largest k for which there is a definable continuous injection ([0, 1] k , e) → (X, d).

Definably Separable Metric Spaces
We say that (X, d) is definably separable if every d-discrete definable subset of X is finite. This terminology is justified: If R is an expansion of the ordered field of reals then every infinite definable set has cardinality |R|, so if (X, d) is not definably separable then X contains a discrete subset with cardinality |R|, which implies that (X, d) is not separable. Theorem 7.1 thus implies that a metric space definable in an o-minimal expansion of the ordered real field is separable if and only if it is definably separable. Lemma 2.1 implies: Lemma 7.2 Suppose that (X, d) is not definably separable. There is a t > 0 and an infinite definable A ⊆ X such that d(x, x ′ ) > t for any distinct x, x ′ ∈ A.
Proof: Let B ⊆ X be an infinite definable set such that (B, d) is discrete. Applying definable choice let f : B → R > be a definable function such that if x, y ∈ B and d(x, y) < f (x) then x = y. By Lemma 2.1 there is an infinite definable subset A ⊆ B and an t ∈ R > such that if x ∈ A then f (x) > t.
For the next lemma, we define the local dimension of (X, d) at x ∈ X to be Proof: We prove the contrapositive. To this effect we an e-open m-dimensional definable U ⊆ X such that dim x (X, d) < dim(X) for all x ∈ U. After replacing U with a smaller open set with the same properties if necessary we may also suppose that dim x (X, d) = m < n for all x ∈ U. Let g : U → R > be a definable function such that dim[B d (x, g(x))] = n for all x ∈ U. We set B x = B d (x, g(x)). We apply a uniform version of the good directions lemma see 4.3 in [Dri98]. We find an m-dimensional open W ⊆ U and a linear projection π : U → R n whose restriction to B x is finite for each x ∈ W . As dim π(W ) = n the fiber lemma for o-minimal dimension implies that there is a q ∈ W such that dim π −1 (q) is (m − n)-dimensional. We fix such a q and let J = π −1 (q). Then J is infinite. We show that (J, d) is discrete. Fix β ∈ J. Let {β 1 , . . . , β N } = B β ∩J. Then if y ∈ J and d(β, y) < d(β, β i ) holds for each i then y = β, so β is isolated in J.
The next lemma shows that there is no definable compactification of a definable discrete metric space.
Lemma 7.4 If (X, d) is definably compact and B ⊆ X is definable then (B, d) is definably separable.
Proof: We prove the contrapositive. Suppose that (B, d) is not definably separable. Suppose that A ⊆ X and t > 0 satisfy the conditions in Lemma 7.2. A path in A is Cauchy if and only if it is eventually constant. Thus there is a path in X which is not Cauchy and so (X.d) is not definably compact.

A Definable Compactification
In this section we show that every definably separable metric space is definably homeomorphic to a definable subspace of a definably compact metric space. After this, it suffices to prove Theorem 7.1 for definably compact metric spaces. Along the way, we will prove several other results about arbitrary definable metric spaces.
We introduce some terminology. We say that a point x ∈ X is yellow if there is a path in X which converges to x in the euclidean topology and converges in the d-topology to some y ∈ X \ {x}. We say that a point x ∈ X is blue if it is not yellow. We say that definable metric space is blue if all of its points are blue. By a "blue metric space" we mean a "blue definable metric space". Our first goal is to show, in Proposition 7.7, that every definable metric space is definably isometric to a blue metric space. We first show that the set of blue points of (X, d) is definable. For y ∈ X let d y : X → R be given by d y (x) = d(y, x).
Lemma 7.5 The following are equivalent for x, y ∈ X: 1. There is a path in X which e-converges to x and d-converges to y.

(x, 0) ∈ cl e [Graph(d y )].
It follows that the set of yellow points is definable.
Proof: Suppose that γ is a path in X which e-converges to x and d-converges to y. Then (γ(t), (d y • γ)(t)) is a path in Graph(d y ) which e-converges to (x, 0). Conversely, suppose that (x, 0) ∈ cl e [Graph(d y )]. Let γ be a path in Graph(d y ) which e-converges to (x, 0). Let π X : X × R → X and π R : X × R → R be the coordinate projections. Then π 1 • γ converges to x and π R • γ converges to 0. As π X • γ = d y • π X • γ, π X • γ is a path in X which e-converges to x and d-converges to y.
As in Section 6 , ( X, d) is the definable completion of (X, d).
Lemma 7.6 Let x ∈ X. Then x is a blue point of ( X, d) if and only if any d-Cauchy path in X which e-converges to x must also d-converge to x.
Proof: Suppose that x is a blue point of X and that γ is a d-Cauchy path which e-converges to x. It follows that γ d-converges in X and so γ must d-converge to x. We now prove the converse. Suppose that every d-Cauchy path in X which e-converges x also d-converges to x. Suppose that γ is a path in X which e-converges to x. Suppose that γ d-converges to y ∈ X. Applying definable choice and the density of X in X there is a path η in X such that d(γ(t), η(t)) < t for all t ∈ R > . Thus η d-converges to y, so η is d-Cauchy. It follows from the assumption on x that η d-converges to x, so γ d-converges to x.
Proposition 7.7 Every definable metric space is definably isometric to a blue definable metric space.
To prove Proposition 7.7 it suffices to prove the following claim: Claim 7.8 Almost every x ∈ X is blue.
Before proving this claim we suppose that it on holds every definable metric space and prove Proposition 7.7. We apply induction on dim(X). If dim(X) = 0 then (X, e) and (X, d) are both discrete and so (X, d) is blue. Suppose dim(X) > 0. We let A be the definable set of points of X which are yellow in (X, d). Clearly (X \ A, d) is blue and dim(A) < dim(X). Applying the inductive assumption on (A, d) we produce a definable isometry τ : (A, d) → (A ′ , d ′ ) to a blue metric space (A ′ , d ′ ). Let X ′ be the disjoint union of X \ A and A ′ . Let σ : X → X ′ be the natural bijection and let d ′ be the pushfoward of d by σ. Any path in X ′ is eventually contained in A ′ or X \ A. This implies that (X ′ , d ′ ) is blue.
We prove a slight strengthening of Claim 7.8, where we use the full strength of the hypothesis in the inductive step.
Claim 7.9 Almost every x ∈ X is a blue point of X.
Proof: We apply induction on dim(X). If dim(X) = 0 then both (X, e) and (X, d) are discrete and the claim trivially holds. We assume that dim(X) > 0 and let l = dim(X). Let σ : X → R l be an injective definable map. Let X ′ = σ(X) and d ′ be the metric on X ′ given by d ′ (σ(x), σ(y)) = d(x, y). Almost every p ∈ X has a neighborhood U such that σ| U is a homeomorphism onto an open neighborhood of σ(p), and if p has such a neighborhood then σ(p) is blue in X ′ if and only if p is blue in X. It suffices to show that almost every point in (X ′ , d ′ ) is blue.
We therefore suppose without loss of generality that X ⊆ R l . We assume towards a contradiction that dim A = l. We apply definable choice to produce definable functions g : A → X and ψ : A × R > → X such that: Then ψ x is a path in X which e-converges to x and d-converges to g(x). Let π : X → R be the projection onto the last coordinate. Fix y ∈ π(X). We have dim π −1 (y) l − 1 so we can apply the inductive assumption to (π −1 (y), d). For almost every x ∈ π −1 (y) we have the following: a d-Cauchy path in π −1 (y) which e-converges to x also d-converges to x. This holds for every y ∈ π(X) so we apply the fiber lemma for o-minimal dimension and conclude that for almost every x ∈ X we have the following: a d-Cauchy path γ in X which e-converges to x and satisfies (π •γ)(t) = π(x) when 0 < t ≪ 1 also d-converges to x. Let A ′ ⊆ A be the definable set of points in A which satisfy this condition. Then A ′ is l-dimensional. If x ∈ A ′ and 0 < t ≪ 1 then (π• ψ x )(t) = π(x). We let We suppose without loss of generality that dim A + = l. Let J ⊆ R be an interval and B ⊆ R l−1 be a product of intervals such that J × B ⊆ A ′ + . For every x ∈ J × B we have π(ψ x (t)) > π(x) when 0 < t ≪ 1. Fix b ∈ J. Suppose x ∈ {b} × B. As x ∈ A ′ there is a s > 0 such that if z ∈ X satisfies d(g(x), z) < s and e(x, z) < s then π(z) = b. Applying Lemma 2.1 there is an open V ′ ⊆ B and s > 0 such that if x ∈ {b} × V ′ and z ∈ X satisfy d(g(x), z) < s and e(x, z) < s then π(z) = b. If x, z ∈ {b} × V ′ and e(x, z) < s then d(g(x), z) s. By shrinking V ′ if necessary we may assume that Diam e (V ′ ) < s. Now if x, z ∈ {b} × V ′ then d(g(x), z) > s. This implies that if x ∈ {b} × V ′ and 0 < t < s then π(ψ x (t)) > b. Applying Lemma 2.2 to the image ψ we find an open V ⊆ V ′ and a δ > 0 such that We show that V and δ satisfy the conditions of Claim 7.10. Let y , y) < s 2 and d(g(x), z) > s so the triangle inequality implies that d(z, y) > 1 2 s. This proves Claim 7.10.

Claim 7.11
There is an interval J ′ ⊆ J, a product of intervals B ′ ⊆ B and s > 0 such that if y, z ∈ J ′ × B ′ and π(y) = π(z) then d(x, y) > s.
Applying definable choice to Claim 7.10 we fix definable functions f, g : . There is an interval J ′ ⊆ J, a product of intervals B ′ ⊆ B and s, δ > 0 such that for all b ∈ J ′ : Here (i) is immediate. (ii) is immediate from the fiberwise openness theorem Theorem 2.2 of [Dri98]. By shrinking J ′ if necessary we suppose that Diam e (J ′ ) < δ.
Every blue metric space admits a definable distance decreasing injection into a definably compact metric space. We define the map ι X in the case when X is a bounded subset of euclidean space. We indicate here how to extend this definition to the general case. Let X ′ be a definable bounded subset of euclidean space for which there is a definable homeomorphism τ : X → X ′ . Let d ′ be the pushforward of d onto X ′ by τ . We then take ι X = τ • ι X ′ . Then ι X depends on the choice of X ′ and τ . These choices will not matter, so we suppress them. Note that, in the situation described, (X ′ , d ′ ) is blue if and only if (X, d) is blue. This ensures that ι X is injective when (X, d) is blue.
Definition 7.12 Suppose that X is a bounded subset of euclidean space. Let d be the function on X 2 given by d(x, y) = min{d(x, y), 1}. It is easily checked that d is a metric and id : (X, d) → (X, d) is distance decreasing. For each x ∈ X we let d x : X → R be d x (y) = d(x, y). We define a pseudometric d H on X by setting d H (x, y) equal to the Hausdorff distance between Graph(d x ) and Graph(d y ). As X is a bounded subset of euclidean space and d is bounded from above by 1, each Graph(d x ) is bounded and so d H (x, y) < ∞ for every x, y ∈ X. For any bounded definable functions f, g : X → R we have: for any x, y ∈ X, (X, d H ) is bounded. We let (B, d H ) be the metric space associated to the pseudometric (X, d H ) and let ( B, d H ) be the definable completion of (B, d H ) . As ( B, d H ) is bounded, Lemma 6.7 implies that ( B, d H ) is definably compact. We define ι X to be the natural distance decreasing map Lemma 7.13 If (X, d) is blue and X is a bounded of subset of euclidean space then ι is injective. Equivalently, if (X, d) is blue and X is a bounded subset of euclidean space then (X, d H ) is a metric space.
Proof: We suppose that d H is not a metric. Let x, y be distinct elements of X for which Corollary 7.14 Any definable metric space admits a continuous injection into a definably compact metric space.
Lemma 7.15 Let A ⊆ X be definable. Then Proof: It suffices to prove the lemma for any definable metric space definably isometric to (X, d). We therefore assume that (X, d) is blue. Thus d H is a metric on X. We use this dimension inequality to prove the following key technical lemma: Lemma 7.16 Let d ′ be another definable metric on X. Suppose that dim x (X, d ′ ) = dim(X) at almost every x ∈ X. Then id : (X, d) → (X, d ′ ) is continuous almost everywhere.
Proof: Let D ⊆ X be the set of points at which id : (X, d) → (X, d ′ ) is not continuous. We suppose towards a contradiction that dim(D) = dim(X). Let π 1 : X 2 × R → X be the projection onto the first coordinate. Let Q ⊆ X 2 × R be the set of (x, x ′ , t) such that By definition D = π 1 (Q). It follows that dim{x ∈ X : (x, y, t) ∈ Q} < dim X for all (y, t) ∈ X × R > .
By the fiber lemma for o-minimal dimension, dim(Q) < 2 dim(X) + 1. Now we get a lower bound on dim Q.
Corollary 7.17 We have the following: Proof: (i) follows immediately from Lemma 7.16. (iii) follows from (i) and Lemma 7.16. We prove (ii) by induction on dim(X). If dim(X) = 0 we can take the X to be the singleton subsets of X. Suppose dim(X) > 0. Let C be the set of points at which id : (X, d) → (X, e) is continuous. We can apply the inductive assumption to (X \ C, d) and partition X \ C into cells X 1 , . . . , X n such that id : (X i , d) → (X i , e) is continuous for every i. We then take some partition of C into cells X n+1 , . . . , X m . Let X = {X 1 , . . . , X n , X n+1 , . . . , X m }. We now prove (iv). Let V ⊆ X be the set of points at which both id : (X, e) → (X, d) and id : (X, d) → (X, e) are continuous. Then id : (V, d) → (V, e) is a homeomorphism. (iii) implies dim(X \ V ) < dim(X). So dim(V ) = dim(X), so Lemma 7.15 implies that the d-interior of V is almost all of V . We let V ′ be the intersection of the d-interior of V with the e-interior of V in X. Then V ′ is almost all of V and id : (v) is proven in the same way as (ii). We prove (vi) using (v). Let X be the partition provided by (v) and let X ′ be the disjoint union of the elements of X . Let d ′ be the natural pushforward of d onto X ′ . Then id : (X ′ , e) → (X ′ , d) is continuous. X ′ is locally closed as it is a disjoint union of cells.
The next lemma is immediate from (iv) above and cell decomposition: Lemma 7.18 Let dim(X) = l. Suppose that dim x (X, d) = l at almost every x ∈ X. There is a definable injection ((0, 1) l , e) → (X, d) which gives a homeomorphism between (0, 1) l and a d-open subset of X.
Proposition 7.19 Every definably separable metric space is definably homeomorphic to a definable subspace of a definably compact metric space.
To prove Propostion 7.19 it suffices to show that a definably separable (X, d) is definably isometric to a definable metric space for which the map ι is a homeomorphism onto its image; this shows that (X, d) is definably homeomorphic to a definable subspace of a definably compact metric space. This is established by the lemma below and Corollary 7.17.
Lemma 7.20 Suppose that id : (X, e) → (X, d) is continuous. Then the topologies given by d and d H agree.
Proof: Continuity of id : (X, e) → (X, d) implies that (X, d) is blue, thus it is enough to show that id : (X, d H ) → (X, d) is continuous. Let x ∈ X and δ > 0. Let ǫ > 0 be such that for all y ∈ Y , if e(x, y) < ǫ then d(x, y) < δ. We assume that ǫ < δ. Suppose that d H (x, y) < ǫ. There is a point on Graph(d y ) whose euclidean distance from (x, 0) is at most ǫ. Namely we have a x ′ such that the euclidean distance between (x, 0) and (x ′ , d y (x ′ )) is at most ǫ. This implies that e(x, x ′ ) < ǫ and that d(y, x ′ ) < ǫ. So d(x, x ′ ) < δ and the triangle inequality gives d(x, y) < ǫ + δ < 2δ. So id : (X, d H ) → (X, d) is continuous.
To prove Theorem 7.1 it now suffices to show that every definably compact metric space is definably homeomorphic to a definable set equipped with its euclidean metric. This is done in the next subsection.

Covering Definably Compact Metric Spaces
In this subsection (X, d) is a definably compact metric space. We want to show that: Claim 7.21 There are definably compact sets Z 1 , . . . , Z n and definable continuous maps ρ i : (Z i , e) → (X, d) whose images cover X.
Suppose that we have such Z i and ρ i . Let Z be the disjoint union of the Z i and let ρ : (Z, e) → (X, d) be the map induced by the ρ i . Then (Z, e) is definably compact and ρ is continuous, Lemma 5.7 gives a definable set Y and a definable homeomorphism (X, d) → (Y, e). Our construction of the Z i is an application of the definable Michael's Selection Theorem, Theorem 4.1 of [AT13], which we now recall. Let T ⊆ E × R m . We say that T is lower semi-continuous if for every (x, y) ∈ T and neighborhood V ⊆ R m of y there is a neighborhood U of x such that T y ∩ V = ∅ for every y ∈ U.
Theorem 7.22 (Aschenbrenner-Thamrongtanyalak) Let E be a definable locally closed set and let T ⊆ E × R m be definable and lower semi-continuous such that each T x is closed and convex. Then there is a definable continuous function σ : E → R m such that σ(x) ∈ T x always.
We will use the following lemma to apply Michael Selection: Lemma 7.23 Let E ⊆ R l and let S ⊆ E × R m be lower semi-continuous. Let T ⊆ E × R m be such that for every x ∈ E, T x is the closure of the convex hull of S x in R m . Then T is lower semi-continuous.
Proof: Fix x ∈ E and let V be an open subset of R m such that T x ∩V = ∅. The intersection of V with the convex hull of S x is nonempty, hence there are p, p ′ ∈ S x and s ∈ (0, 1) such that sp + (1 − s)p ′ ∈ V . There are open W, W ′ ⊆ R m such that p ∈ W , p ′ ∈ W ′ and if (q, q ′ ) ∈ W × W ′ then sq + (1 − s)q ′ ∈ V . Let U be a neighborhood of x such that if y ∈ U then S y ∩ W and S y ∩ W ′ are both nonempty. Fix q ∈ S y ∩ W and q ′ ∈ S y ∩ W ′ . Then sq + (1 − s)q ′ is an element of T y ∩ V . So T is lower semi-continuous.
We now prove Claim 7.21.
Proof: As it suffices to prove the claim for any definable metric space definably isometric to (X, d) we assume that X is a bounded subset of euclidean space. We apply induction on dim(X). The base case dim(X) = 0 is trivial, we treat the case dim(X) > 0. Applying Proposition 7.17 we partition X into cells X 1 , . . . , X n such that each id : (X i , d) → (X i , e) is a homeomorphism. For each i we construct a definably compact definable set Z i and a definable continuous surjection Fix i. To simplify notation we let C = X i and A = ∂ d (C). As (C, e) is locally definably compact so (C, d) is locally definably compact. By Lemma 5.2 this implies that C is a locally closed subset of X. Then C is open in cl d (C), so A is a d-closed subset of X. Thus (A, d) is definably compact. By Lemma 7.15 we have dim(A) < dim(X), so we apply the inductive assumption to (A, d). We let A ′ ⊆ R m be a definably compact subset of euclidean space and let τ : (A, d) → (A ′ , e) be a homeomorphism. We let Y be the disjoint union of X i and A ′ . We define τ ′ : cl d (X i ) → Y to be identity on X i and τ on A. We let d ′ be the pushforward of d by τ . Then (Y, d ′ ) is definably isometric to (cl d (X i ), d), so it suffices to construct a definable continuous surjection ρ : (Z, e) → (Y, d ′ ) from a definably compact Z. We assume without loss of generality that the d-and e-topologies agree on A. Then A is a definably compact subset of euclidean space. We use the definable Michael's Selection Theorem to construct a bounded continuous definable function σ : C → R m which satisfies the following for any path γ in C: if γ d-converges to x ∈ A then lim t→0 We first suppose we have such a σ. Let Z be the closure of Graph(σ) in the ambient euclidean space. Boundedness of C and σ ensures that Z is definably compact. Let π 1 : Z → C and π 2 : Z → R m be the coordinate projections. We define a map ρ : Z → cl d (C) by setting ρ(x) = π 1 (x) when x ∈ Graph(σ) and ρ(x) = π 2 (x) when x ∈ ∂ e [Graph(σ)]. First we must show that ρ does in fact take values in cl d (C). It suffices to show that π 2 (x) ∈ A when x ∈ ∂ e [Graph(σ)], to this effect fix such an x. Let γ be a path in Graph(σ) which e-converges to x. Then π 1 • γ is a path in C which by definable compactness must d-converge to some y ∈ cl d (C). This y must be an element of A, otherwise π 1 • γ would e-converge to an element of C and the continuity of σ would force x ∈ Graph(σ). We have We have shown that ρ takes values in cl d (C). We now show that ρ is surjective. As C is obviously contained in the image of ρ it suffices to show that A is contained in the image of ρ. Let y ∈ A. Applying definable choice let γ be a path in C which d-converges to y. We have lim t→0 + (σ • γ)(t) = y. Letting z be the e-limit of (f (t), (σ • γ)(t)) as t → 0 + we have z ∈ Z and ρ(z) = y.
We finally construct σ. Let B ⊆ C × R m be the set of (x, y) such that y ∈ A and d(y, x) < 2d(A, x). As A is d-closed, d(A, x) is always strictly positive, so B x is always nonempty. We show that B is lower semi-continuous. Fix z, y ∈ C satisfying y ∈ B z . By the definition of B, d(y, z) < 2d(A, z). We show that if z ′ ∈ C satisfies d(z, z ′ ) < 1 4 |2d(A, z) − d(y, z)| then y ∈ B z ′ . As the set of such z ′ is an e-open subset of C this gives lower semi-continuity. We have These two inequalities give d(y, z ′ ) < 2d(A, z ′ ) so y ∈ B z ′ . Let D ⊆ X × R m be the definable set such that for each x ∈ C, D x is the closure of the convex hull of B x . Each D x is closed and convex and D is lower semi-continuous. Applying the Michael's Selection Theorem let σ : C → R m be a continuous definable map such that σ(x) ∈ D x holds for all x ∈ C. Fix a path γ in C which d-converges to x ∈ A. We show that lim t→0 + (σ • γ)(t) = x. Towards this we show that B γ(t) is contained in the d-ball with center x and radius 3d(x, γ(t)). Fix w ∈ B γ(t) . By definition of B we have d(w, γ(t)) < 2d(A, γ(t)). As x ∈ A we have d(A, γ(t)) d(x, γ(t)) and we compute: As (A, d) is definably compact and the d-topology agrees with the e-topology on A, we apply Lemma 5.6 to produce a definable h : R → R satisfying y − y ′ h(d(y, y ′ )) for all y, y ′ ∈ A and such that lim t→0 + h(t) = 0. We let r(t) = h(3d(γ(t), x)). Then r(t) → 0 as t → 0 + and B γ(t) ⊆ B e (x, r(t)) for all t ∈ R > . As euclidean balls are convex, Thus (σ • γ)(t) − x r(t). The path σ • γ e-converges to x.
This completes the proof of Theorem 7.1. The uniform version of Theorem 7.1 given below follows by applying model-theoretic compactness and the existence of definable Skolem functions in the usual way: Corollary 7.24 Let {(X α , d α ) : α ∈ R l } be a definable family of metric spaces. The set of α ∈ R l such that (X α , d α ) is definably separable is definable. In fact, there is a definable family {A α : α ∈ R l } of sets such that A α ⊆ X α , a definable family of sets {Z α : α ∈ R l } and a definable family of functions h α : X α → Z α such that for every α ∈ R l exactly one of the following holds: The set of α for which h α gives such a homeomorphism is definable.
Recall our standing assumption that (X, d) is definably compact. Combining Corollary 7.14 and Theorem 7.1 we have:

Product Structure of General Definable Metric Spaces
In this section we prove Proposition 8.1. As an application in the next section we prove Corollary 9.5, which characterizes the topological dimension of a metric space definable in an o-minimal expansion of the real field. where I is an open interval, n dim(X), and D is a definable set. If n = dim(X) then we can take D to be a singleton.
Proof: Let dim(X) = m. It suffices to prove the proposition for any definable metric space definably isometric to (X, d) as any definable isometry (X, d) → (X ′ , d ′ ) locally gives a homeomorphism (X, e) → (X ′ , e) at almost every point. Therefore after applying Corollary 7.25 we assume that id : ( is a homeomorphism and the proposition holds with D a singleton. We therefore assume that n < m. Let f : W → R > be a definable function such that dim B(p, f (p)) = n for all p ∈ W . For x ∈ W let B x = B(x, f (x)). Applying a version of the good directions lemma in the same way as in the proof Lemma 7.3 we let π : W → R n be a linear projection and W ′ ⊆ W be an e-open m-dimensional definable set such that |π −1 (w) ∩ B x | < ∞ for all w ∈ R n , x ∈ W.
After replacing W with W ′ if necessary we suppose that these properties hold for W . As in the proof of Lemma 7.3 each fiber of π is d-discrete. For all x ∈ W there is a t ∈ R > such that d(x, y) > t whenever y ∈ W is distinct from x and satisfies π(x) = π(y). After applying Lemma 2.1 and replacing W with a smaller m-dimensional open set if necessary we fix a t > 0 such that if x, y ∈ W and π(x) = π(y) then d(x, y) > t. After replacing f with the function max{f, 1 2 t} if necessary we suppose that each B x has radius at most 1 2 t. Note that we still have dim(B x ) = n and dim y (B x ) = n at all y ∈ B x . As Diam d (B x ) < t the restriction of π to each B x is injective. Furthermore if B x ∩ B y = ∅ then the triangle inquality implies d(x, y) < t. Thus if π(x) = π(y) then B x and B y have empty intersection. Injectivity of π on B x implies dim π(B x ) = n. As dim π(W ) = n the fiber lemma for o-minimal dimension gives that some fiber of π is (m − n)-dimensional. We fix an (m − n)-dimensional fiber F ⊆ W and let G = x∈F B x . As the union is disjoint dim(G) = m. As dim y (B x , d) = n at every y ∈ B x we apply Lemma 7.18 uniformly we take β : F × (0, 1) n → G to be a definable function such that for each x ∈ F , β x [(0, 1) n ] is an e-open subset of B x and β x : ((0, 1) n , e) → (β x (I n ), d) is a homeomorphism for each x ∈ W . We fix a definable D ⊆ F with dim(D) = m − n and an interval I ⊆ (0, 1) such that the restriction of β to D × I n gives a continuous map between euclidean topologies. We now replace β with the restriction of β to D × I n . By the o-minimal open mapping theorem, see [Woe96] or [Joh01], β(D × I n ) is an e-open subset of W . We let U = β(D × I n ). U is a d-open subset of X. Then (U, d) is, as a topological space, the disjoint union of the sets β({b} × I n ). It follows that β : (D, d disc ) × (I n , e) → (U, d) is a homeomorphism.
The following two corollaries are weakenings of the previous proposition. We see in particular that every definable metric space is "almost locally definably compact".
Theorem 8.2 Let (X, d) be an arbitrary definable metric space. Almost every x ∈ X has a d-neighborhood U such that id : (U, d) → (U, e) is a homeomorphism.
Theorem 8. 3 Almost every x ∈ X has a d-neighborhood which is definably homeomorphic to an open subset of some R k .
Note that we could have k = 0.

Topological Dimension of Definable Metric Spaces
In this section we assume that R expands the ordered field of real numbers. We describe the topological dimension of a definable metric space (X, d). We first recall the definition and some facts about topological dimension. The notion of topological dimension that we use is frequently called the "small inductive dimension".

Topological Dimension
In this subsection X is a topological space. We inductively define the topological dimension, dim tp (X), of X: 1. dim tp (X) = −1 if and only if X = ∅.

dim tp (X)
n if and only if X has a neighborhood basis consisting of sets whose boundaries have topological dimension at most n − 1, and dim tp (X) ∈ N ∪ {∞} is the least n such that dim tp (X) n. We will need four facts about the topological dimension. The first can be proven with an easy inductive argument: The second is essentially trivial: Fact 9.2 Let {X i : i ∈ I} be a family of topological space and suppose X is the disjoint union of the X i . Then dim tp (X) = sup{dim tp (X i ) : i ∈ I}.
The last two require more effort, see [HW41] for a full account.
Fact 9.3 The topological dimension of R n equipped with the euclidean topology is n.

Topological Dimension of Definable Metric Spaces
In this subsection (X, d) is a definable metric space.
Theorem 9.5 The topological dimension of (X, d) is the maximal m for which there is a definable continuous injection (I m , e) → (X, d) for an open interval I ⊆ R.
There is no definable continuous injection (I m , e) → (A, d), so the inductive assumption implies that dim tp (A, d) < m. As (U, e) is separable we can cover U with countably many e-closed definable sets {F i : i ∈ N} such that each F i is contained in an e-open V ⊆ X which satisfies the conditions on V in the statement. If V satisfies the conditions in the statement by Fact 9.2 then dim tp (V, d) = dim(C) < m, so dim tp (F i , d) < m. As Fact 9.4 gives dim tp (X, d) m.
As an immediate consequence we have: Corollary 9.6 dim tp (X, d) dim(X).