On the Scope of the Universal-Algebraic Approach to Constraint Satisfaction

The universal-algebraic approach has proved a powerful tool in the study of the computational complexity of constraint satisfaction problems (CSPs). This approach has previously been applied to the study of CSPs with finite or (infinite) omega-categorical templates. Our first result is an exact characterization of those CSPs that can be formulated with (a finite or) an omega-categorical template. The universal-algebraic approach relies on the fact that in finite or omega-categorical structures A, a relation is primitive positive definable if and only if it is preserved by the polymorphisms of A. In this paper, we present results that can be used to study the computational complexity of CSPs with arbitrary infinite templates. Specifically, we prove that every CSP can be formulated with a template A such that a relation is primitive positive definable in A if and only if it is first-order definable on A and preserved by the infinitary polymorphisms of A. We present applications of our general results to the description and analysis of the computational complexity of CSPs. In particular, we present a polymorphism-based description of those CSPs that are first-order definable (and therefore can be solved in polynomial-time), and give general hardness criteria based on the absence of polymorphisms that depend on more than one argument.

Abstract. The universal-algebraic approach has proved a powerful tool in the study of the computational complexity of constraint satisfaction problems (CSPs). This approach has previously been applied to the study of CSPs with finite or (infinite) ω-categorical templates, and relies on two facts. The first is that in finite or ω-categorical structures A, a relation is primitive positive definable if and only if it is preserved by the polymorphisms of A. The second is that every finite or ω-categorical structure is homomorphically equivalent to a core structure.
In this paper, we present generalizations of these facts to infinite structures that are not necessarily ω-categorical. Specifically, we prove that every CSP can be formulated with a template A such that a relation is primitive positive definable in A if and only if it is firstorder definable in A and preserved by the infinitary polymorphisms of A. Using existential positive closure we rederive and extend known results about cores, presenting the new notions of core theories (models of which will be cores) and core companions (which are defined analogously to model companions in model theory). We prove a uniqueness result for core companions that yields the uniqueness of model-complete cores of ω-categorical structures. Existential positive closure is also the crucial concept to give an exact characterization of those CSPs that can be formulated with (a finite or) an ω-categorical template.
Finally, we present applications of our general results to the description and analysis of the computational complexity of CSPs. In particular, we give general hardness criteria based on the absence of polymorphisms that depend on more than one argument, and we present a polymorphism-based description of those CSPs that are first-order definable (and therefore can be solved in polynomial time).

Introduction
For a relational structure A over a finite signature the constraint satisfaction problem CSP(A) is the computational problem to decide whether a primitive positive first-order sentence ϕ -that is, the existential quantification of a conjunction of atomic formulasis true on A. The case where the template A is finite has been extensively studied in the literature, and is known to comprise a significant microcosm of the complexity class NP (see, e.g., [24]). The universal-algebraic approach, of studying the invariance properties of relations under the action of polymorphisms, has been particularly powerful in the complexity analysis of finite-domain CSPs (see [23] as a starting point). This approach has also been successfully used in infinite-domain CSPs where the template is ω-categorical, i.e., is the unique countably infinite model of its first-order (fo) theory up to isomorphism -see, e.g., [10].
Many interesting problems can be formulated as infinite CSPs whose template is not ω-categorical. To illustrate the wealth of the class of CSPs studied in this paper, we present three concrete computational problems that can be formulated as CSP(A), for an infinite A.
Each of these problems is solvable in polynomial time -and the proofs of this are generally non-trivial. The templates (Z; +, 1) and (R; +, 1), where + is read as the ternary relation x + y = z, correspond to the solving of Linear Diophantine Equations and Linear Real Equations, respectively. Another template of interest relates to the Unification Problem. Let σ := (f 1 , f 2 , . . .) be a functional signature, we form the template (T ; F 1 , F 2 , . . .), where T is the term algebra on σ built over a countably infinite set of variables, and each F i is the relational form f i (t 1 , . . . , t r i ) = t 0 of f i over T .
Primitive positive definability of formulas. A central role is played in CSPs by the notion of primitive positive (pp) definability. Two templates give rise to the same CSP iff they agree on all pp-sentences (have the same pp-theory). A less central, but often equivalent role is played by existential positive (ep) definability. For example, two templates have the same pp-theory iff they have the same ep-theory. If A pp are the relations pp-definable on A, then A pp ⊆ A ′ pp implies that there is a polynomial time reduction from CSP(A ′ ) to CSP(A). In the case that A is finite or ω-categorical, the set of relations A pp are precisely those that are invariant under the polymorphisms of A -Inv(Pol(A)). We note that this relationship holds on some infinite structures which are not ω-categorical (an example is given in [29], also the natural numbers with the binary successor relation may easily be verified to have this property). In general, a CSP can not be formulated with (a finite or) an ω-categorical template (we return to this below). However, we are able to prove the existence of an equivalent template -with the same pp-theory -which enjoys some of the benign properties of finiteness or ω-categoricity. Given any A, we prove the existence of a highly saturated elementary extension M such that a relation is pp-definable on M iff it is fo-definable on M and invariant under the polymorphisms of (countably) infinite arity of M. In fact, we prove that this relationship holds for all saturated structures of cardinality at least 2 ω . But our construction obviates the need for the set-theoretic assumptions usually required to assert the existence of a saturated elementary extension of an arbitrary structure. However, in many concrete cases, such as for structures that are uncountably categorical, such saturated models arise directly. We go on to prove that each of the three assumptions -high saturation, infinitary (and not finitary) polymorphism and fo-intersection -is necessary. That is, we exhibit structures for which any two of these is insufficient for the respective connection. Existential-positively closed models. We use existential-positively closed (epc) models to easily rederive and extend known results in the literature from [3]. In the case of finitedomain structures there is the well-established notion of core -a structure, homomorphically equivalent to the original, all of whose endomorphisms are embeddings (equivalently, in the finite, automorphisms). The core is unique up to isomorphism, and the task of problem classification is simplified as one may restrict attention to cores. For ω-categorical structures we no longer have uniqueness of cores in general, but it was shown in [3] that every ω-categorical structure is homomorphically equivalent to a model-complete core, i.e. to a structure whose endomorphisms preserve all first-order formulas, that is unique up to isomorphism and again ω-categorical. We present a new proof here, on the way introducing the concepts of core theories, models of which will be cores, and core companions. If an ep-theory S is contained in a model-complete core theory T -with the same existential positive and universal negative restriction -which will be called the core companion of S, then T is unique up to equivalence of theories. In the special case of ω-categorical structures, this yields the uniqueness result for model-complete cores. We give a necessary and sufficient condition as to when CSP(A) can be formulated with a template which has a model-complete core theory, based on whether the class of epc models of a restricted part of A's ∀∃-theory is axiomatizable.
When distinct templates give rise to the same CSP, it might be the case that one is better behaved than another. For example, (Z; <) and (Q; <) share the same ep-theory (pp-theory); yet while Inv(Pol(Z; <)) = (Z; <) pp , we have Inv(Pol(Q; <)) = (Q; <) pp , as (Q; <) is ω-categorical. In the present paper we give a necessary and sufficient condition that a template A has an equivalent A ′ that is finite or ω-categorical -and consequently satisfies Inv(Pol(A ′ )) = A ′ pp . The condition is that the number of maximal ep-n-types consistent with the theory of A is finite, for all n. It follows that none of the three examples of the previous page may be formulated with an ω-categorical template. Our result uses epc models and the direct limit construction.
Applications. We go on to consider the repercussions of our restricted relationship for the complexity of CSPs. Firstly, we show that existential positive (ep) and pp-definability coincide on a structure A iff all ω-polymorphisms of all elementary extensions of A are essentially unary. We demonstrate that the move to elementary extensions is necessary by giving a structure whose ω-polymorphisms include only projections but for which (x = y ∨ u = v) is not pp-definable. Using the notion of local refutability in [6], we note that if a structure A is not locally refutable, and all ω-polymorphisms of all elementary extensions of A are essentially unary, then CSP(A) is NP-hard.
Secondly, and introducing our philosophy to the work of [26], we present a polymorphism based description of those CSPs that are fo-definable. We show that CSP(A) is fo-definable if and only if A has an elementary extension which has a 1-tolerant polymorphism. It follows that such CSPs are polynomial-time solvable.
Thirdly, we recall a known relationship between certain binary injective polymorphisms and Horn definability (given in the context of ω-categorical structures in [4]). Considering as a polymorphism an embedding e of (R; +, 1) 2 into (R; +, 1), we show that the recent complexity classification of [8] may be given a natural algebraic specification. The presence of the polymorphism e separates those fo-expansions of (R; +, 1) whose CSP is in P from those whose CSP is NP-complete. Thus we demonstrate that the presence of certain polymorphisms can delineate complexity even outside of the realm of ω-categoricity.
Related work. There are several extant works on notions of pp-definability over infinite structures, including those involving infinitary polymorphisms and infinitary relations [34,27,30]. Relational operations transcending normal pp-definitions are usually permitted, such as: infinite conjunction, infinite projection and various forms of monotone disjunction. In order for our results to be applicable to the (finite!) instances of CSPs, we are not able to sacrifice anything on the relational side, and so pp-definability must remain in its most basic form. This represents the principle difference between our work and those that have come before. We note that this is the first time that infinitary polymorphisms have been considered in connection with the complexity of CSPs.
An extended abstract of this paper appeared at conference as [7]. Section 4.2, as well as many previously omitted proofs, appear here for the first time.

