Manuscript Offprint
arXiv:2610.41048Faster #PPM from faster #3SAT
Abstract
The counting variant (#PPM) of the permutation pattern matching (PPM) problem asks for the number of occurrences of a permutation pattern in a host permutation of length . The problem admits faster algorithms than the trivial time enumeration; the best known running time, for both PPM and #PPM, is (Gawrychowski and Rzepecki). It is also known that PPM is ETH-hard: an algorithm with running time would imply a subexponential algorithm for 3SAT (Jelínek, Opler, and Pekárek).
We give a reduction in the opposite direction, showing that an algorithm for counting satisfying assignments of a 3-CNF formula (#3SAT) in time , where is the number of variables, yields an algorithm for #PPM with running time . In particular, the recently claimed refutation of ETH by OpenAI implies a #3SAT algorithm with an improvement factor in the exponent; this yields, through our reduction, a subexponential algorithm for #PPM.
Note: This is a technical report not intended for conference or journal publication. AI tools were used interactively to derive and check essential parts of the result; the writeup is by the author.
1 Introduction
In this short note we show that a subexponential algorithm for #3SAT (counting satisfying assignments of a 3-CNF formula) implies a subexponential algorithm for #PPM (counting occurrences of a permutation pattern in a host permutation). Previous work established hardness results for PPM and #PPM under the exponential-time hypothesis (ETH), i.e., through reductions from 3SAT to PPM. Here, we give a reduction in the opposite direction.
The motivation for our study is the recent claim [Ope26] of a subexponential algorithm for #3SAT (which, in particular, refutes ETH). We find the change of perspective from “reducing for hardness” to “reducing for easiness” refreshing, allowing the re-use of techniques and tricks familiar from practical SAT solving. We anticipate that results of this flavor will be established for many problems, and we see #PPM as an interesting and simple, yet not entirely trivial, case study.
A permutation of size is a bijection , viewed alternatively as the sequence . We refer to as the value corresponding to index .
Given permutations and of size and respectively, with , an occurrence of in is a set of indices , whose corresponding values in are in the same relative order as the pattern , i.e.
For example, is an occurrence of pattern in , since the values are ordered like . Another occurrence of the same pattern is .
Let denote the number of occurrences of in . Permutation pattern matching (PPM) asks whether and its counting version () asks to compute .
Both PPM and #PPM are well-studied problems. A naive enumeration algorithm (check all subsets of size ) solves both, running in time . A series of improvements [BL16, BKM21, GR22] led to the current best runtime of for both problems, found by Gawrychowski and Rzepecki.
In the setting where the pattern size is separately considered, an algorithm with runtime was given by Berendsohn, Kozma, and Marx [BKM21] for both PPM and #PPM. For PPM, an algorithm with runtime of the form was found by Guillemot and Marx [GM14], with a subsequent improvement to by Fox [Fox13]. These latter results established the FPT status of PPM; note that they do not transfer to #PPM.
On the complexity side, Jélinek, Opler, and Pekárek [JOP21] showed that, assuming the exponential-time hypothesis (ETH), PPM does not admit a runtime of (the existence of such an algorithm would imply solving 3SAT in time ). Berendsohn, Kozma, and Marx [BKM21] ruled out, also under the ETH, a runtime of the form for #PPM.
In this paper we study the complexity of #PPM assuming the “easiness” of #3SAT. We establish that a subexponential algorithm for #3SAT implies a subexponential algorithm for #PPM (and consequently for PPM), improving the previous exponential bounds. We focus on running times expressed in terms of only.¹
Theorem 1.1. An algorithm for #3SAT with running time implies an algorithm for #PPM with running time .
Here is assumed to be a non-decreasing, efficiently computable function satisfying for all sufficiently large . In particular, the claimed breakthrough for #3SAT [Ope26] implies a function in the exponent of the running time. This yields (assuming that the result holds), an algorithm for #PPM with runtime .
Idea of the reduction. The natural idea is to encode the set of indices of an occurrence as a bitvector of length , and design a circuit (eventually converted to a 3-CNF formula) that verifies whether indeed describes a valid occurrence of in . A straightforward implementation would do a pass through the text permutation , counting for each index that is in , the number of values smaller than the current value , corresponding to already seen indices from ; these counts should then be compared to those of the pattern permutation , to verify the match. This approach involves, however, operations and comparisons with possibly -bit numbers, resulting in a circuit with variables. To take advantage of a (slightly) subexponential #3SAT algorithm, we need a circuit of size close to linear.
To get around this issue, we split into blocks of size . Both the space of indices and the space of values are partitioned into such blocks, and we “guess” for an occurrence of in how many indices fall into each index-block and how many corresponding values fall into each value-block.
Assuming these guesses are correct, verifying whether a given occurrence set (represented as a length bitvector) is correct becomes easier. Indeed, one only needs to check whether each index- and value-block has the correct number of items selected, and whether the selected indices and values indeed describe the pattern permutation . For the latter task, we can aggregate the block counts offline, and the Boolean circuit only needs to work with local counts inside blocks, represented by bits. A further optimization allows parts of the circuit to be reused for multiple equality tests. This gives gates per index, for a final 3-CNF formula of size .
¹We note that the bounds parameterized by mentioned earlier remain preferable to the new bounds derived here, for smaller values of , e.g., when .
For a suitably chosen value , both the guessing (iterating through all feasible block-counts) and the #3SAT subroutine take similar subexponential time, yielding the overall speedup.
We describe the detailed reduction (proving Theorem 1.1) in the next section.
Intuitively, is the -th smallest selected index, and is the -th smallest selected value. In the earlier example, the indices 3, 5, 6 in have index-ranks 1, 2, 3 and value ranks 3, 1, 2, which is the pattern itself. This holds in general, as shown in the next lemma.
Lemma 2.1. A set with is an occurrence of if and only if for every .
Proof. Write , so the selected indices up to are exactly , with . Moreover, numbers the selected indices in increasing order of their values: for all , we have if and only if . If is an occurrence, the values are ordered like the , so . Conversely, if for all , then , so is an occurrence.
By Lemma 2.1, it suffices to encode each index with a Boolean variable , setting exactly when . Then, a circuit can compute the ranks of selected indices in binary and verify , for all . If , however, explicitly representing these ranks already requires variables, leading to no improvement through a (slightly) subexponential #3SAT solver.
Blocks. To facilitate a more compact encoding, partition into consecutive blocks. Precisely, let (an integer to be chosen later) and let . For , the -th block is the interval . Note that the same intervals will be used both as blocks of indices and as blocks of values. For an index , let be the index of the block containing , and the index of the block containing its value .
Profiles. A profile is a pair of nonnegative integer vectors of length , intended to specify the numbers of selected entries in each index-block and value-block. A profile is valid if for every , and both and sum to .
A set has profile if
Every subset of of size has exactly one valid profile, although a valid profile need not be realized by any set. There are at most valid profiles (each of the index-blocks and value-blocks has a count between 0 and ). For a valid profile , let denote the number of occurrences of in that have this profile.
Offsets and local counts. Let be a valid profile. As we pass through the text permutation , we keep track of the total counts in earlier blocks, as follows:
We refer to and as the index- and value offsets of .
For a set of occurrence indices, and an index , we also need to count the entries that come before , within the block of . We refer to these as the local counts, defined as follows:
Both local counts take values in .
Lemma 2.2. If has profile , then every satisfies
Proof. The selected indices up to are the selected indices in earlier blocks, plus the selected indices before in its own block, plus itself. The same argument for the values gives the second identity.
For example, take , , , and . The blocks are , , . The profile of is and . For , with value , Lemma 2.2 gives and , in agreement with .
Lookup tables. Lemmas 2.1 and 2.2 allow us to formulate the occurrence condition as an equation between the two local counts of each selected index. Fix a valid profile . For and with , let
and let be the set of these with . In words: a selected index with local count agrees with the pattern exactly when its other local count equals .
Lemma 2.3. Let have profile . Then is an occurrence of if and only if every satisfies and .
Proof. Since , Lemma 2.1 applies. By Lemma 2.2, , and the condition is equivalent to . Since , this equality implies that .
2.1 Constructing a formula for each profile
Fix a valid profile . We construct a corresponding 3-CNF formula with variables, so that the number of satisfying assignments equals . This allows using a #3SAT solver for counting the number of occurrences for the given profile. We proceed in two steps, first constructing a Boolean circuit, then converting it into a 3-CNF formula.
Circuit construction. We build a circuit with one input bit for each index , interpreted as if and only if . We define , so that the numbers fit into bits.
We use AND, OR, and XOR gates of fan-in at most two, with constants and complemented wires allowed. An -bit incrementer adds a bit to an -bit number using gates (ripple carry). (In)equality of two -bit numbers is tested using XOR gates and an OR of the outputs. Larger conjunctions and disjunctions can be implemented as binary trees, consisting of gates of fan-in two; a conjunction or disjunction of inputs requires gates.
The circuit has the following four components:
-
Index counters. In each block , we go through the indices in increasing order. The first index gets , and every later index gets , computed with an incrementer. For the last index of the block, we test that , i.e., that the count of selected indices in the block matches the count in the profile.
-
Value counters. In each block , we go through the values in increasing order and do the same, with counters and the input bit of the index that corresponds to value . For the last value of the block, we test that .
-
Lookup at . We use a standard binary decoder circuit with an -bit input and a -bit output. The -th output bit, for , is 1 if and only if represents the integer in binary, so exactly one output bit is 1.
Such a decoder circuit can be constructed recursively as follows. For a single input bit , the two outputs are simply and . When one more (less significant) input bit is appended, a number becomes . Thus each existing output gives rise to two new outputs,
Extending the decoder from to bits therefore requires binary AND gates, so the entire circuit uses
gates. At each index , construct one such decoder for and another for . Denote their relevant outputs by and , where indicates whether , and indicates whether .
Compute
The value ok(p) indicates whether index is valid within the given occurrence. If is not selected (), then there is nothing to check. Otherwise, match(p) verifies the condition of Lemma 2.3.
The empty disjunction is interpreted as false. Besides the decoders, this uses at most binary AND gates, at most binary OR gates, and one final OR gate. Thus the entire lookup at uses gates of fan-in at most two.
- Output. A final AND of the 2B tests from parts 1 and 2 and the bits ok(p).
Size. Parts 1 and 2 use gates per index and per value, part 3 uses gates per index, and part 4 uses gates. Thus
This count also includes the gates used to replace larger conjunctions and disjunctions by binary trees.
Lemma 2.4. if and only if the set is an occurrence of with profile .
Proof. No count exceeds , so the incrementers never overflow. Induction along each block gives and . Hence the tests of parts 1 and 2 hold exactly when has profile .
The decoder outputs satisfy
Consequently, match if and only if and . Thus ok if and only if either , or these two conditions hold. Together with the profile tests, Lemma 2.3 proves the claim.
2.2 From circuit to 3-CNF formula
The standard Tseitin-transformation turns a circuit into a 3-CNF formula without changing the number of accepted inputs.
Lemma 2.5. Let be a circuit with inputs and size . A 3-CNF formula with variables and at most clauses can be computed in polynomial time such that .
Proof. The formula has a variable for each input and each gate. For each gate it has the clauses stating that the value equals the gate's function of its two signals. For OR, AND, and XOR gates this is possible with at most four clauses (of size at most 3) per gate, also handling negated and constant inputs (details omitted). A final singleton clause asserts the output gate. The construction guarantees that for every assignment , the gate clauses have exactly one satisfying extension to the gate variables, namely the values computed by the corresponding gates in on input . This extension satisfies the final clause if and only if .
Applying Lemma 2.5 to gives the formula . It has
variables and clauses, and by Lemma 2.4 its number of satisfying assignments is
Algorithm. The algorithm chooses , builds for every valid profile , counts its satisfying assignments with the assumed #3SAT solver, and outputs the sum of the counts. Since every occurrence has exactly one profile,
so the output is correct. Each count is at most , so each addition takes polynomial time.
Running time. There are at most valid profiles, and hence calls. Each formula has variables for an absolute constant , and polynomially many clauses. Each call takes time at most , for an absolute constant , and . The total time is , where
Take . Then and . Both terms of have the same order:
and
Since for all sufficiently large , we have . Thus the polynomial factor is absorbed into the exponential bound, and the total running time is
References
[BKM21] Benjamin Aram Berendsohn, László Kozma, and Dániel Marx. Finding and counting permutations via CSPs. Algorithmica, 83(8):2552–2577, 2021.
[BL16] Marie-Louise Bruner and Martin Lackner. A fast algorithm for permutation pattern matching based on alternating runs. Algorithmica, 75(1):84–117, 2016.
[Fox13] Jacob Fox. Stanley-Wilf limits are typically exponential. CoRR, abs/1310.8378, 2013.
[GM14] Sylvain Guillemot and Dániel Marx. Finding small patterns in permutations in linear time. In Chandra Chekuri, editor, Proceedings of the Twenty-Fifth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2014, Portland, Oregon, USA, January 5-7, 2014, pages 82–101. SIAM, 2014.
[GR22] Pawel Gawrychowski and Mateusz Rzepecki. Faster exponential algorithm for permutation pattern matching. In Karl Bringmann and Timothy M. Chan, editors, 5th Symposium on Simplicity in Algorithms, SOSA@SODA 2022, Virtual Conference, January 10-11, 2022, pages 279–284. SIAM, 2022.
[JOP21] Vít Jélinek, Michal Opler, and Jakub Pekárek. Griddings of permutations and hardness of pattern matching. In Filippo Bonchi and Simon J. Puglisi, editors, 46th International Symposium on Mathematical Foundations of Computer Science, MFCS 2021, Tallinn, Estonia, August 23-27, 2021, volume 202 of LIPIcs, pages 65:1–65:22. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2021.
[Ope26] OpenAI. The exponential time hypothesis is false. OpenAI Math Release Preprint, October 2026. Available at the OpenAI Math GitHub Repository.