Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 7. Near-linear matching with a repeated substring

Proved
BackreferenceMatching.theorem_7

by Soh Kumabe · Dec 1, 2026 · Mathlib 0df444a (Lean v4.33.1)

computational-complexityregular-expressionsstring-algorithms

Given four ordinary regular expressions A,B,C,DA,B,C,DA,B,C,D and a word www, decide whether w=a b c b dw=a\,b\,c\,b\,dw=abcbd for some a∈L(A)a\in L(A)a∈L(A), b∈L(B)b\in L(B)b∈L(B), c∈L(C)c\in L(C)c∈L(C), and d∈L(D)d\in L(D)d∈L(D). The two copies of bbb are identical. One uniform word-RAM algorithm, including preprocessing, runs in 2O(s2)nlog⁡2n2^{O(s^2)}n\log^2 n2O(s2)nlog2n time for s=∣A∣+∣B∣+∣C∣+∣D∣s=|A|+|B|+|C|+|D|s=∣A∣+∣B∣+∣C∣+∣D∣ and n=∣w∣n=|w|n=∣w∣.

Preamble
import Definitions.Def_BackreferenceMatching_Algorithms
Formal statement
namespace BackreferenceMatching

theorem theorem_7 (q : ℕ) :
    ∃ (p : Program) (a c : ℕ), 0 < c ∧
      ∀ (r : Branch q) (w : Word q),
        DecidesWithin p a q (r.code ++ wordCode w) (ABCBD r w)
          (2 ^ (c * r.size^2) * (w.length + 1) * (logFactor w.length)^2) := by
  sorry

end BackreferenceMatching
Source
Soh Kumabe and Yuya Uezato, On the Complexity of the Matching Problem of Regular Expressions with Backreferences, arXiv:2605.07289, Theorem 7 (§§4–12 and Appendix C). https://arxiv.org/html/2605.07289v1#Thmtheorem7
Read-back

What the Lean code literally says, in plain math · GPT-6

For every q∈Nq\in\mathbb Nq∈N, there are a finite deterministic word-RAM program ppp, a natural number aaa, and a positive integer ccc with the following property. Given any four regular expressions A,B,C,DA,B,C,DA,B,C,D over Σq={i∈N∣i<q}\Sigma_q=\{i\in\mathbb N\mid i<q\}Σq​={i∈N∣i<q} and any word www over Σq\Sigma_qΣq​, ppp decides whether w=uvxvyw=uvxvyw=uvxvy for some u∈L(A)u\in L(A)u∈L(A), v∈L(B)v\in L(B)v∈L(B), x∈L(C)x\in L(C)x∈L(C), and y∈L(D)y\in L(D)y∈L(D). It halts within 2cs2(n+1)ℓ(n)22^{cs^2}(n+1)\ell(n)^22cs2(n+1)ℓ(n)2 instructions, where sss counts all syntax nodes in the four expressions, n=∣w∣n=|w|n=∣w∣, and ℓ(k)=1+⌊log⁡2(k+2)⌋\ell(k)=1+\lfloor\log_2(k+2)\rfloorℓ(k)=1+⌊log2​(k+2)⌋.

Both occurrences of vvv must be the same word. Any factor may be empty if its expression accepts the empty word. The target may also be empty, and it is the only possible target when q=0q=0q=0. The entire output is [1][1][1] when the factorization exists and [0][0][0] otherwise.

For an input of NNN entries the machine uses b=(a+1)ℓ(N+q+8)b=(a+1)\ell(N+q+8)b=(a+1)ℓ(N+q+8) bits per word. Its 2b2^b2b writable cells start at zero, and the input supports both sequential and indexed reads. Each executed instruction costs one, including a halt or an exhausted sequential read. Reaching an out-of-range program counter ends execution at no additional cost.

The input concatenates the prefix codes of A,B,C,DA,B,C,DA,B,C,D in that order and then appends the numeric letters of www. The respective tags for the empty language, the empty word, a letter, union, concatenation, and star are 0,1,2,3,4,50,1,2,3,4,50,1,2,3,4,5. A letter tag is followed by its value, and an operator tag is followed by the codes of its operands in order.

Human review
  • Endorsed by Shuze Chen · Dec 1, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Soh Kumabe · Dec 1, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me