Hardy inequalities and Assouad dimensions

We establish both sufficient and necessary conditions for weighted Hardy inequalities in metric spaces in terms of Assouad (co)dimensions. Our sufficient conditions in the case where the complement is thin are new, even in euclidean spaces, while in the case of a thick complement, we give new formulations for previously known sufficient conditions which reveal a natural duality between these two cases. Our necessary conditions are rather straight-forward generalizations from the unweighted case but, together with some examples, indicate the essential sharpness of our results. In addition, we consider the mixed case in which the complement may contain both thick and thin parts.


Introduction
Let X be a complete metric measure space. We say that an open set ⊂ X admits a (p, β)-Hardy inequality, if there exists a constant C > 0 such that holds for all u ∈ Lip 0 ( ) and for all upper gradients g u of u. Here, d (x) = dist(x, c ) is the distance from x ∈ to the complement c = X \ ; and, in the case X = R n , we have g u = |∇u|. There is a well-known dichotomy concerning domains admitting a Hardy inequality: either the complement of the domain is large (or "thick") or sufficiently "thin". For instance, if an open set ⊂ R n admits a (p, β)-Hardy inequality, then there exists δ > 0 such that for each ball B ⊂ R n , either dim H (2B ∩ c ) > n − p + β + δ or dim A (B ∩ c ) < n − p + β − δ ; see [23] (the case β = 0) and [25]. Here, dim H denotes the Hausdorff dimension and dim A is the (upper) Assouad dimension; see Section 2 for definitions.
Reflecting this dichotomy, we can give sufficient conditions for the validity of a (p, β)-Hardy inequality in both of the above cases. For thick complements, a canonical sufficient condition for the unweighted (β = 0) p-Hardy inequality in is the uniform p-fatness of c or, equivalently, a uniform Hausdorff content density condition for c ; see [31,36,22]. In R n , uniform p-fatness of c implies, in particular, that dim H (2B ∩ c ) > n − p for all balls centered at c . On the other hand, in the case of thin complements, the smallness of the (upper) Assouad dimension of the complement (dim A ( c ) < n − p) is known to be sufficient for the p-Hardy inequality; see [23,25] and note that in this case, these results are based on the works of Aikawa [1,3]. See also [7,20,22,28,29] for sufficient conditions for weighted Hardy inequalities and metric space versions of such results.
The main purpose of this paper is to sharpen the previously known sufficient conditions for the validity of Hardy inequalities in the case in which the complement is assumed to be thin. More precisely, we prove the following theorem in the setting of a doubling metric space X supporting certain Poincaré inequalities (cf. Section 2). Here, the thinness is formulated in terms of the so-called lower Assouad codimension of c (a metric space version of the (upper) Assouad dimension; see Section 2.) Theorem 1.1. Let 1 ≤ p < ∞ and β < p − 1, and assume that X is an unbounded doubling metric space. If β ≤ 0, assume further that X supports a p-Poincaré inequality; and if β > 0, assume that X supports a (p − β)-Poincaré inequality. If ⊂ X is an open set satisfying co dim A ( c ) > p − β, then admits a (p, β)-Hardy inequality.
In the unweighted case β = 0, which is the most important and most interesting, Theorem 1.1 shows that a p-Hardy inequality holds in under the assumptions that X supports a p-Poincaré inequality and co dim A ( c ) > p > 1; in a Q-regular space, the latter condition is equivalent to dim A ( c ) < Q − p. In particular, this gives a complete answer to a question of Koskela and Zhong [23,Remark 2.8]; see also Corollary 6.6 for an improvement concerning the boundary values of test-functions in Theorem 1.1.
In R n , the case β = 0 of Theorem 1.1 coincides with the above-mentioned results from [23,25], but our approach gives a completely new proof in this case. For β = 0, the result is new even in eulidean spaces. Our proof of Theorem 1.1 follows the general scheme of Wannebo [36]. We first prove (p, β)-Hardy inequalities for β < 0, with a suitable control for the constants in the inequalities for β close to 0, and then elementary -but slightly technical -integration tricks yield the inequalities for 0 ≤ β < p − 1.
Another goal of this work is to bring together much of the recent research on Hardy inequalities (see, e.g., [20,22,23,25,26,27,28,29,30]) in a unified manner in the setting of metric spaces. For instance, it was shown in [28] that an open set ⊂ X admits a (p, β)-Hardy inequality if the complement c satisfies a uniform density condition in terms of a Hausdorff content of codimension q < p − β. In the present paper, we establish a new characterization for the upper Assouad codimension by means of Hausdorff co-content density; see Corollary 5.2. (In Ahlfors regular spaces, such a characterization was observed in [18,Remark 3.2].) Consequently, we obtain the following sufficient condition for Hardy inequalities in terms of the upper Assouad codimension, which provides a natural counterpart for Theorem 1.1 and shows that there exists a nice "duality" between the sufficient conditions for the cases of thick and thin complements. Theorem 1.2. Let 1 < p < ∞ and β < p−1, and assume that X is a doubling metric space supporting a p-Poincaré inequality if β ≤ 0, and a (p − β)-Poincaré inequality if β > 0. Let ⊂ X be an open set satisfying co dim A ( c ) < p − β; and, in case is unbounded, assume that c is also unbounded. Then admits a (p, β)-Hardy inequality.
Since the euclidean space R n is n-regular and supports p-Poincaré inequalities whenever 1 ≤ p < ∞, for X = R n , the results of Theorems 1.1 and 1.2 can be formulated as follows. Here, dim A = dim A is the (upper) Assouad dimension and dim A is the lower Assouad dimension; see Section 2. In fact, Corollary 1.3 holds, with n replaced with Q, in any Q-regular metric space supporting a 1-Poincaré inequality; prime examples of such spaces are the Carnot groups. Let us mention here that in the recent work [8], which has been prepared independently of the present paper, the authors establish similar sufficient conditions for fractional Hardy inequalities in R n .
The sharpness of Theorems 1.1 and 1.2 are discussed in detail in Section 8, but let us mention here some of the relevant facts. First of all, the bound p − β for the codimensions is very natural and sharp. Indeed, we show in Theorem 6.1 that if admits a (p, β)-Hardy inequality, then either co dim H ( c ) < p − β or co dim A ( c ) > p−β; and it is clear that for sufficiently regular c , co dim H ( c ) = co dim A ( c ). Nevertheless, it is not necessary for a (p, β)-Hardy inequality that either co dim A ( c ) < p − β or co dim A ( c ) > p − β, since suitable local combinations of the assumptions in Theorems 1.1 and 1.2 yield sufficient conditions for Hardy inequalities as well (cf. Section 7); and in such cases, typically only the bound co dim H ( c ) < p − β is satisfied. There is also a corresponding local dimension dichotomy for Hardy inequalities; see Theorem 6.2.
The requirement p − β > 1 is also sharp in both of the theorems. For instance, the unit ball B = B(0, 1) ⊂ R n gives a simple counterexample for the result of Theorem 1.2 in the case 0 < p − β ≤ 1, since co dim A (R n \ B) = 0, but B admits (p, β)-Hardy inequalities only when p − β > 1. However, under additional conditions on , these Hardy inequalities can also be proved in the case p−β ≤ 1; see Remark 4.1 and the discussion in Section 8. The unboundedness assumptions on X and c in Theorems 1.1 and 1.2, respectively, cannot be relaxed either, as the examples at the end of Section 8 show. The only assumption, whose role is not completely understood at the moment, is the (p − β)-Poincaré inequality in the cases β > 0 of the theorems; a p-Poincaré inequality is certainly necessary in any of the cases. See Remark 4.1 for a related discussion.
Part of the motivation for the present work stems from the connection between Hardy inequalities and the so-called quasiadditivity property of the variational capacity. Some aspects of such a connection have been visible, e.g., in [2,3,23,25]; but only recently, has it been shown in [29] that quasiadditivity of the p-capacity with respect to and the validity of a p-Hardy inequality in are essentially equivalent conditions (under some mild assumptions on the space X or the open set ). An assumption equivalent to the dimension bound co dim A (E) > p (or rather dim A (E) < n − p) was used already by Aikawa [1] in connection with the quasiadditivity of the Riesz capacity R 1,p with respect to Whitney decompositions of the complement R n \ E. In order to obtain a corresponding result for the variational p-capacity (in metric spaces), the unweighted case β = 0 of Theorem 1.1 was deduced in [29,Prop. 3] under an additional accessibility condition. (Note that the lower Assouad codimension is called the Aikawa codimension in [29] and in [30]; see Section 2 for a discussion). Now Theorem 1.1 makes such an additional condition unnecessary, and thus we have the following corollary to Theorem 1.1 and [29, Thm 1], yielding a complete analogy with the results of Aikawa [1,3]. Corollary 1.4. Let 1 < p < ∞, and assume that X is an unbounded doubling metric space supporting a p-Poincaré inequality. If ⊂ X is an open set satisfying co dim A ( c ) > p, then the variational p-capacity cap p (·, ) is quasiadditive with respect to Whitney covers W c ( ) for suitably small parameters c > 0.
We refer to [29] for all the relevant definitions. Let us also point out that the proof of the corresponding Hardy inequalities in [29] is more straight-forward than that of Theorem 1.1 here, and so the proof from [29] may actually be preferred in the cases in which the accessibility condition is known to hold.
The organization of the rest of the paper is as follows. In Section 2, we recall the necessary background material concerning metric spaces and the various notions of dimension. Section 3 contains a proof of Theorem 1.1 for the case β < 0; the case 0 ≤ β < p − 1 is then established in the following Section 4. The relation between Hausdorff (co)content density and the upper Assouad codimension is studied in Section 5 with the help of a measure distribution procedure. That section also contains the proof of Theorem 1.2. The necessary conditions for Hardy inequalities are the topic of Section 6. Finally, in Section 7, we discuss the case in which the complement contains both thick and thin parts; and in Section 8, we give examples which indicate the sharpness of our assumptions.
We denote by C and c positive constants whose values are not necessarily the same at each occurrence. If there exist constants c 1 , c 2 > 0 such that c 1 F ≤ G ≤ c 2 F , we sometimes write F G and say that F and G are comparable.

