ITEC Prolog Programming

Similar documents
Logical Consequences of Formulae. Definite Clauses

An Overview of Prolog. Chapter One: Introduction to Prolog

Brief Introduction to Prolog

Advanced Topics in LP and FP

Simon Fraser University School of Computing Science CMPT 383

COMP9414: Artificial Intelligence Propositional Logic: Automated Reasoning

TDDD08 Tutorial 1. Who? From? When? 6 september Victor Lagerkvist (& Wªodek Drabent)

Definite Logic Programs

Definite Logic Programs: Derivation and Proof Trees. CSE 505 Computing with Logic Stony Brook University

COMP9414: Artificial Intelligence First-Order Logic

Resolution and Refutation

Lecture Notes on Logic Programming

Inference in First-Order Predicate Calculus

Lecture Notes on Logic Programming

Individuals and Relations

Artificial Intelligence Chapter 7: Logical Agents

Logic Programming: Prolog

Resolution (14A) Young W. Lim 8/15/14

Strong AI vs. Weak AI Automated Reasoning

Predicate Logic. CSE 595 Semantic Web Instructor: Dr. Paul Fodor Stony Brook University

CS 4700: Artificial Intelligence

Logic & Computation. Autonomous Systems. Sistemi Autonomi. Andrea Omicini

Artificial Intelligence

Knowledge base (KB) = set of sentences in a formal language Declarative approach to building an agent (or other system):

Computational Logic Fundamentals (of Definite Programs): Syntax and Semantics

First Order Logic (FOL)

Top-Down Execution CS240B Notes

Modal Logics. Most applications of modal logic require a refined version of basic modal logic.

Chapter 16. Logic Programming. Topics. Logic Programming. Logic Programming Paradigm

Propositions. c D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 5.1, Page 1

Final exam of ECE 457 Applied Artificial Intelligence for the Fall term 2007.

Final exam of ECE 457 Applied Artificial Intelligence for the Spring term 2007.

Chapter 0 Introduction. Fourth Academic Year/ Elective Course Electrical Engineering Department College of Engineering University of Salahaddin

New fundamental discovery of the reverse Fibonacci sequence

Logic Programming (PLP 11) Predicate Calculus, Horn Clauses, Clocksin-Mellish Procedure

Propositional Resolution Introduction

First Order Logic (FOL)

Foundations of Artificial Intelligence

Logic (3A) Young W. Lim 10/29/13

A Stochastic l-calculus

Foundations of Logic Programming

Getting Real with Unreal Data: Lessons Learned and the Way Ahead

ILP = Logic, CS, ML Stop counting, start reasoning

Künstliche Intelligenz

Logic (3A) Young W. Lim 11/2/13

Logic (3A) Young W. Lim 10/31/13

Extensions to the Logic of All x are y: Verbs, Relative Clauses, and Only

The 30 Years War. Wheeler Ruml (UNH) Lecture 11, CS / 24. Leibniz. Logic in Practice. Satisfiability ILP

First order logic (FOL) Chapters 8 & 9

Database Applications (15-415)

Predicate Logic 1. The Need for Predicate Logic. The Need for Predicate Logic. The Need for Predicate Logic. The Need for Predicate Logic

Logic Programming Theory Lecture 7: Negation as Failure

Prolog: Resolution, Unification, & Cuts

Advanced DB CHAPTER 5 DATALOG

Deliberative Agents Knowledge Representation I. Deliberative Agents

Chapter 6 Constraint Satisfaction Problems

An Early (1971) Conversation. Logic Programming (PLP 11.3) Horn Clauses Introduction to Prolog: Resolution, Unification.

Inference in first-order logic

TOC. Search Paradigms: And Tree Search. Formal Definitions. And-tree-based Search. Formal Definitions

Propositional Reasoning

Logic Background (1A) Young W. Lim 12/14/15

Answer Set Programming (Draft) Vladimir Lifschitz University of Texas at Austin

Computational Logic. Introduction. Damiano Zanardini

spaghetti fish pie cake Ann X X Tom X X X Paul X X X

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar

Predicate Logic: Syntax

