CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.

Slides:



Advertisements
Similar presentations
Some Prolog Prolog is a logic programming language
Advertisements

Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Chapter 11 :: Logic Languages
Prolog.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
CS344 : Introduction to Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 16- Prolog.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Comp 205: Comparative Programming Languages Declarative Programming Languages Logic Programming Horn-Clause Logic Prolog Lecture notes, exercises, etc.,
Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure.
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
Logic Programming Languages. Objective To introduce the concepts of logic programming and logic programming languages To introduce a brief description.
LING 364: Introduction to Formal Semantics Lecture 4 January 24th.
Copyright © 2003 Bolton Institute Logical Analysis and Problem Solving, (LAPS) Programming in Prolog.
Alternative Programming Paradigms
Formal Aspects of Computer Science – Week 12 RECAP Lee McCluskey, room 2/07
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
INFERENCE IN FIRST-ORDER LOGIC IES 503 ARTIFICIAL INTELLIGENCE İPEK SÜĞÜT.
ISBN Chapter 16 Logic Programming Languages.
Logic Programming Languages
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
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.
Evolution of Programming Languages Generations of PLs.
1 Lecture 15: Introduction to Logic Programming with Prolog (Section 11.3) A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
F28PL1 Programming Languages Lecture 16: Prolog 1.
1 COSC3306: Programming Paradigms Lecture 8: Declarative Programming Specifications Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
Getting Started with Visual Prolog
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
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.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
Programming Languages. A Logic Programming Language: Prolog This lesson describes the basic structures and functions of the logic programming language:
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
By: Cory Canter CSC 415 Programming Languages. History  Created by Alain Colmerauer, Phillipe Roussel and Robert Kowalski in 1971  Started as a natural.
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
Logic Programming Dr. Yasser Nada Fall 2010/2011 Lecture 1 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-1 An Introduction to Logical Programming Sept
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.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Copyright 1999Paul F. Reynolds, Jr. Foundations of Logic Programming.
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Recursive stack-based version of Back-chaining using Propositional Logic
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
PROLOG.
ARTIFICIAL INTELLIGENCE LAB UCEL601 ( Second Term) Presented by Nirmala 1.
Tests, Backtracking, and Recursion
3.5 Programming paradigms
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Logic Programming Languages
Dr. Yasser Nada Fall 2010/2011 Lecture 1
Logic Programming Language
PROLOG.
Presentation transcript:

CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog

PROLOG ->PROgramming in LOGic Prolog is a logic language that is suitable for symbolic or non-numeric computation. Prolog is frequently used in Artificial Intelligence where manipulation of symbols and inference about them is common. Prolog consists of a series of rules and facts. A program is run by presenting some query and seeing if it can be proved against the set of known rules and facts.

Topics in Prolog: ◦ Simple facts ◦ Facts with arguments ◦ Variables and unification ◦ Rules ◦ Search ◦ Recursion ◦ Lists

Topics in Prolog: ◦ Simple facts ◦ Facts with arguments ◦ Variables and unification ◦ Rules ◦ Search ◦ Recursion ◦ Lists

Represent a statement that is true Can consist of a particular item or a relationship between items Must begin with a lowercase letter! Examples of simple facts: raining./*it is raining*/ mary_has_a_coat./*mary has a coat*/ jackLikesDogs./*jack likes dogs*/

Represent more complicated facts Consist of a relation and the items it refers to Facts can have an arbitrary number of arguments (>0) Relation names must begin with a lowercase letter! Examples of facts with arguments: hungry( paul )./*paul is hungry*/ likes( john, mary )./*john likes mary*/ plays( john, football )./*john plays football*/

Variables are used to query the database Variable names must begin with an uppercase letter! For example: the letter ‘X’ is a variable the word ‘Who’ is a variable and the string ‘Abcd’ is a variable

To query database must replace unknown data in our query with a variable For example: Assuming the facts stated earlier are in our database If we want to find out who john likes, the query: ?-likes( john, X ). returns X = mary The process of matching items with variables is known as unification

So far we have looked at how to represent facts and how to query a database of facts Rules allow us to make conditional statements i.e. “the main statement is true if its sub- statement(s) are true” Rules are written in the form: main_statement( ) :- sub_statement( ).

Consider the following statement: “All footballers are well paid” In other words: “If a person is a footballer then they are well paid” or“A person is well paid if they are a footballer” This statement can be written in Prolog as a rule: well_paid( X ) :- footballer( X ).

More complex conditional statements can also be written in Prolog using rules Consider the following statement: “A house is energy efficient if it is well insulated and has double glazed windows” This can be written in Prolog as the following rule: energy_efficient( X ) :- house( X ), well_insulated( X ), double_glazed_windows( X ).

Consider the following statement: “A car has good fuel economy if it is a hybrid or it is a diesel” Statements with a disjunction can be written in Prolog as two separate rules: good_fuel_economy( X ) :- car( X ), hybrid( X ). good_fuel_economy( X ) :- car( X ), diesel( X ).

Introduces backtracking in Prolog Consider the following database of facts: eats( jack, curry ). eats( jack, pizza ). eats( jack, tuna ). Earlier we queried a database of facts to find out a single item of information ?- eats( jack, What ).

This query will return:What = curry Suppose we wish to answer the question: “What are all the things that jack eats?” ?- eats( jack, What ).returnsWhat = curry Can continue to ask Prolog for more results using ; What = pizza;What = tuna;No

Backtracking in rules Consider the following database: hold_party( X ) :- birthday( X ), happy( X ). birthday( tom ). birthday( jack ). birthday( helen ). happy( mary ). happy( helen ).

If we want to use the information contained in this database to decide who to hold a party for we can submit the following query: ?- hold_party( Who ). Prolog begins by finding a clause for ‘birthday’ and then binds Who to the argument of clause Prolog will then attempt to find a clause for ‘happy’ that matches the argument bound to Who If a match is not found, the search fails and Prolog backtracks to attempt to find a new birthday clause

hold_party( X ) :- birthday( X ), happy( X ). birthday( tom ). birthday( jack ). birthday( helen ). happy( mary ). happy( helen ). 1.Who binds to tom, search for happy( tom ), fail 2.Who binds to jack, search for happy( jack ), fail 3.Who binds to helen, search for happy( helen ), pass