Extensions and Limits of the Specker-Blatter Theorem

The original Specker-Blatter Theorem (1983) was formulated for classes of structures $\mathcal{C}$ of one or several binary relations definable in Monadic Second Order Logic MSOL. It states that the number of such structures on the set $[n]$ is modularly C-finite (MC-finite). In previous work we extended this to structures definable in CMSOL, MSOL extended with modular counting quantifiers. The first author also showed that the Specker-Blatter Theorem does not hold for one quaternary relation (2003). If the vocabulary allows a constant symbol $c$, there are $n$ possible interpretations on $[n]$ for $c$. We say that a constant $c$ is {\em hard-wired} if $c$ is always interpreted by the same element $j \in [n]$. In this paper we show: 1. The Specker-Blatter Theorem also holds for CMSOL when hard-wired constants are allowed. The proof method of Specker and Blatter does not work in this case. 2. The Specker-Blatter Theorem does not hold already for $\mathcal{C}$ with one ternary relation definable in First Order Logic FOL. This was left open since 1983. Using hard-wired constants allows us to show MC-finiteness of counting functions of various restricted partition functions which were not known to be MC-finite till now. Among them we have the restricted Bell numbers $B_{r,A}$, restricted Stirling numbers of the second kind $S_{r,A}$ or restricted Lah-numbers $L_{r,A}$. Here $r$ is an non-negative integer and $A$ is an ultimately periodic set of non-negative integers.


Introduction
A sequence of natural numbers s(n) is C-finite if it satisfies a linear recurrence relation with constant coefficients.s(n) is MC-finite if it satisfies a linear recurrence relation with constant coefficients modulo m for each m separately.A C-finite sequence s(n) must have limited growth: s(n) ≤ 2 cn for some constant c.No such bound exists for MC-finite sequences: for every monotone increasing sequence s(n) the sequence s ′ (n) = n!s(n) is MC-finite.
A typical example of a C-finite sequence is the sequence f (n) of Fibonacci numbers.A typical example of an MC-finite sequence which is not C-finite is the sequence B(n) of Bell numbers.The Bell number B(n) counts the number of partitions of the set [n] of the numbers {1, 2, . . ., n}.Let Eq(n) be number of equivalence relations over [n].Clearly, B(n) = Eq(n).Let Eq 2 (n) be the number of equivalence relations on [n] with exactly two equivalence classes of the same size.Eq 2 (n) is not MC-finite since the value of Eq 2 (n) is odd iff n is an even power of 2, see [3].

Background in logic
We generally follow the notation of [8], and assume basic knowledge of model theory.
Standard texts for Finite Model Theory are [8,21].In the following, we always refer to a set R = {R 1 , . . ., R ℓ R } of distinct binary relation symbols, a set ā = {a 1 , . . ., a ℓā } of distinct constant symbols, and so on.By a ∈ ā we mean that there exists 1 ≤ i ≤ ℓ ā for which a = a i .We also use the shorthand [n] = {1, . . ., n}.
Let τ = R ∪ ā be a vocabulary, i.e., a set of non-logical constants.We denote by FOL(τ ) the set of first order formulas with its non-logical constants in τ .If τ is clear from the context, we omit it.We denote by MSOL(τ ) the set of Monadic Second Order Logic, obtained from FOL by allowing unary relation variables and quantification over them.The logic CMSOL is obtained from MSOL by allowing also quantification of the form C m,a xϕ(x), which are interpreted by A |= C m,a xϕ(x) iff |{a ∈ A : ϕ(a)}| ≡ a mod m.
In the following we will be interested in the set of models of a logic sentence ϕ over a vocabulary τ whose universe is [n] for any natural number n.We denote this set by

3
The original Specker-Blatter Theorem Let ϕ E be the formula in First Order Logic (FOL) which says that E(x, y) is an equivalence relation.Eq(n) can be written as P O(n), QO(n) and T r(n) can be written in a similar way.
Let Sp ϕ (n) be the number of ways we can interpret the relation symbols in R on [n] such that the resulting structures where A i is the interpretation of R i satisfies ϕ.Formally ▶ Theorem 1 (Specker-Blatter).Let R be a finite set of binary relations and ϕ be a formula of MSOL( R) using relation symbols in R. Then the sequence Sp ϕ (n) is MC-finite.
▶ Corollary 2. The sequences counting the number of partial orders P O(n), quasi-orders QO(n), and transitive relations T r(n) on [n], are MC-finite.
The idea behind the proof of the Specker-Blatter theorem consists of two parts, both of which use the assertion that τ = R contains only binary relation symbols.Unary symbols can also be incorporated, since these can be simulated with binary symbols in a way that preserves the number of satisfying models.
The first part is combinatorial and applies to any family C of structures over the vocabulary τ satisfying a property that we outline below.For such a family, we let Sp C (n) be the number of members of C whose universe is [n].In particular, Sp ϕ (n) is just a shorthand for Sp C ϕ (n).
A pointed R-structure is an R-structure A = ([n], A 1 , . . ., A µ , a) with an additional distinguished point a ∈ [n].Given a pointed R-structure A 1 with universe [n 1 ] and an R-structure A 2 with universe [n 2 ] we define A = Subst(A 1 , a, A 2 ) as follows: (i) The universe A of A is the disjoint union of A 1 and A 2 with the point a removed.It can be assumed to be the set [n 1 + n 2 − 1].(ii) The binary relations are defined such that A 2 is a module in A, i.e., for u ∈ A 1 \ {a} and v ∈ A 2 and R ∈ R, the relation R(u, v) holds in A = Subst(A 1 , a, A 2 ) iff R(u, a) holds in A 1 .For u, v ∈ A 1 \ {a} (respectively u, v ∈ A 2 ), R(u, v) holds in A iff it holds in A 1 (respectively A 2 ).
By using an arbitrary enumeration of all possible pointed R-structures and all possible (non-pointed) R-structures, we construct an N × N matrix M C over {0, 1}, by setting for every i and j the value M C (i, j) to be the indicator as to whether the substitution of the j'th structure in the i'th pointed structure results in a member of C. The main combinatorial part is the following.
▶ Theorem 3 (Specker-Blatter, combinatorial version).Let R be a finite set of binary relations and C be a class of finite R-structures whose substitution rank is finite under Z p q for any prime number p and q ∈ N. Then the sequence Sp C (n) is MC-finite.
The above applies to an uncountable number of families C. Theorem 1 follows from it by the following lemma, which forms the second part of the original proof: ▶ Lemma 4. Let R be a finite set of binary relations and C be a finite class of R-structures defined by an R-sentences ϕ in MSOL.Then the substitution rank of C is finite.
In [15] it is shown that the lemma still holds if MSOL is replaced by CMSOL.On the other hand, when considering relations of arity higher than 2, the substitution operation is no longer well-defined as it is written here.As it later turned out, this is not a merely technical limitation, but an essential one.