Logic (3A) Young W. Lim 12/5/13

Foundations of Artificial Intelligence

The Representation of Medical Reasoning Models in Resolution-based Theorem Provers

Foundations of Artificial Intelligence

Logic Background (1A) Young W. Lim 5/14/18

Theory of Computer Science. Theory of Computer Science. D7.1 Introduction. D7.2 Turing Machines as Words. D7.3 Special Halting Problem

EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS

Logical reasoning - Can we formalise our thought processes?

Foundations of Artificial Intelligence

Injectivity of Composite Functions

Applications of the Situation Calculus To Formalizing. Control and Strategic Information: The Prolog Cut Operator. Fangzhen Lin

Logics for Data and Knowledge Representation

Logic as The Calculus of Computer Science

Comp487/587 - Boolean Formulas

Logical Agents. Chapter 7

Propositional Resolution Part 1. Short Review Professor Anita Wasilewska CSE 352 Artificial Intelligence

Koza s Algorithm. Choose a set of possible functions and terminals for the program.

CSC384: Intro to Artificial Intelligence Knowledge Representation II. Required Readings: 9.1, 9.2, and 9.5 Announcements:

COMP4418: Knowledge Representation and Reasoning First-Order Logic

Logic III. Introduction to Artificial Intelligence CSE 150

Peter Wood. Department of Computer Science and Information Systems Birkbeck, University of London Automata and Formal Languages

Computing the Frequency of Partial Orders

7.5.2 Proof by Resolution

Theory of Computation

System description: CondLean

Logical Agent & Propositional Logic

ITS336 Lecture 6 First-Order Logic

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods for Software Engineering)

On the Complexity of Domain-Independent Planning

Deductive Systems. Lecture - 3

Introduction to Artificial Intelligence Propositional Logic & SAT Solving. UIUC CS 440 / ECE 448 Professor: Eyal Amir Spring Semester 2010

Intelligent Agents. Pınar Yolum Utrecht University

cis32-ai lecture # 18 mon-3-apr-2006

Intelligent Agents. Formal Characteristics of Planning. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University

Transcription:

1 ITEC 198 - Prolog Programming Dr. Maung M. Htay Department of Information Technology 1/18/16

Text Prolog Programming for Artificial Intelligence by Ivan Bratko Third Edition, Addison Wesley 2

References u Artificial Intelligence by George F Luger, Fourth Edition, Addison-Wesley u Prolog Help/References http://www.geocities.com/ saviranid/ u Roman Barták, 1997 page http://ktiml.mff.cuni.cz/ ~bartak/prolog.old/intro.html 3

What is Prolog? u Programming in Logic u Developed in early 1970, by Robert Kowalski, Maarteen van Emden, and David D.H. Warren at Edinburgh, U.K., Alain Colmerauer at Marseilles u For symbolic, non-numeric computation u Suited for solving problems that involve objects and relations between objects 4

Language Design u centered around a small set of basic mechanisms u including pattern matching, tree-based data structuring and automatic backtracking 5

Chapter 1: Introduction to Prolog u Defining relations by facts u Defining relations by rules u Recursive rules u How Prolog answers questions u Declarative and procedural meaning of programs 6

1.1 Defining relations by facts u The fact that Tom is a parent of Bob can be written in Prolog as: u parent(tom,bob). u parent is the relation u tom and bob are its arguments 7

A Family Tree 8

Prolog Program for the previous family tree parent(pam,bob). parent(tom,bob). parent(tom,liz). parent(bob,pat). parent(bob,ann). parent(pat,jim). 9

Clauses u A clause declares one fact about a relation For example, u parent(tom,bob) is a particular instance of the parent relation u an instance is also called a relationship u a relation is defined as the set of all its instances 10

Question to Prolog For example, u Is Bob a parent of Pat? In Prolog, u?- parent(bob,pat). Prolog will answer: u yes 11

More questions A further query can be: u?- parent(liz,pat). Prolog answers: u no 12

More questions continue --- Who is Liz s parent? u?- parent(x,liz). So the answer is: u X = tom 13

More questions continue --- Who are Bob s children? u?- parent(bob,x). The first answer is: u X = ann The another answer follows: u X = pat 14