Preliminaries
2.1. Models, operations and theories. A relational signature (with constants) τ is a set of relation symbols R i , each of which has an associated finite arity k i , and constants c i . We consider only relational signatures (with constants) in this paper. A (relational) structure A over the signature τ (also called τ -structure) consists of a set A (the domain) together with a relation R A ⊆ A k for each relation symbol R of arity k from τ and a constant c A ∈ A for each constant symbol c.
Let A be a τ -structure, and let A ′ be a τ ′ -structure with τ ⊆ τ ′ . If A and A ′ have the same domain and R A = R A ′ , c A = c A ′ for all R, c ∈ τ , then A is called the τ -reduct (or simply reduct) of A ′ , and A ′ is called a τ ′ -expansion (or simply expansion) of A. If A is a τ -structure and a α α<β is a sequence of elements of A, then (A; a α α<β ) is the natural τ ∪ {c α : α < β}-expansion of A with β new constants, where c α is interpreted by a α . A is an extension of B, denoted B ⊆ A, if B ⊆ A and for each R in τ , and for all tuples b from B, b ∈ R B iff b ∈ R A , and for each c in τ , c B = c A . Let b α α<|B| well-order the elements of B. A is an elementary extension of B, denoted B A, if it is an extension and, for each first-order (fo) τ ∪ {c α : α < |B|}-sentence ϕ, An fo-formula is existential positive (ep) if it involves only existential quantification, conjunction and disjunction (no negation). Furthermore, if it involves no instances of disjunction, then it is termed primitive positive (pp). Note that we consider the boolean false ⊥ to be a pp-formula, and we always allow equalities in pp-formulas. Dual to ep are universal negative formulas, involving only universal quantification, conjunction and disjunction, with all atoms negated. Suppose A is a finite structure over a finite signature with domain A := {a 1 , . . . , a s }. Let θ(x 1 , . . . , x s ) be the conjunction of the positive facts of A, where the variables x 1 , . . . , x s correspond to the elements a 1 , . . . , a s . That is, R(x λ 1 , . . . , x λ k ) appears as an atom in θ iff (a λ 1 , . . . , a λ k ) ∈ R A . Define the canonical query ϕ[A] of A to be the pp-formula ∃x 1 . . . x s .θ(x 1 , . . . , x s ). A set of formulas Φ := Φ(x 1 , . . . , x n ) with free variables x 1 , . . . , x n is called satisfiable in A if there are elements a 1 , . . . , a n from A such that for all sentences ϕ ∈ Φ we have A |= ϕ(a 1 , . . . , a n ). We say that Φ is satisfiable if there exists a structure A such that Φ is satisfiable in A.
A τ -theory is a set of τ -sentences; two theories are equivalent if they share the same models. For a τ -structure A, define the theory of A, Th(A), to be the set of τ -sentences true on A. Note that A B implies that Th(A) = Th(B). Define Th ∀ − (A) to be the set of universal negative sentences true on A.
For n ≥ 0, an n-type of a theory T is a set p := p(x 1 , . . . , x n ) of formulas in the free variables x 1 , . . . , x n such that p ∪ T is satisfiable. In a similar manner, a primitive positive n-type (pp-n-type) of a theory T is a set of pp-formulas such that p ∪ T is satisfiable. A pp-n-type p of T is maximal if T ∪ p ∪ ϕ(x 1 , . . . , x n ) is unsatisfiable for any pp-formula ϕ / ∈ T ∪ p. A (pp-) n-type of a structure A is just a (pp-) n-type of the theory Th(A). We define (maximal) ep-n-types in exactly the like fashion, with ep-formulas. A complete ep-n-type of a structure A is the set of all ep-formulas holding on some tuple from A. An n-type p( For an infinite cardinal κ, a structure A is κ-saturated if, for all β < κ and expansions (A; a α α<β ) of A, every 1-type of (A; a α α<β ) is realized in (A; a α α<β ). We say that an infinite A is saturated when it is |A|-saturated. Realization of pp-(ep-)types and pp-(ep-)(κ-)saturation is defined in exactly the analogous way. Note that a structure that is κ-saturated is a fortiori ep-κ-saturated. (Ep-κ-saturation and pp-κ-saturation in fact coincide, though we will only need to apply the trivial direction of this relationship.) A theory T is said to be κ-categorical, for some cardinal κ, if it has a unique model of cardinality κ, up to isomorphism. It is known that, if T is κ-categorical for one uncountable cardinal κ, then T is κ ′ -categorical for all uncountable cardinals κ ′ . A structure A, of cardinality κ, is said to be κ-categorical if Th(A) is κ-categorical.
Let A and B be τ -structures. A homomorphism from A to B is a function f from A to B such that for each k-ary relation symbol R in τ and each k-tuple (a 1 , . . . , a k ), if (a 1 , . . . , a k ) ∈ R A , then (f (a 1 ), . . . , f (a k )) ∈ R B . Also, for each constant c in τ , f (c A ) = c B . In this case we say that the map f preserves the relation R. Injective homomorphisms that also preserve the complement of each relation are called embeddings. Surjective embeddings are called isomorphisms; homomorphisms and isomorphisms from A to itself are called endomorphisms and automorphisms, respectively. An elementary embedding is an embedding that preserves all fo-formulas. A structure is a core if all its endomorphisms are embeddings [3] (in the finite this coincides with the more usual definition of all endomorphisms being automorphisms). B is a core of A if B is a core and A and B are homomorphically equivalent. We will make use later of the following lemma, a close relative of Theorem 10.3.1 in [21]. Lemma 2.1. Let A and B be τ -structures, where B is pp-|A|-saturated. Suppose f is a mapping from {a α : α < µ} ⊆ A (µ < |A|) to B such that all pp-(τ ∪ {c α : α < µ})sentences true on (A; a α α<µ ) are true on (B; f (a α ) α<µ ). Then f can be extended to a homomorphism from A to B.
Proof. Note that, if B is finite, then B is pp-|A|-saturated no matter what cardinality A is.

(Inductive
Step. Successor ordinals.) β := γ + 1 < κ A . Set . By compactness, since Σ is closed under conjunction, we have that Σ is a pp-1-type of (B; b ′ α α<γ ). By pp-|A|-saturation of B it is realized by some element b ′ γ ∈ B. By construction we maintain that all pp-(τ ∪ {c α : α < γ + 1})-sentences true on (A; a ′ α α<γ+1 ) are true on (B; b ′ α α<γ+1 ). The previous lemma, as so often in this paper, holds equally for ep, in place of pp. However, we will want to apply it later to specifically the primitive positive. As a rule, we choose ep over pp in all cases where either could be used without affecting the exposition.
Let A fo (respectively, A ep and A pp ) be the sets of relations, over domain A, that are fo-(respectively, ep-and pp-) definable over A (without parameters). Let Aut(A) and End(A) be the sets of automorphisms and endomorphisms, respectively, of A. A κpolymorphism of A is a homomorphism from A κ to A, where the power is with respect to the direct product already defined. Let Pol ∞ (A), Pol ω (A) and Pol(A) be the sets of κ-polymorphisms (for any κ), κ-polymorphisms (for κ ≤ ω) and k-polymorphisms (for each finite k), respectively. For a set of operations F on domain A, define Inv(F ) to be the set of relations, over A, that are preserved by (invariant under) each of the operations in F (note that the condition of preservation of an m-ary relation by a κ-ary function f : A κ → A is component-wise, i.e. if (a β 1 , . . . , a β m ) ∈ R A , for all β < κ, then (f ( a β 1 β<κ ), . . . , f ( a β m β<κ )) ∈ R A ). Let t be a k-tuple of elements from a structure A. Then the orbit of t under Aut(A) is the set {f (t) | f ∈ Aut(A)}.
Theorem 2.2 (Ryll-Nardzewski, Engeler, Svenonius; see e.g. [21]). A countable relational structure A is ω-categorical if and only if the automorphism group of A has for each k finitely many orbits of k-tuples.
It is a well-known consequence of the proof of Theorem 2.2, as presented for instance in [21], that A is ω-categorical if and only if Inv(Aut(A)) = A fo (see, e.g., [2]). One direction persists in the realm of the primitive positive, as attested to by the following. [19,12,11]). When A is finite or ω-categorical, Inv(Pol(A)) = A pp .
2.2. The constraint satisfaction problem. For a relational structure A over a finite signature, CSP(A) is the computational problem to decide whether a given pp-sentence is true in A. Proof of the following is straightforward (see, e.g., [23]). Proposition 2.4. For A and A ′ with the same domain, such that A pp ⊆ A ′ pp , we have that CSP(A) is polynomial time many-to-one reducible to CSP(A ′ ).
We remark that this result holds for logspace reductions, though this is harder to see and requires the celebrated result of [28]. In light of this observation, together with Theorem 2.3, we may use the sets Pol(A) to classify the computational complexity of CSP(A), and a most successful research program has run in this direction (see [23,13,14], and [17] for a survey).
Sets of the form Pol(A) are always clones (for definitions, see [35]), and the machinery of Clone Theory can be brought to bear on the classification program for CSPs (e.g., the tame congruence theory from [20] as laid out in [16]). It often transpires that instances of the CSP with low complexity can be explained by the presence of certain polymorphisms on the template. When A is finite, the class of problems CSP(A) is conjectured to display complexity dichotomy between those problems that are in P and those that are NP-complete (a remarkable property given the breadth of CSP problems together with the result of Ladner that NP itself does not possess the dichotomy, so long as P =NP [25]). While the dichotomy conjecture was formulated independently of the algebraic method [18], a conjecture as to exactly where the boundary sits was given in the algebraic language [15].
In the case where A is infinite but ω-categorical, the connection of Theorem 2.3 has been used to good effect in the complexity classification of, e.g., temporal CSPs in [10]. In that case a dichotomy between P and NP-complete was again observed. For ω-categorical templates in general, it is known that there are structures whose CSP is undecidable [5] and of various complexities [5] (even coNP-complete). While the algebraic machinery has proved very powerful in the finite and ω-categorical cases, for infinite templates that are not ω-categorical, no such technology has thus far been developed.

