Automated Aggregator — Rewriting with the Counting Aggregate
Abstract
Answer set programming is a leading declarative constraint programming paradigm with wide use for complex knowledge-intensive applications. Modern answer set programming languages support many equivalent ways to model constraints and specifications in a program. However, so far answer set programming has failed to develop systematic methodologies for building representations that would uniformly lend well to automated processing. This suggests that encoding selection, in the same way as algorithm selection and portfolio solving, may be a viable direction for improving performance of answer-set solving. The necessary precondition is automating the process of generating possible alternative encodings. Here we present an automated rewriting system, the Automated Aggregator or AAgg, that given a non-ground logic program, produces a family of equivalent programs with complementary performance when run under modern answer set programming solvers. We demonstrate this behavior through experimental analysis and propose the system’s use in automated answer set programming solver selection tools.
1 Introduction
Developers of answer set programming (ASP) solutions often face situations where individual constraints of a problem or even the problem as a whole can be expressed in several syntactically different but semantically equivalent ways. Picking the right representation is crucial to designing these solutions because, given an instance, certain representations perform better (often much better) than others when processed with modern ASP grounders and solvers. However, techniques for selecting a particular representation are often ad hoc and tailored to the needs of the particular application, and require significant programming expertise from the programmer.
About a decade ago, Gebser et al. presented a set of ”rules-of-thumb” used by their team in manual tuning of ASP solutions [7]. These rules include suggestions on program rewritings that often result in substantial performance gains. This was verified experimentally by Gebser et al., with all rewritings used in their experiments generated manually [7]. Buddenhagen and Lierler studied the impact of these rewritings on an ASP-based natural language processor and reported orders of magnitude gains in memory and time consumption as a result of some program transformations they executed manually [3]. Because of these promising results, researchers proposed to automate the task of program rewriting. Bichler et al. investigated rewritings of long rules guided by the tree decomposition of graphs built of program rules (a form of join optimization) [2]. Hippen and Lierler proposed a method of applying projection to rewrite rules based on estimates of the size of the ground program [9].
These projects demonstrated that automated program rewritings may lead to programs performing better than the original ones when run under current ASP solvers such as gringo/clasp [6]. However, the effects of rewritings are not uniformly the same. In fact, depending on the actual instance they are run with, rewritten programs may perform worse that the original ones. This is a problem because a non-uniform behavior makes the process of selecting the uniformly best encoding ill defined. Nevertheless, automated rewritings potentially can significantly improve the state-of-the-art of ASP solving. Namely, the non-uniform behavior of programs obtained by rewriting opens a possibility of using families of equivalent alternative programs in algorithm selection and portfolio solving [14, 15, 10]. In fact, a recent study of suite of six encodings of the Hamiltonian cycle problem shows that one can train performance prediction models to select, given an instance, a program from the suite to run on that instance, guaranteeing a much better overall performance on large sets of instances than that of each of the six programs alone [13].
In this work, we focused on rewritings in which rules using counting based on explicit naming of a required number of objects are rewritten with the use of a counting aggregate. We designed a software, Automated Aggregator (AAgg), for automating such rewritings into several equivalent forms. We studied the software’s applicability and effectiveness. In our experiments, we applied the software to programs submitted to past ASP Competitions. We found that while many of them already included aggregate expressions and AAgg did not detect any rules to which it could apply, in several cases, it was applicable! For those cases, we studied the performance of the original program and the rewritings produced by AAgg. The results showed that depending on an instance, rewritings produced by our software often performed better than the original programs. In other words, the family of encodings generated by AAgg (the original program and its rewritings) showed a complementary performance on both the instances used in the ASP Competitions and on instances which we generate ourselves. These results show that AAgg can be used as a tool for generating collections of encodings to be used in algorithm selection and portfolio solving. A systematic experimental verification of this claim will be the subject of a future work.
2 Aggregate Equivalence Rewriting
In this section we describe the aggregate equivalence rewriting, its input and output forms. Currently, we support one input form and three output forms. The input form is a rule that expresses a constraint that there are different objects with a certain property by explicitly introducing variables to name these objects. The output forms model the same property by relying, in some way, on the counting aggregate. For each of the rewritings we establish its correctness and experimentally study its performance. The correctness follows from Theorems A.3 and A.5, presented and proved in the appendix.
2.1 Preliminaries
We follow the ASP-Core-2 Input Language Format [4]. We consider rules of the form The head may consist of a single literal or be empty, the latter representing a contradiction, making the rule a constraint. The body may contain one or more literals or be empty, which constitutes a fact. Literals are composed of an atom, which may be preceded by . Negative literals include ; positive literals do not. Atoms have the form , where is a predicate symbol of arity and each is a term, that is, a constant, variable, or expression of the form where is a function symbol of arity and each is a term.111AAgg also accepts other term expressions following the definition used by clingo [6].
Atoms may also take the form of an aggregate expression. In this work, we focus on counting aggregates, that is, expressions of the form:
(1) |
In (1), and form an aggregate element, which is a non-empty tuple of terms and literals, respectively. The count operation simply counts the number of unique term tuples whose corresponding condition holds. The result of the count function is compared by the comparison predicates and to the terms and . These comparison predicates may be one of . One or both of these comparisons can be omitted [6].
2.2 Input Forms
The aggregate equivalence rewriting takes as input rules of the form:
(2) |
where
-
•
is the head of a rule ( may be empty making the rule a constraint)
-
•
is a predicate of arity
-
•
are variables, all in the same position in
-
•
is a comma-separated list of variables, identical in variables and variable positions for all in the rule
-
•
is the remaining body of the rule, possibly empty,
and the following hold true:
-
•
-
•
, , and have no occurrences of variables
-
•
The terms may instead be a continuous chain of comparisons:
or .
Note that ’s need not be in the first position in , so long as they are all in the same position in and the other variables in (if any) are identical in all occurrences of in the rule. Additionally, some other forms logically equivalent to are also acceptable. For instance, the condition may be expressed as , for some integer .
2.3 Output Forms
The form of the output depends on the size of . When , the output form is:
(3) |
where
-
•
, , , and are as above
-
•
Aggregate element follows the form as defined above. The prior, , is a tuple of one term, which in this case is a variable. The second, , is a literal.
When , we perform projection to project out the variable from . This gives us an output form consisting of two rules:
(4) |
where
-
•
, , , , and are as above
-
•
Aggregate element follows the form as above
-
•
is a new predicate symbol of arity equal to the size of Y, that is, equal to the arity of minus one; introducing ensures that variables in are universally quantified.
The correctness of this rewriting, follows from the results presented in the appendix (Theorem A.3). Specifically, we show there that if a program is obtained from another program by rewriting one of its rules in the way described above, then both programs have the same answer sets (modulo atoms , if is introduced).
2.3.1 Alternative Output Forms
Two alternative, logically equivalent output forms are also available, each derived from the output form presented above. First, we observe that is logically equivalent to the negation of . We can then restate the original literal as follows:
(5) |
Second, we note that the input language we consider permits integer-only arithmetic. Consequently, the expression for some integers and is equivalent to the conjunctive expression:
.
Additionally, the result of the count never returns a negative number. Therefore, we can restate the aggregate literal in this alternative output form as a conjunction of aggregate literals having the form:
(6) |
Note that, due to the precise semantics of logic programs, the equivalence of these two alternative logic forms relies on additional assumptions about the input program (it has to be splittable) and the rule to be rewritten. Theorem A.5 provides conditions under which the rewriting is guaranteed to be correct. These conditions are checked by our software and only when they hold, the software proceeds with rewriting into an alternative form (5) or (6), as selected by the user.
3 The Automated Aggregator System
We now present the Automated Aggregator222The system and all encodings, test instances, and driver programs can be found online at:
https://drive.google.com/drive/folders/1lqRsy9HGIDHvyXPvkc8zKt1-xvbwcAp?usp=sharing (AAgg) software system for performing the Aggregate Equivalence rewriting. The software provides an automated way to detect rules within a given program following the input format (2) and rewrite those rules into an equivalent output format (3/4), (5), or (6).
3.1 Usage
The software relies on the clingo Python module provided by the Potassco suite [8]. The module is written in Python 2.7. As such, Python 2.7 is required to run the Automated Aggregator system. Installation information is provided in the software’s README file. The Automated Aggregator is invoked as follows:
python aagg/main.py [-h,--help] [-o,--output FILENAME] [--no-rewrite] [--no-prompt] [--use-anonymous-variable] [--aggregate-form ID] [-d,--debug] [-r,--run-clingo] [encoding_1 encoding_2 ...]
The -h flag lists the help options. The encoding(s) are the filename(s) of the input encoding(s), and the output is the desired name for the output file. If no output filename is given, one is generated based on the first input filename given. When a candidate rule is discovered, the user is shown the proposed rewriting and prompted for confirmation. If the --no-rewrite flag is given, no prompts are given and no rewriting is performed. If the --no-prompt flag is given, no prompts are given and rewriting is performed where possible. The ID supplied to the --aggregate-form argument informs the program which aggregate form to use when performing rewrites: its values , , and correspond to aggregate forms (3/4), (5), and (6), respectively. The -d debug flag directs the application to operate with verbosity, printing details during the rewriting candidate discovery process and printing some statistics after the application’s conclusion. The --r run-clingo flag directs the application to run the resulting program through clingo after any rewritings are performed.
Finally, the --use-anonymous-variable flag indicates an additional modification of the output form to be performed. It uses the anonymous variable ‘_’ in place of the variable in the output forms listed above, with some additional modifications of the rule to ensure the transformation is correct. Specifically, we replace the aggregate element with rather than with , because the latter is not a valid gringo syntax. We mention this option for completeness sake, since it is available in our implementation. However, we found that the programs generated when using and when not using the anonymous variable are identical after grounding, so we neither discuss it further nor use these rewritings in our experiments.
By default all boolean flags are disabled and the aggregate-form ID is set to indicating output form (3). At least one input encoding filename must be specified.
3.2 Methodology
The methodology used for discovering whether a rule is a candidate for the aggregate equivalence rewriting is as follows. The given logic program(s) are parsed by the clingo module, generating an abstract syntax tree for each rule. Each such tree is passed to a transformer class for preprocessing. After preprocessing, some information is gathered from the program as a whole; specifically, predicate dependencies are determined, which in turn determine when output forms (5) and (6) are appropriate for a given rule (see the appendix for more details). Rules are then passed individually to an equivalence transformer class for processing. After processing, and if the requested rewriting is possible and confirmed by the user, the rewritten form of the rule is returned. Otherwise the original rule is returned. All returned rules, rewritten or not, are collected and output to the desired output file location. Optionally, the resulting program is then run using clingo.
When a rule is passed to the equivalence transformer for processing, it first undergoes a process of exploration, which traverses the rule’s abstract syntax tree, recording comparison literals between two variables as well as other pertinent information found along the way. These comparison literals are scrutinized to determine whether a subset of the comparisons follows the form given in (2) or some equivalent format as detailed in the section 2.2. The process also identifies those variables that play the role of as in (2). The rule is then analyzed to determine whether there are occurrences of some positive literal of predicate with the arguments and , where each , , exists at least once in the set of occurrences, and is the same for each occurrence and contains no variables . Let us call this set of literals combined with the corresponding comparisons following the form given in (2) or equivalent, the rule’s counting literals. Similarly, we denote the variables playing the role of the variables as given in (2) as the rule’s counting variables.
After gathering counting literals and counting variables, the equivalence transformer verifies that the counting variables are not used within literals anywhere in the rule excluding literals within the set of counting literals. If this verification fails or if any of the constraints for the counting literals cannot be satisfied or if no such set of counting variables can be obtained, then the rule is not fit for rewriting. As a result, no rewriting is performed on the rule and the original rule is returned.
In the other case, if the verification succeeds (the counting literals and the counting variables satisfy all the required constraints), then we proceed as follows. If the requested output form is (3/4), then we check whether and rewrite the rule accordingly using (3) or (4). If the requested output form is (5) or (6), then the predicate dependency condition related to splitting must be verified (see the appendix for details). If it holds, then we check whether and rewrite the rule into the desired form (5) or (6), adding the second of the two rules in (4) when .
Note that the user is first prompted for confirmation for each rewritten rule before the rule is added to the final program. If the user denies a rewriting, then the original rule is used.
3.3 Limitations
Here we discuss the limitations of the Automated Aggregator in its current form.
- 1.
-
2.
In the cases when multiple rewritings are possible for a single rule, only one rewriting will be detected and performed. To illustrate, if the form given in (2) occurs twice in one rule over a disjoint set of variables and predicates, where both sets of counting literals consider the other set as part of and all conditions hold, then only the set of counting literals with the highest number of counting variables will be used for rewriting. If both sets contain the same number of counting variables, then one is chosen based on the order in which the comparisons using those variables occur in the rule.
-
3.
There are some cases in which the software will not recognize a valid rewriting when one exists. These cases mostly lie in the many obscure ways of representing a chain of comparisons equivalent to that in (2). However, there are no known cases in which an incorrect rewriting will be proposed when no valid rewriting is possible. More details are given in the software’s README document.
4 Experimental Analysis
The Automated Aggregator system has been made available for download online.333https://drive.google.com/drive/folders/1lqRsy9HGIDHvyXPvkc8zKt1-xvbwcAp?usp=sharing Encodings with which the application was tested, their corresponding instances, and (Python) scripts for driving such tests, are included there too.
4.1 Automated Aggregator in Practice
The Automated Aggregator system was applied to logic programs in gringo syntax submitted to the 2009, 2014, and 2015 Answer Set Programming Competitions. Of the 58 encodings given to the application, five contained rules which were candidates for the rewriting described. Table 1 lists the encoding problem names and the ASP Competitions for which they were developed.
ASP Competition Year | Problem Domain of Encodings |
---|---|
2009 | Golomb Ruler & Wire Routing |
2014 | Steiner Tree |
2015 | Steiner Tree & Graceful Graphs |
Additionally, to provide an example of the functionality of AAgg, the system was applied to an encoding for the Hamiltonian Cycle problem. The original program is shown in Figure 1. The rewritten program, as output by AAgg, is shown in Figure 2. We see that the first two constraints in the program are both rewritten with the necessary projection performed as in (4). Experimental results for these encodings when applied to a generated set of hard instances are given in the following section.
node(X) :- edge(X,Y). node(X) :- edge(Y,X). { hc(X,Y) } :- edge(X,Y). :- hc(X,Y), hc(X,Z), Y!=Z. :- hc(X,Y), hc(Z,Y), X!=Z. reach(X,Y) :- hc(X,Y). reach(X,Y) :- hc(X,Z), reach(Z,Y). :- node(X), node(Y), not reach(X,Y).
node(X) :- edge(X,Y). node(X) :- edge(Y,X). { hc(X,Y) } :- edge(X,Y). :- 2 <= #count{ Y : hc(X,Y) }, hc_project_Z(X). hc_project_Z(X) :- hc(X,Y). :- 2 <= #count { X : hc(X,Y) }, hc_project_Z1(Y). hc_project_Z1(Y) :- hc(X,Y). reach(X,Y) :- hc(X,Y). reach(X,Y) :- hc(X,Z), reach(Z,Y). :- node(X), node(Y), not reach(X,Y).
4.2 Experimental Results
Results were gathered by systematically grounding and solving each instance-encoding pair within families of encodings for each problem type. The data sets of instances we used are available together with the AAgg tool (see the url listed earlier).444We thank Daniel Houston and Liu Liu for providing us with the data sets of instances for the Latin Square and the Hamiltonian Cycle problems, respectively. The data sets for the remaining problems were generated by software tools we developed for the purpose. These tools and descriptions of instance sets used in experiments can be found at the AAgg site. Each encoding in each family of encodings was run for each instance. The total grounding plus solving time of instance-encoding pairs were recorded and compared.
The precise encodings used as input to the AAgg software for gathering results are listed in Table 2. Two output encodings are generated for each input encoding and together they form the encoding family for that problem domain. The two output forms used were those shown in equations (3/4) and (6); previous experiments showed extreme similarity between forms (3/4) and (5), so (5) was left out to preserve machine time. The machine used for testing contained an Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz with 16GB RAM.
Source of Encoding | Problem Domain of Encodings |
---|---|
ASP Competition 2009 | Wire Routing |
ASP Competition 2015 | Steiner Tree & Graceful Graphs |
Home-Brewed | Latin Squares& Hamiltonian Cycle555We are thankful to Daniel Houston and Liu Liu for supplying the Latin Squares and Hamiltonian Cycle instance sets, respectively. |
Encoding | Wins | Exclusive Wins | Wins by 20% | Wins by 50% |
---|---|---|---|---|
Wire Routing Input Encoding | 122 (58.4%) | 34 (27.8%) | 115 (92.0%) | 97 (77.6%) |
AAgg Output Form (3/4) | 50 (24.0%) | 26 (52.0%) | 48 (87.3%) | 38 (69.1%) |
AAgg Output Form (6) | 37 (17.7%) | 13 (35.1%) | 39 (90.7%) | 23 (53.5%) |
Steiner Tree Input Encoding | 130 (33.9%) | 0 (0%) | 1 (0.8%) | 0 (0%) |
AAgg Output Form (3/4) | 123 (32.1%) | 0 (0%) | 4 (3.3%) | 0 (0%) |
AAgg Output Form (6) | 130 (33.9%) | 0 (0%) | 6 (4.6%) | 0 (0%) |
Graceful Graphs Input Encoding | 212 (37.3%) | 62 (29.2%) | 182 (85.8%) | 128 (60.4%) |
AAgg Output Form (3/4) | 97 (17.1%) | 23 (23.7%) | 82 (84.5%) | 58 (59.8%) |
AAgg Output Form (6) | 259 (45.6%) | 51 (19.7%) | 229 (88.4%) | 169 (63.7%) |
Latin Squares Input Encoding | 5611 (77.7%) | 5 (0.1%) | 4435 (79.0%) | 2003 (35.7%) |
AAgg Output Form (3/4) | 1432 (19.8%) | 0 (0%) | 655 (45.7%) | 86 (6.0%) |
AAgg Output Form (6) | 176 (2.4%) | 0 (0%) | 64 (36.4%) | 7 (4.0%) |
Hamiltonian Cycle Input Encoding | 72 (28.7%) | 47 (65.3%) | 59 (81.9%) | 34 (47.2%) |
AAgg Output Form (3/4) | 102 (40.6%) | 69 (67.7%) | 79 (77.5%) | 52 (51.0%) |
AAgg Output Form (6) | 77 (30.7%) | 45 (58.4%) | 64 (83.1%) | 44 (57.1%) |
Result statistics are shown in Table 3. Data is grouped by problem domain. The first line of each grouping shows statistics for the input encoding. The second line shows statistics for the encoding output by the AAgg software using the first line as input and the output rule form (3/4) as the selected output form. The third and final line of each grouping shows statistics for the encoding output by the AAgg software again using the first line as input but now selecting the output form (6) as the chosen output form.
A win is when an encoding grounds and solves for an instance in the shortest amount of time as compared with the other two encoding in its grouping. The percentage value beside the win count is the proportion of instances which that encoding won relative to the number of instances in the instance set for which at least one of the three encodings terminated within the total time limit set for grounding and solving. This time limit was set to 200 seconds in all experiments, except those with encodings of the Hamiltonian Cycle problem that used a timeout value of 400 seconds due to the relative difficulty of the instance set (in all problem domains except for the Hamiltonian Cycle domain, the number of instances for which no encoding computed an answer within the time limit was very small; for the Hamiltonian Cycle problem, even with the increased time limit, it was significant).
An exclusive win is when the encoding is the only encoding in its grouping to find a solution (or determine there is no solution) for an instance while both of the other two encodings failed to do so within the time limit. The column shows the number and the percentage of wins which were exclusive wins for the encoding. The next column shows the number and the percentage of wins by a margin of at least 20% (this is when the best encoding runs at least 20% faster than the second one; in case the of exclusive wins, we count a win as by at least 20%, if it is faster by at least 20% than the time limit used). The data in the last column shows the numbers and percentages of wins by at least 50% (it is to be interpreted similarly to the data in the previous column).
Results indicate that in some cases, the rewriting can provide complementary performance of encodings. Specifically, the results for the Wire Routing, Graceful Graphs, and Hamiltonian Cycle problems support the claim. This is shown first by the fact that for each problem, each of the encodings scores a significant proportion of wins, and that among those wins a significant proportion are exclusive wins, and an even greater proportion (about 50% or more) are wins by at least 50%. This means that about half of the times when an encoding outperforms the two other encodings, it outperforms both by a factor of at least two.
The Steiner Tree results indicate that sometimes the rewriting produces little to no effect at all. While each encoding for the problem registers a similar proportion of wins, there are very few instances (just eleven out of 283) when the best encoding outperforms the other two by 20% or more, and no instances when the best encoding would outperform the other two by 50% or more. The Latin Squares results are mixed in the sense that for the most part the original encoding works best. However, one of the rewritings registers almost 20% of wins. Moreover, about 45% of those wins are by 20% or more and 6% by 50% or more.
In summary, we see that the rewriting can provide programs that perform complementary to the original. This complementarity is perhaps somewhat surprising, because aggregates are assumed to lead to better performance. Our results show that the picture is more complicated and whether rewriting with aggregates yields better performance is instance-dependent. It is also interesting to note that for some encodings replacing simple counting, like that used in the Latin Square encodings (no two identical elements in a row or column), with the count aggregates does not lead to substantial improvements. Finally, for some problems (in our experiments for the Steiner Tree problem) where complementary behavior does emerge, the differences in performance are relatively small.
5 Future Work
As detailed in Section 3.3, the Automated Aggregator software can be improved. Extending the software so that it rewrites rules by eliminating the counting aggregate by inverting the current rewriting seems to be a potentially most beneficial direction. Indeed, our results show that introducing aggregates does not guarantee uniformly improved performance. This gives reason to think that removing the counting aggregate, that is, rewriting it in an explicit way, has a potential of generating encodings that on many instances may perform better. Just like the present version of the AAgg system, this could yield collections of encodings of complementary strengths. Moreover, this form of rewriting would be quite widely applicable, as the counting aggregate is commonly used.
Expanding the software to detect and perform multiple aggregate equivalence rewritings on a single rule and to detect more obscure forms of representations are two other directions for improvement. While necessary to ensure the software has a possibly broad scope of applicability, we do not expect these extensions to have a major practical impact due to low frequency with which such less intuitive and convoluted forms of modeling are found in programs.
Automated rewriting has been studied before. The Projector system [9] and the lpopt system [2] are two notable examples. That earlier work sought to develop rewritings improving the performance over the original ones. That goal is in general difficult to meet; both systems were shown to offer gains, but the rewritten encodings are not always performing better. Our goal was different. We aimed at rewritings of varying relative performance depending on input instances. With the AAgg system we showed that even a rather simple rewriting consisting of introducing the count aggregate often leads to families of encodings with complementary strengths (areas of superior performance). This opens a way for using machine learning to develop models in support of effective encoding selection or encoding portfolio solving [13]. In such work, to generate promising collections of encodings, one could use the AAgg system, with extensions mentioned above, but also other program rewriting software such as Projector and lpopt which, as noted, while they do yield good encodings, often better than the original one, they do not perform uniformly better.
References
- [1]
- [2] Manuel Bichler, Michael Morak & Stefan Woltran (2016): lpopt: A Rule Optimization Tool for Answer Set Programming. In Manuel V. Hermenegildo & Pedro López-García, editors: Proceedings of the 26th International Symposium on Logic-Based Program Synthesis and Transformation, LOPSTR 2016, Selected Papers, Lecture Notes in Computer Science 10184, Springer, pp. 114–130, 10.1007/978-3-319-63139-4_7.
- [3] Matthew Buddenhagen & Yuliya Lierler (2015): Performance Tuning in Answer Set Programming. In Francesco Calimeri, Giovambattista Ianni & Miroslaw Truszczynski, editors: Proceedings of the 13th International Conference on Logic Programming and Nonmonotonic Reasoning, LPNMR 2015, Lecture Notes in Computer Science 9345, Springer, pp. 186–198, 10.1007/978-3-319-23264-5_17.
- [4] Francesco Calimeri, Wolfgang Faber, Martin Gebser, Giovambattista Ianni, Roland Kaminski, Thomas Krennwallner, Nicola Leone, Marco Maratea, Francesco Ricca & Torsten Schaub (2020): ASP-Core-2 Input Language Format. Theory Pract. Log. Program. 20(2), pp. 294–309, 10.1017/S1471068419000450.
- [5] Paolo Ferraris, Joohyung Lee, Vladimir Lifschitz & Ravi Palla (2009): Symmetric Splitting in the General Theory of Stable Models. In Craig Boutilier, editor: Proceedings of the 21st International Joint Conference on Artificial Intelligence, IJCAI 2009, pp. 797–803. Available at http://ijcai.org/Proceedings/09/Papers/137.pdf.
- [6] M. Gebser, R. Kaminski, B. Kaufmann, M. Lindauer, M. Ostrowski, J. Romero, T. Schaub & S. Thiele (2015): Potassco User Guide. Available at https://github.com/potassco/guide/releases/.
- [7] Martin Gebser, Roland Kaminski, Benjamin Kaufmann & Torsten Schaub (2011): Challenges in Answer Set Solving. In Marcello Balduccini & Tran Cao Son, editors: Logic Programming, Knowledge Representation, and Nonmonotonic Reasoning - Essays Dedicated to Michael Gelfond on the Occasion of His 65th Birthday, Lecture Notes in Computer Science 6565, Springer, pp. 74–90, 10.1007/978-3-642-20832-4_6.
- [8] Martin Gebser, Roland Kaminski, Benjamin Kaufmann & Torsten Schaub (2019): Multi-shot ASP solving with clingo. Theory Pract. Log. Program. 19(1), pp. 27–82, 10.1017/S1471068418000054.
- [9] Nicholas Hippen & Yuliya Lierler (2019): Automatic Program Rewriting in Non-Ground Answer Set Programs. In José Júlio Alferes & Moa Johansson, editors: Proceedings of the 21th International Symposium on Practical Aspects of Declarative Languages, PADL 2019, Lecture Notes in Computer Science 11372, Springer, pp. 19–36, 10.1007/978-3-030-05998-9_2.
- [10] Holger H. Hoos, Marius Lindauer & Torsten Schaub (2014): claspfolio 2: Advances in Algorithm Selection for Answer Set Programming. Theory Pract. Log. Program. 14(4-5), pp. 569–585, 10.1017/S1471068414000210.
- [11] Yuliya Lierler (2019): Strong Equivalence and Program’s Structure in Arguing Essential Equivalence Between First-Order Logic Programs. In José Júlio Alferes & Moa Johansson, editors: Proceedings of 21th International Symposium on Practical Aspects of Declarative Languages, PADL 2019, Lecture Notes in Computer Science 11372, Springer, pp. 1–18, 10.1007/978-3-030-05998-9_1.
- [12] Vladimir Lifschitz & Hudson Turner (1994): Splitting a Logic Program. In Pascal Van Hentenryck, editor: Proceedings of the 11th International Conference on Logic Programming, ICLP 1994, MIT Press, pp. 23–37.
- [13] Liu Liu & Miroslaw Truszczynski (2019): Encoding Selection for Solving Hamiltonian Cycle Problems with ASP. In Bart Bogaerts, Esra Erdem, Paul Fodor, Andrea Formisano, Giovambattista Ianni, Daniela Inclezan, Germán Vidal, Alicia Villanueva, Marina De Vos & Fangkai Yang, editors: Proceedings of the 35th International Conference on Logic Programming, ICLP 2019, Technical Communications, EPTCS 306, pp. 302–308, 10.4204/EPTCS.306.35.
- [14] John R. Rice (1976): The Algorithm Selection Problem. Advances in Computers 15, pp. 65–118, 10.1016/S0065-2458(08)60520-3.
- [15] Lin Xu, Frank Hutter, Holger H. Hoos & Kevin Leyton-Brown (2008): SATzilla: Portfolio-based Algorithm Selection for SAT. J. Artif. Intell. Res. 32, pp. 565–606, 10.1613/jair.2490.
Appendix A Correctness of Rewritings
Let us consider the following program rule ( may be ):
(7) |
where is a predicate, a tuple of variables , is a list of literals over variables , and and are three pairwise disjoint tuples of variables, and disjoint with , and contains none of .
Let be a program containing rule (7) and let be the program obtained from by replacing that rule with the two rules
(8) |
where is a predicate not occurring in .
Theorem A.1.
The programs and have the same answer sets modulo ground atoms of the form .
Proof.
(Sketch) Consider a ground instance of rule (7) and let be the first atoms in the body of (that is, a ground instance of the atom ). In there are ground rules and obtained from (8) using the same variable instantiation as that used to produce . Clearly, contributes to the reduct of if and only if and contribute to the reduct of . Moreover, if they do, “fires” in the least model computation if and only if fires in the least model computation. It follows that an interpretation of is an answer set of if and only if is an answer set of , where consists of all atoms such that , for some constant and a tuple of constants . ∎
Next, we recall the following theorem proved by Lierler [11].
Theorem A.2.
Let be an atom ( may be ), a list of literals, a variable, a tuple of variables, each different from and each with at least one occurrence in a literal in , and a predicate symbol of arity . If is an integer, and are variables without any occurrence in and , then the logic program rule
(9) |
is strongly equivalent to the logic program rule
(10) |
where is used to represent a sequence of expressions separated by commas.
Combining the two results leads to the following result that proves the correctness of the first rewriting implemented by our tool AAgg.
Theorem A.3.
Let be a program containing a rule of the form
(11) |
under the same assumptions about variable tuples and as before. If is empty, let be . Otherwise, let be obtained from by replacing with the rules (8), adjusting the first of them to contain in place of . Let us call the first of these two rules (reusing the name of the original rule). Finally, let be obtained from by replacing with the corresponding rule (10). Then, the programs and have the same answer sets (in the case, when is not empty, the same answer sets modulo atoms ).
Proof.
Clearly, rule is a special case of a rule of the form (7). By
A.1, programs and have the same answer
sets (when , is not empty, the same answer sets modulo atoms
). The rule in
is of the form (9) required by Theorem A.2. Applying this
theorem shows that programs and have the same answer sets and the
assertion follows.
∎
Once a program has a rule of the form (10), we can often modify it further by exploiting alternative encodings of the aggregate expressions. In particular, under some assumptions about the structure of the program, we can replace a rule (10) by
(12) |
where we assume that the variable is not a variable in , and that all variables in appear in .
We recall that a partition of a program is a splitting of if no predicate appearing in the head of a rule from appears in [12, 5]. A well-known result on splitting states that answer set of programs that have a splitting can be described in terms of answer sets of programs that form the splitting.
Theorem A.4.
Let be a logic program and let be a splitting of . For every answer set of , every answer set of the program is an answer set of . Conversely, for every answer set of , there is an answer set of such that is an answer set of .
This result implies that in programs that have a splitting, a rule in containing in its body an aggregate expression involving only predicates appearing in can be replaced by a rule in which this aggregate expression is replaced by any of its (classically) equivalent forms. We formally state this result for the case of rules of the form (10).
Theorem A.5.
Proof.
(Sketch) Let be the program obtained from by replacing the rule (10) by the rule (12). It is clear that is a splitting of . Let be an answer set of . By A.4, there is an answer set of such that is an answer set of . In particular, is an answer set of the program . Let be the program obtained by simplifying the bodies of the rules in as follows. If a conjunct in the body of a rule in involves only atoms from the Herbrand base of , we remove if , and we remove the rule, if . Because atoms from do not appear in the heads of the rules in , is an answer set of .
We denote by the program obtained by the same simplification process from . From the definition of it follows that (indeed, the only difference between and is in the bodies of some rules, in which an aggregate built entirely from the atoms in is replaced by a classically equivalent one; thus, both expressions evaluate in the same way under and the contribution of the corresponding rules to and in each case is the same). Consequently, is an answer set of . Because atoms from do not appear in the heads of the rules in , is an answer set of and, because is a splitting of , also an answer set of . A similar argument shows that answer sets of are also answer sets of . ∎
It is clear that the same argument applies to other similar rewritings, for instance, to the one that replaces the rule (9) by the rule
(13) |
where, as before, we assume that the variable is not a variable in , and that all variables in appear in .