Programming Languages 2nd edition Tucker and Noonan

Size: px
Start display at page:

Download "Programming Languages 2nd edition Tucker and Noonan"

Transcription

1 Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does a dog have if you call its tail a leg? A: Four. Calling a tail a leg doesn t make it one. Abraham Lincoln Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical inferencing process to produce results Declarative rather that procedural: Only specification of results are stated (not detailed procedures for producing them) Concepts of Copyright Programming Languages, 2006 The 9th McGraw-Hill ed., by Robert W. Companies, Sebesta. Addison Inc. Wesley,

2 Example: Sorting a List Describe the characteristics of a sorted list, not the process of rearranging a list sort(old_list, new_list) permute (old_list, new_list) sorted (new_list) sorted (list) j such that 1 j < n, list(j) list (j+1) Concepts of Copyright Programming Languages, 2006 The 9th McGraw-Hill ed., by Robert W. Companies, Sebesta. Addison Inc. Wesley, Logic and Horn Clauses A Horn clause has a head h, which is a predicate, and a body, which is a list of predicates p 1, p 2,, p n. It is written as: h p 1, p 2,, p n This means, h is true only if p 1, p 2,, and p n are simultaneously true. E.g., the Horn clause: snowing(c) precipitation(c), freezing(c) says, it is snowing in city C only if there is precipitation in city C and it is freezing in city C

3 Horn Clauses and Predicates Any Horn clause h p 1, p 2,, p n can be written as a predicate: p 1 p 2 p n h or equivalently: (p 1 p 2 p n ) h But not every predicate can be written as a Horn clause. E.g., literate(x) reads(x) writes(x) 16-6 Resolution and Unification If h is the head of a Horn clause h terms and it matches one of the terms of another Horn clause: t t 1, h, t 2 then that term can be replaced by h s terms to form: t t 1, terms, t 2 During resolution, assignment of variables to values is called instantiation. Unification is a pattern-matching process that determines what particular instantiations can be made to variables during a series of resolutions

4 Example The two clauses: speaks(mary, English) talkswith(x, Y) speaks(x, L), speaks(y, L), X Y can resolve to: talkswith(mary, Y) speaks(mary, English), speaks(y, English), Mary Y The assignment of values Mary and English to the variables X and L is an instantiation for which this resolution can be made Logic Programming in Prolog In logic programming the program declares the goals of the computation, not the method for achieving them. Logic programming has applications in AI and databases. Natural language processing (NLP) Automated reasoning and theorem proving Expert systems (e.g., MYCIN) Database searching, as in SQL (Structured Query Language) Prolog emerged in the 1970s. Distinguishing features: Nondeterminism Backtracking

5 Prolog Program Elements Prolog programs are made from terms, which can be: Variables Constants Structures Variables begin with a capital letter, like Bob. Constants are either integers, like 24, or atoms, like the, zebra, Bob, and.. Structures are predicates with arguments, like: n(zebra), speaks(y, English), and np(x, Y) The arity of a structure is its number of arguments (1, 2, and 2 for these examples) Facts, Rules, and Programs A Prolog fact is a Horn clause without a right-hand side. Its form is (note the required period.): term. A Prolog rule is a Horn clause with a right-hand side. Its form is (note :- represents and the required period.): term :- term 1, term 2, term n. A Prolog program is a collection of facts and rules

6 Inferencing Process of Prolog Queries are called goals If a goal is a compound proposition, each of the facts is a subgoal To prove a goal is true, must find a chain of inference rules and/or facts. For goal Q: A. B :- A. C :- B. Q :- P. Process of proving a subgoal called matching, satisfying, or resolution Concepts of Copyright Programming Languages, 2006 The 9th McGraw-Hill ed., by Robert W. Companies, Sebesta. Addison Inc. Wesley, Approaches Bottom-up resolution, forward chaining Begin with facts and rules of database and attempt to find sequence that leads to goal Works well with a large set of possibly correct answers A. {A} B :- A. {A, B} C :- B. {A, B, C} Q :- P. {A, B, C,, P, Q}? Q. true Copyright 2009 Addison-Wesley. All rights reserved