Extensions and Limits
Also, it is not clear how to handle hard-wired constant in the definition of the substitution operation.In this paper, instead of incorporating the hard-wired constants directly into the original mechanism, we show a reduction from the question of the original count to a sum of counts over other sentences that do not involve the constants.This approach turns out to be useful also in the other direction, of proving a new limit on the Specker-Blatter theorem.

Previous limitations and extensions
Limitations and extensions of the Specker-Blatter Theorem have been previously discussed in [15,14].
It is well known that Eulerian graphs and regular graphs of even degree are not definable in MSOL, but they are definable in CMSOL.In [15], the Specker-Blatter Theorem was shown to hold also for CMSOL.It follows in particular that Eul(n), which counts the number of Eulerian graphs over [n] (i.e.connected graphs all of whose degrees are even), is also MC-finite.
In [13] the first author showed that the Specker-Blatter Theorem does not hold for quaternary relations: Fischer, 2002).There is an FOL-sentence with only one quaternary relation symbol ϕ, such that Sp ϕ (n) is not an MC-sequence.
The question of whether Specker-Blatter Theorem holds in the presence of ternary relation symbols remained open.

Main new results
Due to space constraints, some proofs are deferred to the full version of this paper1 [17].
The Bell numbers B(n) and the Stirling numbers of the second kind S k (n) for fixed k can be shown to be MC-finite using the Specker-Blatter Theorem. A. Broder in 1984, [4], introduced the restricted Bell numbers B r (n) and the restricted Stirling numbers of the second kind S k,r (n).Let r ∈ N + .S k,r (n) is defined as the number of set partitions of [r + n] into k + r blocks with the additional condition that the first r elements are in distinct blocks.B r (n) is defined as The class of equivalence relations on [r + n] where the first r elements are in different equivalence classes is definable in FOL with one binary relation and r hard-wired constants.The Specker-Blatter Theorem does not directly apply to this case.In [11] it is shown how to circumvent this obstacle in the case of one equivalence relation.It followed that both S k,r (n) and B r (n) are MC-finite.
In this paper we prove a more general theorem: ▶ Theorem 6 (Elimination of hard-wired constants).
Equality here is not modular.(ii) Furthermore, if C is FOL-definable (MSOL-definable, CMSOL-definable), so are the C i .▶ Corollary 7. Let τ consist of a finite set of (hard-wired) constant symbols ā, unary relations symbols Ū , and binary relation symbols R, and let C be class of finite τ -structures definable in CMSOL.Then the sequence Sp C (n) is MC-finite.
The proof of Theorem 6 is given in Section 7. In Section 8 we state Theorem 19, which is an extension of Theorem 6 that works for higher arities and other logics, and sketch its proof.The full proof details of Theorem 19 are deferred to [17].The extension to higher arities is needed for proving Theorem 8 below.
We have seen in Theorem 5 that the Specker-Blatter Theorem does not hold for a single quaternary relation.The question of whether Specker-Blatter Theorem holds in the presence of a single ternary relation symbol remained open.Our second main result here answers this.

▶ Theorem 8 (Ternary Counter-Example).
There is a FOL-sentence ϕ with only one ternary relation symbol (and some lower arity relations), such that Sp ϕ (n) is not an MC-sequence.
The proof of Theorem 8 first produces a sentence ψ which also uses one symbol for a hard-wired constant.This will be shown in Section 9. To construct ϕ without the hard-wired constants, we deploy the aforementioned Theorem 19, which provides a sentence with one ternary relation and several lower arity relations.We can then also eliminate all relations except the ternary one, to arrive at Theorem 31 stated at Section 9, whose proof is deferred to the full version [17].A sketch thereof is still provided.
We conclude this paper with Section 10, containing a summary and open problems.

More details about C-finite and MC-finite sequences of integers
A sequence of integers s(n) is C-finite 2 if there are constants p, q ∈ N and c i ∈ Z, 0 ≤ i ≤ p−1 such that for all n ≥ q the linear recurrence relation below holds for s(n).
A sequence of integers s(n) is modular C-finite, abbreviated as MC-finite, if for every m ∈ N there are constants p m , q m ∈ N + such that for every n ≥ q m there is a linear recurrence relation We denote by s m (n) the sequence s(n) mod m.Note that the coefficients c i,m and both p m and q m generally do depend on m.
n is not MC-finite: s 3 (n) is odd if and only if n is a power of 2 (Lucas, 1878).A proof may be found in [18,Exercise 5.61] or in [26].[20,Chapter 13].(viii) Let p be a prime and f (n) monotone increasing.The sequence s where z(n) is defined to equal 1 if n is a power of p and to equal 0 for any other n, is monotone increasing but not ultimately periodic modulo p, hence not MC-finite.

▶ Proposition 11. (i)
There are uncountably many monotone increasing sequences which are MC-finite, and uncountably many which are not MC-finite.(ii) Almost all integer sequences (under a suitable measure) are not MC-finite.
Proof.(i) follows from Example 10 (v) and (viii).(ii) follows from almost all integer sequences being being absolutely normal (see [9]); the full proof is deferred to [17].◀

7
Proving the reduction

