Logic

One block of quantifiers, read off an algebra

Which properties of words can be stated with existential quantifiers alone — 'there are positions, in this order, carrying these letters' — and Boolean combinations of such statements? Imre Simon answered in 1975: exactly those whose syntactic monoid is J-trivial. Of the 57,068 languages that automata of up to four states recognise, 848 pass the test, and every one of them is decided by which words of length three or less it contains as scattered subwords.

Worth reading first: A language that can name a set · A game that decides what can be said.

A language that can name a set found two exact descriptions of what logic can say about words. With quantifiers over sets of positions, a sentence defines exactly the languages a finite automaton recognises — Büchi’s theorem. With quantifiers over single positions only, first-order logic with the order of positions defines exactly the star-free languages, and a language is star-free exactly when its syntactic monoid is aperiodic — a theorem of Schützenberger, McNaughton and Papert. The boundary at three variables ended its account of the game with a debt from the same story: within first-order logic there is a hierarchy, counted by how many times a sentence alternates between “there exists” and “for all”, and deciding which level a given language sits at is known only at the lowest levels.

This essay computes the lowest. A sentence that uses only existential quantifiers, followed by a quantifier-free statement about letters and order, says that certain letters occur in a certain order: “there are positions x<y<zx < y < z carrying aa, bb, aa”. Boolean combinations of such sentences — and, or, not — make up the first level of the hierarchy. Imre Simon proved in 1975 that a regular language is at this level exactly when its syntactic monoid has a property called J-triviality, an algebraic condition that can be checked mechanically. The figures check it on every language a small automaton recognises, and check Simon’s theorem from the other side as well.

A subword can be checked with one quantifier block; a factor cannot. Subword aba: monoid 7, J-trivial, degree 3; factor aba: monoid 12, aperiodic, not J-trivial; witness abab / abba.
Fig. 1 Two languages with their smallest automata, accepting state shaded: words containing a, b, a as a scattered subword, and words containing aba as three adjacent letters. The first has a J-trivial monoid of 7 elements and is decided by subwords of length 3; the second’s monoid of 12 is not J-trivial, and abab and abba have the same subwords of length 2 but lie on opposite sides.

Subwords, and what one quantifier block can say

A scattered subword of a word is any sequence of its letters read in order, not necessarily adjacent: abaaba is a subword of abbaabba and of babbbabbabbbab, and not of baabbaab. An existential sentence “there are positions x1<x2<⋯<xkx_1 < x_2 < \cdots < x_k carrying the letters u1,…,uku_1, \ldots, u_k” holds in a word exactly when u1⋯uku_1 \cdots u_k is one of its scattered subwords, and every existential sentence is equivalent to a finite disjunction of such statements. So the languages at the first level are exactly those in which membership depends only on which words of length at most kk occur as scattered subwords, for some kk. Simon called them piecewise testable.

The hero figure shows the distinction that matters. Words containing aa, bb, aa in that order, with anything between, form a piecewise testable language: membership is decided by whether the single subword abaaba occurs. Words containing abaaba as a factor, three adjacent letters, are first-order definable — “there are xx, yy, zz with yy immediately after xx and zz immediately after yy”, and “immediately after” needs a universal quantifier to say that nothing lies between — but not piecewise testable. The figure finds the reason concretely: abababab contains the factor abaaba and abbaabba does not, yet both have the same scattered subwords of length up to two, aa, bb, aaaa, abab, baba and bbbb. No statement about short subwords can tell them apart, and the same is true at every length for suitably longer pairs.

The syntactic monoid

Simon’s test lives in the algebra of the language. Every regular language has a smallest automaton, and the ways that words can move the automaton’s states form a monoid: each word acts as a function from states to states, two words acting the same way are identified, and composing actions is the multiplication. This is the syntactic monoid, the algebraic fingerprint the earlier essay used to test for first-order definability. For the subword language it has seven elements, and for the factor language twelve.

