EQUIVALENCE CLOSURE IN THE TWO-VARIABLE GUARDED FRAGMENT

We consider the satisfiability and finite satisfiability problems for the extension of the two-variable guarded fragment in which an equivalence closure operator can be applied to two distinguished binary predicates. We show that the satisfiability and finite satisfiability problems for this logic are 2-ExpTime-complete. This contrasts with an earlier result that the corresponding problems for the full two-variable logic with equivalence closures of two binary predicates are 2NExpTime-complete.

1. Introduction.The two-variable fragment of first-order logic, FO 2 , and the two-variable guarded fragment, GF 2 , are widely investigated formalisms whose study is motivated by their close connections to modal, description and temporal logics.It is well-known that FO 2 enjoys the finite model property [13], and that its satisfiability (= finite satisfiability) problem is NExpTime-complete [4].Since GF 2 is contained in FO 2 , it too has the finite model property; however, its satisfiability problem is slightly easier, namely ExpTime-complete [5].
It is impossible, in FO 2 , to write a formula expressing the condition that a given binary relation is an equivalence (i.e. is reflexive, symmetric and transitive); and the question therefore arises as to whether such a facility could be added at reasonable computational cost.In a series of papers [10,12,9], various extensions of FO 2  were investigated in which certain distinguished binary predicates are declared to be equivalences, or in which an operation of equivalence closure can be applied to these predicates.(The equivalence closure of a binary relation is the smallest equivalence that includes it.)Denote by EQ 2 k the extension of FO 2 in which k distinguished binary predicates are interpreted as equivalences, and by EC 2  k the extension of FO 2 in which we can take the equivalence closure of any of k distinguished binary predicates.The following is known: (i) EQ 2  1 and EC 2  1 retain the finite model property, and their satisfiability (= finite satisfiability) problems are NExpTime-complete; (ii) EQ 2  2 and EC 2 2 lack the finite model property, and their satisfiability and finite satisfiability problems are 2-NExpTime-complete; (iii) when k ≥ 3, the satisfiability and finite satisfiability problems for EQ 2 k and EC 2 k are undecidable.Turning now to GF 2 , denote by GFEQ 2  k the extension of GF 2 in which k distinguished binary predicates are interpreted as equivalences, and by GFEC 2  k the extension of GF 2 in which we can take the equivalence closure of any of k distinguished binary predicates.It was shown in [7] that the satisfiability and finite satisfiability problems for GFEQ 2  1 are both NExpTime-hard, whence, by the above-mentioned results on EQ 2  1 , both these problems are NExpTime-complete.In addition, the undecidability results for EQ 2  k and EC 2 k (k ≥ 3) referred to in the previous paragraph employ only guarded formulas, whence satisfiability and finite satisfiability for GFEQ 2 k and GFEC 2  k are undecidable when k ≥ 3.This leaves only the case k = 2.It is known that GFEQ 2  2 and GFEC 2 2 lack the finite model property (see, e.g., the example in Section 2 of [9], and observe that all formulas there are indeed guarded).The satisfiability problem for GFEQ 2  2 was shown to be 2-ExpTime-complete in [7].The corresponding finite satisfiability problem was not addressed there; and while the method employed to establish the 2-ExpTime lower-bound can easily be adapted to the finite case, the proof of the upper bound, which was based on tree-unravelling methods, fails.In this paper we solve the remaining open problems by establishing a 2-ExpTime upper bound on the satisfiability and finite satisfiability problems for GFEC 2  2 .It follows that these problems are 2-ExpTime-complete, as is the finite satisfiability problem for GFEQ 2  2 .To establish these results, we adopt the same strategy as that employed in [9] for the logics EQ 2  2 and EC 2 2 ; and we briefly review that strategy now.For concreteness, let ϕ be an EQ 2  2 -formula whose finite satisfiability we are trying to establish.We may assume that ϕ features two distinguished binary predicates, which must be interpreted as equivalences.Denote these equivalences (in some putative finite model) by r 1 and r 2 : note that their coarsest common refinement, r 1 ∩ r 2 , is also an equivalence.We call the equivalence classes of r 1 ∩ r 2 intersections, and we show that the intersections arising in any finite model of ϕ can, without loss of generality, be assumed to have cardinality exponentially bounded as a function of the size of ϕ.In particular, every r 1 -class, and also every r 2 -class, is the union of some set of such "small intersections"; and any given r 1 -class and r 2 -class are either disjoint, or have exactly one common intersection.This decomposition into equivalence classes allows us to picture any finite model of ϕ as an edge-coloured, bipartite graph: the r 1 -classes are the left-hand vertices; the r 2 -classes are the right-hand vertices; and two vertices are joined by an edge just in case they share an intersection, with the colour of that edge being the isomorphism type of the intersection concerned.The formula ϕ imposes various constraints on the types of intersections that may arise, and on how intersections may be organized into r 1 -and r 2 classes.These constraints translate to conditions on the induced bipartite graph of equivalence classes, so that the original (finite) satisfiability problem becomes the problem of determining the existence of an edge-coloured bipartite graph satisfying certain conditions on the local configurations it realizes.These conditions, it transpires, can be expressed in purely numerical terms-specifically, as a system of linear inequalities over integer variables.Thus, the problem of determining the finite satisfiability of ϕ is translated into an instance of integer linear programming.The instance in question can be shown to be doubly exponential in the size of ϕ; and using the well-known fact that integer linear programming feasibility is in NPTime, the 2-NExpTime-upper bound for the finite satisfiability of EQ 2 2 follows.The main technical contribution of the present paper is a proof that, for the guarded sub-fragments, GFEQ 2  2 and GFEC 2 2 , we obtain systems of linear inequalities for which solutions may be sought not over integers, but over the reals.The 2-ExpTime-upper bound for these logics then follows from the well-known fact that (real) linear programming feasibility is in PTime.In addition, the need to obtain a 2-ExpTime-upper bound-as opposed to a 2-NExpTime-upper as in the case of EC 2  2 -means that we no longer have the luxury of doubly exponentially many non-deterministic choices in the decision procedure.This fact necessitates various changes at a tactical level throughout the proof.
The plan of the paper is as follows.In Sec. 2, we define the logics GFEQ 2  2 and GFEC 2  2 , introducing a 'Scott-type' normal form for GFEC 2 2 that allows us to restrict the nesting of quantifiers to depth two.In Sec. 3 we define a problem concerning the existence of certain bipartite graphs, called BGE * , and show that both the finite and general versions of this problem are in PTime.In Sec. 4, we prove some technical lemmas that allow us in Sec. 5 to reduce the (finite) satisfiability problem of a GFEC 2 2formula to (finite) BGE * in deterministic doubly exponential time.

