1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//! Algorithms for weighted finite-state transducers.
//!
//! This module provides a comprehensive suite of algorithms for manipulating and
//! analyzing weighted finite-state transducers (WFSTs). The implementations follow
//! the theoretical framework established by Mohri et al. and are optimized for
//! practical speech recognition, natural language processing, and pattern matching
//! applications.
//!
//! # Overview
//!
//! Algorithms are organized into functional categories:
//!
//! | Category | Algorithms | Typical Use Case |
//! |----------|-----------|------------------|
//! | Composition | [`compose()`], [`intersect()`], [`difference()`] | Combining transducers |
//! | Optimization | [`determinize()`], [`minimize()`], [`remove_epsilons`] | Reducing FST size |
//! | Path Finding | [`shortest_path()`], [`shortest_distance()`] | Decoding, scoring |
//! | Transformation | [`reverse()`], [`project_input`], [`project_output`] | FST manipulation |
//! | Construction | [`union()`], [`concat()`], [`closure()`] | Building FSTs |
//!
//! # Complexity Summary
//!
//! | Algorithm | Time | Space | Requirements |
//! |-----------|------|-------|--------------|
//! | [`compose`](crate::algorithms::compose()) | $`O(V_1 V_2 E_1 E_2)`$ | $`O(V_1 V_2)`$ | — |
//! | [`determinize`](crate::algorithms::determinize()) | $`O(2^V)`$ worst | $`O(2^V)`$ | [`DivisibleSemiring`] |
//! | [`minimize`](crate::algorithms::minimize()) | $`O(2^V)`$ worst | $`O(2^V)`$ | [`DivisibleSemiring`] |
//! | [`minimize_hopcroft`](crate::algorithms::minimize_hopcroft()) | $`O(V \log V)`$ | $`O(V + E)`$ | Deterministic input |
//! | [`shortest_path`](crate::algorithms::shortest_path()) | $`O(k V (E + V \log V))`$ | $`O(k V)`$ | [`NaturallyOrderedSemiring`] |
//! | [`shortest_distance`](crate::algorithms::shortest_distance()) | $`O(V + E)`$ acyclic | $`O(V)`$ | — |
//! | [`remove_epsilons`](crate::algorithms::remove_epsilons()) | $`O(V^2 + V E)`$ | $`O(V^2)`$ | [`StarSemiring`] |
//!
//! [`DivisibleSemiring`]: crate::semiring::DivisibleSemiring
//! [`NaturallyOrderedSemiring`]: crate::semiring::NaturallyOrderedSemiring
//! [`StarSemiring`]: crate::semiring::StarSemiring
//!
//! # Core Operations
//!
//! ## Composition
//!
//! - [`compose()`] - Compose two FSTs: $`T_1 \circ T_2`$
//! - [`compose_default()`] - Composition with standard label matching
//! - [`compose_sorted()`] - Optimized composition using sorted arcs
//! - [`compose_with_lookahead()`] - Composition with lookahead filtering
//! - [`intersect()`] - Intersection of acceptor languages
//! - [`difference()`] - Language difference $`L(A_1) - L(A_2)`$
//!
//! ## Optimization
//!
//! - [`determinize()`] - Convert NFST to DFST via weighted subset construction
//! - [`minimize()`] - State minimization using Brzozowski's algorithm
//! - [`minimize_hopcroft()`] - $`O(n \log n)`$ minimization via partition refinement
//! - [`remove_epsilons()`] - Eliminate epsilon transitions
//! - [`connect()`] - Remove non-accessible and non-coaccessible states
//! - [`prune()`] - Weight-based arc and state pruning
//!
//! ## Path Algorithms
//!
//! - [`shortest_path()`] - Find k-shortest paths using Yen's algorithm
//! - [`shortest_distance()`] - Compute sum of path weights to each state
//! - [`shortest_distance_acyclic()`] - $`O(V+E)`$ algorithm for DAGs
//! - [`randgen()`] - Stochastic path generation
//!
//! ## Rational Operations
//!
//! - [`concat()`] - Concatenation: $`L_1 \cdot L_2`$
//! - [`union()`] - Union: $`L_1 \cup L_2`$
//! - [`closure()`] - Kleene star: $`L^*`$
//! - [`closure_plus()`] - Kleene plus: $`L^+`$
//!
//! ## Transformation
//!
//! - [`reverse()`] - Reverse arc directions and swap initial/final states
//! - [`project_input()`], [`project_output()`] - Project transducer to acceptor
//! - [`synchronize()`] - Synchronize input/output label timing
//! - [`push_weights()`], [`push_labels()`] - Push toward initial/final states
//! - [`reweight()`] - Reweight using potential function
//!
//! ## Utility
//!
//! - [`topsort()`] - Topological sort of states
//! - [`state_sort()`] - Sort states by BFS/DFS/topological order
//! - [`replace()`] - Replace labels with sub-FSTs
//! - [`condense()`] - Contract strongly connected components
//! - [`partition()`] - Partition states into equivalence classes
//! - [`weight_convert()`] - Convert between semiring types
//! - [`isomorphic()`] - Test FST structural equivalence
//!
//! # Usage Examples
//!
//! ## Basic Pipeline
//!
//! ```
//! use arcweight::prelude::*;
//!
//! // Create a simple FST
//! let mut fst = VectorFst::<TropicalWeight>::new();
//! let s0 = fst.add_state();
//! let s1 = fst.add_state();
//! fst.set_start(s0);
//! fst.set_final(s1, TropicalWeight::one());
//! fst.add_arc(s0, Arc::new(1, 2, TropicalWeight::new(0.5), s1));
//!
//! // Typical optimization pipeline
//! let connected: VectorFst<TropicalWeight> = connect(&fst)?;
//! let deterministic: VectorFst<TropicalWeight> = determinize(&connected)?;
//! let minimal: VectorFst<TropicalWeight> = minimize(&deterministic)?;
//! # Ok::<(), arcweight::Error>(())
//! ```
//!
//! ## Speech Recognition Pipeline
//!
//! ```
//! use arcweight::prelude::*;
//!
//! // Compose grammar with lexicon (typical ASR pipeline)
//! fn build_decoder(
//! grammar: &VectorFst<TropicalWeight>,
//! lexicon: &VectorFst<TropicalWeight>,
//! ) -> Result<VectorFst<TropicalWeight>> {
//! // G ∘ L composition
//! let gl: VectorFst<TropicalWeight> = compose_default(grammar, lexicon)?;
//!
//! // Optimize for runtime
//! let det: VectorFst<TropicalWeight> = determinize(&gl)?;
//! let min: VectorFst<TropicalWeight> = minimize(&det)?;
//!
//! Ok(min)
//! }
//! # let mut g = VectorFst::<TropicalWeight>::new();
//! # let s = g.add_state(); g.set_start(s); g.set_final(s, TropicalWeight::one());
//! # let mut l = VectorFst::<TropicalWeight>::new();
//! # let s = l.add_state(); l.set_start(s); l.set_final(s, TropicalWeight::one());
//! # build_decoder(&g, &l)?;
//! # Ok::<(), arcweight::Error>(())
//! ```
//!
//! # References
//!
//! The algorithms in this module are based on the following foundational works:
//!
//! \[1\] Mohri, M., Pereira, F., and Riley, M. 2002. Weighted finite-state transducers
//! in speech recognition. *Computer Speech & Language* 16, 1 (January 2002), 69-88.
//! DOI: <https://doi.org/10.1006/csla.2001.0184>
//!
//! \[2\] Mohri, M. 2009. Weighted automata algorithms. In *Handbook of Weighted Automata*,
//! M. Droste, W. Kuich, and H. Vogler, Eds. Springer, 213-254.
//! DOI: <https://doi.org/10.1007/978-3-642-01492-5_6>
//!
//! \[3\] Allauzen, C., Riley, M., Schalkwyk, J., Skut, W., and Mohri, M. 2007.
//! OpenFst: A general and efficient weighted finite-state transducer library.
//! In *Proceedings of the 12th International Conference on Implementation and
//! Application of Automata (CIAA 2007)*, 11-23.
//! DOI: <https://doi.org/10.1007/978-3-540-76336-9_3>
pub use ;
pub use arc_sum;
pub use arc_unique;
pub use ;
pub use ;
pub use ;
pub use concat;
pub use condense;
pub use connect;
pub use ;
pub use determinize;
pub use difference;
pub use ;
pub use intersect;
pub use isomorphic;
pub use minimize;
pub use minimize_hopcroft;
pub use partition;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use reverse;
pub use ;
pub use remove_epsilons;
pub use shortest_distance;
pub use ;
pub use ;
pub use ;
pub use ;
pub use synchronize;
pub use topsort;
pub use union;
pub use weight_convert;