A monoid is J-trivial when no two different elements generate the same two-sided ideal: if ss can be obtained from tt by multiplying on both sides and tt from ss, then s=ts = t. In words, an element can never be undone. For the subword language this is visible in the automaton: reading letters can only move it forward through the stages “nothing yet”, “seen aa”, “seen abab”, “seen abaaba”, never back. For the factor language a bb after abab sends the automaton back to the start, so the action “abab then bb” can be followed by actions that lead back to where “abab” alone led, and the monoid has elements that generate each other’s ideals. Simon’s theorem: a regular language is piecewise testable if and only if its syntactic monoid is J-trivial.

Both directions are worth having. One gives an algorithm — compute the monoid and test the ideals — that decides the first level of the hierarchy for any regular language, which is what the earlier essay’s open question was asking for in general. The other gives the reason the algebra is the right one: a piecewise testable language is a Boolean combination of subword conditions, each of which can only become true and never false as a word is read, and that monotonicity is J-triviality.

The seven actions of the subword automaton

The monoid of the subword language can be listed by hand, and doing so shows what J-triviality looks like. The automaton has four states, 0 to 3, meaning “nothing yet”, “seen aa”, “seen abab” and “seen abaaba”. A word acts on the states by moving each to where the automaton would be after reading the word from it. The empty word does nothing. The letter aa moves 0 to 1 and 2 to 3 and leaves 1 and 3 alone; bb moves 1 to 2 and leaves the rest. Then abab sends 0 and 1 to 2 and 2 to 3; baba sends 0 to 1 and 1 and 2 to 3; babbab sends 0 to 2 and 1 and 2 to 3; and abaaba sends every state to 3, the action that ends everything. Every longer word acts like one of these — abababab, for instance, also sends everything to 3 — so there are seven distinct actions in all, matching the figure.

Every action moves states forward or leaves them where they are, and that is the whole reason the monoid is J-trivial: if one action can be obtained from another by multiplying on both sides, it moves states at least as far, and if each can be obtained from the other they move them equally far, so they are the same action. The factor automaton breaks this, because reading bb in the state “seen abab” sends it back to the start: the actions “abab” and “abbabb” can each be extended into the other, so they generate the same ideal while acting differently on the states. Sixteen of five hundred and seventy-six met monoids and groups as multiplication tables of Latin squares; here the tables are the actions of words, and the property that matters is not associativity, which every monoid has, but whether any element can be reversed.

Every small language, sorted

The census in the next figure enumerates every deterministic automaton over {a,b}\{a, b\} with at most four states, every choice of transitions and accepting states, minimises each one and puts it in a canonical form, and so counts each language once.

Every small language, sorted by its monoid. 1 states: 2 languages, 2 J-trivial, 0 aperiodic only, 0 not aperiodic; 2 states: 24 languages, 6 J-trivial, 4 aperiodic only, 14 not aperiodic; 3 states: 1028 languages, 56 J-trivial, 106 aperiodic only, 866 not aperiodic; 4 states: 56014 languages, 784 J-trivial, 3140 aperiodic only, 52090 not aperiodic.
Fig. 2 Every language of words in a and b recognised by a deterministic automaton with at most four states, grouped by the size of its smallest automaton and sorted by its syntactic monoid: J-trivial, aperiodic but not J-trivial, or not aperiodic.

There are 57,068 such languages: two with one state, everything and nothing; 24 with two; 1,028 with three; and 56,014 whose smallest automaton has four states. Of them, 848 have J-trivial monoids and are piecewise testable; 3,250 more are aperiodic, first-order definable but needing an alternation of quantifiers; and the remaining 52,970 are not aperiodic at all, because they count something — the parity of the number of letters aa, say — that no first-order sentence can express. The shares shift with size: among the two-state languages a quarter are piecewise testable, among the four-state ones fewer than one in seventy. Most languages a small automaton can recognise count modulo something, and the logic of a single quantifier block captures a small and shrinking corner of them. That is the opposite of the situation nearly always, or nearly never found for random graphs, where every first-order property is almost certainly true or almost certainly false: among small automata, first-order definable languages are themselves the rare case.

