Prolog (cont d) Remark. Using multiple clauses. Intelligent Systems and HCI D7023E

Size: px
Start display at page:

Download "Prolog (cont d) Remark. Using multiple clauses. Intelligent Systems and HCI D7023E"

Transcription

1 Intelligent Systems and HCI D703E Lecture : More Prolog Paweł Pietrzak Prolog (cont d) 1 Remark The recent version of SWI- Prolog displays true and false rather than and no Using multiple clauses Different clauses can be used to deal with different arguments.! greet(hamish):-!! write( How are you doin, pal? ).! greet(amelia):-!! write( Awfully nice to see you! ).! = Greet Hamish or Amelia = a disjunction of goals. -!?- greet(hamish).!?- greet(amelia). -! How are you doin, pal?! Awfully nice to see you! -!!!!! Clauses are tried in order from the top of the file. The first clause to match succeeds (= )

2 Variables in Questions We can call greet/1 with a variable in the question. A variable will match any head of greet/1.?- greet(anybody). How are you doin, pal? Anybody = hamish? The question first matches the clause closest to the top of the file. The variable is instantiated (i.e. bound) to the value hamish. As the variable was in the question it is passed back to the terminal (Anybody = hamish?). Re-trying Goals When a question is asked with a variable as an argument (e.g. greet(anybody).) we can ask the Prolog interpreter for multiple answers using: ;?- greet(anybody). How are you doin, pal? Anybody = hamish? ; Redo that match. Awfully nice to see you! Anybody = amelia? ; Redo that match. no Fail as no more matches. This fails the last clause used and searches down the program for another that matches. - RETURN = accept the match - ; = reject that match 6 Unification When two terms match we say that they unify. - Their structures and arguments are compatible. This can be checked using =/!?- loves(john,x) = loves(y,mary).! X = mary,! unification leads to instantiation! Y = john?!! Asking questions of the database We can ask about facts directly:?- mother(x,alan). X = jane? Yes Or we can define rules that prove if a property or relationship holds given the facts currently in the database. mother(jane,alan). father(john,alan). parent(mum,child):- mother(mum,child). parent(dad,child):- father(dad,child).?- parent(jane,x). X = alan? 7

3 Arithmetic Operators () Arithmetic Operators: +, -, *, / = Infix operators but can also be used as prefix. - Need to use is/ to access result of the arithmetic expression otherwise it is treated as a term:!!?- X = +4.!!?- X is +4.!!! X = +4?!! X = 9?!!!!! (Can X unify with +4?) (What is the result of +4?) Mathematical precedence is preserved: /, *, before +,- Can make compound sums using round brackets - Impose new precedence - Inner-most brackets first Satisfying Subgoals Most rules contain calls to other predicates in their body. These are known as Subgoals. These subgoals can match: - facts, - other rules, or - the same rule = a recursive call 1) drinks(alan,beer). ) likes(alan,coffee). 3) likes(heather,coffee). 4) likes(person,drink):-! drinks(person,drink). % a different subgoal ) likes(person,somebody):-! likes(person,drink), % recursive subgoals! likes(somebody,drink) Representing Proof using Trees To help us understand Prolog s proof strategy we can represent its behaviour using AND/OR trees. 1. Query is the top-most point (node) of the tree.. Tree grows downwards (looks more like roots!). Representing Proof using Trees () Using the tree we can see what happens when we ask for another match ( ; ) X/coffee 4 Backtracking 3. Each branch denotes a subgoal. 1. The branch is labelled with the number of the matching clause and. any variables instantiated when matching the clause head. 1 st match is failed and forgotten drinks(alan,x). 4. Each branch ends with either: 1. A successful match,. A failed match, or 3. Another subgoal. 11 X/coffee 1 st solution = Alan likes coffee. nd solution = Alan likes beer because Alan drinks beer. 1

4 Recursion using Trees When a predicate calls itself within its body we say the clause is recursing X/coffee 4 drinks(alan,x). likes(alan,drink) Drink/coffee Conjoined subgoals X/Somebody likes(somebody,drink) Drink = coffee Recursion using Trees () When a predicate calls itself within its body we say the clause is recursing X/coffee 4 drinks(alan,x). likes(alan,coffee) Drink/coffee X/Somebody likes(somebody,coffee) Drink = coffee Somebody /alan Somebody = alan 3 rd solution = Alan likes Alan because Alan likes coffee Recursion using Trees (3) When a predicate calls itself within its body we say the clause is recursing A question X/coffee 4 drinks(alan,x). likes(alan,coffee) likes(somebody,coffee) Drink/coffee Somebody/alan 3 Somebody/heather What is going to happen if we post a query?- likes(smb, coffee) 4 th solution = Alan likes Heather because Heather likes coffee. 1 Somebody = alan Somebody = heather 16

