Prolog Overview Syntax Mechanism Summary. Overview PROLOG : Programming with Logic Uses predicate (first-order) calculus History: Roots: J.A. Robinson.

Slides:



Advertisements
Similar presentations
Artificial Intelligence 8. The Resolution Method
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Standard Logical Equivalences
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
Artificial Intelligence
First Order Logic Resolution
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
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).
Logic.
Chapter 12 - Logic Programming
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
AI - Programming Prolog Lisp AI - Programming Support for Symbolic Computational Exploratory Programming.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Outline Recap Knowledge Representation I Textbook: Chapters 6, 7, 9 and 10.
Programming Languages Third Edition
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Logic Programming Languages. Objective To introduce the concepts of logic programming and logic programming languages To introduce a brief description.
Inference and Resolution for Problem Solving
Artificial Intelligence
Formal Aspects of Computer Science – Week 12 RECAP Lee McCluskey, room 2/07
P-Phunck - Prolog1 Introduction to Prolog Brian Paden.
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.
Lists – More Examples  ‘Translate’ a list to another list  Counting  Split a given list into two  Merge two lists into one  Output a list (some I/O.
1 Chapter 8 Inference and Resolution for Problem Solving.
Chapter 16 Logic Programming Languages. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 16 Topics Introduction A Brief Introduction to.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
ARTIFICIAL INTELLIGENCE Lecture 3 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.
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
First-Order Logic Introduction Syntax and Semantics Using First-Order Logic Summary.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
Predicate Calculus Syntax Countable set of predicate symbols, each with specified arity  0. For example: clinical data with multiple tables of patient.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
Logic Programming Prolog Program = sequence of FOPC sentences All sentences are Horn clauses p1  p2  …  pn  q All variables are universally quantified.
Lecture 9b: Prolog Heshaam Faili University of Tehran The language of logic Concepts Examples.
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
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.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
CS 4100 Artificial Intelligence Prof. C. Hafner Class Notes Jan 24, 2012.
For Monday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
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.
C. Varela1 Logic Programming (PLP 11) Predicate Calculus, Horn Clauses, Clocksin-Mellish Procedure Carlos Varela Rennselaer Polytechnic Institute November.
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Programming Languages Third Edition Chapter 4 Logic Programming.
Principles of programming languages 12: Logic programming Isao Sasano Department of Information Science and Engineering.
Logic Programming (LP) expresses code using of a restricted form of symbolic logic. LP programs are declarative, rather than algorithmic. An LP program.
KU NLP Artificial Intelligence1 Ch 14. An Introduction to Prolog q an Implementation of logic as a programming language(PROgramming in LOGig) q many interesting.
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
1-1 An Introduction to Logical Programming Sept
PREDICATE CALCULS In Propositional Calculus, each atomic symbol denotes a proposition. But there is no way to access the components of an individual assertion.
For Friday No reading Prolog Handout 2. Homework.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
For Wednesday No reading Prolog handout 2 Chapter 9, exercise 4.
Answer Extraction To use resolution to answer questions, for example a query of the form  X C(X), we must keep track of the substitutions made during.
Copyright 1999Paul F. Reynolds, Jr. Foundations of Logic Programming.
Section 16.5, 16.6 plus other references
CS621: Artificial Intelligence
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
PROLOG.
Carlos Varela Rensselaer Polytechnic Institute November 10, 2017
Chapter 2: Prolog (Introduction and Basic Concepts)
Presentation transcript:

Prolog Overview Syntax Mechanism Summary

Overview PROLOG : Programming with Logic Uses predicate (first-order) calculus History: Roots: J.A. Robinson (1965) created algorithms for resolution refutation.

Resolution P V Q ~P V A Q V A star(A75) V galaxy(andromeda) ~star(X) V bright(X) galaxy(andromeda) V bright(A75) Θ = {X/A75}

History First Prolog Program written in France early 1970s as part of a project in natural language understanding. Theoretical background defined by Kowalski, Hayes, and others. Major development of the language done from at the dept. of artificial intelligence of the University of Edinburgh.

Applications Automatic code generation Program verification Design of high-level specification languages Example: Mathematica

Examples “Everyone likes Susie” likes(X,susie) “George likes Kate and George likes Susie” likes(george,kate), likes(george,susie) “George likes Kate or George likes Susie” likes(george,kate) ; likes(george,susie) “George likes Susie if George does not like Kate” likes(george,susie) :- not(likes(george,kate))

Prolog Overview Syntax Mechanism Summary

Syntax There are many dialects of Prolog. We will use C-Prolog (Clocksin and Mellish 1984) Prolog uses Predicate Calculus as its language. EnglishPredicate C.Prolog And^, OrV; Only if  :- Not~not

Prolog Overview Syntax Mechanism Summary

Prolog’s Mechanism A Prolog program is a set of specifications in predicate calculus. The specification is known as the database of the system. Prolog is an interactive language (the user enters queries in response to a prompt).

Example 1 likes(george,kate). likes(george,susie). likes(george,wine). likes(susie,wine). likes(kate,gin). likes(kate,susie). ?- likes(george,kate) yes ?- likes(george,beer) no

Example 2 likes(george,kate). likes(george,susie). likes(george,wine). ?- likes(george,X) X = kate ; X = susie ; X = wine ; no

Points to Consider Successive user prompts ; cause the interpreter to return all terms that can be substituted for X. They are returned in the order found. **ORDER IS IMPORTANT ** PROLOG adopts the closed-world assumption: All knowledge of the world is present in the database. If a term is not in the database, assume it is false.

Defining Rules To define a rule use logical implication :- Example: friends(X,Y) :- likes(X,Z), likes(Y,Z). Only one predicate is allowed on the left of the implication The predicate on the left cannot be negated This is Horn Clause Logic

Example Rule likes(george,kate). likes(george,susie). likes(george,wine). likes(susie,wine). likes(kate,gin). likes(kate,susie). friends(X,Y) :- likes(X,Z), likes(Y,Z). ?- friends(george,susie) yes

Quantifiers When a variable appears in the specification of a database, the variable is universally quantified. Example: likes(susie,Y) “Susie likes everyone” For the existentially quantifier one may do two things: a.Enter the value directly into the database likes(george,Z) becomes likes(george,wine) b. Query the interpreter ?- likes(george,Z) returns a value for Z if one exists.

Recursion in Prolog Recursion is the primary control structure in Prolog. Let’s look at an example with lists: Elements in lists are enclosed by brackets: [1,2,3,4] [[george,kate],[allen,amy],[don,pat]] []

lists The first element of a list can be separated from the tail using operator | Example: Match the list [tom,dick,harry,fred] to [X|Y] then X = tom and Y = [dick,harry,fred] [X,Y|Z] then X = tom, Y = dick, and Z = [harry,fred] [V,W,X,Y,Z|U] will not match [tom,X|[harry,fred]] gives X = dick

List membership We want to write a function member that works as follows: ?- member(a,[a,b,c,d,e]) yes ?- member(a,[1,2,3,4]) no ?- member(X,[a,b,c]) X = a ; X = b ; X = c; no

Function membership Define two predicates: member(X,[X|T]). member(X,[Y|T]) :- member(X,T). Trace the following call ?- member(c,[a,b,c]) yes

Function membership A more elegant definition uses anonymous variables: member(X,[X,_]). member(X,[_|T]) :- member(X,T). The symbol _ indicates that the contents of that variable is unimportant.

Function write list writelist([]). writelist([H|T]) :- write(H), nl, writelist(T). A reverse write of a list is as follows: reverse_writelist([]). reverse_writelist([H|T]) :- reverse_writelist(T), write(H), nl.

Other functions ?- assertz(likes(david,sarah)) Adds this predicate to the database. To remove a predicate p use ?- retract(p)

Other functions To download a database of sentences: ?- consult(myfile) yes Or ?- [myfile] To read and write from console: ?- read(X) ?- write(X)

Prolog Overview Syntax Mechanism Summary

There are many dialects of Prolog; we will use C-Prolog (Clocksin and Mellish 1984). Prolog uses Predicate Calculus as its language. A Prolog program is a set of specifications in predicate calculus. The specification is known as the database of the system. Prolog is an interactive language (the user enters queries in response to a prompt). Recursion is the primary control structure in Prolog. PROLOG adopts the closed-world assumption: All knowledge of the world is present in the database. If a term is not in the database assume it is false.