Executable specifications for hypothesis-based reasoning with Prolog and Constraint Handling Rules

Henning Christiansen
2009 Journal of Applied Logic  
Constraint Handling Rules (CHR) is an extension to Prolog which opens up a spectrum of hypothesis-based reasoning in logic programs without additional interpretation overhead. Abduction with integrity constraints is one example of hypothesis-based reasoning which can be implemented directly in Prolog and CHR with a straightforward use of available and efficiently implemented facilities. The present paper clarifies the semantic foundations for this way of doing abduction in CHR and Prolog as
more » ... as other examples of hypothesis-based reasoning that is possible, including assumptive logic programming, hypotheses with priority and scope, and nonmonotonic reasoning. Examples are presented as executable code so the paper may also serve the additional purpose of a practical guide for developing such programs, and it is demonstrated that the approach provides a seamless integration with existing constraint solvers. Example 1.1. The following program, which specifies and solves an abductive problem, is written in the syntax for chr in SICStus and swi prolog. Constraint predicates are distinguished from normal prolog predicates by declarations. Constraints of chr play the role of abducibles and integrity constraints are written as chr rules, e.g., as indicated below with '==>'. :-chr_constraint professor/1, rich/1, has_good_students/1. professor(X),rich(X) ==> fail. happy(X):-rich(X). happy(X):-professor(X), has_good_students(X). Execution of the query ?-professor(peter), happy(peter) results in a final constraint store (= abducible explanation) consisting of {professor(peter), has_good_students(peter)}. The chr rule excludes an explanation which includes rich(peter), and thereby forcing the prolog engine to try the second clause in its eagerness to verify the query. The approach provides a seamless and efficient integration with all facilities of the underlying prolog and chr system, including existing constraint solvers, in a way that makes it possible to go beyond strictly abductive reasoning. Furthermore, subtle problems with variables in abducible hypotheses in many earlier approaches do not arise here. The main weakness of using chr and prolog for abduction in this way, when comparing with some other systems, is the limited use of negation. By hypothesis-based reasoning, we refer to a space of problem solving and programming techniques in which logic programs are extended with a global state of hypotheses which interacts with the logic program and can be manipulated implicitly as in abductive reasoning or in more explicit ways, and which may or may not relate in all details to declarative specifications. It will be shown how abduction and other instances of hypothesis-based reasoning can be realized in straightforward ways with chr and prolog, and we intend in this way also to indicate that there is a rich scope for developers to produce their own variants for different purposes. Constraint Handling Rules were introduced in the early 1990s by Thom Frühwirth (primary reference [32] from 1998 provides background and early history), and is now available as extensions to major prolog systems, including SICStus and swi. The idea of using chr for abduction was originally suggested by Slim Abdennadher and the present author in 2000 [1] . The combination of prolog and chr for abductive and other kinds of hypothesis-based reasoning has been developed together with Verónica Dahl since 2002 as a central collaborator, e.g., [13] [14] [15] . The present paper aims at giving a coherent presentation of the approach, clarifying the semantic foundations (that were left implicit in earlier publications) as well as exposing hypothesis-based reasoning with prolog and chr as a powerful and flexible programming paradigm. Examples have been checked using SICStus prolog [58]; we use in most cases the chr syntax and facilities provided by SICStus prolog version 4 which is intended to be identical to that of swi prolog [59] . Some extensions to chr that we describe below are implemented using specifics of SICStus prolog version 3, which differs in some details and has a larger collection of low-level facilities, so transfer to version 4 may not be trivial in all cases. Syntax and semantics of CHR and its extensions Where prolog represents a top-down, backward chaining computational paradigm, Constraint Handling Rules, chr, extends with bottom-up, forward chaining computations. Operationally, chr is defined as rewriting rules over a constraint store, which can be seen as a global resource to be used by a prolog program for storing, manipulating and consulting different hypotheses. This resource-oriented understanding of chr has led to the formulation of a semantics for chr [4] based on linear logic (that we have not applied here). We introduce firstly chr, then extend it with disjunctions into chr ∨ [2], and finally we combine it with prolog into a language which we refer to in this paper as prolog+chr. Constraint handling rules, chr Chr inherits the basic nomenclature of prolog, and we refer to the notions of constant and function symbols, predicates, variables, atoms, 1 terms and queries and use initial capital letter for variables, etc. Substitutions, grounding and renaming substitutions are defined as usual. The predicates in a chr program are called constraint predicates, belonging to disjoint sets of program specific ones and a fixed set of built-in predicates each having a fixed meaning, including = with its standard meaning of syntactic equality, and true and false; we assume a theory B for the built-ins, e.g., B | a = a and B | false. A constraint is an atom with a constraint predicate, which may be further classified as program specific or built-in according to its predicate; in contexts with no ambiguity, 'constraint' may also be used for 'constraint predicate'. A chr program consists of rules of the following kinds.
doi:10.1016/j.jal.2008.10.004 fatcat:vci2qqbucjawdje55gc6cxw2ge