Introduction
In the following we consider extending the language with "hard-wired" constants.Specifically, assume that we have a class C that is defined by a sentence ϕ involving a set of constant symbols ā, unary symbols Ū and binary symbols R. The function f C (n) is defined as the number of models over the universe [n + ℓ ā] which satisfy ϕ, for which a i is interpreted as Note the distinction from the non-hard-wired setting, where we would have had to also count the possible interpretations of the constants.Our main result is an expression for the function f C (n) (when constants are allowed) that is based on counting functions for classes that do not utilize constants.We first show this reduction for languages using only unary and binary relations.The reduction preserves many of the common logics, in particular an FOL expression would be reduced to functions involving FOL expressions, and so on.This extends the Specker-Blatter theorem to languages involving hard-wired constants, allowing modular ultimate periodicity proofs of new functions.
In this section we prove Theorem 6.For convenience we state it again as Theorem 12. ▶ The following is the immediate corollary it produces for the Specker-Blatter Theorem, which is a restatement of Corollary 2.
▶ Corollary 13 (Extended Specker-Blatter Theorem).For a class C definable in CMSOL with (hard-wired) constants, unary and binary relation symbols only, the function f C is MC-finite.
Theorem 12 is proved by induction over the number of constants.The basis, ℓ ā = 0, is trivial (with Ū ′ = Ū , r = 1 and C 1 = C).The induction step is provided by the following.
▶ Lemma 14 (Removing a single constant).For any class C defined by an FOL (resp.MSOL, CMSOL) sentence involving a set of constant symbols ā with ℓ ā > 0, unary symbols Ū and binary symbols R, there exist classes C 1 , . . ., C r (where r depends on the original language), definable by FOL (resp.MSOL, CMSOL) sentences over the language (ā ′ , Ū ′ , R′ ), where ā′ = ā\{a ℓā }, The main idea in the proof of this lemma is to encode the "interaction" of the constant a ℓā with the rest of the universe using the additional unary relations.For every i ∈ [ℓ R], we will use the new relation I i to hold every x ̸ = a ℓā for which (x, a) was in R i , and the relation O i to hold every x ̸ = a ℓā for which (a, x) was in R i .
We cannot directly keep track whether (a, a) was in R i , or whether a was in U i for i ∈ [ℓ Ū ], so we count the number of models for each of these options separately.This sets r = 2 ℓ Ū +ℓ R .Instead of a running index, we index each such option with a set U ⊆ [ℓ Ū ] denoting which of the relations in Ū include the constant to be removed a = a ℓā , and a set R ⊆ [ℓ R] denoting which of the relations in R include (a, a).Using these we can define the case where a model N over the language (ā ′ , Ū ′ , R) with universe [n + ℓ ā − 1] corresponds (along with U and R) to an "original model" M with universe [n + ℓ ā] over the original language.
▶ Definition 15.Given a model M over the language (ā, Ū , R) with universe where (as always) in both models every constant a i is interpreted to be n + i, we say that (N, U, R) correspond to M if the following hold.
For every It is important to note, for the purpose of counting, the following observation.Suppose we are given an expression ϕ(x) where x = {x 1 , . . ., x ℓx } is a set of variable symbols over the language (ā, Ū , R), as well as a set U ⊆ [ℓ Ū ] and a set R ⊆ [ℓ R].We will construct, by induction over the structure of ϕ, several expressions, where one of which is an expression ϕ ′ U,R (x) over the language (ā ′ , Ū ′ , R).It will be constructed so that for any M over the language (ā, Ū , R) with universe [n + ℓ ā] and N over the language (ā ′ , Ū ′ , R) with universe [n + ℓ ā − 1], where (N, U, R) correspond to M, and any fixing of x 1 , . . ., . Lemma 14 then immediately follows from the case ℓ x = 0 (i.e.where ϕ is a sentence).To be precise, for a class C defined by a sentence ϕ over the language (ā, Ū , R), we obtain To sustain the induction, the above will not be enough.This is because we need to account under the model N also for the case where some variables are "assigned the value a = a ℓā ", a value which does not exist in its universe (it exists only in that of M).We henceforth consider also a set X ⊆ [ℓ x], and denote the set of variable symbols x X = {x i : i ∈ X}.In our induction we will construct the expressions ϕ . With models M and N as above and a fixing of the variables in x \ x X , denote by xX→a the completion of this fixing to all of x that is obtained by fixing x i to be equal to a for all i ∈ X.We will then have . The rest of this section is concerned with the recursive definition of ϕ ′ X,U,R (x \ x X ).There is a subsection for the base cases, a subsection for Boolean connectives, and a subsection for each class of quantifiers (first order quantifiers, counting quantifiers, and monadic second order quantifiers).In every construction we argue (at times trivially) that we keep the correspondence invariant, namely that M |= ϕ(x X→a ) if and only if N |= ϕ ′ X,U,R (x \ x X ) whenever M and (N, U, R) satisfy the correspondence condition of Definition 15.