Preliminaries.
2.1.Logics, structures and types.We employ standard terminology and notation from model theory throughout this paper (see, e.g.[3]).In particular, we refer to structures using Gothic capital letters, and their domains using the corresponding Roman capitals.We denote by GF 2 the guarded two-variable fragment of first-order logic (with equality), without loss of generality restricting attention to signatures of unary and binary predicates.Formally, GF 2 is the intersection of FO 2 (i.e., the restriction of first-order logic in which only two variables, x and y are available) and the guarded fragment, GF [1].GF is defined as the least set of formulas such that: (i) every atomic formula belongs to GF; (ii) GF is closed under logical connectives ¬, ∨, ∧, ⇒; and (iii) quantifiers are appropriately relativised by atoms, i.e., denoting by x, y tuples of variables, if ϕ(x, y) is a formula of GF and α(x, y) is an atomic formula containing all the free variables of ϕ, then the formulas ∀y(α(x, y) ⇒ ϕ(x, y)) and ∃y(α(x, y) ∧ ϕ(x, y)) belong to GF.In this context, the atom α(x, y) is called a guard.Equalities x=x or x=y are also allowed as guards.
We denote by GFEC 2 k the set of GF 2 -formulas over any signature τ = τ 0 ∪ {r 1 , . . ., r k } ∪ {r # 1 , . . ., r # k }, where τ 0 is an arbitrary set containing unary and binary predicates, and r 1 , . . ., r k , r # 1 , . . ., r # k are distinguished binary predicates, not present in τ 0 .In the sequel, any signature τ is assumed to be of the above form (for some appropriate value of k).We denote by GFEQ 2 k the set of GFEC 2 k -formulas in which the predicates r # 1 , . . ., r # k do not occur.The semantics for GFEC 2  k are standard, subject to the restriction that r # i is always interpreted as the equivalence closure of r i .More precisely: we consider only structures A in which, for all i (1 ≤ i ≤ k), (r # i ) A is the smallest reflexive, symmetric and transitive relation including r A i .Similarly, we require for GFEQ 2 k that r i is always interpreted as an equivalence.Where a structure is clear from context, we may equivocate between predicates and their extensions, writing, for example, r i and r # i in place of the technically correct r A i and (r # i ) A .Let A be a structure over τ .We say that there is an r i -edge between a and a ∈ A if A |= r i [a, a ] or A |= r i [a , a].Distinct elements a, a ∈ A are r i -connected if there exists a sequence a = a 0 , a 1 , . . ., a k−1 , a k = a in A such that for all j (0 ≤ j < k) there is an r i -edge between a j and a j+1 .Such a sequence is called an r i -path from a to a .Thus, A |= r # i [a, a ] if and only if a and a are r i -connected.A subset B of A is called r i -connected if every pair of distinct elements of B is r i -connected.Maximal r i -connected subsets of A are equivalence classes of r # i , and are called r # i -classes.We mostly work with the logic GFEC 2  2 .In any structure A, the relation is also an equivalence, and we refer to its equivalence classes, simply, as intersections.
Thus, an intersection is a maximal set that is both r 1 -and r 2 -connected.When discussing induced substructures, a subtlety arises regarding the interpretation of the closure operations.If B ⊆ A, we take it that, in the structure B induced by B, the interpretation of r # i is given by simple restriction: (r # i ) B = (r # i ) A ∩ B 2 .This means that, while (r # i ) B is certainly an equivalence including r B i , it may not be the smallest, since, for some a, a ∈ B, an r i -path connecting a and a in A may contain elements which are not members of B. (Such a situation may arise even when B is an intersection.)To reduce notational clutter, we use the (possibly decorated) letter A to denote 'full' structures in which we are guaranteed that (r # i ) A is the equivalence closure of r A i .For structures denoted by other letters, B, C, . . .(again, possibly decorated), no such guarantee applies.Typically, but not always, these latter structures will be induced substructures.
An (atomic) 1-type (over a given signature) is a maximal satisfiable set of atoms or negated atoms with free variable x.Similarly, an (atomic) 2-type is a maximal satisfiable set of atoms and negated atoms with free variables x, y.Note that the numbers of 1-types and 2-types are bounded exponentially in the size of the signature.We often identify a type with the conjunction of its elements.
For a given τ -structure A, we denote by tp A (a) the 1-type realized by a, i.e., the 1-type α such that A |= α[a].Similarly, for distinct a, b ∈ A, we denote by tp A (a, b) the 2-type realized by the pair a, b, i.e., the 2-type If ϕ is a formula, we write ϕ to denote the number of symbols in ϕ.
2.2.Normal form and small intersections.In the context of FO 2 , it is often convenient to work with formulas in so-called Scott normal form.The following definition adapts this notion to the setting of GFEC 2  2 .Definition 2.1.A normal guard is any of the formulas r where γ(x) is a τ 0 -atom, η(x, y) is a normal guard, and ψ(x), ψ(x, y) are quantifierfree formulas not using r # 1 and r # 2 , with free variables as indicated.Where a normalform GFEQ 2  2 -formula ϕ is given, we refer to these four types of formulas as its ∀-, ∃-∀∀-and ∀∃-conjuncts, respectively.
The forms (∀) and (∃) are not, strictly speaking, in GFEC 2 2 ; but they can easily be transformed into logically equivalent formulas which are.Thus, for example, ∀xψ(x) is equivalent to ∀x((x = x) → ψ(x)), and similarly for the case (∃).
For technical reasons we assume that τ 0 contains unary symbols 2 , and we will always assume, without loss of generality, that a normal form ϕ contains the following conjuncts ).This guarantees that in every model of ϕ, precisely the elements containing an r i -edge leading into/outside their intersection are marked by K in/out i predicates.It is easy to see that, for a GFEQ 2 2 -formula not featuring the predicates K in/out i , adding these conjuncts results in a formula satisfiable over the same domains.
The following lemma justifies the usefulness of the introduced normal form.Lemma 2.2.The (finite) satisfiability problem for GFEC 2  2 can be reduced to the (finite) satisfiability problem for disjunctions of an exponential number of linearly bounded GFEC 2  2 -formulas in normal form.This can be proved using some standard techniques.See [14] (Lemma 2) for the proof of a similar result, which easily adapts to the present case.Since we are going to show that (finite) satisfiability is in 2-ExpTime, it is enough to consider formulas in normal form.
It is sometimes useful to group together various conjuncts of a normal-form formula.
Definition 2.3.If ϕ is as in Definition 2.1, let us write: -formula, and A a τ -structure, then A |= ϕ if and only if the following three conditions hold: It was shown in [8] (Lemma 4.2) that, when considering (finite) satisfiability of EC 2  2 -formulas, one can restrict attention to models with exponentially bounded intersections.Since this result subsumes the case of GFEC 2  2 , we have: Lemma 2.4.Let ϕ be a satisfiable GFEC 2  2 -formula in normal form over a signature τ .Then there exists a model of ϕ in which the size of each intersection is bounded by f(|ϕ|), for a fixed exponential function f.