Primitive positive definability of formulas
To show hardness of CSP(A), we often try to prove that there is a finite signature reduct A ′ of A pp such that CSP(A ′ ) is NP-hard. An important set of relations that contains the set of all pp-definable relations A pp is the set of all fo-definable relations A fo . For every structure A of cardinality greater than one there are fo-definable relations yielding an NP-hard CSP, and these relations are usually good candidates for proving hardness (e.g.
. Therefore, it is natural and important to understand which fo-definable relations are pp-definable in A.

Equivalent templates.
In this section we show that, for every problem CSP(A), we can find a relational structure M for which CSP(A) = CSP(M) where infinitary polymorphisms exactly characterize pp-definability of fo-definable relations. We will do this by building a model of Th(A) that is highly saturated. The most natural of structures with the homomorphism lifting property are those that are of large cardinality and saturated. Proof. This follows immediately from Lemma 2.1, since |M ω | ≤ |M |.
We remark that the continuum has the property of Lemma 3.2 -that is 2 ω = (2 ω ) ω . On the assumption of the continuum hypothesis, we could simply work with large saturated structures; because then, given an infinite model A, we can assume the existence of an elementary extension M that is of cardinality 2 ω and saturated [22]. Without such a settheoretic assumption, we can still construct a rather unwieldy model as follows.
A that is ω-saturated and has the homomorphism lifting property.
Proof. We will build M by transfinite induction, as the union of a chain of length ℵ 1 . Set M 0 := A. For successor ordinals γ + 1, we take an elementary extension M γ+1 M γ that is |M γ | ω -saturated (such always exists, see Corollary 8.2.2 [22]). For limit ordinals λ, set M is ω-saturated by construction. It remains to prove that M has the homomorphism lifting property. Consider the b 1 , . . . , b k ∈ M and a 1 , . . . , a k ∈ M ω . The set of coordinates (of M ) involved here, Let f −1 be the partial map from M ω to M sending a 1 , . . . , a k to b 1 , . . . , b k (well-defined as all equalities are pp). We first argue that all pp-(τ ∪ {c 1 , . . . , c k })-sentences true in (M µ ω ; a 1 , . . . , a k ) are true in (M µ+1 ; f −1 (a 1 ), . . . , f −1 (a k )). Let ϕ be such a sentence. Then: We will now proceed with a transfinite induction up to ℵ 1 . For successor ordinals, γ +1, suppose that we have a homomorphism f γ : M µ+γ ω → M µ+γ+1 . We will build a homo- be such a sentence, we give the derivation again: Finally, we arrive at the homomorphism f ℵ 1 : M ω → M, which has the desired property.
We describe the model built as in the previous lemma as a monster model (this term is used with different connotation in set theory and model theory).
Let A pp∞ be the set of relations pp-definable on A, possibly involving infinitary conjunction (of pp-formulas in a finite number of free variables). Because we will use it again later, we give the following lemma in its strongest form.
Proof. We argue by induction on the term-complexity of the formula. Let f : Step.) There are two subcases. In the following, suppose v is an m-tuple. Let a β β<α , be a sequence of m-tuples from A such that A |= ϕ(a β ), for all β. ( for each β < α. Then for each µ < γ and β < α we have A |= ψ µ (a β ). By inductive hypothesis, we have each A |= ψ µ (f ( a β β<α )). The result A |= ϕ(f ( a β β<α )) follows.
We are now ready for the main result of this section.
Theorem 3.5. Let A be a structure, over a countable 1 signature, that is ω-saturated and has the homomorphism lifting property. Then a fo-definable relation R is preserved by the ω-polymorphisms of A if and only if R is pp-definable in A, i.e.
Proof. (Backwards.) That pp-formulas are preserved by ω-polymorphisms in any structure is a special case of Lemma 3.4.
(Forwards.) Suppose that R is a k-ary relation that is preserved by all ω-polymorphisms of A and that has a first-order definition ϕ in A. Let if such elements do not exist there is nothing to show. Let U be the set of all pp-τ -formulas θ(x 1 , . . . , x k ) such that A |= ¬θ(b 1 , . . . , b k ). U contains ⊥, ⊥ ∧ ⊥ etc., and so we may assume U to be countably infinite. Let (θ i ) i<ω be an enumeration of U . We claim that for every θ i ∈ U there exists a k-tuple a θ i : . , x k ), and we derive θ i ∈ Ψ and the consequent contradiction A |= θ i (b 1 , . . . , b k ). 1 The restriction to countable signatures allows us to consider polymorphisms of at most arity ω. Were we to consider signatures of infinite cardinality α then the theorem would hold with polymorphisms of arity α (under a slightly different definition of the homomorphism lifting property involving α in the exponent).
Consider the k-tuple a := i<ω a θ i in A ω . Observe that every pp-τ -formula To see this, suppose that A |= ¬χ(b 1 , . . . , b k ). Therefore χ ∈ U , and by choice of a χ we have A |= ¬χ(a χ ). But then A ω |= ¬χ(a). Now, we have just shown that all pp-(τ ∪ {c 1 , . . . , c k })-sentences that hold on (A ω ; a) also hold on (A; b 1 , . . . , b k ). Since A has the homomorphism lifting property, the existence of a homomorphism f : (A ω ; a) → (A; b 1 , . . . , b k ) follows from our definitions. But f is an ω-polymorphism of A, which preserves ϕ, and hence we derive It remains to be shown that Ψ is equivalent on A to a single pp-formula. Note that . , x k ) by construction, the result follows. In the parlance of [27], the following may be seen as the "global" analog of Theorem 3.5.
Proof. It is well-known that uncountable models of uncountably categorical theories are saturated in their own cardinality (Fact 1.2. in [36]). Hence, the statement follows from Lemma 3.2 and Theorem 3.5.
3.2. Tightness of Theorem 3.5. One might be interested in the following potential strengthenings of Theorem 3.5.
(1) To derive the statement for arbitrary relations (not just for fo-definable relations).
(3) To show the statement for arbitrary models of Th(A) (not just for structures with the homomorphism lifting property). The following proposition shows that each of these assumptions is necessary.
(1) There is a saturated structure A sat of cardinality 2 ω such that Inv(Pol ω (A sat )) = A sat pp .
(2) There is a saturated structure A sat of cardinality 2 ω such that Inv( Proof. Necessity of intersection with fo. Let us consider the model A =: (Q; +, 1, (u = v ∨ x = y)). By Lemma 5.3, the infinitary polymorphisms of this structure are equivalent to its endomorphisms, and, in the presence of a fixed 1, it can easily be seen that its only endomorphism is the identity (indeed, there is a pp-definition of each of the rationals from 1 and +). It follows that all subsets of Q are in Inv(Pol ω (A)), yet A pp must be countable. Of course, A is neither saturated nor of cardinality 2 ω . But the continuum of subsets of Q will remain Inv-Pol ω in a saturated model of Th(A) of such cardinality (a copy of A sits elementary in all models of its theory). The existence of a saturated model of Th(A) of cardinality 2 ω follows from this theory's strong minimality (Fact 1.2. in [36]).
Necessity of infinitary polymorphisms. Let {U i : i ∈ ω} be a set of unary relations. Consider the model A := (N; U i : i ∈ ω), involving a countable set of unary relations, defined by U i := N \ {0, i}. Diagrammatically, It is straightforward to verify that P is closed under the finitary polymorphisms of A and is not pp-definable over A. Note that P is not preserved under the infinitary polymorphism f : N ω → N of A defined by f (w) = 0, if w contains all elements of N \ {0}, and f (w) = w 0 (the first element of the sequence w), otherwise. Again, these properties will remain if we move to a saturated model A sat of cardinality 2 ω (such a model will simply be A augmented with a continuum of elements for which all of the relations {U i : i ∈ ω} hold). We now detail a finite signature variant of the above structure that also serves as a suitable (counter)example. Consider the signature E, R involving two binary relations, edge and red edge. Let the structure A contain It is not hard to verify that P is preserved by the finitary polymorphisms of A, but is not pp-definable over A (as it is not preserved by the ω-polymorphisms of A). The saturated elementary extension of A of cardinality 2 ω contains 2 ω copies of each one of the countably infinite set of paths just described. It remains easy to see that P is preserved by A sat 's finitary but not ω-ary polymorphisms.
Proof. By induction on the term complexity of ϕ.
(Base Cases.) ϕ is an atom. The statement is trivially true if ϕ(x) a 2 ), then only a 1 could be zero. Set ǫ := a 2 /2.
ϕ(x) := ∃y.ψ(y, x). If A |= ϕ(a) holds, then we may choose a b s.t. A |= ψ(b, a). By inductive hypothesis, there exists an appropriate ǫ for ψ(b, a) and this may also be used for ϕ(a).
That x ≤ 0 is not pp-definable is a trivial consequence of the lemma, for suppose it were defined by ϕ(x). Since ϕ(0) holds, we may derive the contradiction that ϕ(ǫ) holds for some ǫ > 0. Note that the first part of the inductive step in the previous lemma would fail for infinite conjunctions. Finally, suppose A sat were a saturated model of Th(A) of cardinality 2 ω . While we have A fo ∩ Inv(Pol ω (A)) = A pp , we must have A sat fo ∩ Inv(Pol ω (A sat )) = A sat pp . We note that x ≤ 0 is not Inv(Pol ω (A sat )).

