arXiv · 2612.02336
When do stateful traversals fuse?
Abstract
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 these stages commutes with itself but does not fuse with itself, a counterexample of minimal size to the conjecture of Gibbons and Oliveira that commuting Kleisli arrows fuse; over two states and two letters the conjecture fails for 156 of the 256 stages. Three idempotent stages over four states fuse in pairs but not together, and no three stages over three states with singleton elements behave this way. Bounded testing, commutation and pairwise checks therefore cannot validate the fusion of stateful traversals, whereas an exact check is tractable for a fixed number of stages.
Explore related subjects
Keep this discovery
Explore connections, maps & timelines
Lihui Dong, Zhuo Li. 2026-12-01. When do stateful traversals fuse?. https://searcharxiv.org/abs/2612.02336
Citations retain the original authors and DOI and include this site’s record URL. If this discovery service contributed to your research, you can also cite Search arXiv by Indiciae: BibTeX · RIS.