A problem concerning bipartite graphs.
3.1.Definition of BGE * .In the sequel, we denote by N the set of non-negative integers, and by N * the set N ∪ {ℵ 0 }, where n < ℵ 0 for all n ∈ N. In [9], a family of problems was defined concerning the existence of edge-coloured bipartite graphs satisfying various collections of conditions.The simplest of these, BGE (bipartite graph existence), is shown to be in PTime.This paper employs a variant of BGE, which we denote by BGE * .
Let ∆ be a finite, non-empty set.A ∆-graph is a triple H = (U, V, E ∆ ), where U , V are disjoint sets of cardinality at most ℵ 0 , and E ∆ is a collection of pairwise disjoint subsets E δ ⊆ U × V , indexed by the elements of ∆.We call the elements of W = U ∪ V vertices, and the elements of E δ , δ-edges.It helps to think of E ∆ as the result of colouring the edges of the bipartite graph (U, V, E), where E = δ∈∆ E δ , using the colours in ∆.For any w ∈ W , we define the function ord H w : ∆ → N * , called the order of w, by Thus, ord H w tells us, for each colour δ, how many δ-edges w is incident to in H. Obviously, if H is finite, the values of ord H w all lie in N. When constructing ∆-graphs, it is sometimes more convenient to employ a slightly more general notion.We define a ∆-multigraph in the same way as a ∆-graph, except that the E δ 's are now multi-sets, and are not required to be disjoint.Thus, in a ∆-multigraph (U, V, E ∆ ), a pair of nodes u ∈ U and v ∈ V may be joined by any number of edges of any colours.The order-functions are defined in the obvious way, recording the total number of edges of each colour to which the node in question is incident.
If M is a positive integer, we write M to denote the set { = 0, = 1, ≥ 0, ≥ 1, . . ., ≥ M }.We use the notation = k and ≥ k, where k is a variable, to denote elements of this set; formally, however, these elements have no internal structure.Note that = k makes sense only for k = 0 or k = 1.
Definition 3.1.Let M be a positive integer and ∆ a finite nonempty set.Given functions f : ∆ → N * and p : ∆ → M , we say that f realizes p if, for all δ ∈ ∆: Definition 3.2.Let p : ∆ → M , where M and ∆ are as in Definition 3.1.We denote by p the function p : ∆ → N obtained by erasing decorations from the results of p; that is: A function p : ∆ → M , may be thought of as expressing a collection of conditions on functions f : ∆ → N. To say that f : ∆ → N realizes p is simply to say that f satisfies the conditions in question.Note that, trivially, p realises p.We now proceed to define the problem BGE * .Definition 3.3.A BGE * -instance is a quintuple P = (∆, ∆ 0 , M, P, Q), where ∆ is a finite, non-empty set, ∆ 0 ⊆ ∆, M is a positive integer, and P and Q are sets of functions for all u ∈ U , ord H u realizes some function from P ; (G2) The problem BGE * is as follows: Given: a BGE * -instance P. Output: Yes, if P has a solution; No, otherwise.
The problem finite BGE * is as follows: Given: a BGE * -instance P. Output: Yes, if P has a finite solution; No, otherwise.
That is: suppose we are given a set of colours ∆, a distinguished subset ∆ 0 ⊆ ∆ and sets of functions P , Q mapping ∆ to the set of decorated integers M .We wish to know whether there exists a (finite) ∆-graph (U, V, E ∆ ) in which the vertices in U have only order-functions realising functions from P , the vertices in V have only order-functions realising functions in Q, and each of the colours in ∆ 0 is represented by at least one edge.
In the next two subsections we show that BGE * and finite BGE * can be solved in polynomial time.