Metric spaces and concepts of dimension
Throughout this paper, we assume that X = (X, d, μ) is a complete metric measure space, where μ is a Borel measure supported on X with 0 < μ(B) < ∞ whenever B = B(x, r) : = {y ∈ X : d (x, y) ≤ r} is a (closed) ball in X. In addition, we assume that μ is doubling, i.e., there exists a constant C > 0 such that μ(B(x, 2r)) ≤ C μ(B(x, r)) whenever x ∈ X and r > 0. The completeness of X is actually not needed in all of our results; but for simplicity, we keep it as a standing assumption. We also make the tacit assumption that each ball B ⊂ X has a fixed center x B and radius rad(B) (but these need not be unique), and thus notation such as λB = B(x B , λ rad(B)) is well-defined for all λ > 0. The diameter of a set E ⊂ X is denoted diam(E), the distance from a point x to E is dist(x, E), and χ E denotes the characteristic function of E. We also say that the measure μ is Q-regular if there exists a constant C ≥ 1 such that C −1 r Q ≤ μ(B(x, r)) ≤ Cr Q for all x ∈ X and every 0 < r < diam(X).
A Borel measurable non-negative function g on X is an upper gradient of a measurable function f : X → [−∞, ∞] if whenever γ is a compact rectifiable curve in X, | f (y) − f (x)| ≤ γ g ds, where x and y are the two endpoints of γ. This condition should be interpreted as claiming that γ g ds = ∞ whenever at least one of | f (x)|, | f (y)| is infinite; see, e.g., [4,15,16] for an introduction to analysis on metric spaces based on the notion of upper gradients.
In addition to the doubling condition, we also assume throughout the paper that the space X supports a (1, p)-Poincaré inequality (or simply a p-Poincaré inequality) for 1 ≤ p < ∞, i.e., there exist constants C > 0 and λ ≥ 1 such that whenever B = B(x, r) ⊂ X and g is an upper gradient of a measurable function f , To be more precise, we keep a p-Poincaré inequality as a standing assumption, but as already seen in Theorems 1.1 and 1.2, we occasionally require even stronger Poincaré inequalities.
Moreover, we rely in some of our formulations on the following fundamental result of Keith and Zhong [19] on the self-improvement property of Poincaré inequalities: if 1 < p < ∞ and a complete doubling metric space X supports a p-Poincaré inequality, then there exist 1 ≤ p 0 < p such that X also supports a p 0 -Poincaré inequality, and hence p -Poincaré inequalities for all p ≥ p 0 .
One consequence of Poincaré inequalities for the geometry of X is that a space supporting a p-Poincaré inequality is quasiconvex, meaning that there exists C ≥ 1 such that each pair of points x, y ∈ X can be joined by a rectifiable curve γ x,y of length (γ x,y ) ≤ Cd (x, y); see, e.g., [4] for details. From quasiconvexity, we obtain the useful fact that if We denote the set of all Lipschitz functions u : → R by Lip( ). In addition, Lip 0 ( ) (respectively, Lip b ( )) denotes the set of Lipschitz functions with compact (respectively, bounded) support in . Recall that the support of a function u : → R, denoted spt(u), is the closure of the set where u is non-zero.
Define the upper pointwise Lipschitz constant and lower pointwise Lipschitz constant of a function u : → R at x ∈ by respectively. It is not hard to see that both of these are upper gradients of a (locally) Lipschitz function u : → R (see [4,Proposition 1.14]). On the other hand, in R n , |∇u| is a (minimal weak) upper gradient of u ∈ Lip(R n ); see, e.g., [4] for this result and the related terminology.
Let us now recall the various notions of dimension that are important throughout the paper. Let E ⊂ X. The (upper) Assouad dimension of E, denoted by dim A (E) (or simply by dim A (E)), is the infimum of exponents s ≥ 0 for which there exists a constant C ≥ 1 such that for all x ∈ E and every 0 < r < R < diam(X), the set E ∩ B(x, R) can be covered by at most C(r/R) −s balls of radius r. Notice that for diam(E) ≤ r < diam(X), this condition is trivial. The upper Assouad dimension is the "usual" Assouad dimension found in the literature; see Luukkainen [32] for the basic properties and a historical account on the upper Assouad dimension.
Converse to the above definition is the lower Assouad dimension of E, dim A (E), defined in [18] as the supremum of exponents t ≥ 0 for which there exists a constant c > 0 such that for 0 < r < R < diam(E) and x ∈ E, at least c(r/R) −t balls of radius r are needed to cover E ∩ B(x, R); if diam(E) = 0, we omit the upper bound for R. Closely related concepts have been considered, e.g., by Larman [24] and Farser [10], but an important difference in our definition is that we consider all radii 0 < r < diam(E), not just small radii; in the context of Hardy inequalities, this turns out to be essential.
For comparison, recall that the upper Minkowski dimension of a compact E ⊂ X, denoted dim M (E), is the infimum of λ ≥ 0 such that the whole set E can be covered by at most Cr −λ balls of radius 0 < r < diam(E), and that the lower Minkowski dimension, dim M (E), is the supremum of λ ≥ 0 for which at least cr −λ balls of radius 0 < r < diam(E) are needed to cover E. It follows immediately that Since a doubling metric space is separable, there exists for all r > 0 a maximal r-packing of E ⊂ X, i.e., a countable collection B of pairwise disjoint balls When working in a (non-regular) metric space X, it is often convenient to describe the sizes of sets in terms of codimensions rather than dimensions. For instance, the Hausdorff codimension of E ⊂ X (with respect to μ) is the number We define next the Assouad codimensions following [18]. For E ⊂ X and The lower Assouad codimension, denoted by co dim A (E), is the supremum of all t ≥ 0 for which there exists a constant C ≥ 1 such that for all E ⊂ X; see [18].