7 Approaches Top-down resolution, backward chaining Begin with goal and attempt to find sequence that leads to set of facts in database Works well with a small set of possibly correct answers A. {A, B, C,, P, Q} B :- A. C :- B. Q :- P. {A?, B?, C?,, P?, Q?} {B?, C?,, P?, Q?} {P?, Q?}? Q. {Q?} Prolog implementations use backward chaining Copyright 2009 Addison-Wesley. All rights reserved Subgoal Strategies When goal has more than one subgoal, can use either Depth-first search: find a complete proof for the first subgoal before working on others Breadth-first search: work on all subgoals in parallel Prolog uses depth-first search Can be done with fewer computer resources Copyright 2009 Addison-Wesley. All rights reserved

8 Backtracking With a goal with multiple subgoals, if fail to show truth of one of subgoals, reconsider previous subgoal to find an alternative solution: backtracking Begin search where previous search left off Can take lots of time and space because may find all possible proofs to every subgoal Copyright 2009 Addison-Wesley. All rights reserved Simple Arithmetic Prolog supports integer variables and integer arithmetic is operator: takes an arithmetic expression as right operand and variable as left operand A is B / 17 + C Not the same as an assignment statement! Copyright 2009 Addison-Wesley. All rights reserved

9 Prolog Example cat min.pro min(x, Y, X) :- X < Y. min(x, Y, Y) :- X >= Y. brb0164@faculty% gprolog GNU Prolog ?- consult( min ). compiling min.pro for byte code... min.pro compiled, 2 lines read bytes written, 17 ms?- min(0, 1, 0). true??- min(17, 45, Minimum). Minimum = 17??- min(65, 3, Minimum). Minimum = 3?- ^D Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc Prolog Example brb0164@faculty% cat factorial.pro factorial(0, 1). factorial(n, Factorial) :- M is N 1, factorial(m, M_Factorial), Factorial is N * M_Factorial. brb0164@faculty% gprolog?- consult( factorial ). compiling factorial.pro for byte code... factorial.pro compiled, 3 lines read bytes written, 58 ms?- factorial(5, Factorial). Factorial = 120??- factorial(10, Factorial). Factorial = ??- ^D Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc

10 Example Program speaks(allen, russian). speaks(bob, english). speaks(mary, russian). speaks(mary, english). talkswith(x, Y) :- speaks(x, L), speaks(y, L), X \= Y. This program has four facts and one rule. The rule succeeds for any instantiation of its variables in which all the terms on the right of := are simultaneously true. E.g., this rule succeeds for the instantiation X=allen, Y=mary, and L=russian. For other instantiations, like X=allen and Y=bob, the rule fails Lists A list is a series of terms separated by commas and enclosed in brackets. The empty list is written []. The sentence The giraffe dreams can be written as a list: [the, giraffe, dreams] A don t care entry is signified by _, as in [_, X, Y] A list can also be written in the form: [Head Tail] The functions append joins two lists, and member tests for list membership

11 append Function append([], X, X). append([head Tail], Y, [Head Z]) :- append(tail, Y, Z). This definition says: 1. Appending the empty list to any list (X) returns an unchanged list (X again). 2. If Tail is appended to Y to get Z, then a list one element larger [Head Tail] can be appended to Y to get [Head Z]. Note: The last parameter designates the result of the function. So a variable must be passed as an argument member Function member(x, [X _]). member(x, [_ Y]) :- member(x, Y). The test for membership succeeds if either: 1. X is the head of the list [X _] 2. X is not the head of the list [_ Y], but X is a member of the list Y. Notes: pattern matching governs tests for equality. Don t care entries (_) mark parts of a list that aren t important to the rule