Complexity of finite BGE *
. By a linear Diophantine clause we mean a disjunction of linear Diophantine equations and inequalities.(We allow clauses to have just one disjunct).A solution of a system of linear Diophantine clauses is an assignment of non-negative integers to its variables making all its clauses true.If such a solution exists, the system of linear Diophantine clauses in question is said to be satisfiable.We proceed to reduce finite BGE * to the satisfiability problem for systems of linear Diophantine clauses of a particular form.
To understand the reduction, let P = (∆, ∆ 0 , M, P, Q) be a BGE * -instance, and let us suppose that P has a finite solution H = (U, V, E ∆ ).Order the sets of functions P and Q arbitrarily.For every p ∈ P , let U p be the set of vertices u ∈ U such that p is the first function in P realized by ord H u , and, for every q ∈ Q, let V q be the set of vertices v ∈ V such that q is the first function in Q realized by ord H u .Now set Employing the notation of Definition 3.2, it is obvious that, for all δ ∈ ∆: Now define, for all δ ∈ ∆ and p ∈ P : and similarly for c δ q (q ∈ Q).Since H is a solution of P, E δ is non-empty for all δ ∈ ∆ 0 .Hence, the following sets of inequalities hold: Now define, for all δ ∈ ∆ and p ∈ P : and similarly for d δ q (q ∈ Q).Evidently, if p∈P d δ p x p = 0, no edge in E δ can be incident on more than one vertex of U , so that we in fact have p∈P p(δ)x p = |E δ |.Likewise, if q∈Q d δ q y q = 0, no edge in E δ can be incident on more than one vertex of V , so that we have q∈Q q(δ)y q = |E δ |.It follows from (3.1) that the following sets of linear Diophantine clauses hold: Regarding the x p and y q as variables ranging over N, let E P be the system of linear Diophantine clauses (3.2)- (3.5).Notice that the various constants c δ p , c δ q , d δ p and d δ q depend only on P and not on the supposed solution, H. Thus, we have shown that, if the BGE * -instance P has a finite solution, then the system of linear Diophantine clauses E P has a solution over N.
We now show that, conversely, if the system of linear Diophantine clauses E P has a solution over N, then the BGE * -instance P has a finite solution.Suppose, then, that the collections of integers {x p } p∈P and {y q } q∈Q satisfy (3.2)-(3.5).For each p ∈ P , we take a set of vertices U p of cardinality x p , and let U be the disjoint union of the U p ; similarly, for each q ∈ Q, we take a set of vertices V q of cardinality y q , and let V be the disjoint union of the V q .(We assume that U and V are disjoint.)Let us imagine each u ∈ U p to have p(δ) 'dangling' δ-edges for all δ ∈ ∆; and likewise let us imagine each v ∈ V q to have q(δ) 'dangling' δ-edges for all δ ∈ ∆.Our task is to match up these dangling edges so as to form a bipartite ∆-graph which is a solution of P.
To make our task easier, we first construct a ∆-multigraph G = (U , V , E ∆ ) with the required properties.Fix δ ∈ ∆, let δ(U ) be the set of dangling δ-edges attached to the elements of U , and let δ(V ) be the set of dangling δ-edges attached to the elements of V .Evidently, Suppose first that |δ(U )| ≤ |δ(V )|.Then we identify the elements of δ(U ) with |δ(U )| elements of δ(V ), thus dealing with all the dangling edges in δ(U ) as well as |δ(U )| of the dangling edges in δ(V ).If there are any remaining dangling edges in δ(V ), we observe from (3.6) that p∈P p(δ)x p < q∈Q q(δ)y q , whence, from (3.4), p∈P d δ p x p > 0-i.e.there exists u ∈ U p , for some p such that p(δ) = ≥ k for some k ≥ 0. Pick any such u and attach all the dangling edges in δ(V ) not yet accounted for to u. If, on the other hand, |δ(U )| ≥ |δ(V )|, we apply the mirror-image construction and use (3.5).Either way, all dangling edges will eventually be linked up, and we obtain a ∆-coloured multigraph, G, with node-sets U and V .We see that, for each p ∈ P , and each u ∈ U p , ord G u realizes p; likewise, for each q ∈ Q, and each v ∈ V q , ord G v realizes q.We make one small change to G before proceeding.Consider any δ ∈ ∆ 0 , and suppose there are no δ-edges in G. Then it is impossible that we have x p > 0 for any p ∈ P such that p(δ) ≥ 1; and it is likewise impossible that we have y q > 0 for any q ∈ Q such that q(δ) ≥ 1.From (3.2), then, we can find p ∈ P such that x p > 0 and p(δ) = ≥ 0; likewise, from (3.3), we can find q ∈ Q such that y q > 0 and q(δ) = ≥ 0. Pick u ∈ U p and v ∈ V q , and add a δ-edge between u and v.This change clearly does not compromise the fact that ord G u realizes p or that ord G v realizes q.In this way, we can ensure that, for all δ ∈ ∆ 0 , G contains a δ-edge.
It remains to replace the ∆-multigraph G with a ∆-graph H in such a way that the realized order-functions are not disturbed.Let s be the maximum multiplicity of edges in H (i.e. the maximum number of any edges connecting any pair of vertices).Then H can be constructed by taking s replicas of G and appropriately rearranging the multiple edges.More precisely, let ) is a fresh copy of U (respectively, V ).For every u ∈ U , denote by u i the copy of u in U i , and similarly for every v ∈ V .Now execute the following process for all pairs u ∈ U and v ∈ V joined by at least one edge: let e 0 , . . ., e r−1 (0 < r ≤ s) be the collection of (coloured) edges joining u and v in G; for every p (0 ≤ p ≤ r − 1) and i (0 ≤ i ≤ s − 1), let H contain an edge with the same colour as e p between u i and v i+p mod s .Since r ≤ s, no pair of elements is joined by more than one edge, so that H is a ∆-graph.Moreover, for all u ∈ U , if u is a copy of some element u ∈ U p , then ord H u = ord G u = p; similarly, if v is a copy of some element v ∈ V q , then ord H v = ord G v = q.Thus, H is a solution of P. We have proved: Lemma 3.4.There is a polynomial-time reduction of finite BGE * to the satisfiability problem for sets of linear Diophantine clauses of the forms (3.2)-(3.5).We conclude: Theorem 3.5.Finite BGE * is in PTime.Proof.By Lemma 3.4, it suffices to show that the satisfiability of systems of linear Diophantine clauses of the forms (3.2)-(3.5)can be solved in polynomial time.
Consider any system of r Diophantine linear inequalities of the form a • z ≤ b, in k variables; and let C be the maximum absolute value of any of the constants occurring in that system.It is well-known that, if there exists a solution (over N), then there exists such a solution in which all values are bounded by K = ((k + 1)C) r -that is, by an exponential function of the size of the system [2].Evidently, therefore, given a system E of linear Diophantine clauses of the forms (3.2)-(3.5), the same bound applies.Now let R = kCK, and replace any clause in E of the form by the corresponding linear equality Let the resulting system of linear inequalities be E .We first observe that E entails E. For if (3.8) holds, the corresponding instance of (3.7) clearly does too.Conversely, if E has a solution, then so has E .For consider a solution of E in which all entries are bounded by K, so that the expression c Either way, (3.8) is satisfied, as required.
Hence, the problem of determining the satisfiability (over N) of a system of linear Diophantine clauses of the forms (3.2)-(3.5)can be reduced in polynomial time to the problem of determining the corresponding problem for systems of linear Diophantine inequalities of the form a • z ≥ b.Evidently such a system has a solution over N if and only if it has a solution over the non-negative rationals.The result then follows from the fact that linear programming feasibility is in PTime [6].

