Top-Down Execution CS240B Notes

Similar documents
Computational Logic Automated Deduction Fundamentals

Computational Logic Fundamentals (of Definite Programs): Syntax and Semantics

NOTES ON PREDICATE CALCULUS AND LOGIC PROGRAMMING

Prolog. Resolution (for beginners?) Resolution (cont.) Resolution (cont.) Unification. Resolution (still cont.) Resolution & Unification

Definite Logic Programs: Derivation and Proof Trees. CSE 505 Computing with Logic Stony Brook University

Resolution and Refutation

Computing logical consequences

Models. Let our knowledge base KB, consist of a set of formulas. We say that I is a model of KB or that I satisfies KB

First-Order Logic. Resolution

Chapter 3. SLD-Resolution. 3.1 Informal Introduction

Logic. Knowledge Representation & Reasoning Mechanisms. Logic. Propositional Logic Predicate Logic (predicate Calculus) Automated Reasoning

Strong AI vs. Weak AI Automated Reasoning

Introduction to Answer Set Programming

CogSysI Lecture 8: Automated Theorem Proving

Negative Hyper-Resolution as Procedural Semantics of Disjunctive Logic Programs

Handout Proof Methods in Computer Science

Advanced DB CHAPTER 5 DATALOG

The non-logical symbols determine a specific F OL language and consists of the following sets. Σ = {Σ n } n<ω

Resolution (14A) Young W. Lim 8/15/14

Unification and occur check. The programming language Prolog

CS 730/830: Intro AI. 3 handouts: slides, asst 6, asst 7. Wheeler Ruml (UNH) Lecture 12, CS / 16. Reasoning.

1 Introduction to Predicate Resolution

Outline. Logic. Definition. Theorem (Gödel s Completeness Theorem) Summary of Previous Week. Undecidability. Unification

COMP9414: Artificial Intelligence First-Order Logic

Computational Logic. Davide Martinenghi. Spring Free University of Bozen-Bolzano. Computational Logic Davide Martinenghi (1/26)

Logic Programming in Prolog Part II Substitutions, SLD Resolution Prolog Execution. Raj Sunderraman

Announcements. Project 1 underway... Second midterm Friday. discuss ideas with TAs check out wiki

4 Predicate / First Order Logic

Problem With Natural Deduction

Logic: Top-down proof procedure and Datalog

Propositional Reasoning

Resolution for Predicate Logic

Foundations of Logic Programming

Logic + control: An example of program construction and verification

Resolution for Predicate Logic

Advanced Topics in LP and FP

Bachelor/Master Exam Version V3B

Resolution for predicate logic

Deductive Systems. Lecture - 3

Lecture 10: Even more on predicate logic" Prerequisites for lifted inference: Skolemization and Unification" Inference in predicate logic"

Brief Introduction to Prolog

CPSC 121: Models of Computation

Lecture Notes in Machine Learning Chapter 3: Languages for learning

Propositional and Predicate Logic - V

CSC384: Intro to Artificial Intelligence Knowledge Representation II. Required Readings: 9.1, 9.2, and 9.5 Announcements:

Logic (3A) Young W. Lim 12/5/13

Completeness of Hyper-Resolution via the Semantics of Disjunctive Logic Programs

8 General first order representation

Introduction to Logic in Computer Science: Autumn 2007

Syntax of FOL. Introduction to Logic in Computer Science: Autumn Tableaux for First-order Logic. Syntax of FOL (2)

07 Equational Logic and Algebraic Reasoning

COMP9414: Artificial Intelligence Propositional Logic: Automated Reasoning

3 Propositional Logic

Part I: Definitions and Properties

arxiv:cs/ v1 [cs.pl] 31 Jan 2002

Definite Logic Programs

Inductive Logic Programming. Part 2. Based partially on Luc De Raedt s slides

Chapter 6. Negation: Procedural Interpretation

University of Aberdeen, Computing Science CS2013 Predicate Logic 4 Kees van Deemter

Chapter 7 R&N ICS 271 Fall 2017 Kalev Kask

