Giulia Bernardini
email: giulia.bernardini@unimib.it

Paweł Gawrychowski

Nadia Pisanti
email: pisanti@di.unipi.it

Solon P Pissis
email: solon.pissis@cwi.nl

Giovanna Rosone
email: giovanna.rosone@unipi.it

Elastic-Degenerate String Matching via Fast Matrix Multiplication

An elastic-degenerate (ED) string is a sequence of n sets of strings of total length N , which was recently proposed to model a set of similar sequences. The ED string matching (EDSM) problem is to find all occurrences of a pattern of length m in an ED text. The EDSM problem has recently received some attention in the combinatorial pattern matching community, and an O(nm 1.5 √ log m + N )-time algorithm is known [Aoyama et al., CPM 2018]. The standard assumption in the prior work on this question is that N is substantially larger than both n and m, and thus we would like to have a linear dependency on the former. Under this assumption, the natural open problem is whether we can decrease the 1.5 exponent in the time complexity, similarly as in the related (but, to the best of our knowledge, not equivalent) word break problem [Backurs and Indyk, FOCS 2016].

Our starting point is a conditional lower bound for the EDSM problem. We use the popular combinatorial Boolean Matrix Multiplication (BMM) conjecture stating that there is no truly subcubic combinatorial algorithm for BMM [Abboud and Williams, FOCS 2014]. By designing an appropriate reduction we show that a combinatorial algorithm solving the EDSM problem in O(nm 1.5-+ N ) time, for any > 0, refutes this conjecture. Our reduction should be understood as an indication that decreasing the exponent requires fast matrix multiplication.

String periodicity and fast Fourier transform are two standard tools in string algorithms. Our main technical contribution 1 is that we successfully combine these tools with fast matrix multiplication to design a non-combinatorial Õ(nm ω-1 + N )-time algorithm for EDSM, where ω denotes the matrix multiplication exponent and the Õ(•) notation suppresses polylog factors. To the best of our knowledge, we are the first to combine these tools. In particular, using the fact that ω < 2.373 [Le Gall, ISSAC 2014; Williams, STOC 2012], we obtain an O(nm 1.373 + N )-time algorithm for EDSM. An important building block in our solution, that might find applications in other problems, is a method of selecting a small set of lengthsubstrings of the pattern, called anchors, so that any occurrence of a string from an ED text set contains at least one but not too many such anchors inside.

Introduction

Boolean matrix multiplication (BMM) is one of the most fundamental computational problems. Apart from its theoretical interest, it has a wide range of applications [START_REF] Fischer | Boolean matrix multiplication and transitive closure[END_REF][START_REF] Furman | Application of a method of fast multiplication of matrices in the problem of finding the transitive closure of a graph[END_REF][START_REF] Itai | Finding a minimum circuit in a graph[END_REF][START_REF] Munro | Efficient determination of the transitive closure of a directed graph[END_REF][START_REF] Valiant | General context-free recognition in less than cubic time[END_REF]. BMM is also the core combinatorial part of integer matrix multiplication. In both problems, we are given two N ×N matrices and we are to compute N 2 values. Integer matrix multiplication can be performed in truly subcubic time, i.e., in O(N 3-) operations over the field, for some > 0. The fastest known algorithms for this problem run in O(N 2.373 ) time [START_REF] Gall | Powers of tensors and fast matrix multiplication[END_REF][START_REF] Williams | Multiplying matrices faster than Coppersmith-Winograd[END_REF]. These algorithms are known as algebraic: they rely on the ring structure of matrices over the field.

There also exists a different family of algorithms for the BMM problem known as combinatorial. Their focus is on unveiling the combinatorial structure in the Boolean matrices to reduce redundant computations. A series of results [START_REF] Arlazarov | On economical construction of the transitive closure of a directed graph[END_REF][START_REF] Bansal | Regularity lemmas and combinatorial algorithms[END_REF][START_REF] Chan | Speeding up the four Russians algorithm by about one more logarithmic factor[END_REF] culminating in an Ô(N 3 / log 4 N )-time algorithm [START_REF] Yu | An improved combinatorial algorithm for boolean matrix multiplication[END_REF][START_REF] Yu | An improved combinatorial algorithm for boolean matrix multiplication[END_REF] (the Ô(•) notation suppresses polyloglog factors) has led to the popular combinatorial BMM conjecture stating that there is no combinatorial algorithm for BMM working in time O(N 3-), for any > 0 [START_REF] Abboud | Popular conjectures imply strong lower bounds for dynamic problems[END_REF]. There has been ample work on applying this conjecture to obtain BMM hardness results: see , e.g., [START_REF] Abboud | Popular conjectures imply strong lower bounds for dynamic problems[END_REF][START_REF] Chatterjee | Optimal Dyck reachability for data-dependence and alias analysis[END_REF][START_REF] Henzinger | Unifying and strengthening hardness for dynamic problems via the online matrix-vector multiplication conjecture[END_REF][START_REF] Kopelowitz | Color-distance oracles and snippets[END_REF][START_REF] Larsen | On hardness of several string indexing problems[END_REF][START_REF] Lee | Fast context-free grammar parsing requires fast boolean matrix multiplication[END_REF][START_REF] Roditty | On dynamic shortest paths problems[END_REF].

String matching is another fundamental problem, asking to find all fragments of a string text of length n that match a string pattern of length m. This problem has several linear-time solutions [START_REF] Crochemore | Algorithms on strings[END_REF]. In many real-world applications, it is often the case that letters at some positions are either unknown or uncertain. A way of representing these positions is with a subset of the alphabet Σ. Such a representation is called degenerate string. A special case of a degenerate string is when at such unknown or uncertain positions the only subset of the alphabet allowed is the whole alphabet. These special degenerate strings are more commonly known as strings with wildcards. The first efficient algorithm for a text and a pattern, where both may contain wildcards, was published by Fischer and Paterson in 1974 [START_REF] Fischer | String matching and other products[END_REF]. It has undergone several improvements since then [START_REF] Clifford | Simple deterministic wildcard matching[END_REF][START_REF] Cole | Verifying candidate matches in sparse and wildcard matching[END_REF][START_REF] Indyk | Faster algorithms for string matching problems: Matching the convolution bound[END_REF][START_REF] Kalai | Efficient pattern-matching with don't cares[END_REF]. The first efficient algorithm for a standard text and a degenerate pattern, which may contain any non-empty subset of the alphabet, was published by Abrahamson in 1987 [START_REF] Abrahamson | Generalized string matching[END_REF], followed by several practically efficient algorithms [START_REF] Holub | Fast pattern-matching on indeterminate strings[END_REF][START_REF] Navarro | Nr-grep: a fast and flexible pattern-matching tool[END_REF][START_REF] Wu | Agrep -a fast approximate pattern-matching tool[END_REF].

Degenerate letters are used in the IUPAC notation [START_REF]Abbreviations and symbols for nucleic acids, polynucleotides, and their constituents[END_REF] to represent a position in a DNA sequence that can have multiple possible alternatives. These are used to encode the consensus of a population of sequences [START_REF] Alzamel | Degenerate string comparison and applications[END_REF][START_REF] Gawrychowski | On indeterminate strings matching[END_REF][START_REF]The Computational Pan-Genomics Consortium, Computational pan-genomics: status, promises and challenges[END_REF] in a multiple sequence alignment (MSA). In the presence of insertions or deletions in the MSA, we may need to consider alternative representations. Consider the following MSA of three closely-related sequences (on the left):

GCAACGGGTA--TT GCAACGGGTATATT GCACCTGG----TT

T = GCA • A C • C • G T • GG •    TA TATA ε    • TT
These sequences can be compacted into a single sequence T of sets of strings (on the right) containing some deterministic and some non-deterministic segments. A non-deterministic segment is a finite set of deterministic strings and may contain the empty string ε corresponding to a deletion. The total number of segments is the length of T and the total number of letters is the size of T . We denote the length by n = | T | and the size by N = || T ||. This representation has been defined in [START_REF] Iliopoulos | Efficient pattern matching in elastic-degenerate texts[END_REF] by Iliopoulos et al. as an elastic-degenerate (ED) string. Being a sequence of subsets of Σ * , it can be seen as a generalization of a degenerate string. The natural problem that arises is finding all matches of a deterministic pattern P in an ED text T . This is the elastic-degenerate string matching (EDSM) problem. Since its introduction in 2017 [START_REF] Iliopoulos | Efficient pattern matching in elastic-degenerate texts[END_REF], it has attracted some attention in the combinatorial pattern matching community, and a series of results have been published. The simple algorithm by Iliopoulos et al. [START_REF] Iliopoulos | Efficient pattern matching in elastic-degenerate texts[END_REF] for EDSM was first improved by Grossi et al. in the same year, who showed that, for a pattern of length m, the EDSM problem can be solved on-line in O(nm 2 + N ) time [START_REF] Grossi | On-line pattern matching on similar texts[END_REF]; on-line means that it reads the text segment-by-segment and reports an occurrence as soon as this is detected. This result was improved by Aoyama et al. [START_REF] Aoyama | Faster online elastic degenerate string matching[END_REF] who presented an O(nm 1.5 √ log m + N )-time algorithm. An important feature of these bounds is their linear dependency on N . A different branch of on-line algorithms waiving the linear-dependency restriction exists [START_REF] Cislak | Sopang 2: online searching over a pan-genome without false positives[END_REF][START_REF] Cisłak | SOPanG: online text searching over a pangenome[END_REF][START_REF] Grossi | On-line pattern matching on similar texts[END_REF][START_REF] Pissis | Dictionary matching in elastic-degenerate texts with applications in searching VCF files on-line[END_REF]. Moreover, the EDSM problem has been considered under Hamming and edit distance [START_REF] Bernardini | Approximate pattern matching on elastic-degenerate text[END_REF]. Recent results on founder block graphs [START_REF] Mäkinen | Linear time construction of indexable founder block graphs[END_REF] can also be casted on elastic-degenerate strings.

