Recursion and the order of terms in a PROLOG clause.

Slides:



Advertisements
Similar presentations
PROPIEDADES (Z = x - iy) * z1 +z2 = z1 +z2 * z = z * z1z2 =z1 +z2 * Z= Z * z1 / z2= z1/ z2 * Z = -Z Re {Z} = z + z Im {Z} = z - z 2 2i.
Advertisements

Applications Computational LogicLecture 11 Michael Genesereth Spring 2004.
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Artificial Intelligence: Natural Language and Prolog
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Formal Models of Computation Part II The Logic Model
Program verification: flowchart programs Book: chapter 7.
Program verification: flowchart programs Book: chapter 7.
© 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
Geometric Interpretation of Linear Programs
Chapter 11 :: Logic Languages
Lecture 11: Datalog Tuesday, February 6, Outline Datalog syntax Examples Semantics: –Minimal model –Least fixpoint –They are equivalent Naive evaluation.
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.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
Introduction to Prolog, cont’d Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Reasoning About Code; Hoare Logic, continued
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 13: 10/9.
Logic Programming Lecture 3: Recursion, lists, and data structures.
MB: 2 March 2001CS360 Lecture 31 Programming in Logic: Prolog Prolog’s Declarative & Procedural Semantics Readings: Sections
Rules Simple rules. Processing rules. Multiple sub-goals. PROLOG syntax. Recursive rules.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
REPETITION (loops or iteration) Schneider: Sec. 6.1 & 6.3.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/21.
Resolution Refutation Formal Aspects of Computer Science - Week 10 An Automated Theorem Prover Lee McCluskey, room 2/07
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/6.
Copyright © 2003 Bolton Institute Logical Analysis and Problem Solving, (LAPS) Programming in Prolog.
Intro to Statistics for the Behavioral Sciences PSYC 1900 Lecture 11: Power.
Algorithms: Selected Exercises Goals Introduce the concept & basic properties of an algorithm.
INFERENCE IN FIRST-ORDER LOGIC IES 503 ARTIFICIAL INTELLIGENCE İPEK SÜĞÜT.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 17 Announcement: next few weeks… 9 nd Feb: Comparative Programming.
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
C++ Beginner Tutorial: Functions IV Recursion. What is recursion? A property of function to be able to call itself… Get factorial of a given number: Factorial.
CS 321 Programming Languages and Compilers Prolog part 2.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 13 Recursion Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
Cs7120 (Prasad)L16-Meaning1 Procedural and Declarative Meaning of Prolog
It is very dangerous for our population when children don’t get educated. More girls than boys in the world are not in school. If girls are not educated,
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.
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.
Negation Chapter 5. Stating Negative Conditions n Sometimes you want to say that some condition does not hold n Prolog allows this –not/1this is a predicate.
H EAPS. T WO KINDS OF HEAPS : MAX AND MIN Max: Every child is smaller than its parent Meaning the max is the root of the tree 10 / \ 9 7 / \ 6 8 / \ 2.
Prolog programming....Dr.Yasser Nada. Chapter 7 Control and Negation Taif University Fall 2010 Dr. Yasser Ahmed Nada prolog programming....Dr.Yasser Nada.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
서울대한양대 ( 안 산 ) 충남대 1년1년 컴퓨터기초 (C) 컴퓨터프로그래밍 (C, Java) 컴퓨터프로그래밍 (C) 2. 봄 프로그래밍 원리 (Scheme, ML) Structure & Interpretation of Computer Programs 프로그래밍 방법론.
Selection Using IF THEN ELSE CASE Introducing Loops.
for( 起始條件 ; 判斷式 ; 條件運算 ){ // 迴圈內容 } while( 判斷式 ){ // 迴圈內容 } do{ // 迴圈內容 } while( 判斷式 ) ;
Special Triangles Review
COSC 2P93 Prolog: Debugging
Recursive stack-based version of Back-chaining using Propositional Logic
Recursion.
Use mathematical induction to prove that the formula is true for all natural numbers m. {image} Choose the first step of the proof from the following:
10:00.
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
مديريت موثر جلسات Running a Meeting that Works
Statement-Level Control Structures
What output is produced by the following fragment?
if-else Structures Principles of Engineering
CA 208 Logic Ex8 Describe (i.e. axiomatise, define) the following situation as a Prolog programme (use parent/2 and john, mary etc. as your vocabulary):
Quiz Propositional Logic.
Prolog Based on: Chapter 12 of PLP “Seven languages in seven weeks”
Presentation transcript:

recursion and the order of terms in a PROLOG clause

Lets look at two logically correct ways of encoding the ancestor relation 1. a program that works as desired 2. one that will sometimes loop infinitely Abbreviations: a=ancestor p=parent

1.A version that works p(h,t). p(t,j). (just three generations) a(X,Y) :- p(X,Y). a(X,Y) :- p(X,Z),a(Z,Y) Query: :- a(h,h). Run PROLOG: :- p(h,Z),a(Z,h). Only one choice: :- p(h,t),a(t,h). :- p(h,t),p(t,Z),a(Z,h). Only one choice! :- p(h,t),p(t,j),a(j,h). :- p(h,t),p(t,j),p(j,Z),a(Z,h). FALSE!

2. A version that can loop p(h,t). p(t,j). a(X,Y) :- p(X,Y). a(X,Y) :- a(X,Z),p(Z,Y) Query: :- a(h,h). Run PROLOG: :- a(h,Z1),p(Z1,h). :- p(h,t),p(t,h). FALSE :- a(h,Z2),p(Z2,Z1),p(Z1,h). :- p(h,t),p(t,Z1),p(Z1,h). FALSE :- a(h,Z3),p(Z3,Z2),p(Z2,Z1),p(Z1,h). Etc.

This was another illustration of how the order between the terms in a clause can affect the meaning of a PROLOG program