Remark 2.1.
It was shown in [30, Theorem 5.1] that the lower Assouad codimension can also be characterized as the supremum of all q ≥ 0 for which there exists a constant C ≥ 1 such that for every x ∈ E and all 0 < r < diam(X). Here, we interpret the integral to be +∞ if q > 0 and E has positive measure.
A concept of dimension defined via integrals as in (1) was used by Aikawa in [1] for subsets of R n ; see also [3]. In [29,30], where the interest originates from such integral estimates, the lower Assouad codimension was called the Aikawa codimension. We will see later, especially in Section 6, that this kind of integral estimate arise very naturally in connection with Hardy inequalities. The next lemma records the fact that the Aikawa condition (1) satisfies the property of self-improvement. This property is a direct consequence of the famous self-improvement result for reverse Hölder inequalities (in R n due to Gehring [11]); we need this in Section 6 when proving our necessary conditions for Hardy inequalities. For q > 1, the result of Lemma 2.2 is contained in the proof of [23,Lemma 2.4]; and in the proof of [17,Proposition 4.3], the same fact is used in R n . Lemma 2.2. Let 0 < R 0 ≤ ∞ and assume that E ⊂ X satisfies the Aikawa condition (1) for every x ∈ E and all 0 < r < R 0 with an exponent q > 0 and a constant C 0 > 0. Then there exist δ > 0 and C > 0, depending only on the given data, such that condition (1) holds for every x ∈ E and all 0 < r < R 0 with the exponent q + δ and the constant C.
Fix 0 < s < q, e.g., s = q/2, and let B 0 = B(x, R) with x ∈ E and 0 < R < R 0 . In addition, let B be a ball such that B ⊂ B 0 . If 4B ∩ E = ∅, then we find a ball B centered at E with a radius comparable to rad(B) such that B ⊂ B ; and thus we have, by (1) and the doubling condition, that In the last inequality, we have used the fact that dist(y, E) −s ≥ Crad(B) −s for all y ∈ 2B. In particular, we obtain the reverse Hölder inequality On the other hand, if 4B ∩ E = ∅, then dist(y, E) dist(x, E) for all y ∈ 2B, and thus (2) holds in this case as well.
Since the function f (y) = dist(y, E) −s ∈ L 1 (B 0 ) now satisfies the assumption of the Gehring Lemma [4, Theorem 3.22] for all balls B ⊂ B 0 , the proof in [4] shows that there exists δ > 0 such that for the ball B 1 = 1 2 B 0 , where we have also used Hölder's inequality and the original estimate (1). Moreover, here the constant C > 0 is independent of the ball B 1 . The claim follows, since for balls B 1 with R 0 /2 ≤ rad(B 1 ) < R 0 , we can consider a cover using smaller balls.

