On The Number of Similar Instances of a Pattern in a Finite Set

New bounds on the number of similar or directly similar copies of a pattern within a finite subset of the line or the plane are proved. The number of equilateral triangles whose vertices all lie within an $n$-point subset of the plane is shown to be no more than $\lfloor{(4 n-1)(n-1)/18}\rfloor$. The number of $k$-term arithmetic progressions that lie within an $n$-point subset of the line is shown to be at most $(n-r)(n+r-k+1)/(2 k-2)$, where $r$ is the remainder when $n$ is divided by $k-1$. This upper bound is achieved when the $n$ points themselves form an arithmetic progression, but for some values of $k$ and $n$, it can also be achieved for other configurations of the $n$ points, and a full classification of such optimal configurations is given. These results are achieved using a new general method based on ordering relations.


Introduction
Erdős and Purdy [18,19,20] raised the question of finding the maximum number of equilateral triangles that can be determined by n points in the plane, where we say that a triangle is determined by a set V when the three vertices of the triangle lie in V . This problem is also mentioned in the compendia of unsolved problems in geometry by Croft, Falconer, and Guy [13] and by Brass, Moser, and Pach [9], and is discussed by Pach and Sharir in [27]. There are many other variations of this problem involving other patterns, constraints on the n-set in which instances of the pattern are sought, higher-dimensional ambient spaces, different equivalence relations for the patterns, and different optimization objectives, e.g., [1,3,4,5,6,7,11,12,25,26,28,29]. These problems trace their inspiration to Erdős' question [17] about the maximum number of pairs of points at unit distance that can be determined by an n-subset of the plane, and other related questions, which have led to a rich literature (see [9,24] for an overview). Apart from being a well-known and important question in discrete geometry, the problem of determining S P (n) is relevant to the problem of pattern recognition in data from scanners, cameras, and telescopes [8,9,10].
In all these problems, we have a universe, which is a set U , an equivalence relation ∼ on the power set of U , and a pattern P, which is an equivalence class of ∼. If P ∈ P, we say that P is an instance of pattern P. We call P a k-pattern if its instances are k-sets. For the rest of this paper, the pattern P is always assumed to be a finite set. For V ⊆ U , we let S P (V ) = |{P ⊆ V : P ∈ P}| .
We are concerned with finite subsets of our universe U . For an integer n, we define S P (n) = max V ⊆U |V |=n that is, the largest number of instances of P that can be found in an n-subset of U . The results of this paper concern the case when U is the line R or the plane R 2 (identified with C), where ∼ is the geometric relation of similarity or direct similarity, and where the patterns P are classes of finite subsets, such as arithmetic progressions in the line, or equilateral triangles in the plane.
If our relation ∼ is similarity or direct similarity, and our pattern P has more than one point, and we are counting the number of instances of P in subsets of the plane, then it is not hard to show that S P (n) is O(n 2 ). Elekes and Erdős [16] proved a slightly subquadratic lower bound for general patterns P and a quadratic lower bound if there is an instance of P whose points all have algebraic numbers for their coordinates. Laczkovich and Ruzsa [23] later showed that S P (n) = Θ(n 2 ) if and only if the cross ratio of every quadruplet of distinct points in an instance of P is algebraic. However, before this work there were no patterns P (with at least three points) for which the quadratic coefficient was known.
Let E be the pattern of the vertices of an equilateral triangle, that is, E contains all 3-point subsets of the plane such that all three pairs of points within the set have the same distance. Then the results of Laczkovich and Ruzsa show that S E (n) = Θ(n 2 ). Prior to this paper, the best known bounds [2] for S E (n) were The lower bound is obtained from the points in the equilateral triangle lattice contained in a disk of a suitable radius. It is conjectured [2,Conjecture 1] that this construction is asymptotically optimal and that lim n→∞ S E (n)/n 2 exists and equals 1 3 4π , the lower endpoint of the interval in which the limits inferior and superior for S E (n)/n 2 are known to lie.
The main result of this paper is an improved upper bound on S E (n) that cuts this interval to less than half the previous length. Theorem 1.1. If E is the pattern of the vertices of equilateral triangles in R 2 , then S E (n) ≤ ⌊(4n − 1)(n − 1)/18⌋. Therefore lim sup n→∞ S E (n)/n 2 ≤ 2/9. The proof is given in Section 8, and is based on a new and highly general order-theoretic methodology, developed in Sections 2-4, for attacking pattern-counting problems.
Our new methodology was first developed while exploring the simpler problem of counting instances of finite patterns (such as arithmetic progressions) in finite subset of the line R, and was used to discover interesting results that are presented in Sections 5-7. After settling preliminaries in Section 5, we calculate the precise maximum number of k-term arithmetic progressions that can occur in an n-point subset of the line in Section 6. Theorem 1.2. Let k > 1, and let A k be the pattern of k-term arithmetic progressions on R. If n ∈ N and r is the remainder when n is divided by For each k > 2, we completely classify all n-point subsets of the line that contain as many k-term arithmetic progressions as possible. These optimal sets include n-term arithmetic progressions, but there are some other optimal sets: when k > 3 and k − 1 divides n, sets obtained by deleting the second or penultimate point from an arithmetic progression are also optimal (see Proposition 6.5). When k = 3, the variety of the optimal sets is considerably richer (see Proposition 6.3). This work complements the asymptotic approach of Elekes [15], who studied the structure of n-subsets of the line that contain an asymptotically large number of k-term arithmetic progressions, whereas we determine the precise maximum and those sets that achieve it.
In Section 7, we show that our method can be used to obtain both upper and lower bounds on S P (n) when P is a commensurable pattern in the line, that is, where the ratios of the distances between points in P are all rational. We count the number of directly similar copies of P = {0, 1, 3} in finite subsets of the line, so if P is the pattern for P , we show that and we construct an interesting family of n-point subsets V n of the line with lim n→∞ S P (V n )/n 2 = 3/16, which is the highest known value and, interestingly, lies strictly between the bounds of (2). As noted, our order-theoretic method is a new and highly general tool for counting patterns in finite sets. It combines nicely with other techniques of discrete geometry, for example, the proof of Theorem 1.1 combines our tools with the topological technique of finding three coincident halving lines of a set (cf. [22,Lemma 2], [21,Lemma 3], and [14,Lemma 2]). Further applications will be explored in future works.

