Adaptive Query Algorithms for Relational Structures Based on Homomorphism Counts
Abstract
A query algorithm based on homomorphism counts is a procedure to decide membership for a class of finite relational structures using only homomorphism count queries. A left query algorithm can ask the number of homomorphisms from any structure to the input structure and a right query algorithm can ask the number of homomorphisms from the input structure to any other structure. We systematically compare the expressive power of different types of left or right query algorithms, including non-adaptive query algorithms, adaptive query algorithms that can ask a bounded number of queries, and adaptive query algorithms that can ask an unbounded number of queries. We also consider query algorithms where the homomorphism counting is done over the Boolean semiring , meaning that only the existence of a homomorphism is recorded, not the precise number of them.
Keywords and phrases:
Query algorithms, homomorphisms, homomorphism counts, directed graphs, relational structures, Datalog, constraint satisfactionCopyright and License:
2012 ACM Subject Classification:
Theory of computation Finite Model TheoryEditors:
Paweł Gawrychowski, Filip Mazowiecki, and Michał SkrzypczakSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
A classic result by Lovász [15] states that a finite relational structure is determined up to isomorphism by the numbers of homomorphisms from to for every finite relational structure with the same signature. This list of numbers is called the left homomorphism profile of and is written as , where is the class of all finite relational structures with the same signature as . Similarly, one can define the right homomorphism profile as the list of numbers of homomorphism from to each structure. The right profile also determines the structure up to isomorphism, as shown by Chaudhuri and Vardi [6].
Recently, there has been considerable interest in exploring which structures can be distinguished by the homomorphism profiles when the class is restricted. As an example, in 2010, Dvořák [8] proved that if is the class of graphs of treewidth at most , the left profile can distinguish precisely the same graphs as the -dimensional Weisfeiler-Leman algorithm, a well-known polynomial time graph isomorphism test. Cai, Fürer, and Immerman [2] had already proved that the variable fragment of first-order logic extended with counting quantifiers can distinguish precisely the same graphs as -dimensional Weisfeiler-Leman algorithm. Also, in 2020, Grohe [12] proved that first-order logic with counting of quantifier rank at most can distinguish exactly the same graphs as the left homomorphism profile restricted to graphs of treedepth . Mančinska and Roberson [16] showed that the graphs that are quantum isomorphic are exactly the graphs that have the same left homomorphism profile restricted to planar graphs. In 2024, Seppelt [18] provides further insight into the logical equivalence relations for graphs that can be characterized by restricted left homomorphism profiles, using techniques from structural graph theory. These results highlight the importance of homomorphism profiles in finite model theory by describing a close connection between homomorphism profiles and logical languages.
Taking a slightly different approach, in 2022, Chen et al. [7] ask what properties of graphs can be decided based on finitely many homomorphism count queries. They did this by introducing the notion of a homomorphism-count based query algorithm. A non-adaptive left -query algorithm (also referred to as a left -query algorithm) consists of a finite tuple of structures and a subset . The algorithm is said to decide the class of structures
Non-adaptive right -query algorithms are defined similarly, but using instead of . These notions allow for the study of what classes of structures can be defined using a finite restriction of the left (respectively, right) homomorphism profile. Chen et al. also define an adaptive version of left/right -query algorithms. These are, roughly speaking, algorithms that can ask homomorphism-count queries where the choice of the -th query may depend on the answers to the first queries. Chen et al. [7] studied the expressive power of non-adaptive and adaptive query algorithms for the specific case of simple graphs (i.e., undirected graphs without self-loops). Among other things, they showed that every first-order sentence that is a Boolean combination of universal first-order sentences can be decided by a non-adaptive -left query algorithm for some . On the other hand, they showed that there are first-order sentences that cannot be decided by a non-adaptive left -query algorithm for any . When it comes to adaptive query algorithms, they showed that every class of simple graphs can be decided by an adaptive left 3-query algorithm, but that there exists a class of simple graphs that is not decided by an adaptive right -query algorithm for any , when using only simple graphs for the queries.
In a 2024 paper, ten Cate et al. [19] extend the above analysis by exploring query algorithms for arbitrary relational structures (not only simple graphs) and by considering also query algorithms over the Boolean semiring , which means that instead of being able to query for the number of homomorphisms, the algorithm can only query for the existence of a homomorphism. The query algorithms as defined by Chen et al. [7] can be viewed as query algorithms over the semiring of natural numbers. It is shown in [19] that, for classes of structures that are closed under homomorphic equivalence, non-adaptive left -query algorithms (over ) are no more powerful than non-adaptive left -query algorithms over . In other words, “counting does not help” for such classes. Moreover, for such classes, non-adaptive left query algorithms are equivalent in expressive power to first-order logic, meaning that such classes are first-order definable if and only if they are decided by a non-adaptive left query algorithm over (or ).
Our contributions.
We study the expressive power of different versions of these query algorithms for classes of relational structures. In doing so, we characterize their expressive power, relate it to that of logics and database query languages, and compare it across different types of algorithms. We focus mainly on adaptive query algorithms, including the previously unexplored notion of adaptive unbounded query algorithms – i.e., adaptive query algorithms for which there is no uniform bound on the number of queries they can ask on a given input, but which nevertheless terminate on every input.
Our main contributions are along two lines:
-
1.
We exploit the symmetry of directed cycles and cycle-like structures to give a simple formula (Lemma 4.2) for the number of homomorphisms from a structure to a disjoint union of cycle-like structures of the same size. This formula serves as a powerful tool for deriving homomorphism indistinguishability results for finite profiles, and may be useful more broadly in related contexts. We use it to systematically investigate and compare the expressive power of adaptive and non-adaptive query algorithms over for relational structures. For instance, we show, in Theorem 4.5, that for every signature containing a non-unary relation, there exists a class of structures of that signature that is not decided by an adaptive left -query algorithm over for any . A concrete example of such a class is the class of directed graphs whose number of connected components is an even power of 2. This result is in sharp contrast to the result of Chen et al., which states that every class of simple graphs can be decided by an adaptive left 3-query algorithm over . We also show in Theorem 4.7 that, for each , there exists a class that is decided by a non-adaptive left -query algorithm over but not by any adaptive left -query algorithm over . However, in Theorem 4.8 we also note that there exists a class that is decided by an adaptive left 2-query algorithm but not by any non-adaptive left query algorithm. We thus establish all inclusion and non-inclusion relations between the expressive powers of adaptive and non-adaptive left -query algorithms over (note: it follows from the proof of Lovász’s theorem that every class is decided by an adaptive left unbounded query algorithm). The results are summarized in Figure 1.
Interestingly, the situation is quite different for right query algorithms over . Indeed, it follows from results in [22] that every class of structures can be decided with only two adaptive right queries. This is again in contrast to a prior result of Chen et al. [7], namely that there is no such that every class of simple graphs can be decided by an adaptive right -query algorithm (when the queries themselves are also required to be simple graphs).
-
2.
We investigate the expressive power of adaptive query algorithms over . We observe that adaptive bounded query algorithms over have the same expressive power as non-adaptive query algorithms over , whose expressive power was characterized by ten Cate et al. [19]. However, we show that adaptive unbounded query algorithms over are strictly more expressive. The classes decided by such algorithms exhibit an intricate pattern, which we show can be captured by a topological characterization. In the case of homomorphism-closed classes, we further show that the characterization can be simplified significantly, yielding an elegant condition for establishing whether such a class is decided by an adaptive unbounded query algorithm over or not.
We also apply the topological characterization to examine the expressive power in the special cases of classes that are homomorphism equivalence types, CSPs, or Datalog-definable. Specifically, we show that unboundedness does not increase the expressive power of adaptive left query algorithms over for deciding CSPs and homomorphic-equivalence types, thereby yielding, based on existing results, an effective criterion for determining whether such classes are decided by an adaptive left unbounded query algorithm over . Additionally, we characterize the Datalog definable classes that are decided by such an algorithm in terms of their upper envelopes. Finally, we show that analogous results hold for adaptive right unbounded query algorithms over .
Outline.
Section 2 reviews preliminary definitions and background, including those of relational structures, digraphs, and walks in digraphs. Section 3 introduces the main concepts studied in this paper. We review the definition of non-adaptive query algorithms and introduce a new definition of adaptive query algorithms that applies in both the bounded and unbounded settings. Section 4 contains our main results regarding the expressive power of query algorithms over . Section 4.1 begins with the statement of a key lemma and then builds towards the result that not all classes can be expressed by an adaptive left bounded query algorithm over . In Section 4.2, we establish the results comparing adaptive and non-adaptive algorithms (as depicted in Figure 1). Section 4.3 concisely describes the simpler situation for adaptive right query algorithms over . Section 5 presents our results regarding the expressive power of query algorithms over . In Section 5.1, we show that unboundedness increases the expressive power of adaptive left query algorithms over . Section 5.2 provides the topological characterization of the classes expressed by adaptive left unbounded query algorithms over , and in Section 5.3 we apply this characterization to special cases. In Section 5.4, we show that similar results can be obtained for adaptive right query algorithms over . We conclude in Section 6 by listing directions for further research.
2 Preliminaries
Relational structures and homomorphism counts.
A signature is a set of relational symbols where each symbol has an associated arity . A relational structure of signature consists of a non-empty set and a relation for each symbol . We use to denote the class of all finite relational structures with signature . We will only study finite relational structures; we will thus write “structure” and mean “finite relational structure” throughout this text. If and are structures with signature , we say that is a homomorphism from to if it preserves all the relations, i.e. if
for each . We then write . If there exists a homomorphism from to we write , otherwise, . If and , we then write and say that and are homomorphically equivalent.
For structures and , we let denote the number of homomorphisms from to . We also use to denote this same number. We then define
where denotes the Boolean semiring. For a class of structures, the left homomorphism profile of restricted to is the tuple . Similarly, we can define the right homomorphism profile and the homomorphism profile over . When we speak of a class of structures, we will always assume it is closed under isomorphism.
Properties of structures.
The incidence multigraph of a structure is the bipartite multigraph whose parts are the sets and , and there is an edge between and for each entry in that is . We say that is connected if is connected, and we say is acyclic if is acyclic. In particular, if an element appears multiple times in a fact, then the structure is not acyclic. This notion of acyclicity is also known as Berge-acyclicity. The number of components of is the maximal such that can be written as the disjoint union of structures.
For given structures and we let denote their disjoint union and for a natural number and a structure we write
Digraphs, walks, and homomorphisms to cycles.
A digraph (or a directed graph) is a structure with exactly one binary relation. So it is a pair where . A simple graph is an undirected graph without loops. We let denote the directed cycle of length :
and denote the directed path of length :
For our discussion of adaptive left query algorithms, walks in directed graphs play a large role. We will thus review the definition of an oriented walk and some related concepts.
Definition 2.1.
Let be a digraph.
-
(i)
An oriented walk in is a sequence where for each , and if then while if then .
-
(ii)
The net length of an oriented walk is defined as:
-
(iii)
The oriented walk is said to be closed if .
-
(iv)
A closed oriented walk is called an oriented cycle if for all and .
-
(v)
A directed walk is an oriented walk such that for each . Closed directed walks and directed cycles are defined analogously.
An important thing to note is that oriented walks and their net lengths are preserved under homomorphisms. So if is an oriented walk in and is a homomorphism then
is an oriented walk in with the same net length.
For our proof of the existence of a class that is not decided by an adaptive left unbounded query algorithm, we take advantage of the fact that the existence of a homomorphism to a directed cycle can be described in an easy way.
Lemma 2.2 (Corollary 1.17 in [13]).
Let be a digraph and be a positive natural number. We have if and only if divides the net length of every closed oriented walk in .
We use to denote the greatest common divisor of a collection of natural numbers. For every finite digraph, we can define a parameter very related to the condition in Lemma 2.2.
Definition 2.3.
For a finite digraph we define
where is a listing of the net lengths of all cycles of positive net length in .
Note, here we use the convention . For integers we write if divides , and otherwise. The next proposition relates this parameter to the condition in Lemma 2.2.
Proposition 2.4.
Let be a digraph and be a positive integer. We have if and only if .
Conjunctive queries.
A Boolean conjunctive query (CQ) is a first-order logic (FO) sentence of the form such that each is of the form where each is among the variables in . It is well known that every such CQ has an associated “canonical structure” such that for every structure we have if and only if . Similarly, vice versa, for every (finite) structure , there is a Boolean CQ such that for every structure we have if and only if . A CQ is said to be Berge-acyclic if its canonical structure is acyclic. A (Boolean) union of conjunctive queries (UCQ) is a finite disjunction of (Boolean) CQs. Every Boolean UCQ is a positive existential FO sentence, and, conversely, every positive existential FO sentence is equivalent to a UCQ.
3 Definitions of Query Algorithms
First, we review the definition of non-adaptive query algorithms.
Definition 3.1.
Let be a class of relational structures with the same signature, let , and let be a positive integer.
-
A non-adaptive left -query algorithm over for is a pair , where is a tuple of relational structures with the same signature as the structures in , and is a set of -tuples over , such that for all structures , we have if and only if
-
A non-adaptive right -query algorithm over for is a pair , where is a tuple of relational structures with the same signature as the structures in , and is a set of -tuples over , such that for all structures , we have that if and only if
Example 3.2.
Let where is the singleton digraph with no edges, and let . Then the non-adaptive left 1-query algorithm over decides the class of digraphs that have exactly 3 vertices. It is not difficult to see that does not admit a non-adaptive left query algorithm over . Indeed, this follows from the fact that the class is not closed under homomorphic equivalence. A query algorithm over cannot distinguish between structures that are homomorphically equivalent, since if then if and only if for any .
The example above shows that query algorithms over have more expressive power than query algorithms over in general. However, for classes closed under homomorphic equivalence, the same does not hold, as shown by ten Cate et al. in the following theorem.
Theorem 3.3 (Corollary 5.6 in [19]).
Let be a class of structures that is closed under homomorphic equivalence. Then the following are equivalent:
-
admits a non-adaptive left -query algorithm over for some .
-
admits a non-adaptive left -query algorithm over for some .
-
is FO-definable.
We now formulate the definition of an adaptive unbounded query algorithm.
Adaptive query algorithms were defined in Chen et al. [7]. The definition there is limited in the sense that it only considers query algorithms whose number of queries is bounded by some constant.
For a set , we let denote the set of finite strings with alphabet .
-
For , we write if is an initial segment of .
-
We let denote the concatenation of the strings (we also use this notation if is an element of ).
-
If is a sequence, then we let denote the (possibly infinite) string with length such that for , the -th letter of is the -th letter of for any such that .
A set that is closed under initial segments (so if and then ) is called a subtree of . An element of such a subtree is called a leaf if for every such that we have .
We are now ready to define adaptive left unbounded query algorithms.
Definition 3.4.
Let .
-
(i)
An adaptive left unbounded query algorithm over for structures with signature is a function
where is a subtree of and if and only if is a leaf in .
-
(ii)
For , the computation path of an adaptive left unbounded query algorithm on is the string defined by where
The algorithm halts on input if is finite.
-
(iii)
If halts on all , then is said to be total.
-
(iv)
If is total, we say that it decides the class
-
(v)
We say that is an adaptive left -query algorithm if for every , has length at most . We say is bounded if it is an adaptive left -query algorithm for some .
The notion of an adaptive right unbounded/bounded query algorithm is defined analogously by appending instead of in the computation path.
We will only consider total adaptive query algorithms, so when we speak of adaptive query algorithms we always assume it is total.
Example 3.5.
Let be an adaptive left query algorithm over for digraphs defined with the following:
The corresponding tree would here be the set of all strings of length at most 2.
We can describe a run of the algorithm on a target structure as follows: First, the algorithm queries for the number of homomorphisms from the singleton digraph with no edges to . Let denote the output of that query. It then queries for . If the result is positive, it accepts; otherwise, it rejects.
To see what class this algorithm decides, we first note that the number of homomorphisms from the singleton digraph with no edges to is precisely the number of vertices of . We also have that there exists a homomorphism from to if and only if has a directed walk of length . Since is the size of , we see that such a walk has to visit the same vertex twice. We thus get that such a walk exists if and only if has a directed cycle. The algorithm, therefore, decides the class of digraphs that contain a directed cycle.
Example 3.6.
In this example, we show that every class of structures is decided by an adaptive left unbounded query algorithm over .
The algorithm first queries for the size of the structure. Then it queries the number of homomorphisms from every structure that is not larger than it. By the proof of Lovász’s theorem (see, for example, Section III of [1] for a proof of this), the algorithm has now distinguished the structure (up to isomorphism) and can thus classify it correctly.
To formally define the algorithm, let be the signature of the structures in . We fix an enumeration of all structures of signature such that for each there exists a number such that is an enumeration of all of the structures of size at most . Then the algorithm can be defined with:
4 Query Algorithms over
4.1 Unboundedness helps for adaptive left query algorithms
A starting point for our work in this section is the following result by Chen et al:
Theorem 4.1 (Theorem 8.2 in [7]).
Every class of simple graphs can be decided by an adaptive left 3-query algorithm over .
This result invites the question of what happens in the general case, for arbitrary relational structures. We prove that the same does not hold in this broader setting. We even show that there is a class of directed graphs that is not decided by an adaptive -query algorithm over , for any . To do this, we utilize the symmetry of directed cycles to prove that they are hard to distinguish from each other using left homomorphism queries.
We begin with a lemma that shows that the homomorphism count from a structure to a disjoint union of cycles can be described simply.
Lemma 4.2.
For every digraph and all positive integers we have
The proof of this theorem can be intuitively explained as follows: In disjoint unions of directed cycles, each vertex has in-degree 1 and out-degree 1. For a homomorphism from , the whole map is therefore decided by the value of the map in one vertex from each component of . Since there are ways to pick the value of a homomorphism on that initial vertex (if such a homomorphism exists), the lemma follows.
We say that two classes of structures are separated by a query algorithm if it accepts all structures in and rejects all structures in , or vice versa.
The importance of the above lemma is in the fact that it shows that for a given structure there are only two possible outcomes for . This limits what can be done using few queries, as is shown in the following theorem:
Theorem 4.3.
The class can be separated from the class by a non-adaptive left -query algorithm over if and only if .
Proof.
By Lemma 4.2 we have that for every digraph and every :
where denotes the largest positive integer such that if , if then . It follows from this that to have we must have . To distinguish between and for every the algorithm then needs to query some with for each . The algorithm, therefore, needs at least queries to separate the classes. It is clear that non-adaptive queries suffice: the algorithm can query for each . Every structure in yields a unique outcome from the collection of these queries, and thus they can be classified correctly.
It is worth noting that homomorphism existence queries suffice here, and hence and are already separated by a non-adaptive left -query algorithm over . ∎
Corollary 4.4.
The class can be separated from the class by an adaptive left -query algorithm over if and only if .
Proof.
For any digraph , there are only two possible outcomes for every query (as explained above). Therefore, an adaptive left -query algorithm over that separates from queries at most
different structures in all of its possible computation paths on inputs from . It can thus be translated into a non-adaptive left -query algorithm over separating the two classes. By Theorem 4.3 it follows that such a non-adaptive left -query algorithm over exists if and only if , so . Thus, we have shown that the classes , can only be separated by an adaptive left -query algorithm over if . It is also clear that suffices. The algorithm can use queries of the form to binary search for the of an input structure of the form , and use that to classify it correctly. ∎
Let denote the set of classes that are decided by a non-adaptive left -query algorithm over , and denote the set of classes that are decided by an adaptive left -query algorithm over . Theorem 4.3 and Corollary 4.4 show, among other things, that
Using Corollary 4.4, we can also prove an even stronger result:
Theorem 4.5.
Let be the class of digraphs whose smallest directed cycle (if it exists) has length that is an even power of two. Then is not decided by an adaptive left -query algorithm over for any .
Proof.
Note that we have
where denotes the set theoretic complement of a set . A given adaptive left -query algorithm over cannot separate from , by Corollary 4.4. To decide it must in particular separate these classes, therefore the algorithm can not decide . Thus it is clear that is not decided by any adaptive left -query algorithm over for any .∎
Using the same method it can be shown that many other classes are not decided by an adaptive left -query algorithm over for any . In fact, to show that a class is not decided by such an algorithm it suffices to show that it separates and for infinitely many . Another example of such a class is the class of digraphs whose number of components is an even power of two.
Note.
As we saw in Example 3.6, every class is decided by an adaptive left unbounded query algorithm over . Theorem 4.5 therefore also shows that unboundedness increases the expressive power of adaptive left query algorithms over , i.e. where denotes the class of structures decided by an adaptive left unbounded query algorithm over .
The preceding results show that there exist classes of digraphs that adaptive left bounded query algorithms over do not decide. It follows immediately that for every signature containing a binary relation, there exists a class of structures of that signature that left bounded query algorithms over cannot decide. For signatures containing only unary relations, it can be shown that every class can be decided with an adaptive left bounded query algorithm over . What about signatures that contain some -ary relation with and no binary relation? The following theorem answers this question.
Theorem 4.6.
For every and every signature containing an -ary relation, there exists a class of structures with signature that is not decided by an adaptive left -query algorithm over for any .
The class we construct in the proof of this theorem is similar to the class from Theorem 4.5, except we replace the directed cycles with -ary “cycle-like” structures.
4.2 Adaptive versus non-adaptive left -query algorithms
We now turn to a comparison of the expressive power of adaptive and non-adaptive left query algorithms over . It follows from Theorem 4.3 and Corollary 4.4 that . We also trivially have the relation . This raises the question of where the bound lies, that is, for which we have but ? This is answered by the following theorem:
Theorem 4.7.
For each , there exists a class of structures that is decided by a non-adaptive left -query algorithm over but not by an adaptive left -query algorithm over .
Proof.
Let be distinct primes and write and . Define a non-adaptive left -query algorithm with
where is the Kronecker delta. Let be the class decided by the above query algorithm. It follows from Lemma 4.2 that
so for we have if and only if . We will show that cannot be decided by an adaptive left -query algorithm over .
Let be a given adaptive left -query algorithm over . Using an adversarial argument, we find two structures that are classified in the same way by but differently by . We do this by defining sets such that has the same computation path on all elements of up to stage . We define . Now let be given such that has the same computation path on all elements of up to stage . Write . We have two cases:
-
If is the same for all elements of we can simply define and the computation path is the same up to stage .
-
Assume otherwise. Note that for any element of we have by Lemma 4.2 that
So there are only two possible outcomes. Moreover, if for , then and thus for all and we are in the former case. Thus, there is an such that if and only if . We can thus define . It is clear that for all elements of , so they share the same computation path up to stage .
The above construction gives us a set such that has the same computation path up to stage on all elements of it. Clearly we also have that . This means that there must exist such that and . Thus, we have found elements that classifies in the same way but classifies differently. We have thus shown that does not decide . ∎
The above theorem describes a class of structures where adaptiveness does not help at all when trying to decide the class; therefore, we have that for each . This is interesting as in many cases, adaptiveness greatly reduces the number of queries needed.
In this regard, we now prove that there is an adaptive left 2-query algorithm over that decides a class that no non-adaptive left query algorithm over decides.
Theorem 4.8.
The class of all digraphs that contain a directed cycle is decided by an adaptive left 2-query algorithm over , but not by any non-adaptive left -query algorithm over , for any .
Proof.
Note that directed cycles are preserved by homomorphisms. It then follows that the class is closed under homomorphic equivalence. It is also well known that this class is not first-order definable; this is a standard application of the Ehrenfeucht-Fraïsse method, which can be found in textbooks on finite model theory [9]. It then follows from Theorem 3.3 that the class is not decided by a non-adaptive left -query algorithm over , for any .
In example 3.5 we saw an adaptive left 2-query algorithm over that decides the class. This completes the proof. ∎
The preceding results now give the relations between and shown in Figure 1.
4.3 Adaptive right query algorithms over
In their paper, Chen et al. also prove a result about adaptive right query algorithms on simple graphs:
Proposition 4.9 (Proposition 9.3 in [7]).
There exists a class of simple graphs that is not decided by an adaptive right -query algorithm over for any , using only simple graphs in its queries.
In the general case, we again get a different result. It turns out that using looped structures in the queries changes the picture completely. This result was essentially proved by Wu [22], but it is not stated in this form in his work.
Theorem 4.10 (From [22]).
Every class of structures can be decided by an adaptive right 2-query algorithm over .
This result also is in contrast to our result for left query algorithms: the hierarchy of expressive power of adaptive right -query algorithms collapses at , in contrast to the strict hierarchy shown in Figure 1 for adaptive left -query algorithms. The cause of this is that for right query algorithms, we have more constructions that give useful information about the homomorphism counts. In particular, we have that if is connected then
No construction on the left side allows for addition of the hom-vectors.
5 Query Algorithms Over
We now move on to studying adaptive query algorithms over . We focus on left query algorithms, and we will comment on the case of right query algorithms afterwards.
5.1 Unboundedness helps for adaptive left query algorithms
Every class that can be decided by an adaptive -query algorithm over can also be decided by a non-adaptive -query algorithm over . This is done by querying all the structures that the algorithm can possibly query in the first steps of its run. Since there are at most branches from each node in the computation tree, this is at most queries. This means that adaptive and non-adaptive left bounded query algorithms over have the same expressive power.
The question we answer below is whether every class decided by an adaptive unbounded query algorithm over can be decided by an adaptive bounded query algorithm (and thus a non-adaptive one)? The answer is no.
Theorem 5.1.
The class can be decided by an adaptive left unbounded query algorithm over , but not by an adaptive left -query algorithm over , for any .
Proof.
In theorem 4.8 we showed that is not decided by a non-adaptive left -query algorithm over , it is thus not decided by a non-adaptive left -query algorithm over .
We now provide an adaptive left unbounded query algorithm over that decides . The algorithm runs as follows:
Let be the given input. For query and . If at any point then halt and output NO. If at any point then halt and output YES.
To see that this algorithm decides we note that the following equivalence holds:
| the lengths of directed walks in are bounded | |||
| by a constant | |||
Also, directed cycles are preserved under homomorphism, so has a directed cycle if and only if for some . Thus, it is clear that the algorithm halts on all inputs and produces the correct answer. ∎
5.2 Characterization of the expressive power of adaptive left unbounded query algorithms over
We can use the language of topology to characterize the expressive power of adaptive unbounded query algorithms exactly. For background on topology, we refer the reader to [17]. The topology we define is generated by all “basic observations”, where a basic observation is a class defined by the answer to a single homomorphism query.
More formally, for a structure we define
which, phrased in terms of conjunctive queries (CQs) is simply the set of structures that satisfy the canonical CQ of . We then let
be the subbasis for our topology . In other words, phrased again in terms of conjunctive queries, the open sets of the topology are all classes of structures that can be defined by a CQ or the negation of a CQ, as well as all classes generated from these by closing under finite intersection and arbitrary union.
We have the following characterization of classes that are decided by adaptive left unbounded query algorithms over .
Theorem 5.2.
A class is decided by an adaptive left unbounded query algorithm over if and only if is a clopen set in the topological space .
Remember, a clopen set is a set that is both closed and open. We say that a class of structures is homomorphism-closed if whenever and for some structure , then . We can use the topological characterization to get a simpler characterization for the existence of an adaptive left unbounded query algorithm over in the case of homomorphism-closed classes.
Theorem 5.3.
Let be a homomorphism-closed class; then the following hold:
-
(i)
, hence is open.
-
(ii)
Furthermore, is closed if and only if for some structures .
The preceding two theorems imply that a homomorphism-closed class is decided by an adaptive left unbounded query algorithm over if and only if is an intersection of UCQs.
5.3 Case studies
As our first case study, we consider the definability of Constraint Satisfaction Problems (CSPs) with adaptive left unbounded query algorithms over .
A CSP can be formulated as a problem of deciding whether there is a homomorphism from an input structure to a target structure. For a relational structure we write .
We can combine some known results with our observations from Section 5.2 to get the following result:
Theorem 5.5.
Let be any class of the form or for a structure . Then the following are equivalent:
-
(i)
is decided by an adaptive left unbounded query algorithm over .
-
(ii)
is decided by a non-adaptive left -query algorithm over for some .
This theorem shows that unboundedness does not help when deciding CSPs or homomorphic equivalence classes, and it gives an effective characterization of the classes of this form that are decided by an adaptive left unbounded query algorithm over :
Corollary 5.6.
is decided by an adaptive left unbounded query algorithm over if and only if it first-order definable. Moreover, there is an effective algorithm that decides for a given structure A whether this holds.
The fact that is decided by a non-adaptive left query algorithm over if and only if it is first-order definable follows from Theorem 3.3. The fact that there is an algorithm that decides whether is first-order definable is a well-known result by Larose, Loten, and Tardif [14].
Consider now the database query language Datalog. To conserve space, we omit a detailed definition of the syntax and semantics of Datalog, which can be found in [9]. Here we only consider Boolean Datalog programs, which are Datalog programs with a 0-ary goal predicate. Such a program defines a class of structures that is homomorphism-closed. A Datalog program is monadic if it only uses recursive predicates (a.k.a. IDBs) that are unary; it is linear if every rule body has at most one occurrence of a recursive predicate.
The class of digraphs that contain a directed cycle from Theorem 5.1 is Datalog definable, using the program:
This shows that unboundedness helps even when we restrict ourselves to Datalog definable classes. Contrastingly, Theorem 5.5 shows that for every Datalog program that defines the complement of a CSP, unboundedness does not help. Corollary 5.6 furthermore shows that a class defined by such Datalog programs is decided by an adaptive left unbounded query algorithm if and only if it is first-order definable. Note that the Datalog programs that define the complement of a CSP form a non-trivial fragment of Datalog. Indeed, every (Boolean) monadic Datalog program whose rule bodies are “tree-shaped” defines a complement of a CSP (and moreover, the CSP in question can be constructed effectively from the Datalog program), cf. [10, 3].
We can use these observations to prove a negative result on the expressive power of adaptive left query algorithms over .
Theorem 5.7.
There exists a class definable by a monadic linear Datalog program that is not decided by an adaptive left unbounded query algorithm over .
We now give a characterization of the Datalog definable classes that are also decided by an adaptive left unbounded query algorithm in terms of their upper envelopes.
Chaudhuri and Kolaitis [4, 5], in their study of approximations of Datalog programs by non-recursive queries, they introduced the notion of an upper envelope. For a Boolean Datalog program deciding a class , an upper envelope is a union of conjunctive queries (UCQ) that defines a class such that . Such an upper envelope can be equivalently viewed as a class of the form that contains . Since Datalog definable classes are homomorphism-closed, Theorem 5.3 therefore gives us the following:
Corollary 5.8.
A Datalog definable class is decided by an adaptive left unbounded query algorithm over if and only if it is the intersection of its upper envelopes.
5.4 Adaptive right query algorithms over
For adaptive right query algorithms over we have a result analogous to Theorem 5.1:
Theorem 5.9.
The class of all digraphs that have an oriented cycle with non-zero net length can be decided by an adaptive right unbounded query algorithm over , and not by an adaptive right -query algorithm over , for any .
It can be shown that this class is Datalog definable. So, as in the case for left query algorithms, unboundedness sometimes helps even when we restrict ourselves to Datalog definable classes.
We can also replicate the results from section 5.2 for right query algorithms. We define as the topology generated by the sub-basis
where denotes the set . In other words, consists of all CSPs and their complements. Using the same argument as before, we can prove:
Theorem 5.10.
A class is decided by an adaptive right unbounded query algorithm over if and only if is a clopen set in the topological space .
Then we also get
Theorem 5.11.
Let be any class of the form or for a structure . Then the following are equivalent:
-
(i)
is decided by an adaptive right unbounded query algorithm over .
-
(ii)
is decided by a non-adaptive right -query algorithm over for some .
It then follows from a result by ten Cate et al. [19] that these conditions hold if and only if is homomorphically equivalent to an acyclic structure. Using the language of conjunctive queries, this shows that a CQ has an equivalent adaptive right unbounded query algorithm if and only if is equivalent to a Berge-acyclic CQ. It is also good to note that since every CQ can be written as a Datalog program, this also shows that there are Datalog-definable classes that are not decided by any adaptive right unbounded query algorithm over .
6 Open Problems
Adaptive -query algorithms.
We can define an adaptive -query algorithm as an adaptive unbounded query algorithm that uses at most queries for inputs of size . Then one could ask the question of what the growth rate of needs to be for adaptive left -query algorithms over to be able to decide any class of structures of a given signature. The algorithm described in Example 3.6 gives an upper bound of for such an , where are the arities of the relation symbols in the signature. On the other hand, Corollary 4.4 implies that such an is not . This leaves quite a large gap between the known lower and upper bounds. Shrinking this gap is an interesting avenue for further research.
Decidability of the existence of an adaptive left unbounded query algorithm over .
For classes of the form , Corollary 5.6 shows that determining whether they are decided by an adaptive left unbounded query algorithm is decidable. The criterion given in Corollary 5.8 for Datalog definable classes is, however, not effective. This raises the question of whether there exists such an effective criterion for Datalog definable classes, or whether that problem is undecidable. Note that the “Rice-style” general undecidability result for semantic properties of Datalog programs from [11] appears to be of no help here: although admitting an adaptive left unbounded query algorithm over is a semantic property of Datalog programs, it fails to satisfy their “strong non-triviality” requirement.
Adaptive hybrid -query algorithms over .
A query algorithm that can use both left and right queries can be called a hybrid query algorithm. Adaptive hybrid query algorithms over have been studied by Wu [21], but there has been no research on such algorithms over . Every class of structures that is closed under homomorphic equivalence can be decided by an adaptive hybrid unbounded query algorithm over . On input , the algorithm simply queries for and for each structure . At some point, both of these numbers are 1, then the homomorphic equivalence class of is decided, which suffices to classify it correctly. This evokes the question of what the expressive power of hybrid -query algorithms is: Do we get a strict hierarchy as in Figure 1? What is the relation between the expressive power of non-adaptive and adaptive hybrid query algorithms over ?
References
- [1] Albert Atserias, Phokion G Kolaitis, and Wei-Lin Wu. On the expressive power of homomorphism counts. In 2021 36th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS), pages 1–13. IEEE, 2021. doi:10.1109/LICS52264.2021.9470543.
- [2] Jin-Yi Cai, Martin Fürer, and Neil Immerman. An optimal lower bound on the number of variables for graph identification. Combinatorica, 12(4):389–410, 1992. doi:10.1007/BF01305232.
- [3] Balder ten Cate, Víctor Dalmau, and Jakub Opršal. Right-Adjoints for Datalog Programs. In Graham Cormode and Michael Shekelyan, editors, 27th International Conference on Database Theory (ICDT 2024), volume 290 of Leibniz International Proceedings in Informatics (LIPIcs), pages 10:1–10:20, Dagstuhl, Germany, 2024. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.ICDT.2024.10.
- [4] Surajit Chaudhuri. Finding nonrecursive envelopes for Datalog predicates. In Proceedings of the twelfth ACM SIGACT-SIGMOD-SIGART symposium on Principles of database systems, pages 135–146, 1993. doi:10.1145/153850.153862.
- [5] Surajit Chaudhuri and Phokion G Kolaitis. Can Datalog be approximated? In Proceedings of the thirteenth ACM SIGACT-SIGMOD-SIGART symposium on Principles of database systems, pages 86–96, 1994. doi:10.1145/182591.182602.
- [6] Surajit Chaudhuri and Moshe Y Vardi. Optimization of real conjunctive queries. In Proceedings of the twelfth ACM SIGACT-SIGMOD-SIGART symposium on Principles of database systems, pages 59–70, 1993. doi:10.1145/153850.153856.
- [7] Yijia Chen, Jörg Flum, Mingjun Liu, and Zhiyang Xun. On algorithms based on finitely many homomorphism counts. In Stefan Szeider, Robert Ganian, and Alexandra Silva, editors, 47th International Symposium on Mathematical Foundations of Computer Science (MFCS 2022), volume 241 of Leibniz International Proceedings in Informatics (LIPIcs), pages 32:1–32:15, Dagstuhl, Germany, 2022. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.MFCS.2022.32.
- [8] Zdeněk Dvořák. On recognizing graphs by numbers of homomorphisms. Journal of Graph Theory, 64(4):330–342, 2010. doi:10.1002/jgt.20461.
- [9] Heinz-Dieter Ebbinghaus and Jörg Flum. Finite model theory. Perspectives in Mathematical Logic. Springer, 1995.
- [10] Péter L. Erdős, Dömötör Pálvölgyi, Claude Tardif, and Gábor Tardos. Regular families of forests, antichains and duality pairs of relational structures. Combinatorica, 37(4):651–672, 2017. doi:10.1007/s00493-015-3003-4.
- [11] Haim Gaifman, Harry G. Mairson, Yehoshua Sagiv, and Moshe Y. Vardi. Undecidable optimization problems for database logic programs. J. ACM, 40(3):683–713, July 1993. doi:10.1145/174130.174142.
- [12] Martin Grohe. Counting bounded tree depth homomorphisms. In Proceedings of the 35th Annual ACM/IEEE Symposium on Logic in Computer Science, pages 507–520, 2020. doi:10.1145/3373718.3394739.
- [13] Pavol Hell and Jaroslav Nesetril. Graphs and homomorphisms, volume 28. OUP Oxford, 2004.
- [14] Benoît Larose, Cynthia Loten, and Claude Tardif. A characterisation of first-order constraint satisfaction problems. Log. Methods Comput. Sci., 3(4), 2007. doi:10.2168/LMCS-3(4:6)2007.
- [15] László Lovász. Operations with structures. Acta Mathematica Hungarica, 18(3-4):321–328, 1967.
- [16] Laura Mančinska and David E. Roberson. Quantum isomorphism is equivalent to equality of homomorphism counts from planar graphs. In 2020 IEEE 61st Annual Symposium on Foundations of Computer Science (FOCS), pages 661–672, 2020. doi:10.1109/FOCS46700.2020.00067.
- [17] James R. Munkres. Topology. Prentice Hall, Inc., 2 edition, January 2000. URL: http://www.worldcat.org/isbn/0131816292.
- [18] Tim Seppelt. Logical equivalences, homomorphism indistinguishability, and forbidden minors. Information and Computation, 301:105224, 2024. doi:10.1016/j.ic.2024.105224.
- [19] Balder ten Cate, Victor Dalmau, Phokion G. Kolaitis, and Wei-Lin Wu. When do homomorphism counts help in query algorithms? In Graham Cormode and Michael Shekelyan, editors, 27th International Conference on Database Theory, ICDT 2024, March 25-28, 2024, Paestum, Italy, volume 290 of LIPIcs, pages 8:1–8:20. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.ICDT.2024.8.
- [20] Balder ten Cate, Phokion G. Kolaitis, and Arnar Á. Kristjánsson. Adaptive query algorithms for relational structures based on homomorphism counts, 2025. doi:10.48550/arXiv.2504.16567.
- [21] Wei-Lin Wu. Query algorithms based on homomorphism counts. In Structure Meets Power Workshop (Contributed Talks), page 24, 2022.
- [22] Wei-Lin Wu. A Study of the Expressive Power of Homomorphism Counts. PhD thesis, University of California, Santa Cruz, USA, 2023. URL: https://www.escholarship.org/uc/item/4647715d.
