Paper
Reconstructing Binary Words of Unknown Length with #-Subword Queries
19 pages · 13 marked passages · pdflatex · download PDF · lax-100001
-
The subword counting game
A guesser must find a hidden binary word. It may ask how often a chosen word occurs in the hidden word as a subword. The letters of the chosen word are matched, in order, to letters of the hidden word, and letters of the hidden word may be skipped. Occurrences that use different positions are counted separately. For example, occurs five times in .
The guesser is a rule. It sees its earlier queries together with the answers, and then either asks one more query or stops with a guess. A history is a run of the rule when every answer is true, every query is the one that the rule asks after the exchanges before it, and the rule finally stops with the hidden word. A rule reconstructs all words, with a bound on the number of queries, when one rule, one constant and one length threshold work for every hidden word. The run uses only allowed queries, and a hidden word of length at least the threshold needs at most exchanges.
1 /- 2 Copyright (c) 2026 Anonymous. All rights reserved. 3 Released under Apache 2.0 license as described in the file LICENSE. 4 Authors: ChatGPT (OpenAI), Claude (Anthropic) 5 -/ 6 import Mathlib.Data.List.Count 7 import Mathlib.Data.List.Lex 8 import Mathlib.Data.List.Sublists 9 import Mathlib.Data.Real.Basic 10 11 /-! 12 --- 13 title: The subword counting game 14 type: definition 15 --- 16 A guesser must find a hidden binary word. It may ask how often a chosen word occurs in the 17 hidden word as a subword. The letters of the chosen word are matched, in order, to letters of 18 the hidden word, and letters of the hidden word may be skipped. Occurrences that use different 19 positions are counted separately. For example, occurs five times in . 20 21 The guesser is a rule. It sees its earlier queries together with the answers, and then either 22 asks one more query or stops with a guess. A history is a run of the rule when every answer is 23 true, every query is the one that the rule asks after the exchanges before it, and the rule 24 finally stops with the hidden word. A rule reconstructs all words, with a bound on the number of 25 queries, when one rule, one constant and one length threshold work for every hidden word. The 26 run uses only allowed queries, and a hidden word of length at least the threshold needs at 27 most exchanges. 28 -/ 29 30 namespace Lax100001.Counting 31 32 /-- A binary word, written as a list of bits. The bit is the letter 33 and the bit is the letter . -/ 34 abbrev Word := List Bool 35 36 /-- The number of occurrences of in as a subword. 37 38 An occurrence is a choice of positions of , from left to right, whose letters spell 39 . The list has one entry for each choice of positions, so 40 counting the entries equal to counts the occurrences. For example, 41 . The word is 42 , and the pattern is spelled by the positions , , 43 , and . -/ 44 def count (word pattern : Word) : ℕ := word.sublists.count pattern 45 46 /-- One question and the answer that the guesser received. -/ 47 structure Exchange where 48 /-- The word whose occurrences the guesser asked for. -/ 49 query : Word 50 /-- The number of occurrences that the guesser was told. -/ 51 answer : ℕ 52 53 /-- What the guesser does next: ask for another count, or stop with a guess. -/ 54 inductive Move where 55 /-- Ask for the number of occurrences of in the hidden word. -/ 56 | ask (query : Word) 57 /-- Stop and name as the hidden word. -/ 58 | stop (guess : Word) 59 60 /-- A guesser. It sees the earlier exchanges, oldest first, and chooses its next move. The 61 empty list is what it sees at the start. -/ 62 abbrev Rule := List Exchange → Move 63 64 /-- is a complete play of against the hidden word 65 . 66 67 Every answer in the history is true. Every query in the history is the one that the rule asks 68 when it has seen only the exchanges before it. After the last exchange the rule stops with 69 the hidden word. For example, let a rule ask first and stop with after 70 the answer . Then is a run of this rule against the hidden 71 word . -/ structure IsRun (rule : Rule) (word : Word) (history : List Exchange) : Prop 72 where 73 /-- Every answer is the number of occurrences of its query in the hidden word. -/ 74 answers_true : ∀ e ∈ history, e.answer = count word e.query 75 /-- Each query is the one that the rule asks after the exchanges before it. -/ 76 asks_next : ∀ (i : ℕ) (hi : i < history.length), 77 rule (history.take i) = .ask history[i].query 78 /-- After the whole history the rule stops with the hidden word. -/ 79 stops : rule history = .stop word 80 81 /-- A nonempty word is a Lyndon word when it is smaller than each of its proper rotations. 82 83 Words are compared in dictionary order, with . For example , and 84 are Lyndon words, while and are not. -/ 85 def IsLyndon (pattern : Word) : Prop := 86 pattern ≠ [] ∧ ∀ k, 0 < k → k < pattern.length → 87 pattern < pattern.drop k ++ pattern.take k 88 89 /-- One rule reconstructs every binary word, asks only allowed queries, and uses few queries. 90 91 There are a rule, a positive constant and a length threshold such that every hidden word has a 92 run of the rule in which every query satisfies . When the hidden word has length 93 at least the threshold, the run has at most exchanges. The rule is 94 chosen before the hidden word, so it does not know , which occurs only in the bound. -/ 95 def Reconstructs (allowed : Word → Prop) (rate : ℕ → ℝ) : Prop := 96 ∃ rule : Rule, ∃ constant : ℝ, 0 < constant ∧ ∃ threshold : ℕ, 97 ∀ word : Word, ∃ history : List Exchange, 98 IsRun rule word history ∧ (∀ e ∈ history, allowed e.query) ∧ 99 (threshold ≤ word.length → (history.length : ℝ) ≤ constant * rate word.length) 100 101 end Lax100001.Counting 102 -
Sublogarithmic reconstruction
Every binary word can be reconstructed using ordinary exact counts. The number of queries on a word of length is at most a constant times the square root of , where is the integer logarithm, which rounds down.
1 /- 2 Copyright (c) 2026 Anonymous. All rights reserved. 3 Released under Apache 2.0 license as described in the file LICENSE. 4 Authors: ChatGPT (OpenAI), Claude (Anthropic) 5 -/ 6 import Lax100001.Counting 7 import Mathlib.Analysis.Real.Sqrt 8 import Mathlib.Data.Nat.Log 9 10 /-! 11 --- 12 title: Sublogarithmic reconstruction 13 type: theorem 14 --- 15 Every binary word can be reconstructed using ordinary exact counts. The number of queries on a 16 word of length is at most a constant times the square root of , 17 where is the integer logarithm, which rounds down. 18 -/ 19 20 namespace Lax100001.Unrestricted 21 22 /-- The bound on the number of queries for a word of length 23 . The integer logarithm is the largest with , and when 24 . For example and . -/ 25 noncomputable def rate (n : ℕ) : ℝ := 26 √((Nat.log 2 n : ℝ) * (Nat.log 2 (Nat.log 2 n) : ℝ)) 27 28 /-- One rule reconstructs every binary word with any queries allowed, using a number of queries 29 that is at most a constant times . -/ 30 axiom reconstruction : Counting.Reconstructs (fun _ ↦ True) rate 31 32 end Lax100001.Unrestricted 33 -
thm✓
Lax100001.LyndonReconstruction with Lyndon patterns
Every query is a Lyndon word: it is smaller than each of its proper rotations. Even so, every binary word can be reconstructed. The number of queries on a word of length is at most a constant times , where is the integer logarithm, which rounds down.
1 /- 2 Copyright (c) 2026 Anonymous. All rights reserved. 3 Released under Apache 2.0 license as described in the file LICENSE. 4 Authors: ChatGPT (OpenAI), Claude (Anthropic) 5 -/ 6 import Lax100001.Counting 7 import Mathlib.Data.Nat.Log 8 9 /-! 10 --- 11 title: Reconstruction with Lyndon patterns 12 type: theorem 13 --- 14 Every query is a Lyndon word: it is smaller than each of its proper rotations. Even so, every 15 binary word can be reconstructed. The number of queries on a word of length is at most a 16 constant times , where is the integer logarithm, which rounds down. 17 -/ 18 19 namespace Lax100001.Lyndon 20 21 /-- The bound on the number of queries for a word of length . The integer 22 logarithm is the largest with , and when . For 23 example and . -/ 24 def rate (n : ℕ) : ℝ := ((1 + Nat.log 2 n : ℕ) : ℝ) 25 26 /-- One rule reconstructs every binary word with Lyndon queries only, using a number of queries 27 that is at most a constant times . -/ 28 axiom reconstruction : Counting.Reconstructs Counting.IsLyndon rate 29 30 end Lax100001.Lyndon 31 -
thm✓
Lax100001.RowsCounting a zero followed by ones
The ones of a binary word cut its zeros into groups. Group holds the zeros that have exactly ones before them. A word with ones has the groups . The number of occurrences of followed by ones is determined by the sizes of these groups: a zero in group has ones after it, and it starts as many occurrences as there are ways to choose of those ones.
1 /- 2 Copyright (c) 2026 Anonymous. All rights reserved. 3 Released under Apache 2.0 license as described in the file LICENSE. 4 Authors: ChatGPT (OpenAI), Claude (Anthropic) 5 -/ 6 import Lax100001.Counting 7 import Mathlib.Algebra.BigOperators.Group.Finset.Basic 8 import Mathlib.Data.Nat.Choose.Basic 9 10 /-! 11 --- 12 title: Counting a zero followed by ones 13 type: theorem 14 --- 15 The ones of a binary word cut its zeros into groups. Group holds the zeros that have exactly 16 ones before them. A word with ones has the groups . The number of 17 occurrences of followed by ones is determined by the sizes of these groups: a zero 18 in group has ones after it, and it starts as many occurrences as there are ways to 19 choose of those ones. 20 -/ 21 22 namespace Lax100001.Rows 23 24 open Counting 25 26 /-- The sizes of the groups of zeros of . 27 28 Entry counts the zeros of that have exactly ones before them, and the list 29 has one entry for each of the groups, where is the number of ones. For example, 30 : the word 31 has one zero before the first one, one between the first and second ones, none between the second 32 and third ones, and one after the third one. -/ 33 def groups : Word → List ℕ 34 | [] => [0] 35 | true :: tail => 0 :: groups tail 36 | false :: tail => 37 match groups tail with 38 | [] => [1] 39 | a :: rest => (a + 1) :: rest 40 41 /-- The number of occurrences of followed by ones in a word is the sum over the 42 groups of the size of group times , where is the number of ones and 43 is the number of groups. For the word and the groups are 44 . The sum is 45 , which 46 is . 47 -/ 48 axiom count_zero_ones (word : Word) (r : ℕ) : 49 count word (false :: List.replicate r true) = 50 ∑ s ∈ Finset.range (groups word).length, 51 (groups word)[s]! * ((groups word).length - 1 - s).choose r 52 53 end Lax100001.Rows 54 -
no assumptions
thm✓Lax100001.RowsInduct on the word: a leading zero starts new occurrences and a leading one starts none.
-
thm✓
Lax100001.TailA binomial tail bound
Let be a rational number with . The sum of over the numbers below any bound is at most . The sum over all has exactly this value, so the bound does not depend on .
1 /- 2 Copyright (c) 2026 Anonymous. All rights reserved. 3 Released under Apache 2.0 license as described in the file LICENSE. 4 Authors: ChatGPT (OpenAI), Claude (Anthropic) 5 -/ 6 import Mathlib.Algebra.BigOperators.Ring.Finset 7 import Mathlib.Data.Nat.Choose.Basic 8 import Mathlib.Data.Rat.Cast.Order 9 10 /-! 11 --- 12 title: A binomial tail bound 13 type: theorem 14 --- 15 Let be a rational number with . The sum of over the 16 numbers below any bound is at most . The sum over all 17 has exactly this value, so the bound does not depend on . 18 -/ 19 20 namespace Lax100001.Tail 21 22 /-- A finite weighted sum of binomial coefficients is at most a geometric power. -/ 23 axiom tail_le (x : ℚ) (hx : 0 ≤ x) (hx1 : x < 1) (d N : ℕ) : 24 (∑ j ∈ Finset.range N, x ^ (j + 1) * (j.choose d : ℚ)) ≤ (x / (1 - x)) ^ (d + 1) 25 26 end Lax100001.Tail 27 -
no assumptions
thm✓Lax100001.TailInduct on the row, relating each row of finite sums to the previous one.
-
thm✓
Lax100001.PeelPeeling
Let be the product of over . It is at . At a natural number it is times the binomial coefficient of and , so it vanishes for . Take numbers and weights for , with , and put . Then is times the sum of over . So keeps , drops the next terms, and leaves a remainder that is small when the later terms are small. This is called peeling. It has three consequences.
- If all and are nonnegative, then .
- Let and . If for , then . This needs no sign condition on and .
- Let and be sequences of natural numbers that both satisfy this bound, with nonnegative weights. If they give the same , then .
- thm✓
Lax100001.Peel(1st statement) - thm✓
Lax100001.Peel(2nd statement) - thm✓
Lax100001.Peel(3rd statement)
1 /- 2 Copyright (c) 2026 Anonymous. All rights reserved. 3 Released under Apache 2.0 license as described in the file LICENSE. 4 Authors: ChatGPT (OpenAI), Claude (Anthropic) 5 -/ 6 import Mathlib.Algebra.BigOperators.Group.Finset.Defs 7 import Mathlib.Data.Rat.Defs 8 import Mathlib.Order.Interval.Finset.Nat 9 10 /-! 11 --- 12 title: Peeling 13 type: theorem 14 --- 15 Let be the product of over . It is at . At a natural 16 number it is times the binomial coefficient of and , so it vanishes 17 for . Take numbers and weights for , with 18 , and put . Then is 19 times the sum of over . So keeps , drops 20 the next terms, and leaves a remainder that is small when the later terms are small. This is 21 called peeling. It has three consequences. 22 23 1. If all and are nonnegative, then . 24 2. Let and . If 25 for , then . This needs no 26 sign condition on and . 27 3. Let and be sequences of natural numbers that both satisfy this bound, with nonnegative 28 weights. If they give the same , then . 29 -/ 30 31 namespace Lax100001.Peel 32 33 /-- The polynomial of degree in . The index lets 34 the product range over . For example , which 35 takes the values at . -/ 36 def P (d : ℕ) (s : ℚ) : ℚ := ∏ i ∈ Finset.range d, (1 - s / (i + 1)) 37 38 /-- For nonnegative and with , the weighted sum 39 differs from by times a nonnegative number. 40 So it is at least if is even, and at most if is odd. -/ 41 axiom sign_nonneg (d N : ℕ) (g ω : ℕ → ℚ) (hg : ∀ s ≤ N, 0 ≤ g s) (hω : ∀ s ≤ N, 0 ≤ ω s) 42 (hω₀ : ω 0 = 1) : 43 0 ≤ (-1) ^ d * (∑ s ∈ Finset.range (N + 1), g s * ω s * P d s - g 0) 44 45 /-- Let and . If 46 for , and , then the weighted sum 47 differs from by times a number that is less 48 than . No sign condition on and is needed. -/ 49 axiom lt_one (d N : ℕ) (y M : ℚ) (g ω : ℕ → ℚ) (hω₀ : ω 0 = 1) (hy : 0 ≤ y) (hy₁ : y < 1) 50 (hM : M * (y / (1 - y)) ^ (d + 1) < 1) (hgω : ∀ s ∈ Finset.Icc 1 N, g s * ω s ≤ M * y ^ s) : 51 (-1) ^ d * (∑ s ∈ Finset.range (N + 1), g s * ω s * P d s - g 0) < 1 52 53 /-- Two sequences and of natural numbers that satisfy the bounds of , 54 with nonnegative weights , and have the same weighted sum 55 , have the same first entry. -/ 56 axiom head_eq (d N : ℕ) (y M : ℚ) (g g' : ℕ → ℕ) (ω : ℕ → ℚ) (hω : ∀ s ≤ N, 0 ≤ ω s) 57 (hω₀ : ω 0 = 1) (hy : 0 ≤ y) (hy₁ : y < 1) (hM : M * (y / (1 - y)) ^ (d + 1) < 1) 58 (hg : ∀ s ∈ Finset.Icc 1 N, g s * ω s ≤ M * y ^ s) 59 (hg' : ∀ s ∈ Finset.Icc 1 N, g' s * ω s ≤ M * y ^ s) 60 (hS : ∑ s ∈ Finset.range (N + 1), g s * ω s * P d s = 61 ∑ s ∈ Finset.range (N + 1), g' s * ω s * P d s) : 62 g 0 = g' 0 63 64 end Lax100001.Peel 65 -
no assumptions
The polynomial takes the value times a binomial coefficient at every natural number , so is a sum of nonnegative terms.
-
no assumptions
The remainder is at most times a tail sum of the binomial series, which bounds by .
-
no assumptions
By the first two parts, each sum differs from its first entry by times a number in . So the first entries are integers that differ by less than .
-
no assumptions
thm✓Lax100001.LyndonRule Y asks only Lyndon words, its answers determine the word, and it asks at most queries.
-
no assumptions
Rule U reads the word in rounds and then completes it, its answers determine the word, and it asks at most queries for .
Loading the paper…