WFSX programming Prolog programming style, but with the WFSX semantics Requires: –A new proof procedure (different from SLDNF), complying with WFS, and.

Presentation on theme: "WFSX programming Prolog programming style, but with the WFSX semantics Requires: –A new proof procedure (different from SLDNF), complying with WFS, and."— Presentation transcript:

WFSX programming Prolog programming style, but with the WFSX semantics Requires: –A new proof procedure (different from SLDNF), complying with WFS, and with explicit negation –The corresponding Prolog-like implementation: XSB-Prolog

SLX: Proof procedure for WFSX SLX (SL with eXplicit negation) is a top-down procedure for WFSX Is similar to SLDNF –Nodes are either successful or failed –Resolution with program rules and resolution of default literals by failure of their complements are as in SLDNF In SLX, failure doesn’t mean falsity. It simply means non-verity (i.e. false or undefined)

Success and failure A finite tree is successful if its root is successful, and failed if its root is failed The status of a node is determined by: –A leaf labeled with an objective literal is failed –A leaf with true is successful –An intermediate node is successful if all its children are successful, and failed otherwise (i.e. at least one of its children is failed)

Negation as Failure? As in SLS, to solve infinite positive recursion, infinite trees are (by definition) failed Can a NAF rule be used? YES True of not A succeeds if true-or-undefined of A fails True-or-undefined of not A succeeds if true of A fails This is the basis of SLX. It defines: –T-Trees for proving truth –TU-Trees for proving truth or undefinedness

T and TU-trees They differ in that literals involved in recursion through negation, and so undefined in WFSXp, are failed in T-Trees and successful in TU-Trees a  not b b  not a … b not a TU b not a TU a not b T a T X X X X

Explicit negation in SLX ¬-literals are treated as atoms To impose coherence, the semi-normal program is used in TU-trees a  not b b  not a ¬a b not a X a not b not ¬a ¬a¬a true X b not a ¬a¬a true … X X a not b not ¬a X

Explicit negation in SLX (2) In TU-trees: L also fails if ¬L succeeds true I.e. if not ¬L fail as true-or-undefined c  not c b  not c ¬b a  b not a X ¬b¬b true c not c ¬a¬a b not ¬b a not ¬a X X X c not c c c c … X X X X X X

T and TU-trees definition D T-Trees (resp TU-trees) are AND-trees labeled by literals, constructed top-down from the root by expanding nodes with the rules Nodes labeled with objective literal A If there are no rules for A, the node is a leaf Otherwise, non-deterministically select a rule for A A  L 1,…,L m, not L m+1,…, not L n In a T-tree the children of A are L 1,…,L m, not L m+1,…, not L n In a TU-tree A has, additionally, the child not ¬A Nodes labeled with default literals are leafs

Success and Failure D All infinite trees are failed. A finite tree is successful if its root is successful and failed if its root is failed. The status of nodes is determined by: A leaf node labeled with true is successful A leaf node labeled with an objective literal is failed A leaf node of a T-tree (resp. TU) labeled with not A is successful if all TU- trees (resp. T) with root A (subsidiary tree) are failed; and failed otherwise An intermediate node is successful if all its children are successful; and failed otherwise After applying these rules, some nodes may remain undetermined (recursion through not). Undetermined nodes in T-trees (resp.TU) are by definition failed (resp. successful)

Properties of SLX SLX is sound and (theoretically) complete wrt WFSX. If there is no explicit negation, SLX is sound and (theoretically) complete wrt WFS. See [AP96] for the definition of a refutation procedure based on the AND-trees characterization, and for all proofs and details

Infinite trees example s  not p, not q, not r p  not s, q, not r q  r, not p r  p, not q WFM is {s, not p, not q, not r} not pnot qnot r s X p q not s r not q not r r not p p q not snot r r not p p not q X X q r not p p not q q not snot r

Negative recursion example q  not p(0), not s p(N)  not p(s(N)) s  true WFM = {s, not q} … not q p(0) not p(1) not p(0) q not s X X p(1) not p(2) p(2) not p(3) X X X X s true not p(0) … p(1) not p(2) p(0) not p(1) X X X p(2) not p(3)

Guaranteeing termination The method is not effective, because of loops To guarantee termination in ground programs: Local ancestors of node n are literals in the path from n to the root, exclusive of n Global ancestors are assigned to trees: the root tree has no global ancestors the global ancestors of T, a subsidiary tree of leaf n of T’, are the global ancestors of T’ plus the local ancestors of n global ancestors are divided into those occurring in T-trees and those occurring in TU-trees

