Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15

Slides:



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

Computer Science CPSC 322 Lecture 25 Top Down Proof Procedure (Ch 5.2.2)
Software Development Languages and Environments. Programming languages High level languages are problem orientated contain many English words are easier.
Chapter 11 :: Logic Languages
1. An Overview of Prolog.
Principles of programming languages 1: Introduction (with a simple language) Isao Sasano Department of Information Science and Engineering.
Key Stone Problems… Key Stone Problems… next Set 11 © 2007 Herbert I. Gross.
Lecture Roger Sutton 21: Revision 1.
Chapter 6 Problem Solving and Algorithm Design. 6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Chapter 8: The Logical Paradigm Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
CPSC 322 Introduction to Artificial Intelligence September 15, 2004.
Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
High-Level Programming Languages
Pseudocode and Algorithms
Introduction to a Programming Environment
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
9-Aug-15 Vocabulary. Programming Vocabulary Watch closely, you might even want to take some notes. There’s a short quiz at the end of this presentation!
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
Chapter 9 High-Level Programming Languages: C++. Chapter Goals Describe the expectations of high level languages Distinguish between functional design.
Dr. Ken Hoganson, © August 2014 Programming in R STAT8030 Programming in R COURSE NOTES 1: Hoganson Programming Languages.
Languages and Environments Higher Computing Unit 2 – Software Development.
1 Software Development Topic 2 Software Development Languages and Environments.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
Formal Models of Computation Part II The Logic Model
1 Visual Prolog Programs LabLecture # 3 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
AS Computing Introduction to Programming. What is a Computer Program? A list of instructions that a computer must work through, in a logical sequence,
Evolution of Programming Languages Generations of PLs.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
F28PL1 Programming Languages Lecture 16: Prolog 1.
Getting Started with Visual Prolog
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
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?
Chapter 7 The Practices: dX. 2 Outline Iterative Development Iterative Development Planning Planning Organizing the Iterations into Management Phases.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
Alternative Algorithms for Addition and Subtraction If we don’t teach them the standard way, how will they learn to compute?
Introduction to OOP CPS235: Introduction.
ISBN Chapter 16 Logic Programming Languages.
Knowledge Based Information System
Artificial Intelligence CS370D
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Done By :- -Nesreen Basem -Sara nabil -Rawan Prolog Program.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
Software Design and Development Languages and Environments Computing Science.
OCR A Level F453: High level languages Programming techniques a. identify a variety of programming paradigms (low-level, object- oriented,
JavaScript/ App Lab Programming:
Component 1.6.
Visit for more Learning Resources
CSCI-235 Micro-Computer Applications
Information Science and Engineering
Introduction to Computer Programming
Developing Applications
CS190/295 Programming in Python for Life Sciences: Lecture 1
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Theory of Computation Turing Machines.
A programming language
Chapter 2: Prolog (Introduction and Basic Concepts)
Presentation transcript:

Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15 phone: ex 4029

Assessment: Coursework 1 A sequence of practical exercises issued each week which have to be completed in that week and signed of at the tutorial15 % Coursework 2A practical assignment15% Examinations An observed practical examination (in Week 7)30% An unseen exam paper at the end of the module40%.

The Concept of Logic Programming Languages such as Pascal, Modula-2 and C are known as procedural languages or as imperative languages. A program consists of a sequence of instructions telling the computer how to solve your problem. This in turn means that you have to translate your problem into a form that can be represented in the syntax of the language you are using. Frequently you spend more time trying to manipulate the constucts of the language than on considering the problem you are trying to solve.

High Level Languages High level programming languages are simply abstractions, which allow us to perform our computing operations without considering the underlying mechanisms that exist at the processor level. One instruction in a high level language may replace ten or twenty at machine level. Once written in an imperative language the compiler will translate the program into machine code, appropriate for the processor we are using and we can use our program just as if we had written it in machine code in the first place.

The logic programming paradigm If we consider our program written in a high level imperative language we still find that the underlying number crunching concepts come through. Although we have a high level language, its number crunching roots keep intruding when we would rather be working at a problem oriented level. To avoid the programming errors we have decomposed the program development process into separate analysis, design and implementation stages using methodologies such as SSADM to allow us to work only at the problem solving level.

The logic programming paradigm In the case of logic programming we work with a language which is itself much closer to the problems solving level. Although, as in all languages, at the lowest level we are still number crunching, a logic programming language such as Prolog provides a very high level of abstraction so that our program is not a set of instructions, but simple a description of the real world situation in which we are working. We need to take much less account of how to solve the problem but only need to produce a full, logically sound and complete description of the system in which we are working.

The logic programming paradigm This technique we will be using is also known as declarative programming The logic programming language Prolog that will be used in this module is a very good example of this programming technique. Declarative programming using a language such as Prolog is particularly good for symbolic programming, that is to say programming using non-numeric data.

A Problem to consider Spend a little time considering how you would solve this program in or C++ or Visual Basic We have a set of facts about the games people play of the form  Jon plays rugby  Mary plays hockey... perhaps twenty such facts in all We have some more facts about peoples’ musical ability of the format  Anne plays the trumpet  Jon plays the violin... perhaps twenty more facts with some, but not all, of the people overlapping the list of sports players.

A Problem to consider We now decide that in our world the following definitions apply:  Anyone who plays a sport is a sportsman  Anyone who plays a musical instrument is a musician  Anyone who plays more than one sport is an allrounder  Anyone who plays more than one musical instrument is gifted  Anyone who is both an allrounder and gifted is brilliant

A Problem to consider The problem we want to solve is to be able to use our program to find solutions to problems such as:  who can play cricket?  who can play the violin?  who can play both rugby and the cello?  who is brilliant?  or even, find me a list of people who have the necessary skills to form a string quartet

Logic Programming in Prolog In Prolog we have a very simple syntax which allows us to represent the simple facts and rules which describe our little world. Prolog is basically and interpreted language and therefore once we have described our system we can simple put any of those questions to the Prolog interpreter. The interpreter, using predicate logic, will search for the answers to our questions, which can be derived from our description or the system.

Logic Programming in Prolog We do not have to tell it how to search all we need is our description of our system, which we might call a knowledge base, and the question to which we want an answer. The interpreter does the rest. In other words Prolog provides us with a higher level of abstraction towards the problem level. It frees us from the need to consider how to solve the problem and allows us to concentrate on the problem we want to solve.

Logic Programming in Prolog The two major differences you will notice when you try to implement an example in Prolog rather than a procedural language are.  The program will be much shorter  It will use far fewer program constructs and will therefore be easier to follow. There is a down side to this, although the program will be relatively short, it may still require some thought so don’t assume you can write 20 line of Prolog as quickly as 20 lines of C.

Logic Programming in Prolog Compared with most other languages, the syntax of Prolog uses very few constructs and symbols and therefore it takes very little time to learn enough to write simple programs. There are more complex features which have been built into Prolog to add to its usefulness and these do take a little more effort to master. The most important step in learning Prolog is to put your existing programming ideas to one side and learn to think and work in declarative terms.

Let’s look at a sample of Prolog code parent(dave,jon). parent(dave,anna). parent(jim,lauren). parent(sally,lauren). male(dave). male(jon). female(jane). female(anna). mother(X,Y):- parent(X,Y), female(X). The only symbols we have used that are part of Prolog are (),.:- By default Prolog regards anything which begins with a lower case letter as an atom (Atomic constant) and anything which begins with an upper case letter as a variable

Let’s look at a sample of Prolog code parent(dave,jon). parent(dave,anna). parent(jim,lauren). parent(sally,lauren). male(dave). male(jon). female(jane). female(anna). mother(X,Y):- parent(X,Y), female(X). The program consist of a number of clauses each ending with a full stop. The clause parent(dave,jon). Is used to represent a fact. The functor parent links the two arguments dave and jon. If you like it defines the connection between them. We decide what this clause means in our world

Let’s look at a sample of Prolog code parent(dave,jon). parent(dave,anna). parent(jim,lauren). parent(sally,lauren). male(dave). male(jon). female(jane). female(anna). mother(X,Y):- parent(X,Y), female(X). In the clause male(dave) The functor male defines a property or attribute of its argument dave. Again we decide what this clause means in our world

Let’s look at a sample of Prolog code parent(dave,jon). parent(dave,anna). parent(jim,lauren). parent(sally,lauren). male(dave). male(jon). female(jane). female(anna). mother(X,Y):- parent(X,Y), female(X). The clause mother(X,Y):- parent(X,Y), female(X). Defines a rule, if you like think of it as a generalisation. The functor mother defines the connection between the two arguments which are the variables X and Y.

Let’s look at a sample of Prolog code parent(dave,jon). parent(dave,anna). parent(jim,lauren). parent(sally,lauren). male(dave). male(jon). female(jane). female(anna). mother(X,Y):- parent(X,Y), female(X). The term mother(X,Y) is the head of the clause The terms parent(X,Y), female(X) are the body of the clause The head and body of the clause are separated by the symbol :-

Let’s look at a sample of Prolog code parent(dave,jon). parent(dave,anna). parent(jim,lauren). parent(sally,lauren). male(dave). male(jon). female(jane). female(anna). mother(X,Y):- parent(X,Y), female(X). The head and body of the clause are separated by the symbol :- Think of the symbol :- as meaning if The head of the clause is true if the body of the clause can be proved to be true. Another way of looking at it is to say that the body of the clause (if true) implies the head of the clause.

Let’s look at a sample of Prolog code parent(dave,jon). parent(dave,anna). parent(jim,lauren). parent(sally,lauren). male(dave). male(jon). female(jane). female(anna). mother(X,Y):- parent(X,Y), female(X). This is a simplified explanation but to summarise. Facts, things which are always true are represented by clauses which have a head and no body. Rules are represented by a clause which has a head and a body.

Let’s look at a sample of Prolog code parent(dave,jon). parent(dave,anna). parent(jim,lauren). parent(sally,lauren). male(dave). male(jon). female(jane). female(anna). mother(X,Y):- parent(X,Y), female(X). When we run our progame we load it into Prolog and then set goals, ( if you like ask it questions ). The interpreter tries to satisfy our goals ( answer our questions ) by matching them with the heads of the clauses in the program. You will probably understand the working of the interpreter much better if you think of it as a pattern matching process