Copyright © 2003 Bolton Institute Logical Analysis and Problem Solving, (LAPS) Programming in Prolog.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

Recursion and the order of terms in a PROLOG clause.
AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 2
Structures. Procedural (Imperative) Languages Procedural languages work on the basis of explicitly telling the computer ‘how to do something’; by using.
Introduction to Recursion and Recursive Algorithms
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.
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).
Everyday Math Grade 4 – Lesson 3.12 Unit 3 Review Copyright © 2010 Kelly Mott.
Lesson Objective: I can…  Understand that a letter is an expression or an equation can represent a number. When that number is replaced with a letter,
Prolog programming Introduction to Prolog
Chapter 12 - Logic Programming
MB: 2 March 2001CS360 Lecture 31 Programming in Logic: Prolog Prolog’s Declarative & Procedural Semantics Readings: Sections
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.,
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
Ch 2.2 Objective: To solve problems involving absolute value of numbers or variables.
Everyday Math Grade 4 – Lesson 3.10 Open Sentences Copyright © 2010 Kelly Mott.
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
Everyday Math Grade 4 – Lesson 3.12 Unit 3 Review Copyright © 2010 Kelly Mott.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
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 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 14.
CIS2326 Week2: Logic and Prolog Lee McCluskey First term:
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
ITEC 380 Organization of programming languages Lecture 8 – Prolog.
COMP 170 L2 Part 3 of Course Chapter 3 of Textbook.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
CS 403: Programming Languages Lecture 18 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Everyday Math Grade 4 – Lesson 3.4 Copyright © 2011 Kelly Mott.
Logic Programming. Formal Logics- Recap Formulas – w/out quantifiers Free Variables Bound Variables Assignments and satisfaction Validity and satisfiability.
Logic Programming Tarik Booker. What will we cover?  Introduction  Definitions  Predicate Calculus  Prolog  Applications.
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.
Everyday Math Grade 4 – Lesson 3.10 Open Sentences Copyright © 2010 Kelly Mott.
Everyday Math Grade 4 – Lesson 3.12 Unit 3 Review Copyright © 2010 Kelly Mott.
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.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Everyday Math Grade 4 – Lesson 3.10 Open Sentences Copyright © 2010 Kelly Mott.
Recursive stack-based version of Back-chaining using Propositional Logic
Welcome to Computer Science Jeopardy
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Prolog programming Introduction to Prolog
3.5 Programming paradigms
Prolog Primarily for Symbolic (nonnumeric) Computation
Computer Programming.
Chapter 11 :: Logic Languages
Loop Control Structure.
Learning to Program in Python
1) C program development 2) Selection structure
Take Quiz!!! Good luck.
Prolog programming Introduction to Prolog (part3)
Chapter 12 :: Logic Languages
Chapter 12 :: Logic Languages
Programming Languages 2nd edition Tucker and Noonan
Chapter 12 :: Logic Languages
Presentation transcript:

Copyright © 2003 Bolton Institute Logical Analysis and Problem Solving, (LAPS) Programming in Prolog

Copyright © 2003 Bolton Institute Recap Prolog –Relations can be created between objects. –Specific objects must be in lower-case. –Variables in upper-case. –Queries can be written to interrogate data. –Multiple output can be achieved with OR symbol. –Multiple statements can be connected using the AND connective. –Rules can be defined in Prolog to ease use and development.

Copyright © 2003 Bolton Institute Example The following facts are provided: –Mary works hard, Adi works hard and Jack doesn’t work hard. Mary attends all lessons, Adi attends some lessons and Jack hardly attends. –The following rules are given: –IF a student works hard and attends all lessons THEN the student will pass well. –IF a student works hard and attends some lessons THEN the student will pass –IF a student doesn’t work hard OR a student hardly attends lessons THEN student will fail Write Prolog statements representing the above information. What will happen to Mary, Adi and Joe?

Copyright © 2003 Bolton Institute Recursion Sometimes when relations are defined for objects, there is an indirect relationship between the objects. For example, within a family tree, a person is an ancestor of another person if they are their parent, or grandparent, great grandparent etc. What if we wanted to know whether a person was an ancestor - without knowing the precise relationship, such as grandparent or great grandparent? How could we find this in Prolog? We use recursion.

Copyright © 2003 Bolton Institute Grandparent Rule A Grandparent rule for a family tree could be defined as: /* Rule that defines grandparent relation */ grandparent(Grandparent,Grandchild) :- parent(Grandparent,Parent), parent(Parent,Grandchild). Note: how a grandparent is the parent of the grandchild’s parent!

Copyright © 2003 Bolton Institute Ancestor rule We can state an ancestor rule, as a specific rule and a general rule, as outlined below. ancestor(Ancestor, Descendant) :- parent(Ancestor,Descendant). ancestor(Ancestor, Descendant) :- parent(Ancestor,Parent), ancestor(Parent, Descendant). The first rule is true when the Ancestor variable is the parent of the Descendant. If the first rule is NOT true, the second rule is executed! The second rule finds who the Ancestor is the parent of and then requests that the ancestor rule is tried again - the first rule will be attempted again! See example on board.

Copyright © 2003 Bolton Institute Backtracking Prolog works through rules until a false relation is found. If a false relation is found, Prolog backtracks and tries another fact or rule, until, all relevant facts / rules have been attempted. Backtracking is one of the most powerful aspects of Prolog. Other programming languages require the developer to write code that does backtracking!

Copyright © 2003 Bolton Institute Exercises How could you query whether Jan is an ancestor of Lucy? How could you show all the ancestors of Jack? How could you show all the descendants of Jim? Create Prolog queries for the above questions using the ancestor rules previously defined.

Copyright © 2003 Bolton Institute Recap Review notes and worksheets.