12 More List Functions X is a prefix of Z if there is a list Y that can be appended to X to make Z. That is: prefix(x, Z) :- append(x, Y, Z). Similarly, Y is a suffix of Z if there is a list X to which Y can be appended to make Z. That is: suffix(y, Z) :- append(x, Y, Z). So finding all the prefixes (suffixes) of a list is easy. E.g.:?- prefix(x, [my, dog, has, fleas]). X = []; X = [my]; X = [my, dog]; Prolog Example brb0164@faculty% cat length.pro length([], 0). length([x Xs], Length) :- length(xs, Xs_Length), Length is Xs_Length + 1. brb0164@faculty% gprolog?- consult( length ).?- length([a, b, c, d], Length). Length = 4?- length([a, [b, c]], Length). Length = 2 Yes?- length([], Length). Length = 0?- length([a, [b, c], d, [e, f, [g, h]]], Length). Length = 4 Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc

13 Lisp Examples in Prolog cat lispfunctions.pro car([x Xs], X). cdr([x Xs], Xs). cons(x, Xs, [X Xs]). append([], Ys, Ys). append([x Xs], Ys, [X Zs]) :- append(xs, Ys, Zs). Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc Lisp Examples in Prolog gprolog?- consult( lispfunctions ).?- cons(x, [], A). A = [x]?- cons(y, [x], B). B = [y,x] Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc

14 Lisp Examples in Prolog?- append([y, x], [z], D). D = [y,x,z]?- append([y, x], [z], D), cdr(d, Cdr_D), car(cdr_d, Cadr_D). Cadr_D = x Cdr_D = [x,z] D = [y,x,z] Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc Database Example in Prolog brb0164@faculty% cat ancestors.pro female(shelley). female(mary). female(lisa). female(joan). mother(mary, jake). mother(mary, shelley). mother(lisa, mary). mother(joan, bill). male(bill). male(jake). male(bob). male(frank). father(bill, jake). father(bill, shelley). father(bob, mary). father(frank, bill). Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc

15 Database Example in Prolog parent(father, Child) :- father(father, Child). parent(mother, Child) :- mother(mother, Child). parents(father, Mother, Child) :- father(father, Child), mother (Mother, Child). Copyright Copyright 2006 The 2004 McGraw-Hill Barrett R. Companies, Bryant. Inc Database Example in Prolog gprolog?- consult( ancestors ).?- parents(father, Mother, jake). Father = bill Mother = mary??- parents(bill, mary, Child). Child = jake? ; Child = shelley Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc

16 Database Example in Prolog?- parents(father, Mother, Child). Child = jake Father = bill Mother = mary? ; Child = shelley Father = bill Mother = mary? ; Child = mary Father = bob Mother = lisa? ; Child = bill Father = frank Mother = joan Copyright Copyright 2006 The 2007 McGraw-Hill Barrett R. Companies, Bryant. Inc Database Example in Prolog sibling(child1, Child2) :- father(father, Child1), father(father, Child2), mother(mother, Child1), mother(mother, Child2). Copyright Copyright 2006 The 2004 McGraw-Hill Barrett R. Companies, Bryant. Inc

17 Database Example in Prolog?- sibling(child1, Child2). Child1 = jake Child2 = jake? ; Child1 = jake Child2 = shelley? ; Child1 = shelley Child2 = jake? ; Child1 = shelley Child2 = shelley? ; Child1 = mary Child2 = mary? ; Child1 = bill Child2 = bill Copyright Copyright 2006 The 2007 McGraw-Hill Barrett R. Companies, Bryant. Inc Database Example in Prolog true_sibling(child1, Child2) :- sibling(child1, Child2), \+ Child1 = Child2. /* \+ is negation */?- true_sibling(child1, Child2). Child1 = jake Child2 = shelley? ; Child1 = shelley Child2 = jake? ; no Copyright Copyright 2006 The 2007 McGraw-Hill Barrett R. Companies, Bryant. Inc

18 Database Example in Prolog ancestor(ancestor, Descendant) :- parent(ancestor, Descendant). ancestor(ancestor, Descendant) :- parent(descendants_parent, Descendant), ancestor(ancestor, Descendants_Parent).?- ancestor(ancestor, jake). Ancestor = bill? ; Ancestor = mary? ; Ancestor = frank? ; Ancestor = joan? ; Ancestor = bob? ; Ancestor = lisa? ; no Copyright Copyright 2006 The 2007 McGraw-Hill Barrett R. Companies, Bryant. Inc Postfix Example in Prolog brb0164@faculty% cat postfix.pro /* This program converts a postfix expression, represented as a list of operands and operators, into a syntax tree. */ postfix(exp, Tree) :- postfix_stack(exp, [], [Tree]). Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc

19 Postfix Example in Prolog postfix_stack([], Tree, Tree). postfix_stack([operator Rest_exp], [Top, Next_top Rest_stack], Tree) :- operator(operator), postfix_stack(rest_exp, [tree(operator, Next_top, Top) Rest_stack], Tree). postfix_stack([operand Rest_exp], Stack, Tree) :- postfix_stack(rest_exp, [Operand Stack], Tree). operator(+). operator(-). operator(*). operator(/). Copyright Copyright 2006 The 2004 McGraw-Hill Barrett R. Companies, Bryant. Inc Postfix Example in Prolog gprolog?- consult( postfix ).?- postfix([a,b,c,*,+],tree). Tree = tree(+,a,tree(*,b,c))??- postfix([a,b,+,c,*,d,/,e,-],tree). Tree = tree(-,tree(/,tree(*,tree(+,a,b),c),d),e)? Copyright Copyright 2006 The 2014 McGraw-Hill Barrett R. Companies, Bryant. Inc

20 Practical Aspects of Prolog Tracing The Cut Negation The is, not, and Other Operators The Assert Function Tracing To see the dynamics of a function call, the trace function can be used. E.g., if we want to trace a call to the following function: factorial(0, 1). factorial(n, Result) :- N > 0, M is N - 1, factorial(m, SubRes), Result is N * SubRes. we can activate trace and then call the function:?- trace(factorial/2).?- factorial(4, X). Note: the argument to trace may include the function s arity

21 Tracing Output?- factorial(4, X). Call: ( 7) factorial(4, _G173) Call: ( 8) factorial(3, _L131) Call: ( 9) factorial(2, _L144) Call: ( 10) factorial(1, _L157) Call: ( 11) factorial(0, _L170) Exit: ( 11) factorial(0, 1) Exit: ( 10) factorial(1, 1) Exit: ( 9) factorial(2, 2) Exit: ( 8) factorial(3, 6) Exit: ( 7) factorial(4, 24) X = 24 These are temporary variables These are levels in the search tree The Cut The cut is an operator (!) inserted on the right-hand side of a rule. semantics: the cut forces those subgoals not to be retried if the right-hand side succeeds once. E.g (bubble sort): bsort(l, S) :- append(u, [A, B V], L), B < A,!, append(u, [B, A V], M), bsort(m, S). bsort(l, L). So this code gives one answer rather than many

22 Bubble Sort Trace?- bsort([5,2,3,1], Ans). Call: ( 7) bsort([5, 2, 3, 1], _G221) Call: ( 8) bsort([2, 5, 3, 1], _G221) Call: ( 12) bsort([1, 2, 3, 5], _G221) Redo: ( 12) bsort([1, 2, 3, 5], _G221) Exit: ( 7) bsort([5, 2, 3, 1], [1, 2, 3, 5]) Ans = [1, 2, 3, 5] ; No Without the cut, this would have given some wrong answers The assert Function The assert function can update the facts and rules of a program dynamically. E.g., if we add the following to the foregoing database program:?- assert(mother(jane, joe)). Then the query:?- mother(jane, X). gives: X = ron ; X = joe; No F

23 Solving Word Problems A simple example: Baker, Cooper, Fletcher, Miller, and Smith live in a five-story building. Baker doesn't live on the 5th floor and Cooper doesn't live on the first. Fletcher doesn't live on the top or the bottom floor, and he is not on a floor adjacent to Smith or Cooper. Miller lives on some floor above Cooper. Who lives on what floors? We can set up the solution as a list of five entries: [floor(_,5), floor(,4), floor(_,3), floor(_,2), floor(_,1)] The don t care entries are placeholders for the five names Modeling the solution We can identify the variables B, C, F, M, and S with the five persons, and the structure floors(floors) as a function whose argument is the list to be solved. Here s the first constraint: member(floor(baker, B), Floors), B\=5 which says that Baker doesn't live on the 5th floor. The other four constraints are coded similarly, leading to the following program:

