Prolog programming Introduction to Prolog

Slides:



Advertisements
Similar presentations
AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 2
Advertisements

1. An Overview of Prolog.
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 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
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.
Prolog programming Introduction to Prolog (part4) CS 370 – CS461.
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
Formal Logic Mathematical Structures for Computer Science Chapter 1 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic.
Comp 307 Lecture 4:1 Prolog I, II Prolog was taught as a procedural language Control structures: if, while, recursion Data structures: structured terms,
Chapter 12 - Logic Programming
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.
Introduction to Prolog Proof Procedures. Exercise parent(mark, alex). parent(di, alex). brother(brian, mark). sister(cathy, di). wife(susan, brian). husband(brad,
CS 330 Programming Languages 12 / 12 / 2006 Instructor: Michael Eckmann.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
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.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Prolog Notes for CSCE 330 Based on Bratko and Van Emden Marco.
Copyright © 2003 Bolton Institute Logical Analysis and Problem Solving, (LAPS) Programming in Prolog.
1 Artificial Intelligence CSC 361 Prof. Mohamed Batouche Department of Computer Science CCIS – King Saud University Riyadh, Saudi Arabia
1 MA 1128: Lecture 09 – 6/08/15 Solving Systems of Linear Equations.
Prolog programming Introduction to Prolog CS370d - CS 461.
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.
COSC 2P93 Logic Programming Instructor: Brian Ross Instructor: Brian Ross Texts: Texts: Prolog Programming for Artificial Intelligence,4e, Ivan Bratko,
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
Lesson 7.6 & 7.7 Inverses of a Square Matrix & Determinant.
Flow of Control Chapter 5. Flow of Control n What order computer uses to get answers –sub-goal ordering –clause ordering n Prolog flow-of-control –sequence.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
For Wednesday No new reading Prolog handout 2 Chapter 9, exercise 4.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
Chapter 2 Syntax and meaning of Prolog Programs LP and Prolog Chapter 22 PROLOG domains variable name = type predicates relation(variable name,
Introduction to Prolog Facts, Questions & Rules Atoms & Variables.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
For Monday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
© Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 2: Knowledge E. Tyugu Spring 2003.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
 Let’s demonstrate this process by working on an example problem.
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.
CS 403: Programming Languages Lecture 18 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Prolog Notes for CSCE 330 Based on Bratko, Poole, and Van Emden.
Artificial Intelligence CS370D
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
For Friday No reading Prolog Handout 2. Homework.
For Wednesday No reading Prolog handout 2 Chapter 9, exercise 4.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Logic Programming: Prolog Notes for CSCE 190 Based on Bratko,
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
1 Artificial Intelligence CS370D Prolog programming Introduction to Prolog.
EQUATION IN TWO VARIABLES:
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Prolog programming Introduction to Prolog
Prolog programming Introduction to Prolog (part2)
Prolog Primarily for Symbolic (nonnumeric) Computation
Prolog programming Introduction to Prolog
Prolog programming Introduction to Prolog (part3)
Chapter Two: Syntax and Meaning of Prolog Programs
Prolog programming Introduction to Prolog (part4)
How To Think Like a Prolog ?
Chapter 2: Prolog (Introduction and Basic Concepts)
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 CS 461

What is Prolog programming? Prolog is a programming language for symbolic , non-numeric commutation. It solves problems that involve objects and relations between objects.

Defining relations by facts The fact that Tom is a parent of Bob can be written in prolog as: Parent(tom, bob). tom and bob are objects, Parent(tom, bob) is a relation between these objects.

Defining relations by facts The whole family tree can be described by the following facts: Parent(pam,bob). Parent(tom,bob). Parent(tom,liz). Parent(bob,ann). Parent(bob,pat). Parent(pat,jim). pam tom bob liz ann pat jim

Defining relations by facts We can also add information about the sex of the people by the following facts: female(pam). male(tom). male(bob). female(liz). female(pat). female(ann). male(jim).

Defining relations by facts female(pam) is a Unary relation parent(bob,pat) is a Binary relation. Think about this relation: Sex(pam, feminist).

Questions in prolog. Prolog can posed questions about any relation. So, we can ask a question about Parent relation, For example : Is bob a parent of Pat? ?- Parent(bob,pat). The answer will be YES.

Questions in prolog. Another question can be asked: Who is Liz’s parent? ?- Parent(X, liz). The answer here will not be Yes/No, rather, prolog will find the value of X. So the answer is : tom pam tom bob liz ann pat jim

Class exercise(1) Who are bob’s children? Who is parent of whom? liz pam tom bob liz ann pat jim

Questions in prolog. In prolog, we can ask more complicated questions such as: Who is a grandparent of jim? ?- Parent(Y,jim) , Parent( X,Y). The answer will be: X=bob Y=pat X Parent grandparent Parent Y jim

Class exercise(2) Who are Tom’s grandchildren?

Questions in prolog. Do ann and pat have a common parents? ?- Parent(X,ann) , Parent(X, pat). The answer will be : X = bob.

Some important points A prolog program consists of clauses, each clause ends with a full stop. The arguments of relation can be concrete objects, constant objects (such as bob and pat) or general object (such as X and Y). Questions in prolog consist of one or more goals. parent(X,ann),parent(X,pat) means the conjunctions of the goals: X is parent of ann , and X is parent of Pat.

Defining relations by rules. Consider the relation offspring: offspring(liz, tom) This relation can be defined by making use of the fact that : the parent is the inverse of offspring. The alternative way can be based of the following logical statements: For all X and Y, Y is an offspring of X if X is a parent of Y.

Defining relations by rules. In prolog we can define the offspring relation in the following way: Offspring(Y,X) :- Parent(X, Y) This clause is called a rule The differences between rule and fact: Fact: is a something that always, unconditionally true. Rule: specify things that are true if some condition is satisfied.

Defining relations by rules. Each rule has two parts: Condition. (The right hand side) Conclusion. (The left hand side) offspring(X,Y):-parent(Y,X). offspring(X,Y) -> is a conclusion part. parent(X,Y) -> is a condition part.

Defining relations by rules. How rules are actually used by prolog program? Consider the following question: ?- offspring(liz, tom) There are no facts in the program about the offspring, therefore, the only way to find the answer is to apply the rule about offspring relation.

Defining relations by rules. Now we want to apply this rule: Offspring(Y,X) :- Parent(X, Y) to find the answer of this question: ?- offspring(liz, tom). X= tom, Y= liz. The initial goal is: offspring(liz,tom). The condition part become: parent(tom,liz). The initial goal will be replaced with the subgoal parent(tom,liz). Program can find the answer of this subgoal by using the facts about parent relation. After finding that the condition part is true, the conclusion part will be also true.

Class exercise(2) Write a rule to describe the grandparent relation?

Home exercise(1) Write a rule to describe the sister relation?

Recursive rule Let’s describe the predecessor relation , this relation will be defined in term of parent relation. For all X and Z X is a predecessor of Z if X is a parent of Z predecessor(X,Z):- parent(X,Z).

Recursive rule x z Y1 y2 Y3 What about indirect predecessor? parent Y1 What about indirect predecessor? The rule will be as the following: predecessor(X,Z):- parent(X,Y), parent(Y,Z) parent(X,Y1), parent(Y1,Y2). parent(y2,Z). ……. parent y2 Predecessor parent Y3 parent z

Recursive rule x z Y1 For all X and Z there is a Y such that parent Y1 For all X and Z there is a Y such that X is the parent of Y , and Y is a predecessor of Z. predecessor(X, Z) parent(X,Y), predecessor(Y,Z). parent y2 Predecessor parent Y3 Predecessor parent z