Generalizations of the Ruzsa-Szemer\'edi and rainbow Tur\'an problems for cliques

Considering a natural generalization of the Ruzsa-Szemer\'edi problem, we prove that for any fixed positive integers $r,s$ with $r<s$, there are graphs on $n$ vertices containing $n^{r}e^{-O(\sqrt{\log{n}})}=n^{r-o(1)}$ copies of $K_s$ such that any $K_r$ is contained in at most one $K_s$. We also give bounds for the generalized rainbow Tur\'an problem $\operatorname{ex}(n, H,$rainbow-$F)$ when $F$ is complete. In particular, we answer a question of Gerbner, M\'esz\'aros, Methuku and Palmer, showing that there are properly edge-coloured graphs on $n$ vertices with $n^{r-1-o(1)}$ copies of $K_r$ such that no $K_r$ is rainbow.


Introduction
The famous Ruzsa-Szemerédi or (6, 3)-problem is to determine how many edges there can be in a 3-uniform hypergraph on n vertices if no six vertices span three or more edges. This rather specific-sounding problem turns out to have several equivalent formulations and bounds in both directions have had many applications. It is not difficult to prove an upper bound of O(n 2 ): one first observes that if two edges have two vertices in common, then neither of them can intersect any other edges, and after removing all such pairs of edges one is left with a linear hypergraph, for which the bound is trivial. Brown, Erdős and Sós [13] gave a construction achieving Ω(n 3/2 ) edges and asked whether the maximum is o(n 2 ).
The argument sketched in the previous paragraph shows that this question is equivalent to asking whether a graph on n vertices such that no edge is contained in more than one triangle must contain o(n 2 ) triangles. A positive answer to this question was given by Ruzsa and Szemerédi [12], who obtained a bound of O(n 2 / log * n) with the help of Szemerédi's regularity lemma. They also gave a construction showing that the number of triangles can be as large as n 2 e −O( √ log n) = n 2−o (1) , so the exponent in their upper bound cannot be improved.
One of the applications they gave of their upper bound was an alternative proof of Roth's theorem. Indeed, let A be a subset of {1, . . . , N } that contains no arithmetic progression of length 3. Define a tripartite graph G with vertex classes X = {1, 2, . . . , N }, Y = {1, 2, . . . , 2N } and Z = {1, 2, . . . , 3N }, where if x ∈ X, y ∈ Y and z ∈ Z, then xy is an edge if and only if y − x ∈ A, yz is an edge if and only if z − y ∈ A and xz is an edge if and only if (z − x)/2 ∈ A. Note that these are the edges of the triangles with vertices belonging to triples of the form (x, x + a, x + 2a) with x ∈ X and a ∈ A. If xyz is a triangle in this graph, then a = y − x, b = z − y, c = (z − x)/2 satisfy a, b, c ∈ A and a + b = 2c, which gives us an arithmetic progression of length 3 in A unless y − x = z − y. Thus, the only triangles are the 'degenerate' ones of the form (x, x + a, x + 2a), which implies that each edge is contained in at most one triangle. Therefore, the number of triangles is o(n 2 ) (where n = 6N ). We also have that for each a ∈ A there are N triangles of the form (x, x + a, x + 2a), so |A| = o(N ).
As Ruzsa and Szemerédi also observed, this argument can be turned round: it tells us that if A has density α, then there is a graph with 6N vertices and αN 2 triangles such that each edge is contained in at most one triangle. Since Behrend proved [6] that there exists a subset A of {1, . . . , N } of size N e −O( √ log N ) that does not contain an arithmetic progression of length 3, this gives the lower bound mentioned above.
Several related questions have been studied, as well as applications and generalizations of the Ruzsa-Szemerédi problem: see for example [4,2]. A natural generalization that we believe has not been considered is the following generalized Turán problem. Question 1.1. Let r and s be positive integers with 1 ≤ r < s. Let G be a graph on n vertices such that any of its subgraphs isomorphic to K r is contained in at most one subgraph isomorphic to K s . What is the largest number of copies of K s that G can contain?
The Ruzsa-Szemerédi problem is the case r = 2, s = 3 of Question 1.1, and the answer is trivially Θ(n) if r = 1. One can easily deduce from the graph removal lemma an upper bound of o(n r ) when r ≥ 2. In the case r = 2, the construction for the lower bound can be generalized (for example, by using h-sum-free sets from [3]) to get a lower bound of n 2 e −O( √ log n) . However, there is no obvious way of generalizing the algebraic construction for r ≥ 3. We shall present a geometric construction instead, in order to prove the following result, which is the first of the two main results of this paper. Theorem 1.2. For each 1 ≤ r < s and positive integer n there is a graph on n vertices with n r e −O( √ log n) = n r−o(1) copies of K s such that every K r is contained in at most one K s .
We shall also use a modification of our construction to answer a question about rainbow colourings. Given an edge-colouring of a graph G, we say that a subgraph H is rainbow if all of its edges have different colours. We denote by ex * (n, H) the maximal number of edges that a graph on n vertices can contain if it can be properly edge-coloured (that is, no two edges of the same colour meet at a vertex) in such a way that it contains no rainbow copy of H. The rainbow Turán problem (i.e., the problem of estimating ex * (n, H)) was introduced by Keevash, Mubayi, Sudakov and Verstraëte [11], and was studied for several different families of graphs H, such as complete bipartite graphs [11], even cycles [11,7] and paths [10,8]. Gerbner, Mészáros, Methuku and Palmer [9] considered the following generalized rainbow Turán problem (analogous to a generalization of the usual Turán problem introduced by Alon and Shikhelman [5]). Given two graphs H and F , let ex(n, H, rainbow-F ) denote the maximal number of copies of H that a properly edge-coloured graph on n vertices can contain if it has no rainbow copy of F . Note that ex * (n, H) is the special case ex(n, K 2 , rainbow-H). The authors of [9] focused on the case H = F and obtained several results, for example when H is a path, cycle or a tree, and also gave some general bounds. One of their concluding questions was the following. Question 1.3 (Gerbner, Mészáros, Methuku and Palmer [9]). What is the order of magnitude of ex(n, K r , rainbow-K r ) for r ≥ 4?
For fixed r, a straightforward double-counting argument shows that if H has r vertices, then ex(n, H, rainbow-H) = O(n r−1 ). Indeed, if G is a graph with n vertices that contains no rainbow copy of H, then every copy of H contains two edges of the same colour. But the number of such pairs of edges is at most n 2 n−2 2 = O(n 3 ), since there are at most n−2 2 edges with the same colour as any given edge, and each such pair can be extended to at most r!n r−4 copies of H.
The authors above improved this bound to o(n r−1 ), and gave an example that shows that ex(n, K r , rainbow-K r ) = Ω(n r−2 ). They also asked whether there is a graph H for which the exponent r − 1 in the upper bound is sharp. Our next result shows that H = K r is such a graph.
Note that a triangle is always rainbow in a proper edge-colouring, so we trivially have ex(n, K r , rainbow-K r ) = 0 for r < 4.
In fact, our method can be used to prove the following more general result. Theorem 1.5. Let r ≥ 4, let H be a graph, and let H have a proper edge-colouring with no rainbow K r . Suppose that for each vertex v of H there is a p v ∈ R m , and for each colour κ in the colouring there is a non-zero vector z κ such that for every edge vw of colour κ, z κ is a linear combination of p v and p w with non-zero coefficients. Then ex(n, H, rainbow-K r ) ≥ n m 0 −o (1) , where m 0 is the dimension of the subspace of R m spanned by the points p v .
It is easy to see that Theorem 1.4 is a special case of Theorem 1.5, but Theorem 1.5 also allows us to determine the behaviour of ex(n, H, rainbow-K r ) for several other natural choices of H. We give some examples in Section 5. Theorem 1.5 is 'almost equivalent' to the following, slightly weakened, alternative version.
Theorem 1.5 . Let r ≥ 4, let H be a graph, and let c be a proper edge-colouring of H without a rainbow K r . Suppose that for each vertex v ∈ V (H) we have a vector p v ∈ R m−1 , and for each colour κ of c the lines through the pairs p v , p w with c(vw) = κ are either all parallel, or all go through the same point and that point is different from p v , p w unless p v = p w . Assume that no (m − 2)-dimensional affine subspace contains all the points p v . Then ex(n, H, rainbow-K r ) ≥ n m−o (1) .
It is easy to see that Theorem 1.5 is equivalent to the weakened version of Theorem 1.5 where we make the additional assumption that each p v is non-zero. Indeed, given a configuration of points p v as in Theorem 1.5 (with m = m 0 ), we can project it from the origin to an appropriate affine (m − 1)-dimensional subspace not going through the origin to get a configuration as in Theorem 1.5 . Conversely, a configuration of points p v as in Theorem 1.5 gives a configuration as in Theorem 1.5 by taking the points p v × {1} ∈ R m .

