Angles between curves in metric measure spaces

The goal of the paper is to study the angle between two curves in the framework of metric (and metric measure) spaces. More precisely, we give a new notion of angle between two curves in a metric space. Such a notion has a natural interplay with optimal transportation and is particularly well suited for metric measure spaces satisfying the curvature-dimension condition. Indeed one of the main results is the validity of the cosine formula on $RCD^{*}(K,N)$ metric measure spaces. As a consequence, the new introduced notions are compatible with the corresponding classical ones for Riemannian manifolds, Ricci limit spaces and Alexandrov spaces.


Introduction
The 'angle' between two curves is a basic concept of mathematics, which aims to quantify the infinitesimal distance between two crossing curves at a crossing point. Such a notion is classical in Euclidean and in Riemannian geometries where a global (respectively infinitesimal) scalar product is given: the cosine of the angle between two crossing curves is by definition the scalar product of the velocity vectors. If the space is not given an infinitesimal scalar product, it is a challenging problem to define angles in a sensible way. In this paper, we will study this problem in a metric (measure) sense. More precisely, consider a metric space (X, d), a point p ∈ X, and two geodesics γ, η such that γ 0 = η 0 = p. Our task is to propose a meaningful definition of the angle between the curves γ, η at the point p, denoted by ∠γpη, and to establish some interesting properties.
We recall some examples first. Assume that γ and η are geodesics, and the space (X, d) is an Alexandrov space, with upper or lower curvature bounds. From the monotonicity implied by the Date Alexandrov condition, it is known (see for instance [7]) that the angle ∠γpη is well defined by the cosine formula: In order to define the angle for geodesics in a more general framework, a crucial observation is that a geodesic can be seen as gradient flow of the distance function, i.e. a geodesic γ 'represents' the gradient of −d(γ 0 , γ 1 ) d(γ 1 , ·) on each point γ t . Inspired by the seminal work of De Giorgi on gradient flows [15], given an arbitrary metric space (X, d) with a geodesic γ : [0, 1] → X and a Lipschitz function f : X → R, we say that γ represents ∇f at time 0, or γ represents the gradient of the function f at the point p = γ(0) if the following inequality holds where |γ| = d(γ 0 , γ 1 ) is the (constant, metric) speed of the geodesic γ. Notice that the opposite inequality is always true by Leibniz rule and Cauchy-Schwartz inequality. Hence γ represents ∇f at time 0 if and only if the equality holds. It is easily seen that the geodesic γ always represents the gradient of f γ (·) := −d(γ 0 , γ 1 ) d(γ 1 , ·) at the point γ 0 (see for instance Lemma 3.5). We then say that the angle ∠γpη between two geodesics γ, η with γ 0 = η 0 = p exists if the limit lim t↓0 fγ (ηt)−fγ (η0) t exists. In this case we set Notice that in case (X, d) is the metric space associated to a smooth Riemannian manifold (M, g), the definition (1.1) reduces to the familiar notion of angle Besides the case of Alexandrov spaces, a class of spaces where the angle is particularly well behaved is the one of Lipschitz-infinitesimally Hillbertian spaces. By definition, a metric measure space (X, d, m) is Lipschitz-infinitesimally Hillbertian if for any pair of Lipschitz functions f, g : X → R both the limits for ε → 0 of |lip(f +εg)| 2 (x)−|lip(f )| 2 (x) 2ε and |lip(g+εf )| 2 (x)−|lip(g)| 2 (x) 2ε exist and are equal for m-a.e. x ∈ X, where lip(f ) is the local Lipschitz constant of f (for the standard definition see (2.1)). A remarkable example of Lipschitz-infinitesimally Hillbertian spaces is given by the RCD * (K, N )-spaces, a class of metric measure spaces satisfying Ricci curvature lower bound by K ∈ R and dimension upper bound by N ∈ (1, ∞) in a synthetic sense such that the Laplacian is linear, and which include as notable subclasses the Alexandrov spaces with curvature bounded below and the Ricci limit spaces (i.e. pointed measured Gromov-Hausdorff limits of sequences of Riemannian manifolds with uniform lower Ricci curvature bounds). In the class of Lipschitz-infinitesimally Hillbertian spaces, the second author [26] introduced a notion of 'angle between three points'; more precisely for every fixed pair of points p, q ∈ X, for m-a.e. x ∈ X the angle ∠pxq given by the formula (1.2) [0, π] ∋ ∠pxq := arccos lim ε→0 |lip(r p + εr q )| 2 (x) − |lip(r p )| 2 (x) 2ε , is well defined, unique, and symmetric in p and q. Here r p (·) := d(p, ·) is the distance function from p. A first result of the present paper is to relate the angle between three points with the angle between two geodesics: in Theorem 3.9 we prove that if the angle ∠pxq exists in the sense of [26] then also the angle between the geodesics γ xp , γ xq joining x to p and x to q exists and coincides with the angle between the three points, i.e. ∠γ xp xγ xq = ∠pxq. In particular it follows that in a Lipschitz-infinitesimally Hilbertian geodesic space the angle between two geodesics in well defined in an a.e. sense.
An important class of metric spaces are the spaces of probability measures over metric spaces endowed with the quadratic transportation distance: given a metric space (X, d) denote by W 2 := (P 2 (X), W 2 ) the corresponding Wasserstein space. By using ideas similar to the ones above, together with Otto Calculus (see [28]) and the calculus tools developed by Ambrosio-Gigli-Savaré [2] and Gigli [17], in Subsection 3.3 we study in detail the angle between two geodesics in W 2 . In particular if the underlying space (X, d, m) is an RCD * (K, N ) space, we get the angle ∠pxq between three points as the limit of the angle between the geodesics in W 2 obtained by joining geodesically diffused approximations of Dirac masses centered at p, x and q (see Proposition 3.15 for the precise statement; see also Proposition 3.17 for a more detailed link with the optimal transport picture).
Besides the case of Alexandrov spaces, another class of spaces where the notion of angle is quite well understood is given by Ricci limit spaces. Indeed it was proved by Honda [23] that if (X, d, m) is a Ricci-limit space, then for m-a.e. p ∈ X the angle between two geodesics is well defined and it satisfies the following one-variable cosine formula: One of the main goals of the present paper is to extend the validity of the formula (1.3) to metric measure spaces satisfying Ricci curvature lower bounds in a synthetic sense, the so-called RCD * (K, N )-spaces (for the definition and basic properties of such spaces see Section 2 and references therein). This is the content of the next theorem (corresponding to Theorem 4.4 in the body of the manuscript), which is one of the main results of the paper.
Theorem 1.1 (Cosine formula for angles in RCD * (K, N ) spaces). Let (X, d, m) be an RCD * (K, N ) space and fix p, q ∈ X. Then for m-a.e. x ∈ X there exist unique geodesics from x to p and from x to q denoted by γ xp , γ xq ∈ Geo(X) and The proof of Theorem 1.1 in independent and different from the one of Honda [23] for Ricci limit spaces: indeed Honda argues by getting estimates on the smooth approximating manifolds and then passes to the limit, while our proof for RCD * (K, N ) spaces goes by arguing directly on the non smooth space (X, d, m). More precisely, we perform a blow up argument centered at x and use that for m-a.e. x the tangent cone is unique and euclidean [21,27]. From the technical point of view we also make use of the fine convergence results for Sobolev functions proved in [4,20], and we prove estimates on harmonic approximations of distance functions (see in particular Proposition 4.3). Harmonic approximations of distance functions are well known for smooth Riemannian manifolds with lower Ricci curvature bounds, and are indeed one of the key technical tools in the Cheeger-Colding theory of Ricci limit spaces [12][13][14]; on the other hand for non-smooth RCD * (K, N )-spaces it seems they have not yet appeared in the literature, and we expect them to be a useful technical tool in the future development of the field. As a consequence of Theorem 1.1, we get that our definition of angle between two geodesics agrees (at least in a.e. sense) with the Alexandrov's definition in case (X, d) is an Alexandrov space, and with the Honda's definition [23] in case (X, d, m) is a Ricci limit space. We define the length of γ by where τ := {0 = t 0 , t 1 , ..., t n = 1} is a partition of [0, 1], and the sup is taken over all finite partitions. The space (X, d) is said to be a length space if for any x, y ∈ X we have where the infimum is taken over all γ ∈ C([0, 1], X) connecting x and y. A geodesic from x to y is a curve γ such that: The space of all geodesics on X will be denoted by Geo(X). It is a closed subset of C([0, 1], X).
It is known that (see for example [7]) the length of a curve γ ∈ AC([0, 1], X) can be computed as In particular, on a length space X we have where the infimum is taken among all γ ∈ AC([0, 1], X) which connect x and y.
if x is not isolated, 0 otherwise, while the (global) Lipschitz constant is defined as If (X, d) is a length space, we have Lip(f ) = sup x lip(f )(x).
We are not only interested in metric structures, but also in the interaction between metric and measure. For the metric measure space (X, d, m), basic assumptions used in this paper are: Assumption 2.1. The metric measure space (X, d, m) satisfies: • (X, d) is a complete and separable length space, • m is a non-negative Borel measure with respect to d and finite on bounded sets, • supp m = X.
In this paper, we will often assume that the metric measure space (X, d, m) satisfies the RCD * (K, N ) condition, for some K ∈ R and N ∈ [1, ∞] (when N = ∞ it is denoted by RCD(K, ∞) ). The RCD(K, ∞) and RCD * (K, N ) conditions are refinements of the curvature-dimensions proposed by Lott-Sturm-Villani (see [25] and [30,31] for CD(K, ∞)), and Bacher-Sturm (see [9] for CD * (K, N )) in order to isolate the non-smooth 'Riemannian' structures from the 'Finslerian' ones. More precisely, the RCD conditions are obtained by reinforcing the corresponding CD conditions by adding the requirement that the Sobolev space W 1,2 (X, d, m) is a Hilbert space (see the next subsection for more details). It is then clear that the following relations hold RCD * (K, N ) ⊂ CD * (K, N ) and RCD(K, ∞) ⊂ CD(K, ∞); moreover one has that RCD * (K, N ) ⊂ RCD(K, ∞) and CD * (K, N ) ⊂ CD(K, ∞).
The space P 2 (X) is naturally endowed with the quadratic transportation distance W 2 defined by: where the inf is taken among all couplings π ∈ P(X × X) with marginals µ and ν, i.e. (P 1 ) ♯ π = µ and (P 2 ) ♯ π = ν where P i , i = 1, 2 are the projection maps onto the first and second coordinate respectively. The metric space (P 2 (X), W 2 ) will be denoted by W 2 . Let us recall that the infimum in the Kantorovich problem (2.2) is always attained by an optimal coupling π. We denote the set of optimal couplings between µ and ν by Opt(µ, ν). Below we recall some fundamental properties of the metric space W 2 we will use throughout the paper.
The set of optimal dynamical plans from µ 0 to µ 1 is denoted by OptGeo(µ 0 , µ 1 ). Moreover, if X is a geodesic space, then W 2 is also geodesic.
Absolutely continuous curves in W 2 are characterized by the following theorem: Theorem 2.3 (Superposition principle, [24]). Let (X, d) be a complete and separable metric space and let (µ t ) ∈ AC 2 ([0, 1], P 2 (X)). Then there exists a measure Π ∈ P(C([0, 1], X)) concentrated on AC 2 ([0, 1], X) such that: Moreover, the infimum of the energy Definition 2.4 (Test plan). Let (X, d, m) be a metric measure space and Π ∈ P(C([0, 1], X)). We say that Π ∈ P(C([0, 1], X)) has bounded compression provided there exists C > 0 such that We say that Π is a test plan if it has bounded compression, is concentrated on AC 2 ([0, 1], X) and The notion of Sobolev function is given in duality with that of test plan: Definition 2.5 (The Sobolev class S 2 (X)). Let (X, d, m) be a metric measure space. A Borel function f : X → R belongs to the Sobolev class S 2 (X) (resp. S 2 loc (X)) provided there exists a non-negative function G ∈ L 2 (X, m) (resp. L 2 loc (X, m)) such that In this case, G is called a 2-weak upper gradient of f , or simply weak upper gradient.
It is known, see e.g. [2], that there exists a minimal function G in the m-a.e. sense among all the weak upper gradients of f . We denote such minimal function by |Df | or |Df | X to emphasize which space we are considering and call it minimal weak upper gradient. Notice that if f is Lipschitz, It is known that the locality holds for |Df |, i.e. |Df | = |Dg| m-a.e. on the set {f = g}, moreover S 2 loc (X, d, m) is a vector space and the inequality holds for every f, g ∈ S 2 loc (X, d, m) and α, β ∈ R. Moreover, the space S 2 loc ∩ L ∞ loc (X, d, m) is an algebra, with the inequality being valid for any f, g ∈ S 2 loc ∩ L ∞ loc (X, d, m). The Sobolev space W 1,2 (X, d, m), also denoted by W 1,2 (X) for short, is defined as and is endowed with the norm On an infinitesimally Hilbertian space, we have a natural pointwise inner product ∇·, ∇ · : In order to prove the cosine formula we will use properties of harmonic functions in open sets of a m.m. space. Let us define the relevant quantities and recall the properties we will use; for simplicity, as always we assume the space (X, d) to be proper, complete and separable, and the measure m to be finite on bounded sets (this indeed is the geometric case correspoding to RCD * (K, N ) spaces, for N < ∞ we will be interested in). For the general case see for instance [6,17,19].  We say that f is in the domain of the Laplacian in Ω, and write f ∈ D(∆, Ω) provided f ∈ S 2 (Ω) and there exists a locally finite Borel measure µ on Ω such that for any ϕ ∈ LIP(X) with compact support contained in Ω it holds In this case the measure µ is unique and we denote it by ∆f Ω, or simply ∆f . If ∆f Ω ≪ m, we denote its density with respect to m by ∆f Ω or simply by ∆f . A function f ∈ D(∆, Ω) is said to be harmonic in Ω, or simply harmonic, if ∆f Ω = 0.
For simplicity we state the next proposition for RCD * (K, N ) space, though it is valid more generally for doubling spaces supporting a weak-local 1-2 Poincaré inequality (see [6] for details).
Proposition 2.8. Let (X, d, m) be a RCD * (K, N ) space, for some K ∈ R and N ∈ [1, ∞), and let Ω ⊂ X be a bounded open set. Then the following properties hold.
i) Regularity. Let f : Ω → R be harmonic in Ω. Then f admits a continuous representative (actually even locally Lipschitz).
ii) Existence and uniqueness of harmonic functions. Assume that m(X \ Ω) > 0 and let f ∈ W 1,2 (X). Then there exists a unique harmonic function g on Ω such that f − g ∈ W 1,2 0 (Ω). iv) Strong maximum principle. Let f : Ω → R be harmonic in Ω and assume that its continuous representative has a maximum at a point x 0 ∈ Ω. Then f is constant on the connected component of Ω containing x 0 .

