CHA2555 Week2 Practical: 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.
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).
Comp 307 Lecture 4:1 Prolog I, II Prolog was taught as a procedural language Control structures: if, while, recursion Data structures: structured terms,
Chapter 12 - Logic Programming
MB: 2 March 2001CS360 Lecture 31 Programming in Logic: Prolog Prolog’s Declarative & Procedural Semantics Readings: Sections
Rules Simple rules. Processing rules. Multiple sub-goals. PROLOG syntax. Recursive rules.
CS 330 Programming Languages 12 / 12 / 2006 Instructor: Michael Eckmann.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
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:
Discussion #20 1/11 Discussion #20 Resolution in Datalog.
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
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
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”
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.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
CIS2326 Week2: Logic and Prolog Lee McCluskey First term:
Lecture 9b: Prolog Heshaam Faili University of Tehran The language of logic Concepts Examples.
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.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
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)
The Law of Resolution Formal Aspects of Computer Science - Week 7 The Law of Resolution Lee McCluskey, room 2/07
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Logic Programming: Prolog Lecture 21 – Prolog, Spring CSE3302 Programming Languages, UT-Arlington.
ISBN Chapter 16 Logic Programming Languages.
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
For Monday Exam 1 is Monday Takehome due Prolog Handout 3 due.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
For Friday No reading Prolog Handout 2. Homework.
For Wednesday No reading Prolog handout 2 Chapter 9, exercise 4.
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:... :-....
The portion of a Prolog interpreter that executes queries (goals) is known as the inference engine. An inference engine is a kind of theorem prover, using.
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:
Logic Programming Languages
Prolog a declarative language
Prolog programming Introduction to Prolog (part3)
Programming Paradigms and Languages
Logic Programming Language
Clauses and Predicates
Chapter 2: Prolog (Introduction and Basic Concepts)
Presentation transcript:

CHA2555 Week2 Practical: Lee McCluskey First term:

Artform Research Group Prolog Overview… 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. ::=. ::= ( ) ::= | | ( ) ::= :-.

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 n a. father(X,esau) with father(isaac,Z). n b. cost(X,Y,40) with cost(U,V,60). n c. sentence(X,predicate(Y,object(Z))) with n sentence(subject(bill),Predicate) n d. sentence(X,predicate(Z)) with n sentence(subject(bill),predicate(verb(hit),object(bill)))

Artform Research Group Practicals Exs 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 – Matching and Backtracking 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…