Artificial Intelligence CS370D

Slides:



Advertisements
Similar presentations
© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog.
Advertisements

Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Chapter 11 :: Logic Languages
1. An Overview of Prolog.
Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
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).
2. Syntax and Meaning. Contents Data Objects Matching Declarative meaning of Prolog Procedural meaning Example: monkey and banana Order of clauses and.
1 COMP313A Programming Languages Logic Programming (3)
Prolog Programming for Artificial Intelligence Three edition 2001
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
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
4. PROLOG Data Objects And PROLOG Arithmetic
Lecture 2 Introduction to C Programming
Introduction to C Programming
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure.
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.
1 Artificial Intelligence CSC 361 Prof. Mohamed Batouche Department of Computer Science CCIS – King Saud University Riyadh, Saudi Arabia
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
PROLOG KAIST Gunwoo Park 1. What’s Prolog? 2  General purpose logic programming language  Declarative, which means that the program logic is.
Formal Models of Computation Part II The Logic Model
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
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.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
Programming Languages Tucker and Noonan – 2e Chapter 15 – Part 1 Logic Programming “Q: How many legs does a dog have if you call its tail a leg? A: Four.
CS 603: Programming Languages Lecture 25 Spring 2004 Department of Computer Science University of Alabama Joel Jones.
Prolog Kyle Marcotte. Outline What is Prolog? Origins of Prolog (History) Basic Tutorial TEST!!! (sort of…actually not really at all) My example Why 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/
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
Logic Programming Dr. Yasser Ahmed Nada Fall 2010/2011 Lecture 2 1 Logic Programming.
Logic Programming Tarik Booker. What will we cover?  Introduction  Definitions  Predicate Calculus  Prolog  Applications.
ISBN Chapter 16 Logic Programming Languages.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
Knowledge Based Information System
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
For Friday No reading Prolog Handout 2. Homework.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Logic Programming: Prolog Notes for CSCE 190 Based on Bratko,
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
1 Artificial Intelligence CS370D Prolog programming Declarative meaning of Prolog programs and Lists representation.
1 Artificial Intelligence CS370D Prolog programming Introduction to Prolog.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !
Section 16.5, 16.6 plus other references
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Prolog a declarative language
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 a declarative language
Prolog a declarative language
Prolog a declarative language
Prolog programming Introduction to Prolog (part3)
Chapter Two: Syntax and Meaning of Prolog Programs
Chapter 2: Prolog (Introduction and Basic Concepts)
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

Artificial Intelligence CS370D Prolog programming Introduction to Prolog

Syntax of Prolog: Terms. Facts and Rules. Programs. Queries.

Syntax of Prolog: Terms A- Constants: 1- Identifiers: sequences of letters, digits, or underscore “_” that start with lower case letters.Ex: noura, x25, x_25, alpha_beta. 2- Numbers: Integers and real numbers:1.001, 2, 3.03 3- Strings enclosed in single quotes: ‘Noura A’ Note: can start with upper case letter, number, spaces or special characters like (==, <=,>=… etc)

Syntax of Prolog: Terms B- Variables: Sequence of letters digits or underscore that start with an upper case letter or the underscore. Ex: _x, Amal, Successor_State, Undescore by itself is the special “anonymous” variable.

Defining relations by rules. Rule is: relation can be defined by making use of the fact. structure with functor ' :- ' and two arguments: head and body. Each rule has two parts: Condition. (The right hand side) (head) Conclusion. (The left hand side) (body)

Defining relations by rules. 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. From previous example (parent relation): offspring(X,Y):-parent(Y,X). offspring(X,Y) -> is a conclusion part. parent(X,Y) -> is a condition part. For all X and Y,Y is an offspring of X if X is a parent of Y.

Defining relations by rules. More complex rules: Let’s add the following facts: female(leyla). male(omar). female(nour). male(khaled). female(meriam). male(ali). female(zahra). Now, let’s define the relation mother: For all X and Y ,X is the mother of Y if X is female and X is parent of Y.

Defining relations by rules. The corresponding Prolog rule is: Mother(X,Y):-female (X) , parent(X,Y). Head (conclusion part): mother (X,Y) Body (condition part): female (X) , parent(X,Y).

Defining relations by rules. female X X X offspring parent mother parent parent grandparent Y Y Y parent Z Nodes correspond to objects: arguments of relations. Arcs between nodes correspond to binary relations. Arcs are oriented so as to point from the first to the second argument. Unary relations are represented by marking the corresponding node by the name of the relation.

Defining relations by rules. Question: define the relation sister: Z parent parent X Y sister For any X and Y X is a sister of Y if Both X and Y have the same parent X is a female sister(X,Y):- female(X), parent(Z,X), parent(Z,Y).

Defining relations by rules. Let’s ask the question: is meriam sister of khaled? ?-sister(meriam,khaled). Another question: who is khaled’s sister? ?-sister(X,khaled). Think about ?-sister(X,meriam).

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? 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 Y1 parent y2 Predecessor parent Y3 parent z

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

Summary Prolog programs can be extended by simply adding new clauses. Prolog clauses are of three types: facts, rules and questions. Facts declare things that are always, unconditionally, true. Rules declare things that are true depending on a given condition. By means of questions the user can ask the program what things are true. Prolog clauses consist of the head and the body. The body is a list of goals separated by commas. Commas are understood as conjunctions. Facts are clauses that have a head and the empty body. Questions have only the body. Rules have a head and a body. Variables are instantiated when the system answers questions. Variables are assumed to be universally quantified (for all).