Existential-positively closed models
In this section, we define existential-positively closed models and demonstrate their applications in constraint satisfaction.

Definitions and basic results.
We begin by stating some basic facts regarding existential-positively closed models. They are the positive analogs of existentially closed models (the latter are treated in great detail in Section 7 of [22], which is Section 8 of [21]), and have been studied under the name of existentially closed models in a recent paper on positive model theory by Ben-Yaacov [1].
Definition 4.1. A model A is existential-positively closed for T -or short epc -iff A |= T and for any homomorphism h from A into another model B of T , any tupleā from A, and any existential positive formula ϕ with B |= ϕ(h(ā)) we have that A |= ϕ(ā).
Note that we could equivalently have used primitive positive formulas in the previous definition. To show the existence of certain epc models we apply the direct limit construction. Definition 4.2. Let τ be a relational signature, and let (A i ) i<κ be a sequence of τ -structures of cardinality ≤ κ such that there are homomorphisms f ij : A i → A j with f jk • f ij = f ik for every i ≤ j ≤ k. Then the direct limit lim i<κ A i (with respect to the homomorphisms f ij ) is the τ -structure A defined as follows. The domain A of A comprises the equivalence classes of the equivalence relation ∼ defined on i<κ A i by setting x i ∼ x j for x i ∈ A i and x j ∈ A j iff there is a k such that f ik (x i ) = f jk (x j ). Let g i : A i → A be the limit homomorphism, i.e. the function that maps a ∈ A i to the equivalence class of a in A. For R ∈ τ , define A |= R(ā) iff there is a k andb ∈ A k such that A k |= R(b) andā = g k (b). Note that limit homomorphisms behave well with respect to their homomorphism family (i.e. g i = g j • f ij ).
The direct limits defined above can be seen as a positive variant of the basic model-theoretic notion of a union of chains (see Section 2.4 in [21]); we essentially replace embeddings in chains by homomorphisms. Unions of chains preserve ∀∃-sentences; the analogous statement for direct limits is as follows. A sentence is called ∀∃ + if it is a universally quantified positive boolean combination of existential positive formulas and negated atomic formulas. We could have equivalently defined ∀∃ + -formulas as conjunctions of universally quantified disjunctions of primitive positive formulas and negated atomic formulas. It is easy to see that every ∀∃ + -formula can be re-written into such a formula.  Proof. Suppose that A = lim α<κ A α for a sequence (A α ) α<κ of models that are epc for T ,ā is a tuple from A, ϕ an ep-formula, and h is a homomorphism from A into another model of T such that B |= ϕ(h(ā)). Then there exists a α < κ such thatā = g α (ā ′ ) forā ′ from A α (where g α is as in the definition of direct limits). Note that h • g α is a homomorphism from A α to B, and since A α is a model epc for T , A α |= ϕ(ā ′ ). Since g α preserves ep-formulas, we thus also have that A |= ϕ(ā). Proposition 4.5 (Essentially from [1]). Let A be a model of cardinality κ of a set T of ∀∃ + sentences. Then there is a homomorphism from A to a model B that is epc for T of cardinality ≤ κ.
Proof. Set B 0 := A. Let i > 0 be a natural number and assume we have already constructed B i−1 of cardinality ≤ κ. Let {(ϕ α ,ā α ) | α < κ} be a (not necessarily injective) enumeration of all pairs (ϕ,ā) where ϕ is existential positive with free variables x 1 , . . . , x n , andā is an n-tuple from B i−1 . We construct a sequence (B α i ) 0≤α<κ of models of T of cardinality ≤ κ and a coherent sequence (f µ,α i ) 0≤µ<α<κ of homomorphisms, where f µ,α i : B µ i → B α i , as follows (coherent in the sense that, for α < β < γ, f α,γ Let B i be lim α<κ B α i (with respect to f µ,α i ) and let g i−1 : B i−1 = B 0 i → B i be the corresponding limit homomorphism.
Let B = lim i<ω B i . By construction, B is of cardinality ≤ κ, and it is a model of T by Proposition 4.3; let h i : B i → B for i < ω be the corresponding homomorphisms.
The structure B is epc for T . To verify this, let g be a homomorphism from B to a model C of T , and suppose that there is a tupleb over B and an existential positive formula ϕ such that C |= ϕ (g(b)). There is an i < ω and anā ∈ B i such that h i (ā) =b. Then g • h i is a homomorphism from B i to C, and by our construction we have that B i+1 |= ϕ(g i (ā)). Note that h i+1 • g i = h i . Thus, since h i+1 preserves existential positive formulas, we also have that B |= ϕ(b), which is what we had to show. Proof. (Forwards.) Suppose p(x 1 , . . . , x n ) is the complete ep-n-type, realized in A by the tuple (a 1 , . . . , a n ). Let c 1 , . . . , c n be new constant symbols that denote a 1 , . . . , a n in A. Let ϕ(x 1 , . . . , x n ) be an existential positive formula such that T ∪ p(c 1 , . . . , c n ) ∪ {ϕ(c 1 , . . . , c n )} has a model (C; b 1 , . . . , b n ). Now, let (C sat ; b 1 , . . . , b n ) be an |A|-saturated model of Th(C; b 1 , . . . , b n ); such a model always exists (see Corollary 8.2.2 [22]). Clearly (C sat ; b 1 , . . . , b n ) is ep-|A|-saturated, and all existential positive formulas that are true on (A; a 1 , . . . , a n ) are true on (C sat ; b 1 , . . . , b n ). By Lemma 2.1, there is a homomorphism h from (A; a 1 , . . . , a n ) to (C sat ; b 1 , . . . , b n ). Now, since ϕ(b 1 , . . . , b n ) holds on C sat and A is epc for T , we find that A |= ϕ(a 1 , . . . , a n ), and conclude that p is a maximal ep-type of T .
(Backwards.) Take B |= T , h : A → B a homomorphism,ā a tuple of elements of A, and ϕ(x 1 , . . . , x n ) an existential positive formula such that B |= ϕ(h(ā)). Let p be the ep-type ofā in A. Since B is a model of T and h preserves all ep-formulas, it follows that T ∪p∪{ϕ} is satisfiable. By maximality of p, we have that ϕ ∈ p, and therefore A |= ϕ(ā).
We conclude this section by noting that epc structures are related to the concept of cores, which play such an important role in the classification program for CSPs when the template is finite or ω-categorical. Proposition 4.7. If A is epc for Th ∀ − (A), then A is a core. If A is ep-saturated (or finite) and expanded by all ep-definable relations, then the converse holds also.
Proof. Suppose A is epc for Th ∀ − (A). Take a homomorphism h : A → A. By epc, for a 1 , . . . , a k in A, if A |= R(h(a 1 ), . . . , h(a k )) or A |= h(a 1 ) = h(a 2 ), then A |= R(a 1 , . . . , a k ) or A |= a 1 = a 2 , respectively. It follows that h is an embedding. Now suppose that A is ep-saturated (or finite) and expanded by all ep-definable relations. Suppose B |= Th ∀ − (A) and h : A → B is a homomorphism. Suppose B |= ϕ(h(ā)), where ϕ(x) is an ep-formula andā is a tuple from A; we must prove that A |= ϕ(ā). Let a α α<|A| well-order A. Consider (B; h(a α ) α<|A| ), by Löwenheim-Skolem there is an elementarily equivalent (B ′ ; h(a α ) α<|A| ) such that B ′ is of cardinality no greater than |A|, there is a homomorphism g : B ′ → A by Lemma 2.1 and ep-saturation of A. Therefore A |= ϕ(g • h(ā)) where g • h is an endomorphism of A, which must be an embedding since A is a core. The result A |= ϕ(ā) follows as A is expanded by all ep-definable relations (note that ep-definable relations are not in general preserved by inverse embeddings, but atomic relations are).
We note that the additional assumption of being expanded by all ep-definable relations was necessary. Let Q + 0 be the set {q ∈ Q : q ≥ 0}. Then (Q + 0 ; <) is a saturated core but is not epc for Th ∀ − (Q + 0 ; <).

4.2.
Core theories. We now introduce the notion of core theories, models of which will be cores. We develop a certain existential-positive model theory, akin to the existential model theory developed in [32,33]. Ultimately this will enable us to give a necessary and sufficient condition as to when a template A has an equivalent B (i.e., s.t. CSP(A) = CSP(B)) such that B is a model-complete core. We need the concept of a diagram of a structure, in various variants. For a model A, let A c be the expansion of A by |A| constants naming the elements of A. Let diag fo (A) denote the elementary diagram of A, that is, the set of all fo-sentences true in the structure A c . The set of all qf-sentences that hold on A c is denoted by diag(A), and the set of all universal negative sentences that hold on A c is denoted by diag ∀ − (A). Finally, diag + (A) denotes the set of all positive qf-sentences that hold on A c .  [22]). Let A and B be τ -structures, and let C be the set of new constants involved in the expansion A c . Then the following are equivalent.
(2) There is a homomorphism from A to B.
We will make use of the following well-known preservation theorems. Theorem 4.9 (Homomorphism Preservation Theorem; see e.g. Exercise 2 in Section 5.5 of [22]). Let T be a fo-theory. A fo-formula ϕ is equivalent to an ep-formula modulo T if and only if ϕ is preserved by all homomorphisms between models of T .
Note that ep and pp are not interchangeable in the previous theorem. Theorem 4.10 (Chang-Loś-Suszko Theorem; Theorem 6.5.9 in [21] and remarks after the proof). Let T be an fo-τ -theory. An fo-τ -formula ϕ is equivalent modulo T to a ∀∃-formula if and only if ϕ is preserved in unions of chains (A i ) i≤κ whenever A i and all the A i are models of T .