A weighted Hardy inequality for β < 0
In this section, as a first step towards proving Theorem 1.1, we establish the result in the case β < 0. The particular form of the constant in the (p, β)-Hardy inequalities below plays an important role in the proof of the general case of Theorem 1.1.
Notice that here the test functions are not required to vanish in c , and recall that we have the standing assumption that X is a complete doubling metric space supporting a p-Poincaré inequality.
A standard telescoping trick using the p-Poincaré inequality then yields for every Comparison of the sum on the right-hand side of (3) with the convergent geometric series ∞ j =k 2 (k− j )δ for any δ > 0 shows that there exist a constant C 1 (δ ) > 0, independent of u and B, and an index j (B) ≥ k such that Let us now start to estimate the left-hand side of the (p, β)-Hardy inequality.
where C 2 = 2 p−β C and C = 2 p−1 > 0 is independent of β. The first sum in the last line of (6) can be estimated with the help of the (p, p)-Poincaré inequality (which is a well-known consequence of the p-Poincaré inequality; see, e.g., [13,15]) and the controlled overlap of the balls 4λB for B ∈ B k (with a fixed k ∈ Z, by the doubling condition). We also rewrite the integral, change the order of summation, and use the simple where the constants C > 0 and M = M (λ) ≥ 4 are independent of β; note also how the assumption β < 0 was needed.
In the last sum of (6), we first use (5) and then change the order of summation to obtain Since the balls B, for B ∈ B k , are pairwise disjoint, the assumption co dim Thus we obtain from (8), using also the bounded overlap of 4λB, where the last inequality follows just as in (7). A combination of (6), (7), and (9) thus yields the (p, β)-Hardy inequality where the constant C > 0 is independent of β, but depends on δ (cf. (3)), q 1 , q 2 , p, and the data associated to X. We conclude the proof with a closer examination of the constant in (10). First of all, if −1 < β < 0, then 2 −(M +3)β ≤ 2 M +3 ; and when β is close enough to 0, 1 − 2 β −β. In addition, the constant C in (10) depends on δ , q 1 , and q 2 , and hence indirectly on β as well, since δ = (q 2 − p + β)/p and p − β < q 1 < q 2 < co dim A ( c ). Nevertheless, obviously, if, e.g., p − co dim A ( c ) /2 < β < 0, this constant can be chosen to depend only on p and co dim A ( c ) (and the data associated to X). It follows that there exists β < 0, depending on p and co dim A ( c ), such that for all β < β < 0, where the constant C * > 0 is independent of the particular β. Proof of Theorem 1.1. For β < 0, the claim follows from Proposition 3.1, and thus we are left with the case 0 ≤ β < p − 1. Since co dim A ( c ) > p − β > 1, we have by Proposition 3.1 that admits a (p − β, −β 0 )-Hardy inequality whenever 0 < β 0 < co dim A ( c ) − p + β; here we need to know that X supports a (p − β)-Poincaré inequality. Moreover, there exists β 0 > 0 such that for 0 < β 0 < β 0 , the constant in the (p − β, −β 0 )-Hardy inequality is C * β −1 0 , with C * > 0 independent of β 0 . Fix such β 0 to be chosen later.
Let u ∈ Lip 0 ( ) with an upper gradient g u . The function v defined by v(x) = |u(x)| p/(p−β) d (x) β 0 /(p−β) is a Lipschitz-function with a compact support in , and satisfies |u(x)| p = |v(x)| p−β d (x) −β 0 . Moreover, the function g v defined by (11) g is an upper gradient of v; see, e.g., [4, Theorems 2.15 and 2.16]. Here it is essential that the support of u is a compact subset of . Using the (p − β, −β 0 )-Hardy inequality of Proposition 3.1 for v, we obtain By (11) and Hölder's inequality (for exponents p β and p p−β ), we estimate the above integral for g v as where the constant C(p, β) = 2 p−β p/(p − β) p−β is independent of β 0 .
We now choose 0 < β 0 < β 0 so small that This is possible, since p − β > 1 and the factor C * C(p, β) does not depend on β 0 . After inserting (13) into (12), we observe that under the above choice of β 0 , the second term emerging on the right-hand side is less than half of the left-hand side, and thus we obtain The (p, β)-Hardy inequality for u now follows from (14) by dividing with the first factor on the right-hand side (which we may assume to be non-zero), and then taking both sides to power p/(p − β).
Notice that the requirement p − β > 1 is essential in the above proof. This is not merely a technical assumption, since Theorem 1.1 need not hold if p − β ≤ 1; see Section 8. It is worth recalling that when c (or actually ∂ ) satisfies additional accessibility conditions from within , such direct proofs exist. Moreover, under these accessibility conditions, the results of Theorems 1.1 and 1.2 can be extended to the case β ≥ p − 1; see, e.g., [22,Theorem 1.4], [25,Theorem 4.3], and [28,Theorem 4.5].

Remark 4.2.
An interesting special case of Theorem 1.1 is that in which X is unbounded and the distance function d (x) is replaced with the distance to a fixed point x 0 ∈ X, i.e., we have the inequality It follows from Theorem 1.1 that this inequality holds for all u ∈ Lip 0 (X \ {x 0 }) when co dim A ({x 0 }) > p − β > 1; in fact, by Corollary 6.6 below, u need not vanish at x 0 , so the inequality actually holds for all u ∈ Lip b (X). On the other hand, Theorem 1.2 implies that for co dim A Let us mention here that the lower and upper Assouad codimensions of a point are closely related to the exponent sets of the point x 0 , defined in [5]. Namely, co dim A ({x 0 }) = sup Q(x 0 ) and co dim A ({x 0 }) = inf Q(x 0 ); see [5] for the definitions of the Q-sets.
In the Heisenberg group H n , which is one particular example of a metric space satisfying our general assumptions, an inequality of the type (15) was recently obtained by Yang [37] using a completely different approach. Since co dim A ({0}) = Q : = 2n + 2 for 0 ∈ H n , [37, (3.6)] corresponds exactly to (15), for x 0 = 0, under the condition 1 < p < co dim A ({x 0 }); notice that [37, Theorem 1.1] records only the unweighted case β = 0. However, the requirement p − β > 1 is not needed in [37], and the inequality is established even with the sharp constant p/(Q − p + β) p . With our techniques, there is no hope of obtaining any sharpness for the constants.
Recall also that in euclidean spaces, the corresponding well-known inequality, i.e., with the optimal constant C = p/|n − p + β| p , follows easily from the classical 1-dimensional weighted Hardy inequalities (see [14]) on rays starting from the origin. For p − β < n, this inequality holds for all u ∈ Lip b (R n ); and for p − β > n, it holds for all u ∈ Lip 0 (R n \ {0}). See also [34] for related inequalities, where the distance is taken to a k-dimensional subspace of R n , 1 ≤ k < n.

