qary_defect_seq
The infinite sequence over Fin q with defect spacing B and alphabet size q ≥ 2 whose initial q symbols are 0, ..., q-1 and for i ≥ q repeats the symbol from q-1 steps earlier when B divides i - q + 1, and otherwise takes the unique alphabet symbol absent from the preceding q-1 symbols.
Statement
def qary_defect_seq (q B : ℕ) (hq : 2 ≤ q) : ℕ → Fin q- Defined in
- knowledgebase
- Verified
- 10 Nov 2026
- Axioms
- none listed
- Used by 1
- qary_defect_wordFor alphabet size q ≥ 2, block spacing B, and length n, qary_defect_word q B n hq is the word of length n over Fin q obtained by…
Read back from the Lean
qary_defect_seq is a recursively defined function taking natural numbers q and B with a proof hq : 2 ≤ q, and producing a sequence ℕ → Fin q.
For each index i : ℕ, the value at i is defined by:
1. If i < q, it is i (as an element of Fin q).
2. If i ≥ q:
- If B divides i - q + 1, the value is the term at index i - (q - 1).
- Otherwise, it is the first element a ∈ Fin q (searching in increasing order 0, 1, …, q - 1) such that a is not equal to any of the q - 1 immediately preceding terms (qary_defect_seq q B hq (i - 1 - j)) for j ∈ {0, 1, …, q - 2}. If no such a exists, it defaults to 0 (though by the pigeonhole principle, such an a always exists).
Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.
Lean source view module on GitHub
/-- The deterministic defect sequence over Fin q with block period B. -/ def qary_defect_seq (q B : ℕ) (hq : 2 ≤ q) : ℕ → Fin q := fun i => if hi : i < q then ⟨i, by omega⟩ else if B ∣ i - q + 1 then qary_defect_seq q B hq (i - (q - 1)) else let absent := (List.finRange q).find? (fun a => (List.finRange (q - 1)).all (fun j => qary_defect_seq q B hq (i - 1 - j.1) != a)) absent.getD ⟨0, by omega⟩ termination_by i => i decreasing_by · omega · omega