Positive version of Chang-Loś-Suszko.
The following fact is called the existential amalgamation theorem in [22].  [22]). Let A and B be τ -structures,ā a sequence of elements of A, and h :ā → B an embedding such that every existential sentence true in (B, h(ā)) is also true in (A,ā). Then there exists an elementary extension C of A and an embedding g : B → C such that g(h(ā)) =ā.
The existential amalgamation theorem has the following positive variant. We give the proof (it is omitted in [22]). Proposition 4.12 (Theorem 5.4.7 in [22]). Let A and B be τ -structures,ā a sequence of elements of A, and h :ā → B an embedding such that every existential positive sentence true in (B, h(ā)) is also true in (A,ā). Then there exists an elementary extension C of A and a homomorphism g : B → C such that g(h(ā)) =ā.
Proof. Similar to the proof of 5.4.1 in [22]. Since h is an embedding, we can replace B by an isomorphic copy and assume that h is the identity onā. Let A ′ be the expansion of A by those constant symbols that denote the elements ofā in B c . By Lemma 4.8, it suffices to show that the theory T := diag fo (A ′ ) ∪ diag + (B) is consistent. If T has no model, then by the compactness theorem there is a conjunction ϕ(ā,c) of finitely many sentences in diag + (B) such that A |= ¬∃ȳ.ϕ(ā,ȳ). Since ϕ is quantifier-free and positive, the assumptions imply that B |= ¬∃ȳ.ϕ(ā,ȳ). This contradicts that ϕ(ā,c) is true in B.
Lemma 4.13. Let T be a theory and A a model of the ∀∃ + -consequences of T . Then A can be extended to a model B of T such that every ep-formula that holds on a tupleā in A ⊆ B also holds onā in A.
Proof. It suffices to prove that T ∪ diag(A) ∪ diag ∀ − (A) has a model B. Suppose for contradiction that it were inconsistent; then by compactness, there exists a finite subset U of diag ∀ − (A) ∪ diag(A) such that T ∪ U is inconsistent. Let ϕ be the conjunction over U where all constants are existentially quantified. Then T ∪ {ϕ} is inconsistent as well, and ¬ϕ is equivalent to a ∀∃ + sentence, and a consequence of T . Hence, A |= ¬ϕ, a contradiction.
The following is a positive version of the Chang-Loś-Suszko theorem (Theorem 4.10). We say that an fo-formula ϕ(x 1 , . . . , x n ) is preserved in direct limits of models of T if for all sequences (A i ) i<κ where all the A i and A := lim i<κ A i are models of T , and every n-tuplē a of elements of A we have A |= ϕ(ā) whenever there is for every i < κ an n-tupleā i where the j-th entry is a representative of the j-th entry ofā, and A i |= ϕ(ā i ).
Proposition 4.14. Let T be a τ -theory, and Φ a set of τ -formulas (in a finite set of free variables). Then the following are equivalent.
(1) Φ is modulo T equivalent to a set of ∀∃ + -formulas; (2) Φ is preserved in direct limits of sequences of models of T ; (3) Φ is preserved in direct limits of countable sequences of models of T .
The implication from (2) to (3) is trivial. For the implication from (3) to (1), assume that Φ is preserved by direct limits of sequences (A i ) as in the statement of the proposition. We can assume that Φ is a set of sentences (by adding constants; see the proof of Theorem 5.4.4. in [22]). Let Ψ be the set of all ∀∃ + -sentences that are consequences of T ∪ Φ. We show that T ∪ Ψ implies Φ, whereupon the result follows. It suffices to show that every model of T ∪ Ψ is elementary equivalent to a direct limit of a sequence (B i ) i<ω of models of To construct this sequence, we define an elementary chain of models such that for every tupleā i of elements from A i and every existential positive formula θ, if B i |= θ(f i (ā i )), then A i |= θ(ā i ), and • homomorphisms g i : Let A 0 be a countable model of T ∪ Ψ. To construct the rest of the sequence, suppose that A i has been chosen.
Since A 0 is an elementary substructure of A i , in particular all the ∀∃ + -consequences of T ∪ Φ hold in A i . By Lemma 4.13, the structure A i can be extended to a model B i of T ∪ Φ such that every ep-sentence that holds in (B i ,ā i ) also holds in (A i ,ā i ) (i.e. f i is the identity). Then by Proposition 4.12, there are an elementary extension A i+1 of A i and a homomorphism g i : B i → A i+1 such that g i • f i is the identity on A i . Then C := i<ω A i equals lim i<ω B i , and by the Tarski-Vaught elementary chain theorem (Theorem 2.5.2 in [22]) A 0 is an elementary substructure of C. So C is a model of T , and the direct limit of models B i of T ∪ Φ, and hence C |= Φ.
Note that the variant of Proposition 4.14, in which Φ is a single formula ϕ, holds as its corollary, via an application of compactness at the end.