Upper Assouad codimension and thickness
In this section, we establish a connection between the upper Assouad codimension and Hausdorff content density conditions, which might also be of independent interest. As a consequence, we obtain a proof of Theorem 1.2. The following lemma is a modification of [27, Lemma 4.1], where a corresponding statement is given in terms of Minkowski contents in euclidean spaces.
Lemma 5.1. Let E ⊂ X be a closed set, and assume that co dim A (E) < q. Then there exists a constant C > 0 such that for every w ∈ E and all 0 < R < diam(E).
Proof. Let co dim A (E) < q < q, and fix 0 < δ < 1/2 to be chosen later. Let also w ∈ E and 0 < R < diam(E), and write B 0 = B(w, R) and r k = δ k R.
We begin with a maximal packing

and thus the doubling condition and the fact q > co dim A (E) imply
In particular, there exists a constant c 0 > 0, independent of w and R, such that . We now choose 0 < δ < 1 to be so small that δ q−q < c 0 , whence c 0 δ q > δ q , and so M 0 : = i 1 μ(B i 1 ) > δ q μ(B 0 ). We complete the first step of the construction by defining a measure distribution ν for the balls B i 1 by In the next step, we create a similar measure distribution inside the balls B i 1 . As above, we find for each i 1 ∈ I 0 pairwise disjoint balls B i 1 We define ν(B i 1 i 2 ) := ν(B i 1 )μ(B i 1 i 2 )/M i 1 , and by (17) and (18) Notice that all the balls B i 1 i 2 are pairwise disjoint, since B i 1 ∩ B j 1 = ∅ whenever i 1 = j 1 , and clearly B i 1 i 2 ⊂ B i 1 for every i 2 ∈ I i 1 .
Continuing the construction in the same way, we find in the k th step a collection of pairwise disjoint closed balls B i 1 Thus q > co dim A (E), and the choice of δ imply We now distribute the measure for the balls where we have used (19) and the recursive assumption that This concludes the general step of the construction. Next Then E ⊂ E ∩ B 0 is a non-empty compact set (here we need the assumptions that X is complete and E is closed; recall also that balls are assumed to be closed). Using the Carathéodory construction (see, e.g., [33, pp. 54-55]) for the set function ν, we obtain a Borel regular measureν which is supported on E and satisfiesν(B i 1 i 2 ...i k ) = ν(B i 1 i 2 ...i k ) for all of the balls constructed above; see also [9, pp. 13-14].
For x ∈ E and 0 < r < R, we choose k ∈ N such that Rδ k = r k ≤ r < Rδ k−1 . Then there exists a constant C 1 > 0 (depending on the doubling constant and δ ) such that B(x, r) intersects at most C 1 of the balls B i 1 i 2 ...i k , say B 1 , . . . , B N , from the k th step of the construction. These balls are pairwise disjoint, contained in B(x, 3r), and cover E ∩ B(x, r), Thus, by (20), the choice of k, and the doubling condition,ν Finally, let {B(z i , r i )} i be a cover of E ∩ B 0 with balls of radii 0 < r i < R. Using (21), we conclude that and so taking the infimum over all such covers yields H μ,q R E ∩B 0 ≥ C R −q μ(B 0 ), as desired.
Consequently, we obtain the following characterization for the upper Assouad codimension (of closed sets) in terms of Hausdorff content density.
Corollary 5.2. Let E ⊂ X be a closed set. Then co dim A (E) is the infimum of all q ≥ 0 for which there exists C ≥ 0 such that (16) holds for every w ∈ E and all 0 < R < diam(E).
Proof. Let q ≥ 0 be such that (16) holds for every w ∈ E and all 0 < R < diam(E), and let {B i } be a maximal packing of E ∩ B(w, R/2) with balls of radius 0 < r < R. Then {2B i } is a cover of E ∩ B(w, R/2), and so the doubling condition and (16) imply Thus co dim A (E) gives a lower bound for exponents satisfying (16).
On the other hand, Lemma 5.1 shows that there cannot be a larger lower bound for these q, and thus co dim A (E) is the infimum, as required.
Proof of Theorem 1.2. We assume that co dim A ( c ) < p−β and p−β > 1, and thus can choose q > 1 such that co dim A ( c ) < q < p − β. Lemma 5.1 then implies for every w ∈ c and all 0 < R < diam( c ), with a constant C > 0 independent of w and R. By [28,Theorem 4.1], this condition is sufficient for to admit a (p, β)-Hardy inequality, as desired.
The following remarks are in order here.

Remarks 5.3.
(1) The condition in [28,Thm. 4.1] actually requires that for all x ∈ , where d (x) = dist(x, ∂ ). Recall from Section 2 that the validity of a Poincaré inequality implies that X is quasiconvex, and thus dist(x, ∂ ) dist(x, c ); so the different distance function causes no problems here. Moreover, inspecting the proofs in [28], one sees that for β ≤ 0, the assumption (23) can be replaced in Lemma 3.1(a) of [28] with the condition (22). One subtlety here is the case when is unbounded, since in that case, (22) is needed for all radii 0 < R < ∞. We thus have to assume that in this case, c is unbounded as well. Once Lemma 3.1(a) of [28] is established, the (p, β)-inequalities for β > 0 follow just as in the proof of [28,Theorem 4.1]; the idea is the same as in the proof of Theorem 1.1 of the present paper.
(2) The proofs in [28] require the validity of a p 0 -Poincaré inequality for 1 ≤ p 0 < p, which is guaranteed by the self-improvement result of Keith and Zhong [19].
(3) Actually, both the inner boundary density of (23) and the complement density (22), with an exponent 1 ≤ q < p, are equivalent to the uniform p-fatness of c ; see [20]. The deep fact that (also) uniform fatness is a self-improving condition (see [31,7]) is essential in the necessity part of this claim.