24 Prolog solution floors([floor(_,5),floor(_,4),floor(_,3),floor(_,2), floor(_,1)]). building(floors) :- floors(floors), member(floor(baker, B), Floors), B \= 5, member(floor(cooper, C), Floors), C \= 1, member(floor(fletcher, F), Floors), F \= 1, F \= 5, member(floor(miller, M), Floors), M > C, member(floor(smith, S), Floors), not(adjacent(s, F)), not(adjacent(f, C)), print_floors(floors) Auxiliary functions Floor adjacency: adjacent(x, Y) :- X =:= Y+1. adjacent(x, Y) :- X =:= Y-1. Note: =:= tests for numerical equality. Displaying the results: print_floors([a B]) :- write(a), nl, print_floors(b). print_floors([]). Note: write is a Prolog function and nl stands for new line. Solving the puzzle is done with the query:?- building(x). which finds an instantiation for X that satisfies all the constraints

CASE STUDY LOGIC PROGRAMMING

CASE STUDY LOGIC PROGRAMMING CASE STUDY LOGIC PROGRAMMING 1 OUTLINE Preliminary Concepts Horn Clauses Logic Programming in Prolog Prolog Program Elements Practical Aspects of Prolog Prolog Examples Solving Word Puzzles Natural Language

More information

7COM1023 Programming Paradigms

7COM1023 Programming Paradigms 7COM1023 Programming Paradigms Practical 7: The Logic Paradigm Tutorial: Exercises Propositional and Predicate Logic form the basis for logic programming. 1. Explain what is meant by propositional logic.

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

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

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

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

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

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

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

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

CSE 452: Programming Languages. Prolog Statements. Loading the Knowledge Base. Logical Programming Languages Part 2

CSE 452: Programming Languages. Prolog Statements. Loading the Knowledge Base. Logical Programming Languages Part 2 CSE 452: Programming Languages Logical Programming Languages Part 2 Prolog Statements Prolog statements consist of facts, rules, and queries. Example of facts (written as headless Horn clauses) male(tony).

More information

CS 360: Programming Languages Lecture 10: Logic Programming with Prolog

CS 360: Programming Languages Lecture 10: Logic Programming with Prolog CS 360: Programming Languages Lecture 10: Logic Programming with Prolog Geoffrey Mainland Drexel University Section 1 Administrivia Midterm Tuesday Midterm is Tuesday, February 14! Study guide is on the

More information

IN112 Mathematical Logic

IN112 Mathematical Logic Institut Supérieur de l Aéronautique et de l Espace IN112 Mathematical Logic Lab session on Prolog Christophe Garion DMIA ISAE Christophe Garion IN112 IN112 Mathematical Logic 1/ 31 License CC BY-NC-SA

More information

IN112 Mathematical Logic

IN112 Mathematical Logic Institut Supérieur de l Aéronautique et de l Espace IN112 Mathematical Logic Lab session on Prolog Christophe Garion DMIA ISAE Christophe Garion IN112 IN112 Mathematical Logic 1/ 31 License CC BY-NC-SA

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

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

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

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. (Programming in Logic) Prepared by: Tanay Kumar Saha

Prolog. (Programming in Logic) Prepared by: Tanay Kumar Saha Prolog (Programming in Logic) Prepared by: Tanay Kumar Saha Motivation for Learning Prolog Follow prolog news: http://www.swi-prolog.org/news SWI-Prolog Used For Satellite Anomaly Detection Fast cars and

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

6. Inference and resolution

6. Inference and resolution Computer Science and Software Engineering University of Wisconsin - Platteville 6. Inference and resolution CS 3030 Lecture Notes Yan Shi UW-Platteville Read: Textbook Chapter 8 Part of the slides are

More information

Logic (or Declarative) Programming Foundations: Prolog. Overview [1]