Complexity of BGE * .
In this subsection we show that BGE * can be solved in polynomial time.Rather than introducing infinite values to the systems of equations considered in Sec 3.2, we proceed by reduction to the satisfiability problem for propositional Horn clauses.Recall, in this connection, that, if X 1 , . . ., X m , X are Boolean-valued variables, a Horn clause is an implication of either of the forms interpreted in the usual way.It is well-known that the problem of determining the satisfiability of a collection of Horn clauses is in PTime.
Proof.Let P = (∆, ∆ 0 , M, P, Q) be an instance of BGE * .For p ∈ P , let X p be a proposition letter, which we may informally read as "There are no vertices in U whose order-function realizes p." Similarly, for q ∈ Q, let Y q be a proposition letter, which we may informally read as "There are no vertices in V whose order-function realizes q." Consider the set Γ of propositional Horn-clauses (3.12) Intuitively, (3.9) says "For all δ ∈ ∆, if no vertices in V are allowed to be incident on a δ-edge, then no vertices in U can be required to be incident on a δ-edge;" (3.10) expresses the mirror-image implication; (3.11) says "For all δ ∈ ∆ 0 , some vertices in U are allowed to be incident on some δ-edges;" and (3.12) expresses the same condition for vertices of V .Suppose Γ is satisfiable.For each p ∈ P such that X p is false, take an infinite set U p , and for each q ∈ Q such that Y q is false, take an infinite set V q .Let U = p∈P U p and V = q∈Q V q .For each δ ∈ ∆, for each p ∈ P , and each u ∈ U p , attach p(δ) 'dangling' δ-labelled edges to u; and similarly for the elements of V , using the functions q ∈ Q.By (3.9), if a dangling δ-labelled edge is attached to some vertex of U , then there is q ∈ Q with q(δ) = = 0 such that Y q is false.We have two cases.Either we already have a dangling δ-labelled edge attached to some vertex of V , or no dangling δ-labelled edge is attached to any vertex of V , but there is q ∈ Q with q(δ) = ≥ 0 such that Y q is false.In the latter case, we choose any such q, and for each v ∈ V q , attach one dangling δ-edge.Using (3.10), we proceed analogously with U and V transposed.After this step, if there is a dangling δ-labelled edge attached to some vertex of U (hence infinitely many vertices of U ), then there is a dangling δ-labelled edge attached to infinitely many vertices of V .These dangling edges can easily be matched up without clashes, thus forming an infinite ∆-graph.Finally, for every δ ∈ ∆ 0 if there is no δ-edge attached to any vertex of U then using (3.11)-(3.12),we find p ∈ P and q ∈ Q such that p(δ) = = 0, X p is false, q(δ) = = 0 and Y q is false and we find u ∈ U p and v ∈ V q such that u and v are not connected by any edge and add a δ-edge from u to v. Hence P is a positive instance of BGE * .
Conversely, if P is a positive instance of BGE * , let H = (U, V, E ∆ ) be a solution.Now interpret the variables X p and Y q as indicated above.It is obvious that (3.9)-(3.12)hold.Thus, Γ is satisfiable.This completes the reduction.