A question with a somewhat similar flavor is the word break problem. We are given a dictionary D, m = ||D||, and a string S, n = |S|, and the question is whether we can split S into fragments that appear in D (the same element of D can be used multiple times). Backurs and Indyk [START_REF] Backurs | Which regular expression patterns are hard to match?[END_REF] designed an Õ(nm 1/2-1/18 + m)-time algorithm for this problem 2 . Bringmann et al. [START_REF] Bringmann | A dichotomy for regular expression membership testing[END_REF] improved this to Õ(nm 1/3 + m) and showed that this is optimal for combinatorial algorithms by a reduction from k-Clique. Their algorithm uses fast Fourier transform (FFT), and so it is not clear whether it should be considered combinatorial. While this problem seems similar to EDSM, there does not seem to be a direct reduction and so their lower bound does not immediately apply.

Our Results. It is known that BMM and triangle detection (TD) in graphs either both have truly subcubic combinatorial algorithms or none of them do [START_REF] Williams | Subcubic equivalences between path, matrix and triangle problems[END_REF]. Recall also that the currently fastest algorithm with linear dependency on N for the EDSM problem runs in O(nm 1.5 √ log m + N ) time [START_REF] Aoyama | Faster online elastic degenerate string matching[END_REF]. In this paper we prove the following two theorems.

Theorem 1. If the EDSM problem can be solved in O(nm 1.5-+ N ) time, for any > 0, with a combinatorial algorithm, then there exists a truly subcubic combinatorial algorithm for TD.

Arguably, the notion of combinatorial algorithms is not clearly defined, and Theorem 1 should be understood as an indication that in order to achieve a better complexity one should use fast matrix multiplication. Indeed, there are examples where a lower bound conditioned on BMM was helpful in constructing efficient algorithms using fast matrix multiplication [START_REF] Abboud | If the current clique algorithms are optimal, so is Valiant's parser[END_REF][START_REF] Bringmann | Truly sub-cubic algorithms for language edit distance and RNA-folding via fast bounded-difference min-plus product[END_REF][START_REF] Chang | Hardness of RNA folding problem with four symbols[END_REF][START_REF] Czumaj | Finding a heaviest vertex-weighted triangle is not harder than matrix multiplication[END_REF][START_REF] Matoušek | Computing dominances in E n[END_REF][START_REF] Williams | Finding a maximum weight triangle in n 3-δ time, with applications[END_REF][START_REF] Zwick | All pairs shortest paths using bridging sets and rectangular matrix multiplication[END_REF]. We successfully design such a non-combinatorial algorithm by combining three ingredients: a string periodicity argument, FFT, and fast matrix multiplication. While periodicity is the usual tool in combinatorial pattern matching [START_REF] Crochemore | Two-way string matching[END_REF][START_REF] Knuth | Fast pattern matching in strings[END_REF][START_REF] Kociumaka | Internal pattern matching queries in a text and applications[END_REF] and using FFT is also not unusual (for example, it often shows up in approximate string matching [START_REF] Abrahamson | Generalized string matching[END_REF][START_REF] Amir | Faster algorithms for string matching with k mismatches[END_REF][START_REF] Clifford | Simple deterministic wildcard matching[END_REF][START_REF] Gawrychowski | Towards unified approximate pattern matching for Hamming and L 1 distance[END_REF]), to the best of our knowledge, we are the first to combine these with fast matrix multiplication. Specifically, we show the following result for the EDSM problem, where ω denotes the matrix multiplication exponent.

Theorem 2. The EDSM problem can be solved on-line in Õ(nm ω-1 + N ) time.

In order to obtain a faster algorithm for the EDSM problem, we focus on the active prefixes (AP) problem that lies at the heart of all current solutions [START_REF] Aoyama | Faster online elastic degenerate string matching[END_REF][START_REF] Grossi | On-line pattern matching on similar texts[END_REF]. In the AP problem, we are given a string P of length m and a set of arbitrary prefixes P [1 . . i] of P , called active prefixes, stored in a bit vector U so that

U [i] = 1 if P [1 .
. i] is active. We are further given a set S of strings of total length N and we are asked to compute a bit vector V which stores the new set of active prefixes of P . A new active prefix of P is a concatenation of P [1 . . i] (such that U [i] = 1) and some element of S.

Using the algorithmic framework introduced in [START_REF] Grossi | On-line pattern matching on similar texts[END_REF], EDSM is addressed by solving an instance of the AP problem per each segment i of the ED text corresponding to set S of the AP problem. Hence, an O(f (m) + N i ) solution for the AP problem (with N i being the size of a single segment of the ED text) implies an O(nf (m) + N ) solution of EDSM, as f (m) is repeated n times and N = n i=1 N i . The algorithm of [START_REF] Aoyama | Faster online elastic degenerate string matching[END_REF] solves the AP problem in O(m 1.5 √ log m + N i ) time leading to O(nm 1.5 √ log m + N ) time for the EDSM problem. Our algorithm partitions the strings of each segment i of the ED text into three types according to a periodicity criterion, and then solves a restricted instance of the AP problem for each of the types. In particular, we solve the AP problem in Õ(m ω-1 + N i ) time leading to Õ(nm ω-1 + N ) time for the EDSM problem. 2 The Õ(•) notation suppresses polylog factors.

2

Given this connection between the two problems and, in particular, between their size parameter N , in the rest of the paper we will denote with N also the parameter N i of the AP problem.

An important building block in our solution that might find applications in other problems is a method of selecting a small set of length-substrings of the pattern, called anchors, so that any relevant occurrence of a string from an ED text set contains at least one but not too many such anchors inside. This is obtained by rephrasing the question in a graph-theoretical language and then generalizing the well-known fact that an instance of the hitting set problem with m sets over [n], each of size at least k, has a solution of size O(n/k • log m). While the idea of carefully selecting some substrings of the same length is not new (for example Kociumaka et al. [START_REF] Kociumaka | Internal pattern matching queries in a text and applications[END_REF] used it to design a data structure for pattern matching queries on a string), our setting is different and hence so is the method of selecting these substrings.

In addition to the conditional lower bound for the EDSM problem (Theorem 1), which also appeared in [START_REF] Bernardini | Even Faster Elastic-Degenerate String Matching via Fast Matrix Multiplication[END_REF], we also show here the following conditional lower bound for the AP problem.

Theorem 3. If the AP problem can be solved in O(m 1.5-+ N ) time, for any > 0, with a combinatorial algorithm, then there exists a truly subcubic combinatorial algorithm for the BMM problem.

Roadmap. Section 2 provides the necessary definitions and notation as well as the algorithmic toolbox used throughout the paper. In Section 3 we prove our lower bound result for the AP problem (Theorem 3). The lower bound result for the EDSM problem is proved in Section 4 (Theorem 1). In Section 5 we present our algorithm for EDSM (Theorem 2); this is the most technically involved part of the paper.

Preliminaries

Let T = T [1]T [START_REF] Abboud | Popular conjectures imply strong lower bounds for dynamic problems[END_REF] . . . T [n] be a string of length |T | = n over a finite ordered alphabet Σ of size |Σ| = σ. For two positions i and j on T , we denote by T [i . . j] = T [i] . . . T [j] the substring of T that starts at position i and ends at position j (it is of length 0 if j < i). By ε we denote the empty string of length 0. A prefix of T is a substring of the form T [1 . . j], and a suffix of T is a substring of the form T [i . . n]. T r denotes the reverse of T , that is, T [n]T [n -1] . . . T [START_REF] Abboud | If the current clique algorithms are optimal, so is Valiant's parser[END_REF]. We say that a string X is a power of a string Y if there exists an integer k > 1, such that X is expressed as k consecutive concatenations of Y , denoted by X = Y k . A period of a string X is any integer p ∈ [1, |X|] such that X[i] = X[i + p] for every i = 1, 2, . . . , |X| -p, and the period, denoted by per(X), is the smallest such p. We call a string X strongly periodic if per(X) ≤ |X|/4.

Lemma 1 ([29]

). If p and q are both periods of the same string X, and additionally p+q ≤ |X|+1, then gcd(p, q) is also a period of X.

A trie is a tree in which every edge is labeled with a single letter, and every two edges outgoing from the same node have different labels. The label of a node u in such a tree T , denoted by L(u), is defined as the concatenation of the labels of all the edges on the path from the root of T to u. Thus, the label of the root of T is ε, and a trie is a representation of a set of strings consisting of the labels of all its leaves. By replacing each path p consisting of nodes with exactly one child by an edge labeled by the concatenation of the labels of the edges of p we obtain a compact trie. The nodes of the trie that are removed after this transformation are called implicit, while the remaining ones are referred to as explicit. The suffix tree of a string S is the compact trie representing all suffixes of S$, $ / ∈ Σ, where instead of explicitly storing the label S[i . . j] of an edge we represent it by the pair (i, j).

A heavy path decomposition of a tree T is obtained by selecting, for every non-leaf node u ∈ T , its child v such that the subtree rooted at v is the largest. This decomposes the nodes of T into node-disjoint paths, with each such path p (called a heavy path) starting at some node, called the head of p, and ending at a leaf. An important property of such a decomposition is that the number of distinct heavy paths above any leaf (that is, intersecting the path from a leaf to the root) is only logarithmic in the size of T [START_REF] Sleator | A data structure for dynamic trees[END_REF].

Let Σ denote the set of all finite non-empty subsets of Σ * . Previous works (cf. [START_REF] Aoyama | Faster online elastic degenerate string matching[END_REF][START_REF] Bernardini | Approximate pattern matching on elastic-degenerate text[END_REF][START_REF] Grossi | On-line pattern matching on similar texts[END_REF][START_REF] Iliopoulos | Efficient pattern matching in elastic-degenerate texts[END_REF][START_REF] Pissis | Dictionary matching in elastic-degenerate texts with applications in searching VCF files on-line[END_REF]) define Σ as the set of all finite non-empty subsets of Σ * excluding {ε} but we waive here the latter restriction as it has no algorithmic implications. An elastic-degenerate string T = T [START_REF] Abboud | If the current clique algorithms are optimal, so is Valiant's parser[END_REF] . . . T [n], or ED string, over alphabet Σ, is a string over Σ, i.e., an ED string is an element of Σ * , and hence each T [i] is a set of strings.

Let T denote an ED string of length n, i.e. | T | = n. We assume that for any 1 ≤ i ≤ n, the set T [i] ∈ Σ is implemented as an array and can be accessed by an index, i.e.,

T [i] = { T [i][k] | k = 1, . . . , | T [i]|}.
For any σ ∈ Σ, ||σ|| denotes the total length of all strings in σ, and for any ED string T , || T || denotes the total length of all strings in all T [i]s. We will denote

