6.4 Stratification for Grouping Constructs and Negation
6.4.2 Negation Stratification
Negation as Failure (NaF, cf. [40]), like Xcerpt’snot, is common in rule-based programming languages (e.g. Prolog and Datalog). In NaF, a negated query succeeds if the query itself fails finitely (i.e. can be proven to be not provable). NaF is desirable for a Web query language, because it is close to the intuitive understanding of negation: for instance, it is natural to assume that a train not listed in a train timetable does not exist, instead of requiring that every non-existent train is explicitly listed in the timetable.
Although NaF has a purely operational meaning, it is desirable to provide a declarative semantics as well, because the latter is usually easier to understand than the evaluation algorithm. Unfortunately, like recursion over grouping constructs, negation as failure allows for programs whose meaning is unclear. Consider for instance the following Xcerpt program:
f{a} ←not f{a}
Backward chaining evaluation of this rule does not terminate: for proving f{a}, it is necessary to show (in an auxiliary computation) that f{a}does not hold, which again requires to evaluate the rule, and so on.
Declaratively, the meaning of this rule is problematic. When representing rules by implication as in traditional logic programming, this rule is simply equivalent to f{a} ∨ ¬¬f{a}, which simplifies to f{a}. This interpretation does not reflect the operational behaviour (which is the definition for negation as failure) described in the previous paragraph. Other approaches have been considered (like Clarke’s completion or default negation) that interpret the symbol←differently, but all of these have similar problems.
In this thesis, Xcerpt programs are therefore assumed to be also negation stratifiable, a syntactic re- striction that excludes such programs that involve problematic use of negation as in the example above. Negation stratification in Xcerpt programs is defined in the usual manner (as e.g. in [8]). In stratifiable programs, both recursion and negation are allowed, but a recursion “through negation” is disallowed.
Note that (negation) stratification is one of many approaches suggested for negation in logic program- ming and deductive databases. In contrast to most other approaches (like well-founded semantics or stable
model semantics), stratification has the advantage that it is a property that is decidable, can be determined
statically, and considers only the examined program, whereas most other approaches also require the data on which the program operates. This latter requirement is impractical for Web query languages, as it would require to consider the complete Web when compiling Xcerpt programs.3
As stratification is a rather rigid requirement and also excludes programs that are unproblematic and desirable, it might also be interesting to investigate different, more sophisticated approaches to negation, e.g. local stratification [87] or paraconsistent interpretations [26, 28] in future work. However, all of these approaches first need to be evaluated for their practical applicability.
Similar to grouping stratification, negation stratification divides a program (represented as a set of rules) into strata. The main idea is to disallow recursion over negated queries, but allow any other kind of recursion. A rule R is said to depend negatively on another rule R0, if the rule body of R contains a negated query term (i.e. a query term contained in one or morenotconstructs) that simulation unifies with the head of R0. Likewise, a rule R is said to depend positively on another rule R0, if the rule body of R contains a non-negated query term that simulation unifies with the head of R0. Note that double negation of a query
3In a sense, one could say that after 20 years of research on non-monotonic negation, we have to return to the beginnings due to the particularities of the Web.
CHAPTER 6. RANGE RESTRICTEDNESS, STANDARDISATION APART, AND STRATIFICATION
term also yields a negative dependency, becausenotimplements negation as failure and the query term thus does not yield variable bindings. If a rule R positively depends on a rule R0, then R0may be in the same layer as R or in any lower layer. If a rule R depends negatively on a rule R0, then R0 must be in a strictly lower layer than R. Again, this definition differs from the traditional definition of stratification in that it considers dependencies between rules rather than between terms. The justification for this decision is similar to the reasons given in the previous section.
Again, the following definition uses the simulation unification described in Chapter 8. Recall also, that
P=P1 ]. . . ] Pndenotes the partitioning of a set P into disjoint sets Pi.
Definition 6.7 (Negation Stratification)
Given a program P consisting of rules/goals{R1, . . . ,Rm}(m≥1).
1. Let R=tc←Q and R0=tc0←Q0be rules.
• R depends positively on R0, if there exists a query term tqwhere all variable occurrences have
negative polarity in Q such that tqsimulation unifies in tc0, i.e. simulation unification of tqin tc
yields a non-empty substitution setΣ
• R depends negatively on R0, if there exists a query term tqin Q such that at least one variable occurs positively in tq, and tq simulation unifies in tc0, i.e. simulation unification of tqin tc yields a non-empty substitution setΣ
2. P is called negation stratifiable, if there exists a partitioning (n≥1)
P=P1 ] · · · ]Pn
of P such that for every stratum Pi(1≤i≤n) and every rule R∈Piholds:
• if R depends positively on a rule R0then R0∈Sj≤iPj, i.e. R0is either in the same stratum as R
or in a lower stratum than R
• if R depends negatively on a rule R0then R0∈Sj<iPj, i.e. R0is in a strictly lower stratum than
R
The partition P=P1 ] · · · ]Pnis called a negation stratification of P, and the Piare called negation strata
of P.
Example 6.6 (Negation Stratification)
1. The following program (consisting of a single rule) cannot be stratified, as the rule negatively de- pends on itself:
f{a} ←not f{a}
2. The following program can be stratified into three strata from bottom to top:
P3 p{} ←and{not q{},s{}} P2 q{} ←r{}
r{} ←s{}
P1 s{}
6.4. STRATIFICATION FOR GROUPING CONSTRUCTS AND NEGATION