Logic Programming and Prolog Danielle and Joseph Bennett 24 April 2007.

Slides:



Advertisements
Similar presentations
Some Prolog Prolog is a logic programming language
Advertisements

Chapter 11 :: Logic Languages
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
1. An Overview of Prolog.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
Logic Programming – Part 2 Lists Backtracking Optimization (via the cut operator) Meta-Circular Interpreters.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
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.
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).
Formal Logic Mathematical Structures for Computer Science Chapter 1 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic.
CS 330 Programming Languages 12 / 02 / 2008 Instructor: Michael Eckmann.
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
CS 330 Programming Languages 12 / 12 / 2006 Instructor: Michael Eckmann.
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.,
CPSC 322, Lecture 23Slide 1 Logic: TD as search, Datalog (variables) Computer Science cpsc322, Lecture 23 (Textbook Chpt 5.2 & some basic concepts from.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 27: Prolog’s Resolution and Programming Techniques COMP 144 Programming Language.
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
CPSC 322, Lecture 23Slide 1 Logic: TD as search, Datalog (variables) Computer Science cpsc322, Lecture 23 (Textbook Chpt 5.2 & some basic concepts from.
Inference and Resolution for Problem Solving
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
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.
P-Phunck - Prolog1 Introduction to Prolog Brian Paden.
PROLOG KAIST Gunwoo Park 1. What’s Prolog? 2  General purpose logic programming language  Declarative, which means that the program logic is.
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.
CS 403: Programming Languages Lecture 19 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
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.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
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:
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.
Section Predicates & Quantifiers. Open Statement 2 x > 8 p < q -5 x = y + 6 Neither true nor false.
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?
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
By: Cory Canter CSC 415 Programming Languages. History  Created by Alain Colmerauer, Phillipe Roussel and Robert Kowalski in 1971  Started as a natural.
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.
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:
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 21.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
Programming Languages Third Edition Chapter 4 Logic Programming.
CS 152: Programming Language Paradigms March 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
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.
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.
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.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
PROLOG “Programmation en Logique”
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
CS 326 Programming Languages, Concepts and Implementation
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:
Knowledge Representation and Inference
Programming Languages 2nd edition Tucker and Noonan
Prolog Concepts.
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

Logic Programming and Prolog Danielle and Joseph Bennett 24 April 2007

What is Logic Programming?

“The use of mathematical logic for computer programming.” (Wikipedia) “A declarative, relational style of programming based on first-order logic.” (Dictionary.com)

History of Logic Programming Came about in 1960s and 1970s due to debates about using declarative or procedural representations in AI Stanford and Edinburgh – declarative MIT - procedural Developed Planner in 1969 (first language in the proceduralistic paradigm).

Systems for Logic Programming ALF CLP ECLiPSe Elf Fish Flang Gödel KLIC LIFE MONA Oz System RELFUN SAMPLE XSB Just to name a few….

Systems for Logic Programming, cont. Prolog is the most common system Prolog has many variations: &-Prolog, And-parallel Prolog. ACE, And-Or-parallel Prolog. Actor Prolog Andorra-I, an Or- and (deterministic) and-parallel Prolog. Aurora, Or-parallel Prolog. cu-Prolog, a constraint logic programming language lambda Prolog LeanTaP, a small theorem prover written in SICStus Prolog. Logtalk, an extension for Object-Oriented Programming in Prolog. Mixtus, an automatic partial evaluator for full Prolog. Muse, Or-parallel Prolog.

All About Prolog

Developed in 1972 by Alain Colmerauer and Philippe Roussel Name comes from “PROgramming in LOGic” A solution to the debate about which kinds of logic to use

Prolog Structure Prolog facts – a database of predicates and associations. Prolog rules – define new predicates by using Prolog facts. Note: Prolog considers capital letters to denote variables, not predicates.

Prolog Structure – Queries A query searches the database for the first fact that satisfies its goal. If a fact is found it either unifies the variable with a constant or returns yes. If a fact is not found that meets that condition it returns no.

Prolog Structure – Queries, cont. Use a semi-colon to request subsequent answers. In other words, a semi-colon signifies disjunction. A comma signifies conjunction.

Prolog Structure - Unification A query resolves by unifying all of its elements. A constant unifies with itself and any variable. Scope is limited to the rule in which a variable occurs. When a variable is unified with a constant in a rule, all instances of that variable in that rule are unified to that constant.

Prolog Structure - Backtracking In more complex examples, Prolog uses backtracking to find possible solutions. Prolog will attempt to resolve the first fact of its rule, unifying any variables with the first constant that satisfies that fact It then attempts to resolve the rest of that rules facts. If it is unable to do so under those conditions it “backs up” and tries again with the next available unifying constant.

More Than Just Information Prolog rules can also be used write programs that do more than find the answers to simple database queries. append([], L, L). append([H|T], L, [H|L1]):-append(T, L, L1). This will append a list to another list recursively. A binary tree can be defined as follows tree(nil). tree(node(_, Left, Right):-tree(left), tree(right).

How Prolog Works Example from pages of our text: instructor (bebis, cs365) instructor (looney, cs311) instructor (yuksel, cs446) enrolled (joseph, cs311) enrolled (joseph, cs365) enrolled (joseph, cs446) enrolled (danielle, cs365) enrolled (danielle, cs446) This is the database of Prolog facts.

How Prolog Works, cont. Prolog rules: teaches (P,S) :- instructor (P,C), enrolled (S,C) This is to say that an instructor only teaches if he teaches a class and students are enrolled in that class.

How Prolog Works, cont. Prolog answers queries based off of the database that has been given. ?enrolled (joseph, cs365) yes ?enrolled (X, cs365) joseph danielle ?teaches (X, joseph) bebis looney yuksel

How Prolog Works, cont. Imagine what happens if we expand the database: instructor (bebis, cs365) instructor (looney, cs311) instructor (yuksel, cs446) instructor (helfand, cs493) instructor (quint, math486) enrolled (ben, cs365) enrolled (bill, cs365) enrolled (bill, cs446) enrolled (brian, cs311) enrolled (brian, cs365) enrolled (brittney, cs311) enrolled (brittney, cs365) enrolled (brittney, cs446) enrolled (cody, cs311) enrolled (cody, cs365) enrolled (danielle, cs365) enrolled (danielle, cs446) enrolled (danielle, cs493) enrolled (david, cs365) enrolled (javier, cs365) enrolled (jeffrey, cs365) enrolled (jessica, cs311) enrolled (jessica, cs446) enrolled (jessica, math486) enrolled (joel, cs365) enrolled (joseph, cs311) enrolled (joseph, cs365) enrolled (joseph, cs446) enrolled (joseph, cs493) enrolled (joseph, math486) enrolled (kellen, cs365) enrolled (matts, cs311) enrolled (matts, cs365) enrolled (mattw, cs311) enrolled (mattw, cs365) enrolled (mattw, cs446) enrolled (miran, cs365) enrolled (ryan, cs365) enrolled (samuel, cs365) enrolled (shane, cs311) enrolled (shane, cs365) enrolled (shane, cs446) enrolled (tiffany, cs311) enrolled (tiffany, cs365) enrolled (tiffany, cs446)

How Prolog Works, cont. ?enrolled (X, cs365) ben bill brian brittney cody danielle david javier jeffrey joel joseph kellen matts mattw miran ryan samuel shane tiffany This list now gives us the entire roster of students in CS 365.

How Prolog Works, cont. Queries can be more complicated to compare more data: classmates (S1, S2) :- enrolled (S1, C), enrolled (S2, C) ?classmates (joseph, danielle) yes ?classmates (joseph, jessica) yes ?classmates (jessica, danielle) no

How Prolog Works, cont. classmates (S1, S2, C) :- enrolled (S1, C), enrolled (S2, C) ?classmates (joseph, danielle, C) cs365 cs446 cs493 no ?classmates (joseph, jessica, C) math ?classmates (jessica, danielle, C) no

Free Prolog Access SWI-Prolog YAProlog Strawberry Prolog

Sources ming ming Pages of our textbook CS 326 lectures on Prolog (written by Dr. Mircea Nicolescu)