Order and Partitions
A key theme in this work is that one can place an order relation on the universe U , and use it to create bounds on S P (n). So henceforth, we assume that our universe U has a total ordering relation . If V ⊆ U , then we say that a point v ∈ V is the ith point of V with respect to to mean that there If V is a set and ℓ a positive integer, then an ℓ-partition of V is a partition of V into ℓ subsets. An ℓ-partition of a finite set V with n points is said to be balanced if each set in the partition has either ⌊n/ℓ⌋ or ⌈n/ℓ⌉ points in If k ≥ 2 and there is a -orderly (k − 1)-partition V of V , and a k-subset P of V , then we say that P is of echelon j in V if the jth and (j + 1)th It is a key fact that P must be of echelon j in V for at least one j.
Of course, if k ≥ 4, and V is a set with -orderly (k − 1)-partition V, then a k-subset P of V may be of echelon j in V for more than one j.

Reconstructibility
Let P be a k-pattern in our universe U with order relation . Suppose we are given some j ∈ {1, . . . , k − 1} and two points u, v ∈ U with u ≺ v. Any P ∈ P that has u and v respectively as its jth and (j + 1)th points is called a reconstruction of P with the prescribed points as its jth and (j + 1)th points.
If, for every j ∈ {1, . . . , k − 1} and u ≺ v ∈ U , there is at least one reconstruction of P with u and v as jth and (j + 1)th points, then we say that P admits at least one reconstruction from -consecutive points. If there is at most one reconstruction for every j ∈ {1, . . . , k − 1} and u ≺ v ∈ U , we say that P admits at most one reconstruction from -consecutive points. If both of these hold, then we say that P admits a unique reconstruction from -consecutive points, or is uniquely reconstructible from -consecutive points.

A General Upper Bound on S P (n)
Theorem 4.1. Let k > 1 and let P be a k-pattern in U that admits at most one reconstruction from -consecutive points. If n ∈ N and r is the remainder when n is divided by k − 1, then S P (n) ≤ (n − r)(n + r − k + 1)/(2k − 2).
Proof. Let V be an n-subset of U , and let V = {V 1 ≺ · · · ≺ V k−1 } be a -orderly, balanced (k − 1)-partition of V . By Lemma 2.1, each P ⊆ V with P ∈ P is of echelon j in V for some j ∈ {1, . . . , k −1}. Each subset of echelon j has its jth and (j +1)st elements in V j , and since no two instances of P may have the same jth and (j + 1)th points, this means that there are at most instances of P that are of echelon j. Thus there are at most k−1 j=0 |V j | 2 instances of P in V . If we write n = q(k − 1) + r, then our partition, being balanced, has |V j | = q + 1 for r values of j and The method of counting used in this proof provides a criterion for when this upper bound is achieved.
Lemma 4.2. Let k > 1 and let P be a k-pattern in U that admits at most one reconstruction from -consecutive points. Let n ∈ N and let r be the remainder when n is divided by k − 1. Let V be a n-subset of U withorderly, balanced (k − 1)-partition V = {V 1 , . . . , V k−1 }. Then S P (V ) = (n − r)(n + r − k + 1)/(2k − 2) if and only if for each j ∈ {1, . . . , k − 1} and every pair of distinct points v, w ∈ V j , there exists a reconstruction P of P with v and w as jth and (j + 1)th points, and P is a subset of V that is not of echelon i in V for any i = j.
Proof. Examining the proof of the preceding theorem, we see that if any of the reconstructions mentioned in the statement of this proposition did not exist, or did not lie in V , then |V j | 2 would be an overestimate of the number of instances of P that are of echelon j. And if any instance were of two distinct echelons in V, then we would be counting it twice in k−1 j=0 |V j | 2 , thus making our bound an overestimate.