Logic (or Declarative) Programming Foundations: Prolog. Overview [1] Logic (or Declarative) Programming Foundations: Prolog In Text: Chapter 12 Formal logic Logic programming Prolog Overview [1] N. Meng, S. Arthur 2 1 Logic Programming To express programs in a form of symbolic

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

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

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

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

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

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

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

Predicate Calculus. Problems? Syntax. Atomic Sentences. Complex Sentences. Truth

Predicate Calculus. Problems? Syntax. Atomic Sentences. Complex Sentences. Truth Problems? What kinds of problems exist for propositional logic? Predicate Calculus A way to access the components of an individual assertion Predicate Calculus: used extensively in many AI programs, especially

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

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

10. Logic Programming With Prolog

10. Logic Programming With Prolog Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000 10. Logic Programming With Overview Logic Programming Logic Programming Logic programming is a form of declarative programming A

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

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

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

Quick n Dirty Prolog Tutorial

Quick n Dirty Prolog Tutorial CSc 245 Introduction to Discrete Structures Quick n Dirty Prolog Tutorial (McCann) Last Revised: February 2014 Background: Prolog, whose name is from the phrase PROgramming in LOGic, is a special purpose

More information

References. Topic #16: Logic Programming. Motivation. What is a program? Prolog Program Structure

References. Topic #16: Logic Programming. Motivation. What is a program? Prolog Program Structure References Topic #16: Logic Programming CSE 413, Autumn 2004 Programming Languages Slides from CSE 341 S. Tanimoto See Chapter 16 of the text Read 16.1, 16.4, 16.5, 16.6 (skip 16.6.7) Skim 16.7, 16.8 http://www.cs.washington.edu/education/courses/413/04au/

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

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

Lecture Notes on Prolog

Lecture Notes on Prolog Lecture Notes on Prolog 15-317: Constructive Logic Frank Pfenning Lecture 14 October 15, 2009 In this lecture we introduce some simple data structures such as lists, and simple algorithms on them such

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

The current topic: Prolog. Announcements. Meaning of a Prolog rule. Prolog syntax. Reminder: The deadline for Lab 2 re-mark requests is Friday.

The current topic: Prolog. Announcements. Meaning of a Prolog rule. Prolog syntax. Reminder: The deadline for Lab 2 re-mark requests is Friday. The current topic: Prolog! Introduction! Object-oriented programming: Python! Functional programming: Scheme! Python GUI programming (Tkinter)! Types and values Logic programming: Prolog! Introduction

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

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

Chapter 5. Pure PROLOG. Foundations of Logic Programming