The idea of the construction, and a preliminary lemma
We now briefly describe the construction used in our proof of Theorem 1.2. For simplicity, we focus on the case r = 2, s = 3, i.e., the Ruzsa-Szemerédi problem.
Consider the d-dimensional sphere S d = {x ∈ R d+1 : x = 1}. (We will choose d to be about √ log n.) Join two points of the sphere by an edge if the angle between the corresponding vectors is between 2π/3 − δ and 2π/3 + δ, where δ is some appropriately chosen small number (roughly e − √ log n ). Then there are 'few' triangles containing any given edge, since if xy is an edge then any point z such that xyz is a triangle is restricted to lie in a small neighbourhood around the point −(x + y). However, there are 'many' edges, since the edge-neighbourhood of a point is a set of points around a codimension-1 surface, which is much larger then the neighbourhood of a single point. Choosing the constants appropriately, we can achieve that if we pick n random points then any two of them form an edge with probability n −o (1) , and any three of them form a triangle with probability n −1−o (1) . Then any edge is expected to be in n −o(1) triangles and there are n 2−o(1) edges. After some modification, we get a graph with n 2−o(1) triangles in which any edge extends to at most one triangle.
The general construction is quite similar. We want to define the edges in such a way that knowing the position of any r of the vertices of a K s restricts the remaining s − r vertices to small neighbourhoods around certain points, but knowing the position of i points with i < r only restricts the remaining points to a neighbourhood of a codimension-i surface. For example, when (r, s) = (3, 4), we can define our graph by joining two points if the angle between the corresponding vectors is close to the angle given by two vertices of a regular tetrahedron (centred at the origin).
In fact, our construction and the construction of Ruzsa and Szemerédi based on the Behrend set are more similar than they might at first appear, which also explains why they give similar bounds (namely n 2 e −O( √ log n) for the case r = 2, s = 3). Behrend's construction [6] of a large set with no arithmetic progression of length 3 starts by observing that for any positive integers k, d there is some m such that the grid {1, . . . , k} d intersects the sphere {x ∈ R d : x 2 = m} in a set A consisting of at least k d /(dk 2 ) points. This set A has no arithmetic progression of length 3. (In Behrend's construction, this is transformed into a subset of Z using an appropriate map, but this is unnecessary for our purposes.) Repeating the construction from Section 1, we define a tripartite . . , 3k} d , and edges given by the edges of the triangles ( Explicitly, for x ∈ X, y ∈ Y, z ∈ Z, we join x and y if x − y = m 1/2 (and y i ≥ x i for all i), we join y and z if z − y = m 1/2 (and z i ≥ y i ), and we join x and z if x − z = 2m 1/2 (and z i ≥ x i ). This gives the same phenomenon as our construction: the neighbourhood of a point x is given by a codimension-1 condition, but the joint neighbourhood of two points is a single point, since y must be the midpoint of x and z.
We conclude this section with the following technical fact, whose proof we include for completeness. Given unit vectors v, w, we write ∠(v, w) for the angle between v and w -that is, for cos −1 ( v, w ). Lemma 2.1. There exist constants 0 < α < B such that the following holds. Let d be a positive integer, let 0 < ρ ≤ 2 and let v ∈ S d . Let X ρ = {w ∈ S d : v − w < ρ}. Let µ denote the usual probability measure on S d . Then Furthermore, for any −1 < ξ < 1 there exists β > 0 such that for every positive integer d, every Proof. Using the usual spherical coordinate system, we see that for 0 (1) But we have θ ≥ sin θ ≥ 2 π θ for 0 ≤ θ ≤ π/2. Thus, t 0 sin d−1 θ dθ is between d t d and 1 d t d for all 0 ≤ t ≤ π/2 (for some constant 0 < c 1 < 1). Using this bound for both the numerator and the denominator in (1), we deduce that The first claim follows.
Choosing some sufficiently small β, the second claim follows.

The generalized Ruzsa-Szemerédi problem
In this section we prove the first of our main results, Theorem 1.2. In the case r = 2, s = 3, the construction is based, as we saw in Section 2, on the observation that if we wish to find three vectors in S d = {x ∈ R d+1 : x = 1} in such a way that the angle between any two of them is 120 • , and if we choose the vertices one by one, then there are d degrees of freedom for the first vertex and d − 1 for the second, but the third is then uniquely determined. This gives us an example of a 'continuous graph' with 'many' edges, such that each edge is in exactly one triangle, and a suitable perturbation and discretization of this graph gives us a finite graph with n 2−o(1) triangles such that each edge belongs to at most one triangle.
To generalize this to arbitrary (r, s) we need to find a configuration of s unit vectors (where by 'configuration' we mean an s × s symmetric matrix that specifies the angles, or equivalently inner products, between the unit vectors) with the property that if we choose the points of the configuration one by one, then for i ≤ r the i th point can be chosen with d + 1 − i degrees of freedom, but from the (r + 1) st point onwards all points are uniquely determined. It turns out that all we have to do is choose an arbitrary collection of s points p 1 , . . . , p s in general position from the sphere S r−1 and take the angles ∠(p i , p j ). To see that this works, suppose we we wish to choose x 1 , . . . , x s ∈ S d one by one in such a way that x i , x j = p i , p j for every i, j. Suppose that we have chosen x 1 , . . . , x r and let V be the r-dimensional subspace that they generate. Let u r+1 be the orthogonal projection of x r+1 to V . Then u r+1 , x i = x r+1 , x i for each i ≤ r, and u r+1 ∈ V , so u r+1 is uniquely determined. Furthermore, since the angles p i , p j are equal to the angles x i , x j when i, j ≤ r and to the angles x i , u r+1 when i ≤ r, j = r + 1, and p r+1 is a unit vector, it must be that u r+1 is a unit vector, which implies that x r+1 = u r+1 . Since this argument made no use of the ordering of the vectors, it follows that any r vectors in a configuration determine the rest, as claimed.
We shall now use this observation as a guide for constructing a finite graph with many copies of K s such that each K r is contained in at most one K s .
As above, pick s 'reference' points p 1 , . . . , p s in general position on the sphere S r−1 . Since for any set B ⊆ {1, . . . , s} of size r the points p b (b ∈ B) form a basis of R r , we may write, for any a, For any c > 0 and positive integers N, d we define an s-partite random graph G N,d,c as follows.
(The graph will also depend on r, s, p 1 , . . . , p s , but for readability we drop these dependencies from the notation.) Consider the usual probability measure on the d-sphere S d . Pick, independently and uniformly at random, sN points x a,i (1 ≤ a ≤ s, 1 ≤ i ≤ N ) on S d : these points form the vertex set. Join two points x a,i and We also define a graph G N,d,c as follows. Let M 0 be the maximum among all values of |λ B,a,b | and λ 2 B,a,b , and let M = 2(r +1) This graph is designed to be finite and to have the property that any copy of K s must be close to a configuration with angles determined by the points p 1 , . . . , p s . The vertex deletions are there to ensure that the vertices are reasonably well separated. This will imply that no K r is contained in more than one K s , since once r vertices of a K s are chosen, the remaining vertices are constrained to lie in small neighbourhoods.
Lemma 3.1. The graph G N,d,c has the property that any of its subgraphs isomorphic to K r is contained in at most one subgraph isomorphic to K s (for any choices of r, s, p 1 , . . . , p s , N, d, c).
Proof. Let x a 1 ,i i , . . . , x ar,ir be points that form a K r . Then necessarily all a t are distinct. Suppose that we have two extensions H 1 , H 2 of this K r to a K s . Then both H 1 and H 2 intersect each class V a in exactly one point. We now show that for each a this point must be the same for H 1 and H 2 , which will imply the lemma.
Suppose that By the definition of G N,d,c , we must have x = y.
To prove Theorem 1.2, it suffices to show that the expected number of copies of K s in G N,d,c is at least N r e −O( √ log N ) for suitable choices of d and c. For this purpose we shall use the following technical lemma. For later convenience (in Section 4), we state it in a slightly more general form than required here, to allow the possibility that r = s and the possibility that p 1 , . . . , p s are not in general position (but still span R r ).
Lemma 3.2. Let 1 ≤ r ≤ s be positive integers and let p 1 , . . . , p s be points on S r−1 such that p 1 , . . . , p r form a basis of R r . Then there exist constants α > 0 and h such that for any d ≥ r and 0 < c < 1 the probability that a set {x a : 1 ≤ a ≤ s} of random unit vectors (chosen independently and uniformly) on We may think of the conclusion of Lemma 3.2 as follows. The dominant (smallest) factor in the probability above is the factor c d(s−r)/2 . The probability should be close to this because if we imagine placing the s points one by one and we have already picked x 1 , . . . , x i joined to each other, then • if i < r, then x i+1 is restricted to a neighbourhood of a codimension-i surface, so with reasonably large probability (comparable to c i ) it is connected to all previous vertices; • if i ≥ r, then the linear dependencies between the points restrict x i+1 to be in a ball of radius about c 1/2 around a certain point, which has measure about c d/2 (which is much smaller than c r ).
The proof of Lemma 3.2 is given in an appendix.
Proof of Theorem 1.2. By Lemma 2.1, there are constants c 0 , B, C such that if c < c 0 then the probability that a given vertex x a,i is removed from G N,d,c when forming G N,d,c is at most Here B > 0 is an absolute constant and the constants C, c 0 > 0 depend on r, s, p 1 , . . . , p s only. Moreover, the event 'x a,i is removed' is independent of any event of the form 'x 1,i 1 , . . . , x s,is form a K s in G N,d,c '. Using Lemma 3.2, we deduce that the probability that x 1,i i , . . . , x s,is is contained in G N,d,c and forms a K s is at least (1−sN C d c d/2 )α d c d(s−r)/2+h (where α, h depend on r, s, p 1 , . . . , p s only). So the expected number of copies of K s in G N,d,c is at least for some constants η > 0 and E not depending on N, d.
, and c < c 0 when N is sufficiently large. The result follows, as G N,d,c has at most N s vertices.
Note that our proof in fact also gives the correct (and trivial) lower bound Θ(n) in the case r = 1, since if r = 1 then h = 0 so we may choose d to be a constant and get Θ(N ) in (2).

Generalized rainbow Turán numbers for complete graphs
We now turn to the proofs of our results about generalized rainbow Turán numbers (Theorems 1.4 and 1.5). First we recall a general result of Gerbner, Mészáros, Methuku and Palmer [9], which can be proved using the graph removal lemma. In particular, we know that ex(n, K r , rainbow-K r ) = o(n r−1 ). We would like to match this with a lower bound of the form n r−1−o(1) .
Before we prove such a bound, let us briefly discuss the ideas that underlie the proof. It is easy to show that a lower bound ex(n, K 4 , rainbow-K 4 ) ≥ n 3−o(1) would imply that ex(n, K r , rainbow-K r ) ≥ n r−1−o(1) for all r ≥ 4, so it suffices to consider the case r = 4. However, when r = 4 and G is a properly edge-coloured graph with no rainbow K 4 , then every triangle of G is contained in at most three copies of K 4 . (Indeed, if the vertices of the K 3 are x, y, z, then the only way that adding a further vertex w can lead to a non-rainbow K 4 is if wx has the same colour as yz, wy has the same colour as xz or wz has the same colour as xy. But since the edge-colouring is proper, we cannot find more than one w such that the same one of these three events occurs.) So it is natural to expect that our construction for Theorem 1.2 is relevant here.
To see how a similar construction gives the desired result, it is helpful, as earlier, to look at a simpler continuous example that serves as a guide to the construction. Consider the graph where the vertex set is S d and two unit vectors v, w are joined if and only if v, w = −1/3 (the angle between vectors that go through the origin and two distinct vertices of a regular tetrahedron). Then any K 4 in this graph must be given by the vertices of a regular tetrahedron. We colour an edge by the line that joins the origin to the midpoint of that edge. This is a proper colouring with the property that opposite edges have the same colour, so each K 4 is 3-coloured in this colouring. The construction we are about to describe is a suitable perturbation and discretization of this one.
For the discretized graph, we will again have 'near-regular' tetrahedra forming K 4 s. To ensure that each copy of K 4 is still rainbow, we shall have to modify the colouring slightly. We shall take only certain 'allowed lines' as colours, and we shall colour an edge by the allowed line that is closest to the line through the midpoint (if that line is not very far -otherwise we delete the edge). We need to choose the allowed lines in such a way that no two allowed lines are close (so that near-regular tetrahedra are still 3-coloured), but a large proportion of lines are close to an allowed line (so that not too many edges are deleted). This can be achieved using the following lemma.
Proof. Take a maximal set of points satisfying the condition above. Then the balls of radius 3c 1 around the points ±q 1 , . . . , ±q L cover the entire sphere. But any such ball covers a proportion of surface area at most (Bc 1 ) d for some constant B (by Lemma 2.1). Therefore 2L(Bc 1 ) d ≥ 1, which gives the result.
One can prove Theorem 1.4 using the method described above. However, the proof naturally yields the more general Theorem 1.5 (which is restated below), so that is what we shall do. Essentially, we can prove a lower bound of n m−o(1) for a graph H whenever we can draw H in R m in such a way that for each colour there is a line through the origin meeting (the line of) each edge of that colour, and the vertices of the graph span R m . Theorem 1.5. Let r ≥ 4, let H be a graph, and let H have a proper edge-colouring with no rainbow K r . Suppose that for each vertex v of H there is a p v ∈ R m , and for each colour κ in the colouring there is a non-zero vector z κ such that for every edge vw of colour κ, z κ is a linear combination of p v and p w with non-zero coefficients. Then ex(n, H, rainbow-K r ) ≥ n m 0 −o (1) , where m 0 is the dimension of the subspace of R m spanned by the points p v .
Proof. Passing to a subspace, we may assume that m = m 0 and {p v : v ∈ V (H)} spans R m . Furthermore, by rescaling we may assume that each z κ and each non-zero p v has unit length.
For each c > 0 and any two positive integers N, d, we define a (random) graph F N,d,c as follows. The vertex set of F N,d,c has |H| parts labelled by the vertices of H. If v ∈ V 0 then there is a single point x v,1 = 0 in the part labelled by v. If v ∈ V 1 , then we pick (uniformly and independently at random) N points x v,1 , . . . , x v,N on S d : these will be the vertices in the part labelled by v. We join two vertices x v,a and x w,b by an edge if and only if vw ∈ E(H) and | x v,a , x w,b − p v , p w | < c.
By assumption, we know that for each edge vw of colour κ there exist λ κ,v , λ κ,w non-zero real coefficients such that z κ = λ κ,v p v + λ κ,w p w . Let λ be the minimum and The exact values of the constants are not particularly important -they were chosen so that the graph described below will be properly coloured with no rainbow K r . That is, we could replace 12M 2 0 and 2/λ by other sufficiently large constants.) Let q 1 , . . . , q L be points on S d with L ≥ (δ/c 1 ) d such that q i − q j ≥ 3c 1 for all i = j. Here δ is some positive (absolute) constant, and the existence of such a set follows from Lemma 4.2. Also, pick independently and uniformly at random a rotation R κ ∈ SO(d + 1) for each colour κ used in the edge-colouring of H. The probability measure we use on SO(d + 1) is the usual (Haar) measure, so for any q ∈ S d the points R κ q are independently and uniformly distributed on S d . We think of the points R κ q l (l = 1, . . . , L) as the allowed colours for the edges x v,i x w,j when vw ∈ E(H) has colour κ (and we take different rotations for different colours to have independence).
We form an edge-coloured graph F N,d,c from F N,d,c as follows. For any edge x v,i x w,j of F N,d,c , we perform the following modification. Let κ be the colour of vw in E(H), and let λ κ,v , λ κ,w = 0 be as before, so that z κ = λ κ,v p v + λ κ,w p w .
• If there is some l with λ κ,v x v,i + λ κ,w x w,j − R κ q l < c 1 , then we colour the edge x v,i x w,j with colour (κ, l). Note that such an l must be unique since R κ q l − R κ q l ≥ 3c 1 if l = l.
• Otherwise we delete the edge x v,i x w,j .
Proof. Suppose that x v,i x w,j and x v,i x w ,j are both edges with colour (κ, l). Then vw and vw both have colour κ in E(H), thus w = w . Also, But then j = j by the definition of F N,d,c . So the edge-colouring of F N,d,c is indeed proper.

