The definition of a stable model below, reproduced from [Gelfond and Lifschitz, 1988], uses two conventions. First, a truth assignment is identified with the set of atoms that get the value
T. For instance, the truth assignment : is identified with the set \{p,s\}. This convention allows us to use the
set inclusion relation to compare truth assignments with each other. The smallest of all truth assignments \emptyset is the one that makes every atom false; the largest truth assignment makes every atom true. Second, a logic program with variables is viewed as shorthand for the set of all
ground instances of its rules, that is, for the result of substituting variable-free terms for variables in the rules of the program in all possible ways. For instance, the logic programming definition of even numbers :\operatorname{even}(0) :\operatorname{even}(s(X))\leftarrow \operatorname{not} \operatorname{even}(X) is understood as the result of replacing in this program by the ground terms :0, s(0), s(s(0)),\dots. in all possible ways. The result is the infinite ground program :\operatorname{even}(0) :\operatorname{even}(s(0))\leftarrow \operatorname{not} \operatorname{even}(0) :\operatorname{even}(s(s(0)))\leftarrow \operatorname{not} \operatorname{even}(s(0)) :\dots
Definition Let be a set of rules of the form :A \leftarrow B_{1},\dots,B_{m},\operatorname{not} C_{1},\dots,\operatorname{not} C_{n} where A,B_{1},\dots,B_{m},C_{1},\dots,C_{n} are ground atoms. If does not contain negation (n=0 in every rule of the program) then, by definition, the only stable model of is its model that is minimal relative to set inclusion. (Any program without negation has exactly one minimal model.) To extend this definition to the case of programs with negation, we need the auxiliary concept of the reduct, defined as follows. For any set of ground atoms, the
reduct of relative to is the set of rules without negation obtained from by first dropping every rule such that at least one of the atoms in its body :B_{1},\dots,B_{m},\operatorname{not} C_{1},\dots,\operatorname{not} C_{n} belongs to , and then dropping the parts \operatorname{not} C_{1},\dots,\operatorname{not} C_{n} from the bodies of all remaining rules. We say that is a
stable model of if is the stable model of the reduct of relative to . (Since the reduct does not contain negation, its stable model has been already defined.) As the term "stable model" suggests, every stable model of is a model of .
Example To illustrate these definitions, let us check that \{p,s\} is a stable model of the program :p :r \leftarrow p, q :s \leftarrow p, \operatorname{not} q. The reduct of this program relative to \{p,s\} is :p :r \leftarrow p, q :s \leftarrow p. (Indeed, since q\not\in\{p,s\}, the reduct is obtained from the program by dropping the part \operatorname{not} q. ) The stable model of the reduct is \{p,s\}. (Indeed, this set of atoms satisfies every rule of the reduct, and it has no proper subsets with the same property.) Thus after computing the stable model of the reduct we arrived at the same set \{p,s\} that we started with. Consequently, that set is a stable model. Checking in the same way the other 15 sets consisting of the atoms p, q, r, s shows that this program has no other stable models. For instance, the reduct of the program relative to \{p,q,r\} is :p :r \leftarrow p, q. The stable model of the reduct is \{p\}, which is different from the set \{p,q,r\} that we started with.
Programs without a unique stable model A program with negation may have many stable models or no stable models. For instance, the program :p \leftarrow \operatorname{not} q :q \leftarrow \operatorname{not} p has two stable models \{p\}, \{q\}. The one-rule program :p \leftarrow \operatorname{not} p has no stable models. If we think of the stable model semantics as a description of the behavior of
Prolog in the presence of negation then programs without a unique stable model can be judged unsatisfactory: they do not provide an unambiguous specification for Prolog-style query answering. For instance, the two programs above are not reasonable as Prolog programs—SLDNF resolution does not terminate on them. But the use of stable models in
answer set programming provides a different perspective on such programs. In that
programming paradigm, a given search problem is represented by a logic program so that the stable models of the program correspond to solutions. Then programs with many stable models correspond to problems with many solutions, and programs without stable models correspond to unsolvable problems. For instance, the
eight queens puzzle has 92 solutions; to solve it using answer set programming, we encode it by a logic program with 92 stable models. From this point of view, logic programs with exactly one stable model are rather special in answer set programming, like polynomials with exactly one root in algebra. ==Properties of the stable model semantics==