4.2.2.
Model-complete core theories. A theory T is model-complete if any embedding across models of T is elementary, and T is called a core theory if every homomorphism between models of T is an embedding. The theory of a core need not be a core theory. The integers with successor (Z; succ) is a core, but the homomorphisms from the non-atomic countable models of its theory into (Z; succ) are not even injective (and so are not embeddings). The following closely follows the proof of Theorem 8.3.1 in [21].  (2) is immediate from the definition of epc models: if A and B are models of T and h : A → B is a homomorphism from A to B, then h must be an embedding since T is a core theory, and in fact must be elementary since T is model-complete. Hence, for every tupleā from A and any ep-formula ϕ such that h(ā) satisfies ϕ we have thatā also satisfies ϕ.
(2) implies (3). Assume (2). Let A and B be models of T , and let h be a homomorphism from A to B. Chooseā to be a vector that enumerates the elements of A. Since A is epc for T , h is an embedding. Hence, every existential sentence that holds in (B, h(ā ′ )) also holds in (A,ā ′ ), for any finite subtupleā ′ ofā. Proposition 4.11 now directly implies (3).
(3) implies (4). We first claim that if (3) holds, then every homomorphism between models of T preserves all universal τ -formulas. For if h is a homomorphism of A into B,ā a tuple from A and ϕ(x) a universal τ -formula such that A |= ϕ(ā), then taking C and g as in (3) we have C |= ϕ(g(h(ā))) and so B |= ϕ(h(ā)) since ϕ is a universal formula. This proves the claim. It follows by Theorem 4.9 that all universal τ -formulas are equivalent to ep-τ -formulas.
To finally prove (4), let ϕ(x) be any fo-τ -formula, w.l.o.g. in prenex normal form. By a simple induction on the number of quantifier-blocks we can transform ϕ to an existential formula, using the fact that the innermost quantifier block is either existential or universal, and can therefore be transformed into an existential formula (see Theorem 8.3.1 in [21]). Finally, existential τ -formulas are preserved by homomorphisms between models of T , since such homomorphisms must be embeddings. Hence, the entire formula is even equivalent to an ep-formula by Theorem 4.9.
(4) implies (1). Let A and B be models of T . Any homomorphism from A to B preserves all ep-formulas and therefore all fo-formulas, and hence must be an elementary embedding.
From this we obtain the following. The proof is similar to the one for Lindström's test (see Theorem 8.3.4 in [21]). Proposition 4.16 (Positive version of Lindström's test). Let T be a theory with signature τ which has no finite models but for which there exists a model epc for T of cardinality λ ≥ |τ |. If T is λ-categorical, then T is a model-complete core theory.
Sketch. We prove that every model of T is a model epc for T and use Theorem 4.15. So let A and B be two models of T and let h be a homomorphism from A to B. Letā be a tuple such that B |= ϕ(h(ā)) and suppose for contradiction that A |= ϕ(ā). Then we can put those two structures into a new 2-sorted structure (comprising A, B and the homomorphism h between them) with fo-theory T + , and apply the Löwenheim-Skolem theorem to produce a countable model of T + (where both sorts have the same cardinality since T has no finite models). By applying Löwenheim-Skolem again, this time to T + augmented by sentences expressing a bijection between the two sorts (over a signature expanded by a new function symbol), we obtain a two-sorted model of T + where each sort has cardinality λ, inducing structures C and D, respectively. By assumption there exists a model epc for T of cardinality λ, with λ ≥ |τ |, and by λ-categoricity C is a model epc for T . This contradicts the fact that we can express in T + that A is not a model epc for T . Proposition 4.17. Let T be a model-complete core theory. Then T is equivalent to a ∀∃ + -theory.
Proof. This is an immediate consequence of Proposition 4.14, since for any sequence (B i ) i<κ of models of T with homomorphisms g ij : B i → B j , the g ij are elementary. By the Tarski-Vaught theorem on unions of elementary chains (Theorem 2.5.2 in [22]), we have that lim i<κ B i |= T . Proposition 4.18. A λ-categorical τ -structure A, with λ ≥ |τ |, and epc for the ∀∃ + restriction of Th(A), is a model-complete core iff it has a theory equivalent to a ∀∃ + -theory.
Proof. The forwards direction follows from Proposition 4.17. For the backward direction, we use Proposition 4.16 to derive that Th(A) is a model-complete core theory, whereupon A is a model-complete core.
Proposition 4.19. Let T be an ω-categorical theory without finite models (over a finite or countable signature). Then T is a model-complete core theory if and only if it is equivalent to a ∀∃ + -theory.
Proof. The forward direction follows from Proposition 4.17. For the backward direction, note that there exists an at most countable epc model for T (which is ω-categorical). We now apply Proposition 4.16 to deduce that T is a model-complete core theory.   (1) Every model of T has a homomorphism to a model of T ′ , and every model of T ′ has a homomorphism to a model of T . (2) T and T ′ entail the same universal negative sentences.
Proof. To prove the implication from (1) to (2), assume (1), and let ϕ be a universal negative sentence entailed by T ′ . Suppose for contradiction that T has a model C such that C |= ¬ϕ. By (1), there is a homomorphism from C to a model B of T ′ . Since ¬ϕ is equivalent to an existential positive sentence, is preserved by homomorphisms, and hence we have a contradiction to the assumption that T ′ entails ϕ.
For the implication from (2) to (1), assume (2), and let B be a model of T . Let S be the ep-theory of B. We claim that S ∪ T ′ is satisfiable. If not, then by compactness there is some finite subset {ϕ 1 , . . . , ϕ k } of S such that T ′ entails (¬ϕ 1 ∨ · · · ∨ ¬ϕ k ). The formula ¬ϕ 1 ∨ · · · ∨ ¬ϕ k is equivalent to a universal negative sentence ψ, and T ′ entails ψ, so by (2) we have that T entails ψ, and hence B |= ψ. We have reached a contradiction, since B |= ϕ i for all i ≤ k. So there indeed exists a model A of S ∪ T ′ . The positive variant of the existential amalgamation theorem (Proposition 4.12) applied to A and B for the empty sequenceā gives a model C of T ′ ∪ S and a homomorphism from B to C.
The following two propositions are similar to Theorem 8.3.6 in [21]. Proposition 4.22. Let T be a ∀∃ + -theory with signature τ . If T has a core companion U , then U is up to equivalence of theories unique, and is the theory of the class of all models epc for T .
Proof. We show that the models epc for T are precisely the models of U . First assume that A is a model of U . Since U is a core companion of T , there is a homomorphism e from A to a model B of T . The assumption that U is a core companion of T also implies that there exists a homomorphism f from B into a model C of U . Then f • e is a homomorphism between two models of U , and since U is a model-complete core theory it must be an elementary embedding. This shows in particular that e is an embedding. We claim that A is a model of the ∀∃ + -theory T . Let ϕ = ∀ȳ.ψ be a sentence from T where ψ is a disjunction of ep and negated atomic τ -formulas, and letā be a tuple from A. Since B is a model of T and therefore satisfies ∀ȳ.ψ, in particular the tuple e(ā) satisfies ψ. If e(ā) satisfies a negated atom in the disjunction ψ thenā satisfies ψ as e is an embedding. Otherwise, e(ā) satisfies an ep-formula in the disjunction ψ and f • e(ā) satisfies ψ follows, as f is a homomorphism. Nowā satisfies ψ as f • e is an elementary embedding. Since this holds for allā, we have proven that A satisfies ϕ.
In fact, A is a model epc for T . To verify this, let g be a homomorphism from A into another model D of T ,ā a tuple from A, and ϕ an ep-formula with D |= ϕ(g(ā)). We have to show that A |= ϕ(ā). Again, since U is a core companion of T there exists a homomorphism h from D into a model E of U . Since U is a model-complete core theory, the mapping h • g is elementary. Since h is a homomorphism, E |= ϕ(h(g(ā))). Since h • g is elementary, A |= ϕ(ā).
Conversely, we show that every model A epc for T satisfies U . Since U is a core companion, there is a homomorphism h from A to a model B of U . By Proposition 4.17, U is equivalent to a ∀∃ + -theory, and thus it suffices to show that A satisfies all ∀∃ +consequences ∀ȳ.ψ(ȳ) of U , where ψ is a disjunction of ep and negated atomic τ -formulas. Letā be a tuple of elements of A. We have to show that A |= ψ(ā). Since B |= ∀ȳ.ψ(ȳ), at least one disjunct θ(h(ā)) of ψ(h(ā)) is true in B. If θ is a negated atomic formula, then θ(ā) is also true in A since h is a homomorphism. If θ is an ep-formula, then we deduce C, a model of T , and a homomorphism g : B → C such that C |= θ(g(h(ā))). Now A |= θ(ā) since A is epc for T . In both cases we can conclude that A |= ψ(ā).
Proposition 4.23. Let T be a ∀∃ + -theory with signature τ . Then T has a core companion if and only if the class of models epc for T is axiomatizable by a τ -theory.
Proof. If T has a core companion U , then Proposition 4.22 above implies that U axiomatizes the class of models epc for T .
For the converse, suppose that the class of models epc for T is the class of all models of a τ -theory U . Then every model of U is in particular a model of T , and every model of T homomorphically maps to a model epc for T (and model of U ) by Proposition 4.5. So we only have to verify that U is a model-complete core theory to show that U is the core companion of T .
Every model A of U is a model epc for T . Since being a model of U implies being a model of T , we deduce that A is in fact a model epc for U . It follows by the equivalence of (1) and (2) in Theorem 4.15 that U is a model-complete core theory. Note that A and A ′ may generate the same CSP, i.e. share the same ep-theory, whilst having distinct ∀∃ + -theories. The previous proof shows us that ep-equivalence does not affect the question as to whether or not the class of models epc for the ∀∃ + -theory of A is axiomatizable.

