Date: 2025-11-13 Status: Phase 2 infrastructure complete, logic needs debugging
Phase 2 successfully implemented the infrastructure for transposition with trait-based dispatch. However, acceptance tests are failing, indicating the transposition logic needs correction.
Infrastructure ✅
PositionVariant trait extended with compute_i_successors() and compute_m_successors()successors() method uses trait dispatchBackward Compatibility ✅
Failing: 9 out of 12 transposition tests Passing: 3 tests (distance zero, rejects non-adjacent, with standard operations at distance 2)
Failing tests:
test_transposition_adjacent_swap_start: "test" → "etst"test_transposition_adjacent_swap_middle: "test" → "tset"test_transposition_adjacent_swap_end: "test" → "tets"test_transposition_two_chars: "ab" → "ba"test_transposition_vs_standardtest_transposition_longer_wordstest_transposition_multiple_swapstest_transposition_with_repeated_charstest_transposition_empty_and_single_char (partial failure)Transposition Logic Interpretation
Current implementation (position.rs:202-323):
TranspositionState::Usual => {
// Get standard successors
let mut successors = UniversalPosition::<Self>::successors_i_type_standard(...);
// Add transposition initiation if NO match
if !bit_vector.is_match(match_index) && errors < max_distance {
// Enter transposition: (i+1)#(e+1)_t
successors.push(new_i_with_state(offset + 1, errors + 1, ..., Transposing));
}
}
TranspositionState::Transposing => {
// Complete transposition if match
if bit_vector.is_match(match_index) {
vec![new_i_with_state(offset + 1, errors, ..., Usual)]
} else {
vec![]
}
}
Hypothesis 1: Transposition should trigger on mismatch where the next character would match the previous input character. The current logic might not be checking this correctly.
Hypothesis 2: The bit vector indexing might be off. When checking for transposition:
Bit Vector Semantics
The characteristic vector β(x, w') tells us if character x matches positions in window w'.
For transposition at position k:
Issue: The current bit vector only encodes matches for the current input character. To check transposition, we'd need access to the previous input character, which isn't available in the successor function signature.
State Machine Flow
Current implementation:
Potential issue: The transition might need to verify that:
But we don't have access to previous input/word characters in the successor function.
The fundamental issue is that transposition is a 2-character operation that depends on matching:
However, the Universal automaton processes one character at a time using bit vectors that only encode matches for the current input character.
Traditional Damerau-Levenshtein keeps a full DP matrix where you can look back at diagonal-2 cells. The Universal automaton's parameter-free approach needs a different strategy.
From the thesis (page 16):
For transposition state i#e_t:
δ^D,t_e(i#e_t, b) = {(i+2)#e} if b[1] = 1, else ∅
Key insight: b[1] refers to position 1 in the bit vector, which corresponds to index n+offset+1 in our implementation.
Hypothesis: The transposition state tracks that we've seen a mismatch and advances the position by 1. Then, when processing the next input character, if b[1] = 1 (match at offset+1), we confirm the transposition.
Walk through "ab" → "ba" with n=1:
Initial: State = {I+0#0_usual}
Process 'b' (input[0]):
Hmm, that's wrong - we should process the first character 'b' against word 'ab', and it doesn't match 'a' at position 0.
Let me reconsider: The bit vector β(x_k, s_n(w,k)) is constructed for input character x_k and the relevant subword s_n(w,k).
For "ab" with input "ba":
This needs careful analysis of the bit vector construction and indexing.
Instrument the transposition successor functions to log:
Run both Standard and Transposition variants on same inputs and compare state transitions.
Find worked examples in Mitankin's thesis and trace through them step-by-step.
bit_vector.rssrc/transducer/universal/position.rs:202-323 - Transposition implementationsrc/transducer/universal/bit_vector.rs - Characteristic vector constructionsrc/transducer/universal/automaton.rs - State transitions and acceptanceAfter reviewing the logic more carefully, I believe the issue might be:
src/transducer/universal/position.rssrc/transducer/universal/automaton.rs:588-716Can 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 |