1 Introduction

Let us start with some definitions. We call any point set that determines at most k distances a k -distance set. We denote by \(m_k(d)\) the cardinality of the largest k -distance set in \({\mathbb {R}}^d\). A balanced complete s -partite graph on n vertices is a graph whose vertices are partitioned into k groups of size \(\lfloor n/s\rfloor \) or \(\lceil n/s\rceil \), and in which two vertices are connected by an edge if and only if they belong to different groups. We denote by T(ns) the number of edges in a balanced complete s-partite graph on n vertices. A set \(P\subseteq {\mathbb {R}}^d\) is separated if \(\Vert p_1-p_2\Vert \ge 1\) for any \(p_1,p_2\in P\) with \(p_1\ne p_2\). Let us formulate the main result of this paper.

Theorem 1.1

The following holds for \(k\le 3\) and any d, and for any fixed k and \(d\ge d_0(k)\).

  1. (i)

    There exists \(\varepsilon =\varepsilon (k,d)>0\), such that for any sequences \(t_1,\ldots ,t_k\ge 1\) of distances the following is true. If \(P\subseteq {\mathbb {R}}^d\) is a set such that for any \(p_i,p_j\in P\) with \(p_i\ne p_j\) we have \(\Vert p_i-p_j\Vert \in [t_1,t_1+\varepsilon ]\cup \cdots \cup [t_k,t_k+\varepsilon ]\), then P has size at most \(m_k(d)\). (Stated differently, \(M_k(d) = m_k(d)\).)

  2. (ii)

    There exists \(n_0(k,d)>0\), such that for any sequence \(t_1,\dots ,t_k>0\) of distances the following is true. If \(P\subset {{\mathbb {R}}}^d\) is a separated set of size \(n\ge n_0\), then the number of pairs of points in P whose distance lies in\([t_1,t_1+1]\cup \cdots \cup [t_k,t_k+1]\) is at most \(T(n,m_k(d-1))\). This bound is sharp. Moreover, the same holds with intervals of the form \([t_i,t_i+cn^{1/d}]\) for some \(c=c_0(k,d)>0\).

Theorem 1.1 (ii) for \(k=1\) was proved by Erdős et al. [11] (see Theorem 1.5 below). For \(k=2\), it was shown by Erdős et al. [10] in a slightly weaker form (see Theorem 1.8 below). Although (i) and (ii) are strongly related, the “max clique” problem in (i) has not been addressed before. Theorem 1.1 is a combination of Theorems 1.15 and 1.18 below.

In the long introductory section that follows, we tried to address several points:

  • First, we relate the study of “nearly-equal distances” to that of “equal distances”. The history of the latter is summarised in the next subsection, and the relation between the two notions is developed in Sect. 1.4, in which we give constructions of nearly k-distance sets and compare them with the known constructions of k-distance sets.

  • Second, we relate the older Turán-type problem on the number of “nearly-equal distances” to the proposed problem of determining the largest nearly k-distance set. We give the history of this Turán-type problem in Sect. 1.2, introduce the study of nearly k-distance sets in Sect. 1.3, and establish the first result that relates the two questions in Sect. 1.4.

  • Third, we introduce some of the more technical, but important, notions used in the proofs in Sect. 2, and in particular \(\alpha \)-flat nearly k-distance sets, defined in Sect. 1.3.1. It is via the notion of \(\alpha \)-flat nearly k-distance sets that we actually establish the link between the “nearly k-distance set” problem and the Turán-type problem.

Our main results are presented in Sect. 1.5, with their proofs in Sect. 2.

1.1 Equal Distances

In 1946, Erdős [6] asked the following two questions, which greatly influenced the course of discrete geometry. Take a set X of n points on the plane.

Question 1.2

What is the smallest number of distinct distances that X can determine?

Question 1.3

What is the maximum number of equal distances that X can determine?

These questions have a rich history, and we refer the reader to the book of Brass et al. [4] and the references therein. In the recent years, the development of algebraic methods in discrete geometry lead to a breakthrough of Guth and Katz [16], who showed that the quantity in the first question is \(\Omega (n/{\log n})\), which almost matches Erdős’ upper bound \(O(n/{\log ^{1/2}n})\). For \({{\mathbb {R}}}^d\) with \(d\ge 3\) Solymosi and Vu [26] proved that the quantity in the first question is \(\Omega \bigl (n^{(2/d)(d+1)/(d+2)}\bigr )\), while Erdős proved the close and conjecturably sharp upper bound \(O(n^{2/d})\).

Even though Questions 1.2 and 1.3 seem to have exactly the same flavour, (which is backed by, e.g., the fact that upper bounds in Question 1.3 imply lower bounds in Question 1.2), much less is known about Question 1.3. The best upper bound \(O(n^{4/3})\) is due to Spencer et al. [27], and the best lower bound is due to Erdős is \(\Omega (n^{1+c/{\log \log n}})\) for some \(c>0\). Interestingly, this problem becomes much simpler in dimensions \(d\ge 4\): there are point sets that determine quadratically many unit distances. (Brass [3] and van Wamelen [30] determined the maximum number of unit distances exactly for \(d=4\) and Swanepoel [28] for even \(d\ge 6\) and large n, respectively.) Stated slightly differently, Question 1.2 asks to determine \(m_k(2)\). The bounds mentioned above give \(\Omega (k\log ^{1/2}k)\le m_k(2)\le O(k\log k)\). In 1947, Kelly [17] showed that \(m_2(2) = 5\). Larman et al. [22] showed that \(m_2(d)\le (d+1)(d+4)/2\). Several years later, Bannai et al. [1] and independently Blokhuis [2] found the following better bound, which additionally works for any k:

$$\begin{aligned} m_k(d)\le \left( {\begin{array}{c}d+k\\ k\end{array}}\right) . \end{aligned}$$
(1)

There is the following very natural construction of a k-distance set in \({\mathbb {R}}^d\) if \(k\le d+1\): in \({\mathbb {R}}^{d+1}\), take all vectors in \(\{0,1\}^{d+1}\) with exactly k many 1’s. Then they lie on a sphere in the hyperplane \(\sum x_i=k\) and determine only \(k+1\) distinct scalar products (and thus only k distinct distances). This gives the lower bound

$$\begin{aligned} m_k(d)\ge \left( {\begin{array}{c}d+1\\ k\end{array}}\right) . \end{aligned}$$
(2)

We will refer to (1) and (2) many times in the proofs. Table 1, taken from a paper of Szöllősi and Östergård [29], summarises the best known lower bounds on (and in some cases exact values of) \(m_k(d)\) for small values of k and d. Note also that it is easy to see that for any d we have \(m_1(d)=d+1\) and for any k we have \(m_k(1) = k+1\).

Table 1 Lower bounds on \(m_k(d)\)

1.2 Nearly Equal Distances

Most of the results on k-distance sets use proofs with an algebraic flavour and often use results on incidences of points and surfaces. In the 90s, Erdős et al. [11] proposed the following variant of the problem, which is not of this type: given a set of n points on the plane, how many of the distances between the points could be nearly equal, that is, that fall into the interval \([t,t+1]\) for some t? To avoid trivialities, we only consider separated sets.

It turns out that the answer to this question is very different from the answer to Question 1.3: we can have as many as \(n^2 \) nearly equal distances in a separated set of size 2n. To see this, take 2n points of the form \((x_1,x_2)\), where \(x_1\in \{0,n^2\}\) and \(x_2\in \{1,\ldots ,n\}\). Then any distance between points with different \(x_1\)-coordinates is between \(n^2\) and \(\sqrt{n^4+n^2}<n^2+1\).

This example turns out to be optimal. The following theorem was proved by Erdős, Makai, Pach, and Spencer.

Theorem 1.4

[11, Theorem 3] Let P be a separated set of n points in the plane. If n is sufficiently large, then, for every \(t>0\), the number of pairs of points in P whose distance lies in the interval \([t,t+1]\) is at most \(\lfloor n^2/4\rfloor \). This bound can be attained for every \(t\ge t(n)\), where t(n) is a suitable function of n.

They have studied two natural types of generalisations: one deals with higher dimensions and the other with more intervals in which the distances may fall.

Theorem 1.5

[11, Theorem 5] Let P be a separated set of n points in \({\mathbb {R}}^d\). If n is sufficiently large, then for every \(t>0\), the number of pairs of points in P whose distance lies in the interval \([t,t+1]\) is at most T(nd). This bound can be attained for every \(t\ge t_0(d,n)\), where \(t_0(d,n)\) is a suitable function of d and n.

In the case of several intervals, Erdős et al. [9] proved the following theorem.

Theorem 1.6

[9] Let P be a separated set of n points in the plane, and let k be a positive integer. Then for any \(\gamma >0\) and sufficiently large n the following is true. For any \(t_1,\ldots ,t_k>0\), the number of pairs of points in P whose distance lies in \([t_1,t_1+1]\cup \cdots \cup [t_k,t_k+1]\) is at most

$$\begin{aligned} \frac{n^2}{2}\biggl (1-\frac{1}{k+1}+\gamma \biggr ). \end{aligned}$$

This estimate is tight for every fixed k and for some \(t_1=t_1(k,n),\ldots ,t_k=t_k(k,n)\).

Actually, they have proved something stronger: the allowed intervals in Theorems 1.41.7, and 1.6 are of the form \([t_i,t_i+c\sqrt{n}]\), \([t_i,t_i+c(d)n^{1/d}]\), and \([t_i,t_i+c(k,\gamma )\sqrt{n}]\) respectively, where cc(d), and \(c(k,\gamma )\) are constants (only depending on their arguments).

In [23] Makai et al. surveyed the results on this topic and also stated the following theorem that was supposed to appear in a follow-up paper by Erdős, Makai, and Pach.

Theorem 1.7

([23, Thm. 2.4], stated without proof)  Let \(d\ge 2\) be an integer and let P be a separated set of n points in \({\mathbb {R}}^d\). For any \(\gamma >0\) and sufficiently large n the following is true. For any \(t_1,t_2>0\) the number of pairs of points in P whose distance lies in \([t_1,t_1+1]\cup [t_2,t_2+1]\) is at most

$$\begin{aligned} \frac{n^2}{2}\biggl (1-\frac{1}{m_2(d-1)}+\gamma \biggr ). \end{aligned}$$

This bound is asymptotically tight for some \(t_1=t_1(n)\) and \(t_2=t_2(n)\).

The proof of this theorem was kept in the form of handwritten notes until recently, when Makai and Pach [10] placed on the arXiv a typed version of those notes (joint with Paul Erdős). There, they prove Theorem 1.7 in a stronger form.

Theorem 1.8

[10, Thm. 1] The statement of Theorem 1.7 is true. Moreover, even with intervals of the form \([t_i,t_i+c_d n^{1/d}]\), where \(c_d>0\) is a constant that depends on d, the number of such pairs is at most

$$\begin{aligned} T(n,m_2(d-1))=\frac{n^2}{2}\biggl (1-\frac{1}{m_2(d-1)}\biggr )+O(1) \end{aligned}$$

if \(d\notin \{ 4,5\}\).

Erdős et al. [10, Thm. 2] also considered a less restrictive variant of the notion of nearly k-distance sets. Let us denote by \(W_k(d)\) the maximum cardinality N such that for any \(\varepsilon >0\) there exist \(t_1\le \ldots \le t_k\) and a set \(S\subset {\mathbb {R}}^d\) with \(|S|=N\) such that for any \(p_1\ne p_2\in S\) we have

$$\begin{aligned} \Vert p_1-p_2\Vert \in \bigcup _{i=1}^k\,[t_i,(1+\varepsilon ) t_i].\end{aligned}$$

In [10] they proved that \(W_k(d)=(d+1)^k\), showing that “weakly” nearly k-distance sets can be much bigger than k-distance sets.

1.3 Nearly k-Distance Sets

We say that a separated set of points P is an \(\varepsilon \)-nearly k-distance set with distances \(1<t_1<\ldots <t_k\) if

$$\begin{aligned} \Vert p_1-p_2\Vert \in \bigcup _{i=1}^k\,[t_i,t_i+\varepsilon ]\end{aligned}$$

holds for any \(p_1,p_2\in P\) with \(p_1\ne p_2\). By analogy with \(m_k(d)\), for \(k\ge 1\) and \(d\ge 0\) let \(M_k(d)\) denote the largest number M such that for any \(\varepsilon >0\) there exists an \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^d\) of cardinality M.Footnote 1 Obviously, \(M_k(d)\ge m_k(d)\). An expression equivalent to \(M_k(d)\) occurs in [10, page 19], where they speculate that “for k fixed, d sufficiently large probably \(M_k(d)=m_k(d)\).” We confirm this later.

Note that the difficulty in relating the maximal cardinalities of k-distance sets and nearly k-distance sets lies in the fact that, in nearly k-distance sets, distances of different order of magnitude may appear. If we additionally assume that \({t_{i+1}}/{t_i}\le K\) for some universal constant K in the definition of nearly k-distance sets, a compactness argument would immediately imply that \(m_k(d)\) equals this modified \(M_k(d)\) (see Lemma 2.2 below).

For \(d,k\ge 1\) let \(M_k(d,n)\) denote the largest number M for which there is a separated set \(S\subseteq {\mathbb {R}}^d\) of n points and k real numbers \(1\le t_1\le \ldots \le t_k\) such that the number of pairs \(\{p_1,p_2\}\) with \(p_1,p_2\in S\) satisfying

$$\begin{aligned} \Vert p_1-p_2\Vert \in \bigcup _{i=1}^k\,[t_i,t_i+1] \end{aligned}$$
(3)

is at least M. In these terms, Theorems 1.41.8 determine (or asymptotically determine) the quantity \(M_k(d,n)\) for \(k=1,2\) and \(d\ge 2\), as well as for \(k\ge 1\) and \(d=2\), provided that n is large enough. It is natural to state the following general problem.

Problem 1.9

For any fixed \(k,d\ge 1\) and \(n\ge n_0(k,d)\), determine, at least asymptotically, the value of \(M_k(d,n)\).

1.3.1 Flat Sets

A subspace of a Euclidean space means a linear subspace. A plane of a Euclidean space means an affine plane.

For reasons that appear to be technical, let us also introduce the following notions. We usually use the notation \(\Gamma \) (or \(\Gamma _i\)) to denote linear subspaces of \({\mathbb {R}}^d\), and \(\Lambda \) (or \(\Lambda _i)\) for affine planes. The angle between a vector \(v\ne 0\) and a non-zero linear subspace \(\Gamma \) is the smallest angle that appears between v and the vectors in \(\Gamma \setminus \{0\}\). For two points \(p,q\in {\mathbb {R}}^d\) we denote by \(p-q\) the vector pointing from q to p.

For \(1\le d\le d'\) we say that a set of vectors \(V\subseteq {\mathbb {R}}^{d'}\setminus \{0\}\) is \((d,\alpha )\) -Flat if there exists a linear subspace \(\Gamma \) of dimension d such that the angle between any \(v\in V\) and \(\Gamma \) is at most \(\alpha \). (For \(d=d'\) this is considered to be true for any \(\alpha \ge 0\).) If \(\Gamma \) is such subspace, we say that V is \((d,\alpha )\) -Flat with respect to \(\Gamma \). Let \(P\subseteq {\mathbb {R}}^{d'}\) be a set of points and p be a point in P. We say that P is \((p,d,\alpha )\) -flat (with respect to a linear d-subspace \(\Gamma _p\)) if \(\{p-q:q\in P{\setminus } \{p\}\}\) is \((d,\alpha )\)-Flat (with respect to \(\Gamma _p)\). We call a set P \((d,\alpha )\) -flat if P is \((p,d,\alpha )\)-flat for every \(p\in P\). We say P is globally \((d,\alpha )\) -flat if \(\{p-q:p,q\in P,\,p\ne q\}\) is \((d,\alpha )\)-Flat. If \(|P|\le 1\), then we define P to be \((p,0,\alpha )\)-flat (for any \(p\in P\)) and \((0,\alpha )\)-flat.

Note that there is a difference between flatness and global flatness. For any \(d\ge 2\) and \(\beta <\arcsin d^{-1/2}\), \((d,\alpha )\)-flatness for any \(\alpha \) does not in general imply global \((d,\beta )\)-flatness. For an example for \(d=2\), consider the following set in \({{\mathbb {R}}}^3\): \(\{(0,0,1),(0,0,0),(K,0,0),(K,1,0)\}\), where \(K=K_0(\alpha ,\beta )\) is sufficiently large. However, if for some universal constant K a set S is \((p,d,\alpha )\)-flat for some \(p\in S\) and \({\Vert p_1-p_2\Vert }/{\Vert q_1-q_2\Vert }\le K\) for each \(p_1,p_2,q_1,q_2\in S\) with \(q_1\ne q_2\), then S is globally \((d,K'\alpha )\)-flat, where \(K'\) is a constant depending on K and d.

For \(0\le d \le d'\) let \(N_k(d',d)\) be the largest number N such that for every \(\varepsilon ,\alpha >0\) there exists a \((d,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^{d'}\) of cardinality N. Note that \(N_k(d',0)=1\). For \(d\ge 1\) we denote \(N_k(d):= N_k(d,d-1)\). Then we have \(M_k(d-1)\le N_k(d)\le M_k(d)\). Indeed, any \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^{d-1}\) is a \((d-1,0\))-flat \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^d\).

Surprisingly, the behaviour of \(M_k(d,n)\) is asymptotically determined by the value of \(N_k(d)\) (see Proposition 1.13 and Theorem 1.17), thus the asymptotic solution of Problem 1.9 reduces to the following problem.

Problem 1.10

For any \(k,d\ge 1\) determine \(N_k(d)\).

Below, we state Conjecture 1.11, which relates the behaviour of \(M_k(d)\), \(N_k(d)\), and \(m_k(d)\).

1.4 Constructions of Nearly k-Distance Sets

In this subsection, we relate the quantities \(M_k(d)\), \(M_k(n,d)\), \(N_k(d)\), and \(m_k(d)\). For \(d\ge 0\) and \(k\ge 1\) let us define

$$\begin{aligned} M'_k(d):=\max {\left\{ \prod _{i=1}^s m_{k_i}(d_i):\sum _{i=1}^sk_i=k,\,\sum _{i=1}^sd_i=d\right\} }. \end{aligned}$$
(4)

Conjecture 1.11

\(N_k(d+1)=M_k(d)=M'_k(d)\) holds for all but finitely many pairs \(k,d\ge 1\).

We do not have have any examples with \(N_k(d+1)>M_k(d)\) or \(M_k(d)>M'_k(d)\), and we believe that the first equality should always hold. However, there are constructions, that we will describe later, that suggest there could be some examples with \(M_k(d)>M'_k(d)\). In Theorem 1.15 we show that the conjecture holds for every k and sufficiently large d.

Proposition 1.12

\(M_k(d)\ge M'_k(d)\) holds for every \( k,d\ge 1\).

Proof

Let \(\sum _{i=1}^sk_i=k\) and \(\sum _{i=1}^sd_i=d\). Then there is an \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^d\) of cardinality \(\prod _{i=1}^s m_{k_i}(d_i)\) given by the following construction. For each i let \(S_i\) be a \(k_i\)-distance set in \({\mathbb {R}}^{d_i}\) of cardinality \(m_{k_i}(d_i)\) and such that the distances in \(S_i\) are much larger (in terms of \(\varepsilon \)) than the distances in \(S_{i-1}\). Then \(S_1\times \dots \times S_s\) is an \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^d\) of cardinality \(\prod _{i=1}^s m_{k_i}(d_i)\). \(\square \)

Remark