Surgery on classes.
In this section, we fix a normal form GFEC 2  2 -formula ϕ over signature τ = τ 0 ∪ {r 1 , r 2 } ∪ {r # 1 , r # 2 }.Say that a τ -structure I is a pre-intersection if for all a, a ∈ I we have a ] (but we do not require (r # i ) I to be the equivalence closure of r I i ).Obviously, if I is an intersection of A, then the induced substructure I is a pre-intersection.We will use pre-intersections as building blocks to construct bigger structures in which they will eventually become intersections.By the type of a preintersection, we mean its isomorphism type.Recalling Lemma 2.4, let ∆ be the set of all types of pre-intersections I of size bounded by f(|τ |) such that I |= ϕ 12 .
We write D ≈ f i if D is an r i -connected structure built out of pre-intersections from ∆, and f : ∆ → N * is a function returning for each δ ∈ ∆ the number of realisations of δ in D. We will use such structures as r # i -classes in bigger models.Clearly, f does not fully determine D, but it carries information which is crucial for our purposes.In the case where f : ∆ → N, we define |f | = δ∈∆ f (δ).
For a given isomorphism type of pre-intersection δ and a 1-type α we say that δ realizes α if, for D of type δ, D |= ∃xα(x).For a given function f : ∆ → N * we say that f realizes α if δ realizes α for some δ ∈ ∆ such that f (δ) ≥ 1.
Definition 4.1.We say that a pre-intersection type δ is i-adjoinable to a function f : ∆ → N * , and write δ i f , if the following three conditions hold: (i) every 1-type realized by δ is realized by f , (ii) for any 1-types α realized by δ and α realized by f (possibly α = α ) there exists a 2-type β such that β(x, y) |= ϕ univ and (iii) for any pre-intersection I of type δ, any of its r i -connected components contains an element of 1-type α such that Proof.Condition (i) follows from the fact that f (δ) > 0. To see (ii) consider any 1-type α realized in δ.Assume that I 1 , I 2 are pre-intersections of D of type δ promised by f .Let a ∈ I 1 be a realization of α.For any 1-type α realized by f we can find a realization a of α such that a ∈ I 1 .In particular, if α is realized only in preintersections of type δ then a can be found in I 2 .Now we choose β to be tp D (a, a ).We have that r # i (x, y) ∈ β(x, y) since D is r i -connected and ¬r # 3−i (x, y) ∈ β(x, y) since a and a are in different pre-intersections.Obviously β(x, y) |= ϕ univ , since ϕ univ is a fragment of ϕ 1 and D |= ϕ 1 .Finally consider a realization I of δ in D and its r i -connected component B. Since there are at least two pre-intersections in D and D is r i -connected it follows that there must be at least one r i -edge with one of its endpoints in B and the other in D \ I.Both endpoints in such an edge must be marked by K in i or by K out i (cf. a comment following Definition 2.1).Definition 4.2.For functions f, g : ∆ → N * we say that g safely i-extends f , and write g i f , if for all δ ∈ ∆, (i) g(δ) ≥ f (δ), and (ii) g(δ) > f (δ) implies δ i f .
The following two lemmas will be used later.The first allows us to 'inflate' r # iclasses in a model of ϕ by adjoining pre-intersections.The second is much more involved: it allows us, under certain circumstances, to 'deflate' r # i -classes in a model of ϕ by removing intersections; we show that, after some minor housekeeping, the resulting structure is still a model of ϕ.
Lemma 4.3.Let f, g : ∆ → N * be such that g i f .If there exists D |= ϕ i such that D ≈ f i , then there exists D |= ϕ i such that D ≈ g i .
Proof.Let D |= ϕ i and D ≈ f i .We build D out of D and g(δ) − f (δ) preintersections of type δ for each δ (where ℵ 0 − n = ℵ 0 for all n ∈ N).First let us define connections between D and each of the newly added pre-intersections I.Note that by Definition 4.2 the type of each of these new pre-intersections is i-adjoinable to f .For each element a ∈ I, using condition (i) of Set tp D (a, a ) := β, where β is a 2-type promised by condition (ii) of Definition 4.1 for α = α.This guarantees that a has appropriate witnesses inside D and D (D ∪ I) |= ϕ univ , for, by Definition 2.3, ϕ univ is a conjunct of ϕ 12 and in this section every δ ∈ ∆ is a type of some pre-intersection satisfying ϕ 12 .Moreover due to condition (iii) of Definition 4.1 D is r i -connected (as D is r i -connected, and elements a ∈ I satisfying K in i or K out i must have an r i -edge to D).It remains to define connections between newly added pre-intersections.Let I, I be two distinct newly added pre-intersections, and let a ∈ I, a ∈ I be elements realizing 1-types α, α , respectively.Condition (i) of Definition 4.1 guarantees that α is realized by f .Set tp D (a, a ) := β, where β is a 2-type promised by part (ii) of Definition 4.1 .This ensures that D |= ϕ univ .Together with the earlier remarks we have that D |= ϕ i .
Lemma 4.4.Let f be a function ∆ → N * such that D ≈ f i for some D |= ϕ i .Then there exists a function g : ∆ → N, such that f i g and |g| ≤ g(|τ |) (for a fixed exponential function g) and a structure D ≈ g i such that D |= ϕ i .
Proof.We prove the lemma for i = 1.The proof for i = 2 is symmetric.Let m be the number of ∀∃-conjuncts in ϕ 1 .We proceed by first selecting a sub-model D 0 ⊆ D, and then modifying D 0 to produce the required structure D .The selection of D 0 comprises four steps.
Step 1.For each 1-type α realized in D, mark m distinct pre-intersections containing a realisation of α (or all such pre-intersections if α is realized in fewer than m of them).Let B 0 be the union of all pre-intersections marked in this step.Note that, for any element whose connections with B 0 are not fixed, B 0 will be able to supply any witnesses required by the ∀∃-conjuncts in ϕ 1 .
Step 2. For each a ∈ B 0 and each conjunct ∀x(γ(x) → ∃y(r and mark the pre-intersection of b.Let B 1 be the union of all pre-intersections marked in this step. Step 3.For each pair of elements a, b ∈ B 0 ∪ B 1 which are not r 1 -connected in D (B 0 ∪ B 1 ), if there is an r 1 -path of the form a = c 1 , c 2 , . . ., c l = b with c 2 . . ., c l−1 ∈ B 0 ∪ B 1 , then choose one such path, call it P ab , and mark the pre-intersections of c 2 , . . ., c l−1 .(Obviously, an r 1 -path in D between a and b exists for all a, b ∈ B 0 ∪ B 1 , as D is r 1 -connected.Note that we consider only such paths in which all elements, except a and b, lie outside B 0 ∪ B 1 .)Additionally, call the two elements c 2 and c l−1 peripheral connectors (of P ab ).Let B 2 be the set of all pre-intersections marked in this step.Note that after this step any pair of elements from ).This does not mean however that D (B 0 ∪ B 1 ∪ B 2 ) is r 1 -connected (since some pre-intersections from B 2 may be not internally r 1 -connected).
Step 4. For any element a being a peripheral connector or belonging to B 1 \ B 0 , and for each conjunct ∀x(γ(x) → ∃y , and mark the pre-intersection of b.Let B 3 be the union of all pre-intersections marked in this step.
).We now modify D 0 to yield the desired structure D .At this moment recall that: (i) elements from B 0 , B 1 and peripheral connectors from B 2 have the required witnesses in D 0 ; (ii) the sizes of B 0 , B 1 , B 3 and the number of peripheral connectors are bounded exponentially in |τ |; (iii) all pairs of elements from B 0 ∪ B 1 are r 1 -connected in D 0 .What remains is to decrease the size of B 2 (which at this moment is unbounded), provide any remaining witnesses, and make the whole class r 1 -connected.
Consider a path P ab of the form a = c 1 , c 2 , . . ., c l−1 , c l = b chosen in Step 3. Repeat the following procedure as long as possible: if for some i, j, 3 ≤ i < j ≤ l − 2 such that the 1-types of c i and c j are identical, c i−1 does not belong to the preintersection of c i , and c j−1 does not belong to the pre-intersection of c j then remove elements c i , . . ., c j−1 from P ab and make the connection between c i−1 and c j equal to the connection between c i−1 and c i (note that this connection must contain an r 1edge; thus after this cut, P ab remains an r 1 -path).Since the sizes of pre-intersections and the number of 1-types are bounded exponentially, the length of the final version of P ab is also exponentially bounded.Perform the above process for all paths P ab chosen in Step 3. Let B 2 contain only pre-intersections of elements from the paths P ab so shortened.The size of B 0 ∪ B 1 ∪ B 2 ∪ B 3 is now exponentially bounded.
For any element a from B 2 ∪ B 3 which is not a peripheral connector, modify its connections to B 0 in such a way that witnesses for a required by the ∀∃-conjuncts of ϕ i can be found in B 0 .This is possible due to our choice of B 0 in Step 1, since a may require at most m witnesses.We remark that the special treatment of peripheral connectors is important here: they differ from the remaining elements of B 2 ∪ B 3 in that their connections to some elements from B 0 could earlier have been fixed to contain r 1 -edges.Note in addition that an element may be a peripheral connector of many chosen paths.Denote the resulting structure (over domain We claim that D has the required properties.Indeed, |B 0 ∪ B 1 ∪ B 2 ∪ B 3 | is exponentially bounded in |τ |, as explained.Furthermore, all 2-types occurring in D occur in D, and we took care to provide all required witnesses, whence D |= ϕ 1 .The r 1 -connectivity of D now follows from the fact that r 1 -paths connect all pairs of elements from B 0 ∪ B 1 and each of the remaining elements is r 1 -connected to some element in its pre-intersection satisfying K in 1 or K out 1 which further must have a witness in B 0 connected to it by a direct r 1 -edge (cf.Remarks after Definition 2.1).
Let g : ∆ → N be the function such that D ≈ g 1 .It remains to see that f 1 g.Since we built D using only pre-intersections from D and we did not change the connections inside pre-intersections it is clear that for all δ ∈ ∆ we have f (δ) ≥ g(δ).Consider δ such that f (δ) > g(δ).We must show that δ 1 g.Let α be realized in δ.In Step 1 we choose a pre-intersection containing α and make it a member of B 0 which later becomes a fragment of D .Thus α is realized by g, and condition (i) of Definition 4.1 is satisfied.Consider now any α realized by δ and any α realized by g.Let I 2 be a pre-intersection of D which contains an element a of type α .By our construction I 2 is also a pre-intersection of D. Let I 1 be a pre-intersection of type δ in D different from I 2 (we can choose such I 1 even if I 2 is of type δ since we know that f (δ) > g(δ)).The type tp D (a, a ) can be choosen as β from condition (ii).The argument for condition (iii) is similar to the one given in the proof of Fact 2.
Having obtained the function g in Lemma 4.4, we can present a method of converting functions f : ∆ → N * to functions f i : ∆ → M .Definition 4.5.Let f : ∆ → {0, . . ., M } be a function and i ∈ {1, 2}.Define f i : ∆ → M as follows: Note that the values of f i are indeed in M : in particular, by Fact 2, f i cannot return = k for k > 1.
Proof.Follows directly from definitions.

5.
From logic to graphs.We now present a reduction of the (finite) satisfiability problem for normal-form GFEC 2  2 -formulas to the problem (finite) BGE * , running in time bounded by a doubly-exponential function of ϕ .The reduction employs some nondeterministic guesses, but all of them are of size exponential in |τ |.This ensures that the eventual decision procedure runs in deterministic doubly-exponential time.
Let the normal-form GFEC 2 2 -formula ϕ, with signature τ , be given.Let the set of pre-intersections ∆ be as defined in Sec. 4 and let M = g(|τ |), where g is the function given in Lemma 4.4.Note that |∆| is doubly exponentially bounded as a function of ϕ .We proceed to construct a subset ∆ 0 ⊆ ∆ and sets P , Q of functions mapping ∆ to M .Together with ∆ and M , these will form a (finite) BGE * -instance giving us the desired reduction.
(iv) For each α ∈ α guess a pre-intersection type δ α ∈ ∆ such that α is realized in δ α and δ α realizes only 1-types from α; let ∆ 0 = {δ α : α ∈ α}.|) and there is a structure D |= ϕ 1 such that D ≈ g 1 .By step (v) of the reduction procedure P contains g 1 .By Fact 3 we have that f realizes g 1 .(G3) follows analogously.⇐ In the opposite direction consider a (finite) solution H = (U, V, E ∆ ) of an instance (∆, ∆ 0 , M, P, Q) of BGE * constructed by our procedure, with α being the guess in step (i).We show how to construct a (finite) model A |= ϕ from the graph H.However, first we construct an auxiliary structure A satisfying conditions (i)-(iii) of Fact 1, i.e., a structure satisfying all conjuncts of ϕ except possibly conjuncts from ϕ f ree .Intersections of A correspond to the edges of H: for each δ ∈ ∆ and each e ∈ E δ , we put into A a pre-intersection I e of type δ.Property (G1) of Definition 3.3 ensures that A satisfies all ∃-conjuncts, i.e. condition (i) of Fact 1 holds.Moreover, the fact that all intersections have types from ∆ ensures condition (ii).Consider now any vertex u ∈ U .Let U be the set of all pre-intersections corresponding to the edges incident to u.Our task is to compose from them an r # 1 -class D u satisfying ϕ 1 .Writing f for ord H u , let p ∈ P be a function which is realized by f , guaranteed by (G2).First, we form from some subset of U a class D ≈ p 1 such that D |= ϕ 1 .This is possible by the construction of P in step (v).Note that f 1 p.Indeed, if for some f (δ) > p(δ) then p(δ) = ≥ k for some k ∈ N and by Definition 4.5 we have δ 1 p.Thus, by Lemma 4.3, all the remaining intersections of U can be joined to D, forming the desired D u .We repeat this construction for all vertices in U .This ensures that every pre-intersection is r 1 -connected and that condition (iii) of Fact 1 holds for i = 1.
Similarly, from any vertex v ∈ V , we form a r # 2 -class consisting of all preintersections corresponding to edges incident on v, using (G3) and the construction of Q.This step ensures condition (iii) for i = 2 and makes every pre-intersection r 2connected.Thus, all pre-intersections become both r 1 -and r 2 -connected; moreover, no two pre-intersections can be connected to each other by both r 1 and r 2 (because no two edges of H can have common vertices in both U and V ); hence, every preintersection becomes an intersection of A, as required.
At this point, we have specified the 2-type in A of any pair of elements which belong to the same r # 1 -or r # 2 -class.To complete the definition of A, for any pair of elements which do not share an r # 1 -nor r # 2 class join them by the unique compatible 2-type which does not contain any positive binary literals.Note that each 2-type in A either does not contain any positive binary literals or has been copied from a structure which satisfied ϕ univ .This ensures that A |= ϕ univ .Now we take care of the ∀∃-conjuncts from ϕ f ree using a circular witnessing pattern known from [4].Let m be the number of formulas of type ∀∃ in ϕ f ree .We build A out of 3m disjoint copies of A which are logically divided into three groups X 0 , X 1 , X 2 consisting of m copies each.This guarantees that in each group every 1-type from α is realized at least m times.Now, for every element a ∈ X i (i = 0, 1, 2) and every conjunct from ϕ f ree of the form ∀x(γ(x) → ∃y(η(x, y) ∧ x = y ∧ ψ(x, y))), if the 1-type of a is α, and α(x) |= γ(x) then let α and β be as guaranteed by step (iii) of the procedure.By step (iv) α is realized in A. Take a fresh copy b of such a realisation from X i+1 mod 3 and set tp A (a, b) = β.As in X i+1 mod 3 each necessary 1-type is realized at least m types every element from X i can choose its witnesses without conflicts.All 2-types in A which have not been fixed yet are set in such a way that they contain no positive binary literals.One can see that A satisfies all conditions of Fact 1, hence A |= ϕ.
Definition 4.1, find an element a ∈ D realizing the same 1-type α.For each b ∈ D, b = a set tp D (a, b) := tp D (a , b).
(v) Start with P = ∅.Generate all r # 1 -classes D consisting of at most M = g(|τ |) pre-intersections of types from ∆ realizing only 1-types from α; if D |= ϕ 1 ,then take f such that D ≈ f 1 , and add to P the function f 1 .(vi) Construct Q analogously, adding to Q the function f 2 .Proposition 5.1.ϕ is (finitely) satisfiable iff for some guesses of α in (i) and ∆ 0 in (iv), the run of the above reduction procedure produces a positive instance (∆, ∆ 0 , M, P, Q) of (finite) BGE * .Proof.⇒ Let A be a (finite) model of ϕ with intersections bounded by f(|τ |) as guaranteed by Lemma 2.4, and recall that M = g(|τ |).In step (i) guess α to be the set of 1-types realized in A. Steps (ii) and (iii) are then clearly successful.Also, by definition of ∆ all pre-intersection types realized in A are members of ∆.In step (iv), for each α ∈ α choose δ α to be a type of an arbitrary pre-intersection I from A containing a realisation of α; this defines ∆ 0 .We claim that (∆, ∆ 0 , M, P, Q), where P and Q are generated in steps (v) and (vi), has a (finite) solution.To construct a solution H = (U, V, E ∆ ) define U to be the set of r # 1 -classes and V to be the set of r # 2 -classes of A, and for each δ ∈ ∆ add (D, D ) to E δ iff D and D have a common intersection of type δ.Condition (G1) of Definition 3.3 is obviously satisfied.Consider condition (G2).Let D ∈ U .We know that D |= ϕ 1 .Denote f = ord H D .We want to see that f realizes a function from P .Note that D ≈ f 1 .By Lemma 4.4 there exists g such that f 1 g, |g| ≤ g(|τ