Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 2
First Order Logic Logic is a mathematical attempt to formalize the way we think. First-order predicate calculus was created in an attempt to mechanize.
Some Prolog Prolog is a logic programming language
Getting started with Prolog
Logic Programming Lecture 1: Course orientation; Getting started with Prolog.
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
Chapter 11 :: Logic Languages
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
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
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).
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Comp 205: Comparative Programming Languages Declarative Programming Languages Logic Programming Horn-Clause Logic Prolog Lecture notes, exercises, etc.,
Outline Recap Knowledge Representation I Textbook: Chapters 6, 7, 9 and 10.
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
CSE (c) S. Tanimoto, 2005 Logic Programming 1 Logic Programming Outline: Motivation Examples: The Grandmother relation Formulation in Prolog Logic,
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
Prolog Programming Lecture Module 13. Objective ● What is Prolog? ● Prolog program ● Syntax of Prolog ● Prolog Control Strategy ● Execution of Prolog.
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.
COP4020 Programming Languages Logical programming with Prolog Prof. Xin Yuan.
CS 403: Programming Languages Lecture 19 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
Cs7120 (Prasad)L16-Meaning1 Procedural and Declarative Meaning of Prolog
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.
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.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
1 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 14.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
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 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/
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
1-1 An Introduction to Logical Programming Sept
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
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.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Prolog Overview Syntax Mechanism Summary. Overview PROLOG : Programming with Logic Uses predicate (first-order) calculus History: Roots: J.A. Robinson.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Logic Programming Lecture 8: Term manipulation & Meta-programming.
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.
Section 16.5, 16.6 plus other references
CSE (c) S. Tanimoto, 2001 Logic Programming
Recursive stack-based version of Back-chaining using Propositional Logic
CSE 341, S. Tanimoto Logic Programming -
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Horn Clauses and Unification
CSE (c) S. Tanimoto, 2004 Logic Programming
CSE (c) S. Tanimoto, 2002 Logic Programming
Programming Languages 2nd edition Tucker and Noonan
Chapter 2: Prolog (Introduction and Basic Concepts)
Presentation transcript:

Prolog The language of logic

History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed early version of Prolog for natural language processing, mainly multiple parses. Warren: mid 70’s First version of Prolog that was efficient.

Characteristics Prolog approximates first-order logic. Every program is a set of Horn clauses. Inference is by resolution. Search is by backtracking with unification. Basic data structure is term or tree. Variables are unknowns not locations. Prolog does not distinguish between inputs and outputs. It solves relations/predicates.

SWI-Prolog Notes Free! Down Loadable To load a file: – consult( ‘C:\\kibler\\prolog\\test’). For help: –help(predicate-name). “ ; “ will give you next solution. listing(member) will give definition.

Example Facts: () –likes(john,mary). –likes(john,X). % Variables begin with capital Queries –?- likes(X,Y). – X=john, y=Mary. % hit “;” for more –?- likes(X,X). –X=john.

Example Rules –likes(john,X) :- likes(X,wine). % :- = if –likes(john,X):- female(X), likes(X,john). Note: variables are dummy. Standarized apart Some Facts: –likes(bill,wine). female(mary). female(sue). Query: ? - likes(john,Y). –Y = bill ; –no.

Family father(a,b). father(e,d). mother(c,b). mother(d,f). parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y). grandfather(X,Y):- father(X,Z),parent(Z,Y). % Do your own for practice.

Informal Summary Program is facts + rules. (horn clauses). Query = conjunct of predicates. First set of bindings for variables that solve query are reported. If none, then Prolog returns no. Use “;” to get other solutions. Can be viewed as constraint satisfaction program.

MapColoring color(r). color(g). color(b). colormap(C1,C2,C3):- color(C1),color(C2),color(C3), C1\==C2, C1\==C3, C2\==C3. Query: colormap(X,Y,Z). –X = r, Y= g, Z=b. Is that it. Yes! Turn on trace.

Unification: (matching) terms Two terms UNIFY if there is a common substitution for all variables which makes them identical. f(g(X),Y) = f(Z,Z). % = cheap unification –X = _G225, Y=g(_G225). Look at parse tree for each term. –variables match –variable matches anything (set the binding) –function symbols only match identical function symbols.

Satisfiability: uses unification sat(true). % base case sat(not(false)). % base case sat(or(X,Y)):- sat(X). sat(or(X,Y)):-sat(Y). sat(and(X,Y)):-sat(X),sat(Y). test1(X,Y):- sat(and(not(X),X)). test2(X,Y):- sat(and(X,not(Y))).

List Operator [H |T] [a,b,c] is a list in Prolog. [H|T] = [a,b,c] results in –H = a i.e. the head of list –T = [b,c] i.e. the tail of the list. membership definition –member(H,[H|T]). % base case first. Why? –member(H,[_|T]):- member(H,T). –Use it.

Member Tests ?- member(3,X). –X = [3| _G109]. % _G.., system generated variable – X= [_G11,3| _]. % etc. ?- member(X,Y). –X = _G131, Y= [_G131|, _G321].

Permutation & Insert insert(X,L, [X|L]). insert(X,[H|T],[H|T1]):- insert(X,T,T1). perm([],[]). perm([H|T],P):-perm(T,T1),insert(H,T1,P).

DFS % solve(goal, solution Path) % s(state, successor-state) dfs(N,[N]) :- goal(N). dfs(N,[N|Sol1]):- s(N,N1), dfs(N1,Sol1). s(a,b). s(a,c). s(b,d). s(b,e). s(c,f). s(c,g). s(d,h). s(e,i). s(e,j). s(f,k). goal(i). goal(f). ?- dfs(a,N). N = [a, b, e, i] ; N = [a, c, f] ;

Limitations 2 nd order: Can’t ask what is relationship between heart and lungs? Probabilities: What is likelihood of fire destroying Julian?