We characterize the languages in the individual levels of the quantifier alternation hierarchy of first-order logic with two variables by identities. This implies decidability of the individual levels. More generally we show that two-sided semidirect products with J as the right-hand factor preserve decidability. , the second author provided an algebraic characterization of the levels of the hierarchy, showing that they correspond to the levels of weakly iterated two-sided semidirect products of the pseudovariety J of finite J -trivial monoids. This still left open the problem of decidability of the hierarchy: effectively determining from a description of a regular language the lowest level of the hierarchy to which the language belongs. This problem was apparently solved in Almeida-Weil [2], from which explicit identities for the iterated product varieties can be extracted. However, an error in that paper called the correctness of these results into question. Here we show that the given identities do indeed characterize these pseudovarieties. In particular, since it is possible to verify effectively whether a given finite monoid satisfies one of these identities, we obtain an effective procedure for exactly determining the alternation depth of a regular language definable in two-variable logic.
ACM Subject Classification