The base constructions
We use the Boolean "true" and "false" statements in the following, so for formality's sake they are also considered as atomic statements here.Clearly, if ϕ(x) is simply the "true" statement ⊤ (respectively the "false" statement ⊥), then setting ϕ ′ X,U,R (x \ x X ) to ⊤ (respectively ⊥) gives us the equivalent statement satisfying the correspondence invariant.
For i ∈ [ℓ Ū ] and j ∈ [ℓ x], let us now consider the expression ϕ(x) = U i (x j ).To produce ϕ ′ X,U,R (x \ x X ), we partition to cases according to whether j ∈ X.In the case where j / ∈ X, we simply set ϕ ′ X,U,R (x \ x X ) = U i (x j ) as well, which clearly satisfies the invariant for (N, U, R) correlated with M (recall that the "if and only if" condition in this case should hold when the value of ), noting that in our setting the value of a j is guaranteed to be equal to n Now consider the expression ϕ(x) = U i (x j ) for the case where x j ∈ X. Recall that in this case ϕ ′ X,U,R (x \ x X ) should not depend on x j .Moreover, to preserve the invariant for corresponding sets and models, ϕ ′ X,U,R (x \ x X ) should hold if and only if U j (a) holds (recall that we use the shorthand a = a ℓā throughout).We hence define ϕ ′ X,U,R (x \ x X ) to be ⊤ ("true") if i ∈ U, and define it to be ⊥ ("false") if i / ∈ U.The remaining case for a unary relation is the expression ϕ(x) = U i (a).Again, we define ϕ ′ X,U,R (x \ x X ) to be ⊤ if i ∈ U, and define it to be ⊥ if i / ∈ U.
We now move on to handle the atomic expressions involving a binary relation R i where i ∈ [ℓ R].The first case here is the one analogous to the first case we discussed involving a unary relation.Namely, it is the case where ϕ(x) = R i (x j , x k ) where both j / ∈ X and k / ∈ X.In this case we set ϕ ′ X,U,R (x \ x X ) = R i (x j , x k ), and argue the same argument as above about satisfying the correspondence invariant.
The next four cases we discuss resemble the last two cases we discussed about a unary relation.Namely, these are the cases where ϕ or ϕ(x) = R i (a, x j ) with j ∈ X, and ϕ(x) = R i (a, a).In all these cases the resulting expression should reflect on whether M |= R i (a, a), which for the corresponding (N, U, R) is handled by the set R. We hence set ϕ Next we handle the cases where ϕ(x) = R i (x j , x k ) with j / ∈ X and k ∈ X, and ϕ(x) = R i (x j , a) with j / ∈ X.For both this cases, for the correspondence invariant to follow we need to look at whether M |= R i (x j , a), where the value of x j is in [n + ℓ ā − 1].For the corresponding (N, U, R) this occurs if and only if N |= I i (x j ), where we recall that Moving on to the remaining cases for a binary relation, we consider ϕ(x) = R i (x k , x j ) with j / ∈ X and k ∈ X, and ϕ(x) = R i (a, x j ) with j / ∈ X.These are analogous to the cases handled in the last paragraph, only here we use ).The final atomic formula to consider is the "builtin relation" of equality.We skip all cases involving only constants (e.g. a i = a j ), since these are equivalent to ⊤ or ⊥.We also skip cases that are equivalent by the symmetry of the equality relation to those that we discuss.
First, if ϕ(x) is , then since we are dealing with values that are guaranteed to be in [n + ℓ ā − 1] (the universe of N), we set ϕ ′ X,U,R (x \ x X ) respectively to x i = x j or x i = a k as well (so it is "unaltered" from ϕ(x)).
On the other hand, if ϕ(x) is x i = x j or x i = a for i, j ∈ X, then for the correspondence principle to hold, we need In other words, we have to set ϕ ′ X,U,R (x \ x X ) = ⊤ here.The final cases are those where ϕ(x) is x i = x j or x i = a for i / ∈ X and j ∈ X.For the correspondence principle to hold, we need N |= ϕ ′ X,U,R (x \ x X ) to hold if and only if M |= (x i = a).However, we make here the subtle yet important observation that this should occur for any value that x i can take from the universe of N, which does not include a. Therefor, we can (and should) set ϕ ′ X,U,R (x \ x X ) = ⊥ in these cases.

Boolean connectives
Handling Boolean connectives is the most straightforward part of this construction.For example, suppose that we have ϕ(x) = ¬ψ(x) for some expression ψ(x), for which we have already established (by the induction hypothesis) that The same idea and analysis follow for all other Boolean connectives.For example, for the expression ϕ C S L 2 0 2 4 26:10 Extensions and Limits

First order quantifiers
To deal with quantifiers over variables, we make some assumptions on the structure of our expressions that can easily be justified by the appropriate variable substitutions.Namely, we require that every quantified variable is quantified only once in the expression, and is not used at all outside the scope of the quantification.In particular, this means that the set X that appears in the subscript of our expression cannot contain a reference to the quantified variable.
For notational convenience, when ϕ(x) is our formula, we denote by x = x ℓx+1 the quantified variable.So the two cases that we consider in this subsection are the existential quantification ϕ(x) = ∃ x ψ(x ∪ {x}) and the universal quantification ϕ(x) = ∀ x ψ(x ∪ {x}), and for both of them we would like to construct a corresponding ϕ ′ X,U,R (x \ x X ) where X ⊆ [ℓ x].In the existential case, we want N |= ϕ ′ X,U,R (x\x X ) to occur whenever there is at least one value of x for which M |= ψ(x ∪ {x}).For the values of x within [n + ℓ ā − 1], by the induction hypothesis, this is covered by the expression ∃ x ψ ′ X,U,R (x ∪ {x} \ x X ).However, there is one possible value of x not covered in this way, and that is the value n + ℓ ā, which we identify with the constant a.But by the induction hypothesis, ).The universal case follows an analogous argument, only here M |= ψ(x ∪ {x}) needs to hold for all values of x, those in [n + ℓ ā − 1] as well as the value of a.

Modular counting quantifiers
We briefly recall the definition of a modular counting quantifier.Given ϕ(x) = C r,m x ψ(x∪{x}), this expression is said to hold in M for a specific assignment to the variable of x, if the size of the set {x : M |= ψ(x ∪ {x})} is congruent to r modulo m.As with the previous subsection, we assume that the quantified variable is not used outside the quantification scope, and that no variable is quantified more than once.We again denote for notational convenience the quantified variable by x = x ℓx+1 , and note that X ⊆ [ℓ x] cannot include a reference to x.
When working with (N, U, R) that corresponds to M, to obtain the original modular count, we have to count the set (satisfying the induction hypothesis) {x : X∪{ℓx+1},U,R (x \x X )) as the combined expression for ϕ ′ X,U,R (x \ x X ).