General Patterns in the Line
In this section, our universe U is the line R, our equivalence relation ∼ is direct similarity, and our pattern P can be the equivalence class for any finite subset of R. Our order relation is the usual order relation ≤ for R. We note that any pattern P is uniquely reconstructible from ≤-consecutive points, so Theorem 4.1 applies, amounting to the following.
Theorem 5.1. Let k > 1 and let P be any k-pattern in R. If n ∈ N and r is the remainder when n is divided by k − 1, then S P (n) ≤ (n − r)(n + r − k + 1)/(2k − 2). This upper bound is tight in the sense that for each k > 1, when P is the pattern of k-term arithmetic progressions, then S P (n) equals the bound, as we shall now show.

Arithmetic Progressions in the Line
Here the universe U is the line R and our pattern is A k , the class of kterm arithmetic progressions. Because A k is invariant under reflection, the results are the same whether we make ∼ direct similarity or similarity. This enables an exact computation of S A k (n): we recall and prove Theorem 1.2.
Theorem 6.1. Let k > 1, and let A k be the pattern of k-term arithmetic progressions on R. If n ∈ N and r is the remainder when n is divided by Proof. This is an immediate consequence of Theorem 5.1 above and Lemma 6.2 below. Lemma 6.2. If k > 1 and n ∈ N with r the remainder when n is divided by Proof. For each positive integer s ≤ n/(k − 1), our set {0, 1, . . . , n − 1} contains precisely n − s(k − 1) arithmetic progressions having k points with distance s between consecutive points. The result follows by adding these quantities for 1 ≤ s ≤ n/(k − 1). Now that we know the precise value of S A k (n), we would like to completely classify the n-subsets V of R achieving S A k (V ) = S A k (n). We call such n-sets optimal for k-term arithmetic progressions. Lemma 6.2 above shows that n-term arithmetic progressions are always optimal for k-term arithmetic progressions, but in many cases there are other optimal sets, and we now classify them (up to similarity).
All sets are trivially optimal for 1-or 2-term arithmetic progressions, and any n-set with n < k is trivially optimal for k-term arithmetic progressions. The barycenter of an arithmetic progression is the arithmetic mean of its points. Two progressions are said to be concentric if they have the same barycenter, or nearly concentric if their barycenters differ by 1. Remark 6.4. Before we embark upon the proof, we pause to note that the set E ∪ O described here is an arithmetic progression when |E| and |O| are either equal, or one differs from the other by 1.
Proof of Proposition 6.3: In view of the value of S A 3 (n) from Theorem 6.1, we may use Lemma 4.2 as the criterion for optimality. Suppose that V is an n-subset of R and V = {V 1 < V 2 } is a ≤-orderly, balanced 2-partition of V . Because arithmetic progressions are uniquely reconstructible from consecutive points, and since no 3-term progression may be both of echelon 1 and of echelon 2 (since that would require it to have more than three points), Lemma 4.2 shows that V is optimal for 3-term arithmetic progressions if and only if for every j ∈ {1, 2} and every pair of distinct v, w ∈ V j , the reconstruction of A 3 with v and w as jth and (j + 1)th points is contained in V .
First, suppose V has the form E ∪ O as described in the statement of this proposition. If |E| and |O| are equal or differ by 1, then V is itself an arithmetic progression, and hence optimal by Lemma 6.2, so we may assume that |E| = |O|. We may then view V as X ∪ Y , where X is the larger of E and O, while Y contains the smaller of E and O, along with any points from the larger of E and O that lie between the points of the smaller of E and O. Thus X is an arithmetic progression with distance 2 between its consecutive points, while Y is an arithmetic progression with distance 1 between its consecutive points. We let respectively. Now suppose that v 1 < v 2 are points in V 1 , and let v 3 be the point that makes v 1 < v 2 < v 3 a 3-term arithmetic progression. If v 1 and v 2 are both in X 1 (resp., Y 1 ), then since X (resp., Y ) is an arithmetic progression, and hence optimal for 3-term arithmetic progressions, we may apply Lemma 4.2 to conclude that v 3 ∈ X (resp., Y ), and hence v 3 ∈ V . In the remaining case, where v 1 ∈ X 1 and v 2 ∈ Y 1 , we note that v 3 cannot be larger than the largest point in V and has the same parity as v 1 , hence v 3 ∈ X ⊆ V . By the same argument, if v 2 < v 3 are two points in V 2 , then the point v 1 that makes v 1 < v 2 < v 3 a 3-point arithmetic progression is always in V . Thus our set V satisfies the sufficient criteria of Lemma 4.2 for optimality. Now suppose that V is an n-subset of R that is optimal for 3-term arithmetic progressions. We want to show that V has the form described in the statement of this proposition. First we deal with the case where n is odd, and without loss of generality, we may apply a similarity transformation so that the middle point of V is 0, and the next point in V is 1. We let V = {V 1 < V 2 } be an ≤-orderly, balanced 2-partition of V with the negative points in V 1 , and the nonnegative points in V 2 . By Lemma 4.2, for every positive v 2 ∈ V 2 , the 3-term arithmetic progression −v 2 < 0 < v 2 must lie in V , so the point −v 2 must lie in V 1 . Thus V has reflection symmetry about 0.
If u < v < w are consecutive points in V 2 , then by Lemma 4.2, the 3term progression 2v − w < v < w must lie in V , and so 2v − w ≤ u, that So the spacings between consecutive points of V 2 are nondecreasing as we proceed to the right.
If 1 ≤ u < v are consecutive points in V 2 , then by Lemma 4.2, the 3-term progression 2 − v < 1 < v lies in V , so that v − 2 lies in V by reflection symmetry, and so u ≥ v − 2. So the spacing between any two consecutive points of V 2 is no greater than 2.
We also claim that all the points of V 2 are integers: we proceed by induction. The first two elements of V 2 are 0 and 1, so suppose that v ∈ V 2 with v > 1, and we know that all elements of V 2 less than v are integers. By Lemma 4.2, the arithmetic progression 2 − v < 1 < v lies in V , so that |v − 2| lies in V by reflection symmetry, so |v − 2| must be an element of V 2 less than v, hence an integer. So v is an integer.
Thus spacings between any consecutive points of V 2 is always 1 or 2, and these spacings are nondecreasing as we proceed to the right. Since V has reflection symmetry about 0, we know that V has the form described in this proposition. This completes the proof when n is odd. Now suppose that n is even and V is an n-subset of R optimal for 3term arithmetic progressions. Then the technical Lemma 6.6, whose proof is delayed to the end of this section, shows that an (n − 1)-set V ′ obtained from V by removing either the leftmost or rightmost point is optimal for 3-term arithmetic progression. By applying similarity transformations, we may assume that the rightmost point r is removed and that V ′ has the form described in the statement of this proposition, with 0 being the middle point of V ′ . Then V ′ contains the point 1 since the set of odd points in V ′ is nonempty and centered at 0. Let r ′ be the rightmost point of V ′ . A ≤orderly, balanced 2-partition V = {V 1 < V 2 } of V places all the nonpositive points into V 1 and all the positive points into V 2 .
In view of Lemma 4.2, the 3-term progression 2 − r < 1 < r lies in V , so 2 − r ∈ V ′ . Thus r must be an integer, and by reflection symmetry in V ′ , we must have r − 2 ≤ r ′ , that is r ∈ {r ′ + 1, r ′ + 2}. It is immediate that V ′ ∪ {r ′ + 2} is of the form described in the proposition, so we are done if r = r ′ + 2. If r = r ′ + 1, then by Lemma 4.2, the 3-term progression r ′ − 1 < r ′ < r is contained in V , so then V ′ must consist of all consecutive integers from −r ′ to r ′ , and then it is clear that V = V ′ ∪ {r} is of the form described in the proposition. Proposition 6.5. For n ≥ k ≥ 4, an n-subset V of R is optimal for k-term arithmetic progressions if and only if, up to similarity, V is an arithmetic progression or k − 1 divides n and V is an arithmetic progression with the second point deleted.
Proof. We first analyze all optimal sets V for four-term arithmetic progressions. Suppose that V is such an n-subset of R and n ≥ 4. Let V = {V 1 < V 2 < V 3 } with |V 2 | ≥ 2 be an ≤-orderly, balanced 3-partition of V . Lemma 6.7 below shows that if we remove V 3 from V , then we are left with an optimal set for three-term arithmetic progressions. Since V 1 ∪ V 2 is optimal for three-term arithmetic progressions, Proposition 6.3 tells us that without loss of generality, we may take V 1 ∪ V 2 to be the union of a set E of consecutive even integers and a set O of consecutive odd integers, which either have a common center c (if |E ∪ O| is odd) or E and O have distinct centers d and d + 1 in some order.
We now prove that the distance between the leftmost two points of V 2 is 1. Since V 1 ∪ V 2 = E ∪ O and E and O are nonempty, V 1 ∪ V 2 contains a set of three consecutive integers. The integers are c − 1, c, c + 1 if |E ∪ O| is odd or one of d − 1, d, d + 1 or d, d + 1, d + 2 if |E ∪ O| is even. Then the three consecutive points are either the two rightmost of V 1 and the one leftmost of V 2 or the one rightmost of V 1 and the two leftmost of V 2 . The first case implies the second one, since if the rightmost two points of V 1 have a spacing 1, then the leftmost two points of V 2 will complete a four-term arithmetic progression with the former two points. So we know that distance between the leftmost two points of V 2 is 1.
By Lemma 6.7, the union of V 2 and V 3 is optimal for three-term arithmetic progressions. Now since the leftmost two points of V 2 ∪V 3 are at distance 1, it follows from Proposition 6.3 that V 2 ∪ V 3 is either an arithmetic progression, or an arithmetic progression with the second-to-last point removed. Similarly, V 1 ∪ V 2 is either an arithmetic progression or an arithmetic progression with the second point removed. By Lemma 6.8, V is either an arithmetic progression or else an arithmetic progression with either the second point or the second-to-last point (but not both) removed, and these latter two cases can only occur if 3 | n. Conversely, Lemma 6.8 shows that sets V with these forms really are optimal for four-term arithmetic progressions. Now we analyze all optimal sets for k-term arithmetic progressions where k ≥ 5. For n ≥ k, let V = {V 1 < V 2 < . . . < V k−1 } be an ≤-orderly, balanced (k − 1)-partition of a n-subset V of R, where we insist |V 2 | ≥ 2. Then V ′ = V 1 ∪ . . . ∪ V k−2 and V ′′ = V 2 ∪ . . . ∪ V k−1 are optimal for (k − 1)-term arithmetic progressions by Lemma 6.7. Hence, without loss of generality V ′ is either an arithmetic progression of consecutive integers, or what one obtains by removing either the second or second-to-last point (but not both) from such an arithmetic progression. If the rightmost two points of V k−2 had spacing 2, then V ′′ would begin with two points at spacing 1, then later would have a spacing of 2 between consecutive points, neither of which would be endpoints, and this would contradict the optimality of V ′′ for (k−1)-term arithmetic progressions. So any spacing of 2 between consecutive points in V ′ must be between the leftmost two points. And by a similar argument with V ′′ , we see that all consecutive points of V ′′ have spacing 1, except possibly the two rightmost, which can have spacing 2. Thus all consecutive points of V must have spacing 1, except for possible spacings of 2 between the leftmost pair and the rightmost pair. By Lemma 6.8, V is either an arithmetic progression or else an arithmetic progression with either the second point or the second-to-last point (but not both) removed, and these latter two cases can only occur if k − 1 | n). Conversely, Lemma 6.8 shows that sets V with these forms really are optimal for k-term arithmetic progressions.
We close with the technical lemmata use to prove the two propositions above.
Lemma 6.6. Let V be a n-subset of R that is optimal for 3-term arithmetic progressions. Then either the (n − 1)-set obtained by removing the leftmost point of V or the (n − 1)-set obtained by removing the rightmost point of V is optimal for 3-term arithmetic progressions.
Suppose that the leftmost point ℓ of V is such that there is no 3-term progression ℓ < u < v with u, v ∈ V 2 . Then let V ′ = V {ℓ} with ≤-orderly, balanced 2-partition V ′ = {V 1 {ℓ}, V 2 }, and we see that any pair of points in V 1 {ℓ} (resp., V 2 ) are the leftmost (resp., rightmost) two points of a 3-term progression in V ′ , so V ′ is optimal by Lemma 4.2.
Now suppose that the leftmost point ℓ of V is such that ℓ < m < r is a 3-term progression with m, r ∈ V 2 . Then m and r must respectively be the leftmost and rightmost points of V 2 , for otherwise Lemma 4.2 would dictate that the leftmost and rightmost points of V 2 would be a part of a 3-term progression in V , and that progression would need to involve a point to the left of ℓ, which is absurd.
We set V ′ = V {r}, and claim that it is optimal for 3-term arithmetic progressions. For any u < v ∈ V 1 , we claim that the point w that makes u < v < w a 3-term arithmetic progression is in V ′ . For by Lemma 4.2, w ∈ V , and w = 2v − u, with v < m and u ≥ ℓ, so that w < 2m − ℓ = r (since ℓ < m < r is an arithmetic progression).
If n is even, then set V ′ = {V 1 , V 2 {r}}, which is a ≤-orderly, balanced 2-partition of V ′ , and we see that any pair of points in V 1 (resp., V 2 {r}) are the leftmost (resp., rightmost) two points of a 3-term progression in V ′ , so V ′ is optimal by Lemma 4.2.
If n is odd, let y be the rightmost point of V 1 , and set W = which is a ≤-orderly, balanced 2-partition of V ′ = V {r}. By Lemma 4.2, any pair v < w of points in W 2 form the rightmost two points of a 3-term arithmetic progression in V , so any pair v < w of points in W 2 {r} for the rightmost two points of a 3-term arithmetic progression in V ′ . By the paragraph before the previous one, we know that every pair of points in W 1 = V 1 {y} form the leftmost two points of a 3-term arithmetic progression in V ′ . Thus Lemma 4.2 shows that V ′ is optimal for 3-term arithmetic progressions. Lemma 6.7. If V is a finite subset of R that is optimal for k-term arithmetic progressions, and V = {V 1 < · · · < V k−1 } is a ≤-orderly, balanced (k − 1)partition of V , then both ∪ k−2 j=1 V j and ∪ k−1 j=2 V j are optimal for (k − 1)-term arithmetic progressions. By Lemma 4.2, for a pair of points p and q in the subset V j of V ′ , there is a k-term arithmetic progression P in V that contains these points and is only of echelon i in V for i = j. Note that P ′ = P (P ∩ V k−1 ) is an arithmetic progression of some length that of echelon j in V ′ . If P ′ has fewer than k − 1 points, then it must be true that more than one point of P is in V k−1 , which implies that P is both of echelon k − 1 and echelon j in V, contradicting Lemma 4.2. Hence P ′ is an arithmetic progression of at least k − 1 terms contained in V ′ . By Lemma 4.2, V ′ is optimal for k − 1-term arithmetic progressions. By the same reasoning, ∪ k−1 j=2 V j is also optimal for (k − 1)-term arithmetic progressions. Lemma 6.8. Let n ≥ k ≥ 4. Let V be an n-subset of R that is either an arithmetic progression, or else an arithmetic progression with the second point p or the second-to-last point q (or both) removed. Then V is optimal for k-term arithmetic progressions if and only if (i) V is an arithmetic progression or (ii) k − 1 divides n and V is an arithmetic progression with only one of p or q removed.
Proof. We can assume, without loss of generality, that V ⊆ Z, that the first element of V is 0, and the smallest spacing between any two consecutive integers is 1. Write n = (k − 1)q + r with 0 ≤ r < k − 1.
We already know from Theorem 6.1 and Lemma 6.2 that if V is an arithmetic progression, then it is optimal for k-term arithmetic progressions. Now we assume that V is obtained from an arithmetic progression by removing only the second point, so that V = {0, 2, 3, . . . , n}. Assume V is optimal for k-term arithmetic progressions.
On the other hand, if r = 0, then it is not difficult to use Lemma 4.2 to show that V = {0, 2, 3, . . . , (k − 1)q} is in fact optimal for k-term arithmetic progressions. By symmetry, we have also covered the cases where V is obtained from an arithmetic progression by only removing the second-tolast point. Now we assume that v is obtained from an arithmetic progression by removing both the second point and the second-to-last point, so that V = {0, 2, 3, . . . , n − 2, n − 1, n + 1}. Assume V is optimal for k-term arithmetic progressions. Recall that we are writing n = (k − 1)q + r with 0 ≤ r < k − 1.

