C H A P T E R  2
Game Description

2.3 LOGIC PROGRAMS

Logic programs are built up from four disjoint classes of words, viz. object constants, function constants, relation constants, and variables. In our examples here, we write all constants as strings of alphanumeric characters beginning with a lower case letter or a digit, e.g. a, b, c, john, 123, r14, and so forth. We write variables as strings of alphanumeric characters beginning with an upper case letter, e.g. X, Y, Z, Age14, and so forth.

A term is either an object constant, a variable, or a functional term, i.e. an expression consisting of a function constant and n simpler terms. In what follows, we write functional terms in traditional mathematical notation - the function constant followed by its arguments enclosed in parentheses and separated by commas. For example, if f is a function constant, if a is an object constant, and if Y is a variable, then f(a,Y) is a term. Functional terms can be nested within other functional terms. For example, if f(a,Y) is a functional term, then so is f(f(a,Y),Y).

An atom is an expression formed from a relation constant and n terms. As with functional terms, we write atoms in traditional mathematical notation - the relation constant followed by its arguments enclosed in parentheses and separated by commas. For example, if r is a relation constant, if f is a function constant, if a is an object constant, and if Y is a variable, then r(a,Y) is a term and so is r(a,f(a,Y)). Although functional terms can be used within functional and within atoms, the reverse is not true - atoms cannot be nested inside of other atoms or inside of functional terms.

A literal is either an atom or a negation of an atom. A simple atom is called a positive literal, The negation of an atom is called a negative literal. In what follows, we write negative literals using the negation sign ~. For example, if p(a,b) is an atom, then ~p(a,b) denotes the negation of this atom.

A rule is an expression consisting of a distinguished atom, called the head, and k literals, called subgoals. In what follows, we write rules as in the example shown below. Here, q(X,Y) is the head, and the other literals are subgoals.

q(X,Y) :- p(X,Y), ~r(Y)

A logic program is a finite set of atoms and rules of this form. In order to simpify our definitions and analysis, we occasionally talk about infinite sets of rules. While these sets are useful, they are not themselves logic programs.

A rule in a logic program is safe if and only if every variable that appears in the head or in any negative literal in the body also appears in at least one positive literal in the body. A logic program is safe if and only if every rule in the program is safe.

The dependency graph for a logic program is a directed graph in which the nodes are the relations in the program and in which there is an arc from one node to another if and only if the former node appears in the body of a rule in which the latter node appears in the head. A program is recursive if and only if there is a cycle in the dependency graph.

A negation in a logic program is said to be stratified if and only if there is no recursive cycle in the dependency graph involving a negation. A logic program is stratified with respect to negation if and only if there are no unstratified negations.

The recursion in a set of rules is said to be stratified if and only if every variable in every subgoal relation (including the recursive relation) occurs in a subgoal involving a relation at a lower stratum, i.e. either it is not recursive or its recursive cycle does not include the relation in the head of the rule in which it occurs as a subgoal.

In GDL, we concentrate exclusively on logic programs that are both safe stratified with respect to negation and recursion. While it is possible to extend the results here to other programs, such extensions are beyond the scope of this work.

The Herbrand universe for a logic program is the set of all ground terms that can be formed from the constants used in the program. Note that, in the presence of function constants, the Herbrand universe is infinite (since functional terms can be nested arbitrarily deeply).

The Herbrand base for a logic program is the set of all atoms that can be formed from the terms in the program's Herbrand universe. Said another way, it is the set of all sentences of the form r(t1,...,tn), where r is a relation constant and t1, ..., tn are ground terms.

An instance of a rule in a logic program is a rule in which all variables have been replaced by terms from the program's Herbrand universe. Consistent replacement means that, if one occurrence of a variable is replaced by a given term, then all occurrences of that variable are replaced by the same term.

An interpretation for a logic program is an arbitrary subset of the Herbrand base for the program. A model of a logic program is an interpretation that satisfies the program (as defined below).

An interpretation Δ satisfies a logic program Ω if and only if Δ satisfies every ground instance of every sentence in Ω. The notion of satisfaction is defined recursively. An interpretation Δ satisfies a ground atom φ if and only if φ is in Δ. Δ satisfies a ground negation if and only if φ is not in Δ. Δ satisfies a ground rule ψ :- φ1,...,φn if and only if Δ satisfies ψ whenever it satisfies φ1,...,φn.

A model Δ of a logic program Ω is minimal if and only if no proper subset of Δ is a model for Ω. A logic program that does not contain any negations has one and only one minimal model. A logic program with negation may have more than one minimal model; however, if the program is stratified, then once again there is only one minimal model.

In general, a logic program can have more than one model, which means that there can be more than one way to satisfy the rules in the program. In order to eliminate ambiguity, we adopt the minimal model approach to logic program semantics, i.e. we define the meaning of a safe and stratified logic program to be its minimal model.

2.4 OPEN LOGIC PROGRAMS

Logic programs as just defined are closed in that they fix the meaning of all relations in the program. In open logic programs, some of the relations (the inputs) are undefined, and other relations (the outputs) are defined in terms of these. The same program can be used with different input relations, yielding different output relations in each case.

Formally, an open logic program is a logic program together with a partition of the relation constants into two types - base relations (also called input relations) and view relations (also called output relations). View relations can appear anywhere in the program, but base relations can appear only in the subgoals of rules, not in their heads.

The input base for an open logic program is the set of all atoms that can be formed from the base relation constants of the program and the terms in the program's Herbrand universe. An input model is an arbitrary subset of its input base.

The output base for an open logic program is the set of all atoms that can be formed from the view relation constants of the program and the terms in the program's Herbrand universe. An output model is an arbitrary subset of its output base.

Given an open logic program Ω and an input model Γ, we define the overall model corresponding to Γ to be the minimal model of Ω∪Γ. The output model corresponding to Γ is the intersection of the overall model with the program's output base.

Finally, we define the meaning of an open logic program to be a function that maps each input model for the program into the corresponding output model.

As an example, consider the simple open logic program shown below. The universe of discourse is {a,b,c}, p and q are base relations; and r is a view relation.

r(X,Y) :- p(X,Y), ~q(Y)

In this case, there are 212 input models, and for each there is a unique output model. The table below shows the output model for two of the possible input models.



Input ModelOutput Model
p(a)
q(b)
r(a,c)
p(a)
p(b)
r(a,c)
r(b,c)