Monadic second order quantifiers
Here we deal with quantifiers over unary relations.The cases we cover are the existential quantification ϕ(x) = ∃ U ψ(x) and the universal quantification ϕ(x) = ∀ U ψ(x), where U is a new unary relation that does not appear in the language (ā, Ū , R) of ϕ(x), while being part of the language of ψ(x).As before, we assume that the quantified relation symbol U appears only in the scope of this quantification, and is not quantified anywhere else, and again denote for convenience U = U ℓ Ū +1 .In particular, when analyzing expressions of the type ψ ′ X,U ′ ,R (x \ x X ), we may allow U ′ to contain [ℓ Ū + 1] (the same is not allowed for the expression ϕ ′ X,U,R (x \ x X ), whose language does not contain U ). Consider now the family of possible models M ′ that extend M with an interpretation of the relation U .Now consider (N ′ , U ′ , R ′ ) which correspond to M ′ , in relation to (N, U, R) which correspond to M. Referring to Definition 15, every relation already appearing in Ū will have the same interpretation in N and N ′ .Also, R ′ = R, since the binary relations are the same in the languages of both models.Additionally, from the definition, the interpretation of U = U ℓ Ū +1 in N ′ is the restriction of its interpretation in M ′ to [n + ℓ ā − 1].As for the final ingredient U ′ , for every i ∈ [ℓ Ū ], the condition on whether it is in U or in U ′ is the same.However, U ′ may also include ℓ Ū + 1 according to whether M ′ |= U (a).So considering all possible models M ′ , we have two possibilities.Either U ′ = U, or U ′ = U ∪ {ℓ Ū + 1}.
We can now construct our expression that corresponds to all models extending M. For the existential case we have ϕ , and for the universal one we have ϕ

8
Handling relations of other arities

Nullary relations and a many-one version of the reduction
Before we consider relations of higher arities, let us show how incorporating nullary ("arity zero") relations can replace the reduction of Theorem 6 into a many-one reduction.That is, instead of a reduction into of the original Sp ϕ (n) into a finite sum r i=1 Sp ϕi (n), we will have a reduction into a single Sp ϕ ′ (n) where ϕ ′ may also involve nullary relations.Later, when we consider higher arity relations, nullary relations add much needed consistency to the notation.
Formally, for a nullary relation Z, the corresponding atomic formula is Z(), and a model M over a language that includes Z interprets this formula as either true or false, that is, either M |= Z() or M |= ¬Z().
Note that nullary relations can be simulated using higher arity relations.To replace a nullary relation Z in the language with a unary relation U (while preserving the model count), the logical expression under discussion should be conjuncted with "∀ x ∀ y (U (x) ↔ U (y))", and then every instance of "Z()" in the formula should be replaced with "∃ x U (x)".
The corresponding reduction theorem is the following.
Also here, the theorem follows from a single constant removal lemma, which is used for an inductive argument over ℓ ā.
▶ Lemma 18 (Removing a single constant in a many-one manner).For any class C defined by an FOL (resp.MSOL, CMSOL) sentence involving a set of constant symbols ā with ℓ ā > 0, nullary symbols Z, unary symbols Ū and binary symbols R, there exists a class C ′ , definable by an FOL (resp.MSOL, CMSOL) sentence over the language (ā ′ , Z′ , Ū ′ , R′ ), where ā′ = ā \ {a ℓā }, Z′ = Z ∪ S ∪ D where ℓ S = ℓ U and ℓ The proofs are deferred to the full version of this paper [17].We provide here a "sketch by example" on how this is done.
Adding nullary relations essentially allows us to get rid of the role of U and R, so we will only inductively construct the expressions ϕ ′ X and let nullary relations "hold the information" as to whether some relations hold with a substituted to all their variables.

C S L 2 0 2 4
If for instance we consider a binary relation R(x, y) in the original vocabulary of ϕ, then the new vocabulary will include R(x, y) (holding the information about the contents of R that does not involve the constant a), the unary relations I(x) (holding the information about R(x, a) for all x ̸ = a) and O(y) (holding the information about R(y, a)), and the nullary relation Z() that holds the information whether R(a, a) holds.
In the inductive construction, ϕ ′ X (x \ x X ) will tell us whether ϕ holds where all variables enumerated by X are assigned the constant a, while all other variables are guaranteed to be different from a.
As an example, for the expression ϕ(x) = ∃ y R(x, y), we will have ϕ ′ ∅ (x) = (∃ y R(x, y)) ∨ I(x), which goes over the two options for the existence of y for which R(x, y) holds: the first option being y ̸ = a, and the second one being y = a.Similarly we will have ϕ ′ {1} () = (∃yO(y)) ∨ Z(), which goes over the two options for the existence of y for which R(a, y) holds.

Handling higher arity relations and extended logics
The mechanism behind the proof of Theorem 17 can be extended higher arity relations, as well as more expressive logics, such as Second Order Logic (SOL) and Guarded Second Order Logic (GSOL) Also here, this follows by induction using a corresponding extension of Lemma 18, which allows us to eliminate hard-wired constants one at a time.As a way of demonstrating the proof of this theorem (deferred to [17]), we explain how the single elimination lemma works when considering a ternary relation R(x, y, z).
As before, for eliminating a hard-wired constant a we need to add lower arity relations to R. Namely, since after the reduction R(x, y, z) itself would refer only to values different from a, we add a lower arity relation for every option of substituting the value a in any of these variables.This would add 31 = 3 binary relations which we will denote here by R 1 (y, z), R 2 (x, z) and R 3 (x, y), in addition to 3  2 = 3 unary relations which we will denote by R 12 (z), R 13 (y) and R 23 (x), and a single nullary relation which we will denote by R 123 ().Thus, given for example the expression ϕ(x, y) = ∃ z R(x, y, z), we would have for example In this section we negatively settle the question of whether the Specker-Blatter theorem holds for classes whose language contains only ternary and lower-arity relations.

Using one hard-wired constant
We first construct a class whose language includes a single ternary relation and a single hard-wired constant.Our counterexample builds on ideas used in [13].