Chapter 5. Pure PROLOG. Foundations of Logic Programming Chapter 5 1 Outline vs. logic programming Lists in Adding Arithmetics to Adding the Cut to 2 Syntax of Pure Prolog p(x,a) :- q(x), r(x,yi). p(x, a) q(x), r(x,y i ) % Comment Ambivalent syntax: p(p(a,b),

More information

Lecture Notes on Prolog

Lecture Notes on Prolog Lecture Notes on Prolog 15-317: Constructive Logic Frank Pfenning Lecture 14 October 27, 2015 In this lecture we introduce some simple data structures such as lists, and simple algorithms on them such

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

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

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

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

Logical reasoning systems

Logical reasoning systems Logical reasoning systems Theorem provers and logic programming languages Production systems Frame systems and semantic networks Description logic systems CS 561, Session 19 1 Logical reasoning systems

More information

6.034 Notes: Section 11.1

6.034 Notes: Section 11.1 6.034 Notes: Section 11.1 Slide 11.1.1 We've now spent a fair bit of time learning about the language of first-order logic and the mechanisms of automatic inference. And, we've also found that (a) it is

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

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion simple and/or composition of goals hides complex control patterns not easily represented by traditional

More information

Module 7. Knowledge Representation and Logic (Rule based Systems) Version 2 CSE IIT, Kharagpur

Module 7. Knowledge Representation and Logic (Rule based Systems) Version 2 CSE IIT, Kharagpur Module 7 Knowledge Representation and Logic (Rule based Systems) Lesson 18 Rule based Systems - II 7.2.5 Programs in PROLOG These minimal notes on Prolog show only some of its flavor. Here are facts plays(ann,fido).

More information

CS 360: Programming Language Concepts Lecture 15 Logic Programming

CS 360: Programming Language Concepts Lecture 15 Logic Programming Reference: Ch. 12.1-12.5 CS 360: Programming Language Concepts Lecture 15 Logic Programming I. Logic Programming (Generally) What is logic programming? A logic program is a collection of declarations,

More information

Programming Languages. Dr. Philip Cannata 1

Programming Languages. Dr. Philip Cannata 1 Programming Languages Dr. Philip Cannata 1 10 High Level Languages This Course Jython in Java Java (Object Oriented) Relation ASP RDF (Horn Clause Deduction, Semantic Web) Dr. Philip Cannata 2 I think

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

Visual Prolog Tutorial

Visual Prolog Tutorial Visual Prolog Tutorial Jim Mims April 2008 (with modification by Danjie Zhu) Preface What is Prolog? Programming in Logic. Edinburgh syntax is the basis of ISO standard. High-level interactive language.

More information

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

Q1:a. Best first search algorithm:

Q1:a. Best first search algorithm: Q1:a Best first search algorithm: 1. Open=[A10]; closed=[] 2. Evaluate A10; open=[c20,b30,d40];closed=[a10] 3. Evaluate C20; open=[b30,g35,d40,h40]; closed=[c20, A10] 4. Evaluate B30; open=[e10,f20,g35,d40,h40];

More information

Agenda. CS301 Session 20. A logic programming trick. A simple Prolog program. Introduction to logic programming Examples Semantics

Agenda. CS301 Session 20. A logic programming trick. A simple Prolog program. Introduction to logic programming Examples Semantics CS301 Session 20 Introduction to logic programming Examples Semantics Agenda 1 2 A logic programming trick A two-way translator in two lines of code: translate([],[]). translate([word Words],[Mot Mots])

More information

The Prolog to Mercury transition guide

The Prolog to Mercury transition guide The Prolog to Mercury transition guide Version 14.01.1 Thomas Conway Zoltan Somogyi Fergus Henderson Copyright c 1995 2014 The University of Melbourne. Permission is granted to make and distribute verbatim

More information

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

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

More information

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion simple and/or composition of goals hides complex control patterns not easily represented by traditional

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

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

Logic Programming. CITS 3242 Programming Paradigms. Topic 16: Part IV: Advanced Topics

Logic Programming. CITS 3242 Programming Paradigms. Topic 16: Part IV: Advanced Topics CITS 3242 Programming Paradigms Part IV: Advanced Topics Topic 16: Logic Programming Logic Programming is a paradigm for programming by declaring facts and rules. Programs are executed by querying whether

More information

For Wednesday. No reading Chapter 9, exercise 9. Must be proper Horn clauses

For Wednesday. No reading Chapter 9, exercise 9. Must be proper Horn clauses For Wednesday No reading Chapter 9, exercise 9 Must be proper Horn clauses Same Variable Exact variable names used in sentences in the KB should not matter. But if Likes(x,FOPC) is a formula in the KB,

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

Family Example: Some Facts. respects(barb,dan). respects(barb,katie). respects(dan,brian). respects(dan,barbara).

Family Example: Some Facts. respects(barb,dan). respects(barb,katie). respects(dan,brian). respects(dan,barbara). Family Example: Some Facts respects(barb,dan). respects(barb,katie). respects(dan,brian). respects(dan,barbara). Some Queries?- respects(barb,katie). yes?- respects(barb,x). X=dan; % you type ; and RETURN

More information

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA. R13 SET - 1 III B. Tech I Semester Regular Examinations, November - 2015 1 a) What constitutes a programming environment? [3M] b) What mixed-mode assignments are allowed in C and Java? [4M] c) What is

More information

Artificial Intelligence. Chapters Reviews. Readings: Chapters 3-8 of Russell & Norvig.

