Prolog Recursion Pepper. A rule with that calls itself is_digesting(X,Y) :- just_ate(X,Y). is_digesting(X,Y) :- just_ate(X,Z), is_digesting(Z,Y). 2 rules.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

1. An Overview of Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Rules of Divisibility. Divisible by 2? If the last digit is even then the number is divisible by 2. Even digits are 0, 2, 4, 6 and 8 (yes zero is even!)
Formal Logic Mathematical Structures for Computer Science Chapter 1 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 3: Recursion Theory –Introduce recursive definitions in Prolog –Four examples –Show that there.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 3: Recursion Theory –Introduce recursive definitions in Prolog –Four examples –Show that there.
Rules Simple rules. Processing rules. Multiple sub-goals. PROLOG syntax. Recursive rules.
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Learning outcomes : At the end of the lesson students will be able to…
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
CPSC 433 Artificial Intelligence CPSC 433 : Artificial Intelligence Tutorials T01 & T02 Andrew “M” Kuipers note: please include.
1 LING 438/538 Computational Linguistics Sandiway Fong Lecture 4: 8/31.
Discussion #24 1/17 Discussion #24 Deductive Databases.
RECURSIVE PATTERNS WRITE A START VALUE… THEN WRITE THE PATTERN USING THE WORDS NOW AND NEXT: NEXT = NOW _________.
Sea Creatures: Write your names here Write your class here Write your school here Write the name of your sea animal here.
Concrete Foundations 3/28/11. What is a concrete foundation We now know what concrete is composed of……Cement, Aggregates, & water Advantages of concrete.
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
LING 388: Language and Computers Sandiway Fong Lecture 5.
Warm-Up Warm-Up I will be coming around checking your homework while you are working on your warm-up 1)2(-4 + k) = 24 2)37 = 4x – 6x ) ½(14x – 22)
Click mouse. EQUATIONS The important thing to remember about equations is that both sides must balance (both sides must equal each other). This means.
Factors and Primes by 2July. Definition Product – the answer to a multiplication problem. 5 x 6 = 30 Product.
CSC 270 – Survey of Programming Languages Prolog Lecture 2 – Unification and Proof Search.
1 Knowledge Based Systems (CM0377) Lecture 3 (Last modified 5th February 2001)
SOLVING ONE STEP EQUATIONS. THINK – PAIR - SHARE Think: What does the word inverse mean? Pair Share.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Rules Statements about objects and their relationships Expess ◦ If-then conditions  I use an umbrella if there is a rain  use(i, umbrella) :- occur(rain).
COMP307 Artificial Intelligence Xiaoying Gao Victoria University of Wellington Lecture 2:1 
2.5 Addition and Subtraction Equations Help!!! We’re not in balance!
Invitation to Computer Science, Java Version, Second Edition 1 Logic Programming Logic programming  Various facts are asserted to be true  On the basis.
Artificial Intelligence CS370D
CS 554: Knowledge base systems Part-4: Prolog- 2 By Dr. Syed Noman Hasany.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
For Friday No reading Prolog Handout 2. Homework.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
1 TP #2: How does Prolog answer questions? n Miscellaneous info; n Last TP exercises solved; n How does Prolog answer questions? n Recursive Prolog programs;
Overview of the theory of computation Episode 3 0 Turing machines The traditional concepts of computability, decidability and recursive enumerability.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
1 Artificial Intelligence CS370D Prolog programming Declarative meaning of Prolog programs and Lists representation.
Logic Programming Lecture 2: Unification and proof search.
The portion of a Prolog interpreter that executes queries (goals) is known as the inference engine. An inference engine is a kind of theorem prover, using.
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
Advanced Higher Computing Science
Section 6.2 Constructing Antiderivatives Analytically
(Friday, 8/18) Notes Review Step 1: Finish YESTERDAY’S NOTES
Factors and Primes.
Students will solve two step equations (12-4).
(Friday, 8/26) Notes Review Step 1: Finish YESTERDAY’S NOTES
Unification, Recursion and Lists
Model Functions Input x 6 = Output Input x 3 = Output
Prolog Recursion Pepper Major portions credited to :
Day 93 Explicit and recursive form for sequences (day 1)
Add Subtract Positive Negative integers
1.3 Solving Linear Equations
Day 94 Explicit and recursive form for sequences (day 2)
CPSC 433 : Artificial Intelligence Tutorials T01 & T02
Dividing Polynomials. Dividing Polynomials Example 2X2+14x−16 X−1.
Equations 1 Click mouse.
6/18/ Pair 1 Pair 2 3 levels of LC severity Pair 3 Pair 4
Sine Rule: Missing Sides
Involving One Operation
Add and Subtract Positive & Negative Integers
Mosquitoes Control.
Presentation transcript:

Prolog Recursion Pepper

A rule with that calls itself is_digesting(X,Y) :- just_ate(X,Y). is_digesting(X,Y) :- just_ate(X,Z), is_digesting(Z,Y). 2 rules – You are digesting what you just ate – You are digesting whatever you ate just ate And so on until you come to an animal that did not just eat something.

Use in a query just_ate(mosquito,blood(john)). just_ate(frog,mosquito). just_ate(stork,frog). just_ate(person,cow). just_ate(cow,frog). is_digesting(person,X)"? Please answer 'y' or 'n'? yes X = cow ; X = frog ; X = mosquito ; X = blood(john) ;

Construction is_digesting(X,Y) :- just_ate(X,Y). is_digesting(X,Y) :- just_ate(X,Z), is_digesting(Z,Y). Base case: – Does not use its own predicate. Recursive rule: – Handles one case, – Recurses over the rest of the cases.

Proof Is_digesting(person,A). What just_ate fact has person on the left side, then the right side can be X. : look for just_ate(person,A). Look for just_ate(X,Z), is_digesting(Z,Y). if just_ate (person,_1) and (_1, A) so (person,cow) and (cow,frog) match so A = frog

Recursion Summary How to declare a recursive rule How to pair the recursive rule with a base case How prolog proof leads to recursion No base case – endless recursion