▶ Theorem 20 (Ternary relation counterexample with a constant).
There exists an FOL sentence ϕ M over the language (a, R), where a is a single (hard-wired) constant and R is a single relation of arity 3, so that the corresponding class C satisfies f C (n − 1) = 0 for any n that is not a power of 2, and f C (n − 1) ≡ 1 (mod 2) for n = 2 m for every m ∈ N. In particular, f C is not ultimately periodic modulo 2.
The statement uses f C (n − 1) instead of f C (n), but recalling the definition of f C , this refers to the universe [n 1] ∪ {a} whose size is n.We explain later how to modify this class to produce a counterexample modulo other prime numbers p instead of 2.
By Theorem 19, we have the following immediate corollary that does away with the constant, at the price of adding some additional smaller arity relations.This corollary is effectively a restatement of Theorem 8.

▶ Corollary 21 (Ternary counterexample without constants).
There exists an FOL sentence ϕ ′ M over the language ( R), where R includes one relation of arity 3 and other relations of lower arities, so that the corresponding class C satisfies f C (n) = 0 for every n for which n + 1 is not a power of 2, and f C (n) ≡ 1 (mod 2) for n = 2 m − 1 for every m ∈ N. In particular, f C is not ultimately periodic modulo 2.
At the end of this section we sketch how to further reduce the language so that it includes only one ternary relation and no lower arity relations.The full details are deferred to [17].

The first construction
The starting point of the construction is a structure that is defined over a non-constant length sequence (and hence not yet expressible in FOL) of unordered graphs.This definition follows the streamlining by Specker [25] of the original construction from [13].
▶ Definition 22 (Iterated matching sequence).Given a set V of vertices, An iterated matching sequence is a sequence of graphs over V , identified by their edge sets Ē = E 1 , . . ., E ℓ Ē , satisfying the following for every The connected components of E i are (vertex-disjoint) complete bipartite graphs.The two vertex classes of every complete bipartite graph in E i as above are two connected components of The following properties of iterated matching sequences are easily provable by induction.
C S L 2 0 2 4 26:14 Extensions and Limits ▶ Observation 23.For an iterated matching Ē, every E i corresponds to a perfect matching over the set of connected components of i−1 j=1 E j .Additionally, every connected component of i j=1 E j is a clique with exactly 2 i vertices.The above implies that there can be a full iterated matching sequence over [n] if and only if n is a power of 2, in which case ℓ Ē = log 2 (n).Denoting the number of possible full iterated matching sequences over [n] by f M (n), note the following lemma.
▶ Lemma 24 (see [25]).For every n which is not a power of 2 we have f M (n) = 0, while f M (n) ≡ 1 (mod 2) for n = 2 m for every m ∈ N.
The rest of this section concerns the construction of a sentence ϕ M over a language with one constant and one ternary relation, so that the corresponding class For the construction here, we only have a ternary relation R, and we encode the placement of (u, v) within Ē by the set {w : (u, v, w) ∈ R}.We will have to utilize the hard-wired constant a to make sure that there is exactly one way to encode every full iterated matching sequence.

Setting up and referring to an order over the vertex pairs
We simulate the structure of a full iterated matching sequence over [n] (where n ∈ [n] is identified with the constant a) by assigning "ranks" to pairs of members of [n], which we consider as vertices, where each pair (x, y) is assigned the set r x,y = {z : (x, y, z) ∈ R}.First we need to make sure that "graphness" is satisfied, which means that r x,y is symmetric and is empty for loops.
Next we make sure that every two vertex pairs have ranks that are comparable by containment.This means that for every (x 1 , y 1 ) and (x 2 , y 2 ) either r x1,y1 ⊆ r x2,y2 or r x2,y2 ⊆ r x1,y1 .
Finally, we want every non-loop vertex pair to have a non-empty rank, and moreover for it to include the constant a.This is crucial, because a will eventually serve as an "anchor" making sure that there is only one way to assign ranks when encoding a full iterated matching sequence using the ternary relation R.
It is a good time to sum up the full statement that sets up our pair ranks.
Whenever this statement is satisfied, we can use it to construct expressions that compare ranks.We will use the following expressions, which compare the ranks of (x 1 , y 1 ) and (x 2 , y 2 ), when we formulate further conditions on R that will eventually force it to conform to a full iterated matching sequence.Note that conveniently, these comparison expression also work against loops (whose "rank", the empty set, is considered to be the lowest).

Making the ordered pairs correspond to an iterated matching
In this subsection we consider a ternary relation R that is known to satisfy ϕ rank as defined in Subsection 9.3, and impose further conditions that will force it to correspond to an iterated matching sequence (which will also be full by virtue of every pair having a rank).
For every rank appearing in R, that is for every set A which is equal to r x,y for some x, y ∈ [n], we refer to the set of vertex pairs having this rank as E i , where i is the number of ranks that appear in R (including the empty set, which is the "rank" of loops) and are strictly contained in A. So in particular E 0 = {(x, x) : x ∈ [n]}, and E 1 for example would be the set of vertex pairs that have the smallest non-empty set as their ranks.
We first impose the restriction that for any i, the graph defined by i j=1 E j is a transitive graph, that is a disjoint union of cliques.By Observation 23 this is a necessary condition for Ē to be an iterated matching sequence (note that allowing also the 0-ranked loops does not change the condition).This is the same as saying that for any three vertices x, y, z, it cannot be the case that the rank of (x, z) is larger than the maximum ranks of (x, y) and (y, z).
Whenever R satisfies the above, it is not hard to add the restriction that E i consists of disjoint complete bipartite graphs such that each of them connects exactly two components of i−1 j=1 E j , with all such components being covered.First we state that if some rank A exists, that is, there exists some (x, y) for which A = r x,y , then every vertex z is a part of an edge with such rank.
Then, using the prior knowledge that all connected components of both i−1 j=1 E j and i j=1 E j are cliques, to make sure that every connected component of E i is exactly a bipartite graph encompassing two components of i−1 j=1 E j , it is enough to state that it contains no triangles, excluding of course "triangles" of the type (x, x, x).ϕ part = ∀ x,y,z ((x ̸ = y) → ¬(ϕ = (x, y, y, z) ∧ ϕ = (x, y, x, z))) All of the above is sufficient to guarantee that the relation R corresponds to a full iterated matching sequence.However, as things stand now there can be many relations that correspond to the same iterated matching.This occurs because we still have unwanted freedom in choosing the sets that correspond to the possible ranks.To remove this freedom, we now require that the rank of every pair (x, y) for x ̸ = y consists of exactly one connected component of the union of the lower ranked pairs.This will be sufficient, because by ϕ full the only option for the rank would be the connected component that contains the constant a.
Noting that by ϕ trans these components are cliques, it is enough to require that every member of r x,y is connected via a lower rank edge to a, while every vertex that is connected to a member of r x,y via a lower rank edge is also a member of r x,y .We obtain the following statement.
The final statement that counts the number of full iterated matching sequences, and hence provides the example proving Theorem 20 is the following.

