{'fraction_non_alphanumeric': 0.03177619952652463, 'fraction_numerical': 0.00786902737487913, 'mean_word_length': 4.131223267750213, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Heuristic and computer calculations for the magnitude of metric spaces

The notion of the magnitude of a compact metric space was considered in arXiv:0908.1582 with Tom Leinster, where the magnitude was calculated for line segments, circles and Cantor sets. In this paper more evidence is presented for a conjectured relationship with a geometric measure theoretic valuation. Firstly, a heuristic is given for deriving this valuation by considering 'large' subspaces of Euclidean space and, secondly, numerical approximations to the magnitude are calculated for squares, disks, cubes, annuli, tori and Sierpinski gaskets. The valuation is seen to be very close to the magnitude for the convex spaces considered and is seen to be 'asymptotically' close for some other spaces.


Introduction
This paper is concerned with an empirical look at the magnitude of subspaces of Euclidean space. Magnitude was introduced under the name 'cardinality' by Leinster in [4] as a partially defined invariant of finite metric spaces; his motivation came from enriched category theory, but the invariant had already been considered in the biological diversity literature [6]. In [5] we started to extend the definition to compact, non-finite metric spaces by approximating these with finite metric spaces; we considered, in particular, the magnitude of certain subsets of Euclidean space, such as line segments and circles and we showed that in these cases, when the metric space is scaled up in size, the magnitude asymptotically satisfies the inclusion-exclusion principle. This leads to some natural conjectures and the current paper provides numerical and heuristic evidence for these conjectures. The current paper, however, can be read independently of [5].
As hinted by the title, there are two main ingredients to this paper. The first ingredient is a heuristic argument to calculate the contribution to the magnitude from the 'bulk' of points in the closure of a 'large' open subset X of Euclidean space R n ; this contribution is shown to be roughly vol(X)/n! ω n where ω n is the volume of the unit n-ball. From here one is led to consider, for naturality reasons, the so-called penguin valuation, defined on certain compact subsets of R n by The second ingredient consists of computer calculations of finite spaces approximating squares, cubes, discs, annuli, tori and Sierpinski gaskets. The computer algebra maple was used to calculate the magnitude of finite spaces with around 25, 000 points.
The two ingredients are combined when the calculated magnitudes for the first five types of spaces mentioned above are plotted together with the penguin valuation. In the convex examples -squares, cubes and discs -there is a surprisingly good fit, leading to the conjecture that for K a convex subset of Euclidean space the magnitude and penguin valuation are equal: |K| = P(K). In the case that K is a straight line segment this is proved rigourously in [5]. In the non-convex examples there is a good fit for larger spaces, leading to the conjecture that in those cases the magnitude is asymptotically the same as the penguin functional in the sense that |tX| − P(tX) → 0 as t → ∞, although it is not clear what spaces X this would be expected to hold for in general, other than for the closure of open sets. For instance, for the 'bent line', in which two straight line segments are stuck together at an angle, numerical calculations of the magnitude by David Speyer seem to show a small, constant discrepancy with the penguin valuation; also, asymptotic calculations seem to show that the lower order terms are not right in the case of the 3-sphere, although I do not have much confidence in these calculations at the moment.
In the fractal case it is not possible to make sense of the penguin functional. However, in [5] we were able to calculate precisely the magnitude of the Cantor set and observed that the asymptotic growth rate was the Hausdorff dimension of the Cantor set. In Section 4 we see that the empirical data for the Sierpinski gasket is consistent with its magnitude of the growing like its side length to the power of its Hausdorff dimension.
The rest of this introduction consists of a reminder of the definition of magnitude and an informal analogy which might provide some intuition, followed by a more detailed synopsis of the paper.
Definition of magnitude and a useful analogy. We first define the magnitude on finite metric spaces, then after some comments on the definition we will say how we wish to extend it to non-finite metric spaces.
If X is a finite metric space then a weighting on X is an assignment of a real number w x ∈ R to each point x ∈ X such that for each point x ∈ X the weight equation for x is satisfied: If a weighting exists then the magnitude |X| is defined to be the sum of the weights: Two standard observations to make here are, firstly, that the weights are not necessarily positive, as will be seen in examples below, and, secondly, that if there is more than one weighting then the magnitude is independent of the weighting.
One informal analogy that might be useful to keep in mind is the following. Imagine that the points are certain organisms that wish to maintain a certain body temperature which we normalize to be a temperature of 1 unit. To achieve this body temperature each organism can generate heat or cold and experiences the heat or cold from other organisms in a way that falls off exponentially with the distance. If the amount of heat that organism x is generating is given by w x then the fact that an organism x maintains unit body temperature is expressed in the weight equation for x .
Weightings of some finite subsets of R 2 (with the subspace metric) are given in Figures 1 and 2: the area of each disk is proportional to the weight of the point at its centre and the colour of the disk represents the sign of the weight -red is positive and blue is negative. Note how the weights are greater around the edge of the metric space. In line with the intuition described above, one is led to think about emperor penguins which huddle together in large groups on the Antarctic ice during the winter in order to conserve heat (see [1]); the penguins take turns to be on the outside of the group where it is coldest and they need to use up more energy. Despite being cute and whimsical, this imagery does seem to give helpful intuition.
We are interested here in extending the notion of magnitude to compact subsets of Euclidean space. If X is such a compact subset then we approximate X by a sequence {X k } ∞ k=0 of finite subsets of X converging (in the Hausdorff topology) to X. If lim k→∞ |X k | exists then we define |X| the magnitude of X to be this limit. In general we do not know that this is a well defined process -maybe the limit does not exist, or the limit depends on the choice of approximating sequence, or the approximating subsets do not themselves have a magnitude -but it gives sensible answers in the examples that we can calculate. In this paper typically we start with a compact subset X of R n and intersect it with some lattice L to give a finite setẌ := X ∩ L . (This is pronounced "X dots" and is supposed to indicate the fact that it is a discrete set.) We assume that for a sufficiently fine lattice this gives rise to a good approximation for the magnitude we are interested in: |Ẍ| |X|.
What is in this paper. In Section 1 we have a look at some features of weighting numerically calculated on grid approximations to squares. In Section 2 part of these features are fed into a back-of-the-envelope calculation for the contribution to the magnitude from the bulk of point in a large subset of R n ; this calculation then leads to the definition of the penguin valuation. Section 3 contains the main results of the paper with the penguin valuation being graphed together with numerically calculated approximations to the magnitude for some subsets of Euclidean space. In the convex examples -squares, discs and cubes -the penguin valuation and the magnitude are seen to be very close; in the other examples -annuli and tori -they are seen to be very close when the spaces are large. In Section 4 the Sierpinski gasket is considered and it is seen that the emprirical data is compatible with the growth rate of the magnitude being the Hausdorff dimension. The appendix contains some comments on the computer calculations.
Acknowledgements. I would like to thank Tom Leinster for many stimulating conversations and the information about emperor penguins, David Speyer for useful comments on an earlier draft, Sam Marsh for encouraging me to calculate some examples and also Emma McCabe and Richard Thomas for helping me develop the heat analogy.

Numerically approximating the magnitude of a square
In this section we have our first look at the results of calculations of the weights of points on a square grid and make some observations about these which will feed into the Bulk Approximation in the next section.
Having looked at line segments, circles and Cantor sets in [5], the next most obvious class of spaces to look at was squares. Unlike the simpler examples, we are not yet able to find an exact formula for weighting in this case, but we can look at the results of computer calculations. For t > 0, let tQ be a t × t square, thought of as a subset of R 2 , this will be approximated by tQ which is a square grid of m × m points with the distance between adjacent points being (m − 1)/t. Remember that the magnitude |tQ| is supposed to give an approximation to the magnitude |tQ| of the continuous square-however, it isn't yet proved that the continuous square has a well-defined magnitude, although the data in this paper provides evidence for the existence of such a magnitude.
For specific values of t and m, provided that m is not too large, we can use a computer algebra package such as maple to numerically calculate the weights on the finite metric space tQ, and hence calculate the magnitude |tQ|, which is just the sum of the weights; details of the computer implementation are given in the appendix.
The results of some computer calculations of the weights of tQ for some values of side length t and m points per side are represented graphically in Figures 1 and 2. In these pictures the weight at each point is represented by a disc centred at that point with the area of the disc equal to four times the weight at the point; the colour of the disc represents the sign of the weight, with red meaning a positive (or 'hot') weight and blue meaning a negative (or 'cold') weight. This graphical representation of the weights is not perfect: for instance where the discs overlap near the edges it is not entirely clear what is happening (see Figure 3 for a better picture of the behaviour near the edge). However, these pictures make the following features apparent.
(1) In the 'bulk' of the square the weights are reasonably constant.
(2) On the boundary the weights are bigger, but again are reasonably constant.  The area of a disc is four times the weight of the point at its centre; red denotes a positive weight and blue a negative weight.
In the next section we give a heuristic argument for the first feature and this argument implies that the constant should be 1/2π times the area of the little squares in the grid. A vague heuristic for the second and third features was given in the introduction -you should think of penguins huddling together to keep warm, those on the outside of the huddle need to generate more heat to keep warm whilst those next to them are overheated and so need to cool themselves down.
We finish this section by looking a little closer at the behaviour near the edge. We consider a square with (2s + 1) × (2s + 1) points then we look at the weights near the edge along the middle row -that is the sth row. If a point x has weight w x then, based on the calculations of the next section, we define the bulknormalized weight of a point x in the square to be 2πw x / vol(V) where vol(V) is the volume of a little square in the grid -that is the volume of a Voronoi cell in the language of the next section. According to my rather limited calculations, if the side length t of the square is sufficiently large, say at least 10, then the bulknormalized weight of a point on the middle row near the edge depends only on the distance from the edge and not on the side length or the spacing between points, with the singular exception of the weight of the point nearest to the edge which is usually more negative than might be expected. A sample profile of bulk-normalized weights near the edge is given in Figure 3. It seems from Figure 3 that the weight of a point at a distance d from the edge is of the form This behaviour is reminiscent of acutance in photographic images and the Gibbs phenomenon in signal processing. However, I have not been able to figure out any heuristic giving a quantitative explanation of this.

The bulk approximation and the penguin valuation
In this section we give a heuristic approximation to the contribution to the magnitude by the 'bulk' of points in a 'large' compact subset of R n . Continuing in the heuristic vein and assuming some connection between magnitude and invariant valuations we are led to the definition of the penguin valuation P at the end of this section. In the next section we will see numerical evidence that the penguin valuation is often close to the magnitude.
In the previous section it was observed that in the 'bulk' of a sufficiently large square all of the weights appeared to be constant. Here we use that observation as the seed for a heuristic argument describing, for X the closure of an open subset of R n , the contribution of the bulk of X to the magnitude of X. By bulk(X), the bulk of X, we will mean all of the points 'reasonably far from the boundary'. Remember that the influence of the weight of a point decreases exponentially with distance, so you might take 'reasonably far' to mean 'at least ten units away': this is just a heuristic argument, after all. The following is not a precise statement, but will be supported by numerical evidence in the next section.
Bulk Approximation. Let X be the closure of a large open set in R n , letẌ be the intersection of X with a sufficiently fine lattice and let ω n be the volume of the unit n-ball in R n . Then the contribution to the magnitude ofẌ by the bulk of points inẌ is roughly vol(X)/n! ω n .
Heuristic justification. The idea of the heuristic is that because the space is large and the effect of a point on other points decays exponentially with distance, the points in the bulk ofẌ only really know what is happening locally and so, as far as the weight equation is concerned, do not know that they are not part of an infinite lattice rather than a finite subset of one. We can solve the weight equation for the infinite lattice and get a simple approximation to the resulting weight. It is this approximation that we use to approximate the weight of points in the bulk ofẌ.
So denote the lattice by L . We can solve the weight equations for L , essentially using Speyer's method for homogeneous metric spaces (see [5,Theorem 1]). We will assume without loss of generality that the origin 0 is in the lattice, so we can consider the weight equation for 0: We now assume, motivated by the observation in Section 1 about the points in the bulk of the square, that all the points in L have the same weight w. Writing, as usual, |x| = d(0, x) we get It is not immediate that the sum in the denominator converges, but we can approximate it by Riemann sums in the following way.
First pick a fundamental domain V for L ; for concreteness we can take this to be the Voronoi cell for the origin, which means all of the points in R n which are at least as close to the origin as to any other lattice point. The translates by L of the fundamental domain V give a tessellation of R n , and each of the cells of the tessellation contains one point of the lattice. The volume of the fundamental domain will be denoted by vol(V) and is sometimes called the covolume of the lattice.
We can use this tessellation of the plane to calculate a Riemann sum approximation of an integral. For the function e −|x| , with the lattice sufficiently fine, we Now return to the case of the finite metric spaceẌ which is the intersection of the large space X with a lattice L . As X was taken to be the closure of an open set in R n , if we consider a point x in the bulk, then as far x is concerned it might as well be in the lattice L rather than X ∩ L , because the weight equation says that its interactions with points at a distance r is e −r , so it has exponentially small interaction with far-away points. So assuming local homogeneity, we take the weight of x to be the same as if it were considered as a point in L rather than X. So the points in the bulk ofẌ all have roughly the same weight which is The contribution of the points in the bulk to the magnitude is given by summing these weights, so we obtain roughly vol(bulk X) n! ω n vol(X) n! ω n , as required.
There are lots of approximations in the above argument, so it is not clear that it gives a sensible answer. However, the answer is supported by the empirical data given in the next section; moreover, if we continue in a heuristic manner, as follows, we obtain an answer which is an even better fit with the empirical data.
The above heuristic indicates that for X the closure of a large open subset of R n then |X| vol(X) n! ω n + contributions from near the boundary.
Based on the rather meagre examples from [5], we now assume that for large X the magnitude |X| is close to some valuation P(X). Recall from [3] and [5] that the intrinsic volumes {µ i }form a basis for the space of valuations. As the µ n is the n-dimensional volume of a subset of R n we know that in dimension n we must have P(X) = µ n (X) n! ω n + lower order terms. Now if ι : R i → R n is an inclusion of Euclidean spaces and Y ⊂ R i is some polyconvex subset then by the naturality of the intrinsic volumes with respect to inclusion of Euclidean spaces So the coefficient of µ i in P is of the same form for all i. We therefore define, for want of a better name, the penguin valuation P by and speculate whether or not |X| P(X) for large spaces X. Again, this looks like rather wild speculation; however, when, as in the next section, for certain spaces X we plot P(tX) against the magnitude of approximations to tX an impressively close fit is seen across a wide range of values of t. This is especially true for the convex sets considered, namely the square, the disc and the cube, where P(tX) is seen to be close to the approximation to |tX| for all t, not just for large t.
From this, one is lead to ask if there is an interesting class of spaces X for which the magnitude is asymptotically just the valuation P, i.e., |tX| − P(tX) → 0 as t → ∞, and is it true that for X convex the magnitude is just the valuation, i.e., |X| = P(X).

Numerically comparing the magnitude with the penguin valuation
In this section we will plot the magnitude of various subsets of Euclidean spaces -squares, discs, cubes, annuli and tori -together with the penguin valuation of these subsets. We can exactly calculate the penguin valuation for these and for the magnitude we numerically evaluate the magnitude of finite approximations to these subsets with around 25, 000 points. We see a good correlation between the magnitude and the penguin valuation. However, as pointed out in the introduction, this correlation seems unlikely to hold for every subset of Euclidean space.
In each of the following cases we take an interesting subset X of Euclidean space and approximate it byẌ a finite subset of X consisting of N points. We pick N as large as possible subject to constraints of available computing power; these constraints are discussed in the appendix. We then use maple to calculate the magnitude |tẌ| for various scale factors t; again, see the appendix for details of the maple code. We know from [5] that for a finite metric space in which the points are far apart from one another, the magnitude will essentially be the number of points, this means that |tẌ| → N as t → ∞. However, for t not so large, |tẌ| should give a reasonable approximation to the mythical magnitude |tX| of the space we are actually interested in. Here, empirically, "not so large" seems to mean that the points are at most of order 0.1 units from their nearest neighbour.
Based on the ideas of the previous section we want to compare the magnitude |tX| with the penguin valuation P(tX) as we suspect that they might be the same asymptotically, at least for when X is the closure of an open subset. So for t large, but not too large, we suspect |tẌ| |tX| and |tX| P(tX), thus we would expect |tẌ| P(tX) and it is this which is observed in the graphs below. The graphs are plotted on log-log axes so that wide range of orders of magnitude can be observed. It is striking that for the convex examples we see that |tẌ| P(tX) even for small t, providing the motivation for the conjecture that |X| = P(X) whenever X is convex.
3.1. Squares. Here we consider a 1 × 1 square Q which we approximate by a 150 × 150 grid of pointsQ, this has total number of points, N, of 22, 500. Of course the square Q can be approximated by say a hexagonal grid or a large random set of points inside the square, but these appear to give similar results. Weightings for squares with a square grid approximation were seen in Figures 1  and 2. We scale the finite squareQ by a factor of t for various values of t from 0.1 to 1000, numerically calculate the magnitude |tQ| and plot the magnitudes against t in Figure 4. We also plot P(tQ) on the graph, which is given by as the linear intrinsic volume, µ 1 , of a planar region is given by half the perimeter, which in this case is 2t. The curve gives a remarkable fit to the data points and fuels the suspicion that |X| = P(X) when X is a convex set. . Squares: comparison of the penguin valuation P(tQ) = t 2 /2π + t + 1 with |tQ|, an approximation to the magnitude.

3.2.
Discs. Similar to the last example, we consider D to be a circle of radius 1 and takeD to be a finite, square grid approximation to D; in this calculation we choose the mesh size of the grid to be such that we have approximately 25, 000 points in D. We numerically calculate |tD| the magnitude of the finite setD scaled by a factor of t, taking various values of t from 0.1 to 1, 000, and in Figure 5 we plot these values along with the graph of P(tD), the suspected asymptotic magnitude of the disc D, where Again, we get a remarkably good fit with the data points up until the data points start flattening out. . Cubes: comparison of the penguin valuation P(tC) = t 3 /8π + 3t 2 /2π + 3t/2 + 1 with |tC|, an approximation to the magnitude.

Cubes.
Again we consider a convex set, the cube, but this is one dimension higher than the above two examples of the square and the disc. Let C be the cube of side length 1. Now we approximate it by a 30 × 30 × 30 cubic lattice to get the total number of points, N = 27, 000, close to our computational maximum; this means that we get a less good approximation to the cube than we had for the square, as the points are five times further away from each other and, consequently, we see that the data points flatten out at smaller values of t than for the square. This is a problem of looking at higher dimensional sets. However, there is still a very good fit with the graph of the penguin valuation for t from 0.1 to 40.

Annuli.
We now look at our first non-convex example. We consider A, the annulus with outer radius 1 and inner radius 1/2. This time we approximate not with a square grid but withÄ a grid in polar coordinates. In Figure 7 we compare the calculated the calculated magnitudes with In this case we don't see a good fit at small t, which we didn't necessarily expect anyway, but we certainly see a good fit for medium-sized t. 3.5. Tori. In this example we consider a subset of R 3 which does not fit the hypotheses of the Bulk Approximation: the torus is a closed submanifold and is not the closure of an open subset of R 3 . Nonetheless, the torus does seem to have the asymptotic behaviour predicted by the Bulk Approximation. We consider U to be the standardly embedded torus with major radius 1 and minor radius 1/5, in other words the locus of points (1 + 1 5 cos ϕ) cos θ, (1 + 1 5 cos ϕ) sin θ, 1 5 We get the finite approximationÜ by taking (θ, ϕ) to lie on a m × m grid of points in [0, 2π) × [0, 2π). In Figure 8 we compare the resulting magnitude data with the graph of the function P(tU) = πt 2 /5 2π and again see a good fit before the magnitudes of the finite space flatten out.

Sierpinski gasket
This example is of a different nature to the ones in Section 3 so is given a section of its own. In [5] we considered the fractal example of the ternary Cantor set. It is not a polyconvex set and we can not make sensible interpretation of the intrinsic volumes {µ i } ∞ i=0 . However we observed that the magnitude of Cantor sets asymptotically satisfies an inclusion-exclusion principle in the following sense. Suppose P is some function on a set of subsets of Euclidean space which satisfies the inclusion-exclusion principle, so that P T t denotes the Cantor set of length t, then we have the self-similarity homeomorphism for all t > 0: Thus if the Cantor sets are in the domain of P and we set p(t) := P(T t ) then The general solution to this functional equation is of the form p(t) = f (t)t log 3 2 , where f is a multiplicatively periodic function with f (t) = f (3t) for all t > 0.
In [5] we gave the explicit formula for such a function p so that, as t → ∞, asymptotically, |T t | is p(t); the corresponding function f in that case is almostconstant, f (t) 1.3 for all t > 0. Now we can consider the Sierpinski gasket. Unlike the case of the Cantor set we cannot calculate the magnitude exactly so we will have to numerically approximate it. We can, however, carry out a similar analysis involving the inclusionexclusion principle. If S t denotes the Sierpinski gasket of side length t then for t > 0 the self-similarity can be represented by the homeomorphism so if P a function satisfying the inclusion-exclusion principle, with the Sierpinski gaskets within its domain and with P(point) = 1, then defining p(t) := P(S t ) we obtain the functional equation for all t > 0: The general solution to this is straightforwardly seen to be be p(t) = f (t)t log 2 3 + 3/2, where f is a multiplicatively periodic function with f (2t) = f (t) for all t > 0. Based on the behaviour of the Cantor sets, we might expect then that the magnitude |S t | of the Sierpinski gaskets asymptotically takes this form as t → ∞. We might also expect that the corresponding f might is almost-constant.
For various values of t the magnitude |S t | was approximated by numerically calculating the magnitude ofS t , a finite approximation to S t with 9843 points. The results are plotted in Figure 9 where 1 3 t log 2 3 + 3 2 is also plotted. Here the function f was taken to be the constant 1/3 purely because that gave a good fit by eye to the calculated data. The plot supports the guess that we have an asymptotic inclusion-exclusion principle for the magnitude, so there is an almost-constant function f with f (t) 1 3 for all t > 0, giving rise to the corresponding function p as above with |S t | − p(t) → 0 as t → ∞.
One can observe that this is consistent with the more general guess that for X a compact subset of R n , the asymptotic growth rate of the magnitude |tX|, i.e., lim t→∞ log |tX| log t , is the Hausdorff dimension of X. This is in agreement with the notion that for X the closure of an open subset of R n we have |tX| = t n vol(X) n! ω n + lower order terms.

Appendix A. Computer considerations
The programming code involved in finding a weighting for a finite metric space is very simple as we are just solving N linear equations in N unknowns, where N is the number of points. Computer algebras have good algorithms built-in for solving such problems, so we can just rely on this. This can be done as follows. If X is a metric space with points called P 1 , . . . , P N , then define Z to be the matrix of exponentiated distances, define w to be the vector of weights and define 1 to be the vector of ones, so Z ij := exp −d(P i , P j ) ; w := (w P 1 , . . . , w P N ) T ∈ R N ; 1 := (1, . . . , 1) T ∈ R N .
The weight equations are then expressed as the single vector equation We need to solve this for w and add up the entries of w to obtain the magnitude of X. Here is a piece of pseudo maple code, so you can see how straightforward it is. To get a good approximation we want to take the number of points, N, to be as large as possible. The principal constraints on how large we can take N to be are those of computing time and available memory. I was using the iceberg cluster at the University of Sheffield, each processor there has 12GB RAM and that turned out to be the main constraint. Taking N to be around 25, 000 resulted in between 3GB and 12GB RAM being used, and between 5 and 12 hours of CPU time for the calculation of a single magnitude. Each data point plotted in Section 3 required that level of resources. Interestingly the metric spaces which needed the most time and memory were those near the 'shoulder' in each of the graphs of Section 3 where the data-points begin to flatten out at the top. I should add that I have given no thought to how accurate the answer maple gives is, in terms of what sort of rounding errors would be present after row reducing a 25, 000 × 25, 000 matrix, but, nonetheless, the numerical answers obtained looked sufficiently convincing.
E-mail address: s.willerton@sheffield.ac.uk School of Mathematics and Statistics, Hicks Building, University of Sheffield, Sheffield, S3 7RH, UK