1 Knowledge Based Systems (CM0377) Lecture 8 (Last modified 5th March 2001)

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 10: Cuts and Negation Theory –Explain how to control Prolog`s backtracking behaviour with.
AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 2
SLD-resolution Introduction Most general unifiers SLD-resolution
Logic Programming – Part 2 Lists Backtracking Optimization (via the cut operator) Meta-Circular Interpreters.
Logic Programming – Part 2 Lists Backtracking Optimization (via the cut operator) Meta-Circular Interpreters.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
PROLOG Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
Automated Reasoning Systems For first order Predicate Logic.
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
Prolog OR (disjunction) “;” is same as a logical OR “;” is same as a logical OR It is also equivalent to using separate clauses... It is also equivalent.
CS 330 Programming Languages 12 / 02 / 2008 Instructor: Michael Eckmann.
CS 330 Programming Languages 12 / 12 / 2006 Instructor: Michael Eckmann.
Chapter 8: The Logical Paradigm Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 10 Exercises –Solutions to Exercises of LPN chapter 9 Theory –Explain how to control Prolog`s.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Inference and Resolution for Problem Solving
Proof System HY-566. Proof layer Next layer of SW is logic and proof layers. – allow the user to state any logical principles, – computer can to infer.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
1 CILOG User Manual Bayesian Networks Seminar Sep 7th, 2006.
Artificial Intelligence Chapter 17 Knowledge-Based Systems Biointelligence Lab School of Computer Sci. & Eng. Seoul National University.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
DEDUCTIVE DATABASE.
Formal Models of Computation Part II The Logic Model
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
1 Knowledge Based Systems (CM0377) Lecture 12 (Last modified 2nd May 2002)
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
CS 321 Programming Languages and Compilers Prolog part 2.
CS 2104 – Prog. Lang. Concepts Logic Programming - II Dr. Abhik Roychoudhury School of Computing.
CS 403: Programming Languages Lecture 19 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Knowledge Based Systems (CM0377) Lecture 4 (Last modified 5th February 2001)
1 Chapter 8 Inference and Resolution for Problem Solving.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
Prolog Programming. 2 DATA STRUCTURES IN PROLOG PROGRAMMING TECHNIQUES CONTROL IN PROLOG CUTS.
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
Prolog Programming in Logic. 2 SWI-Prolog SWI-Prolog is a good, standard Prolog for Windows and Linux Can be installed on Macintosh with a little more.
1 Knowledge Based Systems (CM0377) Lecture 3 (Last modified 5th February 2001)
1 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 14.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
Prolog Kyle Marcotte. Outline What is Prolog? Origins of Prolog (History) Basic Tutorial TEST!!! (sort of…actually not really at all) My example Why Prolog?
Prolog Program Style (ch. 8) Many style issues are applicable to any program in any language. Many style issues are applicable to any program in any language.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Automated Reasoning Systems For first order Predicate Logic.
Lab Lecture#4 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami.
Cs774 (Prasad)L6Backtracking1 Controlling Backtracking : Cuts
1 Knowledge Based Systems (CM0377) Introductory lecture (Last revised 28th January 2002)
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
Knowledge Based Information System
For Monday Exam 1 is Monday Takehome due Prolog Handout 3 due.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
1 Knowledge Based Systems (CM0377) Lecture 9 (Last modified 11th April 2002)
Answer Extraction To use resolution to answer questions, for example a query of the form  X C(X), we must keep track of the substitutions made during.
1 Section 9.2 Logic Programming A logic program is a set of clauses with the restriction that there is exactly one positive literal in each clause. Such.
COP4020 Programming Languages Logic Programming Prof. Xin Yuan.
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
6/11/2016 Linear Resolution and Introduction to First Order Logic Michael Leuschel Softwaretechnik und Programmiersprachen Lecture 5.
Artificial Intelligence Chapter 17 Knowledge-Based Systems
Knowledge-Based Systems Chapter 17.
Artificial Intelligence Chapter 17 Knowledge-Based Systems
Prolog: cut & fail © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
Logic: Top-down proof procedure and Datalog
Chapter 12 :: Logic Languages
Artificial Intelligence Chapter 17. Knowledge-Based Systems
Artificial Intelligence Chapter 17 Knowledge-Based Systems
Chapter 2: Prolog (Introduction and Basic Concepts)
Presentation transcript:

1 Knowledge Based Systems (CM0377) Lecture 8 (Last modified 5th March 2001)

2 Controlling the search We will look at two ways of controlling the search in Prolog: –the cut, which prunes the search tree; and –not, which is implemented as negation-as- failure

3 The cut Quite often, want to ‘prune’ the search tree for efficiency. Consider implementation of: Could write f(X, 2):-X<0. f(X, 3):-X>=0, X<2. f(X, 1):-X>=

4 SLD tree for ?- f(-1, Y)

5 Motivation for cut We’ll correctly get one solution in this example, but if we ask Prolog for more solutions it searches the failure nodes first. If we know that at a particular ‘choice point’ at most one of the branches of the subtree rooted at this node will ever be a success branch, then can use the ‘cut’ to cut off futile search: f(X, 2):-X<0, !. f(X, 3):-X>=0, X<2, !. f(X, 1):-X>=2.

6 Revised SLD tree

7 The cut... Definitions: –“Once you’ve reached me, stick with all variable substitutions you’ve found after you entered my clause” or, put another way, –“Don’t try to find alternative solutions to literals to the left of the cut; don’t try alternative clauses for the one in which the cut was encountered either” Note: –The cut, !, is true by definition; it succeeds, but prunes the choice point containing the head of the clause in which the cut is found. –Also, cut doesn’t affect backtracking to the right of the cut.

8 Procedural/Declarative interpretation We could now use our superior knowledge of how Prolog will search, in order to omit bits of the above program. So the folowing program will give the same results for goals of the form ?- f(, Y): f(X, 2):-X<0, !. f(X, 3):-X<2, !. f(X, 1).

9 Procedural/Declarative interpretation (ctd.) But the procedural interpretation is now different from the declarative interpretation, making the latter program very difficult to read. Original example was of using ‘green’ cuts. The above example employs ‘red’ cuts. Generally use red cuts sparingly!

10 Negation-as-failure Suppose we wished to determine whether a second-hand car was suitable for us: suitable_car(X) :- price_of(X, P), affordable(P), manufacturer_of(X, M), acceptable(M), not(stolen(X)).

11 Negation (ctd.) In the nature of things, it will be possible in some cases to establish the car has been stolen, but can never be certain a car hasn’t been stolen (e.g. perhaps it hasn’t been reported yet). So logically we should be able to say ‘I don’t know!’. In practice, in Prolog, not(stolen(X)) succeeds if, and only if, stolen(X) is unprovable - ‘negation as failure’

12 Negation (ctd.) not is a built-in predicate defined thus: not(Goal):- Goal, !, fail. not(Goal). Note that Prolog allows us to use a term as an atom, and ‘call’ it. In fact, Goal in the above program is shorthand for call(Goal). call, and not, are meta-predicates: predicates that take formulas from the same logical language in which they are written as arguments.

13 Another example male(jim). male(fred). female(X):-not(male(X)). Consider the query: ?-female(jenny).

14 SLD tree

15 A couple of points... Although not isn’t true logical negation, we can often use it with far less damage to the meaning of a program than the cut - it’s ‘higher level’ In SICSTUS Prolog, use ‘\+’ instead of ‘not’ Recommended reading: Flach, pp (much more detail + examples) Next time - meta-programs and their role in reasoning