5 Prolog Data Objects (Terms) Atoms Constants Simple objects Integers Symbols a Strings bob l8r_day a Bob L8r day Signs <---> ==> Structured Objects Variables Structures Lists X A_var _Var date(4,10,04) [] person(bob,48) [a,b,g] [[a],[b]] [bit(a,d),a, Bob ] Structures To create a single data element from a collection of related terms we use a structure. A structure is constructed from a functor (a constant symbol) and one of more components. components functor somerelationship(a,b,c,[1,,3]) The components can be of any type: atoms, integers, variables, or structures. As functors are treated as data objects just like constants they can be unified with variables?- X = date(04,10,04). X = date(04,10,04)? Structure unification structures will unify if - the functors are the same, - they have the same number of components, - and all the components unify.?- person(nm,london,age) = person(bob,london,48). Nm = bob, Age = 48? More unification Terms that don t unify fred = jim. Hey you = Hey me. frou(frou) = f(frou). foo(bar) = foo(bar,bar). foo(n,n) = foo(bar,rab).?- person(someone,_,4) = person(harry,dundee,4). Someone = harry? (A plain underscore _ is not bound to any value. By using it you are telling Prolog to ignore this argument and not report it.) 19 0

6 More unification Terms that unify!! Outcome fred = fred.!!. Hey you = Hey you.!. fred=x.!!! X=fred. X=Y.!!! Y = X. foo(x) = foo(bar).!! X=bar. foo(n,n) = foo(bar,x). N=bar, X=bar. foo(foo(bar)) = foo(x) X = foo(bar) Structures = facts? The syntax of structures and facts is identical but: - Structures are not facts as they are not stored in the database as being true (followed by a period. ); - Structures are generally just used to group data; - Functors do not have to match predicate names. 1 A collection of ordered data. Lists Has zero or more elements enclosed by square brackets ( [ ] ) and separated by commas (, ). [a]!!! a list with one element []! an empty list [34,tom,[,3]]!! a list with 3 elements where the!!! 3 rd element is a list of elements. Like any object, a list can be unified with a variable?- [Any, list, of elements ] = X. X = [Any, list, of elements ]? List Unification Two lists unify if they are the same length and all their elements unify.?-[a,b,c,d]=[a,b,c,d]. A = a,!!! W = a, B = b,!!! X = c, C = c,!!! Y = d? D = d?!!?-[(a+x),(y+b)]=[(w+c),(d+b)].?- [[X,a]]=[b,Y].!?-[[a],[B,c],[]]=[X,[b,c],Y]. no!!!! B = b, Length 1 Length X = [a], Y = []? 3 4

7 Definition of a List Lists are recursively defined structures. An empty list, [], is a list. A structure of the form [X, ] is a list if X is a term and [ ] is a list, possibly empty. This recursiveness is made explicit by the bar notation [Head Tail] Head must unify with a single term. Tail unifies with a list of any length, including an empty list, []. - the bar notation turns everything after the Head into a list and unifies it with Tail. Head and Tail!?-[a,b,c,d]=[Head Tail].?-[a,b,c,d]=[X [Y Z]].! Head = a,!!! X = a,! Tail = [b,c,d]?!! Y = b,!!!!! Z = [c,d];!!!!!!!!!?-[a] = [H T].!!?-[a,b,c]=[W [X [Y Z]]].! H = a,!!! W = a,! T = [];!!! X = b,!!!!! Y = c, Z = []?!?-[] = [H T].!!?-[a [b [c []]]]= List.! no!!!! List = [a,b,c]?!!!!! 6

Recursion, Structures, and Lists

Recursion, Structures, and Lists Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 4 04/10/04 30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists 1 The central ideas of Prolog

More information

Tests, Backtracking, and Recursion

Tests, Backtracking, and Recursion Tests, Backtracking, and Recursion Artificial Intelligence Programming in Prolog Lecture 3 30/09/04 30/09/04 AIPP Lecture 3: Rules, Results, and Backtracking 1 Re-cap A Prolog program consists of predicate

More information

PROgramming in LOGic. Part II. By Forrest Pepper 12/7/07

PROgramming in LOGic. Part II. By Forrest Pepper 12/7/07 PROgramming in LOGic Part II By Forrest Pepper 12/7/07 Anatomy of a Program We discussed the three main constructs of a Prolog program Facts contain a property or state a relationship between two or more

More information

Reviews. Arithmetic Operators (2)

Reviews. Arithmetic Operators (2) Introduction to Prolog Useful references: Clocksin, W.F. and Mellish, C.S., Programming in Prolog: Using the ISO Standard (5th edition), 2003. Bratko, I., Prolog Programming for Artificial Intelligence

More information