Necessary conditions
In this section, we extend previously known necessary conditions for Hardy inequalities to cover weighted Hardy inequalities in metric measure spaces. In [23] and [30], such conditions were obtained in the unweighted case β = 0 in metric spaces, and in [25], conditions for weighted inequalities were obtained in the euclidean setting. Let us mention here that actually no Poincaré inequalities are needed to establish the results in this section, so we only need assume that μ is doubling.
The following theorem is a generalization of [ Here "the given data" means the parameters p and β and the constants in the doubling condition and in the assumed Hardy inequality. Our next result gives a local version of such a dimension dichotomy; see [25,Thm. 5.3] for the euclidean case and [30, Theorem 6.2] for the case β = 0. Theorem 6.2. Let 1 ≤ p < ∞ and β = p, and assume that ⊂ X admits a (p, β)-Hardy inequality. Then there exists ε > 0, depending only on the given data, such that for each ball B 0 ⊂ X either co dim H (2B 0 ∩ c ) < p − β − ε or the Aikawa condition (1) holds with an exponent q > p − β + ε for all w ∈ c ∩ B 0 and all 0 < r < rad(B 0 ).
Here the factor 2 in 2B 0 is not essential (but convenient); any fixed L > 1 can be used instead. Remark 6.3. We cannot in general conclude in Theorem 6.2 that either co dim H (2B 0 ∩ c ) < p − β − ε or co dim A (B 0 ∩ c ) > p − β + ε, since the latter would require the Aikawa condition for all 0 < r < diam(X), and this we cannot reach under the assumptions of the theorem. Nevertheless, if we assume further that there exists a constant C > 0 and and exponent s > p − β such that (24) μ (B(x, r)) for all x ∈ X and all 0 < r < R < diam(X), then it is possible to conclude in the setting of Theorem 6.1 that either co dim The main point here is that the Aikawa condition, for all 0 < r < rad(B 0 ), also implies that the condition in the definition of the lower Assouad codimension holds for all 0 < r < R < rad(B 0 ) with some exponent t > p − β + ε (cf. Remark 2.1); while for other radii 0 < r < R < diam(X), the latter condition follows with the help of the above relative measure bound (24) (possibly with another ε > 0). Notice, in particular, that (24) holds in a Q-regular space for s = Q.
Recall that our sufficient conditions for Hardy inequalities were given in terms of co dim A ( c ) and co dim A ( c ). However, in the above necessary conditions, it is not possible to replace co dim H by the (larger) co dim A in either of the theorems; see the discussion in Section 8. Also the assumption β = p is essential in both of the theorems. Indeed, the results need not hold for the (p, p)-Hardy inequality; see [25, Section 6.1]. On the other hand, for β > p, the claims reduce to trivialities, since always co dim A (E) ≥ 0.
One important ingredient in the proofs of these necessary conditions is the following self-improvement result for Hardy inequalities. Proposition 6.4. Let 1 ≤ p < ∞ and β ∈ R, and assume that ⊂ X admits a (p, β)-Hardy inequality. Then there exists ε > 0, depending only on the given data, such that admits (p,β)-Hardy inequalities whenever β − ε ≤β ≤ β + ε. Moreover, the constant C > 0 in all these Hardy inequalities can be chosen to be independent of the particularβ.
The proof of Proposition 6.4 is almost identical to the corresponding result in the euclidean case, which follows from the case s = 0 of [26, Lemma 2.1]. Thus we omit the details. Notice, in addition, that while [26, Lemma 2.1] is formulated only for 1 < p < ∞, the proof given applies also to the case p = 1.
Another fact that we need in the proofs of Theorems 6.1 and 6.2 is that if a part of the complement of is small enough, then the test functions for the Hardy inequalities need not vanish in that particular part of c . This is the content of the following lemma. Lemma 6.5. Let 1 ≤ p < ∞ and 0 ≤ β < p, and assume that ⊂ X admits a (p, β)-Hardy inequality with a constant C 0 > 0. Assume further that U ⊂ X is an open set such that Then a (p, β)-Hardy inequality holds for all u ∈ Lip 0 ( ∪ U) with a constant Proof. Let u ∈ Lip 0 ( ∪ U) with an upper gradient g u . By the definition of H μ,p−β diam(U) , there then exist, for a fixed j ∈ N, balls Let B 0 = B(x 0 , R 0 ) be a ball such that spt(u) ∩ U ∩ c ⊂ 1 2 B 0 . Then iteration of the doubling condition shows that there exist Q > 0 and a constant C > 0 such that μ(B j i )/μ(B 0 ) ≥ C(r i /R 0 ) Q for all i and j ; see, e.g., [4,Lemma 3.3]. Moreover, since one can always choose a larger Q in this condition, we may assume that Q > p − β. Thus it follows from (26) that, for each j ∈ N, all the radii r i (of the balls B j i ) satisfy r Q−p+β i ≤ C2 − j , where the constant C > 0 may depend on u and B 0 , but is independent of j . In particular, r i → 0 uniformly as j → ∞; and hence we may also assume that the covers ; see [4,Cor. 2.20]. Set u j = ψ j u. Then u j ∈ Lip 0 ( ), and g u j = g ψ j |u| + g u is an upper gradient of u j (see [4,Theorem. 2.15]). In addition, since the covers are assumed to be nested and r i → 0 uniformly as j → ∞, u j ≤ u j +1 for each j ∈ N and u j → u pointwise in .
Since β ≥ 0, d (y) β ≤ r β i for all y ∈ B j i , and thus the (p, β)-Hardy inequality for the functions u j and estimate (26) imply that where C = C(C 0 , p) > 0. The claim now follows by monotone convergence, since The following consequence of Lemma 6.5 gives an improvement to Theorem 1.1. Corollary 6.6. Let 1 ≤ p < ∞ and β < p − 1, and assume that X and are as in Theorem 1.1, in particular, that co dim A ( c ) > p − β. Then a (p, β)-Hardy inequality holds for all u ∈ Lip b ( ).
Proof. For β < 0, the claim follows directly from Proposition 3.1. For β ≥ 0, we have, by Theorem 1.1, that admits a (p, β)-Hardy inequality. We now choose and c ⊂ U, it follows in particular that H μ,p−β diam(U) (U ∩ c ) = 0. Lemma 6.5 then implies that the (p, β)-Hardy inequality holds for all Lip 0 ( ∪ U) = Lip b (X), and the claim follows. Lemma 6.5 and the self-improvement property of the Aikawa condition from Lemma 2.2 now yield the following result, which is essentially a "weighted" version of [23,Lemma 2.4]. A similar result can be found in [25, Lemma 5.2] for euclidean spaces, but the proof there is different. In particular, it avoids the use of Gehring's Lemma, and is thus more self-contained. The approach of [25] could be used in the present setting of metric spaces as well, but we choose instead to follow the outline of the proofs from [23] for the sake of brevity and also to emphasize the role of the self-improvement result of Lemma 2.2. Lemma 6.7. Let 1 ≤ p < ∞, 0 ≤ β < p, and assume that ⊂ X admits a (p, β)-Hardy inequality. Assume further that B 0 = B(x 0 , R) ⊂ X is an open ball such that H μ,p−β R (2B 0 ∩ c ) = 0. Then there exists δ > 0, depending only on the given data, such that the Aikawa condition (1) holds with exponent q = p − β + δ > 0 for all w ∈ c ∩ B 0 and all 0 < r < R.
Proof. Let w ∈ c ∩ B 0 and 0 < r < R/2, and write U = 2B 0 and B = B(w, r), so that 2B ⊂ 2B 0 . The function ϕ defined by ϕ(x) = r −1 d x, X \ 2B is a Lipschitz function with a compact support in ∪ U. Also, ϕ ≥ 1 in B, and g ϕ = r −1 χ 2B is an upper gradient of ϕ. By Lemma 6.5, the (p, β)-Hardy inequality holds for ϕ; and since d ≤ 2r in 2B and β ≥ 0, In particular, the Aikawa condition (1) holds with q = p−β > 0 (for R/2 ≤ r < R, the claim follows by covering B(x, r) with smaller balls). By Lemma 2.2, there then exists δ > 0 such that the Aikawa condition holds with p − β + δ , proving the claim.
Remark 6.8. Since δ in Lemma 6.7 depends only on the data associated to X, , and the (p, β)-Hardy inequality, we have the following uniformity result. If (q, β)-Hardy inequalities hold for all p 1 < q < p 2 with a constant C 1 , we can choose δ > 0 in Lemma 6.7 to be independent of the particular q; more precisely, We have now established enough tools to prove Theorem 6.2. The proof follows the lines of the proofs of [23, Corollary 2.7] and [30, Thm. 6.2], but we present the main ideas here for the convenience of the reader.
Proof of Theorem 6.2. Let B 0 = B(x 0 , R) ⊂ X. It is clear that if β > p, we choose δ < β − p and then the Aikawa condition (1) holds with the exponent q = p − β + δ < 0, and so we only need to consider the case β < p.
First, we may assume that β ≥ 0. Indeed, if this is not the case, we have, by [26,Theorem 2.2], that admits a (p − β, 0)-Hardy inequality with a constant depending only on the data, and we may now consider this instead of the original (p, β)-Hardy inequality. Notice that even though [26,Theorem 2.2] is written for euclidean spaces, its proof applies almost verbatim to metric spaces.
By the self-improvement property of Hardy inequalities from Proposition 6.4, we can find ε 1 > 0 and C 1 > 0 such that admits (p,β)-Hardy inequalities for all β ≤β ≤ β + ε 1 . Moreover, the constant in all these inequalities can be taken to be C 1 . In addition, we require that ε 1 ≤ p − β.
The global dimension dichotomy in Theorem 6.1 follows along the same lines as above. If admits a (p, β)-Hardy inequality for 0 ≤ β < p and co dim H ( c ) ≥ p − β − ε, we obtain from Lemma 6.7 that for any ball B = B(w, r) with w ∈ c and 0 < r < diam(X), where C and δ are independent of B and the particular ε. Choosing ε > 0 as in the proof of Theorem 6.2 shows that the Aikawa condition (1) holds with an exponent q > p − β + ε for all w ∈ c and all 0 < r < diam(X). Hence we conclude from Remark 2.1 that indeed co dim A ( c ) > p − β + ε.

Combining thick and thin parts of the complement
Theorem 1.1 gives a sufficient condition for Hardy inequalities in the case in which the complement of is thin. Conversely, Theorem 1.2 gives such a condition in the case in which the complement is thick (everywhere and at all scales). Nevertheless, requiring the whole complement to be either thick or thin rules out all cases where the complement contains both large and small pieces; an easy (and well-understood) example is the punctured ball B(0, 1) \ {0} ⊂ R n . In the next proposition, we show how it is possible to combine the results of Theorems 1.1 and 1.2 for this kind of domain. A slightly different approach to Hardy inequalities in such domains, for β = 0, was given in [29,Section 5]; and, in the euclidean case, earlier results for weighted inequalities can be found in [25]. Both of these require additional accessibility properties for . On the other hand, the results from [25] also cover the case β ≥ p − 1, where such extra conditions are known to be indispensable; see Section 8. Proposition 7.1. Let 1 < p < ∞ and β < p − 1. If β ≤ 0, we assume that X supports a p-Poincaré inequality, and if β > 0 we assume that X supports a (p−β)-Poincaré inequality. Let 0 ⊂ X be an open set satisfying co dim A ( c ) < p − β. If F ⊂ 0 is a closed set with co dim A (F ) > p − β, then = 0 \ F admits a (p, β)-Hardy inequality. Moreover, a (p, β)-Hardy inequality (in ) actually holds for all u ∈ Lip 0 ( 0 ), i.e., the test functions need not vanish in F ∩ 0 .
Since this result (in this generality) is new even in euclidean spaces, let us formulate this special case as a corollary. and since d 0 (y) R for all y ∈ 4B 1 , we obtain (28) |u Now pick q such that co dim A (F ) > q > p − β. Then, by definition, Estimate (28) and the bounded overlap of the balls 4B for B ∈ B (2) k with a fixed k then imply since q + β − p > 0. Following the proof of Proposition 3.1, we can now combine (27) and (29) to obtain as in (6) 4B 1 Note that here, A k 0 +1 = 4B 1 \ N k 0 , and that the first integral in the second line can be estimated just as in (7). Of course, similar estimates hold for all balls B 1 , B 2 , . . ., with constants independent of i. We claim that if x ∈ \ i 4B i , then d (x) ≥ Cd 0 (x): If d (x) = d 0 (x), the claim is trivial, so we may assume that d (x) = d (x, w) for some w ∈ F . Pick B i w. Since x / ∈ 4B i and rad(B i ) ≥cd (w, 0 ) with 0 <c < 1, it follows that =cd (x, 0 ) −cd (x), and the claim follows. In particular, d (x) β−p ≤ Cd 0 (x) β−p for these x, and thus estimate (30) for each B i , the (p, β)-Hardy inequality for 0 , and the bounded overlap of the balls 4λB i (and thus of 4B i ) yield Here, we have also used the facts that d 0 (x) β ≤ d (x) β for all x ∈ (since β < 0) and that μ(F ) = 0.
The above constant C > 0 naturally depends on β. However, for −1 < β < 0 close enough to 0, the dependence can be reduced again to the form C = |β| −1 C * , where C * > 0 is independent of β; the details are exactly the same as in the proof of Proposition 3.1. Hence (p, β)-Hardy inequalities for 0 ≤ β < p − 1 now follow along the same lines as in the proof of the corresponding case of Theorem 1.1; see Section 4.
Finally, regarding the boundary values, we see that in the above proof of the case β < 0, it is not necessary for u to vanish in F , and thus this case indeed holds for all u ∈ Lip 0 ( 0 ). On the other hand, for the case β ≥ 0, we can apply Lemma 6.5 with U = 0 (since p − β < co dim A (F ) ≤ co dim H ( 0 ∩ c )), and it follows again that a (p, β)-Hardy inequality holds for all u ∈ Lip 0 ( ∪ 0 ) = Lip 0 ( 0 ).

Sharpness of the results
We close the paper with an examination of the sharpness of our results. In particular, we consider the necessity of the assumptions in our main theorems.
It has already been mentioned in the Introduction that the bound p − β is very natural for the dimensions in all of the sufficient and necessary conditions and cannot be improved. Moreover, the bound p − β for the lower Assouad codimension appears both in the sufficient and necessary conditions in the cases in which the complement is thin; so it is obvious that co dim A is the optimal concept of dimension in this setting. However, when (a part of) the complement is thick, the sufficient conditions are given in terms of the upper Assouad codimension, while in the necessary conditions the Hausdorff codimension is used, and so these conditions do not quite meet. This raises the question as to whether it is possible to improve the bounds in either sufficient or necessary conditions by using a different concept of dimension. Since the possibility of combining thick and thin parts in the sufficient conditions (Proposition 7.1) immediately rules out such improvements in the global results, the sharpness of the conditions (in terms of dimensions) is established once we show that (i) co dim H (2B 0 ∩ c ) in Theorem 6.2 cannot be replaced by co dim A (2B 0 ∩ c ) and, on the other hand, (ii) the local bound co dim H (B ∩ c ) < p − β, for all balls B = B(w, r) with w ∈ c , does not suffice for the (p, β)-Hardy inequality in .
The following construction yields a counterexample for both (i) and (ii).
Nevertheless, while it is clear that co dim H ( c ∩ B(w, r)) = co dim A ( c ∩ B(w, r)) = 0 whenever w ∈ c , and thus, in particular, co dim H ( c ∩ B(w, r)) < p in accordance with Theorem 6.2, this example shows that co dim H in the theorem cannot be replaced with co dim A ; indeed, for all balls B centered at the origin, e.g. for B = B(0, 1/2), co dim A ( c ∩ B) = n (i.e. dim A ( c ∩ B) = 0), since for all j ≥ 3, c ∩ 2 j B j ⊂ B can be covered by the ball B j , and here the ratio of the radii of the balls has no positive lower bound. Hence neither the estimate co dim A ( c ∩ 2B) < p nor co dim A ( c ∩ B) > p holds here when 1 < p < n, even though admits a p-Hardy inequality. We conclude that, in general, the bound co dim H (2B 0 ∩ c ) < p − β is optimal in Theorem 6.2, and clearly the same conclusion holds for Theorem 6.1 as well. Thus (i) is established.
For (ii), we notice that c is not uniformly perfect, i.e., there exist relatively large annuli around the balls B j which do not intersect c . Since uniform perfectness of c is equivalent to the validity of an n-Hardy inequality in ⊂ R n (see [21]), we conclude that does not admit an n-Hardy inequality. On the other hand, co dim H ( c ∩ B(w, r)) = 0 < n whenever w ∈ c and r > 0, so this example shows that the uniformity provided by the upper Assouad codimension in the sufficient conditions of Theorem 1.2 and Proposition 7.1 is essential and cannot be replaced with the condition that co dim H ( c ∩ B) < p − β for all balls centered at c . This establishes (ii).
Let us next examine the requirement p − β > 1 in Theorems 1.1 and 1.2. It has already been mentioned in the Introduction that for Theorem 1.2, the unit ball B = B(0, 1) ⊂ R n shows the necessity of this condition, since co dim A (R n \ B) = 0 but B admits (p, β)-Hardy inequalities only when p − β > 1. In fact, it is now understood that in the case p − β ≤ 1, it is the thickness of the boundary (rather than the complement) that plays a role in Hardy inequalities. For instance, the planar domain bounded by the usual von Koch showflake curve of dimension λ = log 4/ log 3 admits a (p, β)-Hardy inequality if (and only if) β < p − 2 + λ, i.e., exactly when p − β > co dim A (∂ ); see [22]. However, the requirement co dim A (∂ ) < p − β alone is not sufficient for a (p, β)-Hardy inequality if co dim A (∂ ) < 1, as is shown by [22,Examples 7.3 and 7.4], but certain accessibility conditions are required in addition; see [22,28] and Remark 4.1.
In the case of Theorem 1.1, the unbounded domain s indicated at the end of [25, Example 6.3] serves as an example in which 1 = co dim A (R n \ s ), but the domain does not admit any (p, β)-Hardy inequalities when p − β ≤ 1. Nevertheless, all known counterexamples here are such that co dim A ( c ) ≤ 1 (and thus in the examples in R n , we have dim A ( c ) ≥ n − 1), and so it could be asked if the requirement p − β > 1 can be removed (or weakened) if co dim A ( c ) > 1. Under additional accessibility conditions, Hardy inequalities can be obtained in the range p − β ≤ 1 in the case of thin boundaries as well; see [25] for the euclidean case.
Acknowledgements. Part of the research leading to this work was conducted when the author was visiting the Department of Mathematical Sciences of the University of Cincinnati in February 2013. The author wishes to express his gratitude to Nageswari Shanmugalingam for fruitful discussions, and the whole department for their hospitality. Thanks are also due to Antti Käenmäki for discussions related to Section 5, and to the anonymous referee for many useful comments.