Adapting the example to other primes
We show here how to adapt the FOL sentence from Theorem 20 to provide a sequence that is not ultimately periodic modulo p for any prime number p ≥ 2. The analogous corollary about removing the constant also follows.
▶ Theorem 25 (Ternary relation counterexample for p ≥ 2).For any prime number p, there exists an FOL sentence ϕ Mp over the language (a, R), where a is a (hard-wired) constant and R is a relation of arity 3, so that the corresponding class C p satisfies f Cp (n − 1) = 0 for every n that is not a power of p, and f Cp (n − 1) ≡ 1 (mod p) for n = p m for every m ∈ N. In particular, f Cp is not ultimately periodic modulo p.
The construction follows the same lines as the extension from p = 2 to p ≥ 2 in previous works.For completeness we give some details on how it works with respect to the version of [25].The basic idea is to use a "matching" of p-tuples instead of pairs.▶ Definition 26.A p-matching over the vertex set [n] is a spanning graph, each of whose connected components is either a clique with p vertices or a single vertex.A perfect pmatching is a p-matching in which there are no single vertex components (in other words, it is a partition of [n] into sets of size p).
The following is not hard to prove.▶ Lemma 27.There are no perfect p-matchings over [n] unless n is a multiple of p, in which case their number is congruent to 1 modulo p.
Proof.The case where n is not a multiple of p is trivial.Otherwise, consider the number of possible partitions of the set [p] to a sequence of subsets of sizes i 1 , . . ., i r , where r k=1 i k = p.Note that unless i 1 = p (and hence r = 1), the number of such partitions is divisible by p i1 , which is divisible by p (since p is a prime).
Denoting by f Mp (n) the number of perfect p-matchings over [n], We consider for any p-matching its restriction to [p] (which corresponds to a partition of [p] -the reason we need to consider the partitions as sequences rather than as unordered families of sets is that we need to consider which sets in the restriction of the p-matching over [n] \ [p] they are "attached" to).This implies that f Mp (n) ≡ f Mp (n − p) (mod p) for every n > p, allowing us to prove by induction that f Mp (n) ≡ 1 (mod p) if p divides n. ◀ The definition of an iterated p-matching sequence is what one would expect.
▶ Definition 28 (Iterated p-matching sequence).Given a set V of vertices, An iterated pmatching sequence is a sequence graphs over V , identified by their edge sets Ē = E 1 , .The above implies that there can be a full iterated matching sequence over [n] if and only if n is a power of p, in which case ℓ Ē = log p (n). Denoting the number of possible full iterated matching sequences over [n] by f Mp (n), note the following lemma.▶ Lemma 30.For every n that is not a power of p we have f M (n) = 0, while for n = p m for every m ∈ N we have f Mp (n) ≡ 1 (mod p).
Proof.The case where n is not a power of p was already discussed above.The case n = p m is proved by induction over m using Lemma 27. ◀ From here on the construction of ϕ Mp is identical to that of ϕ M in Subsection 9.3 and Subsection 9.4, with the only exceptions being the replacements for ϕ cover and ϕ part .
To construct ϕ coverp , we need to state that for every existing rank, each vertex is a part of a size p clique consisting of edges from this rank.
To construct ϕ part p , we need to state that no E i may contain a clique with p + 1 vertices.
The final expression is the following.

Reducing the example further to have a single relation
We provide here a sketch on how to produce, starting with Theorem 8, a sentence with a single relation that provides a class that is not MC-finite.
▶ Theorem 31 (A sentence with a single relation).For every prime number p ≥ 1 there exists an FOL-sentence ϕ p over a language consisting of a single relation of arity 3, so that for the class C corresponding to ϕ p , its counting function f C (n) is not ultimately periodic modulo p.
Starting with an expression ϕ that results from invoking Theorem 25 over ϕ Mp , we explain how to reduce it further to an expression that involves a single ternary relation.This transformation is ad-hoc and uses certain specific features and symmetries of models satisfying ϕ Mp , and their reflection in the corresponding models satisfying ϕ.The full details require delving into the specifics of the proof of Theorem 19, and are deferred to [17].
As ϕ Mp involves a single ternary relation R and a single constant a, the resulting ϕ involves a corresponding ternary relation, as well as three binary relations, three unary relations, and a single nullary relation.Since the lower order relations result from substituting the constant at some of the places of the relation R (while restricting the other places to hold values different from a), looking at the working of ϕ Mp allows us to immediately rule out most options for the lower arity relations.
For example, the nullary relation would correspond to whether R(a, a, a) holds, so it must evaluate to ⊥ ("false") for all models of ϕ (since ϕ Mp implies ¬R(x, x, y) for all x and y, equal or unequal to a).Thus we may just remove it and replace its occurrences in ϕ with the ⊥ symbol.

C S L 2 0 2 4
Similar considerations allow us to eliminate the unary relation corresponding to R(a, a, x) for x ̸ = a (always false), and the unary relations corresponding to R(a, x, a) and R(x, a, a) (always true by ϕ full since x ̸ = a).
Next, the binary relation corresponding to R(x, y, a) for x, y ̸ = a, while not constant, can be "fully deduced" and replaced with x ̸ = y by ϕ full and ϕ graph .This leaves us with the two relations corresponding to R(x, a, y) and R(a, x, y).By first noting that for satisfying models they are equal to each other (by ϕ graph ), we can reduce them to a single relation.In the final step, we "fold" this relation into the ternary relation, after noting that R has to satisfy ¬R(x, x, y) for all x, y.The last operation requires first replacing the occurrences of R(x, y, z) in the sentence with "(x ̸ = y) ∧ R(x, y, z)", which now "frees" this part of R to be used instead of the binary relation.This does not change the number of satisfying models, since we make sure that this "region" of R is completely used through a bijection for the role of the binary relation that it replaces.

