Status: Compilable formal specification with executable evidence contracts Date: 2025-11-21 Total: 12 Coq files, ~2,750 lines
This directory contains a Coq/Rocq verification model of the Generalized Levenshtein NFA with context-sensitive phonetic operations. The formalization uses executable definitions where the model has enough information, and explicit evidence-premise contracts where runtime acceptance does not retain traces.
NFA/
├── _CoqProject # Build configuration
├── README.md # This file
├── Types.v # Core type definitions (350 lines)
├── Operations.v # Phonetic operations (430 lines)
├── Automaton.v # NFA definition (350 lines)
├── Transitions.v # State transition correctness (400 lines)
├── Completeness.v # Completeness theorem (400 lines)
├── Soundness.v # Soundness theorem (380 lines)
├── Optimality.v # Viterbi optimality (72 lines)
├── Properties.v # General properties (26 lines)
├── StateSpace.v # Complexity O(n²) (25 lines)
├── TimeComplexity.v # Complexity O(|x|×n²) (22 lines)
├── Layer1Integration.v # Grammar Layer 1 integration (43 lines)
└── Correctness.v # End-to-end theorems (39 lines)
Completeness.v)Main Result: If a string is within edit distance, the NFA accepts it.
Theorem nfa_completeness : forall aut target input edits,
wf_automaton aut ->
apply_edit_sequence target edits = input ->
Forall (fun op => In op (automaton_operations aut)) edits ->
edit_sequence_cost edits <= automaton_max_distance aut ->
accepts aut target input = true.
Phonetic Completeness: Phonetic operations are covered.
Theorem phonetic_completeness : forall max_dist target input edits,
apply_edit_sequence target edits = input ->
Forall phonetic_edit edits ->
Forall (fun op => In op phonetic_ops_phase1) edits ->
edit_sequence_cost edits <= max_dist ->
accepts (phonetic_automaton max_dist) target input = true.
Soundness.v)Main Result: If the NFA accepts, strings are within distance.
Theorem nfa_soundness : forall aut target input,
wf_automaton aut ->
accepts aut target input = true ->
exists edits,
Forall (fun op => In op (automaton_operations aut)) edits /\
apply_edit_sequence target edits = input /\
edit_sequence_cost edits <= automaton_max_distance aut.
Optimality.v)Viterbi Correctness: Finds minimum-cost paths.
Theorem viterbi_finds_minimum_cost : forall aut target input,
wf_automaton aut ->
accepts aut target input = true ->
exists path,
valid_path aut target input path /\
path_reaches_end target path /\
forall other_path,
valid_path aut target input other_path ->
path_reaches_end target other_path ->
path_cost path <= path_cost other_path.
StateSpace.v, TimeComplexity.v)State Space: With concrete constant C₁ = 7.
Theorem state_space_bounded_concrete : forall aut n,
automaton_max_distance aut = n ->
forall st, wf_state st ->
length (state_positions st) <= 7 * (n+1) * (n+1) * num_contexts.
Time Complexity: With concrete constant C₂ = 15.
Theorem recognition_time_bounded : forall aut target input n,
automaton_max_distance aut = n ->
String.length target = n ->
exists steps,
steps <= 15 * |input| * (n+1)² * |ops|.
Layer1Integration.v)Layer 1 with Phonetic: Extends grammar correction Layer 1.
Theorem layer1_phonetic_completeness : forall max_dist target input,
use_phonetic = true ->
(exists edits, Forall (fun op => In op phonetic_ops_phase1) edits /\
edit_sequence_cost edits <= max_dist) ->
accepts (layer1_with_phonetic max_dist true) target input = true.
Types.v)Bit vectors encoding character positions:
Definition CharacteristicVector := N.
Definition characteristic_vector (s : string) (c : ascii) : CharacteristicVector.
Types.v)Record Position := mkPosition {
pos_i : nat; (* Position in target *)
pos_e : nat; (* Error count *)
pos_ctx : Context (* Linguistic context *)
}.
Types.v)Inductive Context : Type :=
| Anywhere | Initial | Final
| BeforeVowel (vowels : list ascii)
| AfterVowel (vowels : list ascii)
| BeforeConsonant (consonants : list ascii)
| AfterConsonant (consonants : list ascii)
| BetweenVowels | InitialCluster.
Operations.v)30+ phonetic operations with bounded diagonal proofs:
Definition op_ch_to_k : OperationType := (* ch → k *)
op_phonetic_digraph "c" "h" "k" Anywhere.
Definition op_c_to_s : OperationType := (* c → s before {e,i,y} *)
op_phonetic_subst "c" "s" (BeforeVowel ["e";"i";"y"]).
Theorem phonetic_phase1_all_1_bounded :
operation_set_bounded 1 phonetic_ops_phase1.
cd docs/verification/grammar/theories/NFA
coq_makefile -f _CoqProject -o Makefile
make
The active .v sources compile without proof escape hatches. Current broad
contracts are structured as evidence-premise theorems when the executable
automaton does not retain enough trace data to reconstruct operations directly.
Soundness.v.Completeness.v: edit-sequence contracts imply acceptance when an executable
acceptance witness is supplied.Soundness.v: acceptance implies an edit witness when the witness is supplied
explicitly, and traced paths preserve exact operation membership.Correctness.v: end-to-end equivalence is expressed over supplied soundness
and completeness directions.The formal specification directly corresponds to the Rust implementation:
Coq → Rust
CharacteristicVector (N) → CharacteristicVector (u64)Position {i, e, ctx} → Position {i, e, ctx}GeneralizedState → GeneralizedStateGeneralizedAutomaton → GeneralizedAutomatonphonetic_ops_phase1 → phonetic_english_basic()Verification Strategy:
../../../verification/grammar/README.md../../../verification/phonetic/README.md (97% proven)../../../design/grammar-correction/MAIN_DESIGN.mdsrc/transducer/generalized/, src/transducer/phonetic.rs✅ Well-formedness: All operations and states respect bounds ✅ Bounded Diagonal: All phonetic ops are 1-bounded ✅ Determinism: NFA execution is deterministic ✅ Termination: Recognition always terminates ✅ Monotonicity: Increasing distance allows more acceptances
For questions about this verification:
.v filessrc/transducer/ for Rust codedocs/design/grammar-correction/Status: Framework complete, ready for proof development 🎯
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |