Manuscript Offprint
arXiv:2610.21961Preprocessed 3SUM: From Reals to Integers
Abstract
The Preprocessed 3SUM problem asks to preprocess a set of numbers so that we can quickly decide whether a query subset contains a solution . The best known query bounds differ substantially between integer and real inputs. For integers, a series of advances with near-quadratic preprocessing reduced the query time from [Chan, Lewenstein; STOC '15] to [Chan, Vassilevska W., Xu; STOC '23], and finally to [Kasliwal, Polak, Sharma; SOSA '25]. For reals, only the first of these bounds has been achieved, by adapting the corresponding integer algorithm [Fischer; SODA '25]. Is this gap inherent to the more limited tools available for real inputs?
We give a randomized real-to-integer reduction with preprocessing overhead and no asymptotic increase in query time. This yields preprocessing and query time for real inputs, closing the gap. We show how to extend our result to the setting where one set is unknown at preprocessing time. Our reduction is conceptually simple, and relies on an interesting technical toolkit around old and new tools from sparse linear algebra. More broadly, it suggests a route to real-to-integer reductions for other additive problems.
1 Introduction
We revisit an ever-present question in algorithm design: “Are problems harder to solve on real-valued inputs than on integer-valued inputs?” Integer inputs enable techniques such as scaling, modular hashing, and bit manipulation that have no immediate counterparts for arbitrary reals. Understanding whether these advantages are essential has repeatedly led to new algorithms and, sometimes, to entirely new ways of approaching a problem.
A striking recent example is single-source shortest paths with negative edge weights. In 2022, Bernstein, Nanongkai, and Wulff-Nilsen [BNW25] gave a breakthrough near-linear-time algorithm for integer weights. However, the algorithm relies on a scaling technique, which seems very hard (if not impossible) to extend to real weights. This left room for a different line of work, initiated by Fineman's breakthrough in 2024 [Fin24], which has now culminated in a very different almost-linear-time algorithm for real weights due to Hair, Li, Li, and Zhang [HLLZ26]. The effort to bridge the integer-real divide has thus helped drive one of the major recent successes in graph algorithms.
But there are many more interesting examples. Another one is computing sumsets : for integer sets, near-linear output-sensitive algorithms have been available since 2002 [CH02], but obtaining an analogous algorithm for real sets took more time and a very different set of techniques [Fis25]. And of course this question frequently arises in computational geometry; see e.g. [CP09].
*Max-Planck Institute for Informatics. nfischer@mpi-inf.mpg.de
Bocconi University. jonas.schmidt2@phd.unibocconi.it
I.e., given integer sets A, B, the goal is to compute the set .
Perhaps the cleanest approach towards approaching such questions is by attempting real-to-integer reductions, i.e., reductions from a problem on real inputs to the same problem on integer inputs. This may appear an unrealistic goal at first, and yet, Chan, Vassilevska W., and Xu [CVX22] have initiated this trend recently in fine-grained complexity by establishing a non-tight reduction from 3SUM on real inputs to 3SUM on integer inputs. Fischer, Polak, and Schmidt [FPS26] recently established the tight equivalence of the integer and real versions of the 3SUM Hypothesis, through an unexpected application of the Frank-Tardos theorem [FT87]. That result has since been overtaken by a dramatic breakthrough [AV26], which refuted the 3SUM Hypothesis for both integer and real inputs. The broader question remains: when can we replace real inputs by integers while preserving precisely the structure that an algorithm needs? Its importance extends beyond a particular hardness hypothesis or a particular problem.
Preprocessed 3SUM. In this work, we consider a variant of 3SUM that has not been affected as dramatically by the recent breakthrough: Preprocessed 3SUM. Given a universe A of n numbers, we preprocess A so that, upon receiving a subset , we can quickly decide whether there exist with . The preprocessing is performed once and can be reused for many queries. Equivalently, one can work with three preprocessed universes A, B, C and queries specifying subsets , , and ; we use the single-universe formulation for simplicity.
This problem has an exciting history which we describe in detail soon. In a nutshell, the state-of-the-art for integers due to Kasliwal, Polak, and Sharma [KPS25] is an algorithm with preprocessing time and query time . For real inputs, the best known bound is , due to Fischer [Fis25]. The faster integer algorithm uses an integer-specific form of hashing, which makes it difficult to replicate for real numbers. In fact, Kasliwal, Polak, and Sharma explicitly ask whether their query time can also be achieved over the reals. We discuss later how the recent improvement for ordinary 3SUM can lead to a slightly subquadratic preprocessing time. Nonetheless, it does not seem to affect any of these query times at all and leaves a substantial polynomial gap.
Main result. We give a reduction from real to integer Preprocessed 3SUM that preserves the query time and incurs only a near-quadratic additive cost in preprocessing.
Theorem 1.1. If Preprocessed 3SUM with integer inputs (over the word RAM model) can be solved in preprocessing time and query time , then Preprocessed 3SUM with real inputs (over the real RAM model) can be solved in preprocessing time and query time .
Up to the near-quadratic overhead in preprocessing, this is exactly the kind of real-to-integer reduction that we are generally aiming for. Our reduction takes a surprisingly clean form, where we actually replace each real by an appropriate integer and then run the integer algorithm as a black box. It is conceptually much simpler than the recent reduction of Fischer, Polak, and Schmidt [FPS26], and does not invoke overly complicated machinery like the Frank–Tardos algorithm. While the approach is pleasingly simple on a conceptual level, some interesting technical aspects remain: the algorithm relies on a combination of sparse linear algebra tools, some of which were known [Wie86, KS91], and some of which we develop here.
Applying our reduction to the integer algorithm of Kasliwal, Polak, and Sharma [KPS25] answers their question and gives the following bound.
Specifically, they write: “It seems to remain a difficult open question whether the subsequent improvement to time [CVX23] or our current improvement to time also can be mirrored in the real RAM.”
| Source | Preprocessing time | Query time | For reals? |
| Chan-Lewenstein [CL15] | ✕ | ||
| Chan-Vassilevska W.-Xu [CVX23] | ✕ | ||
| Fischer [Fis25] | ✓ | ||
| Kasliwal-Polak-Sharma [KPS25] | ✕ | ||
| Corollary 1.2 | ✓ | ||
| Theorem A.1 | ✕ |
Table 1. Known algorithms for Preprocessed 3SUM. Here, is an absolute constant. The table omits recent improvements regarding space complexity [KKMV26, CKK26].
Corollary 1.2. Preprocessed 3SUM with real inputs (over the real RAM model) can be solved in preprocessing time and query time .
This improves the query exponent for real inputs from 13/7 to 3/2, matching the best known integer bound with near-quadratic preprocessing. More broadly, and perhaps even more importantly, our method suggests a route to real-to-integer reductions for other additive problems.
History and the effect of the 3SUM breakthrough. Preprocessed 3SUM has a rich history. The problem was first raised in the work of Bansal and Williams [BW12], who credited Avrim Blum for suggesting this application of preprocessing. Chan and Lewenstein [CL15] gave the first algorithm with truly subquadratic query time and near-quadratic preprocessing time for integer inputs. Their approach is based on a pioneering application of additive combinatorics. The query time was improved to by Chan, Vassilevska W., and Xu [CVX23], and then to by Kasliwal, Polak, and Sharma [KPS25]. None of these results apply to real inputs out of the box; Fischer [Fis25] later extended the Chan–Lewenstein algorithm to real inputs substituting the integer-specific sparse convolution routine with an analogue for reals. Table 1 summarizes the relevant bounds. More recently, Kirkpatrick, Kuszmaul, Mathialagan, and Vassilevska W. [KKMV26], and Carmel, Kosoburd, and Krauthgamer [CKK26], studied space-efficient data structures for a variant of Preprocessed 3SUM where the universe set is partially unknown. In this variant, only two sets are preprocessed, and each query is to decide whether and contain a 3SUM solution. A related line of work studies a different setting of 3SUM that allows for preprocessing, namely 3SUM-Indexing [GKLP17, KP19, GGH20, CL23, DG26], with the goal to find the best tradeoff between space and query time for a data structure that preprocesses integer sets and answers queries of the form: given , is there such that ?
The new algorithm for ordinary 3SUM also has a consequence for Preprocessed 3SUM, although obtaining it requires more than invoking that algorithm at query time. In the appendix, we show how to combine the breakthrough [AV26] with the existing preprocessing techniques to obtain an integer algorithm with preprocessing time and query time , for some absolute constant ; see Theorem A.1. The saving in the preprocessing exponent is small, but establishes that truly subquadratic preprocessing is compatible with the best known query bound.
Other settings. Algorithms for preprocessed 3SUM have been successfully extended to several other directions: (i) derandomizing the algorithms, (ii) balancing query time and space usage, and (iii) allowing the third query set to be unknown at preprocessing time. Perhaps the technically most interesting extension for our algorithm is the third setting, where sets A and B are given at preprocessing time and queries consist of , , and an arbitrary third set . Algorithms must detect a solution to . We resolve this setting with a similarly clean reduction as Theorem 1.1, leading to the following corollary. See Section 5 for how to adapt our algorithm to also solve this setting.
Corollary 5.3. Preprocessed 3SUM with Unknown C with real inputs (over the real RAM model) can be solved in preprocessing time and query time .
The real RAM model. The real RAM is a convenient model for algorithms on arbitrary real inputs, but its unrestricted form can be unrealistically powerful. In particular, unit-cost arithmetic with unrestricted multiplication can conceal computations on numbers of enormous bit complexity. See, e.g., the discussion in Fischer, Polak, and Schmidt [FPS26]. Notably, our reduction works in a much more restricted model which only supports queries of the form “” and “” (and reverse inequalities) for input reals . In particular, it does not require storing results of arithmetic operations. In this restricted model, preprocessing time is unconditionally necessary to support truly subquadratic query time [Eri95, AC05], making our preprocessing bound optimal up to polylogarithmic factors.
Definition 2.1 (Preprocessed 3SUM). Preprocess a given set of numbers A of size n to support the following queries: Given , decide if contains a solution .
This definition slightly differs from the usual, tripartite definition of preprocessed 3SUM, where we preprocess three sets A, B, and C to support queries of the form: Given , , and , decide if there is a solution to . It is well known that for ordinary 3SUM, the tripartite version and the single-set version are equivalent in running time up to logarithmic factors via simple reductions (see, e.g., [DGS20]). These reductions immediately carry over to the preprocessed setting. Therefore, we can choose to work with Definition 2.1, which is more convenient for us.
We consider Preprocessed 3SUM with either real or integer inputs. Unless specified otherwise, we assume that integer inputs are bounded by . All randomized algorithms are Monte Carlo randomized. We sometimes write with high probability to say that an event happens with probability at least for some sufficiently large constant .
Let be a matrix over the finite field for a prime . We denote by the number of nonzero entries of . Similarly, for a vector , the number of nonzero entries in is denoted by . We will equivalently write that is -sparse if .
3 Real-to-Integer Reduction
We start with a high-level description of our reduction. Our starting point is the same as that of Fischer, Polak, and Schmidt [FPS26]. In their work, they design a real-to-integer reduction for 3SUM. That is, they show that if integer 3SUM can be solved in time then real 3SUM can be solved in time . The dependence of on is quite bad, and there is no hope that their approach (as is) can be used to lead to a lossless reduction. (And again, the result has since been subsumed by [AV26].) Nevertheless, the same basic observations are useful. Their result is based on the following theorem due to Frank and Tardos [FT87] (see also [Eis10]):
Theorem 3.1 (Frank–Tardos). Fix any integer . There is a deterministic algorithm that, given reals , computes integers satisfying the following two properties:
• if and only if , for all ,
• .
The algorithm runs in polynomial time .
In words, this theorem allows to replace arbitrary reals by integers such that the order of all subset sums is preserved. Moreover, the integers are reasonably small with bit representations of polynomial length . This should be viewed as a “big hammer”. It can be directly applied to 3SUM to yield the intended real-to-integer reduction, albeit with a (large) polynomial overhead in the preprocessing time.
Specifically, apply the Frank–Tardos theorem to the given set of reals . Then substitute each real by the corresponding integer . This preserves exactly all 3SUM solutions and non-solutions. If then also (by applying the first condition two times, for the vectors and ).
The only remaining problem is that the resulting integers are very large; however, this can be solved by a standard trick. We can hash all integers to the range in such a way that 3SUM solutions remain preserved. A simple way is to sample a random prime of size and to reduce all numbers modulo . In this way, 3SUM solutions are necessarily preserved, while non-solutions stay non-solutions with good probability.
Except for this last technical issue, the approach can be summarized by the following observation:
Observation 3.2. There is a randomized polynomial-time algorithm which, given a set A of n reals, computes an integer encoding , i.e., a function satisfying, for all , that if and only if .
However, applying the Frank–Tardos theorem appears to be a big hammer for a much smaller task. It not only preserves 3SUMs, but even Subset Sums and even the order of Subset Sums.
It turns out that this observation has a simpler alternative proof. (This alternative proof is exactly what was pointed out by an LLM at an early stage of this project, see AI Disclosure.) Write . Consider the matrix , where we insert the row if and only if is a 3SUM solution. Note that every integer encoding of forms a solution to the equation system (when taking ). In this spirit, the idea is to compute a random integer solution to the equation (i.e., a random kernel element of ) and to take .
Clearly, the resulting function preserves all 3SUM solutions. More interestingly, focus on any non-solution . The constraint is not implied by the equation system. Thus, the set of solutions satisfying that extra constraint is of dimension one smaller than the dimension of the kernel. For this reason, the probability of sampling one such solution is small, and with high probability the resulting function satisfies .
The problem, of course, is to implement this alternative proof more economically than the large polynomial time of the naive algorithm. Currently the running time suffers from large polynomial factors for three different reasons:
-
Listing the up to 3SUM solutions in time .
-
Solving an equation system of size up to . This takes time naively, and fast matrix multiplication allows some improvements to time at best. To achieve time we have to exploit the sparsity of the system.
-
Any nonzero integer solution to this equation system must have polynomially many bits in the worst case. E.g., consider the 3SUM instance ; this set cannot be replaced with integers smaller than without introducing or destroying some solutions . Thus, each basic computation with a resulting integer already requires time .
While 1 is acceptable (and unavoidable in the restricted real RAM model), 2 and 3 are real issues. We will deal with 2 by deriving a new algorithm for solving rectangular, row-sparse equation systems; see the following Theorem 4.1. This algorithm is likely to be of independent interest. To deal with 3, as before, we instead perform all computations over sufficiently large finite fields.
Theorem 4.1 (Sparse Rectangular Linear Equation Solving). There is a randomized algorithm that, given a matrix and a vector , returns a uniformly random solution to (or reports that no solution exists). The algorithm runs in time , provided that each row in is -sparse and that .
For us, the parameter regime of interest is and . In this regime the algorithm takes time , which is near-optimal, since already specifying the input takes time .
3.1 Technical Proof
Proof of Theorem 1.1. We start with a description of the preprocessing phase. Given , we first list all 3SUM solutions in time . That is, we first sort in time . Then, for each pair we binary-search whether . (Note that this algorithm can indeed be implemented in the restricted real RAM model mentioned before.) Let denote the set of solutions.
Sample a uniformly random prime in the range , and consider the matrix of size over , where the row corresponding to is exactly . Compute a random solution to by one call to Theorem 4.1. Below we will prove that, with high probability, if and only if . By that claim, it suffices to solve the
Of course, it is not well-defined here what a random integer solution means. We will later make this rigorous by working over a finite field instead.
version of Preprocessed 3SUM: preprocess the set , and then upon query of a subset , decide whether contains a 3SUM solution (modulo ). This problem can easily be reduced to 2 instances of integer Preprocessed 3SUM over the universe (one for the solutions with and one for the solutions with , when viewing the 's as integers).
Claim 3.3. With high probability, if and only if for all .
Proof. Apply the Frank–Tardos theorem (Theorem 3.1) on to obtain integers bounded by such that if and only if . We claim that, with high probability, this is further equivalent to . Indeed, the only failure event is when and divides . This number has at most prime divisors, thus the probability of selecting among these bad choices is at most by the Prime Number Theorem. By a union bound over the choices of , the total error probability is .
Thus, view as an element of . By construction we have (now viewed over ). Sampling a uniformly random kernel element can therefore be equivalently viewed as sampling and a uniformly random scalar , and setting . But then, for any triple with we have that . Since and since is sampled uniformly and independently, it follows that also is uniformly distributed in . The probability of hitting zero is thus , and by a union bound over all non-solution triples the total error probability is .
Let us finally analyze the running time. Listing the 3SUM solutions takes time . The call to Theorem 4.1 is with parameters and , and thus takes time , too. Finally, we preprocess two instances of integer Preprocessed 3SUM in time . In the query phase, we issue two queries to respective two instances taking time as claimed.
4 Sparse Linear Algebra
It remains to design the fast algorithm for solving sparse, rectangular equation systems.
Theorem 4.1 (Sparse Rectangular Linear Equation Solving). There is a randomized algorithm that, given a matrix and a vector , returns a uniformly random solution to (or reports that no solution exists). The algorithm runs in time , provided that each row in is -sparse and that .
Throughout this section, is a prime and we work over the finite field . We assume that fits into machine words so that field operations in can be executed in time.
4.1 Technical Overview
We provide a quick overview of the main ideas behind Theorem 4.1. In our setting, think of A as an matrix with only three nonzero entries per row, encoding all 3SUM solutions.
Technically, our algorithm can be viewed as a reduction to solving a sparse linear equation where is a square, matrix with again only entries per row. For this setting, there already exists an efficient algorithm due to Wiedemann [Wie86], which would yield time with our parameters:
Lemma 4.2 (Sparse Linear Equation Solving [Wie86]). There is a randomized algorithm that, given a matrix and a vector , returns a uniformly random solution to (or reports that no such solution exists) in time .
In fact, the same paper gives algorithms for the rectangular setting, however for our parameters the running time bound becomes , which is insufficient. The main bottleneck in Wiedemann's algorithm for rectangular matrices as well as follow-up improvements [KS91], is that they solve the rectangular case by first (implicitly) computing a basis of the row space. At this point, the algorithm only has to deal with many rows and we are basically back at the fast, square case from Lemma 4.2. However, even the state-of-the-art approach to compute the rank and such a linearly independent set of columns runs in time , or in our setting [CKL12]. Hence, these approaches cannot yield near-quadratic running time if .
Our idea is to replace this expensive reduction to the square case by a simpler one. Indeed, instead of computing a basis of the row space, it is sufficient to find rows that span the full row space, since then Wiedemann's algorithm (Lemma 4.2) solves the equation in time . We show that such an approximate basis can be computed efficiently with a relatively simple, randomized algorithm. The key insight behind this algorithm is the following win/win scheme: If many linearly independent rows are easy to detect because most subsets of rows have a high rank, then a small random subset of rows will also have a high rank. On the other hand, if very specific rows need to be selected to span the full row span, then a random subset of rows allows us to detect and remove many obsolete linearly dependent rows (using weaker but more efficient sparse linear algebra tools). Recursively applying the same idea yields an approximate basis after iterations. See Theorem 4.6 in Section 4.3 for a formal description of this algorithm.
4.2 Basic Sparse Linear Algebra
We rely on a basic computational fact due to Kaltofen and Saunders [KS91].
Lemma 4.3 (Sparse Rank Computation [KS91]). There is a randomized algorithm that, given a matrix , computes with high probability in time .
We will also rely on the following lemma which is implicit in [Wie86]; we provide a quick (and somewhat simplified) proof for convenience.
Lemma 4.4 ([Wie86]). Let be a matrix with rank at most , and let . Let be a matrix where each entry is sampled independently such that with probability the entry is uniformly random from , and with the remaining probability the entry is zero. Then,
Proof. It always holds that , so focus on the other direction. Put . Without loss of generality we can assume by removing all linearly dependent rows from . The goal is to show that the matrix contains a nonsingular minor.
Here, denotes the running time exponent of fast matrix multiplication.
To show this, we view the process of sampling in two stages. In the first stage, we sample a mask matrix , where each entry is * with probability . In the second stage we replace * by uniformly random field elements to obtain .
We start analyzing the first stage. Let be a maximum subset of linearly independent columns in , so . Let denote the matrix restricted to these columns (so that ), and let denote the submatrix of restricted to the rows in . Then can be viewed as the adjacency matrix of a bipartite graph with vertices on the left and vertices on the right, where each edge is sampled independently with probability . With probability , that graph contains a matching covering all vertices on the left [ER63]. Fix such a matching and let be its set of matched right vertices. This choice depends only on the mask.
Now focus on the second stage when we replace each * by a uniformly random field element to obtain H. For the moment, pretend that each random field element is instead a symbolic variable. Let x denote the set of these variables, and write to denote the resulting symbolic matrix. Let be its restriction to the columns in I, and let be its restriction to the rows in J and columns in I. By the previous paragraph, the determinant is not identically zero (viewed as a polynomial in x), as the chosen matching corresponds to a nonzero term in . The Cauchy–Binet formula further implies that
is not identically zero. Indeed, the monomial corresponding to the chosen matching has coefficient and cannot occur in any other summand, since its variables use exactly the rows in .
In other words, is a nonzero polynomial with degree at most . Thus, the Schwartz-Zippel lemma implies that substituting random field elements leads to with probability at most . Otherwise has a nonsingular minor and hence rank . Together with the first-stage failure probability, this proves the claimed bound.
Lemma 4.5 (Linear Dependence Testing). Let . There is a randomized algorithm that preprocesses (nonzero) vectors in time , and then supports the following queries: given , decide whether is linearly dependent from in time . Each query is answered correctly with probability .
Proof. Let be the matrix with rows , and compute by Lemma 4.3. We first describe a simple algorithm for the special case that , and then later give a reduction to this case. If then all queries are trivial. If , then the kernel of has dimension exactly 1, and thus for some nonzero . We can
By Hall’s theorem, a matching covering the left side fails to exist only if there is a set L of k left vertices whose neighbors are contained in a set of k - 1 right vertices. A union bound gives failure probability at most
Here we used that and thus , , and . If , the statement is trivially satisfied.
compute one such by solving one equation system with Lemma 4.2. The total preprocessing time is
Now focus on the query phase. A vector is linearly dependent from if and only if . Indeed, if and only if the matrix with row vectors , has no nontrivial kernel and thus has full rank. Thus, upon query of a vector it suffices to evaluate the inner product in time .
It remains to reduce to the case . So suppose that . We sample as in Lemma 4.4. That is, we let , and we independently choose each entry to be 0 with probability and to be a uniformly random field element with probability . We compute the vectors defined by (viewing as a row vector). Analogously, we write for the matrix with rows . Then Lemma 4.4 implies that with high probability, and thus we have , which is as desired as takes the new role of .
Upon query of a vector , the goal is to check whether is linearly dependent from . We instead compute and query whether is linearly dependent from . The claim is that these two conditions are equivalent (with high probability). Indeed, consider the matrix with row vectors and the matrix with row vectors . Then clearly . Moreover, is linearly independent from if and only if . By Lemma 4.4, this is further equivalent to , and so the correctness follows. The error probability is per query. Rescaling by a constant factor gives the stated guarantee.
We finally analyze the running time per query. Each row of contains at most nonzero entries with high probability. Thus, with high probability the computation of takes time , and the resulting vector satisfies . Querying in the data structure described before takes time . All in all, the query time is as claimed.
4.3 Solving the Rectangular Case
Theorem 4.6 (Approximate Basis Computation). There is a randomized algorithm that, given t-sparse vectors , selects a subset of size such that each vector in is linearly dependent from the vectors . The algorithm runs in time and succeeds with high probability provided that .
Proof. The algorithm is as follows. If , then select all vectors. Otherwise, . In this case our goal is to remove many vectors. Note that a vector can always be safely removed if it is linearly dependent from the other remaining ones.
Specifically, select uniformly at random of size . Preprocess these vectors by Lemma 4.5 (with parameter , where denotes the original input size). Then scan over all other indices , and test whether is linearly dependent from . If it is linearly dependent, we delete . Once this process stops, we recurse on the set of non-deleted vectors.
It is clear that the algorithm is correct (provided it terminates). It remains to argue that the algorithm makes progress. To argue this, analyze the process of sampling T in steps. Initially, T is empty. After each step we select an index from uniformly at random and include it into T.
Before sampling the k-th index, let
There are two cases:
(i) If : Then with probability more than the rank of the selected vectors increases by including a uniformly random into . Let denote the first time that . In each step before , the rank of the selected rows increases with (conditional) probability at least . Since the rank cannot exceed , we must have . By Markov's inequality it follows that . In other words, with probability at least there is a step in which we reach case (ii):
(ii) If : Then at least of the remaining vectors are linearly dependent from . Among those, the algorithm may select up to , but the others will certainly be deleted. Thus, the number of deleted vectors is at least
Putting both arguments together, the algorithm deletes at least vectors with probability at least . It follows that the recursion depth is at most (in expectation, and also with high probability by a simple Chernoff bound).
Finally, we analyze the running time and error probability. The set can be selected in time . Preprocessing the selected vectors by Lemma 4.5 takes time . Each of the queries takes time , so the total time per recursive call is . As argued before, the total overhead due to the recursion is at most . Moreover, each of the queries fails with probability at most . By a union bound, the total error probability is thus .
Proof of Theorem 4.1. To solve the given equation system , we first run Theorem 4.6 to select a submatrix of consisting of rows but with the same rank. Let be the restriction of to the same set of rows. We then compute a uniformly random solution to the equation system by Lemma 4.2; if no such solution exists we report so. We then test whether . If yes, then the equation system is consistent and we report . If no, then the equation system is inconsistent and there cannot be a solution.
The running time of Theorem 4.6 is and the running time of Lemma 4.2 is . All other steps can be implemented in time .
5 Algorithm for Unknown C
We show how the proof of Theorem 1.1 can be adapted to solve the variant of preprocessed 3SUM where one of the three sets is not known during the preprocessing phase. All known algorithms for integer preprocessed 3SUM also give bounds for this setting [CL15, CVX23, KPS25, KKMV26, CKK26]. Note that this task does not make sense in the single-set version of 3SUM, so we have to work with multiple sets in this section. To make it easier to apply our linear algebra toolkit, we work with a slightly odd-looking, two-set problem definition:
Definition 5.1 (Preprocessed 3SUM with Unknown C). Preprocess a given set of numbers A of size n, to support the following queries: Given and any set C of size n, decide if there is a solution to .
It is again simple to convince yourself that this two-set definition is equivalent to the standard three-set definition via standard reductions [DGS20].
In this section, we prove the following reduction.
Theorem 5.2. If Preprocessed 3SUM with Unknown C with integer inputs (over the word RAM model) can be solved in preprocessing time and query time , then Preprocessed 3SUM with Unknown C with real inputs (over the real RAM model ) can be solved in preprocessing time and query time .
Let us comment on the main issues we face when adapting our algorithm to the setting with unknown and how we circumvent them. Recall that our reduction works by simply writing down all 3SUM-solutions that the real instance satisfies, followed by solving a sparse linear equation system of size with up to nonzero entries. However, without knowing one of the three sets, we a priori cannot write down any 3SUM-equation that should be satisfied. Instead, a natural idea is to write down four-term equations over , which are enough to pinpoint all necessary information about in the instance. The remaining issue is that the number of these equations can be up to (since three numbers determine the fourth), leading to a blow-up in the size of the equation system.
We resolve this issue by constructing a smaller equation system that still encodes the required additive information as follows: We make sure that each pair is involved in at most two equations, leading to again only many rows in our matrix. We choose the equations in such a way that all missing equalities will be implied by transitivity. Together, with the state-of-the-art algorithm for integers due to Kasliwal, Polak, and Sharma [KPS25], we then arrive at an algorithm for reals with the same guarantees.
Corollary 5.3. Preprocessed 3SUM with Unknown C with real inputs (over the real RAM model) can be solved in preprocessing time and query time .
Proof of Theorem 5.2. Like in the proof of Theorem 1.1, we can assume without loss of generality that the given algorithm for integer inputs solves the version of Preprocessed 3SUM with Unknown (where is a prime and solutions are modulo ).
We first describe the preprocessing phase, where we are given a set . We denote the entries of by arbitrarily and maintain a set , which is initially empty. We start by sorting the set of all pairs by their sum in non-decreasing order in time . Then, we consider all choices of consecutive pairs and in this ordering. If , we insert into .
Next, sample a uniformly random prime in the range , and consider the matrix of size over , where the row corresponding to is now exactly . Compute a random solution to by one call to Theorem 4.1 and give the set of entries of to the integer algorithm to preprocess.
Note that this algorithm works in a real RAM model that is as restricted as the algorithm of Theorem 1.1, except for also allowing comparisons involving four input reals, that is, of the form “ ?”.
Now, in the query phase, we receive as well as another set which we turn into a suitable query set for the integer algorithm. For each , we start by binary searching the prepared sorted set of pairs to check if there is a pair with . If such a pair exists, we add to . Otherwise, cannot be part of a solution, regardless of , so we can safely discard it. Finally, we hand to the integer algorithm and return the query output. The correctness of the algorithm immediately follows from the following claim since for some is then equivalent to .
Claim 5.4. With high probability, if and only if for all .
Proof. Apply the Frank–Tardos theorem (Theorem 3.1) on to obtain integers bounded by such that if and only if . We claim that, with high probability, this is further equivalent to . Indeed, the only failure event is when and divides . This number has at most prime divisors, thus the probability of selecting among these bad choices is at most by the Prime Number Theorem. By a union bound over the choices of , the total error probability is .
Thus, view as an element of . By construction we have (now viewed over ). Sampling a uniformly random kernel element can therefore be equivalently viewed as sampling and a uniformly random scalar , and setting . But then, for any quadruple with we have that . Since and since is sampled uniformly and independently, it follows that also is uniformly distributed in . The probability of hitting zero is thus , and by a union bound over all non-solution quadruples the total error probability is .
We finally analyze the running time. Preparing the sorted set of pairs as well as takes time . The call to Theorem 4.1 is with parameters and , and thus takes time , too. Finally, we preprocess one instance of Preprocessed 3SUM with Unknown over (or two integer instances) in time . In the query phase, we perform binary searches over a set of size and then issue two queries to respective two integer instances taking time . The total query time is therefore , as claimed.
AI Disclosure
In an early stage of this project, the authors asked ChatGPT 5.6 Sol for a weaker but more efficient real-to-integer hash function than provided by the Frank–Tardos theorem that can exactly maintain 3SUM solutions. The LLM suggested the general approach based on linear algebra outlined below Observation 3.2 without running time analysis. The authors then developed the remaining tools based on sparse linear algebra and the full algorithm without AI tools.
Finally, AI tools (ChatGPT 6 Astra) have been used to assist in drafting parts of the introduction and review the technical sections. The authors assume full responsibility.
References
[ABF23] Amir Abboud, Karl Bringmann, and Nick Fischer. Stronger 3-sum lower bounds for approximate distance oracles via additive combinatorics. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing (STOC 2023), pages 391–404. ACM, 2023. doi:10.1145/3564246.3585240.
[AC05] Nir Ailon and Bernard Chazelle. Lower bounds for linear degeneracy testing. Journal of the ACM, 52(2):157–171, 2005. doi:10.1145/1059513.1059515.
[AV26] Josh Alman and Virginia Vassilevska Williams. Truly subquadratic 3SUM and truly subcubic APSP via triangles in sparse lopsided graphs, 2026. URL: https://arxiv.org/abs/2610.06783, arXiv:2610.06783.
[BFN22] Karl Bringmann, Nick Fischer, and Vasileios Nakos. Deterministic and las vegas algorithms for sparse nonnegative convolution. In Proceedings of the 2022 ACM-SIAM Symposium on Discrete Algorithms (SODA 2022), pages 3069–3090. SIAM, 2022. doi:10.1137/1.9781611977073.119.
[BNW25] Aaron Bernstein, Danupon Nanongkai, and Christian Wulff-Nilsen. Negative-weight single-source shortest paths in near-linear time. Journal of the ACM, 72(4):23:1–23:34, 2025. Announced at FOCS 2022. doi:10.1145/3742890.
[BS94] Antal Balog and Endre Szemerédi. A statistical theorem of set addition. Combinatorica, 14(3):263–268, 1994. doi:10.1007/BF01212974.
[BW12] Nikhil Bansal and Ryan Williams. Regularity lemmas and combinatorial algorithms. Theory of Computing, 8(1):69–94, 2012. Announced at FOCS 2009. doi:10.4086/TOC.2012.V008A004.
[CH02] Richard Cole and Ramesh Hariharan. Verifying candidate matches in sparse and wildcard matching. In John H. Reif, editor, Proceedings on 34th Annual ACM Symposium on Theory of Computing (STOC 2002), pages 592–601. ACM, 2002. doi:10.1145/509907.509992.
[CKK26] Amir Carmel, Yakov Kosoburd, and Robert Krauthgamer. Recovery beats storage: Improved space for preprocessed 3SUM, 2026. URL: https://arxiv.org/abs/2608.22355, arXiv:2608.22355.
[CKL12] Ho Yee Cheung, Tsz Chiu Kwok, and Lap Chi Lau. Fast matrix rank algorithms and applications. In Proceedings of the Forty-Fourth Annual ACM Symposium on Theory of Computing (STOC 2012), page 549–562. ACM, 2012. doi:10.1145/2213977.2214028.
[CL15] Timothy M. Chan and Moshe Lewenstein. Clustered integer 3sum via additive combinatorics. In Proceedings of the Forty-Seventh Annual ACM on Symposium on Theory of Computing (STOC 2015), pages 31–40. ACM, 2015. doi:10.1145/2746539.2746568.
[CL23] Eldon Chung and Kasper Green Larsen. Stronger 3sum-indexing lower bounds. In Proceedings of the 2023 ACM-SIAM Symposium on Discrete Algorithms, (SODA 2023), pages 444–455. SIAM, 2023. doi:10.1137/1.9781611977554.CH19.
[CP09] Timothy M. Chan and Mihai Pătrașcu. Transdichotomous results in computational geometry, I: point location in sublogarithmic time. SIAM Journal on Computing, 39(2):703–729, 2009. doi:10.1137/07068669X.
[CVX22] Timothy M. Chan, Virginia Vassilevska Williams, and Yinzhan Xu. Hardness for triangle problems under even more believable hypotheses: reductions from real APSP, real 3SUM, and OV. In 54th Annual ACM SIGACT Symposium on Theory of Computing (STOC 2022), pages 1501–1514. ACM, 2022. doi:10.1145/3519935.3520032.
[CVX23] Timothy M. Chan, Virginia Vassilevska Williams, and Yinzhan Xu. Fredman's trick meets dominance product: Fine-grained complexity of unweighted apsp, 3sum counting, and more. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing, (STOC 2023), pages 419–432. ACM, 2023. doi:10.1145/3564246.3585237.
[DG26] Itai Dinur and Alexander Golovnev. Improved time-space tradeoffs for 3sum-indexing. In 53rd International Colloquium on Automata, Languages, and Programming (ICALP 2026), pages 78:1–78:17. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2026. doi:10.4230/LIPICS.ICALP.2026.78.
[DGS20] Bartłomiej Dudek, Paweł Gawrychowski, and Tatiana Starikovskaya. All non-trivial variants of 3-ldt are equivalent. In 52nd Annual ACM Symposium on Theory of Computing (STOC 2020), pages 974–981. ACM, 2020. doi:10.1145/3357713.3384275.
[DKPVW20] Lech Duraj, Krzysztof Kleiner, Adam Polak, and Virginia Vassilevska Williams. Equivalences between triangle and range query problems. In 31st Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2020), pages 30–47. SIAM, 2020. doi:10.1137/1.9781611975994.3.
[Eis10] Friedrich Eisenbrand. Integer programming and algorithmic geometry of numbers - A tutorial. In 50 Years of Integer Programming 1958-2008 - From the Early Years to the State-of-the-Art, pages 505–559. Springer, 2010. doi:10.1007/978-3-540-68279-0_14.
[ER63] Paul Erdős and Alfred Rényi. On random matrices. Publ. Math. Inst. Hungar. Acad., 8:455–461, 1963.
[Eri95] Jeff Erickson. Lower bounds for linear satisfiability problems. In Proceedings of the Sixth Annual ACM-SIAM Symposium on Discrete Algorithms, (SODA 1995), pages 388–395. ACM/SIAM, 1995. doi:10.5555/313651.313772.
[Fin24] Jeremy T. Fineman. Single-source shortest paths with negative real weights in time. In Proceedings of the 56th Annual ACM Symposium on Theory of Computing (STOC 2024), pages 3–14. ACM, 2024. doi:10.1145/3618260.3649614.
[Fis25] Nick Fischer. Sumsets, 3SUM, subset sum: Now for real! In Proceedings of the 2025 Annual ACM-SIAM Symposium on Discrete Algorithms, (SODA 2025), pages 4520–4546. SIAM, 2025. doi:10.1137/1.9781611978322.155.
[FJX25] Nick Fischer, Ce Jin, and Yinzhan Xu. New applications of 3sum-counting in fine-grained complexity and pattern matching. In Proceedings of the 2025 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2025), pages 4547–4595. SIAM, 2025. doi:10.1137/1.9781611978322.156.
[FPS26] Nick Fischer, Adam Polak, and Jonas Schmidt. 3SUM is really hard: A real-to-integer reduction, 2026. To appear in FOCS 2026. URL: https://arxiv.org/abs/2610.10153, arXiv:2610.10153.
[FT87] András Frank and Éva Tardos. An application of simultaneous diophantine approximation in combinatorial optimization. Combinatorica, 7(1):49–65, 1987. doi:10.1007/BF02579200.
[GGH 20] Alexander Golovnev, Siyao Guo, Thibaut Horel, Sunoo Park, and Vinod Vaikuntanathan. Data structures meet cryptography: 3sum with preprocessing. In Proceedings of the 52nd Annual ACM SIGACT Symposium on Theory of Computing (STOC 2020), pages 294–307. ACM, 2020. doi:10.1145/3357713.3384342.
[GKLP17] Isaac Goldstein, Tsvi Kopelowitz, Moshe Lewenstein, and Ely Porat. Conditional lower bounds for space/time tradeoffs. In Algorithms and Data Structures - 15th International Symposium, (WADS 2017), pages 421–436. Springer, 2017. doi:10.1007/978-3-319-62127-2_36.
[Gow01] Timothy W. Gowers. A new proof of Szemerédi's theorem. GAFA Geometric And Functional Analysis, 11:465–588, 2001. doi:10.1007/s00039-001-0332-9.
[HLLZ26] Isaac M. Hair, George Z. Li, Jason Li, and Junkai Zhang. Bellman-ford in almost-linear time, 2026. arXiv:2607.19346.
[JX23] Ce Jin and Yinzhan Xu. Removing additive structure in 3sum-based reductions. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing (STOC 2023), pages 405–418. ACM, 2023. doi:10.1145/3564246.3585157.
[KKMV26] Yael Kirkpatrick, John Kuszmaul, Surya Mathialagan, and Virginia Vassilevska Williams. Preprocessed 3sum for unknown universes with subquadratic space. In 53rd International Colloquium on Automata, Languages, and Programming (ICALP 2026), pages 126:1–126:13. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2026. doi:10.4230/LIPICS.ICALP.2026.126.
[KP19] Tsvi Kopelowitz and Ely Porat. The strong 3sum-indexing conjecture is false, 2019. arXiv:1907.11206.
[KPS25] Shashwat Kasliwal, Adam Polak, and Pratyush Sharma. 3SUM in preprocessed universes: Faster and simpler. TheoretiCS, 4, 2025. doi:10.46298/THEORETICS.25.24.
[KS91] Erich L. Kaltofen and B. David Saunders. On wiedemann's method of solving sparse linear systems. In 9th International Symposium on Applied Algebra, Algebraic Algorithms and Error-Correcting Codes (AAECC 1991), volume 539 of Lecture Notes in Computer Science, pages 29–38. Springer, 1991. doi:10.1007/3-540-54522-0_93.
[TV06] Terence Tao and Van H. Vu. Additive Combinatorics. Cambridge Studies in Advanced Mathematics. Cambridge University Press, 2006. doi:10.1017/CB09780511755149.
[VWW18] Virginia Vassilevska Williams and R. Ryan Williams. Subcubic equivalences between path, matrix, and triangle problems. J. ACM, 65(5):27:1–27:38, 2018. doi:10.1145/3186893.
[Wie86] Douglas H. Wiedemann. Solving sparse linear equations over finite fields. IEEE Transactions on Information Theory, 32(1):54–62, 1986. doi:10.1109/TIT.1986.1057137.
A Preprocessed 3SUM with Subquadratic Preprocessing Time
In this section, we demonstrate how the recent subquadratic-time algorithm for 3SUM [AV26] can be turned into an algorithm for Preprocessed 3SUM with subquadratic preprocessing time and query time:
Theorem A.1. Preprocessed 3SUM with integer inputs (over the word RAM model) can be solved with preprocessing time and query time , for some absolute constant .
We have made no attempt to optimize the constants in this section. Besides [AV26], the proof of Theorem A.1 requires ideas from two further sources: the state-of-the-art algorithm for integer Preprocessed 3SUM [KPS25], and a line of work on algorithms for structured 3SUM instances [CL15, ABF23, JX23, FJX25] based on the Balog–Szemerédi–Gowers (BSG) theorem from additive combinatorics [BS94, Gow01] and sparse convolutions [CH02, BFN22]. We start by gathering the required tools.
The following theorem states an algorithmic version of the BSG theorem; see e.g. [ABF23, Appendix B] for a proof. Here, for an integer set , the additive energy is .
Theorem A.2 (Algorithmic BSG Theorem). Let be an integer set with . Then there is a subset such that:
(i) , and
(ii)
The set can be computed in time by a randomized algorithm.
Corollary A.3. Let be an integer set, and let be an integer. There is a partition such that:
(i)
(ii)
The partition can be computed in time by a randomized algorithm.
Proof. We keep a working set that is initially . In each step we call Theorem A.2 on (with some parameter to be determined) to extract some structured subset , remove from and continue. Once , we put and stop. In each step we remove at least an -fraction of the elements of ; thus, after steps the algorithm is forced to stop. For this reason, we may pick .
Property (i) is clear by construction. For Property (ii), a simple application of the Cauchy–Schwarz inequality suffices to bound the number of solutions to by at most . The running time follows from the running time of Theorem A.2 and the fact that we can approximately compute the energy using few samples by a Chernoff bound.
We also rely on the following basic inequality from additive combinatorics; see, e.g., [TV06, Corollary 6.29].
Lemma A.4 (Plünnecke–Ruzsa). Let . If , then for all integers .
And finally we rely on a subroutine to efficiently compute structured sumsets. The following lemma is immediate from [BFN22].
Lemma A.5. There is a deterministic algorithm that, given sets , counts the number of 3SUM solutions with in time .
Proof of Theorem A.1. The algorithm combines ideas from three different lines of work. First, suppose that the given set A contains at most 3SUM solutions for some constant . We will later reduce to this case.
The first idea is to follow the ideas of Kasliwal, Polak and Sharma [KPS25]. In the preprocessing phase we sample a uniformly random prime in the interval . A standard argument shows that any integer triple with satisfies with probability at most . Let us call such a triple a false positive. Then by Markov's bound, with constant probability, the total number of false positives is at most . The idea is to list all false positives in the preprocessing stage; we will describe how to implement this step efficiently in a minute. Upon query of a subset we will then count all solutions with . This can be implemented by FFT in time . We then enumerate all false positives , and subtract 1 whenever . What remains is the true number of 3SUM solutions in . We report YES if and only if that count is positive.
Second, we describe how to efficiently list all false positives. This is based on the recent -time algorithm for 3SUM [AV26]. A well-known result in fine-grained complexity is that if 3SUM can be solved in time , then there is also an algorithm to list up to 3SUM solutions in time (see, e.g., [VWW18, DKPVW20, FPS26]). In particular, we can afford to list all solutions with . These include the at most true solutions (by our initial assumption) plus at most false positives. Afterwards, we scan over the whole list and only retain the false positives. The total time is truly subquadratic, .
Third, it remains to remove the assumption that the number of 3SUM solutions in is at most . Let and be parameters with small to be determined. We first partition the set by Corollary A.3 into structured parts and an unstructured remainder . For each set , we further define a partition so that
• for each , , and
• for each , .
These partitions can easily be computed in total time by sampling (see [FJX25] for a deterministic implementation).
We now follow the same approach as before with the exception that we will not list all false positives. Specifically, we distinguish three types of modular solutions with :
-
-
and ,
-
and .
Corollary A.3 implies that there are at most modular solutions of type (1). We can afford to list these exactly as before in time . Moreover, for each , there are at most modular solutions of type (2), so these can be listed in subquadratic preprocessing time per , and therefore time in total.
This only leaves the false positives of type (3). These we cannot list explicitly. Instead, we will compute the number of false positives of type (3) only in the query phase. That is, given , the goal is to compute
In fact, we will compute as the difference defined by
The quantity can be evaluated by one call to Lemma A.5 in time . The quantity can be evaluated similarly, along with the usual trick to count modular solutions by computing integer solutions for the instance with and without overflow. The running time is also .
To bound the total running time, suppose (only for the sake of the analysis) that a set is sampled uniformly at random with rate . This rate is chosen such that, with high probability, each is involved in at least one solution with and . In other words, . Thus, we can bound the sumset size by
To further bound we apply the Plünnecke–Ruzsa inequality (Lemma A.4) and the fact that has doubling at most . Moreover, the expected size of is . Thus,
and the total time to compute the number of false positives of type (3) can thus be bounded by
All in all, we have worsened the preprocessing time by computing the partitions in time and listing the modular solutions of types (1) and (2) in time , and we have worsened the query time by . For example, choosing and keeps the preprocessing time truly subquadratic and the query time .