Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”

Slides:



Advertisements
Similar presentations
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Advertisements

First Order Logic Logic is a mathematical attempt to formalize the way we think. First-order predicate calculus was created in an attempt to mechanize.
Chapter 11 :: Logic Languages
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
Logic Use mathematical deduction to derive new knowledge.
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
Logic.
1 Logic Programming with Prolog: Resolution, Unification, Backtracking COMP 144 Programming Language Concepts Spring 2003 Stotts, Hernandez-Campos Modified.
CS 330 Programming Languages 12 / 02 / 2008 Instructor: Michael Eckmann.
ISBN Chapter 16 Logic Programming Languages.
Propositional Calculus A propositional calculus formula is composed of atomic propositions, which area simply statements that are either true or false.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 27: Prolog’s Resolution and Programming Techniques COMP 144 Programming Language.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
CSE 452: Programming Languages
Logic Programming Languages. Objective To introduce the concepts of logic programming and logic programming languages To introduce a brief description.
CSE 452: Programming Languages
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Prolog Language Hamid Harroud School of Science and Engineering, Akhawayn University
ISBN Chapter 16 Logic Programming Languages.
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
Logic Programming Tasanawan Soonklang. Programming paradigms Imperative Object-oriented Functional Logic Procedural programming Non-procedural programming.
ISBN Chapter 16 Logic Programming Languages.
Logic Programming Languages
CPS 506 Comparative Programming Languages
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
CS 330 Programming Languages 12 / 04 / 2007 Instructor: Michael Eckmann.
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.
Chapter 16 Logic Programming Languages. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 16 Topics Introduction A Brief Introduction to.
1-1 Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
1 COSC3306: Programming Paradigms Lecture 8: Declarative Programming Specifications Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
Pattern-directed inference systems
1.  Provides the ability to access individual assertions. e.g. in Predicate calculus we may say: P denotes “It rained on Tuesday” but in predicate calculus.
CHAPTER 15 & 16 Functional & Logic Programming Languages.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
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.
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?
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
CS 363 Comparative Programming Languages Logic Programming Languages.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Propositional Logic Predicate Logic
CS 330 Programming Languages 11 / 25 / 2008 Instructor: Michael Eckmann.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Logic Programming: Prolog Lecture 21 – Prolog, Spring CSE3302 Programming Languages, UT-Arlington.
Logic Programming Tarik Booker. What will we cover?  Introduction  Definitions  Predicate Calculus  Prolog  Applications.
ISBN Chapter 16 Logic Programming Languages.
Dr. Muhammed Al-Mulhem ICS An Introduction to Prolog.
Knowledge Based Information System
1-1 An Introduction to Logical Programming Sept
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
First-Order Logic Semantics Reading: Chapter 8, , FOL Syntax and Semantics read: FOL Knowledge Engineering read: FOL.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
1-1 An Introduction to Prolog Sept Prolog statements Like other programming languages, Prolog consists of collection of statements. Prolog.
Logic Programming Languages
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Prolog a declarative language
Logic Programming Languages
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Logic Programming Languages
Logic Programming Languages
Prolog a declarative language
Prolog a declarative language
이산 수학 Discrete Mathematics
Prolog a declarative language
Horn Clauses and Unification
Logic Programming Language
Logic Programming Languages
Logic Programming & Prolog
Chapter 2: Prolog (Introduction and Basic Concepts)
Presentation transcript:

Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”

Introduction Logic programming language or declarative programming language Express programs in a form of symbolic logic Use a logical inferencing process to produce results Declarative rather that procedural: – Only specification of results are stated (not detailed procedures for producing them)

Copyright © 2006 Addison- Wesley. All rights reserved. 1-3 Applications of Logic Programming Relational database management systems Expert systems Natural language processing

Proposition A logical statement that may or may not be true – Consists of objects and relationships of objects to each other – Examples: John is a student : student(john). Hillary is Bill's wife: wife(hillary,bill).

Copyright © 2006 Addison- Wesley. All rights reserved. 1-5 Symbolic Logic Logic which can be used for the basic needs of formal logic: – Express propositions – Express relationships between propositions – Describe how new propositions can be inferred from other propositions Particular form of symbolic logic used for logic programming called predicate calculus

Copyright © 2006 Addison- Wesley. All rights reserved. 1-6 Object Representation Objects in propositions are represented by simple terms: either constants or variables – Constant: a symbol that represents an object – E.g student(mary)  “mary” is a constant – Variable: a symbol that can represent different objects at different times Different from variables in imperative languages E.g student(X)  “X” is a variable

Copyright © 2006 Addison- Wesley. All rights reserved. 1-7 Examples: student(john). like(seth, OSX). like(nick, windows). like(jim, linux). – Functor: function symbol that names the relationship ( e.g. student, like ….) – Ordered list of parameters (tuple) ( e.g. seth, OSX…)

Copyright © 2006 Addison- Wesley. All rights reserved. 1-8 Forms of a Proposition Propositions can be stated in two forms: – Fact: proposition is assumed to be true – Query: truth of proposition is to be determined Compound proposition: – Have two or more atomic propositions – Propositions are connected by operators

Facts A fact is a predicate expression that makes a declarative statement about the problem domain. Whenever a variable occurs in a Prolog expression, it is assumed to be universally quantified.

Rules A rule is a predicate expression that uses logical implication (:-) to describe a relationship among facts. left_hand_side :- right_hand_side. This sentence is interpreted as: left_hand_side if right_hand_side. The left_hand_side is restricted to a single, positive, literal, which means it must consist of a positive atomic expression. It cannot be negated and it cannot contain logical connectives. This notation is known as a Horn clause.

Rules Horn clause - can have only two forms – Headed: single atomic proposition on left side E.g likes(bob, trout):-likes(bob,fish),fish(trout). – Headless: empty left side (used to state facts) E.g father(bob, jake).

Copyright © 2006 Addison- Wesley. All rights reserved Example Rules ancestor(mary,shelley):- mother(mary,shelley). Can use variables (universal objects) to generalize meaning: parent(X,Y):- mother(X,Y). parent(X,Y):- father(X,Y). grandparent(X,Z):- parent(X,Y), parent(Y,Z). sibling(X,Y):- mother(M,X), mother(M,Y), father(F,X), father(F,Y).

Query The Prolog interpreter responds to queries about the facts and rules represented in its database. Whenever you run the Prolog interpreter, it will prompt you with ?-.

% ?- likes(sam,dahl). % ?- likes(sam,chop_suey). % ?- likes(sam,pizza). % ?- likes(sam,curry). likes(sam,Food) :- indian(Food), mild(Food). likes(sam,Food) :- chinese(Food). likes(sam,Food) :- italian(Food). indian(curry). indian(dahl). indian(tandoori). indian(kurma). mild(dahl). mild(tandoori). mild(kurma). chinese(chow_mein). chinese(chop_suey). chinese(sweet_and_sour). italian(pizza). italian(spaghetti ).

Copyright © 2006 Addison- Wesley. All rights reserved Resolution Unification: finding values for variables in propositions that allows matching process to succeed Instantiation: assigning temporary values to variables to allow unification to succeed After instantiating a variable with a value, if matching fails, may need to backtrack and instantiate with a different value