programmation en logique

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

Chapter 11 :: Logic Languages
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
1 Basic Prolog ?- prolog prompt A :- B IMPLIES in rules; if B then A, logical AND ; logical OR -> if-then-else. END of predicate switch query/database.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Declarative Programming Autumn 2014 Introduction.
Prolog Programming slides written by Dr W.F. Clocksin.
4. PROLOG Data Objects And PROLOG Arithmetic
Declarative Programming Autumn 2014 Basic syntax and sample programs.
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.
Overview of Programming Paradigms
Introduction to a Programming Environment
TES3111 October 2001 Artificial Intelligence LISP.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
LISP and PROLOG AI Programming Language Submitted To: Dr. Hesham El-Zoka Submitted By: Eng. Ismail Fathalla El-Gayar.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
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.
Evolution of Programming Languages Generations of PLs.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
Getting Started with Visual Prolog
Artificial Intelligence LECTURE 2 ARTIFICIAL INTELLIGENCE LECTURES BY ENGR. QAZI ZIA 1.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
Programmaing in logic Apurva Patil Gayatri Kharavlikar Meenakshi Borse Manjiri Bankar Nikita Alai Shruti Govilkar.
ARTIFICIAL INTELLIGENCE DR. ABRAHAM AI a field of computer science that is concerned with mechanizing things people do that require intelligent.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
Programming Languages. A Logic Programming Language: Prolog This lesson describes the basic structures and functions of the logic programming language:
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
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?
By: Cory Canter CSC 415 Programming Languages. History  Created by Alain Colmerauer, Phillipe Roussel and Robert Kowalski in 1971  Started as a natural.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Logical and Functional Programming
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
Logic Programming (LP) expresses code using of a restricted form of symbolic logic. LP programs are declarative, rather than algorithmic. An LP program.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Logic Programming: Prolog Lecture 21 – Prolog, Spring CSE3302 Programming Languages, UT-Arlington.
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
Logic Programming Tarik Booker. What will we cover?  Introduction  Definitions  Predicate Calculus  Prolog  Applications.
ISBN Chapter 16 Logic Programming Languages.
CPS120: Introduction to Computer Science Variables and Constants.
Knowledge Based Information System
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
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.
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:... :-....
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.
PROLOG “Programmation en Logique”
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
A Conjunction is a logical operator that connects two logical terms.
The Selection Structure
PROLOG.
Prolog Programming slides written by
Tests, Backtracking, and Recursion
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Chapter 10 Programming Fundamentals with JavaScript
Chapter Two: Syntax and Meaning of Prolog Programs
Topics Introduction to Functions Defining and Calling a Function
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 2: Prolog (Introduction and Basic Concepts)
Representations & Reasoning Systems (RRS) (2.2)
PROLOG.
Presentation transcript:

programmation en logique

LOGIC PROGRAMMING science of reasoning algorithm = logic + control purely based on rules and facts artificial intelligence declarative

HISTORY Created in 1972 by Philippe Roussel and Alain Colmerauer Based on Robert Kowalski’s procedural interpretation of Horn clauses

TWO TYPES OF PROGRAMMING LANGUAGES Procedural (BASIC, Fortran, C++, Java) Declarative (LISP, Prolog) In procedural programming, we tell the computer how to solve a problem. In declarative programming, we tell the computer what problem we want solved.

INTRODUCTION TO PROLOG Prolog is the most widely used language to have been inspired by logic programming research. Some features: Prolog uses logical variables. These are not the same as variables in other languages. Programmers can use them as ‘holes’ in data structures that are gradually filled in as computation proceeds.

…MORE Clauses provide a convenient way to express case analysis and nondeterminism. Sometimes it is necessary to use control features that are not part of ‘logic’. A Prolog program can also be seen as a relational database containing rules as well as facts.

WAT A PROGRAM LOOKS LIKE /* At the Zoo */ elephant(george). elephant(mary). panda(chi_chi). panda(ming_ming). dangerous(X) :- big_teeth(X). dangerous(X) :- venomous(X). guess(X, tiger) :- stripey(X), big_teeth(X), isaCat(X). guess(X, koala) :- arboreal(X), sleepy(X). guess(X, zebra) :- stripey(X), isaHorse(X).

PROLOG IS A DECLARATIVE LANGUAGE Clauses are statements about what is true about a problem, instead of instructions how to accomplish the solution. The Prolog system uses the clauses to work out how to accomplish the solution by searching through the space of possible solutions. Not all problems have pure declarative specifications. Sometimes extralogical statements are needed.

Complete Syntax of Terms Variable Constant Compound Term Names an individual Stands for an individual unable to be named when program is written Names an individual that has parts Atom Number likes(john, mary) book(dickens, Z, cricket) f(x) [1, 3, g(a), 7, 9] -(+(15, 17), t) 15 + 17 - t X Gross_pay Diagnosis _257 _ alpha17 gross_pay john_smith dyspepsia + =/= ’12Q&A’ 1 57 1.618 2.04e-27 -13.6

Compound Terms The parents of Spot are Fido and Rover. parents(spot, fido, rover) Functor (an atom) of arity 3. components (any terms) It is possible to depict the term as a tree: parents spot fido rover