Linear Tabulated Resolution for the Well-Founded Semantics

Figure SUBSTITUTION AND UNIFICATION

CS 730/730W/830: Intro AI

Logic as a Tool Chapter 4: Deductive Reasoning in First-Order Logic 4.4 Prenex normal form. Skolemization. Clausal form.

Resolution: Motivation

SOCLP: A Set Oriented Calculus for Logic Programming

173 Logic and Prolog 2013 With Answers and FFQ

INF3170 / INF4171 Notes on Resolution

A DARK GREY P O N T, with a Switch Tail, and a small Star on the Forehead. Any

Computed answer based on fuzzy knowledgebase a model for handling uncertain information

Web Science & Technologies University of Koblenz Landau, Germany. Models in First Order Logics

SLD-Resolution And Logic Programming (PROLOG)

A Unit Resolution Approach to Knowledge Compilation. 2. Preliminaries

Fuzzy Datalog with background knowledge

Convert to clause form:

Closed Book Examination. Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. M.Sc. in Advanced Computer Science

Some Rewriting Systems as a Background of Proving Methods

Predicate Logic: Syntax

Chapter 7. Negation: Declarative Interpretation

Negation as failure (Normal logic programs)

Predicate Logic - Semantic Tableau

Outline. Formale Methoden der Informatik First-Order Logic for Forgetters. Why PL1? Why PL1? Cont d. Motivation

Bachelor/Master Exam Version V3B

Artificial Intelligence Chapter 7: Logical Agents

Inference in First Order Logic

Introduction to Logic in Computer Science: Autumn 2006

Herbrand Theorem, Equality, and Compactness

Hyper-Resolution AUTOMATED REASONING SLIDES 8: HYPER-RESOLUTION Hyper-resolution Refinement The Otter Theorem Prover Generalised Hyper-resolution.

COMP4418: Knowledge Representation and Reasoning First-Order Logic

Knowledge base (KB) = set of sentences in a formal language Declarative approach to building an agent (or other system):

Logic & Computation. Autonomous Systems. Sistemi Autonomi. Andrea Omicini

CS 4700: Artificial Intelligence

Transformation Rules for Locally Stratied Constraint Logic Programs

Conceptual Graphs and First Order Logic

Automated Reasoning in First-Order Logic

Logic and Reasoning. Foundations of Computing Science. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Propositional Resolution Introduction

Intelligent Agents. First Order Logic. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University. last change: 19.

Answer Set Programming: an Introduction

A GUIDE FOR MORTALS TO TAME CONGRUENCE THEORY

Transcription:

Top-Down Execution CS240B Notes Notes based on Section 9.4 of Advanced Database Systems Morgan Kaufmann, 1997 C. Zaniolo, March 2002 p.1/22

Top-Down Execution of Datalog A strict bottom-up execution strategy is frequently not natural nor efficient. Pure top-down, SLD-resolution, Prolog Mixing top-down and bottom-up in deductive databases p.2/22

Passing Bindings from Goals to Heads r 1 : part_weight(no, Kilos) r 2 : part_weight(no, Kilos) part(no, _, actualkg(kilos)). part(no, Shape, unitkg(k)), area(shape, Area), Kilos = K Area. r 3 : area(circle(dmtr), A) A = Dmtr Dmtr 3.14/4. r 4 : area(rectangle(base, Height), A) A = Base Height. The goal area(shape, Area) in rule r 1 can be viewed as a call to the procedure area defined by rules r 3 and r 4. Thus Shape is instantiated to circle(11) by the execution of r 3, and rectangle(10, 20) and r 4. p.3/22

Passing Bindings from Goals to Heads cont. Instantiated to c means assigned the value of the constant c. Shape/rectangle(10, 20) denotes that Shape has been instantiated to rectangle(10, 20). Arguments can be complex; thus the passing of parameters is performed through a process known as unification. Shape/rectangle(10, 20) is made equal to (unified to) the first argument of the second area rule, rectangle(base, Height), by setting Base/10 and Height/20. p.4/22

