When do stateful traversals fuse?
Gibbons and Oliveira proved that two monadic traversals fuse, \(\mapM f\kc\mapM g=\mapM(f\kc g)\), when the monad is commutative. The state monad is not commutative, so for stages that share a state the equation has to be checked pipeline by pipeline. We ask how hard this check is. Each stage is a total function given by a table over a finite state set and finite element types, and the two programs must return the same list and the same final state. An unsafe pipeline of \(r\) stages over \(m\) states has a counterexample of length at most \(2m^r-1\), a breadth-first search finds a shortest one, and for every fixed \(r\geq2\) safety at a given initial state is \(\NL\)-complete. If every element type is a singleton, safety is \(\coNP\)-complete, also for pipelines described by straight-line grammars. For binary elements there is a fixed library of stages over a fixed state set for which safety is \(\PSPACE\)-complete, and \(\EXPSPACE\)-complete for pipelines described by grammars; the lower bounds come from the word problem of an automaton group. Two stages over two states generate pipelines with \(2t+1\) stages whose shortest counterexamples have length exactly \(2^t\). One of…
- arXiv
- 2612.02336
- Authors
- Lihui Dong, Zhuo Li
- Categories
- cs.PL · cs.CC · cs.FL · cs.LO