1 Introduction
Answer set programming (ASP) (Reference Gelfond and LifschitzGelfond and Lifschitz 1991; Reference Brewka, Eiter and TruszczynskiBrewka et al. 2011) has been proposed over two decades ago as a variant of logic programming for modeling and solving search and optimization problems (Reference Marek and TruszczynskiMarek and Truszczynski 1999; Reference NiemeläNiemelä 1999). Today, it is among the most heavily studied declarative programming formalisms with highly effective processing tools and an ever-growing array of applications (Brewka et al. 2011, 2016). Focusing on decision problems, the scope of applicability of ASP is that of the class $\Sigma _2^P$ (Reference Dantsin, Eiter, Gottlob and VoronkovDantsin et al. 2001). This class includes a vast majority of problems of practical interest. However, many important decision problems belong to higher complexity classes (Reference StockmeyerStockmeyer 1976; Reference Schaefer and UmansSchaefer and Umans 2002). For this reason, several language extensions have been proposed that expand the expressivity of ASP (Reference Bogaerts, Janhunen and TasharrofiBogaerts et al. 2016; Reference Amendola, Ricca and TruszczynskiAmendola et al. 2019; Reference Fandinno, Laferrière, Romero, Schaub and SonFandinno et al. 2021). Among these, Answer Set Programming with Quantifiers (ASP(Q)) (Reference Amendola, Ricca and TruszczynskiAmendola et al. 2019) has been recently introduced to offer a natural declarative means to model problems in the entire Polynomial Hierarchy (PH).
Roughly speaking, the definition of a problem in $\Sigma _n^P$ can be often reformulated as “there is an answer set of a program $P_1$ such that for every answer set of a program $P_2$, $\ldots$ there is an answer set of $P_n$, so that a stratified program with constraint $C$, modeling admissibility of a solution, is coherent,” (and a similar sentence starting with “for all answer set of program $P_1$” can be used to encode problems $\Pi _n^P$).
Both the original paper (Reference Amendola, Ricca and TruszczynskiAmendola et al. 2019) on ASP(Q), and the subsequent one (Reference Amendola, Cuteri, Ricca and TruszczynskiAmendola et al. 2022) presented several examples of problems outside the class $\Sigma ^P_2$ that allow natural representations as ASP(Q) programs. Furthermore, Reference Amendola, Cuteri, Ricca and TruszczynskiAmendola et al. (2022) first, and Reference Faber, Mazzotta and RiccaFaber et al. (2023) later, provided efficient tools for evaluating ASP(Q) specifications providing empirical evidence of practical potential of ASP(Q).
However, ASP(Q) lacks a convenient method for encoding in an elegant way preference and optimization problems (Reference Buccafurri, Leone and RulloBuccafurri et al. 2000; Reference Schaefer and UmansSchaefer and Umans 2002).
In this paper, we address this issue by proposing an extension of ASP(Q) with weak constraints or ASP$^{\omega }$(Q), in short. Weak constraints were introduced in ASP by Buccafurri et al., (2000) to define preferences on answer sets. They are today a standard construct of ASP (Reference Calimeri, Faber, Gebser, Ianni, Kaminski, Krennwallner, Leone, Maratea, Ricca and SchaubCalimeri et al. 2020), used to model problems in the class $\Delta ^P_3$ (i.e., the class of problems that can be solved by a polynomial number of calls to a $\Sigma ^P_2$ oracle). In ASP$^{\omega }$(Q), weak constraints have dual purposes: expressing local optimization within quantified subprograms and modeling global optimization criteria. Both features increase the modeling efficacy of the language, which we demonstrate through example problems. Further, we investigate the computational properties of ASP(Q) programs with weak constraints and obtain complexity results that reveal some non-obvious characteristics of the new language. Among these, the key positive result states that ASP$^{\omega }$(Q) programs with $n$ alternating quantifiers can model problems complete for $\Delta _{n+1}^P$.
2 Answer Set Programming
We now recall Answer Set Programming (ASP) (Reference Gelfond and LifschitzGelfond and Lifschitz 1991; Reference Brewka, Eiter and TruszczynskiBrewka et al. 2011) and introduce the notation employed in this paper.
2.1 The syntax of ASP
Variables are strings starting with uppercase letters, and constants are non-negative integers or strings starting with lowercase letters. A term is either a variable or a constant. A standard atom is an expression of the form $p(t_1, \ldots, t_n)$, where $p$ is a predicate of arity $n$ and $t_1, \ldots, t_n$ are terms. A standard atom $p(t_1, \ldots, t_n)$ is ground if $t_1, \ldots, t_n$ are constants. A standard literal is an atom $p$ or its negation ${\sim } p$. An aggregate element is a pair $t_1,\ldots, t_n : \mathit{conj}$, where $t_1,\ldots, t_n$ is a non-empty list of terms, and $\mathit{conj}$ is a non-empty conjunction of standard literals. An aggregate atom is an expression $f\{e_1;\ldots ;e_n\} \prec T$, where $f \in \{\#count,\#sum\}$ is an aggregate function symbol, $\prec \ \in \{\lt, \leq, \gt, \geq, =\}$ is a comparison operator, $T$ is a term called the guard, and $e_1,\ldots, e_n$ are aggregate elements. An atom is either a standard atom or an aggregate atom. A literal is an atom (positive literal) or its negation (resp. negative literal). The complement of a literal $l$ is denoted by $\overline{l}$, and it is ${\sim } a$, if $l = a$, or $a$, if $l = {\sim } a$, where $a$ is an atom. For a set of literals $L$, $L^+$, and $L^{-}$ denote the set of positive and negative literals in $L$, respectively. A rule is an expression of the form:
where $m\geq k \geq 0$. Here $h$ is a standard atom or is empty, and all $b_i$ with $i\in [1,m]$ are atoms. We call $h$ the head and $b_1,\ldots, b_k, {\sim } b_{k+1}, \ldots, {\sim } b_m$ the body of the rule (1). If the head is empty, the rule is a hard constraint. If a rule (1) has a non-empty head and $m=0$, the rule is a fact. Let $r$ be a rule, $h_r$ denotes the head of $r$, and $B_r = B^+_r \cup B^-_r$ where $B^+_r$ (resp. $B^-_r$) is the set of all positive (resp. negative) literals in the body of $r$.
A weak constraint (Reference Buccafurri, Leone and RulloBuccafurri et al. 2000) is an expression of the form:
where, $m \geq k\geq 0$, $b_1,\ldots, b_k, b_{k+1}, \ldots, b_m$ are standard atoms, $w$ and $l$ are terms, and $T=t_1,\ldots, t_n$ is a tuple of terms with $n\geq 0$. Given an expression $\epsilon$ (atom, rule, weak constraint, etc.), $\mathcal{V}(\epsilon )$ denotes the set of variables appearing in $\epsilon$; $at(\epsilon )$ denotes the set of standard atoms appearing in $\epsilon$; and $\mathcal{P}(\epsilon )$ denotes the set of predicates appearing in $\epsilon$. For a rule $r$, the global variables of $r$ are all those variables appearing in $h_r$ or in some standard literal in $B_r$ or in the guard of some aggregates. A rule $r$ is safe if its global variables appear at least in one positive standard literal in $B_r$, and each variable appearing into an aggregate element $e$ either is global or appears in some positive literal of $e$ (Reference Ceri, Gottlob and TancaCeri et al. 1990; Reference Faber, Pfeifer and LeoneFaber et al. 2011); a weak constraint $v$ of the form (2) is safe if $\mathcal{V}(B_v^-) \subseteq \mathcal{V}(B_v^+)$ and $\mathcal{V}(\{w,l\}) \cup \mathcal{V}(T) \subseteq \mathcal{V}(B_v^+)$. A program $P$ is a set of safe rules and safe weak constraints. Given a program $P$, $\mathcal{R}(P)$ and $\mathcal{W}(P)$ denote the set of rules and weak constraints in $P$, respectively, and $\mathcal{H}(P)$ denotes the set of atoms appearing as heads of rules in $P$.
A choice rule (Reference Simons, Niemelä and SoininenSimons et al. 2002) is an expression of the form: $\{e_1;\ldots ;e_k\}\leftarrow l_1,\ldots, l_n,$ where each choice element $e_i$ is of the form $a^i:b^i_1,\ldots, b^i_{m_i}$, where $a^i$ is a standard atom, $m_i \geq 0$, and $b^i_1,\ldots, b^i_{m_i}$ is a conjunction of standard literals. For simplicity, choice rules can be seen as a shorthand for certain sets of rules. In particular, each choice element $e_i$ corresponds to: $a^i\leftarrow b^i_1,\ldots, b^i_{m_i},l_1,\ldots, l_n,\ {\sim } na^i$, $na^i\leftarrow b^i_1,\ldots, b^i_{m_i},l_1,\ldots, l_n,\ {\sim } a^i$ where $na^i$ denotes the standard atom obtained from $a^i$ by substituting the predicate of $a$, say $p$, with a fresh predicate $p^{\prime }$ not appearing anywhere else in the program.
2.2 The semantics of ASP
Assume a program $P$ is given. The Herbrand Universe is the set of all constants appearing in $P$ (or a singleton set consisting of any constant, if no constants appear in $P$) and is denoted by $ HU_{P}$; whereas the Herbrand Base, that is the set of possible ground standard atoms obtained from predicates in $P$ and constants in $ HU_{P}$, is denoted by $ HB_{P}$. Moreover, $ground(P)$ denotes the set of possible ground rules obtained from rules in $P$ by proper variable substitution with constants in $ HU_{P}$. An interpretation $I \subseteq HB_{P}$ is a set of standard atoms. A ground standard literal $l = a$ (resp. $l={\sim } a$) is true w.r.t. $I$ if $a \in I$ (resp. $a \notin I$), otherwise it is false. A conjunction $conj$ of literals is true w.r.t. $I$ if every literal in $conj$ is true w.r.t. $I$, otherwise it is false. Given a ground set of aggregate elements $S = \{e_1;\ldots ;e_n\}$, $eval(S,I)$ denotes the set of tuples of the form $(t_1,\ldots, t_m)$ such that there exists an aggregate element $e_i\in S$ of the form $t_1,\ldots, t_m: conj$ and $conj$ is true w.r.t. $I$; $I(S)$, instead, denotes the multi-set $[t_1\mid (t_1,\ldots, t_m) \in eval(S,I)]$. A ground aggregate literal of the form $f\{e_1;\ldots ;e_n\}\succ t$ (resp. ${\sim }\ f\{e_1;\ldots ;e_n\}\succ t$) is true w.r.t. $I$ if $f(I(\{e_1,\ldots, e_n\}))\succ t$ holds (resp. does not hold); otherwise it is false. An interpretation $I$ is a model of $P$ iff for each rule $r \in ground(P)$ either the head of $r$ is true w.r.t. $I$ or the body of $r$ is false w.r.t. $I$. Given an interpretation $I$, $P^I$ denotes the FLP-reduct (cfr. Reference Faber, Pfeifer and LeoneFaber et al. (2011)) obtained by removing all those rules in $P$ having their body false, and removing negative literals from the body of remaining rules. A model $I$ of $P$ is also an answer set of $P$ if for each $I^{\prime}\subset I$, $I^{\prime}$ is not a model of $P^I$. We write $AS({P})$ for the set of answer sets of $P$. A program $P$ is coherent if it has at least one answer set (i.e., $AS({P}) \neq \emptyset$); otherwise, $P$ is incoherent. For a program $P$ and an interpretation $I$, let the set of weak constraint violations be $ws(P,I) = \{(w,l,T) \mid \ \leftarrow _{w} b_1,\ldots, b_m\ [w@l,T] \in ground(\mathcal{W}(P)),$ $b_1,\ldots, b_m$ are true w.r.t. $I$, $w$, and $l$ are integers and $T$ is a tuple of ground terms$\}$, then the cost function of $P$ is $\mathcal{C}({P},{I},{l}) = \Sigma _{(w,l,T) \in ws(P,I)} w,$ for every integer $l$. Given a program $P$ and two interpretations $I_1$ and $I_2$, we say that that $I_1$ is dominated by $I_2$ if there is an integer $l$ such that $\mathcal{C}({P},{I_2},{l})\lt \mathcal{C}({P},{I_1},{l})$ and for all integers $l^{\prime } \gt l$, $\mathcal{C}({P},{I_2},{l^{\prime }}) = \mathcal{C}({P},{I_1},{l^{\prime }})$. An answer set $M\in AS({P})$ is an optimal answer set if it is not dominated by any $M^{\prime } \in AS({P})$. Intuitively, optimality amounts to minimizing the weight at the highest possible level, with each level used for tie breaking for the level directly above. The set $OptAS({P})\subseteq AS({P})$ denotes the set of optimal answer sets of $P$.
3 Quantified Answer Set Programming with weak constraints
In this section, we introduce an extension of Answer Set Programming with Quantifiers (ASP(Q)) (Reference Amendola, Ricca and TruszczynskiAmendola et al. 2019) that explicitly supports weak constraints (Reference Buccafurri, Leone and RulloBuccafurri et al. 2000) for modeling optimization problems.
It is worth noting that ASP(Q) can be used to model problems with model preferences and optimization criteria; however, this comes at the price of non-elegant and somehow redundant modeling. For this reason, in analogy to what has been done for ASP, it makes sense to contemplate weak constraints in ASP(Q).
A quantified ASP program with weak constraints (ASP$^{\omega }$(Q) program) $\Pi$ is of the form:
where, for each $i=1,\ldots, n$, $\Box _i \in \{ \exists ^{st}, \forall ^{st}\}$, $P_i$ is an ASP program possibly with weak constraints, $C$ is a (possibly empty) stratified program (Reference Ceri, Gottlob and TancaCeri et al. 1990) with constraints, and $C^w$ is a (possibly empty) set of weak constraints such that $B_{C^w} \subseteq B_{P_1}$. The number of quantifiers in $\Pi$ is denoted by $nQuant(\Pi )$.
As it was in the base language, ASP$^{\omega }$(Q) programs are quantified sequences of subprograms ending with a constraint program $C$. Differently from ASP(Q), in ASP$^{\omega }$(Q) weak constraints are allowed in the subprograms $P_i$ ($1 \leq i \leq n)$, that is, quantification is over optimal answer sets. Moreover, the global weak constraints subprogram $C^w$ is introduced to specify (global) optimality criteria on quantified answer sets.
Formally, the coherence of ASP$^{\omega }$(Q) programs is defined as follows:
• $\exists ^{st} P:C:C^w$ is coherent, if there exists $M\in OptAS({P})$ such that $C \cup \mathit{fix_{P}(M)}$ admits an answer set;
• $\forall ^{st} P:C:C^w$ is coherent, if for every $M\in OptAS({P})$, $C\cup \mathit{fix_{P}(M)}$ admits an answer set;
• $\exists ^{st} P\ \Pi$ is coherent, if there exists $M\in OptAS({P})$ such that $\Pi _{P,M}$ is coherent;
• $\forall ^{st} P\ \Pi$ is coherent, if for every $M\in OptAS({P})$, $\Pi _{P,M}$ is coherent.
where $\mathit{fix_{P}(M)}$ denotes the set of facts and constraints $\{ a \mid a\in M \cap HB_{P}\} \cup \{ \leftarrow a \mid a\in HB_{P} \setminus M\}$, and $\Pi _{P,M}$ denotes the ASP$^{\omega }$(Q) program of the form (3), where $P_1$ is replaced by $P_1\cup \mathit{fix_{P}(M)}$, that is, $\Pi _{P,M} =\Box _1 (P_1\cup \mathit{fix_{P}(M)})\ \Box _2 P_2\ \cdots \Box _n P_n : C:C^w.$
For an existential ASP$^{\omega }$(Q) program $\Pi$, $M \in OptAS({P_1})$ is a quantified answer set of $\Pi$, if $((\Box _2 P_2 \cdots \Box _n P_n : C):C^w)_{P_1,M}$ is coherent. We denote by $QAS(\Pi )$ the set of all quantified answer sets of $\Pi$.
To illustrate the definitions above, let us consider the following ASP$^{\omega }$(Q) program $\Pi = \exists ^{st} P_1 \forall ^{st} P_2 \cdots \exists ^{st} P_{n-1} \forall ^{st} P_n: C: C^w$. “Unwinding” the definition of coherence yields that $\Pi$ is coherent if there exists an optimal answer set $M_1$ of $P_1^{\prime}$ such that for every optimal answer set $M_2$ of $P_2^{\prime}$ there exists an optimal answer set $M_3$ of $P_3^{\prime}$, and so on until there exists an optimal answer set $M_{n-1}$ of $P_{n-1}^{\prime}$ such that for every optimal answer set $M_n$ of $P_n^{\prime}$, there exists an answer set of $C \cup \mathit{fix_{P_n^{\prime}}(M_n)}$, where $P_1^{\prime}=P_1$, and $P_i^{\prime}=P_i\cup \mathit{fix_{P_{i-1}^{\prime}}(M_{i-1})}$ with $i\geq 2$. Note that, as in ASP(Q), the constraint program $C$ has the role of selecting admissible solutions. Weak constraints could be allowed in $C$, but they would be redundant. Indeed, $C$, being stratified with constraints, admits at most one answer set, which would necessarily be optimal. In contrast, the local weak constraints (possibly) occurring in subprograms $P_i$ are essential for determining coherence.
Example 3.1 (Impact of local weak constraints). Let $\Pi _1 = \exists P_1 \forall P_2 : C$, and $\Pi _2 = \exists Q_1 \forall Q_2 : C$, where $C = \{\leftarrow d,f\}$ and also:
Note that, $\Pi _2$ can be obtained from $\Pi _1$ by discarding weak constraints. First, we observe that $\Pi _1$ is incoherent. Indeed, the optimal answer sets of $P_1$ are $OptAS({P_1}) = \{\{a,d\},\{b,d\}\}$. By applying the definition of coherence, when we consider $M = \{a,d\}$, we have that $OptAS({P_2^{\prime }}) = \{\{e,a,d\},\{f,a,d\} \}$. Once we set $M^{\prime } = \{f,a,d\}$, the program $C^{\prime }$ is not coherent, and so $M = \{a,d\}$ is not a quantified answer set. Analogously, when we consider the second answer set of $P_1$, that is, $M = \{b,d\}$, we have that $OptAS({P_2^{\prime }}) =\{\{e,a,d\},\{f,a,d\} \}$. But, when we set $M^{\prime } = \{f,b,d\}$, the program $C^{\prime }$ is not coherent. Thus, $\Pi _1$ is incoherent. On the contrary, $\Pi _2$ is coherent. Indeed, $AS({Q_1}) = \{\{a,d\},\{b,d\},\{a,c\},\{b,c\}\} = OptAS({P_1}) \cup \{\{a,c\},\{b,c\}\}$. The first two, we know, do not lead to a quantified answer set. But, when we set $M = \{a,c\}$, since $d$ is false, it happens that $C^{\prime }$ is coherent (e.g., when we consider the answer set $\{e,a,c\}$ of $Q_2^{\prime }$). Thus, local weak constraints can affect coherence by discarding not optimal candidates.
Global weak constraints in $C^w$ do not affect coherence, but they serve to define optimality criteria across quantified answer sets. For this reason, we require that $C^w$ is defined over the same Herbrand base of $P_1$. Furthermore, note that $C^w$ plays no role in universal ASP$^{\omega }$(Q) programs, where coherence is the sole meaningful task.
Given an existential ASP$^{\omega }$(Q) program $\Pi$ and two quantified answer sets $Q_1, Q_2 \in QAS(\Pi )$, we say that $Q_1$ is dominated by $Q_2$ if there exists an integer $l$ such that $\mathcal{C}({P_1^*},{Q_2},{l})\lt \mathcal{C}({P_1^*},{Q_1},{l})$ and for every integer $l^{\prime } \gt l$, $\mathcal{C}({P_1^*},{Q_2},{l}) = \mathcal{C}({P_1^*},{Q_1},{l})$, where $P_1^* = P_1 \cup C^w$. An optimal quantified answer set is a quantified answer set $Q \in QAS(\Pi )$ that is not dominated by any $Q^{\prime } \in QAS(\Pi )$.
Example 3.2 (Optimal quantified answer sets) Let $\Pi = \exists P_1 \forall P_2 : C :{C^w}$ be such that:
Given that $QAS(\Pi ) = \{\{\},\{b\},\{c\},\{b,c\}\}$, we have that: the cost of $\{\}$ is 3, since it violates all weak constraints in $C^{w}$; {b} and {c} cost 2, since $\{b\}$ (resp. $\{c\}$) violates the first and the third (resp. second) weak constraint; and, {b,c} costs 1, because it only violates the first weak constraint.
Let $\Pi = \Box _1 P_1 \ldots \Box _n P_n$ be an ASP$^{\omega }$(Q) program. $\Pi$ satisfies the stratified definition assumption if for each $1\leq i\leq n$, $\mathcal{H}(P_i)\cap at(P_j) = \emptyset$, with $1\leq j \lt i$. In what follows, we assume w.l.o.g. that ASP$^{\omega }$(Q) programs satisfy the stratified definition assumption.
It is worth noting that, standard ASP(Q) allows for the specification of preferences and optimization. The basic pattern for obtaining optimal models in ASP(Q) is to “clone” a program and use an additional quantifier over its answer sets. This allows us to compare pairs of answer sets and, by means of a final constraint program, to select optimal ones. For example, assume program $P_1$ models the candidate solutions of a problem and, for the sake of illustration, that we are interested in those minimizing the number of atoms of the form $a(X)$. This desideratum can be modeled directly in standard ASP by adding a weak constraint $\leftarrow _w a(X) [1@1,X]$. On the other hand, in ASP(Q) we can model it with the program $\exists P_1 \forall P_2 : C$ such that $P_2=clone^s(P_1)$, and $C = \{ \leftarrow \#count\{X: a(X)\}=K, \#count\{X:a^s(X)\}\lt K\}$. Here, we are comparing the answer sets of $P_1$ with all their “clones”, and keep those that contain a smaller (or equal) number of atoms of the form $a(X)$. This pattern is easy to apply, but it is redundant; also note that checking coherence of an ASP(Q) program with two quantifiers is in $\Sigma _2^p$ (Reference Amendola, Ricca and TruszczynskiAmendola et al. 2019), whereas optimal answer set checking of a program with weak constraints is in $\Delta _{2}^p$ (Reference Buccafurri, Leone and RulloBuccafurri et al. 2000). These observations motivate the introduction of weak constraints in ASP(Q), which will be further strengthened in the following sections.
4 Modeling examples
We showcase the modeling capabilities of ASP$^{\omega }$(Q) by considering two example scenarios where both global and local weak constraints play a role: the Minmax Clique problem (Reference Cao, Du, Gao, Wan and PardalosCao et al. 1995), and Logic-Based Abduction (Reference Eiter and GottlobEiter and Gottlob 1995a).
4.1 Minmax Clique problem
Minimax problems are prevalent across numerous research domains. Here, we focus on the Minmax Clique problem, as defined by Reference Ko and LinKo (1995), although other minimax variants can be also modeled.
Given a graph $G = \langle V,E \rangle$, let $I$ and $J$ be two finite sets of indices, and $(A_{i,j})_{i\in I,j\in J}$ a partition of $V$. We write $J^I$ for the set of all total functions from $I$ to $J$. For every total function $f\colon I\rightarrow J$ we denote by $G_f$ the subgraph of $G$ induced by $\bigcup _{i\in I} A_{i,f(i)}$. The Minmax Clique optimization problem is defined as follows: Given a graph $G$, sets of indices $I$ and $J$, a partition $(A_{i,j})_{i\in I,j\in J}$, find the integer $k$ ($k \leq |V|)$, such that
The following program of the form $\Pi = \exists P_1 \exists P_2 : C : C^w$, encodes the problem:
The input is modeled in program $P_1$ as follows: Node partitions are encoded as facts of the form $v(i,j,x)$ denoting that a node $x$ belongs to the partition $a \in A_{i,j}$; facts of the form $inI(i)$ and $inJ(j)$ model indexes $i\in I$ and $j \in J$, respectively; and, the set of edges $E$ is encoded as facts of the form $e(x,y)$ denoting that the edge $(x,y) \in E$. The first choice rule in $P_1$ guesses one total function $f : I \rightarrow J$, which is encoded by binary predicate $f(i,j)$ denoting that the guessed function maps $i$ to $j$. The second choice rule guesses one possible value for $k$, modeled by predicate $valK(x)$. Thus, there is an answer set of program $P_1$ for each total function $f$ and a possible value for $k$.
Given an answer set of $P_1$, program $P_2$ computes the maximum clique of the subgraph of $G$ induced by $f$, that is, $G_f$. To this end, the first rule computes the nodes of $G_f$ in predicate $n_f(X)$, by joining predicate $f(I,J)$ and $v(I,J,X)$. The second rule computes the edges of $G_f$ considering the edges of $G$ that connect nodes in $G_f$. The largest clique in $G_t$ is computed by a $(i)$ choice rule that guesses a set of nodes (in predicate $inClique$), $(ii)$ a constraint requiring that nodes are mutually connected, and $(iii)$ a weak constraint that minimizes the number of nodes that are not part of the clique. At this point, the program $C$ verifies that the size of the largest clique in the answer set of $P_2$ is exactly the value for $k$ in the current answer set of $P_1$. Thus, each quantified answer set of $\Pi$ models a function $f$, such that the largest clique of induced graph $G_f$ has size $k$. Now, the global weak constraints in $C^w$ prefer the ones that give the smallest value of $k$.
The decision version of this problem is $\Pi _2^p$-complete (Reference Ko and LinKo 1995). Thus, a solution to the Minmax Clique can be computed by a logarithmic number of calls to an oracle in $\Pi _2^p$, so the problem belongs to $\Theta _3^P$ (Reference WagnerWagner 1990). It is (somehow) surprising that we could write a natural encoding without alternating quantifiers (indeed, $\Pi$ features two existential quantifiers). This phenomenon is more general. We will return to it in Section 6.
Logic-Based Abduction Abduction plays a prominent role in Artificial Intelligence as an essential common-sense reasoning mechanism (Reference MorganMorgan 1971; Reference PoplePople 1973).
In this paper we focus on the Propositional Abduction Problem (PAP) (Reference Eiter and GottlobEiter and Gottlob 1995a). The PAP is defined as a tuple of the form $\mathcal{A}=\langle V,T,H,M \rangle$, where $V$ is a set of variables, $T$ is a consistent propositional logic theory over variables in $V$, $H \subseteq V$ is a set of hypotheses, and $M \subseteq V$ is a set of manifestations. A solution to the PAP problem $\mathcal{A}$ is a set $S\subseteq H$ such that $T\cup S$ is consistent and $T \cup S \vDash M$. Solutions to $\mathcal{A}$, denoted by $sol(\mathcal{A})$, can be ordered by means of some preference relation $\lt$. The set of optimal solutions to $\mathcal{A}$ is defined as $sol_{\lt }(\mathcal{A}) =$ $\{S \in sol(\mathcal{A}) \mid \nexists$ $S^{\prime}\in sol(\mathcal{A}) \textit{ such that } \vert S^{\prime}\vert \lt \vert S\vert \}$. A hypothesis $h \in H$ is relevant if $h$ appears at least in one solution $S \in sol_{\lt }(\mathcal{A})$. The main reasoning tasks for PAP are beyond NP (Reference Eiter and GottlobEiter and Gottlob 1995a).
In the following, we assume w.l.o.g. that the theory $T$ is a boolean 3-CNF formula over variables in $V$. Recall that, a 3-CNF formula is a conjunction of clauses $C_1 \wedge \ldots \wedge C_n$, where each clause is of the form $C_i = l_i^1 \vee l_i^2 \vee l_i^3$, and each literal $l_i^j$ (with $1 \leq j \leq 3$) is either a variable $a \in V$ or its (classical) negation $\neg a$.
Given a PAP problem $\mathcal{A}=\langle V,T,H,M \rangle$ we aim at computing a solution $S \in sol_{\lt }(\mathcal{A})$. To this end, we use an ASP$^{\omega }$(Q) program of the form $\exists P_1 \forall P_2: C: C^w$, where:
The aim of $P_1$ is to compute a candidate solution $S \subseteq H$ such that $T \cup S$ is consistent; $P_2$ and $C$ ensure that $T \cup S \vDash M$, and $C^w$ ensures that $S$ is cardinality minimal. More in detail, in program $P_1$, the variables $V$, hypothesis $H$, and manifestations $M$, are encoded by means of facts of the unary predicates $v$, $h$, and $m$, respectively. The formula $T$ is encoded by facts of the form $lit(C,x,t)$ (resp. $lit(C,x,f)$) denoting that a variable $x$ occurs in a positive (resp. negative) literal in clause $C$. Then, to ease the presentation, we compute in a unary predicate $cl$ the set of clauses. The first choice rule guesses a solution (a subset of $H$), and the last five rules verify the existence of a truth assignment $\tau$ for variables in $V$, encoded with atoms of the form $tau(x,t)$ (resp. $tau(x,f)$) denoting that a variable $x$ is true (resp. false), such that $unsatTS$ is not derived (last constraint). Note that, $unsatTS$ is derived either if a clause is not satisfied or if a hypothesis is not part of the assignment. Thus, the assignment $\tau$ satisfies $T \cup S$, that is, $T \cup S$ is consistent. It follows that the answer sets of $P_1$ correspond to candidate solutions $S \subseteq H$ such that $T \cup S$ is consistent. Given a candidate solution, program $P_2$ has one answer set for each truth assignment $\tau ^{\prime}$ that satisfies $T \cup S$, and the program $C$ checks that all such $\tau ^{\prime}$ satisfy also the manifestations in $M$. Thus, every $M \in QAS(\Pi )$ encodes a solution $S \in sol(\mathcal{A})$. The weak constraint in $C^w$ ensures we single out cardinality minimal solutions by minimizing the extension of predicate $s$. Finally, let $h$ be a hypothesis, we aim at checking that $h$ is relevant, that is, $h \in S$ s.t. $S \in sol_{\lt }(\mathcal{A})$. We solve this task by taking the program $\Pi$ above that computes an optimal solution and adding to $C^w$ an additional (ground) weak constraint, namely $\leftarrow _{w} {\sim } s(h)\ \ [1@0]$. Intuitively, optimal solutions not containing $h$ violate the weak constraint, so if any optimal answer set contains $s(h)$ then $h$ is relevant.
4.2 Remark
Checking that a solution to a PAP is minimal belongs to $\Pi _2^p$ (Reference Eiter and GottlobEiter and Gottlob 1995a), so the task we have considered so far is complete for $\Theta ^P_3$ (Reference WagnerWagner 1990). The programs above feature only two quantifiers, whereas alternative encodings in ASP(Q) (i.e., without weak constraints) would have required more. Moreover, we observe that the programs above are rather natural renderings of the definition of the problems that showcase the benefit of modeling optimization in subprograms and at the global level.
5 Rewriting into plain ASP(Q)
In this section, we describe a mapping that transforms an ASP$^{\omega }$(Q) program $\Pi$ into a plain (i.e., without weak constraints) quantifier-alternating ASP(Q) program $\Pi ^{\prime}$ that is coherent iff $\Pi$ is coherent. This transformation is crucial for enabling the study of the complexity of the primary reasoning tasks of ASP$^{\omega }$(Q). Additionally, it could be applied in an implementation that extends current solvers such as that by Reference Faber, Mazzotta and RiccaFaber et al. (2023).
The transformation works by calling a number of intermediate rewritings until none of them can be applied anymore. They $(i)$ absorb consecutive quantifiers of the same kind; and, $(ii)$ eliminate weak constraints from a subprogram by encoding the optimality check in the subsequent subprograms. We first introduce some useful definitions. Given program $\Pi$ of the form (3) we say that two consecutive subprograms $P_i$ and $P_{i+1}$ are alternating if $\Box _i \neq \Box _{i+1}$, and are uniform otherwise. A program $\Pi$ is quantifier-alternating if $\Box _i \neq \Box _{i+1}$ for $1 \leq i \lt n$. A subprogram $P_i$ is plain if it contains no weak constraint $\mathcal{W}(P_i) = \emptyset$, and $\Pi$ is plain if both all $P_i$ are plain, and $C^w = \emptyset$. In the following, we assume that $\Pi$ is an ASP$^{\omega }$(Q) program of the form (3).
5.1 Rewriting uniform plain subprograms
Two plain uniform subprograms can be absorbed in a single equi-coherent subprogram by the transformation $col_1(\cdot )$ defined as follows.
Lemma 1 (Correctness col1(.) transformation) Let program $\Pi$ be such that $n \geq 2$ and the first two subprograms are plain and uniform, that is, $\Box _1 = \Box _2$, and $\mathcal{W}(P_1) = \mathcal{W}(P_{2})=\emptyset$, then $\Pi$ is coherent if and only if $col_1(\Pi ) = \Box _1 P_1 \cup P_{2}\Box _{3} P_{3}\ldots \Box _n P_n:C$ is coherent.
Intuitively, if the first two subprograms of $\Pi$ are uniform and plain then $\Pi$ can be reformulated into an equi-coherent (i.e., $\Pi$ is coherent iff $col_1(\Pi )$ is coherent) program with one fewer quantifier.
5.2 Rewriting uniform notplain-plain subprograms
Next transformations apply to pairs of uniform subprograms $P_1,P_2$ such that $P_1$ is not plain and $P_2$ is plain. To this end, we first define the $or(\cdot, \cdot )$ transformation. Let $P$ be an ASP program, and $l$ be a fresh atom not appearing in $P$, then $or(P,l) = \{H_r\leftarrow B_r,{\sim } l \mid r \in P\}$.
Observation 1 (Trivial model existence) Let $P$ be an ASP program, and $l$ be a fresh literal not appearing in $P$, then the following hold: $\{l\}$ is the unique answer set of $or(P,l)\cup \{l\leftarrow \}$; and $AS({or(P,l)\cup \{\leftarrow l\}})=AS({P})$.
Intuitively, if the fact $l\leftarrow$ is added to $or(P,l)$ then the interpretation $I=\{l\}$ trivially satisfies all the rules and is minimal, thus it is an answer set. On the other hand, if we add the constraint $\leftarrow l$, requiring that $l$ is false in any answer set, then the resulting program behaves precisely as $P$ since literal ${\sim } l$ is trivially true in all the rule bodies.
We are now ready to introduce the next rewriting function $col_2(\cdot )$. This transformation allows to absorbe a plain existential subprogram into a non plain existential one, thus reducing by one the number of quantifiers of the input ASP$^{\omega }$(Q) program.
Definition 1 (Collapse notplain-plain existential subprograms) Let $\Pi$ be an ASP$^{\omega }$(Q) program of the form $\exists P_1 \exists P_2 \ldots \Box _n P_n: C$, where $\mathcal{W}(P_1)\neq \emptyset$, $\mathcal{W}(P_i)=\emptyset$, with $1\lt i\leq n$, and $\Box _i \neq \Box _{i+1}$ with $1\lt i\lt n$, then:
where $W = \{\{unsat\}\leftarrow \} \cup \{\leftarrow _{w} unsat\ [1@l_{min}-1]\}$, with $l_{min}$ be the lowest level in $\mathcal{W}(P_1)$ and $unsat$ is a fresh symbol not appearing anywhere else, and $P_3^{\prime} = or(P_3,unsat)$.
Lemma 2 (Correctness col2(.) transformation) Let $\Pi$ be an ASP$^{\omega }$(Q) program of the form $\exists P_1 \exists P_2 \ldots \Box _n P_n: C$, where $\mathcal{W}(P_1)\neq \emptyset$, $\mathcal{W}(P_i)=\emptyset$, with $1\lt i\leq n$, and $\Box _i \neq \Box _{i+1}$ with $1\lt i\lt n$. Then $\Pi$ is coherent if and only if $col_2(\Pi )$ is coherent.
A similar procedure is introduced for the universal case.
Definition 2 (Collapse notplain-plain universal subprograms) Let $\Pi$ be an ASP$^{\omega }$(Q) program of the form $\forall P_1 \forall P_2 \ldots \Box _n P_n: C$, where $\mathcal{W}(P_1)\neq \emptyset$, $\mathcal{W}(P_i)=\emptyset$, with $1\lt i\leq n$, and $\Box _i \neq \Box _{i+1}$ with $1\lt i\lt n$, then:
where $W = \{\{unsat\}\leftarrow \} \cup \{\leftarrow _{w} unsat\ [1@l_{min}-1]\}$, with $l_{min}$ be the lowest level in $\mathcal{W}(P_1)$ and $unsat$ is a fresh symbol not appearing anywhere else, and $P_3^{\prime} = or(P_3,unsat)$.
Lemma 3 (Correctness col3(.) transformation) Let $\Pi$ be an ASP$^{\omega }$(Q) program of the form $\forall P_1 \forall P_2 \ldots \Box _n P_n: C$, where $\mathcal{W}(P_1)\neq \emptyset$, $\mathcal{W}(P_i)=\emptyset$, with $1\lt i\leq n$, and $\Box _i \neq \Box _{i+1}$ with $1\lt i\lt n$. Then $\Pi$ is coherent if and only if $col_3(\Pi )$ is coherent.
Roughly, if the first two subprograms of $\Pi$ are uniform, $P_1$ is not plain, $P_2$ is plain, and the remainder of the program is alternating, then $\Pi$ can be reformulated into an equi-coherent program with one fewer quantifier.
5.3 Rewrite subprograms with weak constraints
The next transformations have the role of eliminating weak constraints from a subprogram by encoding the optimality check in the subsequent subprograms. To this end, we define the $check(\cdot )$ transformation that is useful for simulating the cost comparison of two answer sets of an ASP program $P$.
First, let $\epsilon$ be an ASP expression and $s$ an alphanumeric string. We define $clone^s(\epsilon )$ as the expression obtained by substituting all occurrences of each predicate $p$ in $\epsilon$ with $p^s$ which is a fresh predicate $p^s$ of the same arity.
Definition 3 (Transform weak constraints) Let $P$ be an ASP program with weak constraints, then
where each $w_{c_i}$ is an aggregate element of the form $W,T : v_{c_i}(W,L,T)$.
Thus, the first two rules compute in predicate $cl_{P}$ the cost of an answer set of $P$ w.r.t. his weak constraints, and the following two rules do the same for $clone^o(P)$. Then, the last four rules derive $dom_{P}$ for each answer set of $P$ that is dominated by $clone^o(P)$.
We now introduce how to translate away weak constraints from a subprogram.
Definition 4 (Transform existential not-plain subprogram) Let $\Pi$ be an existential alternating ASP$^{\omega }$(Q) program such that all subprograms are plain except the first one (i.e., $\mathcal{W}(P_1)\neq \emptyset$, $\mathcal{W}(P_i)=\emptyset$, $1 \lt i \leq n$), then
where $P_2^{\prime} = clone^o(\mathcal{R}(P_1))\cup check(P_1) \cup or(P_2,dom_{P_1})$.
Lemma 4 (Correctness col4(.) transformation) Let $\Pi$ be an existential alternating ASP$^{\omega }$(Q) program such that all subprograms are plain except the first, then $\Pi$ is coherent if and only if $col_4(\Pi )$ is coherent.
Intuitively, for a pair $M_1,M_2 \in AS({P_1})$, $M_1$ is dominated by $M_2$ if and only if $check(P)\cup \mathit{fix_{P}(M_1)}\cup clone^o(\mathit{fix_{P}(M_2)})$ admits an answer set $M$ such that $dom_{P} \in M$. Thus, coherence is preserved since $dom_{P_1}$ discards not optimal candidates such as $M_1$.
A similar procedure can be defined for universal subprogram.
Definition 5 (Transform universal not-plain subprogram). Let $\Pi$ be a universal alternating ASP$^{\omega }$(Q) program such that all subprograms are plain except the first one (i.e., $\mathcal{W}(P_1)\neq \emptyset$, $\mathcal{W}(P_i)=\emptyset$ $1 \lt i \leq n$), then
where $P_2^{\prime} = clone^o(\mathcal{R}(P_1))\cup check(P_1) \cup or(P_2,dom_{P_1})$.
Lemma 5 (Correctness col5(.) transformation) Let $\Pi$ be a universal alternating ASP$^{\omega }$(Q) program such that all subprograms are plain except the first, then $\Pi$ is coherent if and only if $col_5(\Pi )$ is coherent.
Translate ASP $^{\omega }$(Q) to ASP(Q).
Algorithm 1 defines a procedure for rewriting an ASP$^{\omega }$(Q) program $\Pi$ into an ASP(Q) program $\Pi ^{\prime}$, made of at most $n+1$ alternating quantifiers, such that $\Pi$ is coherent if and only if $\Pi ^{\prime}$ is coherent. In Algorithm1, we make use of some (sub)procedures and dedicated notation. In detail, for a program $\Pi$ of the form (3), $\Pi ^{\geq i}$ denotes the i-th suffix program $\Box _i P_i \ldots \Box _n P_n : C$, with $1\leq i \leq n$ (i.e., the one obtained from $\Pi$ removing the first $i-1$ quantifiers and subprograms). Moreover, the procedure $removeGlobal(\Pi )$ builds an ASP(Q) program from a plain one in input (roughly, it removes the global constraint program $C^w$). Given two programs $\Pi _1$ and $\Pi _2$, $replace(\Pi _1,i,\Pi _2)$ returns the ASP$^{\omega }$(Q) program obtained from $\Pi _1$ by replacing program $\Pi _1^{\geq i}$ by $\Pi _2$, for example $replace(\exists P_1 \forall P2 \exists P_3 : C,\ 2,\ \exists P_4 :C)$ returns $\exists P_1 \exists P_4 :C$.
In order to obtain a quantifier alternating ASP(Q) program from the input $\Pi$, Algorithm1 generates a sequence of programs by applying at each step one of the $col_{T}$ transformations. With a little abuse of notation, we write that a program is of type $T$ ($T \in [1,5]$) if it satisfies the conditions for applying the rewriting $col_{T}$ defined above (cfr., Lemmas1–5). For example, when type $T=1$ we check that the first two subprograms of $\Pi$ are plain and uniform so that $col_{1}$ can be applied to program $\Pi$. In detail, at each iteration $s$, the innermost suffix program that is of current type $T$ is identified, say $\Pi _s^{\geq i}$. Then the next program $\Pi _{s+1}$ is built by replacing $\Pi _s^{\gt i}$ by $col_{T}(\Pi _s^{\gt i})$. Algorithm1 terminates when no transformation can be applied, and returns the program $removeGlobal(\Pi _s)$.
Theorem 1 (ASPΩ(Q) to ASP(Q) convergence and correctness) Given program $\Pi$, Algorithm 1 terminates and returns an alternating ASP(Q) program $\Pi ^{\prime}$ that is $\Pi ^{\prime}$ is coherent iff $\Pi$ is coherent, and $nQuant(\Pi ^{\prime}) \leq nQuant(\Pi ) + 1$.
Intuitively, the proof follows by observing that Algorithm1 repeatedly simplifies the input by applying $col_T(\cdot )$ procedures ($T\in [1,5])$ until none can be applied. This condition happens when the resulting $\Pi ^{\prime}$ is plain alternating. Equi-coherence follows from Lemmas1-5. Unless the innermost subprogram of $\Pi$ is not plain, no additional quantifier is added by Algorithm1, so $nQuant(\Pi ^{\prime}) \leq nQuant(\Pi ) + 1$, hence the proof follows.
Proof At each step $s$, Algorithm1 searches for the innermost suffix subprogram $\Pi _s^{\geq i}$ such that either $(i)$ $\Pi _s^{\geq i}$ begins with two consecutive quantifiers of the same type (i.e., it is of type 1,2 or 3), or $(ii)$ $\Pi _s^{\geq i}$ begins with a not plain subprogram followed by a quantifier alternating sequence of plain subprograms (i.e., it is of type 4 or 5). In case $(i)$, one of the subprocedures $col_1, col_2$, or $col_3$ is applied, which results in the computation of program $\Pi _{s+1}$ having one less pair of uniform subprograms (i.e., $nQuant(\Pi _{s+1}) = nQuant(\Pi _{s})-1$). In case $(ii)$, one of the subprocedures $col_4, col_5$ is applied, which results in the computation of program $\Pi _{s+1}$ such that its $i$-th subprogram is plain. After applying $col_4, col_5$ we have that $nQuant(\Pi _{s+1}) \leq nQuant(\Pi _{s})+1$, indeed if $i=nQuant(\Pi _s)$ one more quantifier subprogram is added. So the algorithm continues until neither condition $(i)$ nor $(ii)$ holds. This happens when $\Pi _{s}$ is a plain quantifier alternating program. Note that, unless the innermost subprogram of $\Pi$ is not plain, no additional quantifier is added during the execution of Algorithm1 (if anything, some may be removed), so $nQuant(\Pi ^{\prime}) \leq nQuant(\Pi ) + 1$.
Additionally, it is easy to see that quantified answer set of existential programs can be preserved if only atoms of the first subprogram are made visible.
Corollary 1.1 (Quantified answer set preservation) Let $\Pi$ be an existential ASP$^{\omega }$(Q) program of the form (3) and $\Pi ^{\prime}$ be the result of the application of Algorithm 1 on $\Pi$. Then, $M \in QAS(\Pi )$ if and only if there exists $M^{\prime} \in QAS(\Pi ^{\prime})$ such that $M^{\prime}\cap HB_{P_1} = M$.
The Corollary above follows (straightforwardly) from Theorem1 because the only cases in which the first subprogram $P_1$ of $\Pi$ undergoes a modification during the rewriting is through a collapse operation, which, by definition, does not “filter” out any answer sets of the modified program. Since coherence is preserved by Theorem1, a quantified answer set of $\Pi$ can be obtained from a quantified answer set of $\Pi ^{\prime}$ by projecting out atoms that are not in $HB_{P_1}$ (i.e., those not in the “original” $P_1$).
6 Complexity issues
In this section, we investigate the complexity of problems related to ASP$^{\omega }$(Q) programs. We first study the complexity of the coherence problem. For that problem, global constraints can be ignored. Interestingly, the presence of local constraints leads to some unexpected phenomena. Next, we study the complexity of problems concerning membership of atoms in optimal answer sets. For this study, we restrict attention to existential programs with only global constraints.
Theorem 2 (Upper bound) The coherence problem of an ASP$^{\omega }$(Q) program $\Pi$ is in: $(i)$ $\Sigma _{n{+1}}^p$ for existential programs, and $(ii)$ $\Pi _{n{+1}}^p$ for universal programs, where $n=nQuant(\Pi )$.
Proof Let $\Pi ^{\prime}$ be the result of applying Algorithm1 to $\Pi$. Then, $\Pi ^{\prime}$ is a quantifier-alternating plain program with at most $n=nQuant(\Pi )+1$ quantifiers that is coherent iff $\Pi$ is coherent (Theorem1). Thesis follows from Theorem3 in the paper by Amendola et al., (2019).
Theorem 3 (Lower bound) The coherence problem of an ASP$^{\omega }$(Q) program is hard for $(i)$ $\Sigma _{n}^p$ for existential programs, and hard for $(ii)$ $\Pi _{n}^p$ for universal programs, where $n = nQuant(\Pi )$.
The result above follows trivially from the observation that any quantifier-alternating ASP(Q) program with $n$ quantifiers is a plain ASP$^{\omega }$(Q) program where $C^w=\emptyset$.
The lower and upper bounds offered by the two previous results do not meet in the general case. However, for some classes of ASP$^{\omega }$(Q) programs they do, which leads to completeness results. For instance, note that Algorithm1 produces a quantifier-alternating plain ASP(Q) program with at most $n$ quantifiers when the last subprogram is plain.
Corollary 3.1 (First completeness result) The coherence problem of an ASP$^{\omega }$(Q) program where the last subprogram is plain (i.e., $\mathcal{W}(P_n)=\emptyset$) is $(i)$ $\Sigma _{n}^p$-complete for existential programs, and $(ii)$ $\Pi _{n}^p$-complete for universal programs, where $n = nQuant(\Pi )$.
Proof. (Sketch) The assertion follows from Theorem3 in the paper by Reference Amendola, Ricca and TruszczynskiAmendola et al. (2019) and from properties of Algorithm1.
Note that, in plain ASP(Q) (as well as in related formalisms such as those considered by Reference StockmeyerStockmeyer (1976) and Reference Fandinno, Laferrière, Romero, Schaub and SonFandinno et al. (2021)), the complexity of coherence correlates directly with the number of quantifier alternations (Reference Amendola, Ricca and TruszczynskiAmendola et al. 2019). Perhaps somewhat unexpectedly at first glance, it is not the case of ASP$^{\omega }$(Q). There, when local constraints are present, one can “go up” one level with two consecutive quantifiers of the same kind. This phenomenon is exemplified below.
Theorem 4 (Second completeness results) Deciding coherence of uniform existential ASP$^{\omega }$(Q) programs with two quantifiers (i.e., $n=2$) such that $P_2$ is not plain is $\Sigma _2^p$-complete.
Proof. (Sketch) (Membership) By applying Algorithm1 on a uniform existential ASP$^{\omega }$(Q) programs with two quantifiers where the program $P_2$ is not plain, we obtain an equi-coherent ASP(Q) of the form $\exists P_1^{\prime} \forall P_2^{\prime}:C^{\prime}$. Thus, the membership to $\Sigma _2^P$ follows from Theorem3 of Reference Amendola, Ricca and TruszczynskiAmendola et al. (2019).
Hardness is proved by a reduction of an existential 2QBF in DNF by adapting the QBF encoding in ASP(Q) from Theorem2 of Reference Amendola, Ricca and TruszczynskiAmendola et al. (2019). In detail, a weak constraint in $P_2$ simulates the forall quantifier by preferring counterexamples that are later excluded by the final constraint $C$.
The proof offers insights into this phenomenon, revealing that the second quantifier, governing optimal answer sets, essentially “hides” a universal quantifier. The following result closes the picture for uniform plain programs with two existential quantifiers.
Proposition 1 (Third completeness results) Deciding coherence of plain uniform ASP$^{\omega }$(Q) programs with $2$ quantifiers is $(i)$ NP-complete for existential programs; and $(i)$ coNP-complete for universal programs.
The result follows trivially from Lemma1, once we observe that one application of $col_1$ builds an equi-coherent program with one quantifier.
We will now turn our attention to problems involving optimal quantified answer sets.
Observe that, as for the case of plain ASP, verifying the existence of an optimal quantified answer set has the same complexity as verifying the existence of a quantified answer set. Indeed, if a quantified answer set exists, there is certainly an optimal one. Thus, a more interesting task is to verify whether an atom $a$ belongs to some optimal quantified answer sets. (This is important as it supports brave reasoning as well as allows one to compute an optimal quantified answer set, if one exists).
We will now study this problem for plain ASP$^{\omega }$(Q) programs with global constraints that seem to be especially relevant to practical applications. Similarly to what was proved by Reference Buccafurri, Leone and RulloBuccafurri et al. (2000) for ASP, the task in question results in a jump in complexity. Specifically, it elevates the complexity to being complete for $\Delta _n^P$ in the general case.
Theorem 5 (Fourth completeness results) Deciding whether an atom $a$ belongs to an optimal quantified answer set of a plain alternating existential ASP$^{\omega }$(Q) program with $n$ quantifiers is $\Delta _{n+1}^P$-complete.
Proof. (Sketch) (Hardness) Hardness can be proved by resorting the observations used in the proof by Buccafurri et al., (2000). More precisely, let $X_1,\ldots, X_n$ be disjoint sets of propositional variables, and $\Phi$ be a QBF formula of the form $\forall X_2 \exists X_3 \ldots \mathcal{Q} X_n\ \phi$, where each $Q\in \{\exists, \forall \}$, and $\phi$ is a formula over variables in $X_1,\ldots, X_n$ in 3-DNF if $n$ is even, otherwise it is in 3-CNF, and $X_1 = \{x_1,\ldots, x_m\}$. Deciding whether the lexicographically minimum truth assignment $\tau$ of variables in $X_1$, such that $\forall X_2 \exists X_3 \ldots \mathcal{Q} X_n\ \phi _{\tau }$ is satisfied (assuming such $\tau$ exists), satisfies the condition $\tau (x_m)=\top$ is a $\Delta _{n+1}^P$-complete problem (Reference KrentelKrentel 1992). Such a problem can be encoded as a plain alternating ASP$^{\omega }$(Q) program $\Pi$ with $n$ quantifiers such that an atom $x_m$ appears in some optimal quantified answer set of $\Pi$ if and only if the answer to the problem is “yes”.
(Membership) As observed by Reference Buccafurri, Leone and RulloBuccafurri et al. (2000) and Reference Simons, Niemelä and SoininenSimons et al. (2002), an optimal solution can be obtained with binary search on the value of maximum possible cost, namely $k$. Since $k$ can be exponential in the general case, then an optimal quantified answer set of $\Pi$ can be obtained with a polynomial number of calls to the oracle in $\Sigma _n^P$, with $n=nQuant(\Pi )$. Finally, an extra oracle call checks that the atom $a$ appears in some optimal quantified answer sets.
Another interesting result regards a specific class of plain ASP$^{\omega }$(Q) programs, namely those programs in which there is only one level and all the weights are the same. In this particular case the complexity lowers to $\Theta _{n+1}^P$. Recall that, $\Theta _{n+1}^P$ is the class of problems that can be solved by a logarithmic number of calls to an oracle in $\Sigma _n^P$, that in the literature is also denoted by $\Delta _{n+1}^p[O(log\ m)]$ (Reference WagnerWagner 1986). The next result shows ASP$^{\omega }$(Q) can optimally encode optimization problems in this complexity class (Wagner 1986, 1990), such as the Propositional Abduction Problem discussed in Section 4.
Theorem 6 (Fifth completeness results) Deciding whether an atom $a$ belongs to an optimal quantified answer set of a plain alternating existential ASP$^{\omega }$(Q) program with $n$ quantifiers is $\Theta _{n+1}^P$-complete if there is only one level and all the weights are the same.
Proof (Hardness) Let a QBF formula $\Phi$ be an expression of the form $\mathcal{Q}_1 X_1 \ldots \mathcal{Q}_n X_n \phi$, where $X_1,\ldots, X_n$ are disjoint sets of propositional variables, $\mathcal{Q}_i \in \{\exists, \forall \}$ for all $1\leq i\leq n$, $\mathcal{Q}_i \neq \mathcal{Q}_{i+1}$ for all $1\leq i \lt n$, and $\phi$ is a 3-DNF formula over variables in $X_1,X_2,\ldots, X_n$ of the form $D_1 \vee \ldots \vee D_n$, where each conjunct $D_i = l_1^i\wedge l_2^i\wedge l_3^i$, with $1\leq i\leq n$. A $k$-existential QBF formula $\Phi$ is a QBF formula where $n = k$ and $\mathcal{Q}_1 = \exists$.
Given a sequence of $m$ $k$-existential QBF formulas $\Phi _1,\ldots, \Phi _m$, with $k$ being even and greater than or equal to $2$, and such that if $\Phi _j$ is unsatisfiable then also $\Phi _{j+1}$ is unsatisfiable, where $1\leq j \lt m$, deciding whether $v(\Phi _1,\ldots, \Phi _m) = max\{ j \mid 1\leq j \leq m \wedge \Phi _j\ \textit{is satisfiable}\}$ is odd is $\Theta _{k+1}$-complete (Reference Buccafurri, Leone and RulloBuccafurri et al. 2000).
The above problem can be encoded into an ASP$^{\omega }$(Q) program $\Pi$ such that a literal, namely $odd$, appears in some optimal quantified answer set of $\Pi$ if and only if $v(\Phi _1,\ldots, \Phi _m)$ is odd. For simplicity, we introduce notation for some sets of rules that will be used in the construction of $\Pi$. More precisely, given a QBF formula $\Phi$, $sat(\Phi )$ denotes the set of rules of the form $sat_{\Phi } \leftarrow l_1^i, l_2^i, l_3^i$, where $D_i = l_1^i\wedge l_2^i\wedge l_3^i$ is a conjunct in $\phi$; whereas for a set of variables $X_i = \{x_1^i,\ldots, x_n^i\}$ in $\Phi$, and an atom $a$, $choice(X_i,a)$ denotes the choice rule $\{x_1^i;\ldots ;x_n^i\}\leftarrow a$. We are now ready to construct the program $\Pi$.
First of all, we observe that all the formulas $\Phi _1,\ldots, \Phi _m$ have the same alternation of quantifiers. Thus, there is a one-to-one correspondence between the quantifiers in the QBF formulas and those in $\Pi$. Let $\Pi$ be of the form $\Box _1P_1\Box _2P_2\ldots \Box _k P_k: C: C^w$ where $\Box _i = \exists$ if $\mathcal{Q}_i = \exists$ in a formula $\Phi _j$, otherwise $\Box _i=\forall$. The program $P_1$ is of the form
while, for each $2\leq i \leq k$, the program $P_i$ is of the form
where each $X_i^j$ denotes the set of variables appearing in the scope of the $i$-th quantifier of the $j$-th QBF formula $\Phi _j$. Finally, the programs $C$ and $C^w$ are of the form
Intuitively, the first choice rule in $P_1$ is used to guess one QBF formula, say $\Phi _j$, among the $m$ input ones, for which we want to verify the satisfiability. The guessed formula is encoded with the unary predicate $solve$, whereas, all the following formulas $\Phi _i$, with $i \gt j$, are marked as unsolved by means of the unary predicate $unsolved$.
Then, $P_1$ contains different rules of the form $odd \leftarrow solve(j)$ for each odd index $j$ in $[1,m]$. Thus the literal $odd$ is derived whenever a QBF formula $\Phi _j$ in the sequence $\Phi _1,\ldots, \Phi _m$ is selected (i.e., $solve(j)$ is true) and $j$ is odd. The remaining part of $P_1$ shares the same working principle of the following subprograms $P_i$, with $i\geq 2$. More precisely, for each QBF formula $\Phi _j$ in the sequence $\Phi _1,\ldots, \Phi _m$, they contain a choice rule over the set of variables quantified by the $i$-th quantifier of $\Phi _j$. Note that the atom $solve(j)$ in the body of these choice rules guarantees that only one gets activated, and so the activated choice rule guesses a truth assignment for the variables in the $i$-th quantifier of $\Phi _j$. Similarly, the constraint program $C$ contains, for each QBF formula $\Phi _j$ in the sequence $\Phi _1,\ldots, \Phi _m$, $(i)$ a set of rules that derives an atom $sat_{\phi _j}$ whenever the truth assignment guessed by the previous subprograms satisfies $\phi _j$, and $(ii)$ a strong constraint imposing that is not possible that we selected the formula $\Phi _j$ (i.e., $solve(j)$ is true) and $\phi _j$ is violated (i.e., $sat_{\Phi _j}$ is false). Thus, there exists a quantified answer set of $\Pi$ if and only if there exists a formula $\Phi _j$ in the sequence $\Phi _1,\ldots, \Phi _m$ such that $\Phi _j$ is satisfiable. Since the program $C^w$ contains the set of weak constraints of the form $\leftarrow _{w} unsolved(j)\ [1@1,j]$ for each $j \in [1,\ldots, m]$, the cost of each quantified answer set is given by the index $j$ of the selected formula. Thus, by minimizing the number of unsolved formulas we are maximizing the index of the satisfiable formula $\Phi _j$. Thus, an optimal quantified answer set corresponds to a witness of coherence for a formula $\Phi _j$, s.t. for each $\Phi _{j^{\prime}}$, with $j^{\prime}\gt j$, $\Phi _{j^{\prime}}$ is unsatisfiable. By construction $odd$ is derived whenever $j$ is odd and so the hardness follows.
(Membership) According to Theorem3 of Reference Amendola, Ricca and TruszczynskiAmendola et al. (2019), we know that the coherence of an existential plain alternating program with $n$ quantifiers falls within the complexity class $\Sigma _{n}^P$-complete. By following an observation employed in the proofs by Reference Buccafurri, Leone and RulloBuccafurri et al. (2000), the cost of an optimal solution can be obtained by binary search that terminates in a logarithmic, in the value of the maximum cost, number of calls to an oracle in $\Sigma _{n}^P$ that checks whether a quantified answer set with a lower cost with respect to the current estimate of the optimum exists. Once the cost of an optimal solution is determined, one more call to the oracle (for an appropriately modified instance), allows one to decide the existence of an optimal solution containing $a$. Since each weak constraint has the same weight and the same level, then we can consider as the maximum cost the number of weak constraint violations. Thus, the number of oracle calls is at most logarithmic in the size of the problem and the membership follows.
7 Related work
Disjunctive ASP programs can be used to model problems in the second level of the PH using programming techniques, such as saturation (Reference Eiter and GottlobEiter and Gottlob 1995b; Reference Dantsin, Eiter, Gottlob and VoronkovDantsin et al. 2001), but it is recognized that they are not intuitive. As a consequence, many language extensions have been proposed that expand the expressivity of ASP (Reference Bogaerts, Janhunen and TasharrofiBogaerts et al. 2016; Reference Amendola, Ricca and TruszczynskiAmendola et al. 2019; Reference Fandinno, Laferrière, Romero, Schaub and SonFandinno et al. 2021). This paper builds on one of these, namely: Answer Set Programming with Quantifiers (ASP(Q)) (Reference Amendola, Ricca and TruszczynskiAmendola et al. 2019). ASP(Q) extends ASP, allowing for declarative and modular modeling of problems of the entire PH (Reference Amendola, Ricca and TruszczynskiAmendola et al. 2019). We expand ASP(Q) with weak constraints to be able to model combinatorial optimization problems. In Section 4, we show the efficacy of ASP$^{\omega }$(Q) in modeling problems that would require cumbersome ASP(Q) representations.
The two formalisms most closely related to ASP(Q) are the stable–unstable semantics (Reference Bogaerts, Janhunen and TasharrofiBogaerts et al. 2016), and quantified answer set semantics (Reference Fandinno, Laferrière, Romero, Schaub and SonFandinno et al. 2021). We are not aware of any extension of these that support explicitly weak constraints or alternative optimization constructs.Reference Amendola, Ricca and TruszczynskiAmendola et al. (2019) and Fandinno et al. (Reference Fandinno, Laferrière, Romero, Schaub and Son2021) provided an exhaustive comparison among ASP extensions for problems in the PH.
It is worth observing that ASP$^{\omega }$(Q) extends ASP(Q) by incorporating weak constraints, a concept originally introduced in ASP for similar purposes (Reference Buccafurri, Leone and RulloBuccafurri et al. 2000). Clearly, ASP$^{\omega }$(Q) is a strict expansion of ASP, indeed it is easy to see that any ASP program $P$ is equivalent to a program of the form (3) with only one existential quantifier, where $P_1=\mathcal{R}(P)$, $C^w = \mathcal{W}(P)$, $C = \emptyset$. Related to our work is also a formalism that has been proposed for handling preferences in ASP, called asprin (Reference Brewka, Delgrande, Romero and SchaubBrewka et al. 2023). asprin is effective in defining preferences over expected solutions, nonetheless, the complexity of main reasoning tasks in asprin is at most $\Sigma _3^P$ (Reference Brewka, Delgrande, Romero and SchaubBrewka et al. 2023), with optimization tasks belonging at most to $\Delta _3^P$ (Reference Brewka, Delgrande, Romero and SchaubBrewka et al. 2023); thus, in theory, ASP$^{\omega }$(Q) can be used to model more complex optimization problems (unless P = NP).
8 Conclusion
We proposed an extension of ASP(Q) enabling the usage of weak constraints for expressing complex problems in $\Delta _n^p$, called ASP$^{\omega }$(Q). We demonstrated ASP$^{\omega }$(Q)’s modeling capabilities providing suitable encodings for well-known complex optimization problems. Also, we studied complexity aspects of ASP$^{\omega }$(Q), establishing upper and lower bounds for the general case, and revealing intriguing completeness results. Future work involves tightening the bounds from Theorem2 for arbitrary $n$, extending ASP$^{\omega }$(Q) to support subset minimality, and design a complexity-aware implementation for ASP$^{\omega }$(Q) based on the translation of Section 5 and extending the system PyQASP (Reference Faber, Mazzotta and RiccaFaber et al. 2023).
Supplementary material
The supplementary material for this article can be found at http://dx.doi.org/10.1017/S1471068424000395.