Reviews. Introduction to Prolog. Arithmetic Operators. Tests. Arithmetic Operators (2) Unify with occurs check. References:

Reviews. Introduction to Prolog. Arithmetic Operators. Tests. Arithmetic Operators (2) Unify with occurs check. References: Introduction to Prolog References: http://www.gprolog.org/manual/gprolog.html Bratko, I., Prolog Programming for Artificial Intelligence (3rd edition), 2001. Sterling, L. and Shapiro, E., The Art of Prolog

More information

Lecture 9: A closer look at terms

Lecture 9: A closer look at terms Lecture 9: A closer look at terms Theory Introduce the == predicate Take a closer look at term structure Introduce strings in Prolog Introduce operators Exercises Exercises of LPN: 9.1, 9.2, 9.3, 9.4,

More information

Prolog. Intro to Logic Programming

Prolog. Intro to Logic Programming Prolog Logic programming (declarative) Goals and subgoals Prolog Syntax Database example rule order, subgoal order, argument invertibility, backtracking model of execution, negation by failure, variables

More information

Operators (2A) Young Won Lim 10/2/13

Operators (2A) Young Won Lim 10/2/13 Operators (2A) Copyright (c) 2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Derived from PROgramming in LOGic (1972) Prolog and LISP - two most popular AI languages. Prolog programs based on predicate logic using Horn clauses

Derived from PROgramming in LOGic (1972) Prolog and LISP - two most popular AI languages. Prolog programs based on predicate logic using Horn clauses Prolog Programming Derived from PROgramming in LOGic (1972) Good at expressing logical relationships between concepts Prolog and LISP - two most popular AI languages Execution of a Prolog program is a

More information

Part I Logic programming paradigm

Part I Logic programming paradigm Part I Logic programming paradigm 1 Logic programming and pure Prolog 1.1 Introduction 3 1.2 Syntax 4 1.3 The meaning of a program 7 1.4 Computing with equations 9 1.5 Prolog: the first steps 15 1.6 Two

More information

Operators (2A) Young Won Lim 10/5/13

Operators (2A) Young Won Lim 10/5/13 Operators (2A) Copyright (c) 2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

Prolog Programming. Lecture Module 8

Prolog Programming. Lecture Module 8 Prolog Programming Lecture Module 8 Prolog Language Prolog is unique in its ability to infer facts from the given facts and rules. In Prolog, an order of clauses in the program and goals in the body of

More information

Lecture 11: Feb. 10, 2016

Lecture 11: Feb. 10, 2016 CS323: AI (Hands on with Prolog) Spring 2016 Lecturer: K.R. Chowdhary Lecture 11: Feb. 10, 2016 : Professor of CS (VF) Disclaimer: These notes have not been subjected to the usual scrutiny reserved for

More information

Prolog. IFT 6802 Introduction to Prolog. Declarative programming LOGIC PROGRAMMING BASICS. LOGIC PROGRAMMING BASICS (suite) Facts

Prolog. IFT 6802 Introduction to Prolog. Declarative programming LOGIC PROGRAMMING BASICS. LOGIC PROGRAMMING BASICS (suite) Facts Prolog IFT 6802 Introduction to Prolog Par Jean Vaucher (& Laurent Magnin) A programming language based on the formalism and the concepts of formal logic. PROgrammation LOGique Robinson (resolution) Kowalski

More information

Fundamentals of Prolog

Fundamentals of Prolog Fundamentals of Prolog Prof. Geraint A. Wiggins Centre for Cognition, Computation and Culture Goldsmiths College, University of London Contents Summary of Lecture 1 What makes a good Prolog program? What

More information

Logic Languages. Hwansoo Han

Logic Languages. Hwansoo Han Logic Languages Hwansoo Han Logic Programming Based on first-order predicate calculus Operators Conjunction, disjunction, negation, implication Universal and existential quantifiers E A x for all x...

More information

Lecture 9. Exercises. Theory. Solutions to exercises LPN 8.1 & 8.2. Patrick Blackburn, Johan Bos & Kristina Striegnitz

Lecture 9. Exercises. Theory. Solutions to exercises LPN 8.1 & 8.2. Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9 Exercises Solutions to exercises LPN 8.1 & 8.2 Theory Solution to Exercise 8.1 Suppose we add the noun ``men'' (which is plural) and the verb ``shoot''. Then we would want a DCG which says that

More information

Prolog-2 nd Lecture. Prolog Predicate - Box Model

Prolog-2 nd Lecture. Prolog Predicate - Box Model Prolog-2 nd Lecture Tracing in Prolog Procedural interpretation of execution Box model of Prolog predicate rule How to follow a Prolog trace? Trees in Prolog use nested terms Unification Informally Formal

More information

Prolog. Logic Programming vs Prolog

