Prolog programming Introduction to Prolog (part4)

Slides:



Advertisements
Similar presentations
4. Using Structures: Example Programs. Contents l Retrieving structured information from a database l Doing data abstraction l Simulating a non-deterministic.
Advertisements

1. An Overview of Prolog.
Chapter 4 Predicate Logics
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.
Control Flow Analysis. Construct representations for the structure of flow-of-control of programs Control flow graphs represent the structure of flow-of-control.
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.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Prolog Notes for CSCE 330 Based on Bratko and Van Emden Marco.
Introduction to Trees Chapter 6 Objectives
Prolog programming Introduction to Prolog (part4) CS 370 – CS461.
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,
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Prolog Notes for Ch.1 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Copyright © 2003 Bolton Institute Logical Analysis and Problem Solving, (LAPS) Programming in Prolog.
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
12-CRS-0106 REVISED 8 FEB 2013 CSG2A3 ALGORITMA dan STRUKTUR DATA.
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.
The Evolution of Programming Languages Day 3 Lecturer: Xiao Jia The Evolution of PLs1.
Chapter 2 Syntax and meaning of Prolog Programs LP and Prolog Chapter 22 PROLOG domains variable name = type predicates relation(variable name,
© 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 ______.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
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.
For Friday No reading Prolog Handout 2. Homework.
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;
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Logic Programming: Prolog Notes for CSCE 190 Based on Bratko,
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.
ISOM MIS 215 Module 5 – Binary Trees. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.2
Arithmetic Sequences Explicit Formulas.
Guidelines: Expressions can be rewritten (distributed) to solve.
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
Prolog programming Introduction to Prolog
LINKED LISTS CSCD Linked Lists.
Prolog programming Introduction to Prolog (part2)
Introduction to Sequences
Solve: 1. 4<
Problem solving Plan - do act - check. Problem solving Plan - do act - check.
Prolog programming Introduction to Prolog
Number Patterns Grade 6 Patterning Unit.
Prolog programming Introduction to Prolog (part3)
Warming Up  .
Do Now.
Activity: Prime Path Coverage CS 4501 / 6501 Software Testing
CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.5
Geometric Mean.
Knowledge Representation
How To Think Like a Prolog ?
B.Ramamurthy Chapter 9 CSE116A,B
Algebra Introduction - BIDMAS
Collection of like terms
Sorted Binary Trees.
Day 1 – Recursive Patterns Notes Part 1
Chapter 9.1 Introduction to Sequences
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
Presentation transcript:

Prolog programming Introduction to Prolog (part4) CS 370

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). parent(jim,jon). 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 bob liz ann pat jim jon

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: First rule will define the direct predecessor. Second rule will be the indirect predecessors.

Defining relations by Recursive Rule. 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 parent Predecessor z

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

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 ). parent( X , Y ) , predecessor( Y , Z ).

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