Substitutions Substitutions: A substitution θ is a finite set of the form {v 1 /t 1,..., v n /t n }, where each v i is a distinct variable, and each t i is a term distinct from v i. Each t i is called a binding for v i. The substitution θ is called a ground substitution if every t i is a ground term. (Then X/θ is an instantiation of X to θ.) Eθ denotes the result of applying the substitution θ to E; i.e., of replacing each variable with its respective binding. For instance, if E = p(x, y, f(a)) and θ = {x/b, y/x}. Then Eθ = p(b, x, f(a)). If γ = {x/c}, then Eγ = p(c, y, f(a)). Thus variables that are not part of the substitution are left unchanged. p.5/22

Composition of Substitutions Let θ = {u 1 /s 1,..., u m /s m } and δ = {v 1 /t 1,..., v n /t n } be substitutions. Then the composition θδ of θ and δ is the substitution obtained from the set {u 1 /s 1 δ,..., u m /s m δ, v 1 /t 1,..., v n /t n } by deleting any binding u i /s i δ for which u i = s i δ and deleting any binding v j /t j for which v j {u 1,..., u m }. p.6/22

Composing Substitutions: Example Let θ = {(x/f(y), y/z)} and δ = {x/a, y/b, z/y}. Then θδ = {x/f(b), z/y}. θ δ θδ x/f(y) x/a x/f(b) y/z y/b y/y z/z z/y z/y p.7/22

Unification A substitution θ is called a unifier for two terms A and B if Aθ = Bθ. Example The two terms p(f(x), a), and p(y, f(w)) are not unifiable, because the second arguments cannot be unified (i.e., they cannot be made identical) The two terms p(f(x), z), and p(y, a) are unifiable, since δ = {y/(f(a), x/a, z/a)} is a unifier. p.8/22

