Computing with Logic as Operator Elimination: The ToyElim System
aa r X i v : . [ c s . A I] A ug Computing with Logic as Operator Elimination:The ToyElim System
Christoph Wernhard
Technische Universit¨at Dresden [email protected]
Abstract.
A prototype system is described whose core functionality is, based on propo-sitional logic, the elimination of second-order operators, such as Boolean quantifiers andoperators for projection, forgetting and circumscription. This approach allows to expressmany representational and computational tasks in knowledge representation – for exam-ple computation of abductive explanations and models with respect to logic programmingsemantics – in a uniform operational system, backed by a uniform classical semantic frame-work.
We pursue an approach to computation with logic emerging from three theses:
1. Classical first-order logic extended by some second-order operators suffices to expressmany techniques of knowledge representation.
Like the standard logic operators, second-order operators can be defined semantically , by speci-fying the requirements on an interpretation to be a model of a formula whose principal functoris the operator, depending only on semantic properties of the argument formulas. Neither con-trol structure imposed over formulas (e.g. Prolog), nor formula transformations depending on aparticular syntactic shape (e.g. Clark’s completion) are involved. Compared to classical first-orderformulas, the second-order operators give additional expressive power. Circumscription is a promi-nent knowledge representation technique that can be expressed with second-order operators, inparticular predicate quantifiers [1].
2. Many computational tasks can be expressed as elimination of second-order operators.Elimination is a way to computationally process second-order operators, for example Booleanquantifiers with respect to propositional logic: The input is a formula which may contain theoperator, for example a quantified Boolean formula such as ∃ q (( p ← q ) ∧ ( q ← r )). The outputis a formula that is equivalent to the input, but in which the operator does not occur, suchas, with respect to the formula above, the propositional formula p ← r . Let us assume that themethod used to eliminate the Boolean quantifiers returns formulas in which not just the quantifiersbut also the quantified propositional variables do not occur. This syntactic condition is usuallymet by elimination procedures. Our method then subsumes a variety of tasks: Computation ofuniform interpolants, QBF and SAT solving, as well as computation of certain forms of abductiveexplanations, of propositional circumscription, and of stable models, as will be outlined below.
3. Depending on the application, outputs of computation with logic are convenientlyrepresented by formulas meeting syntactic criteria.
If results of elimination are formulas characterized just up to semantics, they may contain re-dundancies and be in a shape that is difficult to comprehend. Thus, they should be subjected tosimplification and canonization procedures before passed to humans or machine clients. The out-put format depends on the application problem: What is a CNF of the formula? Are certain factsconsequences of the formula? What are the models of the formula? What are its minimal models?What are its 3-valued models with respect to some encoding into 2-valued logics? Correspondinganswers can be computed on the basis of normal form representations of the elimination outputs:CNFs, DNFs, and full DNFs. Of course, transformation into such normal forms might by itselfe an expensive task. Second-order operators allow to counter this by specifying a small set ofapplication relevant symbols that should be included in the output (e.g. by Boolean quantificationupon the irrelevant atoms).
ToyElim is a prototype system developed to investigate operator elimination from a pragmaticpoint of view with small applications. For simplicity, it is based on propositional logic, althoughits characteristic features should transfer to first-order logic. It supports a set of second-orderoperators that have been semantically defined in [11,14,13]. Formula Syntax.
As the system is implemented in Prolog, formulas are represented by Prologterms, the standard connectives corresponding to true /0, false /0, ~ /1, , /2, ; /2, -> /2, <- /2, <-> /2. Propositional atoms are represented by Prolog atoms or compound ground terms. Thesystem supports propositional expansion with respect to finite domains of formulas containingfirst-order quantifiers. Forgetting.
Existential Boolean quantification ∃ p F can be expressed as forgetting [11,4] informula F about atom p , written forget { p } ( F ), represented by forg([p], F ′ ) in system syn-tax, where F ′ is the system representation of F . To get an intuition of forgetting, consider theequivalence forget { p } ( F ) ≡ F [ p \ true ] ∨ F [ p \ false ], where F [ p \ true ] ( F [ p \ false ]) denotes F withall occurrences of p replaced by true ( false ). Rewriting with this equivalence constitutes a naivemethod for eliminating the forgetting operator. The formula forget { p } ( F ) can be said to expressthe same as F about all other atoms than p , but nothing about p . Elimination and Pretty Printing of Formulas.
The central operation of the ToyElim system,elimination of second-order operators, is performed by the predicate elim( F , G ) , with inputformula F and output formula G . For example, define as extension of kb1 /1 a formula (after [3])as follows: kb1(((shoes are wet <- grass is wet),(grass is wet <- rained last night),(grass is wet <- sprinkler was on))). (1) After consulting this, we can execute the following query on the Prolog toplevel: ?- kb1(F), elim(forg([grass is wet], F), G), ppr(G). (2)
This results in binding G to the output of eliminating the forgetting about grass is wet . Thepredicate ppr /1 is one of several provided predicates for converting formulas into applicationadequate shapes. It prints its argument as CNF with clauses written as reverse implications: ((shoes are wet <- rained last night),(shoes are wet <- sprinkler was on)) . (3) Scopes.
So far, the first argument of forgetting has been a singleton set. More generally, itcan be an arbitrary set of atoms, corresponding to nested existential quantification. Even moregenerally, also polarity can be considered: Forgetting can, for example, be applied only to thoseoccurrences of an atom which have negative polarity in a NNF formula. This can be expressedby literals with explicitly written sign in the first argument of the forgetting operator. Forget-ting about an atom is equivalent to nested forgetting about the positive and the negative literalwith that atom. In accord with this observation, we technically consider the first argument offorgetting always as a set of literals , and regard an unsigned atom there as a shorthand repre-senting both of its literals. For example, [+grass is wet, shoes are wet] is a shorthand for [+grass is wet, +shoes are wet, -shoes are wet] . Not just forgetting, but, as shown below,also other second-order operators have a set of literals as parameter. Hence, we refer to a set ofliterals in this context by a special name, as scope . http://cs.christophwernhard.com/provers/toyelim/, under GNU Public License. rojection. In many applications it is useful to make explicit not the scope that is “forgotten”about, but what is preserved. The projection [11] of formula F onto scope S , which can be definedfor scopes S and formulas F as project S ( F ) ≡ forget ALL − S ( F ), where ALL denotes the set ofall literals, serves this purpose. Vice versa, forgetting could be defined in terms of projection: forget S ( F ) ≡ project ALL − S ( F ) . The call to elim /2 in the query (2) can equivalently be expressedwith projection instead of forgetting by elim(proj([shoes are wet, rained last night, sprinkler was on], F) . (4)
User Defined Logic Operators – An Example of Abduction.
ToyElim allows the user tospecify macros for use in the input formulas of elim /2. The following example extends the systemby a logic operator gwsc for a variant of the weakest necessary condition [8], characterized in termsof projection: :- define elim macro(gwsc(S, F, G), ~proj(complements(S), (F, ~G))). (5)
Here complements(S) specifies the set of the literal complements of the members of the scopespecified by S . The term gwsc(S, F, G) is the system syntax for gwsc S ( F, G ), the globally weakestsufficient condition of formula G on scope S within formula F , which satisfies the following: Aformula H is equivalent to gwsc S ( F, G ) if and only if it holds that (1.) H ≡ project S ( H ); (2.) F | = H → G ; (3.) For all formulas H ′ such that H ′ ≡ project S ( H ′ ) and F | = G → H ′ it holds that H | = H ′ . With the gwsc operator certain abductive tasks [3] can be expressed. The following query,for example, yields abductive explanations for shoes are wet in terms of { rained last night , sprinkler was on } with respect to the knowledge base (1): ?- kb1(F),elim(gwsc([rained last night, sprinkler was on], F, shoes are wet),G),ppm(G). (6) The predicate ppm /1 serves, like ppr /1, to convert formulas to application adequate shape. Itwrites a DNF of its input, in list notation, and simplified such that it does not contain tautologiesand subsumed clauses. In the example the output has two clauses, each representing an alternateexplanation: [[rained last night],[sprinkler was on]] . (7)
Scope-Determined Circumscription.
A further second-order operator supported by ToyElimis scope-determined circumscription [14]. The corresponding functor circ has, like proj and forg ,a scope specifier and a formula as arguments. It allows to express parallel predicate circumscriptionwith varied predicates [5] (only propositional, since the system is based on propositional logic).The scope specifier controls the effect of circumscription: Atoms that occur just in a positive literal in the scope are minimized; symmetrically, atoms that occur just negatively are maxi-mized; atoms that occur in both polarities are fixed; and atoms that do not at all occur in thescope are allowed to vary. For example, the scope specifier, [+abnormal, bird] , a shorthand for [+abnormal, +bird, -bird] , expresses that abnormal is minimized, bird is fixed, and all otherpredicates are varied.
Predicate Groups and Systematic Renaming.
Semantics for knowledge representation some-times involve what might be described as handling different occurrences of a predicate differently– for example depending on whether it is subject to negation as failure. If such semantics are tobe modeled with classical logic, then these occurrences can be identified by using distinguishedpredicates, which are equated with the original ones when required. To this end, ToyElim supportsthe handling of predicate groups : The idea is that each predicate actually is represented by several corresponding predicates p , . . . , p n , where the superscripted index is called predicate group . In thesystem syntax, the predicate group of an atom is represented within its main functor: If the groupis larger than 0, the main functor is suffixed by the group number; if it is 0, the main functoroes not end in a number. For example p ( a ) and p ( a ) are represented by p(a) and p1(a) , re-spectively. In scope specifiers, a number is used as shorthand for the set of all literals whose atomis from the indicated group, and a number in a sign functor for the set of those literals whichhave that sign and whose atom is from the indicated group. For example, [+(0), 1] denotes theunion of the set of all positive literals whose atom is from group 0 and of the set of all literalswhose atom is from group 1. Systematic renaming of all atoms in a formula that have a specificgroup to their correspondents from another group can be expressed in terms of forgetting [13]. TheToyElim system provides the second-order operator rename for this. For example, rename([1-0], F ) is equivalent to F after eliminating second-order operators, followed by replacing all atomsfrom group 1 with their correspondents from group 0. An Example of Modeling a Logic Programming Semantics.
Scope-determined circum-scription and predicate groups can be used to express the characterization of the stable modelssemantics in terms of circumscription [7] (described also in [6,13]). Consider the following knowl-edge base: kb2(((shoes are wet <- grass is wet),(grass is wet <- sprinkler was on, ~sprinkler was abnormal1),sprinkler was on)). (8)
Group 1 is used here to indicate atoms that are subject to negation as failure: All atoms in (8) arefrom group 0, except for sprinkler was abnormal1 , which is from 1. The user defined operator stable renders the stable models semantics: :- define elim macro(stable(F), rename([1-0], circ([+(0),1], F))). (9)
The following query then yields the stable models: :- kb2(F), elim(stable((F)), G), ppm(G). (10)
The result is displayed with ppm /1, as in query (6). It shows here a DNF with a single clause,representing a single model. The positive members of the clause constitute the answer set [[grass is wet, shoes are wet, ~sprinkler was abnormal, sprinkler was on]] . (11)
If it is only of interest whether shoes are wet is a consequence of the knowledge base under stablemodels semantics, projection can be applied to obtain a smaller result. The query :- kb2(F), elim(proj([shoes are wet], stable(F)), G), ppm(G). (12) will effect that the DNF [[shoes are wet]] is printed.
The ToyElim system is implemented in SWI-Prolog and can invoke external systems such asSAT and QBF solvers. It runs embedded in the Prolog environment, allowing for example topass intermediate results between its components through Prolog variables, as exemplified by thequeries shown above.The implementation of the core predicate elim /2 maintains a formula which is graduallyrewritten until it contains no more second-order operators. It is initialized with the input formula,preprocessed such that only two primitively supported second-order operators remain: forgettingand renaming. It then proceeds in a loop where alternately equivalence preserving simplifyingrewritings are applied, and a subformula is picked and handed over for elimination to a special-ized procedure. The simplifying rewritings include distribution of forgetting over subformulas andelimination steps that can be performed with low cost [12]. Rewriting of subformulas with theShannon expansion enables low-cost elimination steps. It is performed at this stage if the expan-sion, combined with low-cost elimination steps and simplifications, does not lead to an increaseof the formula size. The subformula for handing over to a specialized method is picked with thefollowing priority: First, an application of forgetting upon the whole signature of a propositionalrgument, which can be reduced by a SAT solver to either true or false , is searched. Second, asubformula that can be reduced analogously by a QBF solver, and finally a subformula whichproperly requires elimination of forgetting. For the latter, ToyElim schedules a portfolio of dif-ferent methods, where currently two algorithmic approaches are supported: Resolvent generation(SCAN, Davis-Putnam method) and rewriting of subformulas with the Shannon expansion [10,12].Recent SAT preprocessors partially perform variable elimination by resolvent generation. Copro-cessor [9] is such a preprocessor that is configurable such that it can be invoked by ToyElim forthe purpose of performing the elimination of forgetting.
We have seen a prototype system for computation with logic as elimination of second-order op-erators. The system helped to concretize requirements on the user interface and on processingmethods of systems which are entailed by that approach. In the long run, such a system should bebased on more expressive logics than propositional logic. ToyElim is just a first pragmatic attempt,taking advantage of recent advances in SAT solving. A major difference in a first-order setting isthat computations of elimination tasks then inherently do not terminate for all inputs.A general system should for special subtasks not behave worse than systems specialized forthese. This can be achieved by identifying such subtasks, or by general methods that implicitlyoperate like the specialized ones. ToyElim identifies SAT and QBF subtasks. It is a challengeto extend this range, for example, such that the encoded stable model computation would beperformed efficiently. The system picks in each round a single subtask that is passed to a specializedsolver. We plan to experiment with a more flexible regime, where different subtasks are alternatelytried with increasing timeouts.Research on the improvement of elimination methods includes further consideration of tech-niques from SAT preprocessors, investigation of tableau and DPLL-like techniques [12,2], and, inthe context of first-order logic, the so called direct methods [1]. In addition, it seems worth toinvestigate further types of output: incremental construction, like enumeration of model represen-tations, and representations of proofs.The approach of computation with logic by elimination leads to a system that provides auniform user interface covering many tasks, like satisfiability checking, computation of abductiveexplanations and computation of models for various logic programming semantics. Variants ofestablished concepts can be easily expressed on a clean semantic basis and made operational. Theapproach supports the co-existence of different knowledge representation techniques in a singlesystem, backed by a single classical semantic framework. This seems a necessary precondition forlogic libraries that accumulate knowledge independently of some particular application.
References
1. D. M. Gabbay, R. A. Schmidt, and A. Sza las.
Second-Order Quantifier Elimination: Foundations,Computational Aspects and Applications . College Publications, 2008.2. J. Huang and A. Darwiche. DPLL with a trace: From SAT to knowledge compilation. In
IJCAI-05 ,pages 156–162. Morgan Kaufmann, 2005.3. A. C. Kakas, R. A. Kowalski, and F. Toni. Abductive logic programming.
Journal of Logic andComputation , 2(6):719–770, 1993.4. J. Lang, P. Liberatore, and P. Marquis. Propositional independence – formula-variable independenceand forgetting.
Journal of Artificial Intelligence Research , 18:391–443, 2003.5. V. Lifschitz. Circumscription. In D. M. Gabbay, C. J. Hogger, and J. A. Robinson, editors,
Handbookof Logic in Artificial Intelligence and Logic Programming , volume 3, pages 298–352. Oxford UniversityPress, 1994.6. V. Lifschitz. Twelve definitions of a stable model. In
ICLP 2008 , volume 5366 of
LNCS , pages 37–51.Springer, 2008.7. F. Lin.
A Study of Nonmonotonic Reasoning . PhD thesis, Stanford University, 1991.. F. Lin. On strongest necessary and weakest sufficient conditions.
Artificial Intelligence , 128:143–159,2001.9. N. Manthey. Coprocessor - a standalone SAT preprocessor. In
WLP 2011 , 2011. (This volume).10. N. V. Murray and E. Rosenthal. Tableaux, path dissolution and decomposable negation normal formfor knowledge compilation. In
TABLEAUX 2003 , volume 2796 of
LNAI , pages 165–180. Springer,2003.11. C. Wernhard. Literal projection for first-order logic. In
JELIA 08 , volume 5293 of
LNAI , pages389–402. Springer, 2008.12. C. Wernhard. Tableaux for projection computation and knowledge compilation. In
TABLEAUX 2009 ,volume 5607 of
LNAI , pages 325–340. Springer, 2009.13. C. Wernhard. Circumscription and projection as primitives of logic programming. In
Tech. Comm.of the ICLP 2010 , volume 7 of
LIPIcs , pages 202–211, 2010.14. C. Wernhard. Literal projection and circumscription. In
FTP’09 , volume 556 of