N i = | T [i]| k=1 | T [i][k]| the total length of all strings in T [i] and N = n i=1 || T [i]
|| the size of T . An ED string T can be thought of as a compact representation of the set of strings A( T ) which is the Cartesian product of all

T [i]s; that is, A( T ) = T [1] × . . . × T [n]
where A × B = {xy | x ∈ A, y ∈ B} for any sets of strings A and B. For any ED string X and a pattern P , we say that P matches X if:

1. | X| = 1 and P is a substring of some string in X [START_REF] Abboud | If the current clique algorithms are optimal, so is Valiant's parser[END_REF], or, 2. | X| > 1 and P = P 1 . . . P | X| , where P 1 is a suffix of some string in X [START_REF] Abboud | If the current clique algorithms are optimal, so is Valiant's parser[END_REF], P | X| is a prefix of some string in X[| X|], and

P i ∈ X[i], for all 1 < i < | X|.
We say that an occurrence of a string P ends at position j of an ED string T if there exists i ≤ j such that P matches T [i] . . . T [j]. We will refer to string P as the pattern and to ED string T as the text. We define the main problem considered in this paper.

Elastic-Degenerate String Matching (EDSM)

INPUT: A string P of length m and an ED string T of length n and size N ≥ m. OUTPUT: All positions in T where at least one occurrence of P ends.

Example 1. Pattern P = GTAT ends at positions 2, 6, and 7 of the following text T .

T = ATGTA • A T • C • G T • CG •    TA TATA ε    • TATGC TTTTA
Aoyama et al. [START_REF] Aoyama | Faster online elastic degenerate string matching[END_REF] obtained an on-line O(nm 1.5 √ log m + N )-time algorithm by designing an efficient solution for the following problem.

Active Prefixes (AP)

INPUT: A string P of length m, a bit vector U of size m, a set S of strings of total length N . OUTPUT: A bit vector V of size m with V [j] = 1 if and only if there exists S ∈ S and i ∈

[1, m], U [i] = 1, such that P [1 . . i] • S = P [1 . . i + |S|] and j = i + |S|.
[i, j] = k (A[i, k] ∧ B[k, j]).
Triangle Detection (TD) INPUT: Three N × N Boolean matrices A, B and C. OUTPUT: Are there i, j, k such that

A[i, j] = B[j, k] = C[k, i] = 1?
An algorithm is called truly subcubic if it runs in O(N 3-) time, for some > 0. TD and BMM either both have truly subcubic combinatorial algorithms, or none of them do [START_REF] Williams | Subcubic equivalences between path, matrix and triangle problems[END_REF].

AP Conditional Lower Bound

To investigate the hardness of the EDSM problem, we first show that an O(m 1.5-+ N )-time solution to the active prefixes problem, that constitutes the core of the solutions proposed in [START_REF] Aoyama | Faster online elastic degenerate string matching[END_REF][START_REF] Grossi | On-line pattern matching on similar texts[END_REF], would imply a truly subcubic combinatorial algorithm for Boolean matrix multiplication (BMM). We recall that in the AP problem, we are given a string P of length m and a set of prefixes P [1 . . i] of P , called active prefixes, stored in a bit vector U (U [i] = 1 if and only if P [1 . . i] is active). We are further given a set S of strings of total length N and we are asked to compute a bit vector V storing the new set of active prefixes of P : a prefix of P that extends P [1 . . i] (such that U [i] = 1) with some element of S. Of course, we can solve BMM by working over integers and using one of the fast matrix multiplication algorithms; plugging in the best known bounds results in an O(N 2.373 )-time algorithm [START_REF] Gall | Powers of tensors and fast matrix multiplication[END_REF][START_REF] Williams | Multiplying matrices faster than Coppersmith-Winograd[END_REF]. However, such an algorithm is not combinatorial, i.e., it uses algebraic methods. In comparison, the best known combinatorial algorithm for BMM works in Ô(N 3 / log 4 N ) time [START_REF] Yu | An improved combinatorial algorithm for boolean matrix multiplication[END_REF]. This leads to the following popular conjecture.

Conjecture 1 ([2]

). There is no combinatorial algorithm for the BMM problem working in time O(N 3-), for any > 0.

Aoyama et al. [START_REF] Aoyama | Faster online elastic degenerate string matching[END_REF] showed that the AP problem can be solved in O(m 1.5 √ log m + N ) time for constant-sized alphabets. Together with some standard string-processing techniques applied similarly as in [START_REF] Grossi | On-line pattern matching on similar texts[END_REF], this is then used to solve the EDSM problem by creating an instance of the AP problem for every set T [i] of T , i.e., with S = T [i].

We argue that, unless Conjecture 1 is false, the AP problem cannot be solved faster than O(m 1.5-+ N ), for any > 0, with a combinatorial algorithm (note that the algorithm of Aoyama et al. [START_REF] Aoyama | Faster online elastic degenerate string matching[END_REF] uses FFT, and so it is not completely clear whether it should be considered to be combinatorial). We show this by a reduction from combinatorial BMM. Assume that, for the AP problem, we seek combinatorial algorithms with the running time O(m 1.5-+ N ), i.e., with linear dependency on the total length of the strings. We need to show that such an algorithm implies that the BMM problem can be solved in O(N 3-) time, for some > 0, with a combinatorial algorithm, thus implying that Conjecture 1 is false. Theorem 3. If the AP problem can be solved in O(m 1.5-+ N ) time, for any > 0, with a combinatorial algorithm, then there exists a truly subcubic combinatorial algorithm for the BMM problem.

Proof. Recall that in the BMM problem the matrices are denoted by A and B. In order to compute C = A×B, we need to find, for every i, j = 1, . . . , N , an index k such that A[i, k] = 1 and B[k, j] = 1. To this purpose, we split matrix A into blocks of size N •L and B into blocks of size L•L. This corresponds to considering values of j and k in intervals of size L, and clearly there are N /L such intervals. Matrix B is thus split into (N /L) 2 blocks, giving rise to an equal number of instances of the AP problem, each one corresponding to an interval of j and an interval of k. This creates (N /L) 2 blocks in matrix B; we will thus create (N /L) 2 separate instances of the AP problem corresponding to an interval of j and an interval of k. We will now describe the instance corresponding to the (K, J)-th block, where 1 ≤ K, J ≤ N /L.

We build the string P of the AP problem, for any block, as a concatenation of N gadgets corresponding to i = 1, . . . , N , and we construct the bit vector U (K,J) of the AP problem as a concatenation of N bit vectors, one per gadget. Each gadget consists of the same string a L ba L ; we set to 1 the k -th bit of the i-th gadget bit vector if A[i, (K -1)L + k ] = 1. The solution of the AP problem V (K,J) will allow us to recover the solution of BMM, as we will ensure that the bit corresponding to the j -th a in the second half of the gadget is set to 1 if and only if, for some k

∈ [L], A[i, (K -1)L + k ] = 1 and B[(K -1)L + k , (J -1)L + j ] = 1.
In order to enforce this, we will include the following strings in set S (K,J) :

a L-k ba j , for every k , j ∈ [L] such that B[(K -1)L + k , (J -1)L + j ] = 1.
This guarantees that after solving the AP problem we have the required property, and thus, after solving all the instances, we have obtained matrix C = A×B. Indeed, consider values j, i.e., the index that runs on the columns of C, in intervals of size L. By construction and by definition of BMM, the i-th line of the J-th column interval of C is obtained by taking the disjunction of the second half of the i-th interval of each (K, J)-th bit vector for every K = 1, 2, . . . , N /L.

We have a total of (N /L) 2 instances. In each of them, the total length of all strings is O(L 3 ), and the length of the input string P is (2L + 1)N = O(L • N ). Using our assumed algorithm for each instance, we obtain the following total time:

O((N /L) 2 • (L 3 + (N • L) 1.5-)) = O(N 2 • L + N 3.5-/L 0.5+ ).
If we set L = N (1.5-)/(1.5+ ) , then the total time becomes:

O(N 2+(1.5-)/(1.5+ ) + N 3.5--(0.5+ )(1.5-)/(1.5+ ) ) = O(N 2+(1.5-)/(1.5+ ) + N 2+(1.5-)-(1.5-)(0.5+ )/(1.5+ ) ) = O(N 2+(1.5-)/(1.5+ ) + N 2+(1.5-)(1.5+ -0.5-)/(1.5+ ) ) = O(N 2+(1.5-)/(1.5+ ) ).
Hence we obtain a combinatorial BMM algorithm with complexity O(N 3-) , where = 1 -(1.5 -)/(1.5 + ) > 0.

Example 3. Consider the following instance of the BMM problem with N = 6 and L = 3.

A B C           0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0           ×           0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0           =           1 0 0 0 0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0 0 0          
From matrices A and B, we now show how the resulting matrix C can be found by building and solving 4 instances of the AP problem constructed as follows. The pattern is

P = aaabaaa • aaabaaa • aaabaaa • aaabaaa • aaabaaa • aaabaaa
where the six gadgets are separated by a • to be highlighted. For the AP instances, the vectors U (K,J) shown below are the input bit vectors, and the sets S (K,J) are the input set of strings.

For each instance, the bit vector V (K,J) shown below is the output of the AP problem. U (1,1) : [0 1 0 0 0 0 0 | 1 0 1 0 0 0 0 |0 0 0 0 0 0 0 |1 0 0 0 0 0 0 |0 0 0 0 0 0 0 |0 1 0 0 0 0 0] S (1,1) : {aba,baaa}

V (1,1) : [0 0 0 0 1 0 0 | 0 0 0 0 0 0 1 |0 0 0 0 0 0 0 |0 0 0 0 0 0 0 |0 0 0 0 0 0 0 |0 0 0 0 1 0 0] U (1,2) : [0 1 0 0 0 0 0 | 1 0 1 0 0 0 0 |0 0 0 0 0 0 0 |1 0 0 0 0 0 0 |0 0 0 0 0 0 0 |0 1 0 0 0 0 0] S (1,2) : {aabaaa,baa} 1) : {aabaa,ba}

