Prolog programming Introduction to Prolog (part4) CS 370 – CS461.

Slides:



Advertisements
Similar presentations
9 x9 81 4/12/2015 Know Your Facts!. 9 x2 18 4/12/2015 Know Your Facts!
Advertisements

1. An Overview of Prolog.
Primitive Recursive Functions (Chapter 3)
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
1 x0 0 4/15/2015 Know Your Facts!. 9 x1 9 4/15/2015 Know Your Facts!
1 x0 0 4/16/2015 Know Your Facts!. 1 x8 8 4/16/2015 Know Your Facts!
3 x0 0 7/18/2015 Know Your Facts!. 4 x3 12 7/18/2015 Know Your Facts!
Control Flow Analysis. Construct representations for the structure of flow-of-control of programs Control flow graphs represent the structure of flow-of-control.
M180: Data Structures & Algorithms in Java
1 Logic Programming. 2 A little bit of Prolog Objects and relations between objects Facts and rules. Upper case are variables. parent(pam, bob).parent(tom,bob).
1 COMP313A Programming Languages Logic Programming (3)
Prolog Programming for Artificial Intelligence Three edition 2001
Introduction to Prolog Language Presented by San Myint.
Introduction to Trees Chapter 6 Objectives
Prolog programming Introduction to Prolog
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
MB: 2 March 2001CS360 Lecture 31 Programming in Logic: Prolog Prolog’s Declarative & Procedural Semantics Readings: Sections
Introduction to Prolog Proof Procedures. Exercise parent(mark, alex). parent(di, alex). brother(brian, mark). sister(cathy, di). wife(susan, brian). husband(brad,
Function Tables 02/12/12 lntaylor ©. Table of Contents Learning Objectives Linear Equations Build a Function Table Build a T Chart Reading a Function.
Exercise Exercise3.1 8 Exercise3.1 9 Exercise
Exercise Exercise Exercise Exercise
Exercise Exercise Exercise Exercise
Exercise Exercise6.1 7 Exercise6.1 8 Exercise6.1 9.
Copyright © 2003 Bolton Institute Logical Analysis and Problem Solving, (LAPS) Programming in Prolog.
Introduction to C Programming CE Lecture 21 Recursion and Linear Linked Lists.
RECURSIVE PATTERNS WRITE A START VALUE… THEN WRITE THE PATTERN USING THE WORDS NOW AND NEXT: NEXT = NOW _________.
Prolog programming Introduction to Prolog CS370d - CS 461.
11.1 Simplifying Radical Expressions
COSC 2P93 Logic Programming Instructor: Brian Ross Instructor: Brian Ross Texts: Texts: Prolog Programming for Artificial Intelligence,4e, Ivan Bratko,
12-CRS-0106 REVISED 8 FEB 2013 CSG2A3 ALGORITMA dan STRUKTUR DATA.
Interesting Integers!. Definition Positive number – a greater than zero
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
Teamwork Chapter 4.
Multiplying decimals. What is the answer to 0.26 x 0.6? In order to work this out you must be able to multiply the whole numbers together In fact do just.
3 x0 0 10/18/2015 Know Your Facts!. 11 x /18/2015 Know Your Facts!
Solving Compound Inequalities “And” implies that BOTH must occur. “Or” implies that one or the other will occur, but not necessarily both.
Chapter 2 Syntax and meaning of Prolog Programs LP and Prolog Chapter 22 PROLOG domains variable name = type predicates relation(variable name,
Binary Search Trees Binary Search Trees (BST)  the tree from the previous slide is a special kind of binary tree called a binary.
© Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 2: Knowledge E. Tyugu Spring 2003.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
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.
10-1 An Introduction to Systems A _______ is a set of sentences joined by the word ____ or by a ________________. Together these sentences describe a ______.
Artificial Intelligence CS370D
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
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;
Seminář 51 Seminář 5. seminář 52 The system λμ It is the system of recursive types. The recursive types come together with an equivalence relation. The.
11.3 Solving Radical Equations Definitions & Rules Simplifying Radicals Practice Problems.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Lesson 3A: Arithmetic Sequences Ex 1: Can you find a pattern and use it to guess the next term? A) 7, 10, 13, 16,... B) 14, 8, 2, − 4,... C) 1, 4, 9,
Fundamentals of Programming II Introduction to Trees
Arithmetic Sequences Explicit Formulas.
Guidelines: Expressions can be rewritten (distributed) to solve.
Prolog programming Introduction to Prolog
Prolog programming Introduction to Prolog (part2)
Solve: 1. 4<
Problem solving Plan - do act - check. Problem solving Plan - do act - check.
CSC 253 Lecture 6.
Prolog programming Introduction to Prolog
Prolog programming Introduction to Prolog (part3)
Prolog programming Introduction to Prolog (part4)
How To Think Like a Prolog ?
Collection of like terms
Objectives The student will be able to:
CS589 Principles of DB Systems Fall 2008 Lecture 4a: Introduction to Datalog Lois Delcambre
CS589 Principles of DB Systems Fall 2008 Lecture 4a: Introduction to Datalog Lois Delcambre
11-5 Solving Rational Equations
Presentation transcript:

Prolog programming Introduction to Prolog (part4) CS 370 – CS461

How to solve this problem? Consider the following facts: parent(pam,bob). parent(tom,bob). parent(tom,liz). parent(bob,ann). parent(bob,pat). parent(pat,jim). If we want to describe a new relation called “ predecessor”, which checks if a specific node is a predecessor of another node or not. For example: ?- predecessor(tom, pat). How can this relation be described? pam tom bobliz annpat jim

Defining relations by Recursive Rule. To solve the previous predecessor(tom, pat) relation problem we have to defined a recursive rule. This relation will be defined in terms of the parent relation. The whole definition can be expressed with two rules: 1.First rule will define the direct predecessor. 2.Second rule will be the indirect predecessors.

Defining relations by Recursive Rule. 1.Direct Rule  For all X and Z X is a predecessor of Z if X is a parent of Z.  The rule will be: predecessor( X, Z ) :- parent( X, Z ). x z Predecessor parent

Defining relations by Recursive Rule. 2. Indirect Rule Y1 Y2 z Predecessor parent x Y1 z Y2 Predecessor parent Predecessor

Defining relations by Recursive Rule. 2. Indirect Rule  For all X and Z there is a Y such that: X is a predecessor of Z if X is a parent of Y and Y is a predecessor of Z.  The rule will be: predecessor( X, Z ) :- parent( X, Y), predecessor(Y,Z).

Defining relations by Recursive Rule. Thus,we have constructed a complete program for the predecessor relation, which consists of two rules: one for direct predecessors and one for indirect predecessors. Both rules must be rewritten together as : predecessor( X, Z ) :- parent( X, Z ). predecessor( X, Z ) :- parent( X, Y ), predecessor( Y, Z ).

Class exercise(1) Write a rule to describe the successor relation?