Date: 2025-11-13 Status: Phase 1 COMPLETE (with architectural refinement)
Phase 1 successfully established the infrastructure for transposition and merge/split operations in the Universal automaton. All 156 tests pass with backward compatibility maintained.
File: src/transducer/universal/position.rs:93-103
pub trait PositionVariant: Clone + fmt::Debug + PartialEq + Eq + std::hash::Hash {
type State: Clone + fmt::Debug + PartialEq + Eq + std::hash::Hash + Default;
fn variant_name() -> &'static str;
}
TranspositionState (position.rs:119-133):
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
pub enum TranspositionState {
#[default]
Usual, // Regular position i#e
Transposing, // Transposition state i#e_t
}
MergeSplitState (position.rs:151-165):
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
pub enum MergeSplitState {
#[default]
Usual, // Regular position i#e
Splitting, // Split state i#e_s
}
File: position.rs:197-233
Changed from:
INonFinal { offset: i32, errors: u8, variant: PhantomData<V> }
To:
INonFinal { offset: i32, errors: u8, variant_state: V::State }
This allows tracking variant-specific state (Transposing, Splitting, Usual).
New constructors (position.rs:350-431):
new_i_with_state() - Create I-type with custom variant statenew_m_with_state() - Create M-type with custom variant statevariant_state() - Accessor for variant stateUpdated constructors:
new_i() and new_m() now use V::State::default()Key Insight: Rust doesn't allow calling methods from specialized impl blocks (impl UniversalPosition<Transposition>) when working with generic types (UniversalPosition<V>).
Solution: Keep a single generic successors() method in impl<V: PositionVariant> that:
variant_state and dispatch to variant-specific logicFile: position.rs:476-491
pub fn successors(
&self,
bit_vector: &CharacteristicVector,
max_distance: u8,
) -> Vec<Self> {
match self {
Self::INonFinal { offset, errors, .. } => {
Self::successors_i_type_standard(*offset, *errors, bit_vector, max_distance)
}
Self::MFinal { offset, errors, .. } => {
Self::successors_m_type_standard(*offset, *errors, bit_vector, max_distance)
}
}
}
$ RUSTFLAGS="-C target-cpu=native" cargo test --lib universal
test result: ok. 156 passed; 0 failed; 0 ignored; 0 measured
Backward Compatibility: ✅ Fully maintained
() is zero-sized type)To implement transposition logic, the successors() method needs to be enhanced to check variant state:
pub fn successors(
&self,
bit_vector: &CharacteristicVector,
max_distance: u8,
) -> Vec<Self> {
match self {
Self::INonFinal { offset, errors, variant_state } => {
V::compute_i_successors(
*offset,
*errors,
variant_state,
bit_vector,
max_distance,
)
}
Self::MFinal { offset, errors, variant_state } => {
V::compute_m_successors(
*offset,
*errors,
variant_state,
bit_vector,
max_distance,
)
}
}
}
Alternative Approach: Add trait methods to PositionVariant:
pub trait PositionVariant {
type State: ...;
fn variant_name() -> &'static str;
// NEW: variant-specific successor generation
fn compute_i_successors(
offset: i32,
errors: u8,
variant_state: &Self::State,
bit_vector: &CharacteristicVector,
max_distance: u8,
) -> Vec<UniversalPosition<Self>>;
}
PositionVariant traitStandard implementationTranspositionState and TranspositionMergeSplitState and MergeAndSplitUniversalPosition enumvariant_state() accessorsuccessors() methodRust's Type System: Specialized impl blocks are great for documentation and type-specific APIs, but generic code can't see them. Need trait-based dispatch or runtime type checking.
Zero-Cost Abstractions: Using associated types with () for Standard variant ensures zero runtime overhead.
Breaking Changes Are OK: Since Universal automaton hasn't been published, we can make breaking API changes to get the design right.
Incremental Development: Phase 1 establishes infrastructure; variant-specific logic comes in Phase 2. This allows validating the design before implementing complex logic.
State associated type to PositionVariant traitTranspositionState and MergeSplitState enumsUniversalPosition to store variant statedocs/universal/transposition_implementation_plan.mddocs/universal/transposition_phase1_complete.mdEstimated Remaining Time for Full Implementation: 5-7 hours
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 |