Pointed measured Gromov-Hausdorff convergence and convergence of functions.
In order to study the convergence of possibly non-compact metric measure spaces, it is useful to fix reference points. We then say that (X, d, m,x) is a pointed metric measure space, p.m.m.s. for short, if (X, d, m) is a m.m.s. as before andx ∈ X plays the role of reference point. Recall that, for simplicity, we always assume supp m = X. We will adopt the following definition of convergence of p.m.m.s. (see [7], [20] and [32]): is said to converge in the pointed measured Gromov-Hausdorff topology (p-mGH for short) to where C b (Z) denotes the set of real valued bounded continuous functions with bounded support in Z.
Sometimes in the following, for simplicity of notation, we will identify the spaces X j with their isomorphic copies ι j (X j ) ⊂ Z. It is obvious that this is in fact a notion of convergence for isomorphism classes of p.m.m.s., moreover it is induced by a metric (see e.g. [20] for details). Next, following [20], we recall various notions of convergence of functions defined on p-mGH converging spaces. Definition 2.11 (Pointwise convergence of scalar valued functions). Let (X j , d j , m j ,x j ), j ∈ N ∪ {∞} be a p-mGH converging sequence of p.m.m.s. and let f j : X j → R, j ∈ N ∪ {∞} be a sequence of functions. We say that f j converge pointwise to f ∞ provided: we say that f j → f ∞ uniformly. Definition 2.12 (L 2 weak and strong convergence). Let (X j , d j , m j ,x j ), j ∈ N∪{∞} be a p-mGH converging sequence of pointed metric measure spaces and let f j ∈ L 2 (X j , m j ), j ∈ N ∪ {∞} be a sequence of functions.
• We say that (f j ) converges strongly in L 2 to f ∞ provided it converges weakly in L 2 to f ∞ and moreover lim j→∞ Xj Strong convergence in W 1,2 is defined by requiring L 2 -strong convergence of the functions and that lim j→∞ Xj The next result proved in [4,Corollary 5.5] (see also [20, Corollary 6.10]) will be useful in the sequel.
2.4. Euclidean tangent cones to RCD * (K, N ) spaces. Let us first recall the notion of measured tangents. Let (X, d, m) be a m.m.s.,x ∈ X and r ∈ (0, 1); we consider the rescaled and normalized p.m.m.s. (X, r −1 d, mx r ,x) where the measure mx r is given by Then we define: Definition 2.15 (Tangent cone and regularity).
as j → ∞ in the p-mGH sense. We denote the collection of all the tangents of (X, d, m) atx ∈ X by Tan(X, d, m,x). A pointx ∈ X is called regular if the tangent is unique and euclidean, i.e. if Tan(X, d, m,x) = {(R n , d E , L n , 0 n )}, where d E is the Euclidean distance and L n is the properly rescaled Lebesgue measure of R n . The a.e. regularity was settled for Ricci-limit spaces by Cheeger-Colding [12][13][14]; for an RCD * (K, N )space (X, d, m), it was proved in [21] that for m-a.e. x ∈ X there exists a blow-up sequence converging to a Euclidean space. The m-a.e. uniqueness of the blow-up limit, together with the rectifiability of an RCD * (K, N )-space, was then established in [27]. More precisely the following holds: Theorem 2.16 (m-a.e. infinitesimal regularity of RCD * (K, N )-spaces). Let (X, d, m) be an RCD * (K, N )-space for some K ∈ R , N ∈ (1, ∞). Then m-a.e. x ∈ X is a regular point, i.e. for m-a.e. x ∈ X there exists n = n(x) ∈ [1, N ] ∩ N such that, for any sequence r j ↓ 0, the rescaled pointed metric measure spaces (X, r −1 j d, m x rj , x) converge in the p-mGH sense to the pointed Euclidean space (R n , d E , L n , 0 n ).

Definition of angle
3.1. Angle between three points. In [26], the second author proposed a notion of angle between three points p, x, q ∈ X in a metric space (X, d). In general such an angle is non unique, the possible causes of non-uniqueness being a lack of regularity of the distance function (e.g. x is in the cut locus of p or q) or a lack of infinitesimal strict convexity of the distance function (for more details we refer to [26,Sections 1,2]). For simplicity, here we only treat the case when the angle is unique. Given two points p, q ∈ X, consider the distance functions Definition 3.1. We say that the angle ∠pxq exists if and only if the limit for ε → 0 of the quantity exists. In this case we set Note that if (X, d) is a smooth Riemannian manifold and x is not in the cut locus of p and q, then ∠pxq is the angle based at x between ∇r p (x) and ∇r q (x); in other words ∠pxq is the angle based at x "in direction of p and q". As already mentioned, for a general triple pxq in a general metric space (X, d) the angle ∠pxq may not exist; moreover, even if both ∠pxq and ∠qxp exist they may not be equal in general. On the other hand, such a definition satisfies some natural properties one expects from the geometric picture: the angle is invariant under a constant rescaling of the metric d, moreover for any two points x, p ∈ X the angle ∠pxp always exists and, if (X, d) is a length space, is equal to 0.
We now discuss an important class of metric measure spaces (X, d, m) where the angle exists and is symmetric in an a.e. sense, the so called Lipschitz-infinitesimally Hilbertian spaces. Definition 3.2. A metric measure space (X, d, m) is said to be Lipschitz-infinitesimally Hilbertian if for any pair of Lipschitz functions f, g ∈ LIP(X) both the limits for ε → 0 of (|lip(f +εg)| 2 (x)−|lip(f )| 2 (x) 2ε and |lip(g+εf )| 2 (x)−|lip(g)| 2 (x) 2ε exist and are equal for m-a.e. x ∈ X, i.e.
It is clear that if (X, d, m) is Lipschitz-infinitesimally Hilbertian then, given p, q ∈ X, for m-a.e. x ∈ X both the angles ∠pxq, ∠qxp exist and ∠pxq = ∠qxp.
Remark 3.3. The concept of Lipschitz-infinitesimally Hilbertian space was proposed in [26] as a variant of the notion of infinitesimally Hilbertian space introduced in [3,17], using the language of minimal weak upper gradients; let us mention that Lipschitz-infinitesimally Hilbertian always implies infinitesimally Hilbertian, but the converse is not clear in general. An important class of spaces where also the converse implication holds is the one of locally doubling spaces satisfying a weak Poincaré inequality. Indeed, by a celebrated result of Cheeger [11], we have that for every f ∈ LIP(X) it holds lip(f ) = |Df | m-a.e., in other words the local Lipschitz constant is equal to the minimal weak upper gradient m-a.e. In particular for CD * (K, N ) spaces, K ∈ R, N ∈ [1, ∞) the two notions are equivalent. For more details we refer to [26,Remark 3.3]. It follows that RCD * (K, N )-spaces are Lipschitz-infinitesimally Hilbertian, for N < ∞; let us recall that the class of RCD * (K, N )-spaces include finite dimensional Alexandrov spaces with curvature bounded below and Ricci limit spaces as remarkable sub-classes.

Angle between two geodesics.
First of all observe that if (X, d) is a metric space and γ ∈ Geo(X) is a geodesic, then |γ t | = d(γ 0 , γ 1 ) for a.e. t ∈ [0, 1]; we will denote such a constant simply by |γ|. The next definition is inspired by the De Giorgi's metric concept of gradient flow [15]. Definition 3.4 (A geodesic representing the gradient of a Lipschitz function). Let f ∈ LIP(X) be a Lipschitz function on (X, d). We say that γ ∈ Geo(X) represents ∇f at time 0, or γ ∈ Geo(X) represents the gradient of f at the point x = γ 0 if the following inequality holds Notice that the opposite inequality is always true, indeed Hence γ ∈ Geo(X) represents ∇f at time 0 if and only if the equality holds. Note that, in the case of Riemannian manifolds, γ represents ∇f at time 0 if and only ifγ 0 = ∇f . It is easy to check that the geodesic γ ∈ Geo(X) represents the gradient of f ∈ LIP(X) at x ∈ X if and only if for every α ∈ (0, 1) the rescaled geodesicγ ∈ Geo(X) defined byγ t := γ αt , ∀t ∈ [0, 1], represents the gradient of the Lipschitz function αf at x. In the next lemma we give a simple but important example of a geodesic representing the gradient of a function.
Lemma 3.5. Let (X, d) be a metric space, fix p ∈ X and let r p (·) := d(p, ·). If for some x ∈ X there exists a geodesic γ xp ∈ Geo(X) such that γ 0 = x and γ 1 = p then γ xp represents the gradient of f (·) := −d(p, x) r p (·) at x.
Proof. For every t ∈ (0, 1) it holds On the other hand, by triangle inequality it is clear that lip(r p ) ≤ 1 and with an analogous argument as above it is easily checked that actually lip(r p )(x) = 1. Therefore lip(f )(x) = d(p, x) =: |γ xp | and the claim follows.
We can now define the angle between two geodesics. Definition 3.6 (Angle between two geodesics). Let (X, d) be a metric space and let γ, η ∈ Geo(X) be two geodesics with γ 0 = η 0 = p. Let f ∈ LIP (X) be a Lipschitz function such that γ represents the gradient of f at time 0. We say that the angle ∠ηpγ exists if and only if the limit as t ↓ 0 of exists. In this case we set Remark 3.7 (Locality of the angle between two geodesics). It is easily seen that the angle between the two geodesics γ, η ∈ Geo(X) at the point p = γ 0 = η 0 depend just on the germs of the curves at p. To see that, fix arbitrary T γ , T η ∈ (0, 1) and callγ,η the restrictions of γ, η to [0, T γ ], [0, T η ] properly rescaled, i.e:γ (t) := γ(T γ t),η(t) := η(T η t), ∀t ∈ [0, 1]. Of course we still haveγ,η ∈ Geo(X), and it is readily seen thatγ represents the gradient of f := T γ f . It follows that ∠ηpγ exists if and only if ∠ηpγ exists, and in this case it holds Remark 3.8 (Dependence on the function f ). 1 Note also in the generality of metric spaces, the angle ∠γpη as given in Definition 3.6 may depend on the function f chosen in (3.5) (for instance this is the case of a tree with a vertex in p and two edges made by γ and η). In case (X, d, m) is an RCD * (K, N )-space we will see later in the paper that actually the angle between two geodesics is well defined for m-a.e. base point p just in terms of the geometric data, so it does not depend on the choice of f . In the general case of a metric space, a way to overcome the problem would be to fix a canonical Lipschitz function f such that γ represents ∇f at time 0. In view of Lemma 3.5, a natural choice is to consider f γ (·) := −d(γ 0 , γ 1 )d(γ 1 , ·). In case (X, d, m) is not an RCD * (K, N ) space we will tacitly make such a choice so to have a good definition.
The next goal is to relate the angle between three points with the angle between two geodesics, i.e. relate Definitions 3.1 and 3.6. Theorem 3.9. 2 Let (X, d) be a metric space and let p, x, q ∈ X satisfy the following assumptions: • the angle ∠pxq exists in the sense of Definition 3.1, • there exists geodesic γ xp , γ xq ∈ Geo(X) from x to p and from x to q respectively.
Note that if (X, d) is a geodesic Lipschitz-infinitesimally Hilbertian space then for every given p, q ∈ X the two assumptions of Theorem 3.9 are satisfied for m-a.e. x ∈ X. This is in particular the case for RCD * (K, N ) spaces (see Remark 3.3).
Proof. Without loss of generality we can assume that d(p, x) ≤ d(q, x), otherwise just exchange the role of p and q in the arguments below. Let f p (·) := −d(p, x) r p (·) and f q (·) := −d(p, x) r q (·). Recall from Lemma 3.5 that γ xp represents ∇f p at x = γ xp 0 in the sense of Definition 3.4, i.e.
On the other hand If ε > 0, dividing both sides by εd(p, x) 2 and letting ε ↓ 0 we get where in the last identity we used the assumption that ∠pxq exists. Analogously, if ε < 0, dividing both sides by εd(p, x) 2 and letting ε ↑ 0 we get The combination of the last two inequalities gives the existence of the limit for t ↓ 0 of 1 and, more precisely, Since by Lemma 3.5 we know that γ xq represents the gradient of −d(q, x)r q (·) = d(q,x) d(p,x) f q (·) at x = γ xq 0 in the sense of Definition 3.4, we get that the rescaled geodesicγ xq defined byγ xq t := γ xq ∀t ∈ [0, 1], represents the gradient of f q at x =γ xq 0 . Therefore ∠γ xp xγ xq exists in the sense of Definition 3.6 and ∠γ xp xγ xq = ∠pxq; recalling the locality of the angle between geodesics (see Remark 3.7), we conclude that ∠γ xp xγ xq = ∠γ xp xγ xq exists in the sense of Definition 3.6 and ∠γ xp xγ xq = ∠pxq.

Angles in Wasserstein spaces.
In the Wasserstein space, we have the notion of "Plans representing gradients" which is similar to the one of "geodesic representing the gradient" above. Definition 3.10 (Plans representing gradients, see [17]). Let (X, d, m) be a metric measure space, g ∈ S 2 (X) and Π ∈ P(C([0, 1], X)) be a test plan. We say that Π represents the gradient of g if Let (µ t ) ∈ AC 2 ([0, 1], P 2 (X)) be with uniformly bounded densities, Π be its lifting given by Theorem 2.3, and let ϕ ∈ S 2 (X). In case (X, d, m) is infinitesimally Hilbertian, it is proved in [18,Theorem 4.6] that Π represents the gradient of ϕ if and only if If (3.10) holds, we also say that the velocity field of µ t at time 0 is ∇ϕ.
Combing the above technical tools with ideas from Otto's calculus [28], we can define the angle between two geodesics in W 2 .
From the formula (3.10), we can see that the value of the angle does not depend on the choice of f, g, but just on (µ t ), (ν t ).
Thanks to the locality expressed in Remark 3.12, given two curves (µ t ) t∈[0,1] , (ν t ) t∈[0,1] such that they are of bounded compression once restricted to [0, T ] for some T ∈ (0, 1), we can define the angle between them as the angle between their restrictionsμ,ν to [0, T ]. This will be always tacitly assumed throughout the paper.
Note that, thanks to Otto calculus and (3.10), Definition 3.13 is the analog for W 2 geometry of the angle between two geodesics in a general metric space in the sense of Definition 3.6.
3.4. The case of RCD * (K, N ) spaces. In Theorem 3.9 we related the angle between three points with the angle between two geodesics, i.e. we related Definitions 3.1 and 3.6. Now, adding a curvature assumption on the space, we wish to relate Definition 3.13 with Definition 3.1 and Definition 3.6, i.e. the angle between two geodesics in W 2 with the angle between three points and the angle between two geodesics of X. To this aim the next lemma will be useful.
Lemma 3.14. Let (X, d, m) be an RCD * (K, N ) space, and let ϕ 1 , ϕ 2 be locally Lipschitz functions on X. Then the functions are well defined at every x ∈ X and it holds Proof. From the definition of local Lipschitz constant we know that the function ǫ → |lip(ϕ 1 + ǫϕ 2 )| 2 (x) is convex for any x. Consider the function and observe that ǫ → F ǫ (x) is non-decreasing on (−∞, 0) and (0, +∞) for any fixed x. Hence F + and F − are well-defined for any point x ∈ X as Since (X, d, m) is a RCD * (K, N ) metric measure space, it holds a local Poincaré inequality and it is locally doubling. Then, from [11, Theorem 6.1], we know lip(f )(x) = |Df |(x) for m-a.e.
Remark 3.16. For uniformity with the rest of the paper we decided to state Proposition 3.15 for RCD * (K, N ) spaces, but using the results of [10] the same conclusion holds for essentially non-branching Lipschitz-infinitesimally Hilbertian spaces satisfying MCP(K, N ).
In the next result we relate Definition 3.6 with the optimal transport picture.
4. The cosine formula for angles in RCD * (K, N ) spaces The goal of this section is to prove Theorem 4.4, stating that the cosine formula holds for the angle between two geodesics in an RCD * (K, N ) space. The first lemma states the almost everywhere uniqueness and extendability of geodesics in RCD * (K, N ) spaces; this fact is already present in the literature under slightly different formulations so we just briefly sketch the proof. Then for m-a.e. x there exist unique geodesics γ xp , γ xq ∈ Geo(X) such that • both γ xp and γ xq are extendable to geodesicsγ xp andγ xq having x as interior point; in other words there existγ xp ,γ xq ∈ Geo(X) andt ∈ (0, 1) such thatγ xp t ,γ xq Proof.
Step 1. ∀p ∈ X, m-a.e. x ∈ X is an interior point of a geodesic with end point at p. Fix p ∈ X and R > 0. Consider m B R (p) and µ 1 := δ p .
Analyzing the optimal transport from µ 0 to µ 1 by following verbatim the proof of [21, Lemma 3.1] (i.e. use Jensen's inequality and the convexity property of the entropy granted by the curvature condition), we get that for m-a.e. x ∈ B R (0) there exists a geodesic γ ∈ Geo(X) such that γ 1 = p and γ t = x, for some t ∈ (0, 1). The claim then follows by the arbitrariness of R > 0.
Step 2. ∀p ∈ X, m-a.e. x ∈ X there exists a unique geodesic from x to p. The uniqueness of geodesics connecting a fixed p ∈ X and m-a.e. x ∈ X is a consequence of [22,Theorem 3.5] applied to the optimal transportation from the measures µ 0 , µ 1 above.
Step 3. Applying steps 1 and 2 to p and q, since the union of two negligible sets is still negligible, the thesis follows.
The next lemma will be useful to get good estimates on harmonic approximations of distance functions. Proof. Since (X, d, m) is a RCD * (K, N ) metric measure space, it satisfies a local (1-2)-Poincaré inequality and it is locally doubling. It is also known [3, Remark 6.9 and Theorem 6.10] that the metric d is induced by the Dirichlet form f → |Df | 2 dm. Therefore the standing assumptions of [8] where c only depends on the constants in the Poincaré inequality and in the doubling condition. In our case, c only depends on N and K. Now, choosing f = 1 on B, we get that G := u f + c satisfies the thesis with C = 2c.
Using Lemma 4.2, in the next proposition we prove a key estimate in order to establish the cosine formula for angles.
Then there exists a harmonic approximation b p of b p with the following properties: Proof. From Proposition 2.8 we know there exists b p satisfying (1) of the thesis. Similarly, we can find a harmonic approximation bp of bp.
We are then left to show the validity of the estimate (4.1). To this aim, let G : B 1 (x 0 ) → R ≥0 be given by Lemma 4.2, so that where C(K, N ) depends only on K, N and in particular is independent of R. From Laplacian Comparison Theorem 2.9 we know that b p , bp ∈ D(∆, B 1 (x 0 )) and for some suitable Ψ : R 3 → R >0 satisfying lim R→+∞ Ψ(R|K, N ) = 0 for fixed K, N . Then we have Applying the comparison statement of Proposition 2.8 to (−b p + b p ) + ΨG we get that Analogously, applying the comparison statement of Proposition 2.8 to −bp + bp + ΨG we get By assumption, we know there exists a function Φ(R|K, N ) satisfying lim R→+∞ Φ(R|K, N ) = 0 for fixed K, N , such that 0 ≤ bp(x) + b p (x) ≤ Φ(R|K, N ) for any x ∈ B 1 (x 0 ). Using maximum principle of Proposition 2.8, we know for any x ∈ B 1 (x 0 ). The combination of the last three estimates gives Putting together (4.4) and (4.5), we get Next, write B = B 1 (x 0 ) for short. Recalling that ∆b p B = 0, combining (4.2) with (4.6) and using that (b p − b p ) ∈ W 1,2 0 (B) in order to integrate by parts, we obtain where we used that, since Summing up (4.6) and (4. Theorem 4.4. Let (X, d, m) be an RCD * (K, N ) space for some K ∈ R, N ∈ (1, ∞), and fix p, q ∈ X. Then for m-a.e. x ∈ X let γ xp , γ xq ∈ Geo(X) be the unique geodesics from x to p and from x to q given by Lemma 4.1. We may also assume that the tangent cone at x is unique and isomorphic as m.m. space to Let r i ↓ 0 be any sequence,p,q ∈ R k be the limit points of γ xp (r i ), γ xq (r i ) under the rescalings (X, r −1 i d, m x ri , x) which converge to (R k , d E , L k , O) in p-mGH sense. Then (4.8) ∠γ xp xγ xq = ∠pxq = ∠pOq = lim t↓0 arccos 2t 2 − d 2 (γ xp t , γ xq t ) 2t 2 , for m-a.e. x. Proof.
From the locality of the angle (see Remark 3.7) we know that (4.10) ∠pxq = ∠γ xp xγ xq = ∠(γ xp | s 0 ) x (γ xq | t 0 ), ∀s, t ∈ (0, 1), where (γ| s 0 ) t := γ st for all t ∈ [0, 1]. Let r i ↓ 0 be any sequence and let (X, r −1 i d, m x ri , x) be the corresponding sequence of rescaled spaces. Since by assumption x is regular, we know that (X, r −1 i d, m x ri , x) p-mGH converge to (R k , d E , L k , O) for some k = k(x) ∈ N ∩ [1, N ]. Since by assumption both γ xp and γ xq are extendable beyond x, they converge in p-GH sense to half lines ℓ p , ℓ q in R k such that O ∈ ℓ p ∩ ℓ q and both ℓ p , ℓ q are extendable to full lines of R k . We parametrize such half lines on [0, +∞) such that for every t > 0 one has that ℓ p (t), ℓ q (t) are the limit points of γ xp (r i t), γ xq (r i t) respectively.  The combination of (4.15), (4.16) and (4.17) yields Since by construction ∆b i p B di 1 (x) = 0, by Proposition 2.14 we get that But then the gradient estimates in (4.16)- (4.17) give that In particular, for every ρ ∈ (0, 1) we have (4.19) lim We now analyze the two sides of (4.19). Recalling (4.9), from the very definitions of m x ri and of d i it follows that ∇b p , ∇b q dm = ∠pxq. On the other hand, since b ∞ p , b ∞ q are the Busemann functions of the lines ℓ p , ℓ q in R k it is readily seen that (4.21) lim Putting together (4.19), (4.20) and (4.21) finally yields as desired.
Step 3. We claim that To this aim, first of all observe that the cosine formula in R k ensures that (4.23) ∠pOq = arccos 2 − d E (p,q) 2 .
It is natural to ask if the same formula holds in the non-smooth case. This remains an open problem even for Ricci limit spaces, so a fortiori in RCD * (K, N ) spaces.
Here let us briefly mention that with analogous arguments as above one can show the weaker statement (4.27) ∠pxq = lim s,t↓0, 1 C ≤ s t ≤C arccos s 2 + t 2 − d(γ xp s , γ xq t ) 2 2st , for every C ≥ 1.
To this aim let s i ↓ 0, t i ↓ 0 be any two sequences. Up to subsequences, we may assume that for all i ∈ N it holds either 0 ≤ s i ≤ t i or 0 ≤ t i ≤ s i . Without loss of generality we may assume the first case. Up to further subsequences we may also assume that s i /t i has a limits ∈ (0, 1] as i → ∞. Let r i := t i ↓ 0 and define the rescaled spaces (X, d i , x) as above, with d i (·, ·) := r −1 i d(·, ·). Calling s ′ i := r −1 i s i →s, t ′ i := r −1 i t i = 1, the p-GH convergence of (X, d i , x) to (R k , d E , O) ensures lim i→∞ d i (γ xp si , γ xq ti ) = d E (ℓ p (s),q).