Predicate Definitions Both facts and rules are predicate definitions. ‘Predicate’ is the name given to the word occurring before the bracket in a fact or rule: parent(jane,alan). By defining a predicate you are specifying which information needs to be known for the property denoted by the predicate to be true. Predicate name

Clauses Predicate definitions consist of clauses. = An individual definition (whether it be a fact or rule). e.g. mother(jane,alan). = Fact parent(P1,P2):- mother(P1,P2). = Rule A clause consists of a head and sometimes a body. Facts don’t have a body because they are always true. head body

Arguments mother(jane,alan). A predicate head consists of a predicate name and sometimes some arguments contained within brackets and separated by commas. mother(jane,alan). A body can be made up of any number of subgoals (calls to other predicates) and terms. Arguments also consist of terms, which can be: Constants e.g. jane, Variables e.g. Person1, or Compound terms (explained in later lectures). Predicate name Arguments

Terms: Constants Constants can either be: Numbers: integers are the usual form (e.g. 1, 0, -1, etc), but floating-point numbers can also be used (e.g. 3.0E7) Symbolic (non-numeric) constants: always start with a lower case alphabetic character and contain any mixture of letters, digits, and underscores (but no spaces, punctuation, or an initial capital). e.g. abc, big_long_constant, x4_3t). String constants: are anything between single quotes e.g. ‘Like this’.

Terms: Variables Variables always start with an upper case alphabetic character or an underscore. Other than the first character they can be made up of any mixture of letters, digits, and underscores. e.g. X, ABC, _89two5, _very_long_variable There are no “types” for variables (or constants) – a variable can take any value. All Prolog variables have a “local” scope: they only keep the same value within a clause; the same variable used outside of a clause does not inherit the value (this would be a “global” scope).

Arity The number of arguments a predicate has is called its arity. greetings is a predicate with no arguments. The number of arguments a predicate has is called its arity. The arity of greetings is zero = greetings/0 The behaviour of predicates can be made more specific by including more arguments. greetings(hamish) = greetings/1 The predicate can then behave differently depending on the arguments passed to it.

Structure of Programs Programs consist of procedures. Procedures consist of clauses. Each clause is a fact or a rule. Programs are executed by posing queries. An example…

Example Predicate Procedure for elephant Facts elephant(george). elephant(mary). elephant(X) :- grey(X), mammal(X), hasTrunk(X). Clauses Rule

Example ?- elephant(george). yes ?- elephant(jane). no Queries Replies

Clauses: Facts and Rules ‘if’ ‘provided that’ ‘turnstile’ Head :- Body. This is a rule. Head. This is a fact. Full stop at the end.

Body of a (rule) clause contains goals. Head Body likes(mary, X) :- human(X), honest(X). Goals

Interpretation of Clauses Clauses can be given a declarative reading or a procedural reading. Form of clause: H :- G1, G2, …, Gn. “That H is provable follows from goals G1, G2, …, Gn being provable.” Declarative reading: “To execute procedure H, the procedures called by goals G1, G2, …, Gn are executed first.” Procedural reading:

EXAMPLE (a) Representing a symmetric relation. (b) Implementing a strange ticket condition. berkshire surrey kent wiltshire hampshire sussex How to represent this relation? Note that borders are symmetric.

Contd... This relation represents one ‘direction’ of border: What about the other? (a) Say border(kent, sussex). border(sussex, kent). border(sussex, kent). border(sussex, surrey). border(surrey, kent). border(hampshire, sussex). border(hampshire, surrey). border(hampshire, berkshire). border(berkshire, surrey). border(wiltshire, hampshire). border(wiltshire, berkshire). (b) Say adjacent(X, Y) :- border(X, Y). adjacent(X, Y) :- border(Y, X). (c) Say border(X, Y) :- border(Y, X).

Contd... Now a somewhat strange type of discount ticket. For the ticket to be valid, one must pass through an intermediate county. A valid ticket between a start and end county obeys the following rule: valid(X, Y) :- adjacent(X, Z), adjacent(Z, Y)

Contd... valid(X, Y) :- adjacent(X, Z), adjacent(Z, Y) border(sussex, kent). border(sussex, surrey). border(surrey, kent). border(hampshire, sussex). border(hampshire, surrey). border(hampshire, berkshire). border(berkshire, surrey). border(wiltshire, hampshire). border(wiltshire, berkshire). adjacent(X, Y) :- border(X, Y). adjacent(X, Y) :- border(Y, X). valid(X, Y) :- adjacent(X, Z), adjacent(Z, Y) ?- valid(wiltshire, sussex). ?- valid(wiltshire, kent). ?- valid(hampshire, hampshire). ?- valid(X, kent). ?- valid(sussex, X). ?- valid(X, Y).

SIGNIGICANT FEATURES Intelligent systems : programs which perform useful tasks by using artificial intelligence techniques Expert systems : intelligent systems which reproduce decision-making at the level of human expert Natural language systems : which can analyze and respond to statements made in ordinary language as opposed to approved keywords or menu selections Relational database systems

Advantages and Disadvantages:- -Logic based languages are able to represent the real world more accurately. -Prolog is able to derive new rules from the existing rules contained within the knowledge base. DISADVANTAGES:- -It can be very difficult to design a database that accurately represents relationships. -Prolog is not best suited to solving complex arithmetical computations. -Prolog programs are not best suited to the current PC architecture (sequential execution) and are best optimised on parallel architectures (fifth generation computers).