4.3.
Equivalent ω-categorical templates. We are now in a position to establish precisely when a template A has an equivalent B (i.e., s.t. CSP(A) = CSP(B)) such that B is ωcategorical. At the same time we reprove the result of [3] that every ω-categorical template is equivalent to a unique template that is a model-complete core. The result in [3] was obtained using ad-hoc arguments that poorly reflected the aspects of our programme for the existential-positive that are similar to the programme for the existential in [32,33].
A structure is homogeneous (sometimes called ultrahomogeneous [21]) if every finite partial automorphism can be extended to a full automorphism.
Lemma 4.25. Let A be a countable homogeneous structure such that for each k only a finite number of distinct k-ary relations can be defined by atomic formulas. Then A is ω-categorical.
Proof. By homogeneity of A, the atomic formulas that hold on the elements of t in A determine the orbit of t under Aut(A). Since there are only finitely many such atomic formulas, it follows that there are finitely many orbits of k-tuples in Aut(A). The claim follows by Theorem 2.2.
A theory T is said to have the Joint Homomophism Property (JHP) if, for all models A and B of T , there exists a model C of T such that both A and B map homomorphically into C. (1) For all ep-τ -sentences ϕ 1 and ϕ 2 , if T ∪ {ϕ 1 } is satisfiable and T ∪ {ϕ 2 } is satisfiable then T ∪ {ϕ 1 , ϕ 2 } is satisfiable as well.
Proof. Assume (1), and let τ be the signature of T . Let A and B be models of T . We claim that the theory T ′ := T ∪ diag + (A) ∪ diag + (B) is satisfiable. By compactness, it suffices to show that every finite subset S of T ′ is satisfiable. Let S 1 := S ∩ diag + (A) and S 2 := S ∩ diag + (B). By forming a finite conjunction, we see that S 1 and S 2 are logically equivalent to single sentences ϕ 1 and ϕ 2 , respectively. Let ϕ ′ 1 and ϕ ′ 2 be the τsentences corresponding to ϕ 1 and ϕ 2 , respectively, in which the new constant symbols are existentially quantified out. Certainly T ∪ {ϕ ′ 1 } and T ∪ {ϕ ′ 2 } are satisfiable since A and B are models of T and therefore satisfy all sentences from T . By (1), the theory T ∪ {ϕ ′ 1 , ϕ ′ 2 } is satisfiable as well. Therefore the claim is true, and there exists a model C ′ of T ′ . Let C be the τ -reduct of C ′ . Finally, Lemma 4.8 asserts the existence of a homomorphism from A to C, and from B to C, which proves (2).
For the implication from (2) to (1), suppose that T is a τ -theory with the JHP, and that ϕ 1 and ϕ 2 are ep-sentences such that T ∪ {ϕ 1 } has a model A and T ∪ {ϕ 2 } has a model B. By (2), there exists a model of T such that A and B homomorphically map to C. Then C clearly satisfies T ∪ {ϕ 1 , ϕ 2 }.
For a satisfiable theory T , let ∼ T n be the equivalence relation defined on ep-formulas with n free variables x 1 , . . . , x n as follows. For two such formulas ϕ 1 and ϕ 2 , let ϕ 1 ∼ T n ϕ 2 iff for all ep-formulas ψ with free variables x 1 , . . . , x n we have that {ϕ 1 , ψ} ∪ T is satisfiable if and only if {ϕ 2 , ψ} ∪ T is satisfiable. By proving that a model epc for a certain type of theory is in fact ω-categorical, we will derive the following. (i) T has a core companion, unique up to equivalence of theories, that is either ω-categorical or the theory of a finite structure. (ii) ∼ T n has finite index for each n. (iii) T has finitely many maximal ep-n-types for each n. (iv) There is a finite or ω-categorical model A that is a model-complete core, and which satisfies an existential positive sentence ϕ iff T ∪ {ϕ} is satisfiable.
Proof. (i) ⇒ (ii). Let U be the core companion of T , since they entail the same universal negative sentences, we can deduce -for ep-formulas ψ -that U ∪ {ψ} is satisfiable if and only if T ∪ {ψ} is satisfiable. It follows that the indices of ∼ U n and ∼ T n coincide. Let A be a finite, or the countable, model of U . For a proof by contraposition, assume ∼ U n has infinite index for some n. Let ϕ 1 and ϕ 2 be two ep-formulas from different equivalence classes of ∼ U n . Hence, there is an ep-formula ϕ 3 with free variables x 1 , . . . , x n such that exactly one of the two formulas ϕ 1 ∧ ϕ 3 and ϕ 2 ∧ ϕ 3 is satisfiable relative to U . This shows that ϕ 1 and ϕ 2 define over A distinct relations, and therefore that A can not be ω-categorical (as Theorem 2.2 asserts that it has only a finite number of inequivalent firstorder definable relations of arity n, and in particular only a finite number of inequivalent ep-definable relations of arity n). the signature τ ′ ). A simple back-and-forth argument shows that we may extend to an automorphism of A ′ , and the result follows.
(iv) ⇒ (i). Let A be the finite or ω-categorical structure that is a model-complete core. We claim Th(A) is a core companion of T . This follows from the fact that T and Th(A) entail the same universal negative sentences, via Proposition 4.21. Observe that Th(A) is equivalent to a ∀∃ + theory, by Proposition 4.17. Being a model-complete core theory follows immediately if A is finite, and via Proposition 4.16 if A is ω-categorical. Uniqueness follows from Proposition 4.22, since the core companion of Th(A) is, up to equivalence of theories, unique (and this implies that Th(A) is already the unique core companion of T , up to equivalence of theories).
We end this section by drawing comparison between Theorem 4.27 and a variant that is existential (but not existential positive). A theory T is said to have the Joint Embedding Property (JEP) if, for all models A and B of T , there exists a model C of T such that both A and B embed into C. A companion to a theory T is a theory T ′ s.t. every model of T ′ can be embedded into a model of T and vice-versa. A model companion is a companion that is model-complete. A ∃ 1 -type is defined exactly as an ep-type but with existential (as opposed to existential positive) formulas.
Theorem 4.28 ([33]). Let T be a theory with the JEP. Then the following are equivalent. 2 • T has a model companion that is either ω-categorical or the theory of a finite structure.
• T has finitely many maximal ∃ 1 -n-types for each n.
We also draw the reader's attention to the similarity between our Proposition 4.6 and Theorem 1.2(b) in [33].

Applications
We give a series of applications of our results in the study of the structure and complexity of CSPs. 5.1. Essentially unary polymorphisms. We will begin by demonstrating that the power of infinitary polymorphisms can be greatly limited. The forthcoming three lemmas are wellknown for finite domains (also for ω-categorical structures). They require a little care in the infinite case.
A function f : A α → A is essentially unary if there exist a β < α and g : A → A such that, for all x ∈ A α , f (x) = g(x β ). For x, w ∈ A α , and X ⊆ α, let x[x X /w X ] be the tuple x with each entry x β , where β ∈ X, substituted by w β .
Lemma 5.1. A function f : A α → A is not essentially unary iff there exist two non-empty and disjoint X, Y ⊆ α, such that both Proof. Let P 4 := (u = v ∨ x = y) ∈ A pp . It follows from Lemma 3.4 that P 4 must be preserved by the polymorphisms of A. Suppose for contradiction that A has a polymorphism f : M α → M that is not essentially unary. From Lemma 5.1, we deduce non-empty and disjoint X, holds, by disjointness of X and Y , while But this violates conservativity of f as q does not appear in x λ λ<ω + (q − p) z λ λ<ω (since p = x i ).
The following definition comes from [6]. For a structure A and an ep-sentence ϕ, we generate the boolean sentence F A (ϕ) by removing all existential quantifiers and replacing each atom R(x 1 , . . . , x k ), where R A is empty, with false, and replacing all other atoms with true. A is said to be locally refutable if for every ep-sentence ϕ, A |= ϕ iff F A (ϕ) is true.
Proposition 5.6. Let A be a structure that is not locally refutable and for which all ωpolymorphisms in all elementary extensions are essentially unary. Then CSP(A) is NPhard.
Proof. It is proved in [6] that the evaluation of ep-sentences on A is NP-hard. The result now follows from Lemma 5.2 (note that the recursive removal of disjunction induces a polynomial time reduction).