Artificial Intelligence. Chapters Reviews. Readings: Chapters 3-8 of Russell & Norvig. Artificial Intelligence Chapters Reviews Readings: Chapters 3-8 of Russell & Norvig. Topics covered in the midterm Solving problems by searching (Chap. 3) How to formulate a search problem? How to measure

More information

Programming Paradigms

Programming Paradigms PP 2017/18 Unit 6 Prolog Basics 1/42 Programming Paradigms Unit 6 Prolog Basics J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE PP 2017/18 Unit 6 Prolog Basics 2/42 Outline

More information

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

Prolog (cont d) Remark. Using multiple clauses. Intelligent Systems and HCI D7023E 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

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

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

COP4020 Programming Languages. Logical programming with Prolog Prof. Xin Yuan

COP4020 Programming Languages. Logical programming with Prolog Prof. Xin Yuan COP4020 Programming Languages Logical programming with Prolog Prof. Xin Yuan Topics Logic programming with Prolog COP4020 Spring 2013 2 Definitions: Prolog Terms Terms are symbolic expressions that are

More information

documenting programs, including: A traditional, command line interactive top level.

documenting programs, including: A traditional, command line interactive top level. Computational Logic Developing Programs with a Logic Programming System 1 Our Development Environment: The Ciao System We use the (ISO-Prolog subset of the) Ciao multiparadigm programming system. In particular,

More information

Prolog. Prolog: Programmation en Logique R.A. Kowalski: Predicate logic as a programming language, Proc IFIP 1974, pp.

Prolog. Prolog: Programmation en Logique R.A. Kowalski: Predicate logic as a programming language, Proc IFIP 1974, pp. Prolog Prolog: Programmation en Logique 1974 - R.A. Kowalski: Predicate logic as a programming language, Proc IFIP 1974, pp. 569-574: First-order predicate logic for the specification of data and relationships

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

Lecture 16: Logic Programming in Prolog

Lecture 16: Logic Programming in Prolog Lecture 16: Logic Programming in Prolog COMP 524 Programming Language Concepts Stephen Olivier March 26, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of

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

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

Logic Programming: Lecture 1

Logic Programming: Lecture 1 Logic Programming: Lecture 1 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in PLC, 3 April 2017 Logic programming Programming with relations Variables Names starting with a capital letter

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

Using Prolog as a CAS

Using Prolog as a CAS Using Prolog as a CAS Kharkiv Pedagogical University A. Stolyarevska July 2002 References 1) Robinson J.A. A machine-oriented logic based on the resolution principle. J. ACM, 12, 23-41. 2) Colmerauer A.

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

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

Logic Programming in Prolog

Logic Programming in Prolog Cristian Giumale / Lecture Notes 1 Logic Programming in Prolog There are important advantages of using programming systems based on logic: Data are neatly separated from the inference engine, which is

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

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

INF5390 Kunstig intelligens. First-Order Logic. Roar Fjellheim

INF5390 Kunstig intelligens. First-Order Logic. Roar Fjellheim INF5390 Kunstig intelligens First-Order Logic Roar Fjellheim Outline Logical commitments First-order logic First-order inference Resolution rule Reasoning systems Summary Extracts from AIMA Chapter 8:

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

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

Symbolic Computation Example Programming Exercises for Prolog

Symbolic Computation Example Programming Exercises for Prolog 2001 July 16 3401 Prolog Programming Exercises Page 1 of 8 Symbolic Computation Example Programming Exercises for Prolog 1. Write a Prolog predicate countbt(tree, Count) to count the number of des in a

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

Lecture 4: January 12, 2015

Lecture 4: January 12, 2015 32002: AI (First Order Predicate Logic, Interpretation and Inferences) Spring 2015 Lecturer: K.R. Chowdhary Lecture 4: January 12, 2015 : Professor of CS (VF) Disclaimer: These notes have not been subjected

More information

Teaching Prolog and CLP

Teaching Prolog and CLP Teaching Prolog and CLP Ulrich Neumerkel Institut für Computersprachen Technische Universität Wien www.complang.tuwien.ac.at/ulrich/ I The magic of Prolog Common obstacles II Reading of programs III Course

More information