Conclusions and open problems
In this work we have extended the Specker-Blatter Theorem to classes of τ -structures definable in CMSOL for vocabularies τ which contain a finite number of hard-wired constants, unary and binary relation symbols, Corollary 7. We have also shown that it does not hold already when τ consists of only one ternary relation symbol, Theorem 31.We note that in [15,16] we have shown that for C definable in CMSOL such that all structures have degree bounded by a constant d, S C (n) is always MC-finite.The degree of a structure A is defined via the Gaifman graph of A. With this the MC-finiteness of S C (n) for CMSOL-definable classes of τ -structures as a function of τ is completely understood.Applications of our results in this paper to restricted Bell numbers and various restricted partition functions are given in [11].
A sequence of integers s(n) is MC-finite if for every m ∈ N + there are constants r(m), p(m) ∈ N + and coefficients α 1 (m), . . ., α p(m) ∈ N + , such that for all n ≥ r(m) we have s(n + p(m) + 1) ≡ p(m) i=0 α i s(i) mod m.
The Specker-Blatter Theorem gives little information on the constants r(m), p(m) or the coefficients α 1 (m), . . ., α p(m) .These in particular depend on the substitution rank of the class C. In fact Theorem 3 gives a very bad estimate of the substitution rank in the case of binary relation symbols.The constants are computable, but it is not known whether they are always computable in feasible time or whether their size is bounded by an elementary function.In the presence of constants the substitution rank is not defined.Our main Theorem 12 allows to eliminate the constants, and therefore gives a formula for which the substitution rank is defined.However, due to the increased complexity of the resulting formula, the estimate of the substitution rank will be even worse.The proof of Theorem 3 depends on the Feferman-Vaught Theorem which also holds for CMSOL(τ ) for any finite relational τ , [10,22].In our context, the Feferman-Vaught Theorem allows to check whether a formula of CMSOL(τ ) holds in Subst(A 1 , a, A 2 ) by checking a sequence of CMSOL(τ )-formulas in A 1 and A 2 independently.This sequence is called a reduction sequence, cf.[14].In [6] it is shown that even for FOL(τ ) the size of the reduction sequences for the Feferman-Vaught Theorem cannot, in general, be bounded by an elementary function.
▶ Problem 33.Does there exist an elementary function f (k), so that for any sentence ϕ in CMSOL(τ ) where τ consists only of constants, unary and binary relation symbols, the size of the constants r(m) and p(m) is bounded by f (max{|ϕ|, m})?
The Specker-Blatter Theorem also applies to hereditary, monotone and minor-closed graph classes, provided they are definable using a finite set of forbidden (induced) subgraphs or minors.In the first two cases such a class is FOL-definable.In the case of a minor-closed class, B. Courcelle showed that it is MSOL-definable, see [5].By the celebrated theorem of N. Robertson and P. Seymour, [7], every minor-closed class of graphs is definable by a finite set of forbidden minors.However, there are monotone (hereditary) classes of graphs where a finite set of forbidden (induced) subgraphs does not suffice.
▶ Problem 34.Are there hereditary or monotone classes of graphs C such that Sp C (n) is not MC-finite?
An analogue question arises when we replace graphs by finite relational τ -structures.In this case one speaks of classes of τ -structures closed under substructures.Every class of finite τ -structures C closed under substructures can be characterized by a set of forbidden substructures.If this set is finite, C is again FOL-definable, and the Specker-Blatter Theorem applies.

▶ Problem 35.
(i) Let τ be a relational vocabulary.Are there substructure closed classes C of τ -structures such that Sp C (n) is not MC-finite?(ii) Same question when all the relations are at most binary?
Let τ consist of a finite set of (hard-wired) constant symbols ā, unary relations symbols Ū , and binary relation symbols R. For every class C of τ -structures there exist classes C 1 , . . ., C r of τ ′ -structures, where τ ′ -contains only a finite number r(ā, Ū , R) of binary relation symbols, such that

▶ Observation 16 .
Definition 15 provides a bijection between the set of possible models M over the universe [n + ℓ ā] (where the constants are interpreted as in Definition 15), and the set of possible triples (N, U, R) where N is a model over [n + ℓ ā − 1] (where the constants are interpreted as in Definition 15) and U ⊆ [ℓ Ū ] and R ⊆ [ℓ R].

▶
Problem 32.Given a sentence ϕ in CMSOL(τ ) where τ consists only of constants, unary and binary relation symbols, (i) what is the time complexity of computing the constants r(m), p(m) and the coefficients α 1 (m), . . ., α p(m) ?(ii) what can we say about the size of these constants?
Theorem 12 (Reducing model counts to the case without constants).For any class C defined by an FOL (resp.MSOL, CMSOL) sentence involving a set of constant symbols ā, unary symbols Ū and binary symbols R, there exist classes C 1 , . . ., C r (where r depends on the original language), definable by FOL (resp.MSOL, CMSOL) sentences involving Ū ′ (which contains Ū ), R and no constants, satisfying f C

Fischer and J. A. Makowsky 26:17 ▶ Observation 29.
. ., E ℓ Ē , satisfying the following for every1 ≤ i ≤ ℓ Ē .The connected components of E i are (vertex-disjoint) complete p-partite graphs.The p vertex classes of every complete p-partite graph in E i as above are p connected components of is a vertex class of some p-partite graph of E i (so in particular E 1 is a perfect p-matching).An iterated matching sequence Ē is full if every vertex pair u, v ∈ V (where u ̸ = v) appears in some E i .Again we have the following properties, analogous to those of iterated matching sequences.For an iterated p-matching Ē, every E i corresponds to a perfect pmatching over the set of connected components of E.