1 Introduction
Harrison et al. 2017 extended the concept of program completion Clark (1978) to a large class of nondisjunctive programs in the input language of the ASP grounder gringo Gebser et al. (2012). They argued that it would be useful to automate the process of generating and simplifying completion formulas for (tight^{1}^{1}1Tightness
is a syntactic condition that guarantees the equivalence between the stable model semantics and the completion semantics of a logic program
Fages (1994); Erdem and Lifschitz (2003).) gringo programs, because examining the output produced by this kind of software may help programmers to see more clearly what their program does and to what degree its set of stable models conforms with their intentions. Furthermore, if a formal specification for a gringo program is available, then it may be possible to use this software, in combination with automated reasoning tools, to verify that the program is correct.This note is a preliminary report on a software development project that follows up on this idea. anthem is a translator that converts a gringo program into its completion and simplifies it. By simplifying we mean, in this case, not so much making formulas shorter as writing them in a form that is “readable”—natural from the perspective of a human who is accustomed to expressing mathematical ideas using propositional connectives, quantifiers, variables for objects of various types, the summation symbol, and other standard notation. The language of gringo and many other input languages of answer set solvers, including those of smodels Niemelä and Simons (1997) and dlv Leone et al. (2006)
, classify variables into global and local, instead of using quantifiers to classify occurrences into free and bound, and that distinguishes them from traditional notation. The same can be said about assuming that all variables range over the same universe, instead of using variables of different sorts or types (for points, lines, and planes; for integers and real numbers; or for sets and classes; etc.).
^{2}^{2}2Answer set programming with sorts Balai et al. (2013) is an exception. What these authors proposed, however, is assigning sorts to argument positions but not assigning them to variables. This is different from what is customary in logic and in procedural programming languages. Each of the two notational traditions has its advantages, and anthem provides a bridge between them.Simplifying a logical formula in the sense of making it more understandable is not the same thing, of course, as rewriting it using fewer characters. For instance, the equivalent formulas
and
use the same number of logical symbols, but the latter is much easier to understand.
Besides generating and simplifying the completion of a program, anthem “hides” auxiliary predicate symbols occurring in the program when possible. In the language of gringo, the fact that a predicate symbol is not considered an essential part of the output can be expressed by not including it in #show directives. To eliminate such predicate symbols from its output, anthem replaces them by their completed definitions.
The input language of anthem is a large part of the input language of gringo. Input programs are supposed to be nondisjunctive. They may use arithmetic operations, intervals, comparisons, singleton choice rules without lower and upper bounds, and constraints. Aggregates and conditional literals are not supported in the current version.
The output of anthem is a list of firstorder formulas with variables of two sorts—for arbitrary precomputed terms (that is, for all elements of the Herbrand universe) and for the precomputed terms that correspond to integers—as proposed by Harrison et al. 2017, Sections 3 and 9. Differences between atoms in gringo programs and atomic parts of formulas are related mostly to arithmetic expressions (see Section 3 below).
The GitHub repository of anthem contains the source code, installation steps, usage instructions, as well as multiple examples to experiment with.^{3}^{3}3https://github.com/potassco/anthem
2 Examples
Example 1. Given the input file
anthem generates the formula
The first two lines of the input file express the condition
in the language of logic programming. The last two lines tell us that the unary predicates p and q are not defined in this file; they can be specified separately.^{4}^{4}4This is slight abuse of the syntax of #external directives, since a predicate’s arity is indicated by its argument. (Without those lines in the input, anthem would have decided that p and q are identically false.) The output of anthem, shown above, expresses the same condition by a firstorder formula.
Example 2. The condition
can be represented by the gringo program
anthem converts this program into the formula
which expresses the same condition in traditional logical notation. It is obtained from the completed definition
of u by replacing s with its completed definition.
Example 3. The rules
express—assuming that p and q do not occur in the heads of any other rules—that and . The formulas
generated by anthem in response to this input express the same conditions in traditional notation.
Example 4. The vertex coloring program
is transformed by anthem into
The second of these formulas will look more natural if we rewrite it as
and the last of them can be improved by writing it in the form
These simplifications will be implemented in a future version of anthem.
3 Arithmetic Expressions in Formulas
In the output of anthem, an integer variable can be recognized by its first character—the letter N. For instance, the formula
exists N p(N) 
is stronger than
exists X p(X) 
—it expresses that the set p contains at least one integer (and not only ground terms formed using symbolic constants).
In the language of gringo, a ground term represents, generally, a finite set of values, rather than a single value (Harrison et al., 2017, Section A.1). For example, the term 1 + 3 has a single value 4, but 1..3 has the values 1, 2, 3. The set of values of 3..1 is empty, and so is the set of values of 3 / (1  1). Accordingly, an atomic formula can be formed from two terms using the symbol in, expressing set membership, for instance:
The first of these formulas is equivalent to X = 4; the second, to
the last two, to #false.
On the other hand, intervals are allowed in a formula in only one position—to the right of the symbol in. For instance, the atom p(1..3), which can be used in gringo rules, is not a formula; in the world of formulas, we distinguish between
exists X (X in 1..3 and p(X)) 
and
The use of arithmetic operations in formulas is restricted in the same way, except for terms formed from integer variables using addition, subtraction, and multiplication. Such terms can be used in a formula anywhere. This exception is motivated by the fact that any ground term of this type has a unique value. For instance, p(N + 1) is a formula, but p(X + 1) is not. To express that
we write
In the output of anthem, an expression of the form int(p/n@k), where is a symbolic constant and , are integers such that , stands for the formula
which expresses that the th member of any tuple satisfying is an integer.
4 Examples Involving Arithmetic Expressions
Example 5. The program
encodes the set of permutations of the letters , , . anthem transforms it into
Example 6. The program
encodes the set of primes up to . anthem turns it into
Example 7. The program
encodes partitions of into sumfree sets. anthem turns it into
5 Implementation
The implementation of anthem takes advantage of gringo’s library functionality for accessing the abstract syntax tree (AST) of a nonground program. The AST obtained from gringo is taken by anthem and turned into the AST of the collection of formulas representing the rules of the program (Harrison et al., 2017, Section 4). That tree is then turned into the AST of the program’s completion. Auxiliary predicates are eliminated, and the result is subject to several simplifications, including those that involve the use of integer variables. In Example 5, for instance, the formula
is replaced at the last stage by the pair of formulas
The final result is prettyprinted to standard output.
In the process of eliminating auxiliary predicates by replacing them with their definitions, a cycle check is employed to detect the cases when this process would not terminate. For example, in response to the input
anthem displays a warning:
Apart from the standard options (for help, version, etc.), anthem allows us to switch on/off completion, simplification, and introducing integer variables from the command line.
6 Future Work
Future work on anthem will proceed in two main directions. First, we would like to support aggregates and conditional literals. When this is accomplished, we will be able to replace, for instance, the first four rules of Example 4 by a single rule
With aggregates added to the input language of anthem, formulas in its output will have more complex syntactic structure (Harrison et al., 2017, Section 8.2).
Second, we will investigate the possibility of using automated reasoning tools for classical logic, in combination with anthem, for verifying programs written in the input language of gringo. For instance, the specification for the program from Example 6—encode the set of primes up to —can be expressed by the formula
It is easy to show that this formula is equivalent to the first formula in the output of anthem using firstorder logic, simple properties of inequalities, and the meaning of the interval notation. We expect that it will be possible to verify claims of this kind using a proof checker.
Acknowledgements
Thanks to Amelia Harrison and to the anonymous referees for comments on a draft of this note. The first author was partially supported by the National Science Foundation under Grant IIS1422455.
References
 Balai et al. (2013) Balai, E., Gelfond, M., and Zhang, Y. 2013. Towards Answer Set Programming with Sorts. In Proceedings of International Conference on Logic Programming and Nonmonotonic Reasoning (LPNMR). 135–147.
 Clark (1978) Clark, K. 1978. Negation as Failure. In Logic and Data Bases, H. Gallaire and J. Minker, Eds. Plenum Press, New York, 293–322.
 Erdem and Lifschitz (2003) Erdem, E. and Lifschitz, V. 2003. Tight Logic Programs. Theory and Practice of Logic Programming 3, 499–518.
 Fages (1994) Fages, F. 1994. Consistency of Clark’s Completion and Existence of Stable Models. Journal of Methods of Logic in Computer Science 1, 51–60.

Gebser
et al. (2012)
Gebser, M., Kaminski, R., Kaufmann, B., and Schaub, T. 2012.
Answer Set Solving in Practice.
Synthesis Lectures on Artificial Intelligence and Machine Learning. Morgan and Claypool Publishers.
 Harrison et al. (2017) Harrison, A., Lifschitz, V., and Raju, D. 2017. Program Completion in the Input Language of gringo. Theory and Practice of Logic Programming 17, 5–6, 855–871.
 Leone et al. (2006) Leone, N., Pfeifer, G., Faber, W., Eiter, T., Gottlob, G., Perri, S., and Scarcello, F. 2006. The DLV System for Knowledge Representation and Reasoning. ACM Transactions on Computational Logic 7, 3, 499–562.
 Niemelä and Simons (1997) Niemelä, I. and Simons, P. 1997. Smodels—An Implementation of the Stable Model and WellFounded Semantics for Normal Logic Programs. In Proceedings 4th International Conference on Logic Programming and Nonmonotonic Reasoning. Springer, 420–429.
Comments
There are no comments yet.