Simon’s theorem, checked from the other side

The census classified languages by their monoids. The next figure checks the classification against the definition, by computing for each J-trivial language the length of subwords its membership actually depends on.

How long a subword the decision needs. Degrees of the J-trivial languages: 0: 2, 1: 14, 2: 232, 3: 600; aperiodic non-J-trivial languages (≤ 3 states) separated on words ≤ 10 at k ≤ 4: 110 of 110.
Fig. 3 For each J-trivial language in the census, the least k such that two words with the same scattered subwords of length at most k are always both in or both out, checked on all 2,047 words of up to ten letters.

For every one of the 848 J-trivial languages there is such a kk, and it is at most three: two languages need k=0k = 0 (everything and nothing), fourteen need k=1k = 1, 232 need k=2k = 2 and 600 need k=3k = 3. The check runs over every word of up to ten letters, 2,047 words, and for each language and each candidate kk looks for two words with the same subwords of length at most kk on opposite sides; for the J-trivial languages it finds none at the stated kk. In the other direction, among the first-order languages with at most three states that are not J-trivial — 110 of them — every one shows two words with the same subwords up to length four on opposite sides, within ten letters. So on everything small enough to check exhaustively, the algebra and the definition agree completely.

A finite check cannot prove the theorem, and it has a particular blind spot: on words of bounded length, long subwords determine a word almost completely, so any language looks piecewise testable if kk is allowed to approach the word length. The checks therefore cap kk well below the length of the words used — three and four against ten — where the separation is meaningful.

Finitely many classes for each length

Why piecewise testable languages are regular at all is itself a counting fact. For a fixed kk, two words are equivalent when they have the same scattered subwords of length at most kk, and there are only finitely many sets of short words, so only finitely many classes.

Finitely many subword sets of each length. k=1: 1,3,4,4,4,4,4,4,4,4,4,4,4,4,4; k=2: 1,3,7,13,16,16,16,16,16,16,16,16,16,16,16; k=3: 1,3,7,15,29,51,66,68,68,68,68,68,68,68,68.
Fig. 4 The number of different sets of scattered subwords of length at most k among all words in a and b up to a given length, for k = 1, 2 and 3, on a logarithmic scale. The counts stop at 4, 16 and 68.

With k=1k = 1 there are four classes, according to which of aa and bb occur, and every class is met by words of two letters. With k=2k = 2 there are sixteen, all met by words of four letters. With k=3k = 3 there are sixty-eight, all met by words of seven letters, and longer words never produce a new one. Each piecewise testable language is a union of classes, so it is recognised by an automaton that tracks the class, which is finite. The numbers 4, 16, 68 grow quickly with kk, and this is the price of the first level’s simplicity: membership is easy to describe and the description can be long.

The classes are also the positions of an Ehrenfeucht–Fraïssé game restricted to existential moves. A game that decides what can be said played the full game, where a player may move in either structure; when the first player must always move in the same word, as an existential sentence’s quantifiers do, the second player can answer kk rounds exactly when every subword of length kk of that word is also a subword of the other. Two words in the same class are those where neither player can win a one-sided game of kk rounds starting from either side.

The algebra of one quantifier block is small

The last figure compares the sizes of the syntactic monoids in the three classes, among the four-state languages.

The algebra of one quantifier block is small. J-trivial: 784 languages, mean monoid 6.255, max 10; aperiodic only: 3140 languages, mean monoid 10.729, max 20; not aperiodic: 52090 languages, mean monoid 44.544, max 176.
Fig. 5 For the languages whose smallest automaton has four states, the number of elements of the syntactic monoid, as shares within each class. J-trivial monoids average 6.3 elements, aperiodic ones 10.7, and the non-aperiodic ones 44.5, up to 176.

