Answer Set Programming with Functions

Answer Set Programming with Functions

Proceedings, Eleventh International Conference on Principles of Knowledge Representation and Reasoning (2008) Answer Set Programming with Functions Fangzhen Lin Yisong Wang1,2 Department of Computer Science and Engineering 1Guizhou University, Guiyang, P.R. China Hong Kong University of Science and Technology 2Hong Kong University of Science and Technology, Clear Water Bay, Kowloon, Hong Kong Clear Water Bay, Kowloon, Hong Kong Abstract Syntactically, functions are allowed in logic programming from the very beginning (c.f. (Lloyd 1987)). However, they To compute a function such as a mapping from vertices to col- are normally interpreted under Herbrand universe. For in- ors in the graph coloring problem, current practice in Answer stance, in Prolog, one cannot declare a fact like “f(a) = b”. Set Programming is to represent the function as a relation. Among other things, this often makes the resulting program In fact, the query “f(a) = b” will always receive a “no” an- unnecessarily large when instantiated on a large domain. The swer. In other words, functions are pre-defined and their extra constraints needed to enforce the relation as a function values cannot be changed by the user. The same holds also make the logic program less transparent. In this paper, for most of the work in ASP that allows function symbols we consider adding functions directly to normal logic pro- (e.g. (Bonatti 2004; Baselice, Bonatti, & Criscuolo 2007; grams. We show that the answer set semantics can be gen- Syrj¨anen 2001; Simkus & Eiter 2007; Calimeri, Cozza, & eralized to these programs straightforwardly. We also show Ianni 2007)). While lparse (Syrj¨anen 1998) allows function that the notions of loops and loop formulas can be extended, symbols, terms constructed of these functions are just names and that through program completion and loop formulas, a standing for constants. normal logic program with functions can be transformed to a One noticeable exception is the work of Cabalar and Constraint Satisfaction problem. Lorenzo (2004) and Cabalar (2005) where they proposed a logic programming language with functions only. The main Introduction differences between their language and ours are that we ex- tend normal logic programs with functions rather than using Currently in Answer Set Programming (ASP), functions are a pure functional language, and that functions must be total represented as special relations. For instance, to encode the in our language but can be partial in theirs. A more detailed graph coloring problem, instead of a unary function, say comparison will be given later in the paper. color(x) that maps vertices to colors, one uses a binary rela- In the next section, we introduce our language of normal tion, say color(x, c) to mean that the vertex x is assigned the logic programs with functions. We then extend the answer color c. For this to work, one needs to add some axioms say- set semantics to this language and show that under this se- ing that the predicate color(x, c) is in fact functional. More mantics, functions can indeed be replaced by relations in a importantly, it increases the size of the final instantiated pro- systematic way. We then extend the notions of loops and gram both in terms of the number of atoms and the number loop formulas to normal logic programs with functions and of rules. For instance, with color(x, c) we get M ×N atoms, show how they can be used to translate logic programs with where M is the number of vertices and N colors. For the N- functions to constraint satisfaction problems (CSPs). We de- queen’s problem, if we use a predicate q(x, y) to say that the scribe an implementation of logic programs with functions 2 queen at row x is placed in column y, this will generate N using CSP solvers based on this result, and report some pre- atoms. liminary experimental results. In this paper, we consider adding functions to logic pro- grams. We shall argue that this allows for more direct and Normal Logic Programs with Functions compact representation of problems like the graph coloring, the queen’s problem, and the Hamiltonian circuit problem. In the following, let L be a many-sorted first-order language. We shall extend the answer set semantics to programs with Recall that in such a language, every predicate has an ar- functions and relate it to Constraint Satisfaction Problem ity that specifies the number of arguments the predicate has (CSP) through program completion and loop formulas. Our and the type (sort) of each argument, and similarly for con- preliminary experimental results indicate that the reduction stants and functions. Variables also have types associated in size as a result of using functions can pay off when the with them, and when they are used in a formula, their types problem become large. are normally clear from the context. The language L may have pre-interpreted symbols like Copyright c 2008, Association for the Advancement of Artificial the standard arithmetic functions such as “+”, “−”, and the Intelligence (www.aaai.org). All rights reserved. absolute function “|.|”. 454 In this paper, by an atom we mean an atomic formula that Here q is a function of the type pos → pos, and q(i) is does not mention equality, and by an equality atom we mean the column where the ith-queen (the one in row i) is to be a formulaof the form t = t′. Unless stated otherwise, in this placed. The expression x 6= y in a rule stands for not x = y. paper, by functions we mean proper functions, not constants. There are actually two types here: pos, whose domain is A normal rule with functions, or simply a rule, is an ex- 1..N, and int, whose domain is −N..N, for the N-queen pression of the form: problem. The pre-interpreted function “−” is of the type pos × pos → int and “|.|” of int → int. These two func- A ← B1,...,Bm, not C1, . , not Cn (1) tions have their standard meanings. This program is essen- tially the same as Cabalar’s encoding of 8-queens problem where A is empty or an atom, Bi, 1 ≤ i ≤ m, and Cj , 1 ≤ j ≤ n) are atoms or equality atoms. If A is an atom, in his functional action language. then the rule is a proper rule; if A is empty, we also call the For logic programs without functions, an answer set is a rule a constraint. set of atoms that defines the relations in the program: an A normal logic program P is a set of rules together with atom is true iff it is in the answer set. For logic programs a set of type definitions, one for each type τ used in the rules with functions, a model needs to define not only relations of P , of the form: but also functions in the program. Given a logic program τ : D (2) P that may contain functions, an interpretation I of P is a where D is a finite and nonempty set of elements. Unless mapping that assigns each relation and function symbol in stated otherwise, all logic programs in this paper are as- P a meaning in the domains given in the type definitions of sumed to be normal. P : Informally, a type definition defines a domain for a type • if R is a relation of arity τ1 × · · · × τn and the type I (sort). This is like in a first-order structure for a many-sorted definitions τi : Di, 1 ≤ i ≤ n, are in P , then R ⊆ language, there is a domain for each type. Here we require D1 × · · · × Dn. that if a constant c of type τ occurs in the rules of P , then • if f is a function of type τ1 × · · · × τn → τn+1, n > 1, the domain D of τ as specified in the type definitions of P and the type definitions τi : Di, 1 ≤ i ≤ n + 1, are in I must contain c. P , then f is a function from D1 × · · · × Dn to Dn+1. Example 1 The graph coloring problem can be formalized Notice here that a pre-interpreted function should follow with the following constraint: its standard interpretation, thus cannot change it meaning from one interpretation to another. ← arc(x, y), clr(x) = clr(y), (3) We now define the conditionsfor an interpretationto be an where arc is of arity vertex×vertex, and clr a unary func- answer set of a logic program with functions. We basically tion of type vertex → color. A particular instance of the follow the stable model semantics for logic programs with- graph coloring problem is specified by giving type defini- out functions (Gelfond & Lifschitz 1988): we first instanti- tions for vertex and color along with a set of facts about ate all variables in the rules, use the given interpretation to arc(x, y). transform the program into one without negation and func- tions, and check if the resulting program entails the same set Example 2 The Hamiltonian circuit problem can be for- of atoms true in the given interpretation. malized by the following rules: Given a logic program P , the grounding of P consists of ← not reached(x), type definitions as in P and the rules that are obtained by re- ← not arc(x, hc(x)), placing variables in the rules of P with elements in their re- reached(hc(x)) ← initial(x), spective domains (recall that we are assuming a many-sorted reached(hc(x)) ← reached(x). first-order language, and each variable has a type associated with it). Thus if variable x is of type τ and the domain of τ Here reached(x) and initial(x) are of arity vertex, and is D according to the type definitions in P , then x is to be hc(x) is a unary function of the type vertex → vertex.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us