Pruning rules For cyclic positive recursion: Rule 1 If the label of a node belongs to its local ancestors, then the node is marked failed, and its children are ignored For recursion through negation: Rule 2 If a literal L in a T-tree occurs in its global T-ancestors then it is marked failed and its children are ignored

Rule 2Rule 1 Pruning rules (2) L L L L …

Other sound rules Rule 3 If a literal L in a T-tree occurs in its global TU-ancestors then it is marked failed, and its children are ignored Rule 4 If a literal L in a TU-tree occurs in its global T-ancestors then it is marked successful, and its children are ignored Rule 5 If a literal L in a TU-tree occurs in its global TU-ancestors then it is marked successful, and its children are ignored

Pruning examples a  not b b  not a ¬a b not a X a not b not ¬a ¬a¬a true X c  not c b  not c ¬b a  b not a X ¬b¬b true c not c ¬a¬a b not ¬b a not ¬a X X X X X Rule 3 b Rule 2 X

Non-ground case The characterization and pruning rules apply to allowed non-ground programs, with ground queries It is well known that pruning rules do not generalize to general programs with variables: p(X)  p(Y) p(a) p(X) p(Y) What to do? p(Z) If “fail”, the answers are incomplete If “proceed” then loop

Tabling To guarantee termination in non-ground programs, instead of ancestors and pruning rules, tabulation mechanisms are required –when there is a possible loop, suspend the literal and try alternative solutions –when a solution is found, store it in a table –resume suspended nodes with new solutions in the table –apply an algorithm to determine completion of the process, i.e. when no more solutions exist, and fail the corresponding suspended nodes

Tabling example SLX is also implemented with tabulation mechanisms It uses XSB-Prolog tabling implementation SLX with tabling is available with XSB-Prolog from Version 2.0 onwards Try it at: p(X)  p(Y) p(a) p(X) p(Y) 1) suspend X = a 2) resume Y = a X = _ Table for p(X) http://xsb.sourceforge.net/

Tabling (cont.) If a solution is already stored in a table, and the predicate is called again, then: –there is no need to compute the solution again –simply pick it from the table! This increases efficiency. Sometimes by one order of magnitude.

A methodology for KR WFSXp provides mechanisms for representing usual KR problems: –logic language –non-monotonic mechanisms for defaults –forms of explicitly representing negation –paraconsistency handling –ways of dealing with undefinedness In what follows, we propose a methodology for representing (incomplete) knowledge of taxonomies with default rules using WFSXp

Representation method (1) Definite rules If A then B: –B  A penguins are birds: bird(X)  penguin(X) Default rules Normally if A then B: –B  A, rule_name, not ¬ B rule_name  not ¬ rule_name birds normally fly:fly(X)  bird(X), bf(X), not ¬fly(X) bf(X)  not ¬bf(X)

Representation method (2) Exception to default rules Under conditions COND do not apply rule RULE: –¬ RULE  COND Penguins are an exception to the birds-fly rule ¬bf(X)  penguin(X) Preference rules Under conditions COND prefer rule RULE + to RULE - : –¬ RULE -  COND, RULE + for penguins, prefer the penguins-don’t-fly to the birds-fly rule: ¬bf(X)  penguin(X), pdf(X)

Representation method (3) Hypotethical rules “If A then B” may or not apply: –B  A, rule_name, not ¬ B rule_name  not ¬ rule_name ¬ rule_name  not rule_name quakers might be pacifists: pacifist(X)  quaker(X), qp(X), not ¬pacifist(X) qp(X)  not ¬qp(X) ¬qp(X)  not qp(X) For a quaker, there is a PSM with pacifist, another with not pacifist. In the WFM pacifist is undefined

Taxonomy example Mammal are animal Bats are mammals Birds are animal Penguins are birds Dead animals are animals Normally animals don’t fly Normally bats fly Normally birds fly Normally penguins don’t fly Normally dead animals don’t fly The taxonomy: Pluto is a mammal Joe is a penguin Tweety is a bird Dracula is a dead bat The elements: Dead bats don’t fly though bats do Dead birds don’t fly though birds do Dracula is an exception to the above In general, more specific information is preferred The preferences:

The taxonomy flies animal bird penguin mammal bat dead animal plutotweetydraculajoe Definite rules Default rules Negated default rules