On Signings and the Well-Founded Semantics
aa r X i v : . [ c s . L O ] F e b Under consideration for publication in Theory and Practice of Logic Programming On Signings and the Well-Founded Semantics
Michael J. Maher
Reasoning Research InstituteCanberra, Australia ( e-mail: [email protected] ) submitted 1 January 2003; revised 1 January 2003; accepted 1 January 2003 Abstract
We use Kunen’s notion of a signing to establish two theorems about the well-founded semantics of logicprograms, in the case where we are interested in only (say) the positive literals of a predicate p that areconsequences of the program. The first theorem identifies a class of programs for which the well-foundedand Fitting semantics coincide for the positive part of p . The second theorem shows that if a program hasa signing then computing the positive part of p under the well-founded semantics requires the computationof only one part of each predicate. This theorem suggests an analysis for query-answering under the well-founded semantics. In the process of proving these results, we use an alternative formulation of the well-founded semantics of logic programs, which might be of independent interest. A signing of a logic program identifies a structure of the program that ensures that no predicatedepends both positively and negatively on another predicate. Signings have been used in sev-eral previous works. (Kunen 1989) introduced signings and used them to establish cases wherea three-valued model of the Clark-completion of P can be extended to a two-valued model.Any program has a corresponding signed program that is equivalent wrt SLDNF-resolution(Drabent and Martelli 1991). (Dung 1992) uses signings to establish existence of a stable modeland to identify cases where the well-founded and sceptical stable model semantics coincide.(Turner 1993) shows that signed logic programs have at least two stable models, unless the well-founded model is itself a stable model.In this note we address the situation where we are only interested in (say) the positive con-sequences of a program, for a predicate p (which we term the positive part of p ). This situationarose in the implementation of a defeasible logic (Maher et al. 2020) by compilation to Datalog ¬ (Maher 2021). Using signings, we identify a case where the well-founded and Fitting semanticscoincide for the positive part of p . More importantly, we show that, for programs with a signing,the positive part of p can be computed using only one part (positive or negative) of each predicateit depends on. This result extends to an analysis that can determine the extent to which a pro-gram without a signing can avoid computing parts of predicates. The proofs are facilitated by analternative formulation of the well-founded semantics, which might be of independent interest.The paper is structured as follows. In the next section, we provide the background needed,including defining signings and the well-founded semantics. Following that, in Section 3, wedefine an alternative formulation of the well-founded semantics. In Section 4 we establish thetwo theorems. The appendix contains re-proofs of the results by Kunen, Dung, and Turner. M.J. Maher
We introduce the elements of logic programming that we will need. The first part defines notationand terminology for syntactic aspects of logic programs, including signings. The second partdefines the semantics of logic programs we will use.
Let Π be a set of predicate symbols, Σ be a set of function symbols, and V be a set of variables.Each symbol has an associated arity greater or equal to 0. A function symbol of arity 0 is called a constant , while a predicate of arity 0 is called a proposition . The terms are constructed inductivelyin the usual way: any variable or constant is a term; if f ∈ Σ has arity n and t , . . . , t n are termsthen f ( t , . . . , t n ) is a term; all terms can be constructed in this way. An atom is constructed byapplying a predicate p ∈ Π of arity n to n terms. A literal is either an atom or a negated atom not a , where a is an atom.A logic program is a collection of clauses of the form a :- b , . . . , b m , not c , . . . , not c n where a, b , . . . , b m , c , . . . , c n are atoms ( m ≥ , n ≥ ). The positive literals and the negativeliterals are grouped separately purely for notational convenience. a is called the head of theclause and the remaining literals form the body . Sometimes, for brevity, we write a rule as a :- B .The set of all clauses with predicate symbol p in the head are said to be the clauses defining p . Weuse ground as a synonym for variable-free. The set of all variable-free instances of clauses in alogic program P is denoted by ground ( P ) . ground ( P ) can be considered a propositional logicprogram but it is infinite, in general. For the semantics we are interested in, P and ground ( P ) are equivalent with respect to inference of ground literals.We present some notions of dependence among predicates that are derived purely from thesyntactic structure of a logic program P . We follow the notation and definitions of (Kunen 1989). p , q and r range over predicates. We define p ⊒ +1 q if p appears in the head of a rule and q isthe predicate of a positive literal in the body of that rule. p ⊒ − q if p appears in the head of arule and q is the predicate of a negative literal in the body of that rule.We can represent these dependencies of P in a signed predicate dependency graph G whereeach predicate forms a vertex and there is an edge from p to q labeled + iff p ⊒ +1 q and an edgefrom p to q labeled − iff p ⊒ − q . (See Figure 1 for an example.) Given a logic program, thisgraph can be constructed in linear time.Building on these dependencies, we can define further dependencies and properties of a pro-gram. We define p ⊒ q iff p ⊒ +1 q or p ⊒ − q , and say p directly depends on q . The transitiveclosure of ⊒ is denoted by ≥ . If p ≥ q , we say p depends on q . We define p ≈ q iff p ≥ q and q ≥ p , expressing that p and q are mutually recursive. The binary relations ≥ +1 and ≥ − aredefined inductively as the least relations such that, for all predicates p , q and r , p ≥ +1 p and p ⊒ i q and q ≥ j r implies p ≥ i · j r n Signings and the Well-Founded Semantics i · j denotes multiplication of i and j . Essentially, ≥ +1 denotes a relation of dependencethrough an even number of negations and ≥ − denotes dependence through an odd number ofnegations. As is usual, we will write p ≤ q when q ≥ p , and similarly for other orderings.The transitive closure of ⊒ +1 is denoted by ≥ (Fages 1994) . P is positive order-consistent (Fages 1994) (also referred to as P being tight ) if ≥ is well-founded on ground ( P ) .A program P is stratified if there are no predicates p and q in Π such that p ≈ q and p ≥ − q .In other words, P is stratified if there is no negative dependency within a strongly connectedcomponent of the signed predicate dependency graph. This is equivalent to the original definition(Apt et al. 1988) that explicitly identified strata. A program P is said to be strict if no predicate p depends both positively and negatively on a predicate q , that is, we never have p ≥ +1 q and p ≥ − q .A set P ⊆ Π of predicates in a program P is downward-closed if, whenever p ∈ P and q ≤ p ,then q ∈ P . P is downward-closed with floor F if F ⊆ P and both P and F are downward-closed. The notion of downward-closed with floor underlies Dung’s notion of bottom-stratifiedand top-strict logic programs (Dung 1992). Indeed, if P is downward-closed with floor F , P isstrict on P\F , and P is stratified on F , then P is bottom-stratified and top-strict.A signing on P for a program P is a function s that maps P to {− , +1 } such that, for p, q ∈P , p ≤ i q implies s ( p ) = s ( q ) · i . A signing is extended to atoms by defining s ( p ( ~a )) = s ( p ) . Forany signing s for a set of predicates P , there is an inverted signing ¯ s , defined by ¯ s ( p ) = − s ( p ) . s and ¯ s are equivalent in the sense that they partition P into the same two sets. Obviously, ¯¯ s = s .Let all the predicates of P be contained in P . If P has a signing for P , then P is strict; if P hasa ≥ -largest predicate and P is strict, then P has a signing for P (Kunen 1989).It is relatively easy to determine whether a program P has a signing on P . We assume anundirected version of the signed predicate dependency graph G , restricted to P . We analyse eachconnected component of G separately. Arbitrarily choose a vertex in the component and assignit a value in { +1 , − } . We now propagate signs to adjacent vertices: if p has sign i and thereis an (undirected) edge to q of sign j (that is, either p ⊒ j q or q ⊒ j p ), then q must have sign i · j , if there is a signing. Thus, if such a vertex q is unassigned, it is assigned i · j . If it alreadyhas a different sign than i · j , then we halt with failure: there is no signing. Otherwise, iteratingthis process for each newly-signed vertex generates a signing for the component. The wholepropagation, for all components, can be done during a single depth-first search of G . Thus, thecomputational cost is linear in the size of G (Cormen et al. 2001) and, hence, linear in the size of P . Proposition 1
Deciding whether a logic program has a signing is computable in linear time.A similar set of dependencies over ground atoms can be defined by applying these definitionsto ground ( P ) , where ground atoms are considered propositions (i.e. predicates). The results ofthis paper continue to hold using those notions.Given a program P , an infinite sequence of atoms { q i ( ~a i ) } is unfounded wrt a set of predicates Q if, for every i , q i ⊒ +1 q i +1 and q i ∈ Q . We say a predicate p avoids negative unfoundedness Equivalently, if we view these conditions as definite clauses, ≥ +1 and ≥ − are determined by the least model ofthese clauses and facts for ⊒ +1 and ⊒ − . Note that, despite the notation, ≥ and ≥ are not necessarily reflexive: if p does not depend on p , then we do not have p ≥ p nor p ≥ p . If it is desired that a specific predicate has a positive sign, that can be enforced here.
M.J. Maher wrt a signing s on Q if for every negatively signed predicate q on which p depends, no q -atomstarts an unfounded sequence wrt Q .We have the following sufficient condition for avoiding negative unfoundedness. Let ≥ Q de-note the transitive closure of ⊒ +1 on Q . We say a predicate p avoids negative predicate unfound-edness wrt a signing s on Q if, for all q ≤ p , ( q ≥ Q q ) → s ( q ) = +1 . That is, the only predicateson which p depends that take part in a positive cycle among predicates of Q have a positive sign. Proposition 2
Let P be a program, Q a finite subset of Π , and p ∈ Q . Let s be a signing on Q for P . If p avoidsnegative predicate unfoundedness wrt s on Q , then p avoids negative unfoundedness wrt s on Q . Proof
We prove the contrapositive. Suppose p does not avoid negative unfoundedness. Then there isa predicate q such that p ≥ q , s ( q ) = − , and { q i ( ~a i ) } forms an unfounded sequence wrt Q with q ≡ q . Then we must have q ⊒ +1 q ⊒ +1 q ⊒ +1 · · · and, because s ( q ) = − and thedependencies are positive, s ( q i ) = − , for every i . Since Q has only finitely many predicates,a predicate q j must be repeated. Hence, q j ≥ Q q j and s ( q j ) = − . Therefore, p does not avoidnegative predicate unfoundedness.Using the signed predicate dependency graph, we can determine which predicates avoid nega-tive predicate unfoundedness wrt s on Q . We restrict our attention to the subgraph with verticesin Q . First, using only the positive dependencies ⊒ +1 in the subgraph we find the strongly con-nected components (SCCs). Given the signing, all vertices in an SCC have the same sign. ThoseSCCs consisting of a single vertex without an edge to itself can be ignored; of the remainingSCCs, we choose a predicate from each SCC that has a negative sign. Then, using the full signedpredicate dependency graph, we mark all vertices that depend on any of the chosen vertices;these predicates do not avoid negative predicate unfoundedness. Unmarked predicates do avoidnegative predicate unfoundedness and, hence, avoid negative unfoundedness. This method has alinear cost in the size of the signed predicate dependency graph. We define the semantics of interest in this paper and identify important relationships betweenthem.We will only be interested in Herbrand interpretations and models. A is a mapping from ground atoms to one of three truth values: true , false , and unknown . This mapping can be extended to all formulas using Kleene’s 3-valued logic (Kleene 1952).Equivalently, a 3-valued Herbrand interpretation I can be represented as the set of literals { a | I ( a ) = true } ∪ { not a | I ( a ) = false } . This representation is used in the following definitions. Theinterpretations are ordered by the subset ordering on this representation. Given an interpretation I , the positive part of a predicate p is { p ( ~a ) | p ( ~a ) ∈ I } , the restriction of I to p -atoms, and the negative part of p is { not p ( ~a ) | not p ( ~a ) ∈ I } , the restriction of I to negative p -literals.We review some notions of fixedpoints of functions on 3-valued Herbrand interpretations. Aninterpretation X is a pre-fixedpoint of a function f if f ( X ) ⊆ X ; thus, a pre-fixedpoint is closedunder the action of f . X is a fixedpoint of f if f ( X ) = X . f is monotonic if X ≤ Y implies We refrain from referring to this property as negative positive order-consistency . n Signings and the Well-Founded Semantics f ( X ) ≤ f ( Y ) . For any X and monotonic f , we define lf p ( f, X ) to be the least fixedpointgreater than (or equal to) X . lf p ( f ) is the least fixedpoint greater than the bottom element ∅ .We refine the ↑ notation and Kleene sequence. The Kleene sequence for f from X is a possiblytransfinite sequence of interpretations, defined as follows: f ↑ Xf ↑ ( β + 1) = f ( f ↑ β ) ∪ f ↑ βf ↑ α = S β<α f ↑ β if α is a limit ordinalIf f is monotonic and lf p ( f, X ) exists then the limit of this sequence is lf p ( f, X ) . This isdifferent from the usual definition of Kleene sequence, so that it can start from any X . It isstraightforward to show that if X ⊆ f ( X ) , then lf p ( f, X ) exists, by induction on the Kleenesequence, and that lf p ( f, X ) is also the least pre-fixedpoint greater than X .Fitting (Fitting 1985) defined a semantics for a logic program P in terms of a function Φ P mapping 3-valued interpretations, which we define as follows. Φ P ( I ) = Φ + P ( I ) ∪ ¬ Φ − P ( I )Φ + P ( I ) = { a | there is a rule a :- B in ground ( P ) where I ( B ) = true } Φ − P ( I ) = { a | for every rule a :- B in ground ( P ) with head a, I ( B ) = false } where ¬ S denotes the set { not s | s ∈ S } . Fitting’s semantics associates with P the least fixedpoint of Φ P , that is lf p (Φ P ) . This is theleast 3-valued Herbrand model of the Clark completion P ∗ of P . Thus, the conclusions justifiedunder this semantics are those formulas that evaluate to true under all 3-valued Herbrand modelsof P ∗ .The stratified semantics (Apt et al. 1988) (or iterated fixedpoint semantics) applies only when P is stratified. It is defined in stages, by building up partial models, based on the strata, until a fullmodel is constructed. For a more complete description, see (Apt et al. 1988; Apt and Bol 1994).The stratified semantics extends Fitting’s semantics, when the program is stratified.The well-founded semantics (Van Gelder et al. 1991) extends Fitting’s semantics by, roughly,considering atoms to be false if they are supported only by a “loop” of atoms. This is based onthe notion of unfounded sets.Given a logic program P and a 3-valued interpretation I , a set A of ground atoms is an un-founded set with respect to I iff each atom a ∈ A satisfies the following condition: For each rule r of ground ( P ) whose head is a , (at least) one of the following holds:1. Some literal in the body evaluates to false in I .2. Some atom in the body occurs in A The greatest unfounded set of P with respect to I (denoted U P ( I ) ) is the union of all theunfounded sets with respect to I . Notice that, if we ignore the second part of the definition ofunfounded set wrt I , the definition of unfounded set is the same as the expression inside thedefinition of Φ − P ( I ) . It follows that Φ − P ( I ) ⊆ U P ( I ) , for every I .The function W P ( I ) is defined by W P = Φ + P ( I ) ∪ ¬ U P ( I ) . The well-founded semantics ofa program P is represented by the least fixedpoint of W P . This is a 3-valued Herbrand model of P ∗ . Because Φ − P ( I ) ⊆ U P ( I ) , for every I , we have Φ P ( I ) ⊆ W P ( I ) , for every I , and, hence, lf p (Φ P ) ⊆ lf p ( W P ) . That is, Fitting’s semantics is weaker than the well-founded semantics.(Hitzler and Wendt 2002) show that the well-founded semantics and the Fitting semantics arecharacterized by different partial level mappings, where the level mappings for the well-founded M.J. Maher semantics are more permissive than those for Fitting’s semantics. If P is stratified then the well-founded semantics is a 2-valued Herbrand model of P ∗ and equal to the stratified semantics. We will find it useful to have a different formulation of the well-founded semantics that clarifieshow the well-founded semantics extends Fitting’s semantics. We say a set A of ground atoms is a circular unfounded set with respect to I iff A is an unfounded set wrt I and, for each a ∈ A thereis a rule r ∈ ground ( P ) with head a with no literal evaluating to false in I (and, hence, someatom b in the body of r occurs in A ). The greatest circular unfounded set of P with respect to I (denoted Z P ( I ) ) is the union of all the circular unfounded sets with respect to I . Obviously,any element of Z P ( I ) , for any I , is the start of an unfounded sequence. Consequently, if P ispositive order-consistent (or tight), then Z P ( I ) is empty.A minimalistic circular unfounded set of P wrt I is a circular unfounded set S of P wrt I such that either it is empty, or it cannot be partitioned into two disjoint nonempty circularunfounded sets . If P has a signing s , all elements of a minimalistic circular unfounded setmust have the same sign. Thus, with a slight abuse of language, we can say that minimalisticcircular unfounded sets have a sign. Let a program P and a signing s for P be fixed. We define Z − P ( I ) to be the greatest circular unfounded set of P wrt I consisting only of atoms a with s ( a ) = − . It can be obtained as the union of all minimalistic circular unfounded sets with sign − . Similarly, Z +1 P ( I ) is the greatest circular unfounded set with sign +1 . It should be clear that Z P ( I ) = Z +1 P ( I ) ∪ Z − P ( I ) .Define W ′ P ( I ) = Φ + P ( I ) ∪ ¬ Φ − P ( I ) ∪ ¬ Z P ( I ) . Then W ′ P ( I ) ⊆ W P ( I ) , for every I , sinceboth Φ − P ( I ) and Z P ( I ) are clearly subsets of U P ( I ) . We now show that W P and W ′ P have thesame pre-fixedpoints and fixedpoints. Lemma 3
For every 3-valued interpretation I , W P ( I ) ⊆ I iff W ′ P ( I ) ⊆ I and W P ( I ) = I iff W ′ P ( I ) = I Proof
Part 1. One direction is straightforward: since W ′ P ( I ) ⊆ W P ( I ) , if W P ( I ) ⊆ I then also W ′ P ( I ) ⊆ I .For the other direction, suppose W ′ P ( I ) ⊆ I . Let I − = { a | not a ∈ I } be the atoms thatevaluate to false in I . Then Φ + P ( I ) ⊆ I , Φ − P ( I ) ⊆ I − , and Z P ( I ) ⊆ I − . Let S = U P ( I ) \ I − .For every a ∈ S , a / ∈ Φ − P ( I ) because Φ − P ( I ) ⊆ I − , so there is a rule in ground ( P ) such that “circular” is something of a misnomer. If ground ( P ) is infinite, then an infinite set A can satisfy the conditionswithout any circularity. However, for finite Datalog ¬ programs, A does exhibit a cycle. The definition of circular unfounded set is similar to the definition in (Brass et al. 2001) of an unfounded set oncethe program is simplified by all literals inferred by Fitting’s semantics, but here the program is not simplified and, ingeneral, most literals have not been inferred. A minimalistic circular unfounded set is not necessarily a minimal circular unfounded set. For example, given theprogram { q :- p. p :- p. } , the set { p, q } is minimalistic, because it cannot be partitioned into disjoint nonempty circularunfounded sets, but not minimal because { p } is a circular unfounded set. n Signings and the Well-Founded Semantics false under I and, hence, there is a body atom b in U P ( I ) , by thedefinition of unfounded set. Further, b / ∈ I − , because no body literal evaluates to false under I .Thus, b ∈ S . Hence, S is a circular unfounded set of P with respect to I . Thus, S ⊆ Z P ( I ) ⊆ I − .This shows that S must be empty. Hence, U P ( I ) ⊆ I − and, consequently, W P ( I ) ⊆ I .Part 2. Suppose W ′ P ( I ) = I . Then W P ( I ) ⊆ I by Part 1. W ′ P ( I ) ⊆ W P ( I ) , as observed above,so I ⊆ W P ( I ) . Hence, W P ( I ) = I .Suppose W P ( I ) = I . Then W ′ P ( I ) ⊆ I by Part 1. Let S = U P ( I ) \ Φ − P ( I ) . Suppose a ∈ S .Then there is a rule instance a :- B such that I ( B ) = false , because a / ∈ Φ − P ( I ) , and, hence,there is an atom b ∈ B such that b ∈ U P ( I ) , by the definition of unfounded set. But then not b ∈ I because I = W P ( I ) = Φ + P ( I ) ∪ U P ( I ) and, as a result, I ( B ) = false . Thiscontradiction shows that S is empty. Consequently, U P ( I ) = Φ − P ( I ) .Now I = W P ( I ) = Φ + P ( I ) ∪ U P ( I ) = Φ + P ( I ) ∪ Φ − P ( I ) ⊆ W ′ P ( I ) . Hence, W ′ P ( I ) = I .It is now straightforward to show that W ′ P provides an alternative formulation of the well-founded semantics. Theorem 4
For any interpretation J , if either lf p ( W P , J ) or lf p ( W ′ P , J ) is defined, then they are bothdefined and lf p ( W P , J ) = lf p ( W ′ P , J ) In particular lf p ( W P ) = lf p ( W ′ P ) Proof
If there is a least fixedpoint greater than J , then it is a fixedpoint of both W P and W ′ P , by theprevious lemma. In particular, when J = ∅ , lf p ( W P ) = lf p ( W ′ P ) .Because Φ + P , Φ − P , and Z P are monotonic, they can be interleaved in any fair way to obtain thefixedpoint, as a chaotic iteration. Indeed, each of these functions can be decomposed further, andapplication of those pieces interleaved.Finally, using the alternate characterization of the well-founded semantics, we have a simpleproof of an extension of a result of (Berman et al. 1995). If a logic program is positive order-consistent (or tight) then the well-founded and Fitting semantics coincide. Proposition 5
Let P be a logic program, P ⊆ Π be a downward-closed set of predicates with floor F , Q be P\F , and Q be the rules in P defining predicates in Q . Let I be a fixed semantics for F .If Q is positive order-consistent, then lf p ( W Q , I ) = lf p (Φ Q , I ) . Proof Q is positive order-consistent, so ≤ is well-founded and Z Q ( J ) is empty, for every J . Conse-quently W ′ Q ( J ) = Φ Q ( J ) , for every J , and, hence, lf p ( W Q , I ) = lf p (Φ Q , I ) . If P is downward-closed with floor F , and I is a 3-valued Herbrand model of predicates in F then lf p ( W P , I ) is the well-founded model of P extending I , that is, the well-founded semantics M.J. Maher of P after all predicates in F are interpreted according to I . Similarly, lf p (Φ P , I ) , the Fittingsemantics of P extending I , is the Fitting semantics of P after all predicates in F are interpretedaccording to I . Such a notion is interesting, in general, because predicates in F might be definedoutside the logic programming setting, or in a different module.It is interesting in the context of this paper because often a full logic program does not have asigning but, after omitting some support and utility predicates, the remainder does have a signing.So, if P is downward-closed with floor F , then F can be considered the support predicates and P\F the remainder with a signing.We can now establish conditions under which the well-founded semantics and Fitting seman-tics agree on the truth value of some ground literals (even if they may disagree on other literals).This can be seen as a refinement of Proposition 5 in that only a subset of predicates is requiredto be positive order-consistent.
Theorem 6
Let P be a logic program, P ⊆ Π be a downward-closed set of predicates with floor F , Q be P\F , and s be a signing on Q . Let I be a fixed semantics for F and p be a predicate defined in Q . Suppose p avoids negative unfoundedness wrt s .For any ground atom p ( ~a ) :If s ( p ) = +1 then p ( ~a ) ∈ lf p ( W Q , I ) iff p ( ~a ) ∈ lf p (Φ Q , I ) If s ( p ) = − then not p ( ~a ) ∈ lf p ( W Q , I ) iff not p ( ~a ) ∈ lf p (Φ Q , I ) Proof
Let Q denote the subset of P defining predicates q of Q that p depends on (that is, p ≥ q ). Itsuffices to prove the result for Q , since P and Q agree on the semantics of the predicates in Q under both well-founded and Fitting semantics.We prove the theorem using transfinite induction on the Kleene sequences from I . The “if”directions are well-known to hold when the floor is empty, independent of the other condi-tions (Van Gelder et al. 1991). They can be proved by transfinite induction, using the facts that Φ P ( I ) ⊆ W P ( I ) , for any P and I , and both functions are monotonic over the subset ordering.The proof of the “only if” directions is also by transfinite induction on the Kleene sequence.We use the alternate formulation of the well-founded semantics. We claim that, at each stage α ,the set of true positively-signed atoms is the same in Φ Q ↑ α and W ′ Q ↑ α and the set of falsenegatively-signed atoms is the same in Φ Q ↑ α and W ′ Q ↑ α . This is true trivially when α = 0 ,since Φ Q ↑ I = W ′ Q ↑ . If α is a limit ordinal then Φ Q ↑ α = S β<α Φ Q ↑ β and W ′ Q ↑ α = S β<α W ′ Q ↑ β . By the induction hypothesis, the two sets agree on true positively-signed atoms and false negatively-signed atoms.Suppose α is a successor ordinal, say α = β + 1 . Suppose the induction hypothesis holds at β .Consider a positively-signed predicate p and a ground instance a :- b , . . . , b n , not c , . . . , not c m of a rule for p . Because of the signing, b , . . . , b n have positive signs and c , . . . , c m havenegative signs, except perhaps for those with predicates from F . By the induction hypothesis, b i ∈ W ′ Q ↑ β iff b i ∈ Φ Q ↑ β and not c j ∈ W ′ Q ↑ β iff not c j ∈ Φ Q ↑ β . Hence, a ∈ W ′ Q ↑ α iff a ∈ Φ Q ↑ α .Now, consider a negatively-signed predicate p and a ground instance of a rule for p : a :- b , . . . , b n , not c , . . . , not c m . Under the signing s , b , . . . , b n have negative signs and c , . . . , c m have positive signs, except for those with predicates from F . Because p avoids neg-ative unfoundedness wrt s , there is not a circular unfounded set wrt W ′ Q ↑ β containing any n Signings and the Well-Founded Semantics b i . Thus, not a ∈ W ′ Q ( W ′ Q ↑ β ) iff not a ∈ ¬ Φ − Q ( W ′ Q ↑ β ) iff some not b i ∈ W ′ Q ↑ β orsome c j ∈ W ′ Q ↑ β , for every ground instance of a rule in P with head a . By the inductionhypothesis, not b i ∈ W ′ Q ↑ β iff not b i ∈ Φ Q ↑ β and c j ∈ W ′ Q ↑ β iff c j ∈ Φ Q ↑ β . Hence, not a ∈ W ′ Q ↑ ( β + 1) iff not a ∈ Φ Q ↑ ( β + 1) .By induction, the claim holds for each stage α and, in particular, at the fixedpoint. Thus, wehave p ( ~a ) ∈ lf p ( W Q , I ) iff p ( ~a ) ∈ lf p (Φ Q , I ) for any predicate p in P with a positive sign, andalso not p ( ~a ) ∈ lf p ( W Q , I ) iff not p ( ~a ) ∈ lf p (Φ Q , I ) for any predicate p in P with a negativesign.Hence, if we are only interested in the part of a predicate p satisfying the conditions of thetheorem, and the predicates of F are computed, then the Fitting and well-founded semantics areequivalent. That is, it suffices to compute using Φ P instead of W P or W ′ P . When P is a finitepropositional program, this gives a linear cost to compute the part of p , instead of a worst-casequadratic cost. (In other cases, the advantage is less clear.) Alternatively, under the conditions ofthe theorem, we can compute Fitting’s semantics for the part of p by using an implementation ofthe well-founded semantics.This result is applicable to the metaprogram for the defeasible logic DL ( ∂ || ) (Maher 2021),where we are only interested in the positive part of the predicate defeasibly . That part repre-sents the defeasible consequences of a defeasible theory. The signed program dependency graphis depicted in Figure 1. Let P be all predicates in the program and Q be the set { defeasibly , overruled , defeated } . Let F be P\Q . Then P is a downward-closed set of predicates withfloor F . Furthermore, Q has a signing s that maps defeasibly and defeated to +1 and overruled to − . Finally, overruled avoids negative unfoundedness wrt s and Q , because overruled does not depend positively on any predicate in Q .The previous theorem shows that, in some circumstances, we can ignore the computation ofunfounded sets when computing the well-founded semantics. In the next theorem we show that,in different circumstances, only the positive or only the negative conclusions for each predicateneed to be computed. In terms of an alternating fixedpoint implementation (Van Gelder 1989),only the underestimate or only the overestimate needs to be computed for each predicate.We will need refinements of the Φ functions used in defining Fitting’s semantics. Let s bea signing on P . We define Φ + sP ( I ) = { a ∈ Φ + P ( I ) | s ( a ) = +1 } and Φ − sP ( I ) = { a ∈ Φ − P ( I ) | s ( a ) = − } . Notice that + and − in this notation are doing double duty, represent-ing both the sign of the predicates and the polarity of the inference.Now we can define a very weak form of W ′ P : UU sP ( I ) = Φ + sP ( I ) ∪ ¬ Φ − sP ( I ) ∪ ¬Z − P ( I ) UU sP only infers positively signed atoms and negatively signed negative literals, that is, it onlyinfers the positive part of a positively signed predicate and the negative part of a negatively signedpredicate. So UU sP is substantially weaker than W ′ P . In fact, W ′ P ( I ) = UU sP ( I ) ∪ UU ¯ sP ( I ) . Theorem 7
Let P be a logic program, P ⊆ Π be a downward-closed set of predicates with floor F , Q be P\F , and s be a signing on Q . Let I be a fixed semantics for F .For any ground atom a :If s ( a ) = +1 then a ∈ lf p ( W Q , I ) iff a ∈ lf p ( UU sQ , I ) If s ( a ) = − then not a ∈ lf p ( W Q , I ) iff not a ∈ lf p ( UU sQ , I ) M.J. Maher defeasiblyoverruled defeatedlambdadefinitely supfact rules or d defeaterdefeasiblestrict – + – + + – ++ – + + +++ + ++ ++++ Fig. 1. A signed predicate dependency graph. Positive (negative) dependencies are labelled by+ (respectively, –).
Proof
Let Q be the clauses defining the predicates in Q . We use the alternate formulation of the well-founded semantics. We claim that, at each stage α , the set of true positively-signed atoms isthe same in UU sQ ↑ α and W ′ Q ↑ α and the set of false negatively-signed atoms is the same in UU sQ ↑ α and W ′ Q ↑ α . This is true trivially when α = 0 , since UU sQ ↑ I = W ′ Q ↑ . If α is alimit ordinal then UU sQ ↑ α = S β<α UU sQ ↑ β and W ′ Q ↑ α = S β<α W ′ Q ↑ β . By the inductionhypothesis, the two sets agree on true positively-signed atoms and false negatively-signed atoms.If α is a successor ordinal, say α = β + 1 , suppose the induction hypothesis holds at β . Con-sider any positively-signed predicate p and a ground instance a :- b , . . . , b n , not c , . . . , not c m of a rule for p . Because of the signing, b , . . . , b n have positive signs and c , . . . , c m have neg-ative signs, except perhaps for those predicates from F , which are not signed. By the induction n Signings and the Well-Founded Semantics b i ∈ W ′ Q ↑ β iff b i ∈ UU sQ ↑ β and not c j ∈ W ′ Q ↑ β iff not c j ∈ UU sQ ↑ β . Hence, a ∈ W ′ Q ↑ ( β + 1) iff a ∈ UU sQ ↑ ( β + 1) .Now, consider a negatively-signed predicate p and a ground instance of a rule for p : a :- b , . . . , b n , not c , . . . , not c m . Under the signing s , b , . . . , b n have negative signs and c , . . . , c m have positive signs, again except for predicates in F . By the induction hypothesis, not b i ∈ W ′ Q ↑ β iff not b i ∈ UU sQ ↑ β and c j ∈ W ′ Q ↑ β iff c j ∈ UU sQ ↑ β . Sincethis applies to all such clauses for a , a ∈ Φ + P ( W ′ Q ↑ β ) iff a ∈ Φ + sP ( UU sQ ↑ β ) . Further-more, a ∈ Z Q ( W ′ Q ↑ β ) iff a ∈ Z − Q ( UU sQ ↑ β ) , because a has a negative sign. Hence, a ∈ W ′ Q ↑ ( β + 1) iff a ∈ UU sQ ↑ ( β + 1) . This applies to all atoms a with a negatively-signedpredicate.By transfinite induction, for all ordinals α , and all ground atoms a , if s ( a ) = +1 then a ∈W ′ Q ↑ α iff a ∈ UU sQ ↑ α , and if s ( a ) = − then not a ∈ W ′ Q ↑ α iff not a ∈ UU sQ ↑ α . Inparticular, this applies to the ordinal that reaches a fixedpoint.Since lf p ( W Q , I ) = lf p ( W ′ Q , I ) (by Theorem 4), the result follows.Thus, for signed programs, the situation is analogous to computing predicates in stratifiedprograms, where only the positive part need be computed: the negative part is then known as thecomplement of the positive part. However, in the case of signed programs, the negative part isnot needed.If we want to infer a negatively signed atom, we can use ¯ s in place of s , that is, use UU ¯ sP .However, if we want to infer both a negatively signed atom and a positively signed atom, even ifthey contain different predicates, neither function will suffice.The above theorem suggests a very simple analysis for arbitrary programs that, given a query,can determine whether the positive or negative parts of a predicate do not need to be computedwhen evaluating the well-founded semantics. Specifically, we identify which predicates appearpositively and which appear negatively in the query, that is, which predicates require their posi-tive part and which require their negative part. This information can then be propagated over thesigned predicate dependency graph. If the positive part of p may be needed and p depends posi-tively on q , then the positive part of q may be needed. If the positive part of p may be needed and p depends negatively on q , then the negative part of q may be needed. Similarly, if the negativepart of p may be needed and p depends positively (negatively) on q , then the negative (positive)part of q may be needed.After full propagation, those predicates that may need only the positive (respectively, negative)parts to be computed can safely avoid generating their negative (respectively, positive) parts.Those predicates that may be needed both positively and negatively will need both parts to becomputed. This is a simple analysis, and should be easy to incorporate into an algorithm foranswering queries under the well-founded semantics. Its cost is linear in the size of the signedpredicate dependency graph. For implementations based on Van Gelder’s alternating fixedpointapproach, the result should be an improvement in both time and space requirements.Applying this analysis to the program of Figure 1, where only the positive part of defeasibly is of interest, we find that only the predicates definitely , fact , s or d , defeasible , and strict may be needed both positively and negatively. For each of the remaining predicates,only one part will need to be computed.Specifically, definitely and lambda can be computed using only their positive parts, sincethat part of the program is stratified. Then we only need the positive part of defeated and thenegative part of overruled to compute the positive part of defeasibly .2 M.J. Maher
The integration of the ideas in this paper with magic sets (Morishita 1996; Kemp et al. 1997)and optimizations based on pre-mappings (Zaniolo et al. 2017) is left for further research.
Acknowledgements:
The author has an adjunct position at Griffith University and an honoraryposition at UNSW. He thanks the referees for comments that helped improve this paper.
References A PT , K. R., B LAIR , H. A.,
AND W ALKER , A. 1988. Towards a theory of declarative knowledge. In
Foundations of Deductive Databases and Logic Programming.
Morgan Kaufmann, 89–148.A PT , K. R. AND B OL , R. N. 1994. Logic programming and negation: A survey. J. Log. Program. 19/20 ,9–71.B
ERMAN , K. A., S
CHLIPF , J. S.,
AND F RANCO , J. V. 1995. Computing well-founded semantics faster. In
Logic Programming and Nonmonotonic Reasoning, Third International Conference, LPNMR’95 , V. W.Marek and A. Nerode, Eds. Lecture Notes in Computer Science, vol. 928. Springer, 113–126.B
RASS , S., D IX , J., F REITAG , B.,
AND Z UKOWSKI , U. 2001. Transformation-based bottom-up computa-tion of the well-founded model.
Theory and Practice of Logic Programming 1,
5, 497–538.C
ORMEN , T. H., L
EISERSON , C. E., R
IVEST , R. L.,
AND S TEIN , C. 2001.
Introduction to Algorithms,Second Edition . The MIT Press and McGraw-Hill Book Company.D
RABENT , W.
AND M ARTELLI , M. 1991. Strict completion of logic programs.
New Gener. Comput. 9,
UNG , P. M. 1992. On the relations between stable and well-founded semantics of logic programs.
Theor.Comput. Sci. 105,
1, 7–25.F
AGES , F. 1994. Consistency of Clark’s completion and existence of stable models.
Meth. of Logic inCS 1,
1, 51–60.F
ITTING , M. 1985. A Kripke-Kleene semantics for logic programs.
J. Log. Program. 2,
4, 295–312.G
ELFOND , M.
AND L IFSCHITZ , V. 1988. The stable model semantics for logic programming. In
Proc.JICSLP . 1070–1080.G
IRE , F. 1992. Well founded semantics and stable semantics of semi-strict programs. In
Database Theory- ICDT’92, 4th International Conference, Berlin, Germany, October 14-16, 1992, Proceedings , J. Biskupand R. Hull, Eds. Lecture Notes in Computer Science, vol. 646. Springer, 261–275.G
IRE , F. 1994. Equivalence of well-founded and stable semantics.
J. Log. Program. 21,
2, 95–111.H
ITZLER , P.
AND W ENDT , M. 2002. The well-founded semantics is a stratified Fitting semantics. In
KI2002: Advances in Artificial Intelligence, 25th Annual German Conference on AI, KI 2002 , M. Jarke,J. Koehler, and G. Lakemeyer, Eds. Lecture Notes in Computer Science, vol. 2479. Springer, 205–221.K
EMP , D. B., R
AMAMOHANARAO , K.,
AND S TUCKEY , P. J. 1997. An efficient evaluation technique fornon-stratified programs by transformation to explicitly locally stratified programs.
Journal of SystemsIntegration 7,
LEENE , S. C. 1952.
Introduction to Metamathematics . Van Nostrand.K
UNEN , K. 1989. Signed data dependencies in logic programs.
J. Log. Program. 7,
3, 231–245.M
AHER , M. J. 2021. Defeasible reasoning via Datalog ¬ . , forthcoming.M AHER , M. J., T
ACHMAZIDIS , I., A
NTONIOU , G., W
ADE , S.,
AND C HENG , L. 2020. Rethinking defea-sible reasoning: A scalable approach.
TPLP 20,
4, 552–586.M
ORISHITA , S. 1996. An extension of Van Gelder’s alternating fixpoint to magic programs.
J. Comput.Syst. Sci. 52,
3, 506–521.T
URNER , H. 1993. A monotonicity theorem for extended logic programs. In
Proc. of the Tenth Int. Conf.on Logic Programming . 567–585.V AN G ELDER , A. 1989. The alternating fixpoint of logic programs with negation. In
Proceedings of theEighth ACM Symposium on Principles of Database Systems . 1–10. n Signings and the Well-Founded Semantics V AN G ELDER , A., R
OSS , K. A.,
AND S CHLIPF , J. S. 1991. The well-founded semantics for general logicprograms.
J. ACM 38,
3, 620–650.Z
ANIOLO , C., Y
ANG , M., I
NTERLANDI , M., D AS , A., S HKAPSKY , A.,
AND C ONDIE , T. 2017. Fixpointsemantics and optimization of recursive Datalog programs with aggregates.
TPLP 17, M.J. Maher
Appendix A Re-proofs
This appendix contains proofs of minor variations of theorems in (Kunen 1989), (Dung 1992),and (Turner 1993). This is just a bonus; the results of this paper do not depend on these results.The statements of the theorems now allow a floor, which is not signed, and have other smallvariations.The following theorem is a minor variation of a theorem (Theorem 3.3) that was stated in(Kunen 1989) without proof.
Theorem 8 (Kunen 1989)
Let P be a logic program, P ⊆ Π be a downward-closed set of predicates with floor F , let Q be P\F , and s be a signing on Q for P . Let I be a fixed two-valued semantics for F and let A be a3-valued model of Clark’s completion P ∗ extending I . Then there is a two-valued model A ′ of P ∗ that extends A .Specifically, A ′ can be defined as follows:If s ( p ) = +1 then p ( ~a ) ∈ A ′ iff not p ( ~a ) / ∈ A If s ( p ) = − then not p ( ~a ) ∈ A ′ iff p ( ~a ) / ∈ A Proof
We need to establish that A ′ is a model of P ∗ , Clark’s completion of P . Consider ground ( P ) ,where the rules of P are grounded by the elements of A , and the corresponding completion ground ( P ) ∗ , which might involve infinite disjunctions. We will refer to the elements of ground ( P ) ∗ of the form a ↔ ∨ i ∈ I B i as defs .For each ground atom a , consider all ground rules with a as head, and the corresponding def.If A ( a ) = true then the body of some rule evaluates to true in A . If A ( a ) = false then in eachrule, some literal evaluates to false in A . In both cases, the def for a is also satisfied by A ′ .If A ( a ) = unknown then no rule body evaluates to true and some rule body B evaluatesto unknown (that is, no body literal evaluates to false and at least one literal evaluates to unknown ) in A . Suppose s ( a ) = +1 . Then A ′ ( a ) = true , from the definition of A ′ . Ifan atom b ∈ B evaluates to unknown in A then, because s ( b ) = +1 , A ′ ( b ) = true . If not c ∈ B evaluates to unknown in A then, because s ( c ) = − , A ′ ( c ) = false . As a result, A ′ ( B ) = true . Now suppose s ( a ) = − . Then A ′ ( a ) = false . If an atom b ∈ B evaluates to unknown in A then, because s ( b ) = − , A ′ ( b ) = false . If not c ∈ B evaluates to unknown in A then, because s ( c ) = +1 , A ′ ( c ) = true . As a result, A ′ ( B ) = false . In both cases, the deffor a is satisfied by A ′ .When I is not already a 2-valued model of P ∗ , we can get a second 2-valued model by using ¯ s , instead of s . This is similar to Turner’s extension of a well-founded model to a stable model,below, where ¯ s provides a second stable model, provided the well-founded model is not stableitself.To present Turner’s theorem, we need to define stable models. Let P be a ground logic programand I be a 2-valued interpretation. Then the Gelfond-Lifschitz reduct of P wrt I , denoted by P I ,is obtained by deleting from P those rules with a negative literal that evaluates to false in I , anddeleting those negative literals that evaluate to true in I from the remaining rules. A stable modelis a 2-valued interpretation S such that the least model of P S is S (Gelfond and Lifschitz 1988).The proof of Theorem 2 of (Turner 1993) is very compact and in a notation I am not familiarwith. The following proof of a variation of that theorem is also brief, and is more intuitive to me. n Signings and the Well-Founded Semantics Theorem 9 (Turner 1993)
Let P be a logic program, P ⊆ Π be a downward-closed set of predicates with floor F , let Q be P\F , and s be a signing on Q for P . Let I be a fixed stable model for F and let W be thewell-founded model of P extending I . Then there is a stable model S of P that extends W .Specifically, S can be defined as follows:If s ( p ) = +1 then p ( ~a ) ∈ S iff not p ( ~a ) / ∈ W If s ( p ) = − then not p ( ~a ) ∈ S iff p ( ~a ) / ∈ W Proof
We need to prove that S is a stable model. W is a 3-valued model of P ∗ (Van Gelder et al. 1991)so, by Theorem 8, S is a 2-valued model of P ∗ and, hence, also a model of P .We use a characterization of stable models established in Theorem 2.5 of (Dung 1992). Amodel S of P is stable iff for all A , if A is unfounded wrt S then A ∩ S = ∅ .We first prove by induction on the Kleene sequence that no atom a ∈ W is in an unfoundedset wrt S . If a ∈ W ↑ ( β + 1) then there is a rule a :- B in ground ( P ) such that B evaluates to true in W ↑ β . By the induction hypothesis, every atom b ∈ B is not in an unfounded set wrt S . Hence, a is not in an unfounded set wrt S , since B is neither false in S nor does B containan atom from an unfounded set wrt S . If a ∈ W ↑ α , for limit ordinal α , then a ∈ W ↑ β forsome β < α and, by the induction hypothesis, a is not in an unfounded set wrt S . Hence, if A isunfounded wrt S , then A ⊆ S \ W .Let A be unfounded wrt S . Then, for any a ∈ A , a ∈ S \ W and, by the definition of S , s ( a ) = +1 . Furthermore, for any rule a :- B for a , if b ∈ B then s ( b ) = +1 and if not b ∈ B then s ( b ) = − . Thus, for any a ∈ A and rule a :- B , if B evaluates to false in S then, fromthe definition of S , B evaluates to false in W . (If b ∈ B is false in S and s ( b ) = +1 , then not b ∈ W ; if not b ∈ B is false in S s ( b ) = − , then b ∈ W .) It follows that A is unfoundedwrt W . Consequently, not a ∈ W , which contradicts a ∈ S . Hence, A = ∅ .Thus, by the characterization above, S is stable.As observed above, a second stable model can be obtained by using ¯ s , if W is not stable.Along similar lines, but not using signings, (Gire 1992; Gire 1994) showed that, supposing P isorder-consistent, if W is not stable then P has at least two stable models. ( P is order-consistent(Fages 1994) if ≤ ± is well-founded, where p ≤ ± q iff p ≤ +1 q and p ≤ − q .)Using the construction in the previous theorem, based on Dung’s characterization of stablemodels (Dung 1992), we can give a shorter and more direct proof of a variant of Theorem 5.11of (Dung 1992) than in that paper. The proof still uses the same idea as Dung. The statementof this theorem uses a signing, rather than strictness in (Dung 1992), but these two concepts arevery closely related (see Section 2.1).The sceptical stable semantics extending an interpretation I is the set of all literals true inevery stable model extending I . Theorem 10 (Dung 1992)
Let P be a logic program, P ⊆ Π be a downward-closed set of predicates with floor F , and let Q be Π \F . Let I be a fixed stable model for F . Let W be the well-founded model of P extending I , and T be the sceptical stable semantics of P extending I .If Q has a signing for P then T = W .6 M.J. MaherProof