The example given above can be turned into a globally flat set in \({{\mathbb {R}}}^{d+1}\), providing a lower bound on \(N_k(d+1)\). Actually, we do not know of any case when a flat set would provide a strictly better bound on \(N_k(d)\) than a globally flat set. However, for some k and d there are extremal examples that are not globally flat. More precisely, for any \(\alpha ,\varepsilon >0\) there is a \(\beta >0\) depending only on d, such that we can construct a \((d-1,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set S of cardinality \(N_k(d)\) that is not globally \((d-1,\beta )\)-flat.

Indeed, for example, for any \(\alpha , \varepsilon > 0\) we can construct \((3,\alpha )\)-flat \(\varepsilon \)-nearly 2-distance sets of cardinality \(N_2(4)=m_2(3)=6\) (see Theorem 1.15) in \({\mathbb {R}}^4\) as follows. Consider an equilateral triangle \(\{p_1,p_2,p_3\}\) in \({\mathbb {R}}^4\) of side length K spanning a 2-dimensional plane H. For each \(i\in [3]\) let \(p_i-q_i\) be a vector of length 1 orthogonal to H. It is not hard to check that \(P=\{p_1,p_2,p_3,q_1,q_2,q_3\}\) is a \((3,\alpha )\)-flat \(\varepsilon \)-nearly 2-distance set if \(K=K(\alpha ,\varepsilon )\) is sufficiently large. However, if \(p_1-q_1\) and \(p_2-q_2\) are orthogonal, then P is not globally \((3,\beta )\)-flat, where \(\beta \) can be taken to be \(\pi /6\).

We can give a lower bound on \(M_k(d,n)\) in terms of \(N_k(d)\).

Proposition 1.13

For any fixed \(k\ge 1\), \(d\ge 2\) we have

$$\begin{aligned} M_k(d,n)\ge T(n,N_k(d))\ge \frac{n^2}{2}\biggl (1-\frac{1}{N_k(d)}\biggr )+O(1). \end{aligned}$$
(5)

The statement of Proposition 1.13 also holds with \(N_k(d)\) replaced by \(M_k(d-1)\), since \(M_k(d-1)\le N_k(d)\).

Proof

Let \(\alpha ,\varepsilon >0\) be sufficiently small, and \(t_1>10n^2\). Consider a \((d-1,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set \(S'\subseteq {\mathbb {R}}^d\) with distances \(t_1\le \ldots \le t_k\) of cardinality \(N_k(d)\). For simplicity assume that \(N_k(d)\,|\,n\).

For each \(p\in S'\), let \(\Gamma _p\) be a \((d-1)\)-dimensional subspace such that \(S'\) is \((p,d-1,\alpha )\)-flat with respect to \(\Gamma _p\). Further, let \(v_p\) be a unit vector that is orthogonal to \(\Gamma _p\). Replace each point \(p\in S'\) with an arithmetic progression \(A_p=\{p+i v_p:i\in \{1,\dots ,{n}/{N_k(d)}\}\}\).

If \(|{\sin \alpha }|<{1}/({10n})\), then the distances between any point from \(A_p\) and any point from \(A_q\) for \(p\ne q\), are within 1/2 from the distance between p and q. The set \(S=\bigcup _{p\in S'}A_p\) has cardinality n. Define a graph G on S by putting an edge between two points if their distance is in \([t_1-1/2,t_1+1/2]\cup \cdots \cup [t_k-1/2,t_k+1/2]\). Then G is an \(N_k(d)\)-partite graph with equal parts. By definition, the number of edges in such graph is \(T(n,N_k(d))\). This argument can easily be modified to deal with the case when \(N_k(d){\not |}\,n\). \(\square \)

We point out the following difference between the case of \(k=1\) and \(k\ge 2\) of the known constructions with \(M_k(d,n)\) nearly equal distances. Let \(S\subseteq {\mathbb {R}}^d\) be a set of n points and \(1\le t_1\le \ldots \le t_k\) be reals such that the number of pairs \(\{p_1,p_2\}\) with \(p_1,p_2\in S\) and with \(\Vert p_1-p_2\Vert \in \bigcup _{i=1}^k[t_i,t_i+1]\) is \(M_k(d,n)\). For \(k=1\) the known constructions are all of the type that was described in Proposition 1.13 with \(S'\) being globally \((d-1,\alpha _n)\)-flat with \(\alpha _n\rightarrow 0\), and thus the normal vectors \(m_v\) being almost parallel. However, this is not the case for \(k=2\). For \(k=2\), \(d=4\), as explained before, there are \((3,\alpha )\)-flat \(\varepsilon \)-nearly 2-distance sets of cardinality \(N_2(4)\) in \({\mathbb {R}}^4\) for any \(\alpha ,\varepsilon >0\) that are not globally \((3,\pi /6)\)-flat, and hence the corresponding normal vectors \(m_v\) are not pairwise almost parallel.

1.4.1 Example from [10]

The authors of [10] suggested that a construction in the same spirit as the one in Proposition 1.13 should give a close to optimal bound for \(M_k(d,n)\). With the two propositions above in hand, their construction is easy to describe: take \(k_1,\ldots , k_s\), \(d_1\le \ldots \le d_s\), such that \(\sum _{i=1}^sk_i = k\) and \(\sum _{i=1}^s d_i=d-1\). Next, represent the hyperplane \(x_d=0\) as \({\mathbb {R}}^{d_1}\times \cdots \times {\mathbb {R}}^{d_s}\). In each \({\mathbb {R}}^{d_i}\), take the following \(k_i\)-distance set: either the set that gives the lower bound (2) or, if \(d_i=1\), an arithmetic progression of length \(k_i+1\). Then combine the sets in the same way as in the proof of Proposition 1.12, obtaining a nearly k-distance set in the hyperplane \(x_d=0\). Then extend it in \({\mathbb {R}}^d\) as in Proposition 1.13. Assume that either \(\ell =0\) and \(d_1> 1\), or \(\ell \ge 1\) and \(d_{\ell }=1<d_{\ell +1}\), and we have chosen arithmetic progressions in the first \(\ell \) subspaces. The obtained set has \({n^2}(1-1/Q+o(1))/2\) distances that fall in the k intervals, where

$$\begin{aligned} Q := (k_1+1)\cdot \ldots \cdot (k_{\ell }+1)\cdot {\left( {\begin{array}{c}d_{l+1}+1\\ k_{l+1}\end{array}}\right) }\cdot \ldots \cdot {\left( {\begin{array}{c}d_s+1\\ k_s\end{array}}\right) }.\end{aligned}$$
(6)

One then needs to optimise the value of Q over all choices of \(d_i\), \(k_i\), \(\ell \), and s. It is possible that Q gives the value of \(N_k(d)\) and \(M_k(d+1)\) in many cases. Evidently, in order to maximise Q, one should take \(k_1,\dots ,k_{\ell }\) to be nearly equal.

We add the following observation.

Observation

For any fixed kd, there is a choice of \(s,\ell ,k_i,d_i\) that maximises Q and such that \(\ell = s-1\), that is, there is only one term of the form \({\left( {\begin{array}{c}d_i+1\\ k_i\end{array}}\right) }\).

Let us prove this. First, we observe that for any \(i\ge l+1\), we may suppose that \(k_i\le d_i/2\). Otherwise, reducing the number of distances does not decrease Q. We need the following claim.

Claim 1.14

For any integers \(a_1,a_2,z_1,z_2\) such that \(z_1,z_2\ge 3\) and \(a_1\le z_1/2\), \(a_2\le z_2/2\), except \(z_1=z_2=4\) and \(a_1=a_2=2\), we have

$$\begin{aligned} {\left( {\begin{array}{c}z_1\\ a_1\end{array}}\right) }{\left( {\begin{array}{c}z_2\\ a_2\end{array}}\right) }\le {\left( {\begin{array}{c}z_1+z_2-1\\ a_1+a_2\end{array}}\right) }.\end{aligned}$$
(7)

The proof is a simple calculation and is deferred to the appendix. Using this claim, we can replace any pair of binomial coefficients with \(d_i,d_j\ge 2\), \(i,j>l\), in (6) with one binomial coefficient without decreasing Q, unless both binomial coefficients are \(\left( {\begin{array}{c}4\\ 2\end{array}}\right) \). Moreover, if \(d_i=1\) for \(i>l\), then \(k_i=1\) and we may simply replace \(\left( {\begin{array}{c}1+1\\ 1\end{array}}\right) \) by \((1+1)\), making it a term of the first type. Finally, if we have two terms of the form \(\left( {\begin{array}{c}4\\ 2\end{array}}\right) \), then we may replace them with \((2+1)\cdot \left( {\begin{array}{c}6\\ 2\end{array}}\right) \), which is larger, and also uses six dimensions and four distances.

1.4.2 Examples with fixed k or d

It is not true that \(M_k(d)=m_k(d)\) holds for every k and d. There are several examples of k and d for which we need more than one multiplicative term to maximise (4), and hence \(M_k(d)\ge M'_k(d)>m_k(d)\). Some of these examples we list below. When needed, we rely on the information from Table 1.

  • In \({\mathbb {R}}^2\) the largest cardinality of a 6-distance set is 13, while the product of two arithmetic progressions of length 4 (\(d_1=d_2=1\), \(k_1=k_2=3\) in (6)) gives an \(\varepsilon \)-nearly 6-distance sets of cardinality 16. Thus \(M_6(2)\ge M'_6(2)\ge 16>m_2(6)\).

  • In \({\mathbb {R}}^3\), the largest 4-distance set has 13 points, while we can construct \(\varepsilon \)-nearly 4-distance sets of cardinality \(15=3\cdot 5\) as a product of arithmetic progression of length 3 and a 2-distance set on the plane of cardinality 5. Thus \(M_4(3)\ge M'_4(3)\ge 15>m_4(3)\).

  • In \({\mathbb {R}}^2\) the cardinality of a k-distance set is \(O (k\log k)\) by [16], while the product of two arithmetic progressions of length \(\lfloor k/2 \rfloor +1\) and of length \(\lceil k/2 \rceil +1 \) gives an \(\varepsilon \)-nearly k-distance set of cardinality \((\lfloor k/2 \rfloor +1)(\lceil k/2 \rceil +1 )\ge k^2/4\).

  • In \({\mathbb {R}}^d\) for \(d\ge 3\) the cardinality of a k-distance set is \(O(k^{(d/2)(d+2)/(d+1)})\) by the result of Solymosi and Vu [26]. On the other hand, the product of d arithmetic progressions of size \(\lfloor k/d \rfloor +1\) gives an \(\varepsilon \)-nearly k-distance set of cardinality \((\lfloor k/d\rfloor +1)^d\ge (k/d)^d\).

The largest 5-distance set in \({\mathbb {R}}^2\) is of cardinality 12. We may construct \(\varepsilon \)-nearly 5-distance sets using product-type constructions as described in the list above, also of cardinality 12. In addition, we can construct an \(\varepsilon \)-nearly 5-distance set of size 12 that is not of this product construction, and neither does it have the structure of a 5-distance set. Take a large equilateral triangle, and in each of its vertices put a rhombus of a much smaller size with angles \(\pi /3\) and \(2\pi /3\) such that the angle of the corresponding sides of the rhombus and the triangle is \(\pi /2\) as shown in Fig. 1. This example makes us suspect that there could be some exceptions to Conjecture 1.11. Though we also believe there are only finitely many examples with \(M_k(d)\) points that are not products of \(k_i\)-distance sets.

Fig. 1
figure 1

\(\varepsilon \)-nearly 5-distance set on the plane that is not product-type

1.5 Main Results

Let us stress that all the sets that we consider in the paper are separated, which we assume tacitly for the rest of the paper. The first theorem deals with small values of k and is one of the main results of the paper.

Theorem 1.15

We have \(N_k(d+1)=M_k(d)=m_k(d)\) for \(d\ge 0\) if one of the following holds:

  1. (i)

    \(d\ge d(k)\), where d(k) is some constant depending on k;

  2. (ii)

    \(k\le 3\).

For fixed d and large k we prove the following simple estimate.

Theorem 1.16

We have \(M_k(d)=\Theta (k^{d})\) and \(N_k(d)=\Theta (k^{d-1})\) for any fixed \(d\ge 2\).

We conjecture that \(M_k(d)= (k/d)^d+o(k^d)\).

Another main result of the paper is the following theorem, which gives the promised relation between \(N_k(d)\) and \(M_k(d,n)\).

Theorem 1.17

For any \(d\ge 2\), \(k\ge 1\), \(\gamma >0\) there exists \(n_0\), such that for any \(n\ge n_0\) we have

$$\begin{aligned} T(n,N_k(d))\le M_k(d,n)\le T(n,N_k(d))+\gamma n^2.\end{aligned}$$
(8)

Moreover, (8) remains valid if in the definition of \(M_k(d,n)\) we change the intervals of the form \([t_i,t_i+1]\) to intervals of the form \([t_i,t_i+cn^{1/d}]\) for some constant \(c=c(k,d,\gamma )>0\).

Theorem 1.17 combined with Theorem 1.15 gives the value of \(M_2(d,n)\), \(M_3(d,n)\), and \(M_k(d,n)\) for \(d\ge d_0(k)\) asymptotically in terms of \(m_2(d)\), \(m_3(d)\), and \(m_k(d)\). In the mentioned cases, we can strengthen the result and determine the exact value of \(M_k(d,n)\) for large n. In particular, this extends results of [10] (cf. Theorem 1.8) to the cases of \(d=4,5\).

Theorem 1.18

For \(n\ge n_0(d,k)\) we have

$$\begin{aligned} M_k(d,n) = T(n,m_k(d-1)) \end{aligned}$$

if either \(k\le 3\) or \(d\ge d(k)\). Moreover, the same holds with intervals of the form \([t_i,t_i+cn^{1/d}]\) for some \(c=c(k,d)>0\).

Again, in view of Proposition 1.13, we only need to show that \(M_k(d,n) \le T(n,m_k(d-1))\). This is a consequence of the more general Theorem 2.15, presented in Sect. 2.5. Observe that \(M_k(d,n)\le T(n,M_k(d))\) is obvious from Turán’s theorem and the definition of \(M_k(d)\). Hence the difficulty in proving Theorem 1.17 lies in bounding \(M_k(d,n)\) by the maximal cardinality of \((d-1,\alpha )\)-flat nearly k-distance sets. Similarly, the difficulty in proving Theorem 1.18 is bounding \(M_k(d,n)\) by the maximal cardinality of k-distance sets in the space of one dimension smaller.

We note that many different classes of dense geometric graphs were studied from a similar perspective. We mention diameter graphs [19, 21, 28] and double-normal graphs [20, 24, 25]. In some cases, the relationship between the largest clique and the maximum number of parts in an arbitrarily large complete multipartite graph is quite intricate, as it is the case for double-normal graphs, see [20].

Note that an extended abstract [14] of this work with the same title was accepted for the Eurocomb 2019 conference.

2 Proofs

The structure of this section is as follows. We start by giving sketches of the proofs of the theorems. The first subsection gives auxiliary results that are going to be used in the proof of Theorem 1.15, which is doubtless the hardest result in the paper. Most of this section can be skipped in the first reading. We summarise its content below. Sections  2.2 and 2.3 are devoted to the proof of parts (i) and (ii) of Theorem 1.15, respectively. In Sect. 2.4 we give a simple and short proof of Theorem 1.16. This is largely independent from the previous material. In Sect. 2.5 we give the proofs of Theorems 1.18 and 1.17. These proofs are almost completely independent of the previous subsections, they basically only require Theorem 1.15 as an input.

Section 2.1: The section starts with an important Lemma 2.1 which allows us to find a very precise structure in the graph of distances between the points in case we can split distances into ‘small’ and ‘large’: it splits into clusters of points at small distances, and the distances between any two points from different clusters are large. Lemma 2.2 is a compactness statement, which states that, in case the ratio of the largest and the smallest distance is uniformly bounded, then a nearly k-distance set converges to a usual k-distance set, and, in particular, is at most as big. This gives the intuition that non-trivial cases in the proof of Theorem 1.15 deal with the case when \(t_{i+1}/t_i>K\) for some i and arbitrarily large K. The second part additionally tells us that, in case the ratio of two consecutive distances tends to 1, then these distances are ‘glued’, and in the limit we will have a \((k-1)\)-distance set. Lemma 2.3 gives a simple upper bound on \(M_k(d)\) only based on Lemma 2.2. Lemmas 2.42.5 develop the machinery to deal with almost-flat sets. First, we translate the simple statement that if a vector (or a set) lies in several planes, then it lies in their intersection to the almost-flat setting. Somewhat surprisingly, this turns out to be quite tricky. Lemma 2.5 is a culmination of the subsection and is a key complement to Lemma 2.1. It translates to the almost-flat setting the following simple argument. Assume that we are given a nearly k-distance set, and there is an i such that \(t_{i+1}/t_i>K\) for some large K. Then, using Lemma 2.1, we can split it into ‘red clusters’, such that inside the cluster each distance is at most \(t_i\), while the distance between any two points in different red cluster is at least \(t_{i+1}\). Moreover, assume that for any red cluster \(R_i\) and a point p outside it the distances between p and points from \(R_i\) are very close to the same \(t_j\), \(j\ge i+1\) (for later reference in the sketches, let us call this ‘property \(\star \)’). Then it is easy to see that \(R_i\) should be nearly orthogonal to \(p-r\) for any \(r\in R_i\). Thus, the intuition tells us that all red clusters should be close to planes that are orthogonal to the plane of B, where B is a set of points that includes exactly one point from each red cluster. This is not difficult to check for a set B that is ‘not flat’, e.g., an almost-regular simplex, but it requires preparations in general. In the first reading, we recommend to read Lemma 2.1, as well as the statements of Lemmas 2.2 and 2.5 and omit the rest.

Proof of Theorem 1.15

(i) The proof is by induction on k. We look for the last ‘big jump’ in the sequence of distances, and additionally induct on the position i of this jump (the size of the jump being dependent on the position: the smaller i is, the bigger the jump is). If \(i=k\) (i.e., \(t_k/t_{k-1}>K\)) then we use Lemma 2.5, even in the simple variant that we described above. In this case, the set B forms an almost-regular simplex, and we conclude that the red clusters must be almost-flat w.r.t. the plane, orthogonal to the plane of B. We then use the fact that \(m_{k-1}(d-j) m_1(j)<m_k(d)\) for large d. If \(i<k\), then the argument is mostly similar, however, it has an additional twist to deal with one complication. Namely, we may not be able to guarantee that property \(\star \) holds if two large distances have very small difference and thus apply Lemma 2.5. But then Lemma 2.2 (ii) helps us out, telling that in the limit these two distances glue. If this is the case, we ignore the orthogonality structure that can be given by Lemma 2.5, and apply a bound of the form \(m_{i-1}(d)m_{k-i}(d)<m_k(d)\), valid for d large w.r.t. k.

(ii) The proof follows a very similar outline as part (i). The case of two distances uses the same ideas as part (i), even in a simpler form. The case of three distances, however, poses some complications. First, if \(t_3/t_2>K\) then the proof is as in the case \(i=k\) above. If \(t_2/t_1>K>t_3/t_2>1+2/K\) then the proof is as above for \(i<k\), but with property \(\star \), i.e., our main tool is the ‘almost orthogonal decomposition’ via Lemma 2.5. If \(t_3/t_2<1+2/K\) then the two largest distances glue, and the argument as above allows us to finish the proof for \(d\ge 6\). However, this is not sufficient for small d, which we deal with separately. We have two subcases in this situation, each of which allow us to get more information on our nearly 3-distance set. The first subcase is when \(t_1\gg t_3-t_2\). In that case, we are again able to guarantee the almost-orthogonality of red clusters to the almost-regular simplex B (cf. Fig. 2) and again finish using Lemma 2.5. The second subcase is when \(t_1\) is not so large w.r.t. \(t_3-t_2\). We are then able to find additional structure in between any two red clusters, say \(R_i\) and \(R_{\ell }\). Namely, if both distances \(t_2,t_3\) appear from \(r\in R_i\) to points in \(R_{\ell }\), then at most one distance can appear between a point \(r'\in R_{\ell }\) and any point in \(R_i\). This turns out to be sufficient to settle this case. Such ‘bizarre’ cases as the last one also should give a hint on why it is difficult to extend the result to more distances. \(\square \)

We also note that an additional complication in both proofs is that we had to work with a notion of almost-flat sets (defined at the end of Sect. 2.1) instead of flat sets. This is only needed in order to prove Theorem 1.18. We omit the sketch of proof of Theorem 1.16, which is short and simple, and go on to the Turán-type results.

Proof of Theorem 1.18

The proof essentially uses certain supersaturation-type results for Turán’s theorem, and then refines the geometric structure of the relations between the points until we get a contradiction. We argue indirectly. Let \(\ell -1\) be the largest size of an almost-flat \(\varepsilon \)-nearly k-distance set. The main (and the one that is less standard) extremal graph theory tool is the following supersaturation result of Erdős that states that, once the number of edges in an n-vertex graph is at least \(T(n,\ell -1)+1\), it contains a positive fraction of all \((\ell -2)\)-cliques containing some edge e. Using this and some other results and ideas from exremal graph theory, we start with a graph that has one more edge than the theorem states and find the following configuration: a multipartite graph \(K_{1,1,2,\ldots ,2}\) with \(\ell \) parts, where any two points in the configuration lie at a distance \(\gg cn^{1/d}\), the distances between any two fixed parts all fall into the same interval \([t_i,t_i+cn^{1/d}]\), and any angle \(p_ip_jq_i\) for \(p_i,q_i\) belonging to the i-th part and \(q_j\) belonging to the j-th part, \(i\ne j\), is at most \(\alpha \). Then, after rescaling, we get a separated set with all distances falling into \([t_i',t_i'+\varepsilon ]\) for some i (thus the need for point of the set before the scaling to be far apart) and that can be shown to be almost-flat w.r.t. some hyperplanes.

Let us comment on the almost-flatness. Almost -flatness requires that the local flatness condition is satisfied for all but at most two vertices of the graph, and the reason for almost-flatness here (and, as a consequence, additional complications in the proof of Theorem 1.15) is the result of Erdős that we cited. It does not guarantee a positive density of \(\ell \)-cliques once we add an extra vertex (to do so, one has to add \(\gamma n^2\) extra edges, as in Theorem 1.17), it only guarantees a positive density of \((\ell -2)\)-cliques sharing some edge. As a result, the final graph has the first two parts of size 1, and we cannot ensure the local flatness condition in these vertices. \(\square \)

The proof of Theorem 1.17 follows the same logic and thus we omit it here.

2.1 Auxiliary Lemmas

Lemma 2.1

Let \(S\subseteq {\mathbb {R}}^d\) be a finite set. Assume that for every \(p_1,p_2\in S\) with \(p_1\ne p_2\) the pair \(\{p_1,p_2\}\) is coloured with red or blue, such that the distance between the points in any blue pair is strictly more than three times as big as the distance between any red pair. If B is a largest blue clique in S, then S can be partitioned into |B| vertex-disjoint red cliques \(R_1,\dots ,R_{|B|}\) having the following properties.

  • Each \(R_i\) shares exactly one vertex with B.

  • If \(p\in R_i\), \(q\in R_j\), and \(i\ne j\), then \(\{p,q\}\) is blue.

Proof

Take a largest blue clique \(B=\{p_1,\ldots ,p_s\}\). Construct \(R_i\) by including in it \(p_i\) and all the points that form a red pair with \(p_i\). By the triangle inequality each \(R_i\) is a red clique. Further, by the maximality of B, each point from S forms a red distance with at least one point in B, and thus \(R_1,\dots , R_b\) cover S. Next, they are disjoint: if \(p\in R_i\cap R_j\), then both \(\{p,p_i\}\) and \(\{p,p_j\}\) are red, which by triangle inequality implies that either \(i=j\) or that \(\{p_i,p_j\}\) is red (but the second possibility contradicts the definition of B). Finally, if \(p\in R_i\), \(q\in R_j\), \(i\ne j\), then \(\{p,q\}\) must be blue by the triangle inequality: otherwise \(\Vert p_i-q_j\Vert \le \Vert p_i-p\Vert +\Vert p-q\Vert +\Vert q-p_j\Vert \), and if all the pairs on the right are red, then \(\{p_i,p_j\}\) is red. \(\square \)

Note that a statement similar to that of Lemma 2.1 was also used in [9]. The next lemma follows by a standard compactness argument.

Lemma 2.2

Let \(S_1,S_2,\dots \) be a sequence such that \(0\in S_i\) is an \(\varepsilon _i\)-nearly k-distance set in \({\mathbb {R}}^{d'}\) with distances \(1\le t_{i,1}<\ldots <t_{i,k}\) and with \(\varepsilon _i\rightarrow 0\). Further, let \(\alpha _i\) be a sequence with \(\alpha _i\rightarrow 0\). Then the following is true.

  1. (i)

    If \(k=1\) or \(k\ge 2\) and there is a K such that \(\sup _i\max _{1\le j<k}({t_{i,j+1}}/{t_{i,j}})\le K\), then we have \(\limsup _{i\rightarrow \infty } |S_i|\le m_k(d')\). If additionally there is a \(0\le d\le d'\) such that for every i the set \(S_i\) is \((p_i,d,\alpha _i)\)-flat for some \(p_i\in S_i\), then \(\limsup _{i\rightarrow \infty } |S_i|\le m_k(d)\).

  2. (ii)

    If \(k\ge 2\) and there is a K such that \(\sup _i\max _{1\le j<k}({t_{i,j+1}}/{t_{i,j}})\le K\) and for some \(1\le r\le k-1\) we have \(\lim _{i\rightarrow \infty }({t_{i,r+1}}/{t_{i,r}})=1\), then \(\limsup _{i\rightarrow \infty } |S_i|\le m_{k-1}(d')\). If additionally for every i, \(S_i\) is \((p_i,d,\alpha _i)\)-flat for some \(p_i\in S_i\), then \(\limsup _{i\rightarrow \infty } |S_i|\le m_{k-1}(d)\).

Proof

We only give details of the proof of (ii), part (i) can be done similarly. We start with the first part of the statement. Take any sequence \(S_1,S_2,\ldots \), satisfying the conditions and scale each \(S_i\) by \({1}/{t_{i,1}}\). Abusing notation, we denote the new sets \(S_i\) as well. Then the condition \(\sup _i\max _{1\le j<k}({t_{i,j+1}}/{t_{i,j}})\le K\) implies that there is an absolute \(R>0\) such that each \(S_i\) is contained in a ball B with centre 0 and of radius R. A volume argument implies that there exists an \(M_K\) such that \(|S_i|\le M_K\) for all i. Take an infinite subsequence of \(S_1,S_2,\ldots \) in which all sets have fixed cardinality \(M\le M_K\). Using the compactness of

$$\begin{aligned} \underbrace{B\times \cdots \times B}_{M\text { times}}, \end{aligned}$$

select out of it a subsequence \(S_{i_1},S_{i_2},\ldots \) that pointwise converges to the set \(S:=\{P_1,\ldots , P_M\}\subset B\) with distances \(T_1,\ldots ,T_k\), and where \(T_j = \lim _{s\rightarrow \infty }({t_{i_s,j}}/{t_{i_s,1}})\). Note that \(T_{r+1}=T_r\) due to the assumption \(\lim _{i\rightarrow \infty }({t_{i,r+1}}/{t_{i,r}})=1\). Thus S is a \((k-1)\)-distance set, and so \(M = |S|\le m_{k-1}(d')\).

Let us next show the second part of the statement. Taking the set S as above, we obtain that it must additionally be (d, 0)-flat. This means that S lies in a d-plane, thus \(M= |S|\le m_{k-1}(d)\). \(\square \)

The statement below allows us to get a grip on \(M_k(d)\).

Lemma 2.3

For any \(1\le k\), and \(0\le d\le d'\) we have

$$\begin{aligned}N_k(d',d)\le f(d,k)=\max {\left\{ \prod _{i=1}^s m_{k_i}(d):\sum _{i=1}^s k_i=k\right\} }.\end{aligned}$$

In particular, \(M_k(d)<\infty \).

Note the difference in the definition of \(M'_k(d)\) and the function f above.

Proof

First note that f satisfies \(f(d,k_1+k_2)\ge f(d,k_1)f(d,k_2)\) for any \(1\le k_1,k_2\). Let S be a \((d,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^d\) with distances \(1\le t_1<\ldots <t_k\) and with sufficiently small \(\alpha ,\varepsilon \). We need to show that \(|S|\le f(d,k)\). For each d we induct on k.

If \({t_i}/({t_{i-1}+\varepsilon })\le 3\) holds for every \(1<i\le k\) (or if \(k=1\)), then by (i) of Lemma 2.2 we have \(|S|\le m_k(d)\le f(d,k)\). Otherwise, let i be the largest index such that \({t_i}/({t_{i-1}+\varepsilon })> 3\). For every \(p_1,p_2\in S\) with \(p_1\ne p_2\) colour the pair \(\{p_1,p_2\}\) with blue if \(\Vert p_1-p_2\Vert \ge t_i\) and with red otherwise. Let B be a largest blue clique in this colouring. By induction, \(|B|\le f(d,k-i+1)\) if \(\alpha \) and \(\varepsilon \) are sufficiently small. Next, by Lemma 2.1, S can be covered by |B| vertex disjoint red cliques \(R_1,\dots ,R_{|B|}\). By induction again, the cardinality of any red clique is at most \(f(d,i-1)\), thus

$$\begin{aligned}|S|\le f(d,k-i+1)f(d,i-1)\le f(d,k).\end{aligned}$$

\(\square \)

The next three statements describe some cases when \(\alpha \)-flatness with respect to different subspaces can be “combined” into \(\alpha \)-flatness with respect to a smaller-dimensional subspace. For a linear subspace \(\Gamma \) we denote by \(\Gamma ^{\bot }\) the orthogonal complement of \(\Gamma \), and for a vector \(v\in {\mathbb {R}}^d\setminus \{0\}\) we denote by \(v^{\bot }\) the \((d-1)\)-dimensional subspace orthogonal to v.

Lemma 2.4

For any \(\gamma '>0\) there exists \(\beta _0>0\) such that the following is true for all \(0<\beta \le \beta _0\) and all \(d\ge 1\). Let \(R\subseteq {\mathbb {R}}^d\) be a set of points, and let \(p\in R\). Further, let \(V\subset {\mathbb {R}}^d\setminus \{0\}\) be a set of vectors such that for every \(v\in V\) the set R is \((p,d-1,\beta ^d)\)-flat with respect to \(v^{\bot }\). If \(j\ge 1\) is the smallest integer for which V is \((j,\beta ^j)\)-Flat, then R is \((p,d-j,\gamma ')\)-flat.

Proof

We are going to prove that for every \(\gamma '>0\) there exists \(\beta _0>0\) such that the following is true for every \(0<\beta \le \beta _0\). Let \(w\in {\mathbb {R}}^d{\setminus }\{0\}\) be a vector, and let \(V\subset {\mathbb {R}}^d\setminus \{0\}\) be a set of vectors, such that for every \(v\in V\) the angle between w and \(v^{\bot }\) is at most \(\beta ^d\). (This is equivalent to \(|\langle w/\Vert w\Vert ,v/\Vert v\Vert \rangle |\le \beta ^d\), hence also to that the angle between v and \(w^{\bot }\) is at most \(\beta ^{d}\).) If \(j\ge 1\) is the the smallest integer for which V is \((j,\beta ^j)\)-Flat, and V is \((j,\beta ^j)\)-Flat with respect to \(\Gamma \), then the angle between w and \(\Gamma ^{\bot }\) is at most \(\gamma '\). Applying this for every vector of the form \(w=q-p\), where \(q\in R{\setminus }\{p\}\), implies the statement, since \(\Gamma '\) is of dimension \(d-j\).

Arguing indirectly, assume that for every \(\beta _0\) there is a \(\beta <\beta _0\) such that the angle between w and \(\Gamma ^{\bot }\) is larger than \(\gamma '\). We will show that then V is \((j-1,\beta ^{j-1})\)-Flat with respect to \(\Gamma \cap w^{\bot }\). If \(\beta \) is sufficiently small, then \(w\notin \Gamma ^{\bot }\), thus the dimension of \(\Gamma \cap w^{\bot }\) is \(j-1\), contradicting the minimality assumption on j.

We may assume that \(\Vert w\Vert =1\) and \(\Vert v\Vert =1\) for every \(v\in V\). Let \(\{w_1,\dots ,w_{d}\}\) be an orthonormal basis of \({{\mathbb {R}}}^d\), where additionally \(\{w_1,\ldots ,w_{j-1}\}\) is an (orthonormal) basis of \(\Gamma \cap w^{\bot }\), further \(\{w_1,\dots , w_j\}\) is a basis of \(\Gamma \), and \(\{w_{j+1},\dots ,w_d\}\) is a basis of \(\Gamma ^{\bot }\). Then w can be written as \(w=\eta _jw_j+\dots +\eta _dw_d\), where

$$\begin{aligned} |\eta _j|> \sin \gamma ', \end{aligned}$$
(9)

since w has angle larger than \(\gamma '\) with \(\Gamma ^{\bot }\). Next, any \(v\in V\) can be written as \(\theta _1 w_1+\dots +\theta _d w_d\), where

$$\begin{aligned} \theta _1^2+\dots +\theta _j^2\ge \cos ^2\beta ^j, \end{aligned}$$

since v has an angle at most \(\beta ^j\) with \(\Gamma \). Further, we have

$$\begin{aligned} |\langle v, w\rangle |=|\theta _j \eta _j+\theta _{j+1}\eta _{j+1}+\cdots +\theta _d \eta _d|\le \beta ^d,\end{aligned}$$

since the angle of w and v is in \([{\pi }/{2}-\beta ^d,{\pi }/{2}+\beta ^d]\). By the Cauchy–Schwarz inequality we have

$$\begin{aligned} |\theta _{j+1}\eta _{j+1}+\dots +\theta _d \eta _d|\le \sqrt{\theta _{j+1}^2+\dots +\theta _d^2}\cdot \Vert w\Vert \le \sqrt{1-\cos ^2\beta ^j}=\sin \beta ^j\le \beta ^j. \end{aligned}$$

By the triangle inequality and the previous two inequalities, we get

$$\begin{aligned} |\theta _j \eta _j|\le |\theta _j \eta _j+\dots +\theta _d \eta _d|+|\theta _{j+1}\eta _{j+1}+\cdots +\theta _d \eta _d|\le 2\beta ^j. \end{aligned}$$

If \(\beta <({\sin ^2\gamma '})/{4}\), then the inequality above together with (9) implies that \(|\theta _j|=|\theta _j\eta _j|/|\eta _j|\le 2\beta ^j/\sin \gamma '<\beta ^{j-0.5}\). Thus, if \(\beta \) is sufficiently small, then

$$\begin{aligned} \theta _1^2+\dots +\theta _{j-1}^2\ge \cos ^2\beta ^j-\beta ^{2j-1}\ge \cos ^2\beta ^{j-1},\end{aligned}$$

where the last inequality follows from the fact that \(\cos \theta = 1-({1}/{2}+o(1))\theta ^2\) for small \(\theta \). This means that the angle between v and \(\Gamma \cap w^{\bot }\) is at most \(\beta ^{j-1}\). Since this is valid for any \(v\in V\), we conclude that V is \((j-1,\beta ^{j-1})\)-flat with respect to \(\Gamma \cap w^{\bot }\), a contradiction. \(\square \)

Lemma 2.5

For any \(d'\) and \(\gamma >0\) there exist \(\beta '>0\) such that the following is true for any \(0<\beta \le \beta '\), sufficiently small \(0<\alpha \le \alpha (\beta )\), and sufficiently large \(K\ge K(\alpha ,\beta )\). Let \(B\cup R\subseteq {\mathbb {R}}^{d'}\) be a separated set with \(B\cap R=\{b\}\), and with the following two properties.

  1. (a)

    For any \(r,r'\in R\) with \(r\ne r'\) and for any \(b'\in B{\setminus } \{b\}\) we have \(K\Vert r-r'\Vert \le \Vert b-b'\Vert \).

  2. (b)

    For any \(b'\in B\setminus \{b\}\) there is a number \(t>0\) such that for any \(r\in R\) we have \(\Vert b'-r\Vert \in [t,t+\beta ^{d'+1}]\).

Further, let \(j\ge 1\) be the lowest dimension such that B is \((b,j,\beta ^j)\)-flat. Assume that for some \(r\in R\) and \(d\le d'\) the set \(B\cup R\) is \((r,d,\alpha )\)-flat. Then R is \((r,d-j,\gamma )\)-flat.

Proof

For \(|R|\le 1\) the statement holds by definition. So we will suppose that \(|R|\ge 2\). Let \(\beta _0\) as in Lemma 2.4 with \(\gamma '=\gamma /2\), and let \(\beta '\le \beta _0\) be sufficiently small, to be further specified later. Let \(r\in R\) be any point of R. Assume that \(B\cup R\) is \((r,d,\alpha )\)-flat with respect to a d-dimensional subspace \(\Gamma _r\). Let \(\pi _r(V)\) be the projection of \(V:=\{b'-r:b'\in B\setminus \{b\}\}\) on \(\Gamma _r\). Assume that \(j_r>1\) is the lowest dimension such that \(\pi _r(V)\) is \((j_r,\beta ^{j_r}/2)\)-Flat. Further, let \(\Gamma _r'\) be a subspace of \(\Gamma _r\) of dimension \(j_r\) such that \(\pi _r(V)\) is \((j_r,{\beta ^{j_r}}/{2})\)-Flat with respect to \(\Gamma _r'\).

By condition (a), for any \(b'\in B\setminus \{b\}\) the angle between \(b'-b\) and \(b'-r\) is at most \(\alpha \) if K is sufficiently large. The angle between \(b'-r\) and \(\pi _r(b'-r)\) is at most \(\alpha \). Further, the angle between \(\pi _r(b'-r)\) and \(\Gamma '_r\) is at most \(\beta ^{j_r}/2\). These, together with the triangle inequality imply that B is \((b,j_r,\beta ^{j_r})\)-flat with respect to \(\Gamma '_r\) if \(2\alpha +\beta ^{j_r}/2\le \beta ^{j_r}\). By the minimality of j, it follows then that \(j_r\ge j\).

Let \(\Lambda _r\) be the affine plane in \({\mathbb {R}}^{d'}\) of dimension \(j_r\) through r parallel to \(\Gamma _r\). For a point \(p\in {\mathbb {R}}^{d'}\) we denote by \(\pi '_r(p)\) the projection of p on \(\Lambda _r\). Similarly, for a set \(X\subseteq {\mathbb {R}}^{d'}\), let \(\pi '_r(X)\) denote the projection of X on \(\Lambda _r\). Note that \(\pi '_r(r)=r\). Let \((\pi _r'(b')-r)^{\bot _r}\) denote the \((d-1)\)-dimensional subspace in \(\Gamma _r\) that is orthogonal to \(\pi _r'(b')-r\). Note that the vector \(\pi _r'(b')-r\) lies in \(\Gamma _r\).

Claim 2.6

For every \(b'\in B\setminus \{b\}\) and \(r\in R\), the projection \(\pi '_r(R)\) is \((r,d-1, \beta ^{d})\)-flat with respect to \((\pi _r'(b')-r)^{\bot _r}\) if \(\alpha \) and \(\beta \) are sufficiently small and K is sufficiently large.

Proof

Let \(r'\in R\setminus \{r\}\) be any point of R. Condition (b) gives \(| \Vert b'-r\Vert -\Vert b'-r'\Vert |\le 2\beta ^{d'+1}\). Since \(1\le \Vert r-r'\Vert \le ({t+\beta ^{d'+1}})/K\), we obtain that \(\angle b'rr'\in [\pi /2-\beta ^{d'}/2,\pi /2+\beta ^{d'}/2]\), if \(\beta \) is sufficiently small and K is sufficiently large. Further, we have \(\angle r'r\pi '_r(r')\le \alpha \) and \(\angle \pi _r'(b')rb'\le \alpha \). Thus, \(\angle \pi _r'(b') r\pi '_r(r')\in [{\pi /2-\beta ^d},{\pi /2+\beta ^d}]\) if \(\alpha \) is sufficiently small. Since \(\pi '_r(R)\) is contained in \(\Lambda _r\), we obtain that for any \(b'\in B\) the set \(\pi '_r(R)\) is \((r,d-1,\beta ^{d})\)-flat with respect to \((\pi _r'(b')-r)^{\bot _r}\). \(\square \)

Now we apply Lemma 2.4 with \(\pi _r(V)\) and \(\gamma '=\gamma /2\), and obtain that \(\pi '_r(R)\) is \((r,d-j_r,\gamma /2)\)-flat. The inequality \(j_r\ge j\) implies that \(\pi '_r(R)\) is \((r,d-j,\gamma /2)\)-flat. Since for any \(r'\in R\) the angle between \(r'-r\) and \(\pi _r'(r')-r\) is at most \(\alpha \), it follows that R is \((r,d-j,\gamma )\)-flat if \(\alpha \) is sufficiently small. \(\square \)

The proof of the following lemma is a simple calculation.

Lemma 2.7

Let \(S\subseteq {\mathbb {R}}^d\) be a set such that \({\Vert p_1-p_2\Vert }/{\Vert q_1-q_2\Vert }\le K\) holds for any \(p_1,p_2,q_1,q_2\in S\) with \(q_1\ne q_2\). If S is \((p,j,\alpha )\)-flat for some \(p\in S\), then S is \((q,j,20(K\alpha )^{1/2})\)-flat for any \(q\in S\).

Proof

Let S be \((p,j,\alpha )\)-flat with respect to \(\Gamma \). We will show that for any \(q,r\in S\) with \(q\ne r\) there is a vector \(v\in \Gamma \) such that the angle between \(q-r\) and v is at most \(20(K\alpha )^{1/2}\). Let \(v_q,v_r\in \Gamma \) be vectors such that the angle between \(q-p\) and \(v_q\), and the angle between \(r-p\) and \(v_r\) is at most \(\alpha \). Further, assume that \(\Vert q-p\Vert =\Vert v_q\Vert \) and \(\Vert r-p\Vert =\Vert v_r\Vert \). The following claim, whose proof is deferred to the appendix, finishes the proof.

Claim 2.8

The angle between \((v_q-v_r)\in \Gamma \) and \(q-r\) is at most \(20(K\alpha )^{1/2}\). \(\square \)

We need the following seemingly technical variant of \(\alpha \)-flatness, which is however crucial for proving Theorem 1.18. For \(d\ge 1\) we say that P is almost \((d,\alpha )\) -flat if P is \((p,d,\alpha )\)-flat for all but at most two \(p\in P\). Note that this means if P is almost \((0,\alpha )\)-flat and \(\alpha \le \pi /2\), then \(|P|\le 2\). We also use the convention that for any \(\alpha >0\) a set P is \((0,\alpha )\)-flat if \(|P|\le 2\). Let \(A_k(d',d)\) denote the largest number A such that for any \(\varepsilon ,\alpha >0\) there exists an almost \((d,\alpha \))-flat \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^{d'}\) of cardinality A. Note that \(A_k(d',0) = 2\). For \(d\ge 1\) let \(A_k(d)= A_k(d,d-1)\).

Let us summarise the trivial inequalities between the different parameters we introduced:

$$\begin{aligned} m_k(d)\le M_k'(d)\le M_k(d)\le N_k(d',d)\le A_k(d',d)\le M_k(d'),\end{aligned}$$
(10)

for any \(d'\ge d\ge 0\).

2.2 Proof of Theorem 1.15 (i)

We will prove that for any \(k\ge 1\) if d is sufficiently large compared to k, then for any \(d'\ge d\) we have \(A_k(d',d) = m_k(d)\). This is sufficient in view of (10). We induct on k. The case \(k=1\) is implied by Lemma 2.2 (i). Assume that the statement of Theorem 1.15 is true for every \(k'\le k-1\) with \(d>D_{k'}\). We will prove the statement for k and \(d>D_k\), where the quantity \(D_k\) is chosen later.

For \(K>0\) and for an \(\varepsilon \)-nearly k-distance set S with distances \(1\le t_1<\ldots <t_k\) let \(\phi _S(K)=1\) if \(\max _{1<i\le k}{t_i}/(t_{i-1}+\varepsilon )<K\), and otherwise let \(\phi _S(K)\) be the largest index \(1< i\le k\) such that \({t_{i}}/({t_{i-1}+\varepsilon })\ge K\).

Lemma 2.9

If \(\varepsilon _k\) and \(\alpha _k\) are sufficiently small and \(d>D_k\) for some sufficiently large \(D_k\), then the following is true for every \(1\le i \le k\). There exist \(K_i\ge K_{i+1}\ge \ldots \ge K_k\) such that if S is an almost \((d,\alpha _k)\)-flat \(\varepsilon _k\)-nearly k-distance set in \({\mathbb {R}}^{d'}\), and for some \(j\ge i\) we have \(\phi _S(K_j)\ge j\), then \(|S|\le m_k(d)\).

Note that since \(\phi _S(K)\ge 1\) holds for any K, Lemma 2.9 with \(i=1\) implies the theorem. We phrased Lemma 2.9 in this seemingly strange form, because this way it is convenient to prove it by backwards induction on i.

Proof

The proof is by backwards induction on i. We start by showing that the statement is true for \(i=k\) with some sufficiently large \(K_k\ge 4\).

Assume that \(\phi _S(K_k)=k\) and for every \(p_1,p_2\in S\) with \(p_1\ne p_2\) colour the pair \(\{p_1,p_2\}\) with blue if \(\Vert p_1-p_2\Vert \in [t_k,t_k+\varepsilon _k]\) and with red otherwise. Let B be a largest blue clique in S. Then S can be partitioned into |B| red cliques \(R_1,\dots ,R_{|B|}\) as in Lemma 2.1. Let R be a largest red clique and let \(R\cap B=\{b\}\). We will apply Lemma 2.5 to \(R\cup B\) with a sufficiently small \(\gamma \) (to be chosen later) to bound |R|.

Let \(\beta '\) be as in Lemma 2.5, and \(0<\beta \le \beta '\) be sufficiently small, to be set later. We may assume that \(\alpha _k\le \alpha (\beta )\) and choose \(K_k\) such that \(K_k\ge 2K(\alpha _k,\beta )\). We may apply Lemma 2.5, as conditions (a) and (b) are automatically satisfied if \(\varepsilon _k\le \beta ^{d'+1}\). Let j be as in the Lemma with \(\alpha =\alpha _k\). Since S is almost \((d,\alpha _k)\)-flat, we have that \(R\cup B\) is \((r,d,\alpha _k)\)-flat for all but at most two \(r\in R\). If \(r\in R\) is such that \(R\cup B\) is \((r,d,\alpha _k)\)-flat, then by Lemma 2.5 we obtain that R is \((r,d-j,\gamma )\)-flat.

Thus, if \(\gamma \le \alpha _{k-1}\) then we have \(|R|\le A_{k-1}(d',d-j)\). Note also that B is \((j,20\beta ^{j/2})\)-flat by Lemma 2.7, thus \(|B|\le m_1(j)=j+1\) by Lemma 2.2 (i) if \(\beta \) and \(\varepsilon _k\) are sufficiently small. These imply that

$$\begin{aligned} |S|\le |B|\cdot |R|\le (j+1)A_{k-1}(d',d-j). \end{aligned}$$

We separate two cases in order to bound \((j+1) A_{k-1}(d',d-j)\).

Case 1: \(d-j\ge D_{k-1}\).   In this case we obtain

$$\begin{aligned} (j+1) A_{k-1}(d',d-j)\le (j+1)\left( {\begin{array}{c}d-j+k-1\\ k-1\end{array}}\right) \le \left( {\begin{array}{c}d+1\\ k\end{array}}\right) \le m_k(d), \end{aligned}$$

where the first inequality is true by induction and by (1), the second is true if d is sufficiently large, and the third is true by (2).

Case 2: \(d-j< D_{k-1}\).   In this case we have \(A_{k-1}(d',d-j)\le 2+N_{k-1}(d',d-j)\). By Lemma 2.3 we have \(N_{k-1}(d',d-j)\le C_k\) where \(C_k\) depends only on k and \(D_{k-1}\), hence depends only on k. Thus we obtain

$$\begin{aligned} (j+1)A_{k-1}(d',d-j)\le (j+1)(C_k+2)\le \left( {\begin{array}{c}d+1\\ k\end{array}}\right) \le m_k(d),\end{aligned}$$

where the second inequality is true d is sufficiently large, and the third inequality is true by (2).

We now turn to the induction step. Assume that the statement holds for every \(i+1\) with \(K_{i+1}\ge K_{i+2}\ge \ldots \ge K_k\), and let us prove that if \(K_i\) is sufficiently large, then it holds for i with \(K_i\ge K_{i+1}\ge \ldots \ge K_k\). Again, for every \(p_1,p_2\in S\) with \(p_1\ne p_2\) colour the pair \(\{p_1,p_2\}\) with blue if \(\Vert p_1-p_2\Vert \ge t_i\) and with red otherwise. Let B be a largest blue clique in S. Then S can be partitioned into |B| red cliques \(R_1,\dots ,R_{|B|}\) as in Lemma 2.1.

We may assume that \(\phi (K_{i+1}) \le i\), otherwise we are done by induction. This implies that \(\max _{i<j\le k}t_j/({t_{j-1}+\varepsilon _k})\le K_{i+1}\). Thus, by Lemma 2.2 (ii) we may assume that there exists a sufficiently small constant \(\delta >0\) such that the following is true for sufficiently small \(\alpha _k\) and \(\varepsilon _k\):

$$\begin{aligned} \text {if }\ \ \min _{i<j\le k}\frac{t_{j}}{t_{j-1}+\varepsilon _k}<1+\delta ,\quad \text { then }\quad |B|\le m_{k-i}(d). \end{aligned}$$
(11)

Set \(K_i'=\max {\{{2}/{\delta },K_{i+1}\}}\). We are ready to verify the statement of the lemma for sufficiently large \(K_i>2K_i'\). We separate two cases.

Case 1: \(\min _{i<j\le k}({t_{j}}/({t_{j-1}+\varepsilon _k}))< 1+\delta \).   If R is a largest red clique then we obtain

$$\begin{aligned} |S|\le |B|\cdot |R|\le m_{k-i}(d)A_{i-1}(d',d)\le & {} \left( {\begin{array}{c}k-i+d\\ k-i\end{array}}\right) \left( {\begin{array}{c}i-1+d\\ i-1\end{array}}\right) < \left( {\begin{array}{c}d+1\\ k\end{array}}\right) \\ {}\le & {} m_k(d), \end{aligned}$$

where the second inequality follows from (11) and the fact that R is an almost \((d,\alpha _k)\)-flat \(\varepsilon _k\)-nearly \((i-1)\)-distance set and that \(\alpha _k,\varepsilon _k\) are sufficiently small, the third inequality follows by induction and by (1), the fourth is true if d is sufficiently large, and the last is true by (2).

Case 2: \(\min _{i<j\le k}({t_{j}}/({t_{j-1}+\varepsilon _k}))\ge 1+\delta \).   Let R be a largest red clique and let \(R\cap B=\{b\}\). We will apply Lemma 2.5 to \(R\cup B\) with a sufficiently smal \(\gamma \) (to be chosen later) to bound |R|. Let \(\beta '\) be as in Lemma 2.5 and \(0<\beta \le \beta _0\) sufficiently small to be specified later. We may assume that \(\alpha _k\le \alpha (\beta )\) and choose \(K_i\) such that \(K_i\ge 2K(\alpha _k,\beta )\). Then condition (a) is satisfied automatically. We may further assume that \(\varepsilon _k\le \beta ^{d'+1}\). Then condition (b) is satisfied as well with \(\beta \) if “all distances from a point in B to R fall in one interval”. That is, to apply the lemma, we need to as show that it is not possible to find indices \(j_1>j_2\ge i\) and points \(b, b'\in B\) with \(b\ne b'\) and \(r_1,r_2\in R\), such that \(\Vert b'-r_1\Vert \in [t_{j_1},t_{j_1}+\varepsilon _k]\) and \(\Vert b'-r_2\Vert \in [t_{j_2},t_{j_2}+\varepsilon _k]\). If that would have been the case, then, by the triangle inequality \(t_{j_1}\le \Vert b'-r_1\Vert \le \Vert b'-r_2\Vert +\Vert r_1-r_2\Vert \le t_{j_2}+t_{i-1}+2\varepsilon _k\), but, on the other hand, \(t_{j_1}-t_{j_2}\ge \delta t_i\ge \delta K_it_{i-1}\ge \delta t_{i-1} \cdot 2/{\delta }\ge 2t_{i-1}>t_{i-1}+2\varepsilon _k\), a contradiction. Thus, condition (b) is indeed satisfied as well.

Using Lemma 2.5, we will show that R is almost \((d-j,\gamma )\)-flat. Since S is almost \((d,\alpha _k)\)-flat, we have that \(R\cup B\) is \((r,d,\alpha _k)\)-flat for all but at most two points \(r\in R\). If \(r\in R\) is such that \(R\cup B\) is \((r,d,\alpha _k)\)-flat, then by Lemma 2.5 we obtain that R is \((r,d-j,\gamma )\)-flat. Since this is true for all but at most two points \(r\in R\), we obtain that R is indeed almost \((d-j,\gamma )\)-flat. Thus, if \(\gamma \) is sufficiently small, we have \(|R|\le A_{i-1}(d',d-j)\). Note also that

$$\begin{aligned} \max _{i< j\le k}\frac{t_{i}}{t_{i-1}+\varepsilon _k}\le K_{i+1},\end{aligned}$$

thus B is \((j,20(K_{i+1}\beta )^{j/2})\)-flat by Lemma 2.7. We obtain that \(|B|\le m_{k-i+1}(j)\) by Lemma 2.2 (i) if \(\varepsilon _k\) and \(\beta \) are sufficiently small. Overall, for |S| we obtain that

$$\begin{aligned} |S|\le |R|\cdot |B|\le m_{k-i+1}(j) A_{i-1}(d',d-j),\end{aligned}$$

if \(\beta \), \(\alpha _k\), and \(\varepsilon _k\) is sufficiently small, and K is sufficiently large. We separate two cases in order to bound \(m_{k-i+1}(j) A_{i-1}(d',d-j)\).

Case 2.1: \(d-j\ge D_{i-1}\).   In this case we obtain

$$\begin{aligned} m_{k-i+1}(j) A_{i-1}(d',d-j)\le & {} \left( {\begin{array}{c}j+k-i+1\\ k-i+1\end{array}}\right) \left( {\begin{array}{c}d-j+i-1\\ i-1\end{array}}\right) \le \left( {\begin{array}{c}d+1\\ k\end{array}}\right) \\ {}\le & {} m_k(d), \end{aligned}$$

where the first inequality is true by induction and by (1), the second is true if d is sufficiently large, and the third is true by (2).

Case 2.2: \(d-j<D_{i-1}\).   In this case we have \(A_{i-1}(d',d-j)\le 2+N_{i-1}(d',d-j)\). By Lemma 2.3 we have \(N_{i-1}(d',d-j)\le C_i\) where \(C_i\) depends only on i and \(D_{i-1}\), hence depends only on i. Thus, we obtain

$$\begin{aligned} m_{k-i+1}(j) A_{i-1}(d',d-j)\le \left( {\begin{array}{c}j+k-i+1\\ k-i+1\end{array}}\right) (2+C_i)\le \left( {\begin{array}{c}d+1\\ k\end{array}}\right) \le m_k(d),\end{aligned}$$

where the first inequality follows from (1), the second is true if d is sufficiently large, and the third follows from (2). \(\square \)

2.3 Proof of Theorem 1.15 (ii)

For \(d=0\) the statement is obvious since \(N_k(1)=M_k(0)=m_k(0)=1\) holds for any \(k\ge 1\). For \(d\ge 1\) in Claim 2.10 and in Claim 2.11 we will prove that for any \(d'\ge d\) and \(k=2,3\) we have \(A_k(d',d) = m_k(d)\). This is sufficient in view of (10).

Claim 2.10

We have \(A_2(d',d)=m_2(d)\).

Proof

Let \(\varepsilon ,\alpha >0\) be sufficiently small and S be an almost \((d,\alpha )\)-flat \(\varepsilon \)-nearly 2-distance set in \({\mathbb {R}}^{d'}\) with distances \(1\le t_1<t_2\). Then for all but at most two points \(p\in S\) we have that S is \((p,d,\alpha )\)-flat with respect to a d-dimensional subspace \(\Gamma _p\). Let \(K>3\) be a sufficiently large constant to be specified later. We may assume that \({t_2}/({t_1+\varepsilon })>K\), otherwise we have \(|S|\le m_2(d)\) by Lemma 2.2 (i). For every \(p_1,p_2\in S\) with \(p_1\ne p_2\) colour the pair \(\{p_1,p_2\}\) with blue if \(\Vert p_1-p_2\Vert \ge t_2\) and with red otherwise. Let B be a largest blue clique in S. Then S can be partitioned into |B| red cliques \(R_1,\dots ,R_{|B|}\) as in Lemma 2.1.

Let \(\Gamma \) be the subspace spanned by \(B-B=\{b_1-b_2:b_1,b_2\in B\}\) and let j be the dimension of \(\Gamma \). Note that, since B is an \(\varepsilon \)-nearly 1-distance set, B approximately a regular simplex. Hence, if \(\varepsilon \) is sufficiently small, there is an absolute \(\mu >0\) such that there is no \(b\in B\) for which the set B is \((b,j-1,\mu )\)-flat.

Let R be any of the red cliques and let \(B\cap R=\{b\}\). We will apply Lemma 2.5 to \(R\cup B\) with a sufficiently small \(\gamma \) (to be specified later).

Let \(\beta '\) be as in Lemma 2.5 and let \(0<\beta \le \beta '\) be sufficiently small. We may assume that \(\alpha \le \alpha (\beta )\) and that \(K\ge K(\alpha _k,\beta )\). We may now apply Lemma 2.5, as conditions (a) and (b) are automatically satisfied if \(\varepsilon \le \beta ^{d'+1}\). If \(j\ge 2\) and we have \(\beta <\mu ^{1/(j-1)}\), then \(\beta ^{j-1}<\mu \). Further, note that since we may assume that there is at least one blue edge, we have that \(|B|\ge 2\). Thus, there is no \(\gamma \) for which B is \((0,\gamma )\)-flat. In other words, there is no \(\gamma \), for which B is \((j-1,\gamma )\)-flat if \(j-1\). Thus, if \(\beta \) is sufficiently small, then j is as in Lemma 2.5.

Since S is \((p,d,\alpha )\)-flat for all but at most two \(p\in S\), for all but at most two (say \(R_1\) and \(R_2\)) red cliques R we have that \(B\cup R\) is \((r,d,\alpha )\)-flat for some \(r\in R\). Thus by Lemma 2.5 we obtain that if R is not \(R_1\) or \(R_2\), then R is \((r,d-j,\gamma )\)-flat for some \(r\in R\). Now, since R is an \(\varepsilon \)-nearly 1-distance set, Lemma 2.2 (i) implies that if R is not \(R_1\) or \(R_2\), then we have \(|R|\le m_1(d-j)=d-j+1\) if \(\varepsilon \) and \(\gamma \) are sufficiently small. We also have \(|R_1|+|R_2|\le 2\), since there are only at most two \(p\in S\) such that S is not \((p,d,\alpha )\)-flat.

Noting further that \(|B|=j+1\), we obtain

$$\begin{aligned} |S|=|R_1|+\dots +|R_{|B|}|\le \max {\{(j+1)(d-j+1), j(d-j+1)+2\}}.\end{aligned}$$

Then either \(d=j\) or \((j+1)(d-j+1)\ge j(d-j+1)+2\) holds. In the first case, we have

$$\begin{aligned}|S|\le d+2\le \left( {\begin{array}{c}d+1\\ 2\end{array}}\right) \le m_2(d)\end{aligned}$$

if \(d\ge 3\), and

$$\begin{aligned}|S|\le d+2\le m_2(d)\end{aligned}$$

if \(d=1,2\), since \(m_2(1)=3\) and \(m_2(2)=5\). In the second case, we have

$$\begin{aligned}|S|\le (j+1)(d-j+1) \le \biggl (\frac{d+2}{2}\biggr )^{\!2}\le \left( {\begin{array}{c}d+1\\ 2\end{array}}\right) \le m_2(d)\end{aligned}$$

if \(d\ge 4\), and

$$\begin{aligned} |S|\le (j+1)(d-j+1)\le m_2(d)\end{aligned}$$

if \(d=2,3\) since \(m_2(2)=5\) and \(m_2(3)=6\) (see Table 1). \(\square \)

Claim 2.11

We have \(A_3(d',d)=m_3(d)\).

Proof

Let \(\varepsilon ,\alpha >0\) be sufficiently small and S be an almost \((d,\alpha )\)-flat \(\varepsilon \)-nearly 3-distance set in \({\mathbb {R}}^{d'}\) with distances \(0<t_1<t_2<t_3\). Later we will apply Lemma 2.5 with a sufficiently small \(\gamma \). Let \(\beta '\) be as in Lemma 2.5, and let \(0<\beta \le \beta '\) be sufficiently small to be specified later. We may assume that \(\alpha \le \alpha (\beta )\) and that \(K\ge \max {\{3,K(\alpha ,\beta )\}}\) is sufficiently large. We may assume \(t_2/(t_1+\varepsilon )\ge K\) or \(t_3/(t_2+\varepsilon )\) \(\ge K\) holds, otherwise we immediately obtain \(|S|\le m_3(d)\) by Lemma 2.2 (i) if \(\varepsilon \) and \(\alpha \) are sufficiently small. We will analyse these two cases separately.

Case 1: \({t_3}/({t_2+\varepsilon })\ge K\).   For every \(p_1,p_2\in S\) with \(p_1\ne p_2\) colour the pair \(\{p_1,p_2\}\) with blue if \(\Vert p_1-p_2\Vert \ge t_3\) and with red otherwise. Let B be a largest blue clique in S. Then S can be partitioned into |B| red cliques \(R_1,\dots ,R_{|B|}\) as in Lemma 2.1.

Let \(\Gamma \) be the subspace spanned by \(B-B=\{b_1-b_2:b_1,b_2\in B\}\), and let j be the dimension of \(\Gamma \). Note that, since B is an \(\varepsilon \)-nearly 1-distance set, B is approximately a regular simplex. Hence, there is an absolute \(\mu >0\) such that if \(\varepsilon \) is sufficiently small, then for no \(b\in B\), the set B is \((b,j-1,\mu )\)-flat.

Let R be any of the red cliques and let \(B\cap R=\{b\}\). We will apply Lemma 2.5 to \(R\cup B\) with \(\gamma \). Conditions (a) and (b) of Lemma 2.5 are automatically satisfied if \(\varepsilon \le \beta ^{d'+1}\). Moreover, if \(j\ge 2\) and we have \(\beta <\mu \), then \(\beta ^{j-1}<\mu \), thus j is as in Lemma 2.5. (The \(j=1\) case can be handled in the same way as in Claim 2.10.)

Since S is \((p,d,\alpha )\)-flat for all but at most two \(p\in S\), for every red clique R, for all but at most two points \(r\in R\), we have that \(B\cup R\) is \((r,d,\alpha )\)-flat. Thus, by Lemma 2.5 we obtain that every R is \((r,d-j,\gamma )\)-flat for all but at most two \(r\in R\). Moreover, since R is an \(\varepsilon \)-nearly 2-distance set, we obtain that \(|R|\le A_2(d',d-j)\) if \(\gamma \) is sufficiently small. Noting further that \(|B|=j+1\), overall we obtain

$$\begin{aligned} |S|=|R_1|+\dots +|R_{|B|}|\le (j+1) A_2(d',d-j).\end{aligned}$$

For sufficiently small \(\gamma \) and any red clique R, we have \(|R|\le 2\) if \(d=j\). In this case it follows that \(|S|\le 2(d+1)\). Then for \(d\ge 4\) we have

$$\begin{aligned} |S|\le 2(d+1)\le \left( {\begin{array}{c}d+1\\ 3\end{array}}\right) \le m_3(d),\end{aligned}$$

where the second inequality is true by a simple calculation, and the third is by (1). For \(d=1,2,3\) we have

$$\begin{aligned} |S|\le 2(d+1)\le m_3(d)\end{aligned}$$

given that \(m_3(1)=4\), \(m_3(2)=7\), and \(m_3(3)=12\) (see Table 1).

If \(j<d\), then \(|R|\le A_2(d',d-j')\le m_2(d-j)\), where the second inequality is by the \(k=2\) case of the theorem (Claim 2.10) for sufficiently small \(\gamma \). In this case, for \(d\ge 9\) we have

$$\begin{aligned} |S|\le (j+1) m_2(d-j)\le (j+1)\left( {\begin{array}{c}d-j+2\\ 2\end{array}}\right) \le \left( {\begin{array}{c}d+1\\ 3\end{array}}\right) \le m_3(d),\end{aligned}$$

where the second inequality is true by (1), the third by a simple calculation, and the fourth by (2). For \(d\le 8\), using the known values and bounds of \(m_2(d)\) and \(m_3(d)\), we check in the appendix that

$$\begin{aligned} (j+1)m_2(d-j)\le m_3(d). \end{aligned}$$
(12)

Case 2: \({t_2}/({t_1+\varepsilon })\ge K>{t_3}/({t_2+\varepsilon })\).   For every \(p_1,p_2\in S\) with \(p_1\ne p_2\) colour the pair \(\{p_1,p_2\}\) with blue if \(\Vert p_1-p_2\Vert \ge t_2\) and with red otherwise. Let B be a largest blue clique in S. Using Lemma 2.1, partition the set S into |B| red cliques \(R_1,\dots ,R_{|B|}\). We split the analysis into two more subcases.

Case 2.1: \(t_3/({t_2+\varepsilon })> 1+{2}/{K}\).   Let R be one of the red cliques and let \(R\cap B=\{b\}\). We will apply Lemma 2.5 to \(R\cup B\) with \(\gamma \), similarly as before. Condition (a) is automatically satisfied. To check condition (b), note that for any \(p_1,p_2\in R\) and \(b'\in B\) with \(b\ne b'\), if \(|p_1-b'|\in [t_i,t_i+\varepsilon ]\) and \(|p_2-b'|\in [t_{\ell }, t_{\ell }+\varepsilon ]\), then by the triangle inequality we obtain that \(\ell =i\) if \(\varepsilon \) is sufficiently small. Thus, condition (b) is satisfied as well if \(\varepsilon \le \beta ^{d'+1}\) and \(\varepsilon \) is sufficiently small.

Let j be as in Lemma 2.5. If for some \(p\in R\) we have that S is \((p,d,\alpha )\)-flat, then R is \((p,d-j,\gamma )\)-flat by Lemma 2.5. Further, note that the same is true for any red clique R with the same j. Indeed, since \(t_3/({t_2+\varepsilon })<K\), Lemma 2.7 implies that if \(\beta \) is sufficiently small, then there is a j such that B is \((b',j,\beta ^j)\)-flat for every \(b'\in B\), but there is no \(b'\in B\) for which it is \((b',j-1,\beta ^{j-1})\)-flat. This and Lemma 2.2 (i) imply that for all but at most two red cliques R we have \(|R|\le m_1(d-j)=d-j+1\) if \(\gamma \) and \(\varepsilon \) are sufficiently small. Moreover, if the two potential exceptions are say \(R_1,R_2\), then \(|R_1|+|R_2|\le 2\). Note also that by Lemma 2.2 (i) we have \(|B|\le m_2(j)\) if \(\beta \) and \(\varepsilon \) are sufficiently small. Overall, we obtain

$$\begin{aligned} |S|\le |R_1|+\dots +|R_{|B|}|\le \max { \{m_2(j)(d-j+1), (m_2(j)-1)(d-j+1)+2\}}.\end{aligned}$$

Then we either have \(d=j\) or \(j\le d-1\), and thus \((m_2(j)-1)(d-j+1) +2\le m_2(j)(d-j+1)\). In the first case (\(d=j\)) for \(d\ge 6\) we have

$$\begin{aligned} |S|\le m_2(d)+1\le \left( {\begin{array}{c}d+2\\ 2\end{array}}\right) +1\le \left( {\begin{array}{c}d+1\\ 3\end{array}}\right) \le m_3(d),\end{aligned}$$

where the second inequality is by (1), the third is by a simple calculation, and the fourth is by (2). For \(1\le d \le 5\) we have

$$\begin{aligned}|S|\le m_2(d)+1\le m_3(d)\end{aligned}$$

since \(m_2(1)=3\), \(m_2(2)=5\), \(m_2(3)=6\), \(m_2(4)=10\), \(m_2(5)=16\), and \(m_3(1)=4\), \(m_3(2)=7\), \(m_3(3)=12\), \(m_3(4)=16\), \(m_3(5)\ge 24\) (see Table 1). Finally, in the second case (\(j\le d-1\)) we do the same analysis as in the end of Case 1.

Case 2.2: \(t_3/({t_2+\varepsilon })\le 1+2/K\).   First, we will show that \(|B|\le d+1\). Indeed, we either have that \(|B|\le 2\), or there is a \(b\in B\) such that B is \((b,d,\alpha )\)-flat. In the latter case, by Lemma 2.7 we obtain that B is \((d,20((1+2/K)\alpha )^{1/2})\)-flat. Then, by Lemma 2.2 (ii), if 2/K, \(\alpha \), and \(\varepsilon \) are sufficiently small, we have that \(|B|\le m_1(d)= d+1\).

Next, we will show that for any red clique R we have \(|R|\le d+1\). Indeed, we either have that \(|R|\le 2\), or there is an \(r\in R\) such that R is \((r,d,\alpha )\)-flat. In the latter case, by Lemma 2.7 we obtain that R is \((d,20\alpha ^{1/2})\)-flat. Then, by Lemma 2.2 (i), if \(\alpha \) and \(\varepsilon \) are sufficiently small, we have that \(|R|\le m_1(d)= d+1\). We obtain that

$$\begin{aligned} |S|=|R_1|+\dots +|R_{|B|}|\le (d+1)^2.\end{aligned}$$

Then if \(d\ge 9\), it follows by a simple calculation and by (2) that

$$\begin{aligned} |S|\ge (d+1)^2\le \left( {\begin{array}{c}d+1\\ 3\end{array}}\right) \le m_3(d).\end{aligned}$$

Further, for \(d=7\) and for \(d=8\) we have \(m_3(8)\ge 121\ge (8+1)^2\), \(m_3(7)\ge 65\ge (7+1)^2\) (see Table 1). Therefore, in the rest of the proof we may assume that \(d\le 6\).

Case 2.2.1: \(t_1\ge K^{0.1}(t_3-t_2)\).   Let R be a largest red clique. To bound the cardinality of R in this case we will not use Lemma 2.5, but we will use Lemma 2.4 directly.

Fig. 2
figure 2

Illustration of proof of Claim 2.12

Let \(R\cap B=\{b\}\), and let \(\gamma \) be sufficiently small (to be specified later). For \(\gamma '={\gamma }/{2}\) let \(\beta _0\) as in Lemma 2.4, and let \(\beta \le \beta _0\) be sufficiently small. Further, let r be any point of R, and let \(V=\{b'-r:b'\in B{\setminus }\{b\}\}\). Assume that \(j\ge 1\) is the smallest integer such that V is \((j,\beta ^j)\)-Flat, and assume that V is \((j,\beta ^j)\)-flat with respect to \(\Gamma \). Let \(q\in R\) be any point of R such that \(q\ne r\).

Claim 2.12

For every \(b'\in B\setminus \{b\}\) the angle between the vectors \(q-r\) and \(b'-r\) falls in \([{\pi /2-\beta ^{d'}/2},{\pi /2+\beta ^{d'}/2}]\), if K is sufficiently large, and \(\varepsilon \) is sufficiently small.

Proof

Let \({\mathcal {S}}_2,{\mathcal {S}}_3\) be spheres centred at \(b'\) and of radii \(t_2\) and \(t_3\) respectively (see Fig. 2). Then r is \(\varepsilon \)-close to one of them. We only spell out the proof in the case when r is \(\varepsilon \)-close to \(S_1\), as the case when it is \(\varepsilon \)-close to \(S_3\) can be done very similarly. Note that q is also \(\varepsilon \)-close to \({\mathcal {S}}_2\) or \({\mathcal {S}}_3\). If q is \(\varepsilon \)-close to \({\mathcal {S}}_2\), then some simple calculation shows that for some absolute constant \(c_1\) the angle between the vectors \(q-r\) and \(b'-r\) falls in \([{\pi /2-c_1/K},{\pi /2+c_1/K}]\). If q is \(\varepsilon \)-close to \({\mathcal {S}}_3\), then we claim that for some absolute constant \(c_2\) the angle between the vectors \(q-r\) and \(b'-r\) falls in \([{\pi /2-c_2/K^{0.1}},{\pi /2+c_2/K^{0.1}}]\). Indeed, this follows from the facts that \(|q-r|\in [t_1,t_1+\varepsilon ]\), \(t_1\ge K^{0.1}(t_3-t_2)\), and that the radius of \({\mathcal {S}}_3\) is much bigger than \(t_1\). Thus, we can conclude that if K is sufficiently large, then the angle between the vectors \(q-r\) and \(b'-r\) falls in \([{\pi /2-\beta ^{d'}/2},{\pi /2+\beta ^{d'}/2}]\). \(\square \)

Next, we will show that if for some \(r\in R\) the set \(R\cup B\) is \((r,d,\alpha )\)-flat, then R is \((r,d-j,\gamma )\)-flat. This part of the proof is very similar to the proof of Lemma 2.4, but for completeness we spell it out with all details.

Assume that \(B\cup R\) is \((r,d,\alpha )\)-flat with respect to a d-dimensional subspace \(\Gamma _r\). Let \(\pi _r(V)\) be the projection of \(V=\{b'-r:b'\in B\setminus \{b\}\}\) on \(\Gamma _r\). Assume that \(j_r'\ge 1\) is the lowest dimension such that \(\pi _r(V)\) is \((j_r,{\beta ^{j_r}}/{2})\)-Flat. Further, let \(\Gamma _r'\) be a subspace of dimension \(j_r\) such that \(\pi _r(V)\) is \((j_r,\beta ^{j_r}/2)\)-Flat with respect to \(\Gamma _r'\).

The angle between \(b'-b\) and \(b'-r\) is at most \(\alpha \) if K is sufficiently large and \(\beta \) is sufficiently small. The angle between \(b'-r\) and \(\pi _r(b'-r)\) is at most \(\alpha \). Further, the angle between \(\pi _r(b'-r)\) and \(\Gamma _r\) is at most \(\beta ^{j_r}/2\). These, together with the triangle inequality imply that B is \((b,j_r,\beta ^{j_r})\)-flat with respect to \(\Gamma '_r\) if \(2\alpha \le {\beta ^{j_r}}/2\). By the minimality of j, it follows than that \(j_r\ge j\).

Let \(\Lambda _r\) be the affine plane through r parallel to \(\Gamma '_r\). For a point \(p\in {\mathbb {R}}^{d'}\) we denote by \(\pi '_r(p)\) the projection of p on \(\Lambda _r\). Similarly, for a set \(X\subseteq {\mathbb {R}}^{d'}\), let \(\pi '_r(X)\) denote the projection of X on \(\Lambda _r\). Note that \(\pi '_r(r)=r\). Let \((b'-r)^{\bot _r}\) denote the \((d-1)\)-dimensional subspace in \(\Gamma '_r\) that is orthogonal to \({b'-r}\).

Claim 2.13

For any \(b'\in B\setminus \{b\}\) and any \(r\in R\), the projection \(\pi '_r(R)\) is \((r,d-1, \beta ^{d})\)-flat with respect to \((b'-r)^{\bot _r}\) if \(\alpha \) and \(\beta \) are sufficiently small and K is sufficiently large.

Proof

Let \(q\in R\setminus \{r\}\) any point of R. It follows from Claim 2.12 that if K is sufficiently large and \(\varepsilon \) is sufficiently small, then the angle between the vectors \(q-r\) and \(b'-r\) falls in \([{\pi /2-\beta ^{d'}/2},{\pi /2+\beta ^{d'}/2}]\). Further, we have \(\angle qr\pi '_r(q)\le \alpha \). Thus, \(\angle b'r\pi '_r(q)\in [{\pi /2-\beta ^d},{\pi /2+\beta ^d}]\) if \(\alpha \) is sufficiently small. Since \(\pi '_r(R)\) is contained in \(\Lambda _r\), we obtain that for every \(b'\in B\) the set \(\pi '_r(R)\) is \((r,d-1,\beta ^{d})\)-flat with respect to \((b'-r)^{\bot _r}\). \(\square \)

Now we apply Lemma 2.4 with \(\pi _r(V)\) and \(\gamma '={\gamma }/2\), and obtain that \(\pi '_r(R)\) is \((r,d-j_r,\gamma /2)\)-flat. This, by \(j_r\ge j\), implies that \(\pi _r(R)\) is \((r,d-j,\gamma /2)\)-flat. Since for any \(q\in R\) the angle between \(q-r\) and \(\pi _r(q)-r\) is at most \(\alpha \), it follows that R is \((r,d-j,\gamma )\)-flat if \(\alpha \) is sufficiently small.

Thus, either there is no \(r\in R\) for which R is \((r,d,\alpha )\)-flat, in which case \(|R|\le 2\), or there is an \(r\in R\) such that R is \((r,d-j,\gamma )\)-flat. In the latter case, by Lemma 2.7 we obtain that R is \((d-j,20\gamma ^{1/2})\)-flat. Thus, by Lemma 2.2 (i) we have \(|R|\le m_1(d-j)\) if \(\gamma \) and \(\varepsilon \) are sufficiently small. Overall, we have that \(|R|\le \max {\{2,m_1(d-j)\}}\).

Finally, we claim that \(|B|\le j+1\). To see this, note if K is sufficiently large, then the angle between the vectors \(b'-r\) and \(b-r\) is at most \(\beta ^{j}\). Then, since V is \((j,\beta ^j)\)-Flat, we obtain that B is \((b,j,2\beta ^j)\)-flat. Lemma 2.7 implies that B is \((j,20((1+2/K)\beta ^j)^{1/2})\)-flat. By Lemma 2.2 (ii) we conclude that \(|B|\le m_1(j)=j+1\) if \(\beta \) and \(\varepsilon \) are sufficiently small. Overall, we obtain that

$$\begin{aligned}|S|\le (j+1)(d-j+1)\le m_3(d),\end{aligned}$$

where the second inequality was already proven in the previous cases.

Case 2.2.2: \(t_1\le K^{0.1}(t_3-t_2)\).   For every \(1\le i\le |B|\) let \(\{b_i\}=B\cap R_i\), and for \(m=2,3\), let \({\mathcal {S}}_{\ell }(i)\) be the sphere of radius \(t_{m}\) centred at \(b_i\). We need the following claim.

Claim 2.14

Assume that for some \(1\le i, \ell \le |B|\) with \(i\ne \ell \) there are points from \(R_i\) in the \(\varepsilon \)-neighbourhoods of both \({\mathcal {S}}_2(\ell )\) and \({\mathcal {S}}_3(\ell )\). Then \(R_{\ell }\) is contained in the \(\varepsilon \)-neighbourhood either of \({\mathcal {S}}_2(i)\) or of \({\mathcal {S}}_3(i)\).

Proof

Assume the contrary. We may assume that \(|b_i-b_{\ell }|\in [t_2,t_2+\varepsilon ]\) (the case with \(t_2\) replaced by \(t_3\) can be treated similarly). Then there are points \(p\in R_i\), \(q\in R_{\ell }\) such that p is in the \(\varepsilon \)-neighbourhood of \({\mathcal {S}}_3(\ell )\), and q is in the \(\varepsilon \)-neighbourhood of \({\mathcal {S}}_3(i)\) (see Fig. 3). Let \(p',q'\) denote the projections of pq on the line e passing through \(b_i\) and \(b_{\ell }\), and let \(r_i\) and \(r_{\ell }\) denote the points of intersection of e and spheres \({\mathcal {S}}_3(\ell )\), \({\mathcal {S}}_3(i)\) respectively. Note that \(\Vert r_i-r_{\ell }\Vert \ge t_3+(t_3-t_2)\).

Fig. 3
figure 3

Illustration of proof of Claim 2.14

We claim that \(\Vert r_i-p'\Vert ,\Vert r_{\ell }-q'\Vert \le (t_3-t_2)/10\). This would imply that \(\Vert q-p\Vert \ge \Vert q'-p'\Vert \ge \Vert r_i-r_{\ell }\Vert -2(t_3-t_2)/10>t_3+\varepsilon \), which is a contradiction. Let us only show that \(\Vert r_{\ell }-q'\Vert \le (t_3-t_2)/10\), since the other inequality can be proven in the same way. Due to our condition on \(t_2\), we have \(\Vert r_{\ell }-q\Vert \le \Vert r_{\ell }-b_{\ell }\Vert +\Vert b_{\ell }-q\Vert \le 2t_i+2\varepsilon \le 3K^{0.1}(t_3-t_2)\). Since we have \(t_3-t_2\le 2t_3/K\), and q lies in the \(\varepsilon \)-neighbourhood of \({\mathcal {S}}_3(i)\), for the angle \(\gamma \) between the vector \(q-r_{\ell }\) and the line e we have \(2\cos \gamma =\Vert {r_{\ell }-q}\Vert /\Vert {q-b_i}\Vert \le {3K^{0.1}(t_3-t_2)}/{t_3}\le 3K^{-0.9}\). Therefore, we have \(\Vert r_{\ell }-q'\Vert =\Vert r_{\ell }-q\Vert \cos \gamma \le 3/K^{0.8}<(t_3-t_2)/10\) for sufficiently large K. \(\square \)

Assign an ordered pair \((\rho _1,\rho _2)\) to each ordered pair \((i,\ell )\) with \(i\ne \ell \), if \(R_{i}\) can be covered by the \(\varepsilon \)-neighbourhood of \(\rho _1\) many spheres out of \({\mathcal {S}}_2(\ell ),{\mathcal {S}}_3(\ell )\), and \(R_{\ell }\) can be covered by the \(\varepsilon \)-neighbourhood of \(\rho _2\) many spheres out of \({\mathcal {S}}_2(i),{\mathcal {S}}_3(i)\). By Claim 2.14 we have that \((\rho _1,\rho _2)\in \{(1,1),(2,1),(1,2)\}\). If there are \(\tau (i)\) indices \(\ell ^1,\ldots ,\ell ^{\tau (i)}\in B{\setminus } \{i\}\) such that we assigned (1, 2) or (1, 1) to \((i,\ell )\), then \(R_{i}\) is contained in the intersection of the \(\varepsilon \)-neighbourhood of \(\tau (i)\) spheres of radii \(t_2\) or \(t_3\) (with centres in \(b_{\ell ^1},\ldots , b_{\ell ^{\tau (i)}}\)).

Let \(\gamma \) be sufficiently small, that will be specified later. Using Lemma 2.4, we will show that for any \(r\in R_{i}\) the set \(R_i\) is \((r,d-\tau (i),\gamma )\)-flat provided that \(\varepsilon ,\alpha \) are sufficiently small, and K is sufficiently large. Let \(\beta _0\) be as in Lemma 2.4 for \(\gamma '=\gamma /2\), and let \(\beta \le \beta _0\) be sufficiently small.

We denote by \(\Gamma _{i}'\) the subspace spanned by the set of vectors \(\{b_{\ell ^s}-b_i:1\le s\le \tau (i)\}\). Standard calculation shows that if \(\varepsilon \) and \(\beta \) are sufficiently small, and K is sufficiently large, then there is no \(j<\tau (i)\) for which \(\Gamma _{i}'\) is \((j,\beta ^j)\)-Flat. (On an intuitive level, this is the case because B is approximately a regular simplex.) On the other hand, \(\Gamma _{i}'\) is of dimension at most \(\tau (i)\), thus it is \((\tau (i),\beta ^{\tau (i)})\)-Flat.

Let \(p\in R_i\) be such that \(p\ne r\). If \(\varepsilon \) is sufficiently small and K is sufficiently large, then for any \(1\le s\le \tau (i)\) the angle of the vectors \(b_{\ell ^s}-r\) and \(r-p\) is \((\beta ^{d'}/2)\)-close to \(\pi /2\). Indeed, this follows since the lengths \(\Vert b_{\ell ^s}-r\Vert \) and \(\Vert b_{\ell ^s}-p\Vert \) are \(\varepsilon \)-close to each other, and \(\Vert b_{\ell ^s}-r\Vert \) is at least K times as large as \(\Vert r-p\Vert \). Further, if \(\varepsilon \) is sufficiently small and K is sufficiently large, then the angle of the vectors \(b_{\ell ^s}-b_i\) and \(b_{\ell ^s}-r\) is at most \(\beta ^{d'}/2\). Thus, the angle of \(r-p\) and \(b_{\ell ^s}-b_i\) is \(\beta ^{d'}\)-close to \(\pi /2\).

Assume that for some \(r\in R_{i}\) the set \(R_i\cup B\) is \((r,d,\alpha )\)-flat with respect to \(\Gamma _r\). Then using Lemma 2.4 after projecting to a subspace parallel to \(\Gamma _r\) through r, we obtain that \(R_i\) is \((r,d-\tau (i),\alpha )\)-flat. We omitted the details of this argument, as they are essentially the same as the proof of Lemma 2.5 and of the proof of Case 2.2.1 after Claim 2.12.

Recall that S is \((r,d,\alpha )\)-flat for all but at most two \(r\in S\). Thus, for all but at most two (say, \(R_{1}\) or \(R_{1}, R_{2}\)) sets \(R_{i}\) there is an \(r\in R_i\) such that \(R_i\) is \((r,d-\tau (i),\gamma )\)-flat. Then Lemmas 2.7 and 2.2 (i) together imply that \(|R_{i}|\le d-\tau (i)+1\) if \(\alpha \) if \(\gamma \) is sufficiently small.

Each pair of vertices contributes to at least one of the \(\tau (i)\)’s, which implies that

$$\begin{aligned} \sum _{i=1}^{|B|} \tau (i) \ge \left( {\begin{array}{c}|B|\\ 2\end{array}}\right) .\end{aligned}$$

If in all \(R_{i}\) there is an r such that R is \((r,d,\alpha )\)-flat, then we obtain

$$\begin{aligned} |S|=\sum _{i=1}^{|B|}|R_i|\le |B|(d+1)-\sum _{i=1}^{|B|} \tau (i)\le |B|(d+1)- \left( {\begin{array}{c}|B|\\ 2\end{array}}\right) . \end{aligned}$$
(13)

Otherwise, repeating the same argument for \(S':=\bigcup _{i=2}^{|B|} R_i\) or for \(S'':=\bigcup _{i=3}^{|B|}R_i\),and using \(|R_1|\le 2\) or \(|R_{1}|+|R_{2}|\le 2\), we obtain

$$\begin{aligned} |S|=\sum _{i=1}^{|B|}|R_i|\le (|B|-1)(d+1)-\left( {\begin{array}{c}|B|-1\\ 2\end{array}}\right) +2. \end{aligned}$$
(14)

By Lemma 2.2 (ii) we have \(|B|\le d+1\), if K is sufficiently large and \(\varepsilon \) and \(\alpha \) are sufficiently small. Thus, recalling that we assumed \(d\le 6\), in both (13) and (14) the right hand side is bounded from above by \(m_3(d)\), by a simple calculation and by the fact that \(m_3(2)=7\), \(m_3(3)=12\), \(m_3(4)=16\), \(m_3(5)\ge 24\), and \(m_3(6)\ge 40\) (see Table 1). \(\square \)

2.4 Proof of Theorem 1.16

In order to prove the theorem, we will need the spherical analogues of our quantities. For a set P on a d-sphere \({\mathcal {S}}^d\subset {\mathbb {R}}^{d'}\) centred at \(\textbf{0}\), we say that P is \((d,\alpha ,{\mathcal {S}}^d)\) -flat if for each \(p\in P\) it is \((p,d,\alpha )\)-flat with respect to a d-dimensional subspace \(\Gamma _p\) that contains the vector \(p-{\textbf{0}}\). Note that we do not impose any conditions on the radius of the sphere.

Let \(NS_k(d',d)\) denote the largest number M such that for any \(\alpha ,\varepsilon >0\) there is a \((d,\alpha ,{\mathcal {S}}^d)\)-flat \(\varepsilon \)-nearly k-distance set of cardinality M on a d-sphere \({\mathcal {S}}^{d}\subset {\mathbb {R}}^{d'}\).

We call two subspaces \(\Gamma _1\) and \(\Gamma _2\) of \({\mathbb {R}}^d\) intersecting-orthogonal if there is an orthogonal basis \(\{v_1,\dots ,v_d\}\) of \({\mathbb {R}}^d\) with indices \(1\le i\le j\le d\) such that \(\{v_1,v_2,\dots ,v_j\}\) is an orthogonal basis of \(\Gamma _1\) and \(\{v_i,v_{i+1},\dots ,v_d\}\) is an orthogonal basis of \(\Gamma _2\). Slightly abusing notation, we will also call two affine planes \(\Lambda _1\) and \(\Lambda _2\) of \({\mathbb {R}}^d\) intersecting orthogonal if the subspaces \(\Gamma _1=\Lambda _1-\Lambda _1\) and \(\Gamma _2=\Lambda _2-\Lambda _2\) are intersecting orthogonal.

For each \(d,d'\), with \(0\le d<d'\), we are going to prove that \(N_k(d',d),NS_k(d',d) \le 2(k+1)^d\) simultaneously by induction on d. As the proof for \(N_k(d',d)\) and for \(NS_k(d',d)\) are very similar, we only spell it out with details for \(NS_k(d',d)\), which is the slightly more complicated case. Then we will comment on how to modify the proof for \(N_k(d',d)\).

The statement for \(NS_k(d',d)\) is clear for \(d=0\) and for any \(d'\). Suppose that the statement holds for \(d-1\). More precisely, we assume that there exist \(\varepsilon _{d-1},\alpha _{d-1}>0\) such that any \((d-1,\alpha _{d-1},{\mathcal {S}}^{d-1})\)-flat \(\varepsilon _{d-1}\)-nearly k-distance set P on a \((d-1)\)-sphere \({\mathcal {S}}^{d-1}\subset {\mathbb {R}}^{d'}\) satisfies \(|P|\le 2(k+1)^{d-1}\). We are now going to prove a similar statement for d with \(\varepsilon _{d},\alpha _d>0\), where \(\varepsilon _d,\alpha _d\) are sufficiently small compared to \(\varepsilon _{d-1},\alpha _{d-1}\).

Fix some sufficiently small \(\varepsilon _d,\alpha _d>0\). Take a \((d,\alpha _d,{\mathcal {S}}^d)\)-flat \(\varepsilon _d\)-nearly k-distance set P of points on a sphere \({\mathcal {S}}^d\). Let \(\rho \) be the radius of \({\mathcal {S}}^d\), and let the k distances be \(1\le t_1\le \ldots \le t_k\). Note that we may also assume that \(t_1\ge 2\). Indeed, to get this, simply enlarge P from \(\textbf{0}\). Then the enlarged image is a \((d,\alpha _d,{\mathcal {S}}^d)\)-flat \(2\varepsilon _d\)-nearly k-distance set with distances \(2t_1\le \ldots \le 2t_k\).

Take any point \(p\in P\), and for each \(i\in [k]\) let \({\mathcal {S}}_i^{d-1}\) be the \((d-1)\)-sphere obtained as the intersection of \({\mathcal {S}}^d\) with the d-sphere \({\mathcal {S}}(p,t_i)\) of radius \(t_i\) centred at p. Note that every point of \(q\in P\setminus \{p\}\) is contained in the \(\varepsilon _d\)-neighbourhood of \({\mathcal {S}}(p,t_i)\) for some i. Further, let \(\Gamma _p\) be a subspace of dimension d containing the vector \(p-{\textbf{0}}\) such that P is \((p,d,\alpha _d)\)-flat with respect to \(\Gamma _p\).

Let \(j'\) be the largest index j such that \(t_{j}<\varepsilon ^{1/4}_d\rho \), if there is any, and otherwise let \(j'=0\). Then all points at distance at most \(t_{j'}+\varepsilon _d\) from p lie in a spherical cap with centre in p and of angular radius \(K_1\varepsilon ^{1/2}_d\) for some constant \(K_1\). Denote the set of these points by X. For every \(q\in X\), let \(\Lambda _q\) be the d-dimensional affine plane (contained in the \((d+1)\)-dimensional affine plane spanned by \({\mathcal {S}}^d\)) tangent to \({\mathcal {S}}^d\) at q. Further, let \(\Gamma '_q\) be a d-dimensional subspace parallel to \(\Lambda _q\). Then one can show (by combining a projection argument with standard calculations) that there is a universal constant \(K_2\) such that X is globally \((d,K_2\varepsilon ^{1/2}_d)\)-flat with respect to \(\Gamma _q'\).

Recall that at the same time for every \(q\in X\) we have that X is \((q,d,\alpha _d)\)-flat with respect to a d-dimensional subspace \(\Gamma _q\) containing \(q-\textbf{0}\). Since \(\Gamma _q\) contains the vector \(q-\textbf{0}\), the subspace \(\Gamma _q'\) is intersecting-orthogonal to \(\Gamma _q\). Let \(\Gamma _q''\) denote the intersection of \(\Gamma _q\) and \(\Gamma _q'\). We can conclude by simple calculation that for any \(q\in X\) we have that X is \((q,d-1,\alpha _{d-1})\)-flat with respect to \(\Gamma _q''\) provided \(\varepsilon _d,\alpha _d\) are chosen appropriately small. Thus, by the induction hypothesis we obtain \(|X|\le 2(k+1)^{d-1}\).

Next, let \(j''\) be the smallest index such that \(t_{j''}\ge (2-\varepsilon ^{1/2}_d)\rho \) (if there is no such \(j''\) then we put \(j'':=k+1\)). Let Y be the set of those points of P that are at distance at least \(t_{j''}\) from p. Let \(p'\) be the point on \({\mathcal {S}}^d\) that is diametrically opposite to p. Then Y is contained in a spherical cap with centre in \(p'\) and of angular radius \(K_1\varepsilon ^{1/2}_d\). Following the same argument that we used to bound |X|, we obtain that \(|Y|\le 2(k+1)^{d-1}\).

Now consider the set \(P':=P\setminus (X\cup Y\cup \{p\})\). For every point of \(q\in P'\) there is an index \(j'<i<j''\) such that the distance of q and p falls in \([t_i,t_i+\varepsilon _d]\). Note also that for every point \(q\in P'\) the angle between \(q-\textbf{0}\) and \(p-{\textbf{0}}\) is at least \(\varepsilon ^{1/2}_d\). Standard calculations show that if for some \(q\in P'\) and \(j'<i<j''\) we have \(\Vert q-p\Vert \in [t_i,t_i+\varepsilon _d]\), then the distance from q to \(S_i^{d-1}\) is at most \(K_3\varepsilon ^{1/2}_d\) for some constant \(K_3\).

For each \(q\in P'\), replace q with the closest point on the corresponding \(S_i^{d-1}\). Denote the resulting set \(P''\). Then the distances between distinct points of \(P''\) are contained in

$$\begin{aligned} \biggl [t_{1}-\frac{\varepsilon _{d-1}}{3}, t_{1}+\frac{\varepsilon _{d-1}}{3}\biggr ]\cup \cdots \cup \biggl [t_{k}-\frac{\varepsilon _{d-1}}{3}, t_{k}+\frac{\varepsilon _{d-1}}{3}\biggr ],\end{aligned}$$

provided that \(\varepsilon _d\) is small enough. Thus, \(P''\) is a \((2\varepsilon _{d-1}/3)\)-nearly k-distance set with distances \(1\le t_1'\le \ldots \le t_k'\), where the first inequality follows from the assumption that \(t_1\ge 2\) and that \(\varepsilon _{d-1}\) is sufficiently small.

Since the set \(P''\) is obtained by a small perturbation from a subset of P, we can show by a simple calculation that there is a constant \(K_4\) such that for any \(q\in P''\) the set \(P''\cup \{p\}\) is \((q,d,\alpha _d+K_4\varepsilon ^{1/2}_d)\)-flat with respect to a subspace \(\Gamma _q\) containing \(q-\textbf{0}\). Let \(\Gamma _q'\) be a rotation of \(\Gamma _q\) by an angle at most \(\alpha _4+K_4\varepsilon ^{1/2}_d\) such that \(\Gamma _q'\) contains \(q-\textbf{0}\) and \(p-\textbf{0}\). Then, by the triangle inequality, \(P''\) is \((q,d,2(\alpha _d+K_4\varepsilon ^{1/2}_d))\)-flat with respect to \(\Gamma _q'\).

For every \(j'<i<j''\) let \(M_i\) be the affine \((d-1)\) dimensional plane containing \(S_i^{d-1}\), and let \(\Delta _i\) be the \((d-1)\)-dimensional subspace parallel to \(M_i\). If \(q\in P''\) is in \(S_i^{d-1}\), then \(\Gamma '_q\) and \(\Delta _i\) are intersecting-orthogonal. Moreover, \(\Gamma _q'\) contains the centre of \(S^{d-1}_i\). These imply that the set \(P''_i:=P''\cap {\mathcal {S}}_i^{d-1}\) is \((d-1,\varepsilon _{d-1},{\mathcal {S}}^{d-1}_i)\)-flat, where the subspace for the flatness at point q is \(\Gamma '_q\cap \Delta _i\). Thus, by induction we have \(|P''_i|\le 2(k+1)^{d-1}\). Overall, we have

$$\begin{aligned} |P|\le 1+\sum _{i=1}^{j'}|X|+\sum _{i=j''}^k|Y|+\sum _{i=j'+1}^{j''-1}|P''_i|\le 1+k\cdot 2(k+1)^{d-1}\le 2(k+1)^d.\end{aligned}$$

A similar, but simpler proof works for non-spherical sets. Let us sketch the proof. We fix a point p, decompose the set P into p and the \(\varepsilon _d\)-neighbourhoods of k spheres at distance \(t_i\) from p. We then project the points on the corresponding spheres and apply inductive hypothesis for the spherical sets of dimension \(d-1\). The only thing to verify is that the sets are \((d-1,\varepsilon _{d-1}, S_i^{d-1})\)-flat, and notably that the corresponding approximating plane passes through the centre of the sphere \(S_i^{d-1}\). But we may assume that, since the approximating plane \(\Gamma _q\) of any point \(q\in P\setminus \{p\}\) was containing \({\textbf{0}}\) and was forming an angle at most \(\alpha _d\) with the line pq. Thus, by a slight perturbation (and by a possibly slightly weaker approximation), we may assume that both p and \({\textbf{0}}\) are contained in \(\Gamma _q\). Since the centre of \({\mathcal {S}}_i^{d-1}\) lies on the line \(p{\textbf{0}}\), it is contained in \(\Gamma _q\) as well.

2.5 Proof of Theorems 1.17 and 1.18

Let us start with the proof of the upper bound in Theorem 1.18. It is immediately implied by the following theorem, combined with the fact that \(A_k(d)=m_k(d-1)\) in the cases covered in Theorem 1.18. (This is what we have actually shown in the proof of Theorem 1.15.)

Theorem 2.15

For any \(d\ge 2\) and \(k\ge 1\) there exists \(n_0\), such that for any \(n\ge n_0\) we have

$$\begin{aligned} M_k(d,n)\le T(n,A_k(d))\le \biggl (1-\frac{1}{A_k(d)}\biggr )\frac{n^2}{2}. \end{aligned}$$
(15)

Moreover, (15) remains valid if in the definition of \(M_k(d,n)\) we change the intervals of the form \([t_i,t_i+1]\) to intervals of the form \([t_i,t_i+cn^{1/d}]\) for some constant \(c=c(k,d)\).

We first prove Theorem 2.15, that is, we show that (15) holds with intervals of the form \([t_i,t_i+cn^{1/d}]\), where \(c=c(k,d)\) is a sufficiently small constant, to be specified later. The proof of Theorem 1.17 is very similar and is actually simpler. We sketch the changes needed to be made in order to prove it in the end of this section.

Let \(\ell =A_k(d)+1\) and let \(\alpha ,\varepsilon >0\) be fixed such that there exists no almost \((d-1,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^d\) of cardinality \(\ell \). Assume on the contrary that (15) does not hold for some set of n points \(S''\subset {{\mathbb {R}}}^d\) for sufficiently large n. Let \(1\le t_1\le \ldots \le t_k\) be the corresponding distances, and let c be the constant from the statement of the theorem. Our goal is to derive a contradiction by constructing an almost \((d-1,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set of cardinality \(\ell \).

In the proof, we will use a hierarchy of “small” constants given below. We write \(\mu \ll \nu \) if \(\mu \) is a certain (positive, but typically quickly tending to 0) function, depending on \(\nu \) only. Thus, the arrows indicate the order of choosing the parameters: from the right to the left below (and thus, for consistency, one only needs to check that every condition we impose on a constant in the hierarchy only depends on the constants that are to the right from it and is of the form “it is sufficiently small compared to some of the constants to the right”). Note also that all the constants given below are independent of n.

$$\begin{aligned} \frac{1}{n}\ll c\ll c_1\ll \frac{1}{C}\ll \frac{1}{m}\ll \frac{1}{M},\delta ,c_2,\nu \ll \frac{1}{d},\frac{1}{k},\alpha ,\varepsilon . \end{aligned}$$
(16)

We recommend the reader to refer to this chain of dependencies throughout the proof. We use the following simple claim.

Claim 2.16

For any \(k\ge 0\), we have \(N_k(d)<A_{k+1}(d)\).

Proof

Take a construction S of a \((d-1,\mu )\)-flat \(\mu \)-nearly k-distance set in \({{\mathbb {R}}}^d\) in which the distances are at least \(K/\mu \) for a sufficiently large K. Pick any \(p\in S\), and let \(\Gamma \) be a subspace of dimension \(d-1\) such that S is \((p,d-1,\mu )\)-flat with respect to \(\Gamma \). Let \(q\in {\mathbb {R}}^d\) be a point at distance 1 apart from p such that \(p-q\) is orthogonal to \(\Gamma \). Then it is easy to see that \(S\cup \{q\}\) is an almost \((d-1,3\mu )\)-flat \(3\mu \)-nearly \((k+1)\)-distance set in \({{\mathbb {R}}}^d\) if \(\mu \) is sufficiently small and K is sufficiently large.

Indeed, for any \(r\in S\setminus \{p,q\}\) we have \(|\Vert r-p\Vert -\Vert r-q\Vert |\le \mu \) if K is sufficiently large and \(\mu \) is sufficiently small. Thus, the only distance between points of \(S\cup \{q\}\) that is not \(\mu \)-close to a distance between points of S, is the distance \(\Vert p-q\Vert \). Then by the triangle inequality we obtain that S is a \(3\mu \)-nearly \((k+1)\)-distance set. Further, the angle between \(p-r\) and \(q-r\) is at most \(\mu \), if \(\mu \) is sufficiently small and K is sufficiently large. Thus, again, by the triangle inequality, for any \(r\in S\setminus \{p,q\}\) we have that S is \((r,d-1,3\mu )\)-flat. \(\square \)

Using the claim above, we may assume that \(t_1\ge c_2 n^{1/d}\). Indeed, assume the contrary. Since \(S''\) is separated, a volume argument implies that for each vertex \(v\in S''\), the number of vertices in \(S''\) at distance at most \(c_2 n^{1/d}\) from v is at most \((4c_2)^dn\). Thus, removing all edges from \(G''\) that correspond to such distances, we only remove at most \((4c_2)^dn^2\) edges. At the same time, we reduce the size of the set of possible intervals by at least 1. Hence, we apply Theorem 1.17 with \(\nu \) playing the role of \(\varepsilon \), and obtain

$$\begin{aligned} M_k(d,n)\le & {} (4c_2)^dn^2+M_{k-1}(d,n)\le (4c_2)^dn^2+\frac{n^2}{2}\biggl (1-\frac{1}{N_{k-1}(d)}+\nu \biggr )\\ {}\le & {} \frac{n^2}{2}\biggl (1-\frac{1}{A_{k}(d)}\biggr )\end{aligned}$$

by using the hierarchy (16). We note here that in the proof of Theorem 1.17, this step is automatic, since the removal of edges corresponding to small distances only change the potential value of \(\gamma \).

Our next goal is to obtain a sufficiently structured subset of \(S''\). We need the following result of Erdős.

Theorem 2.17

[8] Every n-vertex graph with at least \(T(n, \ell -1)+1\) edges contains an edge that is contained in at least \(\delta n^{\ell -2}\) cliques of size \(\ell \), where \(\delta \) is a constant that depends only on \(\ell \).

Consider the graph \(G''=(S'',E)\), where the set of edges consist of all pairs of points \(\{p_1,p_2\}\) for \(p_1,p_2\in S\) that satisfy

$$\begin{aligned} \Vert p_1-p_2\Vert \in \bigcup _{i=1}^k\,[t_i,t_i+c n^{1/d}].\end{aligned}$$

Using the theorem above, we will show that the following lemma holds.

Lemma 2.18

For any fixed m, there exists a choice of \(c_1=c_1(m)\) such that \(G''\) contains a complete \(\ell \)-partite subgraph \(K_{1,1,m,\ldots ,m}\) with the distances between any two of its vertices strictly bigger than \(c_1n^{1/d}\).

Proof

We construct this multipartite graph in three steps.

Step 1. Using Theorem 2.17, we find an edge \(e=\{v_1,v_2\}\) that is contained in at least \(\delta n^{\ell -2}\) cliques of size \(\ell \). Let \(E''\) be the set of those edges of the \(\ell \)-cliques, that are not incident to \(v_1\) or \(v_2\). Further, let F be the set of the \((\ell -2)\)-tuples formed by the \(\ell -2\) vertices of the cliques that are different from \(v_1\) and \(v_2\). The vertices of e form the first two parts of the multipartite graph. In what follows, we will work with the graph \(G''\) induced on \(S''\setminus \{v_1,v_2\}\) by \(E''\).

Step 2. We select a set \(S_H\) of C vertices of \(G''\) at random, and define a hypergraph \(H'\) on \(S_H\) as follows. Recall that \(c_1\ll 1/C\ll \delta ,1/\ell ,1/m\) (see (16); the exact dependency of C on \(\delta ,m\) and of \(c_1\) on C shall be clear later), and consider the induced subgraph \(G':=G''[S_H]\). \(S''\) is separated, hence a volume argument implies that any vertex in \(S''\setminus \{v_1,v_2\}\) is at distance strictly bigger than \(c_1n^{1/d}\) from all but at most \((4c_1)^dn\) vertices of \(S''\setminus \{v_1,v_2\}\). The number of vertices in \(S''{\setminus }\{v_1,v_2\}\) is \(n-2\), so by the union bound we have the following.

  1. (I)

    With probability at least \(1-\left( {\begin{array}{c}C\\ 2\end{array}}\right) (4c_1)^d n/(n-2)>1-c_1\), every pair of vertices in \(S_H\) is at distance bigger than \(c_1n^{1/d}\) from each other.

Indeed, the total number of pairs of vertices is \(\left( {\begin{array}{c}C\\ 2\end{array}}\right) \), and for each pair the probability that it is at distance \(\le c_1n^{1/d}\) is at most \((4c_1)^dn/(n-2)\). The inequality in (I) is possible to satisfy by fixing \(\ell ,C\) and choosing \(c_1\) to be sufficiently small.

Next, we consider the \((\ell -2)\)-uniform hypergraph \(H''=(S''\setminus \{v_1,v_2\},F)\). The following is an easy consequence of a Markov inequality-type argument.

  1. (II)

    With probability at least \(\delta /2\), the edge density of the hypergraph \(H'=H''[S_H]\) is at least \(\delta /2\).

Indeed, the average density of cliques should be the same as of \(H''\), i.e., at least \(\delta \). But if (II) does not hold, then the average density is at most \((1-\delta /2)\cdot \delta /2+\delta /2\cdot 1=\delta -\delta ^2/4<\delta \), a contradiction.

If we choose \(c_1<\delta /2\), then with positive probability both the property in (I) and in (II) hold. Pick a subset \(S_H\subseteq S{\setminus }\{v_1,v_2\}\) that satisfies both.

Step 3. We apply the following hypergraph generalisation of the Kővári–Sós–Turán theorem due to Erdős.

Theorem 2.19

[7] For any \(\ell \ge 4\), \(m\ge 1\), \(\delta >0\) there is a constant \(C(\ell ,m,\delta )\) such that the following holds for any \(C\ge C(\ell ,m,\delta )\). Any \((\ell -2)\)-uniform hypergraph on C vertices of edge density at least \(\delta /2\) contains a copy of a complete \((\ell -2)\)-partite \((\ell -2)\)-uniform hypergraph with parts of size m.

Applying the theorem to the \((\ell -2)\)-hypergraph \(H'\), we obtain a complete \((\ell -2)\)-partite \((\ell -2)\)-uniform hypergraph with parts of size m. This complete multipartite hypergraph corresponds to a complete \((\ell -2)\)-partite graph in G with parts of size m and with all distances between points being at least \(c_1n^{1/d}\). Together with the edge e, this gives the desired \(\ell \)-partite subgraph \(K_{1,1,m,\dots ,m}\). \(\square \)

Let the \(\ell \) parts of the \(K_{1,1,m\dots ,m}\) in \(G''\) be \(S'_1,\dots ,S'_{\ell }\), with \(S_1=\{v_1\}\), \(S_2=\{v_2\}\), and with \(|S_3|=\ldots =|S_{\ell }|=m\), further set \(S'=S_1\cup \ldots \cup S_{\ell }\). \(S'\) has much more structure than the original set \(S''\). However, distances from several intervals from \([t_1,t_1+cn^{1/d}],\dots ,[t_k,t_k+cn^{1/d}]\) may appear between the vertices of \(S'_i\) and \(S'_j\), \(i\ne j\). To reduce it to one interval between any two parts, we will do the second “preprocessing” step using the following version of the Kővári–Sós–Turán theorem.

Theorem 2.20

[18] For any \(\zeta >0\) and \(r\ge 1\) there exists \(n_0\), such that for any \(n\ge n_0\) we have the following. Any graph on n vertices with at least \(\zeta \left( {\begin{array}{c}n\\ 2\end{array}}\right) \) edges contains \(K_{r,r}\) as a subgraph.

Take \(S'\) and set \(i:=1\). Then do the following procedure.

  1. 1.

    Set \(j:=i+1\). If \(i=1\), \(j=2\), set \(j:=3\).

  2. 2.

    Take the subgraph of \(G'\) induced between \(S_i'\) and \(S_j'\). Choose an index \(\psi =\psi (i,j)\in [k]\), such that

    $$\begin{aligned} \bigl |\bigl \{(v_i,v_j):v_i\in S_i',\,v_j\in S_j',\,|v_i-v_j|\in [t_\psi ,t_\psi +c n^{1/d}]\bigr \}\bigr |\ge \frac{m^{\sigma }}{k}, \end{aligned}$$

    where \(\sigma =1\) if \(i\in \{1,2\}\) and \(\sigma =2\) otherwise. Set \(G_{ij}\) be the graph between \(S_i'\) and \(S_j'\) with the set of edges specified in the displayed formula above.

  3. 3.

    If \(i\in \{1,2\}\), let \(S''_i\) be the set of neighbours of \(p_i\) in \(G_{ij}\). If \(i\notin \{1,2\}\), apply Theorem 2.20 to \(G_{ij}\) and find sets \(S''_i\subset S'_i\), \(S''_j\subset S'_j\), each of size \(1\ll m'\ll m\), such that the graph \(G_{ij}\) between \(S''_i\) and \(S''_j\) is complete bipartite.

  4. 4.

    Set \(S'_i:=S''_i\), \(S'_j:=S''_j\), \(m:=m'\), \(j:=j+1\). If \(j\le k\) then go to step 2. If \(j>k\) then set \(i:=i+1\). If \(i\ge k\), then terminate, otherwise go to step 1.

Clearly, if m in the beginning of the procedure was large enough, then at the end of the procedure m is still larger than some sufficiently large M. By running a procedure similar to the one above, we can shrink the parts \(S_i\)’s further such that for any \(p_i\in S_i\) and \(p_j,q_j\in S_j\), \(j\notin \{1,2\}\), the angle \(\angle p_jp_iq_j\) is at most \(\alpha \). If M is sufficiently large (see the hierarchy (16)), then at the end of this second procedure each \(S_i\), \(i\notin \{1,2\}\), has at least two points. Thus, we obtain a subset \(S\subset S'\), such that \(G:=G''[S]\) is complete multipartite with parts \(S_1,\dots ,S_{\ell }\) such that \(|S_1|=|S_2|=1\) and \(|S_3|=\ldots =|S_{\ell }|=2\), moreover for any two parts \(S_i, S_j\) there is an index \(\psi (i,j)\in [k]\) such that

  • for any \(p_i\in S_i\), \(p_j,q_j\in S_j\) we have \(\Vert p_i-p_j\Vert \in [t_{\psi (i,j)},t_{\psi (i,j)}+c n^{1/d}]\) and \(\angle p_jp_iq_j\le \alpha \).

For each \(3\le i \le \ell \) let \(S_i=\{p_i,q_i\}\). Let P be the set \(\{p_1,\dots ,p_{\ell }\}\) scaled by \({1}/({c_2n^{1/d}})\), that is, let \(P=({1}/({c_2n^{1/d}}))\{p_1,\dots ,p_{\ell }\}\). We will show that P is an almost \((d-1,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set, and obtain the desired contradiction. Indeed, this set is separated, since all the distances between \(p_i\) and \(p_j\) for \(i\ne j\) were at least \(c_2n^{1/d}\). Further, it is an \(\varepsilon \)-nearly k-distance set, since the length of each of the intervals in which the distances fall is \(cn^{1/d}/c_2n^{1/d}=c/c_2\le \varepsilon \).

Finally, we claim that for any \(i\notin \{1,2\}\) and any \(j\ne i\) we have \(\angle q_ip_ip_j\in [{\pi /2-\alpha },{\pi /2+\alpha }]\). Let us show this. Take the point \(q_i'\) on the line through \(p_i,p_j\) such that \(\Vert q_i-p_j\Vert =\Vert q_i'-p_j\Vert \). Then, first, \(\angle q_iq_i'p_j\in [(\pi -\alpha )/2,\pi /2]\) since \(\angle q_ip_jp_i\le \alpha \) and the triangle \(q_iq_i'p_j\) is isosceles. Second, we have \(\Vert q_i'-p_i\Vert \le cn^{1/d}\). Since \(\Vert q_i-p_i\Vert \ge c_1n^{1/d}\), we may assume that \(\angle q_i'q_ip_i\le \alpha /2\), and thus \(\angle q_ip_ip_j\in [(\pi -\alpha )/2-\angle q_i'q_ip_i,\pi /2+\angle q_i'q_ip_i]\subset [\pi /2-\alpha ,\pi /2+\alpha ]\).

Thus, for every \(i\notin \{1,2\}\) we have that P is \(((1/(c_2n^{1/d}))p_i,d-1,\alpha )\)-flat with respect to the \((d-1)\)-dimensional subspace orthogonal to \(p_i-q_i\). This finishes the proof of Theorem 2.15.

We now turn to the proof of Theorem 1.17. We prove that for every \(\gamma >0\) inequality (8) holds with intervals of the form \([t_i,t_i+cn^{1/d}]\) where \(c=c(k,d,\gamma )\) if n is sufficiently large. As the proof is very similar to the proof of Theorem 2.15, we only sketch it, pointing out the differences.

Let \(\ell :=N_k(d)+1\) and \(\alpha ,\varepsilon >0\) be fixed such that there exists no \((d-1,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set in \({\mathbb {R}}^d\) of cardinality \(\ell \). Assume on the contrary that for every \(c>0\) and \(n_0\) there is an \(n\ge n_0\), there are k distances \(t_1<\ldots \le t_k\) and a set \(S''\subset {{\mathbb {R}}}^d\) of n points for which

$$\begin{aligned} \bigl |\bigl \{(p,q)\in S''\times S'':\Vert p-q\Vert\in & {} [t_i,t_i+cn^{1/d}] \text { for some } i\in [k]\bigr \}\bigr |\\ {}> & {} T(N_k(d),n)+\gamma n^2.\end{aligned}$$

Our goal is to derive a contradiction by constructing an a \((d-1,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set of cardinality \(\ell \).

After including \(\gamma \) in the hierarchy of constants on the same level as \(\alpha \), the proof is the same as that of () up to the point of Lemma 2.18. Instead of Lemma 2.18 we will use the following.

Lemma 2.21

For any fixed m, there exists a choice \(c_1=c_1(m,\gamma )\) such that \(G''\) contains a complete \(\ell \)-partite subgraph \(K_{m,\dots ,m}\) such that the distance between any two of its vertices is bigger than \(c_1n^{1/d}\).

The proof of Lemma 2.21 is very similar to the proof of Lemma 2.18, except that instead of Theorem 2.17 we use a result of Erdős and Simonovits [12] about the supersaturation of \(\ell \)-cliques. (And then work with \(\ell \)-uniform hypergraphs instead of \(\ell -2\).) Therefore, we only give an outline of the proof.

Theorem 2.22

[12] For any \(\ell ,\gamma >0\) there is a \(\delta \) such that if a graph G on n vertices has at least \(T(n,\ell )+\gamma n^2\) edges, then it contains at least \(\delta n^{\ell }\) cliques of size \(\ell \).

Sketch of proof of Lemma 2.21

We construct this multipartite graph in three steps.

Step 1. Using Theorem 2.22, we find \(\delta n^{\ell }\) cliques of size \(\ell \). Let \(E''\) be the set of the \(\ell \)-cliques, and F be the set of the \(\ell \)-tuples. In what follows, we will work with the graph \(G''\) induced on \(S''\) by \(E''\).

Step 2. Select C vertices of \(G''\) at random, where \(c_1\ll 1/C\ll \delta ,1/\ell ,1/m\). Denote by \(S_H\) the set of C vertices that we chose and consider the induced subgraph \(G':=G''[S_H]\). A similar calculation as in the proof of Lemma 2.18 implies the following.

  1. (I)

    With probability at least \(>1-c_1\), every pair of vertices in \(S_H\) is at distance bigger than \(c_1n^{1/d}\) from each other.

Next, we consider the \(\ell \)-uniform hypergraph \(H''=(S'',F)\). As before we obtain the following.

  1. (II)

    With probability at least \(\delta /2\), the edge density of the hypergraph \(H'=H''[S_H]\) is at least \(\delta /2\).

If we choose \(c_1<\delta /2\) then with positive probability both the property in (I) and in (II) hold. Pick a subset \(S_H\subseteq S\) that satisfies both.

Step 3. Applying Theorem 2.19 to the \(\ell \)-hypergraph \(H'\), we obtain a complete \(\ell \)-partite \(\ell \)-uniform hypergraph with parts of size m. This complete multipartite hypergraph corresponds to a complete \(\ell \)-partite graph in G with parts of size m and with all distances between points being at least \(c_1n^{1/d}\). \(\square \)

Let the \(\ell \) parts of the \(K_{m\dots ,m}\) in \(G''\) be \(S'_1,\dots ,S'_{\ell }\), with \(|S_1|=\ldots =|S_{\ell }|=m\) and set \(S'=S_1\cup \cdots \cup S_\ell \). Running a similar procedure as before we obtain a subset \(S\subset S'\), such that \(G:=G''[S]\) is complete multipartite with parts \(S_1,\ldots , S_{\ell }\) such that \(|S_1|=\ldots =|S_{\ell }|=2\), moreover for any two parts \(S_i, S_j\) there is an \(\psi (i,j)\in [k]\) with

  • for any \(p_i\in S_i\), \(p_j,q_j\in S_j\) we have \(\Vert p_i-p_j\Vert \in [t_{\psi (i,j)},t_{\psi (i,j)}+c n^{1/d}]\) and \(\angle p_jp_iq_j\le \alpha \).

For each \(1\le i\le \ell \) let \(S_i = \{p_i,q_i\}\). Then we can show that P given by \((1/(c_2n^{1/d}))\{p_1,\dots ,p_{\ell }\}\) is a \((d-1,\alpha )\)-flat \(\varepsilon \)-nearly k-distance set, and obtain a contradiction.

3 Concluding Remarks

Let us list some of the intriguing open problems that arose in our studies. One important step forward would be to get rid of the (almost-)flatness in the relationship between nearly k-distance sets and the quantity \(M_k(d,n)\) that appears in Theorems 1.17 and 2.15. In particular, it would be desirable to prove the first equality in Conjecture 1.11 and, more generally, show the following.

Problem 3.1

Show that \(A_k(d+1,d) = N_k(d+1) = M_k(d)\) holds for any kd.

In fact, even showing the first equality would imply that the value of \(M_k(d,n)\) for large n is determined exactly by the value of \(N_k(d+1)\). Another interesting question that looks approachable is to determine the value of \(M_k(d)\) on the part of the spectrum opposite to that of Theorem 1.15: for any fixed d and k sufficiently large. Note that the order of magnitude of \(M_k(d)\) in this regime is easy to find, as it is shown in Theorem 1.16.

Problem 3.2

Determine \(M_k(d)\) for any fixed d and sufficiently large k.

If resolved, then with some effort it would most likely be possible to determine the value of \(M_k(d,n)\) for large n in this regime as well.