V (1,2) : [0 0 0 0 0 0 0 | 0 0 0 0 0 1 1 |0 0 0 0 0 0 0 |0 0 0 0 0 0 1 |0 0 0 0 0 0 0 |0 0 0 0 0 0 0] U (2,1) : [0 1 0 0 0 0 0 | 0 0 0 0 0 0 0 |0 0 1 0 0 0 0 |0 1 0 0 0 0 0 |1 0 0 0 0 0 0 |0 0 0 0 0 0 0] S (2,
V (2,1) : [0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 |0 0 0 0 1 0 0 |0 0 0 0 0 0 0 |0 0 0 0 0 1 0 |0 0 0 0 0 0 0] U (2,2) : [0 1 0 0 0 0 0 | 0 0 0 0 0 0 0 |0 0 1 0 0 0 0 |0 1 0 0 0 0 0 |1 0 0 0 0 0 0 |0 0 0 0 0 0 0] S (2,2) : {aba,baa} V (2,2) : [0 0 0 0 1 0 0 | 0 0 0 0 0 0 0 |0 0 0 0 0 1 0 |0 0 0 0 1 0 0 |0 0 0 0 0 0 0 |0 0 0 0 0 0 0]
As an example on how to obtain matrix C, consider the bold part of C above (i.e., the first line of block (1, 1) of C). This is obtained by taking the disjunction of the bold parts of V (1,1) and V (2,1) .

EDSM Conditional Lower Bound

Since the lower bound for the AP problem does not imply per se a lower bound for the whole EDSM problem, in this section we show a conditional lower bound for the EDSM problem. Specifically, we perform a reduction from Triangle Detection to show that, if the EDSM problem could be solved in O(nm 1.5-+ N ) time, this would imply the existence of a truly subcubic algorithm for TD. We show that TD can be reduced to the decision version of the EDSM problem: the goal is to detect whether there exists at least one occurrence of P in T . To this aim, given three matrices A, B, C, we first decompose matrix B into blocks of size N /s × N /s, where s is a parameter to be determined later; the pattern P is obtained by concatenating a number (namely z = N s 2 ) of constituent parts P i of length O(N /s), each one built with five letters from disjoint subalphabets. The ED text T is composed of three parts: the central part consists of three degenerate segments, the first one encoding the 1s of matrix A, the second one those of matrix B and the third one those of matrix C. These segments are built in such a way that the concatenation of strings of subsequent segments is of the same form as the pattern's building blocks. This central part is then padded to the left and to the right with sets containing appropriately chosen concatenations of substrings P i of P , so that an occurrence of the pattern in the text implies that one of its building blocks matches the central part of the text, thus corresponding to a triangle. Formally: Theorem 1. If the EDSM problem can be solved in O(nm 1.5-+ N ) time, for any > 0, with a combinatorial algorithm, then there exists a truly subcubic combinatorial algorithm for TD.

Proof. Consider an instance of TD, where we are given three N × N Boolean matrices A, B, C, and the question is to check if there exist i, j, k such that

A[i, j] = B[j, k] = C[k, i] = 1.
Let s be a parameter, to be determined later, that corresponds to decomposing B into blocks of size (N /s) × (N /s). We reduce to an instance of EDSM over an alphabet Σ of size O(N ). Pattern P . We construct P by concatenating, in some fixed order, the following strings:

P (i, x, y) = v(i)xa N /s x$$ya N /s yv(i)
for every i = 1, 2, . . . , N and x, y = 1, 2, . . . , s, where

a ∈ Σ 1 , $ ∈ Σ 2 , x ∈ Σ 3 , y ∈ Σ 4 , v(i) ∈ Σ 5 ,
and Σ 1 , Σ 2 , . . . , Σ 5 are disjoint subsets of Σ. ED text T . The text T consists of three parts. Its middle part encodes all the entries equal to 1 in matrices A, B and C, and consists of three string sets X =X 1 • X 2 • X 3 , where:

1. X 1 contains all strings of the form v(i)xa j , for some i ∈

[N ], x ∈ [s] and j ∈ [N /s] such that A[i, (x -1) • (N /s) + j] = 1;
2. X 2 contains all strings of the form a N /s-j x$$ya N /s-k , for some x, y ∈ [s] and j, k

=∈ [N /s] such that B[(x -1) • (N /s) + j, (y -1) • (N /s) + k] = 1, i.e., if the corresponding entry of B is 1; 3. X 3 contains all strings of the form a k yv(i), for some i ∈ [N ], y ∈ [s] and k ∈ [N /s] such that C[(y -1) • (N /s) + k, i] = 1.
It is easy to see that |P (i, x, y)| = O(N /s). This implies the following:

1. The length of the pattern is m = O(N • s 2 • N /s) = O(N 2 • s); 2. The total length of X is ||X || = O(N • s • N /s • N /s + s 2 • (N /s) 2 • N /s + N • s • N /s • N /s) = O(N 3 /s).
By the above construction, we obtain the following fact.

Fact 1. P (i, x, y) matches X if and only if the following holds for some j, k = 1, 2, . . . , N /s:

A[i, (x -1) • (N /s) + j] = B[(x -1) • (N /s) + j, (y -1) • (N /s) + k] = C[(y -1) • (N /s) + k, i] = 1
Solving the TD problem thus reduces to taking the disjunction of all such conditions. Let us write down all strings P (i, x, y) in some arbitrary but fixed order to obtain P = P 1 P 2 . . . P z with z = N s 2 , where every P t = P (i, x, y), for some i, x, y. We aim to construct a small number of sets of strings that, when considered as an ED text, match any prefix P 1 P 2 . . . P t of the pattern, 1 ≤ t ≤ z -1; a similar construction can be carried on to obtain sets of strings that match any suffix P k . . . P z-1 P z , 2 ≤ k ≤ z. These sets will then be added to the left and to the right of X , respectively, to obtain the ED text T . ED Prefix. We construct log z sets of strings as follows. The first one contains the empty string ε and P 1 P 2 . . . P z/2 . The second one contains ε, P 1 P 2 . . . P z/4 and P z/2+1 . . . P z/2+z/4 . The third one contains ε, P 1 P 2 . . . P z/8 , P z/4+1 . . . P z/4+z/8 , P z/2+1 . . . P z/2+z/8 and P z/2+z/4+1 . . . P z/2+z/4+z/8 . Formally, for every i = 1, 2, . . . , log z, the i-th of such sets is:

T p i = ε ∪ {P j z 2 i-1 +1 . . . P j z 2 i-1 + z 2 i | j = 0, 1, . . . , 2 i-1 -1}. ED Suffix.
We similarly construct log z sets to be appended to X :

T s i = ε ∪ {P z-j z 2 i-1 -z 2 i +1 . . . P z-j z 2 i-1 | j = 0, 1, . . . , 2 i-1 -1}.
The total length of all the ED prefix and ED suffix strings is

O(log z • N 2 • s) = O(N 2 • s • log N ).
The whole ED text T is thus:

T = T p 1 • • • • • T p log z • X • T s log z • • • • • T s 1 .
We next show how a solution of such instance of EDSM corresponds to the solution of TD. Lemma 2. The pattern P occurs in the ED text T if and only if there exist i, j, k such that

A[i, j] = B[j, k] = C[k, i] = 1.
Proof. By Fact 1, if such i, j, k exist then P t matches X , for some t ∈ {1, . . . , z}. Then, by construction of the sets T p i and T s i , the prefix P 1 . . . P t-1 matches the ED prefix (this can be proved by induction), and similarly the suffix P t+1 . . . P z matches the ED suffix, so the whole P matches T , and so P occurs therein. Because of the letters $ appearing only in the center of P i s and strings from X 2 , every P i s and a concatenation of X 1 ∈ X 1 , X 2 ∈ X 2 , X 3 ∈ X 3 having the same length, and the P i s being distinct, there is an occurrence of the pattern P in T if and only if X 1 X 2 X 3 = P t for some t and X 1 ∈ X 1 , X 2 ∈ X 2 , X 3 ∈ X 3 . But then, by Fact 1 there exists a triangle.

Note that for the EDSM problem we have

m = N 2 • s, n = 1 + 2log z and N = ||X || + O(N 2 •s•log N ). Thus if we had a solution running in O(log z • m 1.5-+ ||X ||+N 2 • s • log N ) = O(log N • (N 2 • s) 1.5-+ N 3 /s)
time, for some > 0, by choosing a sufficiently small α > 0 and setting s = N α we would obtain, for some δ > 0, an O(N 3-δ )-time algorithm for TD.

5 An Õ(nm ω-1 + N )-time Algorithm for EDSM Our goal is to design a non-combinatorial Õ(nm ω-1 + N )-time algorithm for EDSM, which in turn can be achieved with a non-combinatorial Õ(m ω-1 + N )-time algorithm for the AP problem, that is the bottleneck of EDSM (cf. [START_REF] Grossi | On-line pattern matching on similar texts[END_REF]).

We reduce AP to a logarithmic number of restricted instances of the same problem, based on the length of the strings in S. We start by giving a lemma that we will use to process naïvely the strings of length up to a constant c, to be determined later, in O(m + N ) time.

Lemma 3. For any integer t, all strings in S of length at most t can be processed in O(m log m + mt + N ) time.

Proof. We first construct the suffix tree ST of P and store, for every node, the first letters on its outgoing edges in a static dictionary with constant access time. This can be done in O(m log m) time [START_REF] Ružić | Constructing efficient dictionaries in close to sorting time[END_REF]. For every S ∈ S, find and mark its corresponding (implicit or explicit) node of ST . This takes O(N ) time overall. For every possible length t ≤ t, scan P with a window of length t while maintaining its corresponding node of ST . This takes O(m) time overall. If the current window P [i . . (i + t -1)] corresponds to a marked node of ST and additionally

U [i -1] = 1, we set V [i + t -1] = 1.
We build the rest of the restricted instances of the AP problem by restricting on strings in S k ⊆ S of length in [ (19/18) Denoting by N k the total size of strings in S k , we have that, if we solve every such instance of AP in O(N k +f (m)) time, then we can solve the original instance of AP in O(N + f (m) log m) time by taking the results disjunction. Switching to Õ notation that disregards polylog factors, it thus suffices to solve each such instance of the AP problem in Õ(N + m ω-1 ) time.

We further partition the strings in S k into three types, compute the corresponding bit vector V for each type separately and, finally, take the disjunction of the resulting bit vectors V to obtain the answer for each restricted instance.

Partitioning S k . Keeping in mind that from now on (until Section 5.4) we address the AP problem assuming that S only contains strings of length in [9/8 • , 5/4 • ), and thus is in fact S k , to lighten the notation we now switch back to denote it simply with S. The three types of strings are as follows:

Type 1: Strings S ∈ S such that every length-substring of S is not strongly periodic.

Type 2: Strings S ∈ S containing at least one length-substring that is not strongly periodic and at least one length-substring that is strongly periodic.

Type 3: Strings S ∈ S such that every length-substring of S is strongly periodic (in Lemma 4 we show that in this case per(S) ≤ /4).

These three types are evidently a partition of S. We start with showing that, in fact, strings of type 3 are exactly strings with period at most /4. Before proceeding with the algorithm, we show that, for each string S ∈ S, we can determine its type in O(|S|) time.

Lemma 5. Given a string S we can determine its type in O(|S|) time.

Proof. It is well-known that per(T ) can be computed in O(|T |) time for any string T (cf. [START_REF] Crochemore | Algorithms on strings[END_REF]). We partition S into blocks T α = S[α /2 . . (α + 1) /2 -1] of size /2 , and compute per(T α ) for every α in O(|S|) total time. Observe that every substring S[i . . i + -1] contains at least one whole block inside.

If per(T α ) > /4 then the period of any substring S[i . . i + -1] that contains T α is also larger than /4. Consequently, if per(T α ) > /4 for every α, then we declare S to be of type 1.

Consider any α such that p = per(T α ) ≤ /4. If the period p of a substring S = S[i . . i+ -1] that contains T α is at most /4, then in fact it must be equal to p, because p ≥ p and so, by Lemma 1 applied on T α , p must be a multiple of p and, by repeatedly applying S [j] = S [j + p ] and T α [j] = T α [j + p] and using the fact that T α occurs inside S , we conclude that in fact S [j] = S [j + p] for any j, and thus p = p. This allows us to check whether there exists a substring S = S[i . . i + -1] that contains T α such that per(S ) ≤ /4 by computing, in O( ) time, how far the period p extends to the left and to the right of T α in T α-1 T α T α+1 (if either T α-1 or T α+1 do not exist, then we do not extend the period in the corresponding direction). There exists such a substring S if and only if the length of the extended substring with period p is at least . Therefore, for every α we can check in O( ) time if there exists a length-substring S containing T α with per(S ) ≤ /4. By repeating this procedure for every α, we can distinguish between S of type 2 and S of type 3 in O(|S|) total time.

Since we have shown how to efficiently partition the strings of S into the three types, in what follows we present our solution of the AP problem for each type of strings separately.

Remark 1. The length of every string in S belonging to [9/8 • , 5/4 • ) implies that every string in S contains at most /4 length-substrings (and at least 1 + /8 of them).

Type 1 Strings

In this section we show how to solve a restricted instance of the AP problem where every string S ∈ S is of type 1, that is, each of its length-substrings is not strongly periodic, and furthermore |S| ∈ [9/8 • , 5/4 • ) for some ≤ m. Observe that all (and hence at most /4 by Remark 1) length-substrings of any S ∈ S must be distinct, as otherwise we would be able to find two occurrences of a length-substring at distance at most /4 in S, making the period of the substring at most /4 and contradicting the assumption that S is of type 1.

We start with constructing the suffix tree ST of P (our pattern in the EDSM problem) in O(m log m) time [START_REF] Weiner | Linear pattern matching algorithms[END_REF]. Let us remark that we are spending O(m log m) time and not just O(m) so as to avoid any assumptions on the size of the alphabet. For every explicit node u ∈ ST , we construct a perfect hash function mapping the first letter on every edge outgoing from u to the corresponding edge. This takes O(m log m) time [START_REF] Ružić | Constructing efficient dictionaries in close to sorting time[END_REF] and allows us to navigate in ST in constant time per letter. Then, for every S ∈ S, we check in O(|S|) time using ST if it occurs in P and, if not, we disregard it from further consideration. Therefore, from now on we assume that all strings S, and thus all their length-substrings, occur in P . We will select a set of lengthsubstrings of P , called the anchors, each represented by one of its occurrences in P , such that:

1. The total number of occurrences of all anchors in P is O(m/ • log m).

2. For every S ∈ S, at least one of its length-substrings is an anchor.

The total number of occurrences of all anchors in strings S ∈ S is O(|S| • log m).

We formalize this using the following auxiliary problem, which is a strengthening of a well-known Hitting Set problem, which given a collection of m sets over [n], each of size at least k, asks to choose a subset of [n] of size O(n/k • log m) that nontrivially intersects every set.

Node Selection (NS)

INPUT: A bipartite graph G = (U, V, E) with deg(u) ∈ (d, 2d] for every u ∈ U and weight w(v) for every v ∈ V , where W = v∈V w(v).

OUTPUT: A set V ⊆ V of total weight O(W/d • log |U |) such that N [u] ∩ V = ∅ for every node u ∈ U , and u∈U |N [u] ∩ V | = O(|U | log |U |).
We reduce the problem of finding anchors to an instance of the NS problem, by building a bipartite graph G in which the nodes in U correspond to strings S ∈ S, the nodes in V correspond to distinct length-substrings of P , and there is an edge (u, v) if the length-string corresponding to v occurs in the string S corresponding to u. Using suffix links, we can find the node of the suffix tree corresponding to every length-substring of S in O(|S|) total time, so the whole construction takes O(m log m + S∈S |S|) = O(m log m + N ) time. The size of G is O(m + N ), and the degree of every node in U belongs to ( /8, /4]. We set the weight of a node v ∈ V to be its number of occurrences in P , and solve the obtained instance of the NS problem to obtain the set of anchors. It is not immediately clear that an instance of the NS problem always has a solution. We show that indeed it does, and that it can be found in linear time. Lemma 6. A solution to an instance of the NS problem always exists and can be found in linear time in the size of G.

Proof. We first show a solution that uses the probabilistic method and leads us to an efficient Las Vegas algorithm; we will then derandomize the solution using the method of conditional expectations.

We independently choose each node of V with probability p to obtain the set V of selected nodes. The expected total weight of V is v∈V p • w(v) = p • W , so by Markov's inequality it exceeds 4p • W with probability at most 1/4. For every node u ∈ U , the probability that

N [u] does not intersect V is at most (1 -p) d ≤ e -pd . Finally, E[ u∈U |N [u] ∩ V |] ≤ |U | • 2pd, so by Markov's inequality u∈U |N [u] ∩ V | exceeds |U | •
8pd with probability at most 1/4. We set p = ln(4|U |)/d (observe that if p > 1 then we can select all nodes in V ). By union bound, the probability that V is not a valid solution is at most 3/4, so indeed a valid solution exists. Furthermore, this reasoning gives us an efficient Las Vegas algorithm that chooses V randomly as described above and then verifies if it constitutes a valid solution. Each iteration takes linear time in the size of G, and the expected number of required iterations is constant.

To derandomize the above procedure we apply the method of conditional expectations. Let X 1 , X 2 , . . . be the binary random variables corresponding to the nodes of V . Recall that in the above proof we set X i = 1 with probability p. Now we will choose the values of X 1 , X 2 , . . . oneby-one. Define a function f (X 1 , X 2 , . . .) that bounds the probability that X 1 , X 2 , . . . corresponds to a valid solution as follows:

f (X 1 , X 2 , . . .) = v X v • w(v) 4W/d • ln(4|U |) + u∈U v∈N [u] (1 -X v ) + u∈U v∈N [u] X v 8|U | ln(4|U |) .
As explained above, we have E[f (X 1 , X 2 , . . .)] = 3/4. Assume that we have already fixed the values X 1 = x 1 , . . . , X i = x i . Then there must be a choice of X i+1 = x i+1 that does not increase the expected value of f (X 1 , X 2 , . . .) conditioned on the already chosen values. We want to compare the following two quantities:

E[f (X 1 , X 2 , . . .) | X 1 = x 1 , . . . , X i = x i , X i+1 = 0] E[f (X 1 , X 2 , . . .) | X 1 = x 1 , . . . , X i = x i , X i+1 = 1]
and choose x i+1 corresponding to the smaller one. Cancelling out the shared terms, we need to compare the expected values of:

0 + u∈N [i+1] v∈N [u]
(1 -X v ) + 0 and

w(i + 1) 4W/d • ln(4|U |) + 0 + deg(i + 1) 8|U | ln(4|U |)
.

The second quantity can be computed in constant time. We claim that (ignoring the issue of numerical precision) the first quantity can be computed in time O(deg(i + 1)) after a linear-time preprocessing as follows. In the preprocessing we compute and store

E[i] = E[ i j=1 (1 -Y j )],
where the Y j 's are independent indicator variables with Pr[Y j = 1] = p, for every i = 0, 1, . . . , |V |. It is straightforward to compute E[i+1] from E[i] in constant time. Then, during the computation we maintain, for every u ∈ U , the number c[u] of v ∈ N [u] for which we still need to choose the value X e , and a single bit b[u] denoting whether for some v ∈ N [u] ∩ {1, . . . , i} we already have x v = 1. This information can be updated in O(deg(i + 1)) time after selecting x i+1 . Now to compute the first quantity, we iterate over u ∈ N [i + 1] and, if b[u] = 0 then we add E[c[u]] to the result. Finally, we claim that it is enough to implement all calculations with precision Θ(log |V |) bits. This is because such precision allows us to calculate both quantities with relative accuracy 1/(8|V |), so the expected value of f (X 1 , X 2 , . . .) might increase by a factor of (1 + 1/(4|V |)) in every step, which is at most (1 + 1/(4|V |)) |V | ≤ e 1/4 overall. This still guarantees that the final value is at most 3/4 • e 1/4 < 1, so we obtain a valid solution.

In the rest of this section we explain how to compute the bit vector V from the bit vector U , and thus solve the AP problem, after having obtained a set A of anchors. For any S ∈ S, since S contains an occurrence of at least one anchor H ∈ A, say S[j . .(j + |H| -1)] = H, so any occurrence of S in P can be generated by choosing some occurrence of H in P , say We first construct the suffix tree ST of P $ and the suffix tree ST r of P r $ (again in O(m log m) time not to make assumptions on the alphabet). We augment both trees with data for answering both weighted ancestor (WA) and lowest common ancestor (LCA) queries, that are defined as follows. For a rooted tree T on n nodes with an integer weight D(v) assigned to every node u, such that the weight of the root is zero and D(u) < D(v) if u is the parent of v, we say that a node v is a weighted ancestor of a node v at depth , denoted by WA T (u, ), if v is the highest ancestor of u with weight at least . Such queries can be answered in O(log n) time after an O(n) preprocessing [START_REF] Farach-Colton | Perfect hashing for strings: formalization and algorithms[END_REF]. For a rooted tree T , LCA T (u, v) is the lowest node that is an ancestor of both u and v. Such queries can be answered in O(1) time after an O(n) preprocessing [START_REF] Bender | The LCA problem revisited[END_REF]. Recall that every anchor H is represented by one of its occurrences in P . Using WA queries, we can access in O(log m) time the nodes corresponding to H and H r , respectively, and extract a lexicographically sorted list of suffixes following an occurrence of H in P $ and a lexicographically sorted list of reversed prefixes preceding an occurrence of H in P r $ in time proportional to the number of such occurrences. Then, by iterating over the lexicographically sorted list of suffixes and using LCA queries on ST we can build T (H) in time proportional to the length of the list, and similarly we can build T r (H). To construct L(H) we start by computing, for every S ∈ S and j = 1, . . . , |S|, the node of ST r corresponding to (S[1 . . j]) r and the node of ST corresponding to S([(j + 1) . . |S|] (the nodes might possibly be implicit). This takes only O(|S|) time, by using suffix links. We also find, for every length-substring S[j . . (j + -1)] of S, an anchor H ∈ A such that S[j . . (j + -1)] = H, if any exists. This can be done by finding the nodes (implicit or explicit) of ST that correspond to the anchors, and then scanning over all length-substrings while maintaining the node of ST corresponding to the current substring using suffix links in O(|S|) total time. After having determined that S[j . . (j + -1)] = H we add (u, v) to L(H), where u and v are the previously found nodes of ST r and ST corresponding to (S[1 . . (j -1)]) r and S[(j + ) . . |S|], respectively. By construction, we have the following property, also illustrated in Figure 1.

P [i . . (i + |H| -1)] = H,
Fact 2. A string S ∈ S starts at position i-j +1 in P if and only if, for some anchor H ∈ A, L(H) contains a pair (u, v) corresponding to S[j . . (j +|H|-1)] = H, such that the subtree of T r (H) rooted at u and that of T (H) rooted at v contain a leaf decorated with i.

Note that the overall size of all lists L(H), when summed up over all H ∈ A, is S∈S occ S = O(|S| log m), and since each S is of length at least this is O(N/ • log m).

Processing. The goal of processing D(H) is to efficiently process all occurrences generated by H. As a preliminary step, we decompose T r (H) and T (H) into heavy paths. Then, for every pair of leaves u ∈ T r (H) and v ∈ T (H) decorated by the same i, we consider all heavy paths above u and v. Let p = u 1 -u 2 -. . . be a heavy path above u in T r (H) and q = v 1 -v 2 -. . . be a heavy path above v in T (H), where u 1 is the head of p and v 1 is the head of q, respectively. Further, choose the largest x such that u is in the subtree rooted at u x , and the largest y such that v is in the subtree rooted at v y (this is well-defined by the choice of p and q, as u is in the subtree rooted at u 1 and v is in the subtree rooted at v 1 ). We add (i, | L(u x )|, | L(v y )|) to an auxiliary list associated with the pair of heavy paths (p, q). In the rest of the processing we work with each such lists separately. Notice that the overall size of all auxiliary lists, when summed up over all H ∈ A, is O(m/ • log 3 m), because there are at most log 2 m pairs of heavy paths above u and v decorated by the same i, and the total number of leaves in all trees T r (H) and T (H) is bounded by the total number of occurrences of all anchors in P , which is O(m/ • log m). By Fact 2, there is an occurrence of a string S generated by H and starting at position i -j + 1 in P if and only if L(H) contains a pair (u, v) corresponding to S[j . . (j + |H| -1)] = H such that, denoting by p the heavy path containing u in T r (H) and by q the heavy path containing v in T (H), the auxiliary list associated with (p, q) contains a triple (i, x, y) such that x ≥ | L(u)| and y ≥ | L(v)|. This is illustrated in Figure 2. Henceforth, we focus onthe problem of processing a single auxiliary list associated with (p, q), together with a list of pairs (u, v), such that u belongs to p and v belongs to q.

An auxiliary list can be interpreted geometrically as follows: for every (i, x, y) we create a red point (x, y), and for every (u, v) we create a blue point (| L(u)|, | L(v)|). Then, each occurrence of S ∈ S generated by H corresponds to a pair of points (p 1 , p 2 ) such that p 1 is red, p 2 is blue, and p 1 dominates p 2 . We further reduce this to a collection of simpler instances in which all red points already dominate all blue points. This can be done with a divide-and-conquer procedure products M × U i to that of computing O(s/z) matrix-matrix products of the form M × M , where M is an 5/4 • × z matrix. Even if M is not necessarily a square matrix, we can still apply the fast matrix multiplication algorithm to compute M × M using the standard trick of decomposing the matrices into square blocks. We would like to assume that ≥ log 3 m so that we can set z = / log 3 m. This is indeed possible, because for any t we can switch to a more naïve approach to process all strings of length at most t in O(mt 2 + N ) time as described in 3. After applying it with t = log 3 m in O(m log 6 m + N ) time, we can set z = / log 3 m (so that indeed 5/4 • ≥ z as required in case s ≥ z) and the overall time complexity for all matrices M and both cases becomes O(N + ω-2 • m log 5+3(3-ω) m). Summing up over all values of and taking the initialization into account we obtain O(m log 7 m + m ω-1 log 5+3(3-ω) m + N ) = Õ(m ω-1 + N ) total time.

Type 2 Strings

In this section we show how to solve a restricted instance of the AP problem where every string S ∈ S is of type 2, that is, S contains a length-substring that is not strongly periodic as well as a length-substring that is strongly periodic, and furthermore |S| ∈ [9/8 • , 5/4 • ) for some ≤ m.

Similarly as in Section 5.1, we select a set of anchors. In this case, instead of the NodeSelection problem we need to exploit periodicity. We call a string T -periodic if |T | ≥ and per(T ) ≤ /4. We consider all maximal -periodic substrings of S, that is, -periodic substrings S[i . . j] such that either i = 1 or per(S[(i -1) . . j]) > /4, and j = |S| or per(S[i . . (j + 1)]) > /4. We know that S contains at least one such substring (because there exists a length-substring that is strongly periodic), and that the whole S is not such a substring (because otherwise S would be of type 3). Further, two maximal -periodic substrings cannot overlap too much, as formalized in the following lemma. Lemma 9. Any two distinct maximal -periodic substrings of the same string S overlap by less than /2 letters.

Proof. Assume (by contradiction) the opposite; then we have two distinct -periodic substrings S[i . . j] and S[i . . j ] such that i < i ≤ j < j and j -i + 1 ≥ /2. Then, both p = per(S[i . . j]) and p = per(S[i . . j ]) are periods of S[i . . j], and hence by Lemma 1 we have that gcd(p, p ) is a period of S[i . . j]. If p = p then, because S[i . . j] contains an occurrence of both S[i . . (i + p -1)] and S[i . . (i + p -1)], we obtain that one of these two substrings is a power of a shorter string, thus contradicting the definition of p or p . So p = p , but then p ≤ /4 is actually a period of the whole S[i . . j ], meaning that S[i . . j] and S[i . . j ] are not maximal, a contradiction. By Lemma 9, every S ∈ S contains exactly one maximal -periodic substring, and by the same argument P contains O(m/ ) such substrings. The set of anchors will be generated by considering the unique maximal -periodic substring of every S ∈ S, so we first need to show how to efficiently generate such substrings.

Lemma 10. Given a string S of length at most 5/4 For every S ∈ S, we apply Lemma 10 on S to find its (unique) maximal -periodic substring S[i . . j] in O(|S|) time. If i > 1 then we designate S[(i -1) . . (i -1 + )] as an anchor, and similarly if j < |S| we designate S[(j + 1 -) . . (j + 1)] as an anchor. Observe that because S is of type 2 (and not of type 3) either i > 1 or j < |S|, so for every S ∈ S we designate at least one if its length-( + 1) substrings as an anchor. As in Section 5.1, we represent each anchor by one of its occurrences in P , and so need to find its corresponding node in the suffix tree of P (if any). This can be done in O(|S|) time, so O(N ) overall. During this process we might designate the same string as an anchor multiple times, but we can easily remove the possible duplicates to obtain the set A of anchors in the end. Then, we generate the occurrences of all anchors in P by accessing their corresponding nodes in the suffix tree of P and iterating over all leaves in their subtrees. We claim that the total number of all these occurrences is only O(m/ ). This follows from the following characterization.

Lemma 11. If P [x . . (x + )] is an occurrence of an anchor then either P [(x + 1) . . y] is a maximal -periodic substring of P , for some y ≥ x + , or P [x . . (x + -1)] is a maximal -periodic substring of P , for some x ≤ x.

Proof. By symmetry, it is enough to consider an anchor H created because of a maximalperiodic substring S[i . . j] such that i > 1, when we add S[(i -1) . . ] can be extended to some maximal -periodic substring S[i . . j ] such that i ≤ i -1 and j ≥ i -1 + . The overlap between S[i . . j] and S[i . . j ] is at least , so by Lemma 9 i = i and j = j , which is a contradiction. Consequently, x = x and we obtain the lemma.

By Lemma 11, the number of occurrences of all anchors in P is at most two per each maximal -periodic substrings, so O(m/ ) in total. We thus obtain a set of length-( + 1) anchors with the following properties:

1. The total number of occurrences of all anchors in P is O(m/ ).

2. For every S ∈ S, at least one of its length-( + 1) substrings is an anchor.

3. For every S ∈ S, at most two of its length-( + 1) substrings are anchors. These properties are even stronger than what we had used in Section 5.1 (except that now we are working with length-( + 1) substrings, which is irrelevant), we can now prove our final result also for strings of type 2.

Theorem 5. An instance of the AP problem where all strings are of type 2 can be solved in Õ(m ω-1 + N ) time.

Type 3 Strings

In this section we show how to solve a restricted instance of the AP problem where every string S ∈ S is of type 3, that is, per(S) ≤ /4. Furthermore |S| ∈ [9/8 • , 5/4 • ) for some ≤ m. Recall that strings S ∈ S are such that every length-substring of S is strongly periodic and, by Lemma 4, in this case, per(S) ≤ /4. An occurrence of such S in P must be contained in a maximal -periodic substring of P . Recall that a string T is called -periodic if |T | ≥ and per(T ) ≤ /4. For an -periodic string T , let its root, denoted by root(T ), be the lexicographically smallest cyclic shift of T We will now make a partition of type 3 strings based on their root. We start with extracting all maximal -periodic substrings of P using Lemma 10 and compute the root of every such substring. This can be done in O(m) total time because two maximal -periodic substrings cannot overlap by more than /2 letters, and hence their total length is at most 3/2 • . We also extract the root of every S ∈ S in O(N ) total time. We then partition maximal -periodic substrings of P and strings S ∈ S into groups that have the same root. In the remaining part we describe how to process each such group corresponding to root R in which all maximal -periodic substrings of P have total length m , and the strings S ∈ S have total length N .

Recall that the bit vector U stores the active prefixes input to the AP problem, and the bit vector V encodes the new active prefixes we aim to compute. For every maximal -periodic substring of P with root R we extract the corresponding fragment of the bit vector U and need to update the corresponding fragment of the bit vector V . To make the description less cluttered, we assume that each such substring of P is a power of R, that is, R α for some α ≥ 4. This can be assumed without loss of generality as it can be ensured by appropriately padding the extracted fragment of U and then truncating the results, while increasing the total length of all considered substrings of P by at most half of their length. In the description below, for simplicity of presentation, U and V denote these padded fragments of the original U and V . When computing V from U we use two different methods for processing the elements S = R[i . . |R|]R β R[1 . . j] of S depending on their length: either β > α/|R| (large β) or β ≤ α/|R| (small β).

Large β. We proceed in phases corresponding to β = α/|R| + 1, . . . , α. In each single phase, we consider all strings S ∈ S with S = R[i . . |R|]R β R[1 . . j], for some i and j. Let C(β) be the set of the corresponding pairs (i, j), and observe that β |C(β)| • |R β | ≤ N . This is because the length of R β is not greater than that of S = R[i . . |R|]R β R[1 . . j], there are |C(β)| distinct strings of We are now in a position to prove the following result for type 3 strings. Theorem 6. An instance of the AP problem where all strings are of type 3 can be solved in Õ(m ω-1 + N ) time.

Proof. Recall that we consider strings S of type 3 with root R and substrings of P with root R together. We first analyze the time to process a single group containing a number of substrings of P of total length m and a number of strings S ∈ S of total length N . Let us denote by R α i the i-th considered substring of P and further define α = i α i = m /|R|.

If β > α/|R| we use the first method and spend O(α i • |C(β)|) time, where C(β) is the set of (i, j) for this specific β. The overall time used for all applications of the first method is: For each α i , we process together all β ≤ α i /|R| using the second method, and we need to multiply two |R| × |R| matrices of polynomials of degree up to α i /|R|, that we can Because all values of N sum up to N and all values of m sum up to O(m), by convexity of x ω-1 we obtain that the overall time complexity is Õ(m ω-1 + N ).

Wrapping Up

In Sections 5.1, 5.2 and 5.3 we design three Õ(m ω-1 + N )-time algorithms for an instance of the AP problem where all strings are of type 1, 2 and 3, respectively. We thus obtain Theorem 2, and using the fact that ω < 2.373 [START_REF] Gall | Powers of tensors and fast matrix multiplication[END_REF][START_REF] Williams | Multiplying matrices faster than Coppersmith-Winograd[END_REF] we obtain the following corollary.

Corollary 7. The EDSM problem can be solved on-line in O(nm 1.373 + N ) time.

Note that the polylog factors are shaved from Õ(nm ω-1 + N ) by using the fact that the inequality of ω < 2.373 is strict.

Final Remarks

Our contribution in this paper is twofold. First, we designed an appropriate reduction showing that a combinatorial algorithm solving the EDSM problem in O(nm 1.5-+ N ) time, for any > 0, refutes the well-known BMM conjecture. Second, we designed a non-combinatorial Õ(nm ω-1 +N ) -time algorithm to attack the same problem. By using the fact that ω < 2.373, our algorithm runs in O(nm 1.373 + N ) time thus breaking the combinatorial conditional lower bound for the EDSM problem. Let us point out that if ω = 2 then our algorithm for the AP problem is time-optimal up to polylog factors.

  In more detail, given an ED text T = T [1] . . . T [n], one should consider an instance of the AP problem per each T [i]. Hence, an O(f (m) + N i ) solution for AP ( N i being the size of T [i]) implies an O(n • f (m) + N ) solution for EDSM, as f (m) is repeated n times and N = n i=1 N i . We provide an example of the AP problem.

Example 2 .

 2 Let P = ababbababab of length m = 11, U = 01000100000, and S = {ε, ab, abb, ba, baba}. We have that V = 01011101010. For our lower bound results we rely on BMM and the following closely related problem. Boolean Matrix Multiplication (BMM) INPUT: Two N × N Boolean matrices A and B. OUTPUT: N × N Boolean matrix C, where C

Lemma 4 .

 4 Let S be a string. If per(S[j . . j + -1]) ≤ /4 for every j then per(S) ≤ /4. Proof. We first show that, for any string W and letters a, b, if per(aW ) ≤ |aW |/4 and per(W b) ≤ |W b|/4 then per(aW ) = per(W b). This follows from Lemma 1: since per(aW ) and per(W b) are both periods of W and (1 + |W |)/4 ≤ |W |/2, then we have that d = gcd(per(aW ), per(W b)) is a period of W . Assuming by contradiction that per(aW ) = per(W b), then it must be that either d < per(aW ) or d < per(W b); by symmetry it is enough to consider the former possibility, and we claim that then d is a period of aW . Indeed, a = W [per(aW ) -1] (observe that per(aW ) -1 ≤ |W |) and W [i] = W [i + d] for any i = 1, 2, . . . , |W | -d, so by per(aW ) being a multiple of d we obtain that a = W [per(aW ) -1] = W [d -1], which is a contradiction because by definition of per(aW ) we have that d < per(aW ) cannot be a period of aW .If per(S[j . . j + -1]) ≤ /4 for every j then by the above reasoning the periods of all substrings S[j . . j + -1] is the same and in fact equal to p. But then S[i] = S[i + p] for every i, so per(S) ≤ /4.

  and then checking that S[1 . . (j -1)] = P [(i -j + 1) . . (i -1)] and S[(j + |H|) . . |S|] = P [(i + |H|) . . (i + |S| -j)]. In other words, S[1 . . (j -1)] should be a suffix of P [1 . . (i -1)] and S[(j + |H|) . . |S|] should be a prefix of P [(i + |H|) . . |P |]. In such case, we say that the occurrence of S in P is generated by H. By the properties of A, any occurrence of S ∈ S is generated by occ S ≥ 1 occurrences of anchors, where S∈S occ S = O(|S| log m). For every H ∈ A we create a separate data structure D(H) responsible for setting V [i + |S|-1] = 1, when U [i -1] = 1 and P [i . .(i+|S|-1)] = S is generated by H. We now first describe what information is used to initialize each D(H), and how this is later processed to update V . Initialization. D(H) consists of two compact tries T (H) and T r (H). For every occurrence of H in P , denoted by P [i . . (i + |H| -1)] = H, T (H) should contain a leaf corresponding to P [(i + |H|) . . |P |]$ and T r (H) should contain a leaf corresponding to (P [1 . . (i -1)]) r $, both decorated with position i. Additionally, D(H) stores a list L(H) of pairs of nodes (u, v), where u ∈ T r (H) and v ∈ T (H). Each such pair corresponds to an occurrence of H in a string S ∈ S h , S[j . . (j + |H| -1)] = H, where u is the node of T r (H) corresponding to (S[1 . . (j -1)]) r $ and v is the node of T (H) corresponding to S[(j + |H| + 1) . . |S|]$. We claim that D(H), for all H, can be constructed in O(m log m + N ) total time.

Figure 1 :

 1 Figure 1: An occurrence of S starting at position i in P is generated by H: (u, v) corresponds to S[j . . (j + |H| -1)] = H and i appears in the subtree of T r (H) rooted at u, as well as in the subtree of T (H) rooted at v.

Lemma 8 .

 8 If two N × N matrices can be multiplied in O(N ω ) time, then, for any N ≥ N , an N × N and an N × N matrix can be multiplied in O((N /N ) 2 N ω ) time.Proof. We partition both matrices into blocks of size N × N . There are (N /N ) 2 such blocks in the first matrix and N /N in the second matrix. Then, to compute the product we multiply each block from the first matrix by the appropriate block in the second matrix in O(N ω ) time, resulting in the claimed complexity.By applying Lemma 8, we can compute M × M in O( 2 z ω-2 ) time (as long as we later verify that 5/4 • ≥ z), so all products M × U i can be computed in O( 2 z ω-2 • (s/z + 1)) time. Note that this case can occur only O(m/( • z) • log 5 m) times, because all values of s sum up to O(m/ • log 5 m). This makes the total computation time, when summed up over all such matrices M , O(2 z ω-2 • m/( • z) • log 5 m) = O( z ω-3 • m log 5 m).We can now prove our final result for strings of type 1. Theorem 4. An instance of the AP problem where all strings are of type 1 can be solved in Õ(m ω-1 + N ) time. Proof. The total time complexity is first O(m+N ) to construct the graph G, then O(m log m+N ) to solve its corresponding instances of the NodeSelection problem and obtain the set of anchors H. The time to initialize all structures D(H) is O(m log m + N ). For every D(H), we obtain in O(m/ • log 5 m + N/ • log 3 m) time a number of simpler instances, and then construct the corresponding Boolean matrices M and bit vectors U i in additional O(m log 5 m) time. Note that some M might be sparse, so we need to represent them as a list of 1s. Then, summing up over all matrices M and both cases, we spend O(N/ • log 3 m • z + z ω-3 • m log 5 m) time.

  (i -1 + )] to A. Thus, per(H[2 . . |H|]) ≤ /4 and if P [x . . (x + )] = H then per(P [(x + 1) . . (x + )]) ≤ /4, making P [(x + 1) . . (x + )] a substring of some maximal -periodic substring of P [(x + 1) . . y], where x ≤ x and y ≥ x + . If x < x then per(H) ≤ /4. But then H = S[(i -1) . . (i -1 + )

  [1 . . per(T )]. Because per(T ) ≤ /4 and |T | ≥ by definition, there are at least four repetitions of the period in T , so we can writeT = R[i . . |R|]R α R[1 . . j],where R = root(T ), for some i, j ∈ [1, |R|] and α ≥ 2. It is well known that root(T ) can be computed in O(|T |) time[START_REF] Duval | Factorizing words over an ordered alphabet[END_REF].

Example 4 .

 4 Let T = babababab and = 8. We have |T | = 9 ≥ = 8 and per(T ) = 2 ≤ /4 = 2, so T is -periodic. We have root(T ) = R = ab, and T can be written as T = b • (ab) 3 • ab, for i = 2 and j = 2.

iO

  (α i • β>α/|R| |C(β)|) = O(α/|R α/|R| | • β>α/|R| |C(β)| • |R α/|R| |) = O( β>α/|R| |C(β)| • |R β |) = O(N ),using the fact that β |C(β)| • |R β | ≤ N and α/|R α/|R| | = α/(α/|R|)|R| = O(1).

  build in time O(N ) and multiply in time O(|R| ω • α i /|R| + |R| 2 (α i /|R|) log(α i /|R|)) by Lemma 12. The overall time used for all applications of the second method is:O(N ) + i O(|R| ω • α i /|R| + |R| 2 (α i /|R|) log(α i /|R|)) = O(|R| ω-2 m + m log m + N ),using the fact that α = m /|R|. Since |R| ≤ m , this is in fact O((m ) ω-1 + m log m + N ).

  k , (19/18) k+1 ) for each integer k ranging from . These intervals are a partition of the set of all strings in S of length up to m; longer strings are not addressed in EDSM by solving AP.For each integer k from , let be an integer such that the length of every string in S k belongs to [9/8 • , 5/4 • ). Note that such an integer always exists for an appropriate choice of the integer constant c. In fact, it must hold that The last equation holds for k ≥ 58, implying that we will process naïvely the strings of length up to c = 23, and each S k , for k ranging from 58 to log m log(19/18) , will be processed separately as described in the next paragraph.

														log c log(19/18) to
	log m
	log(19/18) log c log(19/18) to log(19/18) 9 log m 8 • ≤ 19 18 k < 19 18 k+1 ≤ 5 4 • ⇐⇒	4 5	•	19 18	k+1	≤	≤	8 9	•	19 18
	4 5	•	19 18	k+1	+ 1 ≤	8 9	•	19 18	k	⇐⇒	45 2	≤	19 18

k .

To ensure that there exists an integer satisfying such conditions, it must actually hold that k .

  • , we can generate its (unique) maximal -periodic substring in O(|S|) time.Proof. We start with observing that any length-substring of S must contain S[( /2 + 1) . . ] inside. Consequently, we can proceed similarly as in the proof of Lemma 5. We compute

p = per(S[( /2 + 1) . . ]) in O(|S|) time. If p > /4 then S does not contain any -periodic substrings. Otherwise, we compute in O(|S|) time how far the period p extends to the left and to the right; that is, we compute the smallest i ≤ /2 + 1 such that S[k] = S[k + p] for every k = i, i+1, . . . , /2 and the largest j ≥ such that S[k] = S[k-p] for every k = +1, +2, . . . , j. If j -i + 1 ≥ then S[i . . j] is a maximal -periodic substring of S, and, as shown earlier by Lemma 9, S cannot contain any other maximal -periodic substrings. We return S[i . . j] as the (unique) maximal -periodic substring of S.

A preliminary version of this work appeared in ICALP

[START_REF] Bernardini | Even Faster Elastic-Degenerate String Matching via Fast Matrix Multiplication[END_REF].

Acknowledgments

GR and NP are partially supported by MIUR-SIR project CMACBioSeq "Combinatorial methods for analysis and compression of biological sequences" grant n. RBSI146R5L.

This project has received funding from the European Union's Horizon 2020 research and innovation programme under the Marie Skłodowska-Curie grant agreement No 872539.

which is essentially equivalent to constructing a 2D range tree [START_REF] Bentley | Multidimensional binary search trees used for associative searching[END_REF]. The total number of points in all obtained instances increases by a factor of O(log 2 m), making the total number of red points in all instances O(m/ • log 5 m), while the total number of blue points is O(N/ • log 3 m). There is an occurrence of a string S ∈ S generated by H and starting at position i -j + 1 in P if and only if some simpler instance contains a red point created for some (i, x, y) and a blue point created for some (u, v) corresponding to S[j . . (j + |H| -1)] = H. In the following we focus on processing a single simpler instance.

To process a simpler instance we need to check if U [i -j] = 1, for a red point created for some (i, x, y) and a blue point created for some (u, v) corresponding to S[j . . (j + |H| -1)] = H, and if so set V [i -j + |S|] = 1. This has a natural interpretation as an instance of BMM: we create a 5/4

and only if there is a blue point created for some (u, v) corresponding to S[j . . (j + |H| -1)] = H; then for every red point created for some (i, x, y) we construct a bit vector U i = U [(i -5/4 • ) . . (i -1)] (if i < 5/4 • , we pad U i with 0s to make its length always equal to 5/4 • ); calculate V i = M × U i ; and finally set V [i + j] = 1 whenever V i [j] = 1 (and i + j ≤ m). Lemma 7. V i [k] = 1 if and only if there is a blue point created for some (u, v) corresponding to S[j . . (j + |H| -1)] = H such that U [i -j] = 1 and k = |S| -j.

Proof. By definition of

and hence the previous condition can be rewritten as

The total length of all vectors U i and V i is O(m log 5 m), so we can afford to extract the appropriate fragment of U and then update the corresponding fragment of V . The bottleneck is computing the matrix-vector product V i = M × U i . Since the total number of 1s in all matrices M is bounded by the total number of blue points, a naïve method would take O(N/ • log 3 m) time; we overcome this by processing together all multiplications concerning the same matrix M , thus amortizing the costs. Let U i 1 , U i 2 , . . . , U is be all bit vectors that need to be multiplied with M , and let z a parameter to be determined later. We distinguish between two cases: (i) if s < z, then we compute the products naïvely by iterating over all 1s in M , and the total computation time, when summed up over all such matrices M , is O(N/ • log 3 m • z); (ii) if s ≥ z, then we partition the bit vectors into s/z ≤ s/z + 1 groups of z (padding the last group with bit vectors containing all 0s) and, for every group, we create a single matrix whose columns contain all the bit vectors belonging to the group. Thus, we reduce the problem of computing all matrix-vector the latter form, and the total length of all S ∈ S is N . The total number of occurrences of a string

, and all such occurrences can be generated in time proportional to their number. Thus, for every (i, j) ∈ C(β), we can generate all occurrences of the corresponding string and appropriately update V in O(α • |C(β)|) total time.

Small β. We start by giving a technical lemma on the complexity of multiplying two r × r matrices whose cells are polynomials of degree up to d. Lemma 12. If two r × r matrices over Z can be multiplied in O(r ω ) time, then two r × r matrices over Z[X] with degrees up to d can be multiplied in Õ(dr ω ) time.

Proof. Let A and B be two r × r matrices over Z[X] with degrees up to d. We reduce the product A • B = C to 2d products of r × r matrices over Z as follows. We evaluate the polynomials of each matrix in the complex (2d)th roots of unity: let A i and B i be the matrices obtained by evaluating the polynomials of A and B in the i-th such root, respectively. We then perform the 2d products

are finally interpolated to obtain the coefficient representation of C[i, j], for each i, j = 1, . . . , r, in O(d log d) time for each polynomial [START_REF] Cooley | An algorithm for the machine calculation of complex Fourier series[END_REF]. Since we perform 2d products of matrices in Z r×r , and we evaluate and interpolate r 2 polynomials of degree up to 2d, the overall time complexity is 2dO(r ω ) + r 2 O(d log d) = Õ(dr ω ).

Unlike in the large β case, we process β = 2, . . . , α/|R| simultaneously as follows. For each β we construct an |R| × |R| matrix M β , with M β [i, j] = 1 if and only if (i, j) ∈ C(β) (and M β [i, j] = 0 otherwise), and collect them in a single 3D matrix M ∈ {0, 1} |R|×|R|×(α/|R|-1) with the third dimension corresponding to the value of β. We then create another α × |R| matrix, denoted by M , by setting The product M • M = M allows us to recover the updates to V by observing that V [(q + 1) • |R| + j] = 1 if and only if x q appears with non-zero coefficient in the polynomial at M [j]. We aim at reducing this product to a matrix-matrix product over Z[X] with degrees up to α/|R|, so as to compute it efficiently by applying Lemma 12.

The idea now is to decompose the columns of M into |R| chunks of size α/|R| in order to transform it into another 3D matrix. To this end, we transform M into an |R| × |R| × (α/|R|) matrix A by setting

By interpreting A as an |R| × |R| matrix over Z[X] with degrees up to α/|R|, and interpreting M as a vector of length |R| over Z[X] with degrees up to α, we have that the first row of A consists of the coefficients of x 1 , . . . , x α/|R| of each of the |R| polynomials of M , the second row consists of the coefficients of x α/|R|+1 , . . . , x 2α/|R| of each of the |R| polynomials of M , and so on. In general, A[k, i] consists of the coefficients of x (k-1)α/|R|+1 , . . . , x kα/|R| of polynomial M [i].

The product A • M = C still allows us to recover the updates of V , by observing that V [((k -1)α/|R| + 1 + q + 1)|R| + j] = 1 if x q appears with non-zero coefficient in the polynomial at C[k, j]. This is because at row A[k, •] there are the coefficients that correspond to U [γ•|R|+i-1] for γ = (k -1)α/|R| + 1, . . . , kα/|R| and i = 1, . . . , |R|, and hence a x q appearing at C[k, j] is equivalent to a x q+(k-1)α/|R|+1 at M [j].