Prolog. Logic Programming vs Prolog Language constructs Prolog Facts, rules, queries through examples Horn clauses Goal-oriented semantics Procedural semantics How computation is performed? Comparison to logic programming 1 Logic Programming

More information

PROgramming in LOGic PROLOG Recursion, Lists & Predicates

PROgramming in LOGic PROLOG Recursion, Lists & Predicates PROgramming in LOGic PROLOG Recursion, Lists & Predicates CSC9Y4 1 Recursion Recursion in Prolog means placing in the body of a rule a call to the predicate which occurs in the head of the rule. Here is

More information

The object level in Prolog. Meta-level predicates and operators. Contents. The flow of computation. The meta level in Prolog

The object level in Prolog. Meta-level predicates and operators. Contents. The flow of computation. The meta level in Prolog Lecture 8 Meta-level predicates and operators Contents Object level vs. meta level Controlling flow of computation Checking and dismantling expressions Comparison operators The object level in Prolog Prolog

More information

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy Topics Chapter 16 Logic Programming Summary (resolution, unification, Prolog search strategy ) Disjoint goals The cut operator Negative goals Predicate fail Debugger / tracer Lists 2 Resolution Resolution

More information

COMP 9416, session 1, 2006 p. 1. Datalog. COMP 9416, session 1, 2006

COMP 9416, session 1, 2006 p. 1. Datalog. COMP 9416, session 1, 2006 OMP 9416, session 1, 2006 p. 1 Datalog OMP 9416, session 1, 2006 OMP 9416, session 1, 2006 p. 2 Atoms, integers and variables The fact "person(socrates).", the fact "sum(2,3,y)." and the rule "mortal(x)

More information

Topic B: Backtracking and Lists

Topic B: Backtracking and Lists Topic B: Backtracking and Lists 1 Recommended Exercises and Readings From Programming in Prolog (5 th Ed.) Readings: Chapter 3 2 Searching for the Answer In order for a Prolog program to report the correct

More information

Logic Programming. Let us have airline flight information of the form: 1. Application Domains: 2. Definitions

Logic Programming. Let us have airline flight information of the form: 1. Application Domains: 2. Definitions Logic Programming 1. Application Domains: Logic programming language application areas include natural language processing, expert systems, specifications checking, theorem proving, and control systems

More information

Brief Introduction to Prolog

Brief Introduction to Prolog CSC384: Intro to Artificial Intelligence Brief Introduction to Prolog Prolog Programming for Artificial Intelligence by Ivan Bratko. Prolog is a language that is useful for doing symbolic and logic based

More information

Operational Semantics

Operational Semantics 15-819K: Logic Programming Lecture 4 Operational Semantics Frank Pfenning September 7, 2006 In this lecture we begin in the quest to formally capture the operational semantics in order to prove properties

More information

PROLOG. First simple Prolog Program. Basic elements of Prolog. Clause. NSSICT/CH/Nov., 2012.

PROLOG. First simple Prolog Program. Basic elements of Prolog. Clause. NSSICT/CH/Nov., 2012. PROLOG Prolog is a programming language for symbolic, n-numeric computations. It is specially well suited for solving problems that involve objects and relation between objects. First simple Prolog Program

More information

Introduction to Prolog

Introduction to Prolog Introduction to Prolog York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 03_Prolog 1 Overview Introduction & Preliminaries Syntax Characters Constants

More information

Introduction to predicate calculus

Introduction to predicate calculus Logic Programming Languages Logic programming systems allow the programmer to state a collection of axioms from which theorems can be proven. Express programs in a form of symbolic logic Use a logical

More information

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation Topics Chapter 16 Logic Programming Proving Theorems Resolution Instantiation and Unification Prolog Terms Clauses Inference Process Backtracking 2 Predicate Calculus and Proving Theorems A use of propositions

More information

Prolog Introduction. Gunnar Gotshalks PI-1

Prolog Introduction. Gunnar Gotshalks PI-1 Prolog Introduction PI-1 Physical Symbol System Hypothesis A physical symbol system has the necessary and sufficient means for general intelligent action. Allen Newell and Herbert A. Simon PI-2 Physical

More information

Lecture 19: Functions, Types and Data Structures in Haskell

Lecture 19: Functions, Types and Data Structures in Haskell The University of North Carolina at Chapel Hill Spring 2002 Lecture 19: Functions, Types and Data Structures in Haskell Feb 25 1 Functions Functions are the most important kind of value in functional programming

More information

INTRODUCTION TO PROLOG

INTRODUCTION TO PROLOG INTRODUCTION TO PROLOG PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/44 STRUCTURE OF A PROLOG PROGRAM Where, declaratively, Haskell expresses a computation as a system

More information

