CIS2326 Week2: Logic and Prolog Lee McCluskey First term:

Slides:



Advertisements
Similar presentations
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
Advertisements

LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
Bahar Pamuk. Outline Introduction Syntaxa Clauses, Programs and Queries List Manipulation Operators Backtracking, Cuts References.
Chapter 12 - Logic Programming
MB: 2 March 2001CS360 Lecture 31 Programming in Logic: Prolog Prolog’s Declarative & Procedural Semantics Readings: Sections
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Comp 205: Comparative Programming Languages Declarative Programming Languages Unification Backtracking Lecture notes, exercises, etc., can be found at:
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 18 LECTURE: Comparative Programming Languages + Prolog PRACTICALS:
AI - Week 16 Logic and Reasoning in AI: Resolution Refutation Lee McCluskey, room 2/07
CIA2326 Week3: Prolog: List Processing Lee McCluskey First term:
Formal Aspects of Computer Science – Week 12 RECAP Lee McCluskey, room 2/07
CHA2555 Week2: Knowledge Representation, Logic and Prolog Lee McCluskey First term:
CIA2326 Week4: Predicate Logic : introduction Lee McCluskey, room 2/07
ISBN Chapter 16 Logic Programming Languages.
Logic Programming Languages
Formal Models of Computation Part II The Logic Model
1 Prolog I. 2 Syllogisms “Prolog” is all about programming in logic. –Socrates is a man. –All men are mortal. –Therefore, Socrates is mortal.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
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.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
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.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
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.
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.
Prolog Programming in Logic. 2 SWI-Prolog SWI-Prolog is a good, standard Prolog for Windows and Linux Can be installed on Macintosh with a little more.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
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.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
For Monday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Lab Lecture#4 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami.
UNIVERSITI TENAGA NASIONAL CMPB454 ARTIFICIAL INTELLIGENCE (AI) CHAPTER 6 LOGIC PROGRAMMING USING PROLOG CHAPTER 6 LOGIC PROGRAMMING USING PROLOG Instructor:
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)
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Propositional Logic Predicate Logic
CHA2555 Week2 Practical: Lee McCluskey First term:
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.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
C. Varela1 Logic Programming (PLP 11, CTM 9.1) Terms, Resolution, Unification, Search, Backtracking (Prolog) Relational Computation Model (Oz) Carlos Varela.
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.
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:... :-....
O A procedure: a set of axioms (rules and facts) with identical signature (predicate symbol and arity). o A logic program: a set of procedures (predicates),
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
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 fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Logic Programming Languages
Prolog a declarative language
Prolog a declarative language
Prolog a declarative language
Logic Programming Language
Predicate Logic: Syntax.
Predicate Logic.
Chapter 2: Prolog (Introduction and Basic Concepts)
Presentation transcript:

CIS2326 Week2: Logic and Prolog Lee McCluskey First term:

Artform Research Group Summary This week we will look at the basic structure and operation of Prolog, and consider its connection to Logic,

Artform Research Group Logics – a popular form of knowledge representation All men are mortalEnglish Socrates is a man Therefore Socrates is mortal Ax Man(x) => Mortal(x)First-Order Logic Man(Socrates) |= Mortal(Socrates) mortal(X) :- man(X).Prolog man(socrates). QUERY- mortal(socrates). PROLOG RETURNS - Yes.

Artform Research Group Logics I n this course we will consider “Classical Logic” - where propositions (or “formulae) can only be 2 valued (true or false) There are other logic families for representing/dealing with all kinds of human knowledge.. - Time - Belief - Uncertainty / Fuzziness - Possibility and Certainty - Change - Action They all stem from Classical Logic

Artform Research Group Rest of lecture: Prolog parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y). grandad(X,Y) :- father(X,Z),parent(Z,Y). father(jacob,freda). mother(freda,frank). -- a Prolog program is a sequence of CLAUSES, each ending in ‘.’ -- each clause may be either a FACT or a RULE. – lowercase parameters are constants – uppercase parameters are vaiables

Artform Research Group Prolog Structure parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y). grandad(X,Y) :- father(X,Z),parent(Z,Y). father(jacob,freda). mother(freda,frank). A “rough” Syntax Definition for rules and facts in Prolog is as follows: ::=. ::= ( ) ::= | | ( ) ::= :-.

Artform Research Group Prolog Structure parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y). grandad(X,Y) :- father(X,Z),parent(Z,Y). father(jacob,freda). mother(freda,frank). A rule contains a HEAD and RULE BODY separated by the ':-' symbol. Each head must be a predicate and each rule body is a sequence of predicates separated by commas Rules can be read two ways: DECLARATIVELY or PROCEDURALLY. ** X is the grandad of Y is true if there exists a Z such that X is the father of Z and Z is the parent of Y. (declarative) ** To prove X is the grandad of Y, first prove X is the father of some Z, then prove this Z is the parent of Y. (procedural)

Artform Research Group To execute Prolog programs: parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y). grandad(X,Y) :- father(X,Z),parent(Z,Y). father(jacob,freda). mother(freda,frank). To execute/activate/run a program a GOAL is typed to the Prolog interpreter. It responds with no (failure) or yes (success) together with the successful instantiations of variables that appeared in the goal. ?- grandad(jacob,frank). -yes ?- grandad(X,frank). X = jacob -yes

Artform Research Group How Prolog works…. parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y). grandad(X,Y) :- father(X,Z),parent(Z,Y). father(jacob,freda). mother(freda,frank). To solve a goal such as: ?-grandad(jacob,frank). Prolog tries to MATCH this goal with facts and rule heads in the program, starting from the top and working down - search. -- constants/predicate symbols must match with constants/predicate symbols -- variables can match with any term When a variable MATCHES with a term we say it is instantiated.

Artform Research Group How Prolog works…. parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y). grandad(X,Y) :- father(X,Z),parent(Z,Y). father(jacob,freda). mother(freda,frank). To solve a goal such as: ?-grandad(jacob,frank). When a rule head is matched, matching variables become instantiated throughout the rule, and the TAIL of the rule is executed as if it were a GOAL. So Prolog executes ‘father(jacob,Z),parent(Z,frank)’ next….

Artform Research Group Practicals Exs from Notes.. Matching a. father(X,esau) with father(isaac,Z). b. cost(X,Y,40) with cost(U,V,60). c. sentence(X,predicate(Y,object(Z))) with sentence(subject(bill),Predicate) d. sentence(X,predicate(Z)) with sentence(subject(bill),predicate(verb(hit),object(bill)))

Artform Research Group Example from Notes.. Backtracking furry(tabby). furry(leo). small(tabby). has_whiskers(leo). has_big_teeth(leo). has_whiskers(tabby). cat(X) :- has_whiskers(X), furry(X). timid(X) :- cat(X), small(X). If the query '?-timid(X)' was typed, the second rule's first predicate 'cat(X)' would succeed with X = leo; this, however, would cause the second predicate to fail and control would backtrack to 'cat(X)'. The last successful match is then failed: this is the match of furry(leo) of the 'cat' rule with the identical fact in the database. furry(leo) fails completely since it can find no alternative match; consequently backtracking takes place in the 'cat' rule which eventually results in a success with X = tabby. The predicate 'small(X)' with this binding then succeeds.

Artform Research Group Summary Prolog programs are lists of facts and rules. To execute a program, you type a query. The Prolog interpreter tries to execute (prove) the query using the rules like procedures, and using matching on variables, and backtracking when a rule fails. Practical: Continue with the online exercises. Make sure you understand Prolog’s procedural method (up to the end of section 2) Advance to section 3 and beyond…