Library

FST · Rational transduction

Thousands separators

Write 1234567 as 1_234_567. Where the separators go depends on the length mod 3, counted from the right — which a left-to-right reader does not know yet. So the transducer guesses the phase at the start and only the branch whose guess was right ends in an accepting state.

startp2p1p00/0, 1/1, 2/2…0/0, 1/1, 2/2…0/0, 1/1, 2/2…0/0, 1/1, 2/2…0/0, 1/1, 2/2…0/_0, 1/_1, 2…
The machine as drawn — 4 states, 60 transitions.

The author’s examples, run

7 → accept · 742 → accept · 42123 → accept · 1231234 → accept · 1_23412345 → accept · 12_3451234567 → accept · 1_234_567