Commensurable Patterns in the Line
Here the universe U is the line R, and our equivalence relation ∼ is direct similarity. A commensurable pattern P in R is one such that for P ∈ P, all the distances between pairs in P are commensurable, that is, are related by rational ratios. Equivalently, P is commensurable if it contains some P ⊆ Z. Or yet again, P is commensurable if its instances are subsets of arithmetic progressions. Indeed if P ∈ P, there is a unique arithmetic progression A of minimum cardinality such that P ⊆ A. We call this A the enveloping arithmetic progression for P , and of course the set of all enveloping arithmetic progressions of elements of P is itself a pattern, called the enveloping pattern for P. For a positive ℓ, we let A ℓ be the pattern consisting of ℓ-term arithmetic progressions Theorem 7.1. Let P be a commensurable k-pattern on R, and suppose that A ℓ is the enveloping pattern for P. If n ∈ N and r and s are respectively the remainders when n is divided by k − 1 and ℓ − 1, then Proof. The right side of the inequality follows directly from Lemma 4.2, which gives an upper bound on the maximum number of instances of a k-pattern P in an n-subset of R. Now let A = {p, . . . , q} and A ′ = {p ′ , . . . , q ′ } be distinct l-term arithmetic progressions in R. Then they are enveloping arithmetic progressions for distinct instances of the commensurable pattern P: P = {p, . . . , q} and P ′ = {p ′ , . . . , q ′ }. We see that in a given set, there are at least as many instances of P as there are l-term arithmetic progressions, so that S A ℓ (n) = (n − s)(n + s − ℓ + 1)/(2ℓ − 2) ≤ S P (n).
We now construct a family of sets V n where each V n is a set with n points containing S P (V n ) = (3n 2 − 8n)/16 directly similar copies of {0, 1, 3}. This makes lim n→∞ S P (V n )/n 2 = 3/16, which is strictly between the two limits we computed in the previous paragraph using the lower and upper bounds on S P (V n ) furnished by Theorem 7.1. We now describe our construction V n , and then prove our claim that S P (V n ) = (3n 2 − 8n)/16. Construction 7.2. If n = 96k for any positive integer k, we let V n be the union of the following four sets: Proposition 7.3. If P is the pattern containing {0, 1, 3}, and V n is the n-point set V n described in Construction 7.2, then S P (V n ) = (3n 2 − 8n)/16.
To compute the number of instances {p 1 < p 2 < p 3 } of P in V n with (p 1 , p 2 , p 3 ) ≡ (a, b, c) (mod 6) for a given triple (a, b, c), one counts lattice points in regions of Z 2 defined by a system of inequalities. For example, if n = 96k and (a, b, c) = (0, 5, 3), we could represent each instance {p 1 < p 2 < p 3 } of P with