Broader Questions -- Who is a parent of whom? In other words, u Find X and Y such that X is a parent of Y. In Prolog, u?- parent(x,y). 15

Broader Questions Continue --- The answers are output as: u X = pam u Y = bob; u X = tom u Y = bob; u X = tom u Y = liz; u... 16

Composed Query in Prolog u Who is a grandparent of Jim? 17

Composed Query in Prolog Continue -- To find a grandparent, we need two steps: u Who is a parent of jim? Assume that there is some Y. u Who is a parent of Y? Assume that there is some X. In Prolog, u?- parent(y, jim), parent(x,y). 18

Composed Query in Prolog Continue -- Who are Tom s grandchildren? u?- parent(tom,x), parent(x,y). Do Ann and Pat have a common parent? u?- parent(x,ann), parent(x,pat). 19

Important Points u Easy to define a relation, by stating the n-tuples of objects that satisfy the relation such as parent u Easy to query the Prolog system about relations defined in the program u A Prolog program consists of clauses. Each clause terminates with a full stop u Arguments of relations can be concrete objects, or constants (such as tom and ann), or general objects such as X and Y 20

Important Points Continue --- u Concrete objects or constants are called atoms and general objects are called variables u Questions to the system consist of one or more goals that are to be satisfied in the program such as:?- parent(x,ann), parent(x,pat). u Answer can be positive ( if satisfiable) or negative (if unsatisfable) u If several answers satisfy the question then Prolog will find as many of them as desired by the user 21

1.2 Defining relations by rules More relations Unary relations Binary relations u female(pam). sex(pam,feminine). u male(tom). sex(tom,masculine). u male(bob). sex(bob,masculine). u female(liz). sex(liz,feminine). u... Unary relations are simple yes / no properties of objects. 22

More Relations Example u to define a relation offspring as the inverse of the parent relation as a fact u offspring(liz, tom) is inverse of parent(tom, liz) It is understood as Liz is an offspring of Tom if Tom is a parent of Liz. In general, we can say that Y is an offspring of X if X is a parent of Y. 23

Relations are Defined Elegantly u to define offspring relation using already defined parent relation For all X and Y, Y is an offspring of X if X is a parent of Y. In Prolog, u offspring(y,x) :- parent(x,y). 24

What is Rules? For all X and Y, if X is a parent of Y then Y is an offspring of X In Prolog, u offspring(y,x) :- parent(x,y). is called a Rule. 25

Difference between facts and rules u A fact like parent(tom,liz) is something always, unconditionally true. u On the other hand, rules specify things that are true if some condition is satisfied. 26

Rules have u body, a condition part (the right-hand side of the rule) and u head, a conclusion part (the left-hand side of the rule) The format is offspring(y,x) :- parent(x,y). ------------------ --------------- head body 27

More Rules To define mother relation by rule For all X and Y, X is the mother of Y if X is a parent of Y and X is a female. In Prolog, u mother(x,y) :- parent(x,y), female(x). 28

More Rules Continue --- To define grandparent relation by rule For all X and Y, X is a grandparent of Y if X is a parent of Z and Z is a parent of Y. In Prolog, u grandparent(x,y) :- u u parent(x,z), parent(z,y). 29

More Rules Continue --- How do we define sister relation? For all X and Y, In Prolog, X is a sister of Y if both X and Y have the same parent, and X is a female. u sister(x,y) :- u u u parent(z,x), parent(z,y), female(x). 30

Question to prolog Who is pat s sister? In Prolog, u?- sister(x,pat). The answer to the previous program u X = ann u X = pat u We need to modify the program since pat is a sister of herself 31

Some Important Points, So Far u Prolog program can be added new clauses u Clauses are of three types: facts, rules, and questions u Facts declare things that are always, unconditionally true u Rules declare things that are true depending on a given condition u Questions are to be asked by the user 32

More Important Points u Clauses consists of head and body u Body is a list of goals separated by commas u Facts have a head and the empty body u Questions only have the body u Rules have the head and the non-empty body u A variable can be substituted by another object, that is called, variable is instantiated 33