5.2.
First-order definable CSPs. Recall ϕ[B] to be the canonical query of B. CSP(A) is said to be first-order definable if there is an fo-sentence ψ A such that, for all finite B, A |= ϕ[B] (i.e. ϕ[B] ∈ CSP(A)) iff B |= ψ A . The following definition comes from [26]. The one-tolerant n-th power 1 A n of a τ -structure A is the τ -structure with domain A n where a k-ary R ∈ τ denotes the relation consisting of all those k-tuples ((a 1 1 , . . . , a n 1 ), . . . , (a 1 k , . . . , a n k )) such that |{j : (a j 1 , . . . , a j k ) ∈ R A }| ≥ n − 1 . For n ≥ 3, an n-ary polymorphism f of A is called a 1-tolerant polymorphism if f is a homomorphism from 1 A n to A. The following is our analog of the result from [26]. Proof of Claim 1. We note, for structures A and B, that if A and B are elementarily equivalent, then so are 1 A n+1 and 1 B n+1 (as 1 A n+1 is fo-definable in A). The assumption of the claim may be restated as that all pp-τ -sentences true in 1 M n+1 are true in M. This is clearly true by assumption that all finite substructures C map homomorphically to M.
A finite τ -structure C is an obstruction for the τ -structure A if there is no homomorphism from C to A. A family F of obstructions for A is called a complete set of obstructions if for every τ -structure B that does not admit a homomorphism to A there exists some C ∈ F which admits a homomorphism to B. The structure A is said to have finite duality if it admits a finite complete set of obstructions. An obstruction C for A is called critical if every proper (not necessarily induced) substructure of C admits a homomorphism to A. For any set A, let pr n k denote the projection map from A n to A which maps any tuple to its k-th coordinate. We claim the following (essentially from [26]: Claim 2. If there exists an (n + 1)-ary 1-tolerant polymorphism of A then the critical obstructions of A have at most n hyperedges. If A is a monster extension, the converse holds as well.
Proof of Claim 2. (Forwards.) By contraposition. Let C be a critical obstruction of A with m distinct hyperedges e 1 , . . . , e m , m > n. Then for k ∈ {1, . . . , m}, the τ -structure C k obtained from C by removing e k (without changing the domain) admits a homomorphism h k to A. By definition of 1 A m , the map h = (h 1 , . . . , h m ) is a homomorphism from C to 1 A m . Therefore there is no homomorphism from 1 A m to A, and in particular none from 1 A n+1 to A.
(Backwards.) Conversely, suppose that A is a monster extension, and that there is no homomorphism from 1 A n+1 to A. It follows from Claim 1 that there exists a finite substructure C of 1 A n+1 which has no homomorphism to A. Hence, C is an obstruction of A which admits a homomorphism h to 1 A n+1 . Let C ′ be a (not necessarily induced) substructure of C that is critical (such a C ′ always exists). For every k ∈ {1, . . . , n + 1} there exists a hyperedge e k of C ′ which is not preserved by pr n+1 k • h, since pr n+1 k • h is not a homomorphism from C to A. By definition of 1 A n+1 , e k is respected by pr n+1 j • h for every j = k, and thus e j = e k for j = k. Therefore C has at least n + 1 hyperedges.
Proof of Theorem. (Forwards.) Suppose first that CSP(A) is first-order definable. Since CSP(A) is a class of finite structures that is closed under inverse homomorphisms, by the dual version of Rossman's Theorem, [31], there is a universal negative first-order τ -sentence ϕ that holds on a finite structure B if and only if B homomorphically maps to A. Bringing ϕ into prenex negation normal form, it is straightforward to read from ϕ a finite complete set F of obstructions to A. Let m be the maximal number of hyperedges in the obstructions from F. By the claim above, since A is a monster, there is a homomorphism from 1 A m+1 to A. This is by definition a 1-tolerant polymorphism of A.
(Backwards.) Now suppose that for some n the structure 1 A n+1 admits a homomorphism to A. By the claim above the critical obstructions of A have at most n hyperedges. Since our signature is finite and relational, this implies that there are finitely many critical obstructions to A. This implies that the set of all critical obstructions is a finite obstruction set for A. It is now straightforward to write down a (universal) first-order definition of CSP(A). 5.3. Horn definability. We will briefly examine a class of structures for which we can give a neat algebraic condition as to whether a relation that is qf-definable admits a qf Horn definition. Recalling known complexity results for fo-expansions of (R; +, 1) we will see that the presence of a certain polymorphism exactly delineates those fo-expansions for which the CSP is NP-complete from those which are in P. The following proposition is essentially from [4]. Proposition 5.9. Let A be a structure with an embedding e from A 2 into A. Then a relation R that is qf-definable in the relations of A is preserved by e iff it admits a qf-Horn definition in A.
Proof. In this proof x 1 . . . , x k should be read as variable subtuples of the variable tuple x. Likewise with the element subtuples a 1 . . . , a k of a.
(Backwards.) Let F be a Horn definition of R. Suppose a and a ′ ∈ R A . It suffices to demonstrate the preservation of each clause in F of the form (R 1 (x 1 ) ∧ . . . ∧ R l (x l )) → R l+1 (x l+1 ), for R 1 , . . . , R l+1 relations of A.
) (R 1 (e(a 1 , a ′ 1 )) ∧ . . . ∧ R l (e(a l , a ′ l ))) → R l+1 (e(a l+1 , a ′ l+1 )) If the former clauses are true, there are two cases. Either some antecedent R i (a i ) or R i (a ′ i ) is false, in which case R i (e(a i , a ′ i )) is false, and the latter clause is true. Or, if all antecedents in both former clauses are true, then both R l+1 (a l+1 ) and R l+1 (a ′ l+1 ) are true, so it follows that R l+1 (e(a l+1 , a ′ l+1 )) is true, and the latter clause is true. (Forwards.) By contraposition. Consider a CNF definition F of R in A that is irreducible in the sense that it has no redundant literals in its clauses. If it is not Horn, there exists a clause R 1 (x 1 ) ∨ R 2 (x 2 ) ∨ S 3 (x 3 ) ∨ . . . ∨ S l (x l ), with R 1 , R 2 positive literals S 3 , . . . , S l positive or negative literals, with a, a ′ ∈ R A s.t. R 1 (a 1 ) ∧ ¬R 2 (a 2 ) ∧ ¬S 3 (a 3 ) ∧ . . . ∧ ¬S l (a l ) ¬R 1 (a ′ 1 ) ∧ R 2 (a ′ 2 ) ∧ ¬S 3 (a ′ 3 ) ∧ . . . ∧ ¬S l (a ′ l ) Consider the tuple e(a, a ′ ). Clearly it will fail to satisfy the clause.
We have already met an example of a structure with such an embedding: (R; +, 1). Corollary 5.10. Let B be an fo-expansion of (R; +, 1) and let e : (R; +, 1) 2 → (R; +, 1) be an embedding. Then: if e is a polymorphism of B, then CSP(B) is in P; otherwise CSP(B) is NP-complete.
Proof. Note that (R; +, 1) admits quantifier elimination and so all fo-expansions may be specified as qf CNFs. It is proved in [8] that those that admit qf-Horn definitions give a CSP that is in P while those that do not give CSPs that are NP-complete. The result follows from Proposition 5.9.

Concluding remarks and open problems
The universal-algebraic approach to the complexity of CSPs relies on two basic facts: the fact that every finite or ω-categorical structure is homomorphically equivalent to a modelcomplete core structure, and that primitive positive definability is characterized by preservation under polymorphisms.
In this paper we have presented generalizations of those two facts to not necessarily ω-categorical structures. A key concept in our proofs is the concept of existential-positive closure, which we used to re-derive and generalize results in the literature about the presence and uniqueness of model-complete cores [3]. We also give a necessary and sufficient condition as to when a CSP can be formulated with an ω-categorical template.
The results of this paper show that the second part of the universal algebraic approach -the characterization of pp-definability by polymorphisms -can be applied to study the complexity of CSP(A) for arbitrary (and not just ω-categorical) infinite-domain structures A. Among one of the first applications, we • gave a polymorphism-based characterization of those CSPs that are fo-definable; • demonstrated in the context of real-valued constraint satisfaction problems that for large classes of CSPs the border between easy and hard constraint satisfaction can be described in terms of the existence of a certain polymorphism of the constraint language; • have presented a strong universal-algebraic hardness criterion based on the absence of essential polymorphisms from the constraint language.
The following question is left for future research: can we strengthen our preservation theorem (Theorem 3.5) to show, under the additional assumption that A is epc (or epc and saturated, or has a model-complete core theory), that a first-order definable relation is pp-definable if and only if it is preserved by the finitary polymorphisms of A?