School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 18 LECTURE: Comparative Programming Languages + Prolog PRACTICALS:

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

Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
1. An Overview of Prolog.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
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.
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
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.
Comp 205: Comparative Programming Languages Declarative Programming Languages Unification Backtracking Lecture notes, exercises, etc., can be found at:
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
Formal Aspects of Computer Science – Week 12 RECAP Lee McCluskey, room 2/07
CHA2555 Week2: Knowledge Representation, Logic and Prolog Lee McCluskey First term:
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
CIA2326 Week4: Predicate Logic : introduction Lee McCluskey, room 2/07
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 17 Announcement: next few weeks… 9 nd Feb: Comparative Programming.
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.
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.
1-1 Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
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.
F28PL1 Programming Languages Lecture 16: Prolog 1.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
Getting Started with Visual Prolog
15/11/04 AIPP Lecture 14: Database Manipulation1 Database Manipulation Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 14 15/11/04.
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 Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
CSC 270 – Survey of Programming Languages Prolog Lecture 2 – Unification and Proof Search.
CIS2326 Week2: Logic and Prolog Lee McCluskey First term:
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?
I Power Higher Computing Software Development Development Languages and Environments.
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.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
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
Logic Programming Dr. Yasser Ahmed Nada Fall 2010/2011 Lecture 2 1 Logic Programming.
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.
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
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.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
C H A P T E R N I N E Logic Programming Part 2 Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Chapter 2 Syntax and meaning of prolog programs Part 1.
1 TP #2: How does Prolog answer questions? n Miscellaneous info; n Last TP exercises solved; n How does Prolog answer questions? n Recursive Prolog programs;
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.
More on Prolog syntax Already seen program statement types: Already seen program statement types: rules: p(X) :- q(X,Y), r(Y,z). rules: p(X) :- q(X,Y),
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
Prolog a declarative language
Prolog a declarative language
Prolog a declarative language
Prolog a declarative language
Programming Paradigms and Languages
Chapter 2 Syntax and meaning of prolog programs
Programming Languages 2nd edition Tucker and Noonan
Clauses and Predicates
Chapter 2: Prolog (Introduction and Basic Concepts)
PROLOG.
Presentation transcript:

School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 18 LECTURE: Comparative Programming Languages + Prolog PRACTICALS: Again, read through the notes on Blackboard OR on web – and do the exercises as directed

School of Computing and Mathematics, University of Huddersfield Prolog - getting started Writing programs in Prolog is a cycle involving 1. Write/Edit the program in a text-editor 2. Save the program in the text editor 3. Tell Prolog to load the program 4. If Prolog gives you errors, go back to step 1 and fix them 5. Test it - if it doesn't do what you expected, go back to step 1 (reference:

School of Computing and Mathematics, University of Huddersfield 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 Prolog program is a sequence of CLAUSES, each ending in ‘.’ -- each clause may be either a FACT or a RULE. ::=. ::= ( ) ::= | | symbol( )

School of Computing and Mathematics, University of Huddersfield 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)

School of Computing and Mathematics, University of Huddersfield 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

School of Computing and Mathematics, University of Huddersfield 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. -- 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.

School of Computing and Mathematics, University of Huddersfield 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….

School of Computing and Mathematics, University of Huddersfield How Prolog works….example from notes.. online(kings_cross,northern). online(kings_cross,circle). online(kings_cross,victoria). online(kings_cross,piccadilly). online(barbican,circle). online(holburn,circle). online(moorgate,northern). online(moorgate,circle). online(barbican,circle). online(bank,northern). online(angel,northern). online(finsbury_park,piccadilly). sameline(Station1,Station2,Line1) :- online(Station1,Line1), online(Station2,Line1). interchange(Line1,Line2,Station1) :- online(Station1,Line1), online(Station1,Line2). route(Station1,Station2) :- sameline(Station1,Station2,Line1), nl,write('use '),write(Line1),write(' direct'),nl. route(Station1,Station2) :- online(Station1,Line1), interchange(Line1,Line2,StationX), sameline(Station2,StationX,Line2), nl,write('use '),write(Line1), nl,write('change at '),write(StationX), nl,write('then use '),write(Line2).

School of Computing and Mathematics, University of Huddersfield Summary - A Prolog program is a list of facts and rules, executed by typing in a goal. n Facts and rules are made from predicates – which is a predicate symbol followed by 0,1, or more terms n A rule may be given a declarative (logical) or procedural interpretation. n Two predicates match if their predicate symbols and ‘arities’ are identical, and corresponding arguments are identical or variables can be instantiated to terms. n Prolog executes a goal by trying to match the goal with the head of a rule (or a fact) in top down order. If the goal matches with a rule head, Prolog then tries to execute the rule’s tail (which is a list of goals).