14ÁBREGO, FERNÁNDEZ-MERCHANT, KATZ, AND KOLESNIKOV
The first inequality makes sure that p 1 < p 2 , and the remaining three inequalities make sure that p 1 , p 2 , and p 3 are in the ranges prescribed for their respective congruence classes, as described in Construction 7.2.
In this way we calculate the following number of instances {p 1 < p 2 < p 3 } of P in V n : 54k 2 − 3k instances with (p 1 , p 2 , p 3 ) ≡ (0, 0, 0) (mod 6), If we add up all the counts, we get 1728k 2 −48k, or equivalently (3n 2 −8n)/16 for the the total number of instances of P in V n .

Equilateral Triangles in the Plane
In this section we explore S E (n), where U is the Euclidean plane (identified with C), V is a finite subset, and E is the pattern of vertices of an equilateral triangle. Our order relation on C is lexicographic ordering: y ≺ z means that either (i) Re(y) < Re(z) or (ii) Re(y) = Re(z) and Im(y) < Im(z). This order relation respects addition, so if y ≺ y ′ and z z ′ , then y + z ≺ y ′ + z ′ .
If u and v are distinct points in C, they are vertices of only two equilateral triangles, and if we let w and w ′ be the respective third vertices of these two triangles, then u, w, v, and w ′ are vertices of a parallelogram with u + v = w + w ′ . Then the compatibility of our order relation with addition shows that E admits at most one reconstruction from any pair of consecutive points, for neither u, v ≺ w, w ′ nor u, v ≻ w, w ′ is consistent with u + v = w + w ′ .
Since E admits at most one reconstruction from any pair of consecutive points, Theorem 4.1 immediately tells us that S E (n) ≤ n(n − 2)/4 if n is even and S E (n) ≤ (n − 1) 2 /4 if n is odd, that is, S E (n) ≤ ⌊(n − 1) 2 /4⌋ in any case. This observation recovers upper bound on S E (n) of [2, Theorem 1] (given here in (1)), which was previously obtained using a much more sophisticated geometric proof.
We shall get an improved upper bound on S E (n) by noting that sometimes E admits no reconstruction from a pair of consecutive points. To see this, we define the usual principal value of the argument function Arg : C * → (−π, π]. Proof. Let ζ 6 = e πi/3 . Then u and v are vertices of only two equilateral triangles, with the third point being either (i) w = ζ 6 u + ζ 6 v or (ii) w ′ = ζ 6 u + ζ 6 v.
Note that u, v ≺ w requires Re(w) ≥ Re(u) (with Im(w) > Re(u) in case of equality) and Re(w) ≥ Re(v) (with Im(w) > Im(v) in case of equality). Since ζ 6 + ζ 6 = 1, this is equivalent to Re(ζ 6 (v − u)) ≥ 0 and Re(−ζ 6 (v − u)) ≥ 0, with the corresponding imaginary parts strictly positive in cases of equality. These conditions are fulfilled if and only if Arg(v−u) ∈ (π/6, 5π/6]. One can similarly show that u, v ≻ w ′ under the same conditions, and that u, v ≺ w ′ if and only if Arg(v − u) ∈ (−5π/6, −π/6], with u, v ≻ w under the same conditions. Let A = (−5π/6, −π/6] ∪ (π/6, 5π/6], the set of values of Arg(v − u) that admit a reconstruction of E with u and v as consecutive points. To get a good upper bound for S E (V ) in an n-set V , we rotate V in such a way that the first ⌈n/2⌉ points of V (with respect to ordering ) have many pairs (u, v) of points with Arg(v − u) ∈ A, and the last ⌊n/2⌋ points of V have many pairs (u, v) of points with Arg(u − v) ∈ A. This requires some care, for as we rotate, points change from being among the first ⌈n/2⌉ to the last ⌊n/2⌋.
We define a direction ζ to be complex number of unit modulus, so the set of directions is the complex unit circle. A directed line with direction ζ is line with parameterization t → ζt + η for some η ∈ C, where the parameter t ranges over R. Every directed line with direction ζ may be uniquely written as L(t) = ζt + s(−iζ), where s is a scalar uniquely determined by the line L; we call this the canonical form of the directed line L. Note that |s| is the distance from L to the origin, and the sign of s tells us which side of L the origin lies on. We may thus identify the set of directed lines with the Cartesian product of the unit circle (for ζ) and the real line (for s), and give the directed lines the topology of this product space.
For each direction ζ, we define a total ordering relation ζ on C with y ζ z if and only if iζy ≺ iζz. Note that i is the same as , and for any direction ζ, we have y −ζ z if and only if y ζ z. If L(t) is a directed line with direction ζ, then we say z ∈ C lies to the left (resp., to the right) of L(t) if z ≺ ζ L(t) for all t ∈ R (resp., z ≻ ζ L(t) for all t ∈ R). If y, z ∈ C are on the line L(t), say y = L(t y ) and z = L(t z ), then we say that y is below (resp., above) z on L if t y < t z (resp., t y > t z ). Note that these concepts of left and right, below and above, all correspond to the usual notions when L(t) = it is the positively directed y-axis, or indeed if L is any translate thereof.
If ζ is a direction and V = {v 1 ≺ ζ · · · ≺ ζ v n } is a finite set, then the ζ-median of V is v (n+1)/2 if n is odd, and is v n/2 +v n/2+1 2 if n is even. If ζ is a direction and V is a finite set of points, then the ζ-halving line of V is the directed line L V,ζ with direction ζ that passes through the ζ-median of V . The line is called a halving line because ⌊n/2⌋ of the points of V are (with respect to ζ ) less than the median, and so lie to the left of the line or below the ζ-median of V on the directed line, while ⌊n/2⌋ of the points of V are greater than the median, and so lie to the right of the line or above the median on the directed line. Our definition of halving line makes a unique halving line for V in each direction, and is identical to the definition used by Erickson, Hurtado, and Morin [21]. If c is the ζ-median of V , we call any point z with z ζ c formally to the left of L V,ζ and any point z with z ≻ ζ c formally to the right of L V,ζ . Thus ⌈n/2⌉ of the points of V lie formally to the left of L V,ζ and ⌊n/2⌋ of the points of V lie formally to the right of L V,ζ .
With the topology for the space of directed lines introduced above, we claim that L V,ζ is continuous in ζ. Indeed, L V,ζ evolves by rotating about a particular median for a segment of values of ζ, changing from median v to w precisely for the value of ζ that makes v and w both lie on the line L V,ζ . Note that the ζ-median and the (−ζ)-median of V are the same, so that L V,ζ and L V,−ζ are the same line, but with opposite directions. These considerations lead to the following useful observation, first proved in this precise form in [21,Lemma 3] (see also [22,Lemma 2] and [14, Lemma 2]). Lemma 8.2. Let V be a finite subset of C. Then there is some direction ζ such that the halving lines of V in directions ζ, e 2πi/3 ζ, and e 4πi/3 ζ are concurrent.
Proof. Let ω = e 2πi/3 . If the point L V,ω ∩ L V,ω 2 is on or to the left (resp., right) of the directed line L V,1 , then the same point L V,−ω ∩ L V,−ω 2 must be on or to the right (resp., left) of the same but oppositely directed line L V,−1 . As ζ traverses the unit circle, the lines L V,ζ , L V,ωζ , and L V,ω 2 ζ evolve continuously, and so the intersection point L V,ωζ ∩L V,ω 2 ζ also evolves continuously. Thus there must be some ζ such that L V,ωζ ∩ L V,ω 2 ζ crosses L V,ζ . Now we are ready to recall and prove our improved bound (Theorem 1.1) on S E (n). Theorem 8.3. If E is the pattern of the vertices of equilateral triangles in R 2 , then S E (n) ≤ ⌊(4n − 1)(n − 1)/18⌋. Proof. Let V be an n-subset of R 2 (identified with C). Obtain three concurrent halving lines of V , say L, M , and N , as described in Lemma 8.2, where the directions of M and N are obtained from that of L by rotating by 2π/3 and 4π/3, respectively. This means that a point can only be formally left (or formally right) of all three lines if it lies on all three. So we may partition V into six or seven classes of points, where a point is classified according to its position (formally left or right) relative to the three lines. formally right formally right formally left V 7 on on on (if this point is not in V 1 ∪ · · · ∪ V 6 ) Note that V 7 is nonempty if and only if a point of V happens to lie on the intersection of the three lines and if said point happens to be formally left of all three lines or formally right of all three lines.
Let A = (−5π/6, −π/6] ∪ (π/6, 5π/6], the set of values of Arg(v − u) that (by Lemma 8.1) admit a reconstruction of E with u and v as consecutive points. We can rotate V and the directed lines L, M , and N so that one of them (without loss of generality, L), is the positively directed y-axis, and so that at least one-third of the pairs (u, v) of points in 6 j=1 V j × V j have Arg(v − u) ∈ A. Every instance {v 1 ≺ v 2 ≺ v 3 } of E in V either has v 1 and v 2 formally to the left of L or has v 2 and v 3 formally to the right of L. Furthermore, Lemma 8.1 shows that in the former case Arg(v 2 −v 1 ) ∈ A and v 3 is uniquely determined by v 1 and v 2 , while in the latter case Arg(v 3 −v 2 ) ∈ A and v 1 is uniquely determined by v 2 and v 3 . Since L is a halving line, there are ⌈n/2⌉ points formally to the left of L and ⌊n/2⌋ points formally to the right of L. So we count the number of pairs (u, v) in V with u and v formally to the same side of L, and deduct the number of pairs that we deliberately rotated to prevent them from admitting a reconstruction of E to obtain Now 6 j=1 |V j | is either n or n−1 (depending on whether V 7 is empty or not), and by convexity, the sum of binomial coefficients in (3) is minimized when the various values |V j | are as close to equal as possible. So if n−1 = 6q+2r+s