The J-trivial monoids are the smallest, averaging 6.3 elements with at most ten; the other aperiodic monoids average 10.7, at most twenty; and monoids containing a group — the counting languages — average 44.5 and reach 176. J-triviality forces this: since no element can return to an earlier ideal, words can only push the automaton’s states forward in a fixed partial order, and few distinct actions are possible. A group, at the other extreme, lets words permute states freely, and the actions multiply. The syntactic monoid’s size is a rough measure of a language’s complexity, and the first level of the quantifier hierarchy is, measured this way, the simplest class of languages that is not trivial.

What the census cannot show

The census is exhaustive for automata of up to four states and says nothing about larger ones, though Simon’s theorem covers all of them. Its checks against the definition are exhaustive only up to words of ten letters, and the separations they find for non-J-trivial languages are evidence that the theorem’s hard direction is working, not a proof of it. The figures also say nothing about the efficiency of the test: computing the syntactic monoid can take time exponential in the automaton’s size, since the monoid can be exponentially large, and later work found ways of testing J-triviality directly on the automaton, in polynomial time, without building the monoid.

The census is also restricted to two letters. Over larger alphabets every count grows, and the proportion of piecewise testable languages among all regular ones falls further; the structure of the classification is unchanged.

Where the hierarchy came from

The hierarchy was first defined without logic. Janusz Brzozowski introduced the dot-depth of a star-free language in 1971, counting how many times concatenation and Boolean operations must alternate to build it from single letters. Ehrenfeucht–Fraïssé games entered when Wolfgang Thomas showed in 1982 that dot-depth is the number of quantifier alternations in a first-order sentence defining the language, with the order and the first and last positions available; Howard Straubing and Denis Thérien gave the variant without them. So the levels of the hierarchy can be read three ways: by alternations of quantifiers, by alternations of concatenation and Boolean operations, and by algebraic conditions on the syntactic monoid, of which J-triviality is the first.

The quantifier reading is the one these essays have followed. Six sentences from two quantifiers counted the meanings that two quantifiers of different kinds produce in different orders, and every row or one column showed that swapping a “for all” and a “there exists” changes what a sentence says. The alternation hierarchy is the systematic version: each new alternation lets a sentence say something its predecessors could not, and Brzozowski and Robert Knast proved in 1978 that the dot-depth hierarchy never collapses. Simon’s theorem was the first level at which the infinite hierarchy acquired an algorithm.

Still open: the levels above

Simon’s theorem decides the first level of the hierarchy of quantifier alternations. The level above, sentences with an existential block followed by a universal block, was decided by Jean-Éric Pin and Pascal Weil and then by Thomas Place and Marc Zeitoun, who between 2014 and 2019 decided several further levels with new techniques based on separating languages rather than characterising them. Whether every level of the quantifier alternation hierarchy is decidable is open. The full first-order class is decidable by aperiodicity, and the levels below it are known to be strictly increasing — each alternation lets a sentence say more — but no general algorithm determines the least number of alternations a given star-free language needs.

The same question arises with the order replaced by the successor relation, the logic of a machine that carries one bit and of locally testable languages, where Brzozowski, Simon, McNaughton and Thérien found algebraic characterisations of the lowest levels, and where the higher levels are equally open.

Monotone reading

The properties that a single block of existential quantifiers can state are exactly those that are decided once certain patterns have been seen, and never undone by what follows. That monotonicity has an algebraic shadow: a monoid in which no element can be undone, J-trivial. Simon’s theorem says the shadow is exact, and the census confirms it on every language a four-state automaton can recognise: 848 J-trivial languages, each decided by subwords of length at most three, and every other first-order language small enough to check showing two words that agree on their short subwords and disagree on membership. The factor abaaba and the subword abaaba differ by one word of quantifier — “immediately” — and that word is the difference between the first level of the hierarchy and the second.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A dashed tag is an object no other essay names yet.

AssociativityClassificationDecidabilityEquivalence relationExhaustive searchExpressive powerFinite automatonQuantifier