Chapter 16. Logic Programming Languages

Chapter 16. Logic Programming Languages Chapter 16 Logic Programming Languages Chapter 16 Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic Programming The Origins of

More information

AI2 Remedial Prolog Tutorial 2

AI2 Remedial Prolog Tutorial 2 AI2 Remedial Prolog Tutorial 2 Rules The Prolog interpreter is able to make inferences (i.e. reasoning of the form If Alan drinks beer, then he must like it). This is done by way of using rules. There

More information

3 Lists. List Operations (I)

3 Lists. List Operations (I) 3 Lists. List Operations (I) The list is the simplest yet the most useful Prolog structure. A list is a sequence of any number of objects. Example 3.1: L = [1, 2, 3], R = [a, b, c], T = [john, marry, tim,

More information

Implementação de Linguagens 2016/2017

Implementação de Linguagens 2016/2017 Implementação de Linguagens Ricardo Rocha DCC-FCUP, Universidade do Porto ricroc @ dcc.fc.up.pt Ricardo Rocha DCC-FCUP 1 Logic Programming Logic programming languages, together with functional programming

More information

This lecture covers: Prolog s execution strategy explained more precisely. Revision of the elementary Prolog data types

This lecture covers: Prolog s execution strategy explained more precisely. Revision of the elementary Prolog data types This lecture covers: Prolog s execution strategy explained more precisely The execution strategy has been presented as simply placing all matching clauses onto the stack. In fact, Prolog is slightly more

More information

CAP 5602 Summer, Lesson 4: Loops. The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop

CAP 5602 Summer, Lesson 4: Loops. The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop CAP 5602 Summer, 2011 Lesson 4: Loops The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop 1. The cut The cut (!) is a way of controlling backtracking. If a rule contains a

More information

Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3.

Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3. 1 Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3. Satisfying goals 2 Prolog A standard free Prolog can be downloaded from http://www.swi-prolog.org

More information

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors. 1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN

More information

CPS 506 Comparative Programming Languages. Programming Language Paradigm

CPS 506 Comparative Programming Languages. Programming Language Paradigm CPS 506 Comparative Programming Languages Logic Programming Language Paradigm Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic

More information

will take you everywhere.

will take you everywhere. Prolog COMP360 Logic will get you from A to B. Imagination will take you everywhere. Albert Einstein Prolog Assignment A programming assignment in Prolog has been posted on Blackboard Upload your.pl file

More information

Logic Programming Languages

Logic Programming Languages Logic Programming Languages Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical inferencing process to

More information

Functional programming with Common Lisp

Functional programming with Common Lisp Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions

More information

Exercises on the Fundamentals of Prolog

Exercises on the Fundamentals of Prolog 1 Introduction Exercises on the Fundamentals of Prolog These exercises are intended to help reinforce material taught in the lectures of CIS335 course in Prolog. They do not contribute any marks to the

More information

First-Order Logic (FOL)

First-Order Logic (FOL) First-Order Logic (FOL) FOL consists of the following parts: Objects/terms Quantified variables Predicates Logical connectives Implication Objects/Terms FOL is a formal system that allows us to reason

More information

Chapter 16. Logic Programming Languages ISBN

Chapter 16. Logic Programming Languages ISBN Chapter 16 Logic Programming Languages ISBN 0-321-49362-1 Chapter 16 Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic Programming

More information

15 Unification and Embedded Languages in Lisp

15 Unification and Embedded Languages in Lisp 15 Unification and Embedded Languages in Lisp Chapter Objectives Chapter Contents Pattern matching in Lisp: Database examples Full unification as required for Predicate Calculus problem solving Needed

More information

Software Paradigms (Lesson 6) Logic Programming

Software Paradigms (Lesson 6) Logic Programming Software Paradigms (Lesson 6) Logic Programming Table of Contents 1 Introduction... 2 2 Facts... 3 3 Predicates (Structured Terms)... 4 3.1 General Structures... 4 3.2 Predicates (Syntax)... 4 3.3 Simple

More information

Z Notation. June 21, 2018

Z Notation. June 21, 2018 Z Notation June 21, 2018 1 Definitions There are many different ways to introduce an object in a Z specification: declarations, abbreviations, axiomatic definitions, and free types. Keep in mind that the

More information

Introduction to Logic Programming in Prolog 1 / 39

Introduction to Logic Programming in Prolog 1 / 39 Introduction to Logic Programming in Prolog 1 / 39 Outline Programming paradigms Logic programming basics Introduction to Prolog Predicates, queries, and rules Understanding the query engine Goal search

More information

Prolog - 3 Prolog search trees + traces

Prolog - 3 Prolog search trees + traces Prolog - 3 Prolog search trees + traces 1 Review member(a, [A B]). member(a, [B C]) :- member (A,C). goal-oriented semantics: can get value assignment for goal member(a,[b C]) by showing truth of subgoal

More information

CS 321 Programming Languages and Compilers. Prolog

CS 321 Programming Languages and Compilers. Prolog CS 321 Programming Languages and Compilers Prolog Prolog PROgramming LOGic Algorithm = Logic + Control Logic programming deals with computing relations rather than functions. To understand Prolog one must

More information

CSC324 Logic & Relational Programming Illustrated in Prolog

CSC324 Logic & Relational Programming Illustrated in Prolog CSC324 Logic & Relational Programming Illustrated in Prolog Afsaneh Fazly 1 Winter 2013 1 with many thanks to Anya Tafliovich, Gerald Penn and Sheila McIlraith. 1 2 admin notes Please check your marks

More information

SML A F unctional Functional Language Language Lecture 19

SML A F unctional Functional Language Language Lecture 19 SML A Functional Language Lecture 19 Introduction to SML SML is a functional programming language and acronym for Standard d Meta Language. SML has basic data objects as expressions, functions and list

More information

LING/C SC/PSYC 438/538. Lecture 20 Sandiway Fong

LING/C SC/PSYC 438/538. Lecture 20 Sandiway Fong LING/C SC/PSYC 438/538 Lecture 20 Sandiway Fong Today's Topics SWI-Prolog installed? We will start to write grammars today Quick Homework 8 SWI Prolog Cheatsheet At the prompt?- 1. halt. 2. listing. listing(name).

More information

Introduction to TURING

Introduction to TURING Introduction to TURING Comments Some code is difficult to understand, even if you understand the language it is written in. To that end, the designers of programming languages have allowed us to comment

More information

The Logic Paradigm. Joseph Spring. 7COM1023 Programming Paradigms

The Logic Paradigm. Joseph Spring. 7COM1023 Programming Paradigms The Logic Paradigm Joseph Spring 7COM1023 Programming Paradigms 1 Discussion The Logic Paradigm Propositional and Predicate Logic See also notes and slides on PP website Horn Clauses Definition, Examples

More information

An introduction to logic programming with Prolog

An introduction to logic programming with Prolog An introduction to logic programming with Prolog Dr. Constantinos Constantinides Department of Computer Science and Software Engineering Concordia University A running example: A family genealogy tree

More information

Concepts of programming languages

Concepts of programming languages Concepts of programming languages Prolog Winand, Roald, Sjoerd, Alexey and Anvar 1 What is logic programming? Logic programming is a type of programming paradigm which is largely based on formal logic.

More information

Information technology Programming languages Prolog Part 1: General core

Information technology Programming languages Prolog Part 1: General core INTERNATIONAL STANDARD ISO/IEC 13211-1:1995 TECHNICAL CORRIGENDUM 3 Published 2017-07 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE

More information

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is

More information

Chapter 16. Logic Programming Languages ISBN

Chapter 16. Logic Programming Languages ISBN Chapter 16 Logic Programming Languages ISBN 0-321-49362-1 Chapter 16 Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic Programming

More information

Outcome-Oriented Programming (5/12/2004)

Outcome-Oriented Programming (5/12/2004) 1 Outcome-Oriented Programming (5/12/2004) Daniel P. Friedman, William E. Byrd, David W. Mack Computer Science Department, Indiana University Bloomington, IN 47405, USA Oleg Kiselyov Fleet Numerical Meteorology

More information

Foundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution

Foundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution Foundations of AI 9. Predicate Logic Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution Wolfram Burgard, Andreas Karwath, Bernhard Nebel, and Martin Riedmiller 09/1 Contents Motivation

More information

Wan Hussain Wan Ishak

Wan Hussain Wan Ishak February 2 nd Session 2014/2015 (A142) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com

More information

Combining Lists & Built-in Predicates

Combining Lists & Built-in Predicates Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 6 11/10/04 11/10/04 AIPP Lecture 6: Built-in Predicates 1 Collecting Results Last time we

More information

SC/MATH Boolean Formulae. Ref: G. Tourlakis, Mathematical Logic, John Wiley & Sons, York University

SC/MATH Boolean Formulae. Ref: G. Tourlakis, Mathematical Logic, John Wiley & Sons, York University SC/MATH 1090 1- Boolean Formulae Ref: G. Tourlakis, Mathematical Logic, John Wiley & Sons, 2008. York University Department of Computer Science and Engineering York University- MATH 1090 01-Boolean 1 Overview

More information

Our Strategy for Learning Fortran 90

Our Strategy for Learning Fortran 90 Our Strategy for Learning Fortran 90 We want to consider some computational problems which build in complexity. evaluating an integral solving nonlinear equations vector/matrix operations fitting data

More information

CS 381: Programming Language Fundamentals

CS 381: Programming Language Fundamentals CS 381: Programming Language Fundamentals Summer 2017 Introduction to Logic Programming in Prolog Aug 2, 2017 Outline Programming paradigms Logic programming basics Introduction to Prolog Predicates, queries

More information

Topic 1: Introduction to Knowledge- Based Systems (KBSs)

Topic 1: Introduction to Knowledge- Based Systems (KBSs) Topic 1: Introduction to Knowledge- Based Systems (KBSs) 1.5 Introduction to Logic Programming (Prolog) 32 Simple example: Algorithm for checking sorted list? We all know how to check if a list is sorted:

More information

Principles of Programming Languages Topic: Logic Programming Professor Lou Steinberg

Principles of Programming Languages Topic: Logic Programming Professor Lou Steinberg Principles of Programming Languages Topic: Logic Programming Professor Lou Steinberg 1 Logic Programming True facts: If I was born in year B, then in year Y on my birthday I turned Y-B years old I turned

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

The Idea Underlying Logic Programming. CSci 8980, Fall 2012 Specifying and Reasoning About Computational Systems An Introduction to Logic Programming

The Idea Underlying Logic Programming. CSci 8980, Fall 2012 Specifying and Reasoning About Computational Systems An Introduction to Logic Programming The Idea Underlying CSci 8980, Fall 2012 Specifying and Reasoning About Computational Systems An Introduction to Department of Computer Science and Engineering University of Minnesota Lectures in Fall

More information

What are Operators? - 1. Operators. What are Operators? - 2. Properties. » Position» Precedence class» associativity. » x + y * z. » +(x, *(y, z)).

What are Operators? - 1. Operators. What are Operators? - 2. Properties. » Position» Precedence class» associativity. » x + y * z. » +(x, *(y, z)). What are Operators? - 1 Functors Introduce operators to improve the readability of programs Operators syntactic sugar Based on Clocksin & Mellish Sections 2.3, 5.5 O-1 O-2 The arithmetic expression:» x

More information

proof through refutation

proof through refutation Prolog's logic; resolution grammars & parsing 1 proof through refutation we saw that Prolog uses the strategy: test the claim that a query is false by (1) finding it is immediately true (matches a fact

More information

LOGIC AND DISCRETE MATHEMATICS

LOGIC AND DISCRETE MATHEMATICS LOGIC AND DISCRETE MATHEMATICS A Computer Science Perspective WINFRIED KARL GRASSMANN Department of Computer Science University of Saskatchewan JEAN-PAUL TREMBLAY Department of Computer Science University

More information

Notes for Chapter 12 Logic Programming. The AI War Basic Concepts of Logic Programming Prolog Review questions

Notes for Chapter 12 Logic Programming. The AI War Basic Concepts of Logic Programming Prolog Review questions Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions The AI War How machines should learn: inductive or deductive? Deductive: Expert => rules =>

More information

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 2.1-2.7 p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer

More information

Page 1 of 5. University of Toronto CSC326 Programming Languages, Fall 2009

Page 1 of 5. University of Toronto CSC326 Programming Languages, Fall 2009 University of Toronto CSC326 Programming Languages, Fall 2009 Assignment # 4 Part B (Due: Monday, Dec. 7rd 2009, 11:00am sharp) Details: - Programming in Prolog. This is the Part B of assignment 4, and

More information

Lecture 21: Relational Programming II. November 15th, 2011

Lecture 21: Relational Programming II. November 15th, 2011 Lecture 21: Relational Programming II November 15th, 2011 Lecture Outline Relational Programming contd The Relational Model of Computation Programming with choice and Solve Search Strategies Relational

More information

UNIT 2 A. I. LANGUAGES-2: PROLOG

UNIT 2 A. I. LANGUAGES-2: PROLOG UNIT 2 A. I. LANGUAGES-2: Structure Page Nos. 2.0 Introduction 42 2.1 Objectives 43 2.2 Foundations of Prolog 43 2.3 Notations in Prolog for Building Blocks 46 2.4 How Prolog System Solves Problems 50

More information

PROLOG PROgramming in LOGic

PROLOG PROgramming in LOGic PROLOG PROgramming in LOGic 1 Knowledge-Based Information Systems (Relational) database systems are very efficient in the handling of data. Information is data together with a suitable interpretation.

More information

Backtracking. Backtracking. Backtracking. Backtracking. Backtracking. Backtracking. Functional & Logic Programming - Backtracking October, 01

Backtracking. Backtracking. Backtracking. Backtracking. Backtracking. Backtracking. Functional & Logic Programming - Backtracking October, 01 Functional & Logic Programming - October, 01 already seen how to control execution ordering the clauses and goals can affect the speed of execution and the order of evaluation of the clauses now going

More information

What is Prolog? - 1. A Prolog Tutorial. What is Prolog? - 2. Prolog Programming. » Declaring some facts about objects and their relationships

What is Prolog? - 1. A Prolog Tutorial. What is Prolog? - 2. Prolog Programming. » Declaring some facts about objects and their relationships What is Prolog? - 1 Prolog is an example of a logic programming language Invented by Alain Colmeraurer in 1972 A Prolog Tutorial Based on Clocksin and Mellish Chapter 1 The version implemented at the University

More information

Basic Scheme February 8, Compound expressions Rules of evaluation Creating procedures by capturing common patterns

Basic Scheme February 8, Compound expressions Rules of evaluation Creating procedures by capturing common patterns Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns Previous lecture Basics of Scheme Expressions and associated values (or syntax and

More information

Week 7 Prolog overview

Week 7 Prolog overview Week 7 Prolog overview A language designed for A.I. Logic programming paradigm Programmer specifies relationships among possible data values. User poses queries. What data value(s) will make this predicate

More information

Introduction Prolog Activity! Prolog. Dr. Mattox Beckman. University of Illinois at Urbana-Champaign Department of Computer Science

Introduction Prolog Activity! Prolog. Dr. Mattox Beckman. University of Illinois at Urbana-Champaign Department of Computer Science Prolog Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science Outline Introduction Objectives Logic Prolog Prolog Queries Builtin Structures Activity! Activity Objectives

More information

More Planning and Prolog Operators

More Planning and Prolog Operators More Planning and Prolog Operators Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 16 22/11/04 22/11/04 AIPP Lecture 16: More Planning and Operators 1 Planning continued Contents

More information

zebra puzzle continued recap Prolog concepts family relations

zebra puzzle continued recap Prolog concepts family relations zebra puzzle continued recap Prolog concepts family relations 1 recapping the Zebra puzzle 2 ****** the facts ****** There are 5 houses, occupied by politicallyincorrect gentlemen of 5 different nationalities,

More information

Introduction to Prolog

Introduction to Prolog Introduction to Prolog David Woods dwoods@scss.tcd.ie Week 3 - HT Declarative Logic The Prolog programming language is, at its theoretical core, a declarative language. This is unlike more commonly used

More information

Logic Programming. Efficiency Issues. Temur Kutsia

Logic Programming. Efficiency Issues. Temur Kutsia Logic Programming Efficiency Issues Temur Kutsia Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria kutsia@risc.uni-linz.ac.at Efficiency Issues in Prolog Narrow the

More information

Prolog Programming. Chapter 2. Syntax and Meaning of Prolog Programs 1/16/2010

Prolog Programming. Chapter 2. Syntax and Meaning of Prolog Programs 1/16/2010 Prolog Programming Chapter 2 Syntax and Meaning of Prolog Programs 1/16/2010 1 Chapter 2 Syntax and Meaning of Prolog Programs Data Objects Matching Declarative meaning of Prolog programs Procedural meaning

More information

What needs to be kept track of ffl The current substitution ffl The current goal ffl The clause currently in use ffl Backtrack Information 2

What needs to be kept track of ffl The current substitution ffl The current goal ffl The clause currently in use ffl Backtrack Information 2 Prolog Implementation ffl The Generic Idea: Everything except unification. ffl An Introduction to the WAM: Flat unification only. 1 What needs to be kept track of ffl The current substitution ffl The current

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Logic Programming with Prolog Lists CMSC 330 Spring 2017 1 Review: Execution = Search Prolog execution: Goal-directed search Query = predicate you wish to

More information

Processing lists in Prolog - 2

Processing lists in Prolog - 2 Processing lists in Prolog - 2 This lecture shows that techniques introduced before (analysing terminating conditions and recursive programming) can be used to develop more complex procedures. This lecture

More information

Functional Logic Programming. Kristjan Vedel

Functional Logic Programming. Kristjan Vedel Functional Logic Programming Kristjan Vedel Imperative vs Declarative Algorithm = Logic + Control Imperative How? Explicit Control Sequences of commands for the computer to execute Declarative What? Implicit

More information

UNIVERSITY OF TORONTO AT MISSISSAUGA April 2006 Examination CSC 324H5 S Instructor: Richard Krueger Duration 3 hours No Aids Allowed

UNIVERSITY OF TORONTO AT MISSISSAUGA April 2006 Examination CSC 324H5 S Instructor: Richard Krueger Duration 3 hours No Aids Allowed UNIVERSITY OF TORONTO AT MISSISSAUGA April 2006 Examination CSC 324H5 S Instructor: Richard Krueger Duration 3 hours No Aids Allowed Student Number: Last (Family) Name(s): First (Given) Name(s): SOLUTIONS

More information