PaperGeneralized finite automata theory with an application to a decision problem of second-order logic