Most General Unifier A unifier θ for two terms is called a most general unifier (mgu), if for each other unifier γ, there exists a substitution δ such that γ = θδ. δ = {y/(f(a), x/a, z/a)} is not the mgu of p(f(x), z), and p(y, a). A most general unifier for these two is θ = {y/(f(x), z/a}. Note that δ = θ{x/a}. There exist efficient algorithms to perform unification: such algorithms either return a most general unifier or report that none exists. p.9/22

Resolvent of rule r and goal g A rule r : A B 1,..., B n, and A query goal g, r and g have no variables in common. If a most general unifier (mgu) δ for A and g, the goal list: B 1 δ,..., B n δ. is called resolvent of r and g. p.10/22

SLD-Resolution Algorithm Input: A first-order program P and a goal list G. Output: A Gδ that was proved from P, or failure. begin Set Res = G; While Res is not empty, repeat the following: Choose a goal g from Res; Choose a rule A B 1,..., B n (n 0) from P such that A and g unify under the mgu δ, (renaming the variables in the rule as needed); If no such rule exists, then output failure and exit. else Delete g from Res; Add B 1,..., B n to Res; Apply δ to Res and G; If Res is empty then output Gδ end p.11/22

SLD-resolution. Example s(x, Y) p(x, Y), q(y). p(x, 3). q(3). q(4). 1. The initial goal list is: s(5, W) 2. This unifies the head of the first rule with mgu: {X/5, Y/W}. New goal list: p(5, W), q(w) 3. Say that we choose q(w) as a goal: it unifies with the fact q(3), under the substitution {W/3}: p(5, 3) This unifies with the fact p(x, 3) under the substitution {X/5}. The goal list becomes empty and we report success. Thus, a top-down evaluation returns the answer {W/3} for the query s(5, W). from the example program. But if we choose p.12/22

Examples of SLD-Resolution Any realization of the top-down evaluation procedure will have to make two choices at each step by selecting 1. the next goal from the goal list and 2. the rule whose head unifies with the selected goal. In general, there will be more than one goal and many rules to choose from. The choice affects the efficiency of the deduction process and also the actual result when the search falls into an infinite loop. PROLOG interpreters usually choose goals in a left-to-right order and rules in a sequential order that corresponds to a depth-first search of the SLD-tree with backtracking when failure occurs. Thus, PROLOG treats the goal list as a stack onto which goals are pushed or popped, depending on success or failure. p.13/22

The SLD-Refutation Procedure Example: the goal p(x,b) on program 1. p(x,z) q(x,y), p(y,z) 2. p(x,x) 3. q(a,b). p(x, b) 1 2 q(x,y), p(y, b) X A finite SLD-tree is shown at the left. This SLD-tree comes from the standard Prolog computation rule that selects the leftmost atom. Selected atoms are underlined. 3. p(b,b) 1 2 q(b,z),. p(z, b) X/a denotes success. p.14/22

An infinite SLD-tree. p(x,b) 1. p(x,z) q(x,y), p(y,z) 2. p(x,x) 3. q(a,b) 1 2 q(x,y), p(y, b) 1 2 q(x,y), g(y, Z), p(z,b) p(x, b) q(x, b) X/b 1 2 q(x,y), q(y, Z), q(z, U), p(u, b) q(x, Y), q(y,b) 1 2 3 3 X/a infinite q(x,a) failure p.15/22

Success Set SLD-derivations can be finite or infinite. A finite SLD-derivation can be successful or failed. A successful SLD-derivation is a finite one that ends in the empty clause. This is also called an SLD-refutation. A failed SLD-derivation is a finite one that ends in a non-empty goal, where the selected atom in this goal does not unify with the head of any program clause. Definition Let P be a program. The success set of P is the set of all A B P such that P { A} has an SLD-refutation (i.e., there exist some successful p.16/22

Equivalent Semantics Theorem: The success set of a program is equal to its least Herbrand model. Equivalence of the three formal semantics. (Least Model, Least Fixpoint, and SLD-resolution). SLD-resolution is a form of theorem proving (an efficient one). In general, generation of the success requires that all choices are visited in a breadth-first fashion. This too inefficient for practical languages such as Prolog that use depth-first instead. p.17/22

Let S be a set of closed formulas. We say that S is Satisfiability satisfiable when there is an interpretation that is a model for S. S is valid if every interpretation of L is a model for S. S is unsatisfiable if it has no models. Theorem: Let S be a set of clauses. Then S is unsatisfiable iff S has no Herbrand models. We say F is a logical consequence of S if, every interpretation that is a model for S is also a model for F. Note that if S = {F 1,..., F n } is a finite set of closed formulas, then F is a logical consequence of S iff F 1... F n F is valid. p.18/22

Refutation S = {F 1,..., F n } is a finite set of closed formulas, then F is a logical consequence of S iff F 1... F n F is valid. Theorem: Let S be a set of closed formulas and F be a closed formula. Then F is a logical consequence of S iff S { F } is unsatisfiable. Thus to prove a goal G from a set of rules and facts P we simply have to prove that P { G} is unsatisfiable i.e., we have to refute P { G}. Resolution theorem proving does exactly that: It refutes the goal list. Prolog can be viewed in that light. But, actually, there is no real refutation just procedural composition via unification. The term SLD stands for Selected literal Linear resolution p.19/22

Prolog Depth-first exploration of alternatives, where goals are always chosen in a left-to-right order and the heads of the rules are also considered in the order they appear in the program. The programmer is given responsibility for ordering the rules and their goals in such a fashion as to guide Prolog into successful and efficient searches. The programmer must also make sure that the procedure never falls into an infinite loop. p.20/22

Prolog Example: The goal?anc(marc, mary) on the program: anc(x, Y) anc(x, Z) anc(x, Y), parent(y, Z). parent(x, Y). This causes an infinite loop that never returns any result. p.21/22

Programming in Prolog A solution to the previous problems is to put the exit rule before the recursive one. anc(x, Y) anc(x, Z) parent(x, Y). anc(x, Y), parent(y, Z). Prolog loops after the generation of all the results. To make things work parent must be put before anc in the recursive rule. A skill not hard to learn. Cycles in the parent database will also cause problems SLDresolution has no memory. p.22/22