Claim 2.
There is no rainbow copy of K r in F N,d,c .
Proof. Suppose that the vertices x v 1 ,i 1 , . . . , x vr,ir form a K r in F N,d,c . Then v 1 , . . . , v r form a K r in H. This K r is not rainbow (by assumption). By symmetry, we may assume that the edges v 1 v 2 and v 3 v 4 both have colour κ. Write x a for x va,ia and λ a for λ κ,va for a = 1, 2, 3, 4. Then we have (recalling that M 0 = max κ ,v |λ κ ,v |) But if x 1 x 2 has colour (κ, l) and x 3 x 4 has colour (κ, l ), then It follows that l = l and hence the K r with vertices x v 1 ,i 1 , . . . , x vr,ir is not rainbow. Proof. Pick arbitrary vertices x v,iv in the classes (with i v = 1 if v ∈ V 0 and 1 ≤ i v ≤ N otherwise). We consider the probability that they form a copy of H in F N,d,c . Write x v for x v,iv .
Let > 0 be a small constant to be specified later. By Lemma 3.2, we have for some constants α > 0 and h.
Let v ∈ V 1 . By Lemma 2.1, the probability that x v is removed when we form F N,d,c is at Finally, for each colour κ in the colouring of E(H), pick an edge v κ w κ of that colour in H. Write y κ = λ κ,vκ x vκ + λ κ,wκ x wκ and y κ = yκ yκ . Note that y κ = 0 with probability 1, since all λ κ,v are non-zero and at least one of p vκ and p wκ is non-zero. For each κ, if is sufficiently small then by Lemma 2.1 we have for some constants η, η 1 > 0.
Observe that the events in (3), (4) and (5) (for all κ) are independent. It follows that P[the events in (3), (4), and, for all κ, where γ is some constant depending on (but not on N, d, c). We show that these events together imply that the x v form a copy of H, if is sufficiently small. The only property that we need to check is that no edge is removed when F N,d,c is formed out of F N,d,c . Consider then an edge uu of H. Let κ be its colour and write v = v κ , w = w κ , y = y κ , y = y κ , λ v = λ κ,v , λ w = λ κ,w , λ u = λ κ,u , and λ u = λ κ,u . We have Furthermore, if we write y = λ u x u + λ u x u , then It follows that This is indeed less than c 1 = (12M 2 0 c) 1/2 if is sufficiently small. Choosing appropriately, (6) gives that the expected number of copies of H in F N,d,c is at least Deduction of Theorem 1.4 from Theorem 1.5. Given a complete graph K r on vertex set {1, . . . , r}, we can properly edge-colour it by giving the edges 12 and 34 the same colour κ, and giving arbitrary different colours to the remaining edges. Pick r − 1 linearly independent points p 2 , p 3 , . . . , p r in R r−1 , and let p 1 = p 2 + p 3 + p 4 . Let z κ = p 3 + p 4 = p 1 − p 2 and let z κ = p i + p j when ij is an edge of colour κ = κ. Theorem 1.5 gives that ex(n, K r , rainbow-K r ) ≥ n r−1−o(1) , and we have a matching upper bound by Proposition 4.1.

Some applications of Theorem 1.5
We have already seen that Theorem 1.5 can be used to answer the question of Gerbner, Mészáros, Methuku and Palmer about the order of magnitude of ex(n, K r , rainbow-K r ). In this section we give some other examples of applications of the theorem.
To show that our lower bounds are sharp, we shall use a simple proposition to give matching upper bounds. This will require the following definition. Given a graph H and a proper edgecolouring c of H, we say that a subset V 0 ⊆ V (H) is a c-spanning set if there is an ordering v 1 , . . . , v k of the vertices in V (H)\V 0 such that for all i there are some u, u , w ∈ V 0 ∪{v 1 , . . . , v i−1 } such that uu ∈ E(H), v i w ∈ E(H) and c(uu ) = c(v i w). In other words, we can add the remaining vertices to V 0 one by one in a way that new vertices are joined to some vertex in the set by a colour already used. Proof. Let G be a graph on n vertices and let κ be a proper edge-colouring of G without a rainbow copy of F . Let G contain M copies of H. Then we can partition the vertices into classes Note that any x with c x = c is determined by (x v ) v∈V 0 , since the edge-colouring is proper. But there are O(n r ) choices for (x v ) v∈V 0 , hence M = O(n r ). Now assume that r < |V (H)| and that for every proper edge-colouring c of H without a rainbow F and every edge e of H there is a c -spanning set of size at most r that contains e. By the graph removal lemma and the first part of our proposition, we can remove o(n 2 ) edges from G so that the new graph G contains no copy of H. So it suffices to show that each edge appeared in at most O(n r−2 ) tuples x with c x = c. Given an edge e = y v y w with y v ∈ X v , y w ∈ X w , vw ∈ E(H) we can pick in H a c-spanning set V 0,e of size at most r containing vw. Then any x with c x = c and x v = y v , x w = y w is determined by (x u ) u∈V 0 \{v,w} , which gives the result. Now we give some sample applications of Theorem 1.5 and Proposition 5.1. We shall give two illustrations, but it is quite easy to generate additional examples.

Complete graphs
Perhaps the most natural extension of Question 1.3 is to determine the behaviour of the function ex(n, K r , rainbow-K s ). Note that trivially ex(n, K r , rainbow-K s ) = Θ(n r ) when s > r (by taking a complete r-partite graph), and we have seen that ex(n, K s , rainbow-K s ) = n s−1−o(1) (when s ≥ 4). We also have ex(n, K r , rainbow-K s ) = 0 whenever r ≥ r s for some integer r s depending on s. Indeed, if we have a K r with no rainbow copy of K s , and the largest rainbow subgraph has order t ≤ s, then any of the remaining (r − t) vertices must be joined to this K t by one of the t 2 colours appearing in the K t . But each such colour appears at most once at each vertex, giving r = O(s 3 ). In fact, Alon, Lefmann and Rödl showed [1] that r s = Θ(s 3 / log s).
However, the question is non-trivial for s < r < r s . First note that ex(n, K r , rainbow-K s ) = o(n s−1 ) whenever r ≥ s by Proposition 5.1 (since any maximal rainbow subgraph is a c-spanning set). The simplest case for the lower bound is (r, s) = (5,4). In this case Theorem 1.5 gives a matching lower bound n 3−o (1) . Indeed, take an arbitrary proper edge-colouring of K 5 with no rainbow K 4 , and take points p 1 , . . . , p 5 in general position in R 3 . The existence of appropriate values of z κ follows from the fact that any four of the p i are linearly dependent (but any three are independent), and each colour is used at most twice. It is easy to deduce that ex(n, K s+1 , rainbow-K s ) = n s−1−o(1) for all s ≥ 4.
When s = 4 then r s = 7 (since any triangle is in at most one K 4 ), leaving the case (r, s) = (6, 4). Unfortunately, in this case Theorem 1.5 does not give a lower bound of n 3−o (1) . (To see this, observe that to get such a bound the corresponding points p v would all have to be non-zero. Then we can use the alternative formulation Theorem 1.5 to see that we would have to be able to draw a properly edge-coloured K 6 in the plane such that there is no rainbow K 4 and lines of edges of the same colour are either all parallel or go through the same point. Applying an appropriate projection and affine transformation, we may assume that we have two colour classes where the edges are all parallel, and these two parallel directions are perpendicular. This leaves essentially two cases to be checked, and neither of them yields an appropriate configuration.) However, we can still deduce a lower bound of ex(n, K 6 , rainbow-K 4 ) ≥ n 12/5−o(1) , as sketched below. We can take 6 points p 0 = 0 and p a = e 2πia/5 (for a = 1, . . . , 5), that is, the vertices of a regular pentagon together with its centre. We define a colouring c as follows. Give parallel lines between vertices of the pentagon the same colour, and also give the same colour to the edge incident at the centre which is perpendicular to these lines (see Figure 1). This gives a proper edge-colouring of K 6 and corresponding points in 2 dimensions for which the conditions of Theorem 1.5 are satisfied, giving a lower bound of n 2−o (1) . (The point z κ is chosen to be p a when p 0 p a has colour κ.) This can be improved to n 12/5−o(1) by a product argument as follows. Looking at the construction, we see that our graph G is 6-partite with classes V 0 , . . . , V 5 , at most n vertices, and a proper edge-colouring κ such that the following hold.
• There are (at least) n 2−o(1) copies of K 6 in G.
• There is a 5-colouring c of the edges of K 6 (on vertex set {0, . . . , 5}) with no rainbow K 4 such that whenever gives an isomorphism of colourings between the restrictions of c and κ to the appropriate fourvertex graphs (i.e., κ(v i j v i l ) = κ(v i j v i l ) if and only if c(i j i j ) = c(i j i l )). Moreover, this 5-colouring c has the property that for all i, j ∈ {1, . . . , 6} there is a permutation of the vertices {0, . . . , 5} which is an automorphism of colourings and maps i to j. (Indeed, we can take rotations of the pentagon when i, j = 0, and we can take the permutation (01)(34) when i = 0, j = 1.) We construct a new graph as follows. For each i ∈ {0, . . . , 5}, pick a permutation π i of {0, . . . , 5} which gives a colouring automorphism of c and sends i to 0. Define a 6-partite graph G i obtained from G by permuting the vertex classes: G i has classes V i 0 , . . . , V i 5 given by V i a = V π i (a) and same edge set as G. Let G be the product of these 6-partite graphs, that is, it is 6partite with vertex classes W a = V 0 a × V 1 a × · · · × V 5 a , and two vertices (v 0 , . . . , v 5 ) ∈ W a and (w 0 , . . . , w 5 ) ∈ W b are joined by an edge if v i w i ∈ E(G) for all i. Moreover, colour such an edge by colour (κ(v 0 w 0 ), . . . , κ(v 5 w 5 )). It is easy to check that the colouring is proper, G contains no rainbow K 4 , G has at most n 5 vertices in each class, and G contains at least n 12−o(1) copies of K 6 , giving the bound stated. This leaves some open questions about ex(n, K r , rainbow-K s ). It would be interesting to determine its order of magnitude for (r, s) = (6, 4), or the magnitude for other pairs with s < r < r s .

King's graphs
Given positive integers k, l ≥ 2, write H k,l for the graph with vertex set {1, . . . , k} × {1, . . . , l} where (a, b) and (a , b ) are joined by an edge if and only if they are distinct and |a−a |, |b−b | ≤ 1. In other words, H k,l is the strong product of a path with k points and a path with l points, sometimes called the k × l king's graph. We can use our results to show that ex(n, H k,l , rainbow-K 4 ) = n k+l−1−o (1) .
First consider the upper bound. It is easy to see that any sequence of vertices p 1 , . . . , p k+l−1 is a c-spanning set (for all proper edge-colourings c of H k,l without a rainbow K 4 ) if either of the following statements holds.  (Indeed, this follows from the fact that we can add the other vertices one by one, creating a new copy of K 4 in our set in each step.) Since any edge is contained in such a sequence, Proposition 5.1 gives ex(n, H k,l , rainbow-K 4 ) = o(n k+l−1 ).
For the lower bound, consider an edge-colouring c of H k,l with c((a, b)(a + 1, b)) = a, where the other edges are given arbitrary distinct colours. This gives a proper edge-colouring of H k,l with no rainbow K 4 . For each vertex (a, b) of H, define p a,b ∈ R k+l to be the vector with i th coordinate For each 1 ≤ a ≤ k − 1 we let z a ∈ R k+l be the vector with all entries zero except the a th and (a + 1) th coordinates which are 1, and for each other colour κ used in the colouring of H k,l we take z κ = p v + p w , where vw is the unique edge of colour κ. Then we have p a,b + p a+1,b = z a , so the conditions of Theorem 1.5 are satisfied. The dimension of the subspace of R k+l spanned by the vectors p a,b is at least k + l − 1, since p 1,l , p 1,l−1 , . . . , p 1,1 , p 2,1 , p 3,1 , . . . , p k,1 are linearly independent. We get the required lower bound n k+l−1−o (1) .
So it suffices to show that if and δ are sufficiently small (depending on p 1 , . . . , p r+1 only), then the event above implies that | x a , x r+1 − p a , p r+1 | < c for all 2 ≤ a ≤ r. But we have Lemma A.2. Let r be a positive integer and let p 1 , . . . , p r be linearly independent points in S r−1 .
Then there are exist real numbers α 1 > 0 and h 1 such that whenever d ≥ r is a positive integer and 0 < c < 1 then the probability that r points x 1 , . . . , x r chosen independently and uniformly at random on S d satisfy | x i , x j − p i , p j | < c for all 1 ≤ i, j ≤ r is at least α d 1 c h 1 .
Proof. The proof is essentially the same as for the previous lemma. We prove the statement by induction on r. The case r = 1 is trivial. Now assume that r ≥ 2 and that the statement holds for smaller values of r. By symmetry, we may assume that x 1 = (0, 0, . . . , 0, 1) ∈ S d and p 1 = (0, 0, . . . , 0, 1) ∈ S r−1 . Define p a and x a for a ≥ 2 as in the proof of Lemma A.1. Let > 0 be some small constant to be determined later. By induction, we have P[| x a , x b − p a , p b | < c for all 2 ≤ a, b ≤ r] ≥ α d−1 1 ( c) h 1 for some α 1 > 0 and h 1 (where the constants depend only on p 1 , . . . , p r+1 ).
It follows that whenever b, b > r then Choosing a sufficiently small > 0 gives the result.