First-Order Logic. Cholwich Nattee. Sirindhorn International Institute of Technology Thammasat University. Lecture 9: First-Order Logic 1/60

Size: px
Start display at page:

Download "First-Order Logic. Cholwich Nattee. Sirindhorn International Institute of Technology Thammasat University. Lecture 9: First-Order Logic 1/60"

Transcription

1 First-Order Logic Cholwich Nattee Sirindhorn International Institute of Technology Thammasat University Lecture 9: First-Order Logic 1/60

2 Pros and Cons of Propositional Logic Propositional logic is declarative. Propositional logic can deal with partial information using disjunctive and negation. Propositional logic is compositional. The meaning of a sentence comes from the meaning of its parts. For example, Round Square Meaning in propositional logic is context-independent. Propositional logic has very limited expressive power. Lecture 9: First-Order Logic 2/60

3 First-Order Logic (FOL) Whereas propositional logic assumes the world contains facts. FOL defines the world with: Objects Relations Functions Lecture 9: First-Order Logic 3/60

4 Models for FOL: Example crown person brother brother on head person king R $ J left leg left leg Lecture 9: First-Order Logic 4/60

5 Terminology Objects are elements in the domain, e.g. Richard, John, etc. A relation is the set of tuples of objects that are related. For example, brother = { Richard, John, John, Richard } on head = { the crown, John } king = { John } person = { John, Richard } A function is a kind of relations that a given object must be related to exactly one object. For example, a unary function left leg includes: Richard Richard s left leg John John s left leg Lecture 9: First-Order Logic 5/60

6 FOL: Basic Elements Type Examples Constants SIIT, Student, Somchai,... Predicates StudyAt, >, Brother,... Functions LeftLegOf, Sqrt,... Variables x, y, a, b,... Connectives,,,, Equality = Quantifier, Lecture 9: First-Order Logic 6/60

7 FOL: Atomic Sentences AtomicSentence = predicate(term 1, term 2,..., term n ) or term 1 = term 2 term = function(term 1,..., term m ) or or constant variable For example, Brother(John, Richard) > (Length(LeftLegOf (Richard)), Length(LeftLegOf (John))) Lecture 9: First-Order Logic 7/60

8 FOL: Complex Sentences In the same manner as propositional logic, complex sentences are made from atomic sentences using connectives. S, S 1 S 2, S 1 S 2, S 1 S 2, S 1 S 2 For example, Sibling(John, Richard) Sibling(Richard, John) >(1, 2) (1, 2) >(1, 2) >(1, 2) Lecture 9: First-Order Logic 8/60

9 Truth in FOL Sentences are true with respect to a model and an interpretation. Model contains objects and relations among objects. Interpretation specifies referents for constant symbols objects predicate symbols relations function symbols functional relations objects An atomic sentence predicate(term 1,..., term n ) is true, if and only if the objects referred by term 1,..., term n are in the relation referred by predicate. Lecture 9: First-Order Logic 9/60

10 Universal Quantification The universal quantifier ( ) is used to describe situation/things that are true about all objects For example, Every one studying at SIIT is smart. x StudyAt(x, SIIT) Smart(x) x P is true in a model m iff P is true with x being each possible object in the model. Roughly speaking, equivalent to the conjunction of instantiations of P... StudyAt(John, SIIT) Smart(John) StudyAt(Richard, SIIT) Smart(Richard) StudyAt(SIIT, SIIT) Smart(SIIT) Lecture 9: First-Order Logic 10/60

11 A common mistake to avoid Typically, is the main connective with. Common mistake: using as the connective with : x StudyAt(x, SIIT) Smart(x) It means Everyone is studying at SIIT and everyone is smart. Lecture 9: First-Order Logic 11/60

12 Existential Quantification The existential quantifier ( ) is used to state properties of some objects without naming it. For example, Someone studying at SIIT is smart. x StudyAt(x, SIIT) Smart(x) x P is true in a model m iff P is true with x being some possible object in the model. Roughly speaking, equivalent to the disjunction of instantiations of P... StudyAt(John, SIIT) Smart(John) StudyAt(Richard, SIIT) Smart(Richard) StudyAt(SIIT, SIIT) Smart(SIIT) Lecture 9: First-Order Logic 12/60

13 Another common mistake to avoid Typically, is the main connective with. Common mistake: using as the connective with : x StudyAt(x, SIIT) Smart(x) It is true if there is anyone who is not at SIIT. Lecture 9: First-Order Logic 13/60

14 Nested Quantifiers The order of quantification is very important: x y Loves(x, y) means Everybody loves somebody. or For every person, there is someone that person loves. y x Loves(x, y) means There is someone who is loved by everyone. Lecture 9: First-Order Logic 14/60

15 Connections between and Both quantifiers are connected with each other through negation. x Likes(x, Broccoli) x Likes(x, Broccoli) x Like(x, IceCream) x Likes(x, IceCream) De Morgan rules for quantified sentences: x P x P x P x P x P x P x P x P Lecture 9: First-Order Logic 15/60

16 Equality term 1 = term 2 is true under a given interpretation iff term 1 and term 2 refer to the same object. For example, x, y Brother(x, Richard) Brother(y, Richard) (x = y) means Richard has at least two brothers. Lecture 9: First-Order Logic 16/60

17 Exercises Represent the following sentences in FOL: Every student who takes French passes it. The best score in Greek is always higher than the best score in French. No person buys an expensive policy. Politicians can fool some of the people all of the time, and they can fool all of the people some of the time, but they can t fool all of the people all of the time. Source: Lecture 9: First-Order Logic 17/60

18 Prolog Prolog (Programming in Logic) is based on FOL calculus but it allows only Horn clauses. Prolog provides a way to develop a knowledge base and conduct inferences using first-order resolution. Prolog is widely used in various artificial intelligence applications, such as natural language processing, legal, medical and financial domains. Lecture 9: First-Order Logic 18/60

19 Prolog Programs A Prolog program = a set of facts and rules Facts = terms that are true in the knowledge base. Facts are written in a form of constants or predicates. For example, green(grass). mother(susan, john). All contants and predicates must start with a lower-case letter. Each fact must end with a period (.) Rules = FOL Horn clauses. For example, Parent(x, y) Female(x) Mother(x, y) Anyway, we usually write them using the connective. For example, Mother(x, y) Parent(x, y) Female(x) In Prolog, mother(x,y) :- parent(x,y), female(x). Lecture 9: First-Order Logic 19/60

20 Rules in Prolog [1] mother(x,y) :- parent(x,y), female(x). Left-hand side of :- is called head, the rest is body. The head will be true, if all parts of the body is true. Any literals starting with an upper-case letter is considered variables, e.g., X, Y, Person, etc. All variables in head are assumed to be universally quantified. Thus, the above sentence means For all X and Y, if X is a parent of Y and X is female then X is a mother of Y. Lecture 9: First-Order Logic 20/60

21 Rules in Prolog [2] Note that function is not allowed in Prolog. Every function is considered as a predicate. Variables in body can be considered universally quantified or existentially quantified. For example, hasachild(x) :- parent(x,y). 1. For all X and Y, if X is a parent of Y then X has a child. 2. For all X, X has a child if there exists Y such that X is a parent of Y. Lecture 9: First-Order Logic 21/60

22 Exercises Write the following statements into Prolog rules: 1. Everybody who has a child is happy. 2. For all X, if X has a child who has a sister then X has two children. (introduce a predicate hastwochildren) 3. For all X and Y, X is a grandfather of Y, if there exists Z that X is a parent, and Z is a parent of Y. 4. For all X, if X is written in a death note then X dies. Lecture 9: First-Order Logic 22/60

23 Recursive Rules [1] Let us consider a relation predecessor. We want to define it in terms of the parent relation. There are two definitions for predecessor: direct predecessor, and indirect predecessor. Direct predecessor: predecessor(x,y) :- parent(x,y). Indirect predecessor: X is a predecessor of Y, if there is a parentship chain of people between X and Y. predecessor(x,y) :- parent(x,z), parent(z,y). predecessor(x,y) :- parent(x,z), parent(z,a), predecessor(x,y) :-... parent(a,y). Lecture 9: First-Order Logic 23/60

24 Recursive Rules [2] A correct formulation of predecessor relation is needed to be correct at any depth. The key idea is to define it in terms of itself. predecessor(x,y) :- parent(x,y). (1) predecessor(x,y) :- parent(x,z), predecessor(z,y). (2) X is a predecessor of Y if either the rule (1) or (2) is true. Anyway, we need both of them to make the stopping condition for the recursive rule. Lecture 9: First-Order Logic 24/60

25 Prolog Interpreters Nowadays, there are several Prolog interpreters developed in both commercial and open-source software. We will use an open-source Prolog interpreter. YAP (Yet Another Prolog) is developed by LIACC/Universidade do Porto and at COPPE Sistemas/UFRJ. YAP is ported to several platforms: GNU/Linux: most distros provide a binary package. Mac OS X: via DarwinPorts MS Windows: Lecture 9: First-Order Logic 25/60

26 Using Prolog Interpreter [1] Before start the interpreter, we need to prepare the knowledge base for the Prolog. The prepared KB must be a text file containing facts, and rules. For example, family.pl parent(pam, bob). parent(tom, bob). parent(tom, liz). parent(bob, ann). parent(bob, pat). parent(pat, jim). female(pam). male(tom). male(bob). female(liz). female(ann). female(pat). male(jim). mother(x, Y) :- parent(x, Y), female(x). predecessor(x, Y) :- parent(x, Y). predecessor(x, Y) :- parent(x, Z), predecessor(z, Y). Lecture 9: First-Order Logic 26/60

27 Using Prolog Interpreter [2] Then, start the interpreter, it will show a prompt?- waiting for a query. Typhoon:~ cholwich$ yap % Restoring file /usr/local/lib/yap/startup YAP version Yap-5.1.1?- To exit, input a built-in fact halt.?- halt. To load the KB from file, use consult?- consult(family). If the file is ended with.pl, just put the file name. Otherwise,?- consult( family.pl ). Lecture 9: First-Order Logic 27/60

28 Querying After loading the KB into Prolog, we infer some conclusion from the KB by using querying. A query maybe a simple predicate,?- parent(tom,liz). yes A query may contain some variables, for example, we can ask Who is Tom s child? using a predicate parent,?- parent(tom,x). X = bob? ; X = liz? ; no Lecture 9: First-Order Logic 28/60

29 How Prolog answers questions? [1] A query in Prolog = a sequence of one or more goals. Prolog tries to satisfy all the goals. To satisfy all goals means to demonstrate that KB = α where α is the query. For example,?- predecessor(tom,pat). Prolog gets and evaluates the first rule having the same head (same number of arguments). predecessor(x,y) :- parent(x,y). predecessor(tom,pat) {X=tom, Y=pat} parent(tom,pat) no Lecture 9: First-Order Logic 29/60

30 How Prolog answers questions? [2] Prolog tries the next rule if the first rule does not satisfy the goal. predecessor(tom,pat) {X=tom, Y=pat} parent(tom,pat) no {X=tom, Y=pat} parent(tom,z), predecessor(z,pat). {Z=bob} predecessor(bob,pat). parent(bob,pat). yes Lecture 9: First-Order Logic 30/60

31 How Prolog answers questions? [3] :- predecessor(tom,pat). :- parent(tom,z), predecessor(z,pat). predecessor(x,y) :- parent(x,z), predecessor(z,y). {X=tom,Y=pat} parent(tom,bob) {Z=bob} :- predecessor(bob,pat). Lecture 9: First-Order Logic 31/60

32 How Prolog answers questions? [4] :- predecessor(bob,pat). predecessor(x,y) :- parent(x,y). :- parent(bob,pat). {X=bob,Y=pat} parent(bob,pat). Lecture 9: First-Order Logic 32/60

33 How Prolog answers questions? [5] Basically, Prolog conducts a backtracking search in order to satisfy the goal/query. Thus, each rule matched with the query will be tested one by one. Given 2 terms, they match if: they are identical the variables in both terms can be instantiated to objects to make the terms become identical. For example, date(d,m,2007) and date(d1,may,y1) parent(x,liz) and parent(x,y) Lecture 9: First-Order Logic 33/60

34 Matching General rules to decide matching between two terms S and T: 1. If S and T are constants then they match only if they are the same object. 2. If S is a variable, and T is anything, then they match, and S is instantiated to T. 3. If S and T are structures then they match only if 3.1 S and T have the same principle functor, and 3.2 all their corresponding components match. For example, triangle(point(1,1), A, point(2,3)) triangle(x, point(4,y), point(2,z)) Lecture 9: First-Order Logic 34/60

35 Exercises Will the following matching operations succeed or fail? 1. point(a,b) = point(1,2) 2. point(a,b) = point(x,y,z) 3. plus(2,2) = (2,D) = +(E,2) 5. triangle(p(-1,0),p2,p3) = triangle(point(x,y), p(1,1), P4) Lecture 9: First-Order Logic 35/60

36 Querying in Prolog: More Example Prolog uses backtracking in querying to check whether the given literal is true, or binding constants to variables. For example, if our KB contains two clauses: 1. member(x,[x T]). 2. member(x,[h T]) :- member(x,t). Case 1: user inputs a query member(a,[b,a,c]). 1. Match the given clause with the head of the first clause. This is unmatched (member(a,[b [a,c]]) member(x,[x T])) because X cannot be bound to two different values. 2. Match with the second clause. This is matched. Thus, X=a, H=b, and T=[a,c]. Then, Prolog needs to prove member(a,[a,c]). 2.1 Match member(a,[a [c]]) with the first clause. This is matched, then member(a,[a [c]]) is true. 3. Thus, member(a,[b,a,c]) is true. 4. Prolog answers yes. Lecture 9: First-Order Logic 36/60

37 Querying in Prolog: More Complicated Example Case 2: user inputs a query member(x,[a,b]). 1. Match with the head of the first clause. Then, member(a,[a [b]]). and X is bound to a. Prolog answers X=a. If the user wants more answers, he/she then inputs ;. 2. Prolog continues matching the rest which is the second clause. Then, It matches member(x,[a [b]]), and H=a, T=[b]. Then, member(x,t) is called recursively. Thus, Prolog needs to satisfy member(x,[b]). 2.1 Match the first clause. Then, member(b,[b []]) or X=b. 2.2 If the user still wants more answers, Prolog try to match the second clause. Thus, it matches member(x,[b []]) and calls member(x,[]) which cannot be matched with any clauses. 2.3 Thus, Prolog answers no. Lecture 9: First-Order Logic 37/60

38 Data Structure in Prolog The common and simple data structure in Prolog is list. Basically, a list is represented by a sequence of atoms in brackets. For example, [ann, tennis, tom, skiing], [],... Internally, lists are defined recursively. A list composes of two parts: head and tail as.(head, Tail). Head is the first item of the list; Tail is the list for the remaining part. We may write in form of [Head Tail]. Lecture 9: First-Order Logic 38/60

39 List Representation: Example [a,b,c,d] =.(a,.(b,.(c,.(d, [])))) = [a [b [c [ d []]]]] = [a,b [c,d]] a b c d [] Lecture 9: First-Order Logic 39/60

40 List Membership We can write Prolog rules/program to manipulate lists. Implement a rule member(x,l) that is true when object X is a member of list L. For example, member(a,[a,b,c]) is true member(a,[b,a,c]) is true member(a,[b,c,[a]]) is not true member([b,c],[a,[b,c]]) is true By thinking recursively, X is a member of L if either: 1. X is the head of L, or 2. X is a member of the tail of L. member(x,[x T]). member(x,[h T]) :- member(x,t). Lecture 9: First-Order Logic 40/60

41 Exercises 1. Write Prolog rules for concat(l1,l2,l3). that is true when concatenating two lists (L1 and L2) yields a list L3. For example, concat([a,b],[c],[a,b,c]) is true. 2. Write Prolog rules for last(x,l). that is true when X is the last member of L. For example, last(a,[b,c,a]) is true. Lecture 9: First-Order Logic 41/60

42 More Exercises 1. Define the relation reverse(list, ReversedList) that reverses lists. For example, reverse([a,b,c,d], [d,c,b,a]). 2. Define the predicate palindrome(list). A list is palindrome if it reads the same in the forward and in the backward direction. For example, palindrome([m,a,d,a,m]). 3. Define the relation shift(list1, List2) so that List 2 is List 1 shifted rotationally by one element to the left. For example, shift([1,2,3,4,5], [2,3,4,5,1]). Lecture 9: First-Order Logic 42/60

43 Arithmetic in Prolog [1] Some predefined operators can be used in Prolog: + addition - subtraction * multiplication / division ** power // integer division mod modulo Note that = in Prolog means term equality.?- X=1+2. X=1+2 The is operator will force evaluation.?- X is 1+2. X=3 Lecture 9: First-Order Logic 43/60

44 Arithmetic in Prolog [2] The comparison operators are also predefined in Prolog: > greater than < less than >= greater than or equal =< less than or equal =:= equal =\= not equal Lecture 9: First-Order Logic 44/60

45 Exercise 1. Define the relation length(list, N) that N is the number of members of List. 2. Define the predicate maxlist(list, Max) that Max is the maximum number in the list. 3. Define the predicate ordered(list) that is true when List is an ordered list of numbers. For example, ordered(1,3,4,5,7). 4. Define the predicate quicksort(list, SortedList) that conducts the quick sort on List yielding SortedList. Lecture 9: First-Order Logic 45/60

46 Structured Data and Data Abstraction [1] We can use Prolog for defining a logical database, and manipulating data structures. For example, using a Prolog program to manage studying/teaching time table. Lecture 9: First-Order Logic 46/60

47 Structured Data and Data Abstraction [2] courses.pl teaches(lecturer(cholwich), its451). sections(its451,[section(1, [time(tu,10,12):room(bkd,2401), time(th,10,12):room(bkd,2401)]), section(2, [time(mo,10,12):room(bkd,3216), time(th,14,16):room(bkd,3216)])]). teaches(lecturer(thanaruk), its453). sections(its453,[section(1, [time(tu,14,16):room(bkd,2401), time(th,13,15):room(bkd,2401)])]). Lecture 9: First-Order Logic 47/60

48 Structured Data and Data Abstraction [3] courses.pl :- use_module(library(lists)). occupied(room,day,time) :- sections(x,l), member(section(_,tr),l), member(time(day,s,f):r, TR), Room=R, S=<Time, F>=Time. Lecture 9: First-Order Logic 48/60

49 Exercises Add rules defining the following relations: 1. busy(lecturer,day,time) 2. teach_at(lecturer, Day, Time, Room) Lecture 9: First-Order Logic 49/60

50 Controlling Backtracking Uncontrolled backtracking causes inefficient program. Cut (!) is used to control backtracking. From a clause H :- B1, B2,..., Bm,!,..., Bn. If the user inputs a query H, each literal in the body of H will be executed one by one. At the moment that the cut is being executed, the system found some solution of the goals B1,..., Bm. When the cut is executed, the current solution of B1,..., Bm becomes frozen and all possible remaining alternatives are discarded. The system continues executing until Bn is satisfied. Then, H is satisfied. If the user still wants more answers, the system will try to backtrack to get alternative solutions. However, the literals B1,..., Bm will not be re-executed. Lecture 9: First-Order Logic 50/60

51 Cut: Example max(x,y,x) :- X>=Y. max(x,y,y) :- X<Y. This is a predicate to find the larger of two numbers denoted by X and Y. It means If X Y then Max = X. If X < Y then Max = Y. We can write another version of this predicate using cut: max(x,y,x) :- X>=Y,!. max(x,y,y). Prolog will try to satisfy the first rule. If Prolog can satisfy X Y, it will execute the cut. This means the solution will be frozen, no alternative solutions will be generated. However, if Prolog cannot satisfy the first rule, the second rule will be executed, and automatically Max = Y. Note that the rule order is important in this case. Lecture 9: First-Order Logic 51/60

52 Knowledge Engineering Knowledge engineering is the general process for constructing knowledge base. A knowledge engineer investigates a problem domain, learns what concepts are important in the domain, and creates a formal representation of the objects and relations in the domain. Domain Expert Knowledge Engineer Knowledge Acquisition Knowledge Base Lecture 9: First-Order Logic 52/60

53 Knowledge Engineering Process Knowledge engineering projects include the following steps: 1. Identify the task: Determining the range of questions that the KB will support. Determining the kinds of facts being available for each specific problem instance. 2. Assemble the relevant knowledge: Conducting knowledge acquisition to understand the scope of the KB and how the domain actually works. 3. Decide on a vocabulary of predicates, functions, and constants 4. Encode general knowledge about the domain 5. Encode a description of the specific problem instance 6. Pose queries to the inference procedure and get answers 7. Debug the knowledge base Lecture 9: First-Order Logic 53/60

54 Knowledge Engineering Example Identify the task C1 1 2 X1 X2 1 3 A2 A1 O1 2 We aim to analyze the circuit s functionality. For example, if all the inputs are 1, what is the output of gate A2? Lecture 9: First-Order Logic 54/60

55 Electronic Circuits Assemble the relevant knowledge Digital circuits compose of wires and gates. Signals flow along wires to the input terminals of gates. Each gate produces a signal on the output terminal that flows along another wire. There are four types of gates: AND, OR, XOR, and NOT which has only one input terminal. All gates have one output terminal. We focus on reasoning about functionality and connectivity. Thus, we do not talk about the wires, such as the paths the wires take, size or shape of the wires. Lecture 9: First-Order Logic 55/60

56 Electronic Circuits Decide on a vocabulary We need to distinguish a gate from other gates by using constants e.g. x1, x2, a1, o1, etc. Each gate has its type. We can set a predicate type(gate,gatetype) to refer to the type of the gate. For example, type(x1,xor), or type(a1,and). We use two predicates: in1 and in2 to specify inputs, and predicate out for output. For example, in1(x1,1), in2(x1,0). We need a predicate to show connectivity between gates such as connected(x1,o1,1) means the output of gate x1 is connected to the first input of gate o1. Finally, we need a predicate table for evaluation. For example, table(or,0,0,0). Lecture 9: First-Order Logic 56/60

57 Electronic Circuits Encode general knowledge of the domain Some rules and facts are needed to be prepared: circuit.pl in1(g,x) :- connected(g1,g,1), out(g1,x),!. in1(g,x) :- out(g,z), type(g,t), in2(g,y),!, table(t,x,y,z). in2(g,x) :- connected(g1,g,2), out(g1,x),!. in2(g,x) :- out(g,z), type(g,t), in1(g,y),!, table(t,y,x,z). out(g,z) :- type(g,t), in1(g,x), in2(g,y),!, table(t,x,y,z). table(or,0,0,0). table(or,0,1,1). table(or,1,0,1). table(or,1,1,1).... Lecture 9: First-Order Logic 57/60

58 Electronic Circuit Encode the specific problem instance We define the following circuit: 1 X1 0 O1 1 type(x1,xor). type(o1,or). in1(x1,1). in2(x1,1). connected(x1,o1,2). out(o1,1). circuit2.pl Lecture 9: First-Order Logic 58/60

59 Electronic Circuit Pose queries to the inference engine We then load the prepared KB to the Prolog interpreter, and we can query the KB. For example,?- in1(o1,x). X = 0 ; X = 1 ; no Debug the knowledge base We may need to debug the KB, if the KB does not work as we want. Lecture 9: First-Order Logic 59/60

60 References Ivan Bratko, Prolog: Programming for Artificial Intelligence, Pearson Education/Addison-Wesley, ISBN: Leo Sterling and Ehud Shapiro, The Art of Prolog, MIT Press, ISBN: Lecture 9: First-Order Logic 60/60

Symbolic Programming Declarative Programming

Symbolic Programming Declarative Programming CS370 Symbolic Programming Declarative Programming LECTURE 2: Introduction to Prolog park@cs.kaist.ac.kr Computer Science Department Korea Advanced Institute of Science and Technology http://nlp.kaist.ac.kr/~cs370

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

Logic as a Programming Language

Logic as a Programming Language Logic as a Programming Language! Logic can be considered the oldest programming language! Aristotle invented propositional logic over 2000 years ago in order to prove properties of formal arguments! Propositions

More information

Vibhav Gogate University of Texas, Dallas Artificial Intelligence: CS 4365 First-order Logic

Vibhav Gogate University of Texas, Dallas Artificial Intelligence: CS 4365 First-order Logic Artificial Intelligence: CS 4365 First-order Logic Vibhav Gogate University of Texas, Dallas First-order Logic Course Outline: Where are we? Introduction and Agents Search, Heuristics and CSPs Adversarial

More information

Logic Programming. fac(n-1,m) fac(n,n m) fac(1,1) ex) factorial program query. cf) in procedural programming. ?- fac(5,120). yes?- fac(5,x).

Logic Programming. fac(n-1,m) fac(n,n m) fac(1,1) ex) factorial program query. cf) in procedural programming. ?- fac(5,120). yes?- fac(5,x). Logic Programming Logic Programming = ex) factorial program query fac(1,1) fac(n-1,m) fac(n,n m)?- fac(5,120). yes?- fac(5,x). X=120 cf) in procedural programming x=1; for (i=1;i

More information

E.g., Brother(KingJohn,RichardTheLionheart)

E.g., Brother(KingJohn,RichardTheLionheart) First-Order Logic Chapter 8 Outline Why FOL? Syntax and semantics of FOL Using FOL Wumpus world in FOL Knowledge engineering in FOL 1 Pros and cons of propositional logic Propositional logic is declarative

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

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

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. 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

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

Introduction to Artificial Intelligence 2 nd semester 2016/2017. Chapter 8: First-Order Logic (FOL)

Introduction to Artificial Intelligence 2 nd semester 2016/2017. Chapter 8: First-Order Logic (FOL) Introduction to Artificial Intelligence 2 nd semester 2016/2017 Chapter 8: First-Order Logic (FOL) Mohamed B. Abubaker Palestine Technical College Deir El-Balah 1 Introduction Propositional logic is used

More information

Notes. Notes. Introduction. Notes. Propositional Functions. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry.

Notes. Notes. Introduction. Notes. Propositional Functions. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry Spring 2006 1 / 1 Computer Science & Engineering 235 Introduction to Discrete Mathematics Sections 1.3 1.4 of Rosen cse235@cse.unl.edu Introduction

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

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

COMP3411: Artificial Intelligence 8. First Order Logic

COMP3411: Artificial Intelligence 8. First Order Logic COMP9414/9814/3411 16s1 First Order Logic 1 COMP3411: Artificial Intelligence 8. First Order Logic Overview First Order Logic Universal and Existential Quantifiers Russell & Norvig, Chapter 8. Fun with

More information

Chapter 16. Logic Programming. Topics. Logic Programming. Logic Programming Paradigm

Chapter 16. Logic Programming. Topics. Logic Programming. Logic Programming Paradigm Topics Chapter 16 Logic Programming Introduction Predicate Calculus Propositions Clausal Form Horn Clauses 2 Logic Programming Paradigm AKA Declarative Paradigm The programmer Declares the goal of the

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

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

ITCS 6150 Intelligent Systems. Lecture 13 First-Order Logic Chapter 8

ITCS 6150 Intelligent Systems. Lecture 13 First-Order Logic Chapter 8 ITCS 6150 Intelligent Systems Lecture 13 First-Order Logic Chapter 8 First-order logic We saw how propositional logic can create intelligent behavior But propositional logic is a poor representation for

More information

CSE 473 Lecture 12 Chapter 8. First-Order Logic. CSE AI faculty

CSE 473 Lecture 12 Chapter 8. First-Order Logic. CSE AI faculty CSE 473 Lecture 12 Chapter 8 First-Order Logic CSE AI faculty What s on our menu today? First-Order Logic Definitions Universal and Existential Quantifiers Skolemization Unification 2 Propositional vs.

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

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

Last time: Logic and Reasoning

Last time: Logic and Reasoning Last time: Logic and Reasoning Knowledge Base (KB): contains a set of sentences expressed using a knowledge representation language TELL: operator to add a sentence to the KB ASK: to query the KB Logics

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

Set 7: Predicate logic Chapter 8 R&N. ICS 271 Fall 2015

Set 7: Predicate logic Chapter 8 R&N. ICS 271 Fall 2015 Set 7: Predicate logic Chapter 8 R&N ICS 271 Fall 2015 Outline New ontology objects, relations, properties, functions New Syntax Constants, predicates, properties, functions New semantics meaning of new

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

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

First-Order Predicate Logic. Introduction to Intelligent Systems

First-Order Predicate Logic. Introduction to Intelligent Systems First-Order Predicate Logic Introduction to Intelligent Systems First-Order (Predicate) Logic Propositional logic assumes the world contains facts Predicate logic (like natural language) assumes the world

More information

Prolog Programming. Chapter 5. Controlling Backtracking : 1/16/2010

Prolog Programming. Chapter 5. Controlling Backtracking : 1/16/2010 Prolog Programming Chapter 5 Controlling Backtracking : 1/16/2010 1 Chapter 5 Controlling Backtracking Preventing backtracking Examples using cut Negation as failure Problems with cut and negation 2 5.1

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

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

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

Logic Programming Paradigm

Logic Programming Paradigm Logic Programming Paradigm Sample Courseware Logic Programming Paradigm Logic programming offers a formalism for specifying a computation in terms of logical relations between entities. A logic program

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

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

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

First-Order Logic Syntax

First-Order Logic Syntax First-Order Logic Syntax Reading: Chapter 8, 9.1-9.2, 9.5.1-9.5.5 FOL Syntax and Semantics read: 8.1-8.2 FOL Knowledge Engineering read: 8.3-8.5 FOL Inference read: Chapter 9.1-9.2, 9.5.1-9.5.5 (Please

More information

Question about Final Exam. CS 416 Artificial Intelligence. What do we like about propositional logic? First-order logic

Question about Final Exam. CS 416 Artificial Intelligence. What do we like about propositional logic? First-order logic Page 1 Question about Final Exam CS 416 Artificial Intelligence I will have a date for you by Tuesday of next week. Lecture 13 First-Order Logic Chapter 8 First-order logic We saw how propositional logic

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

CSC384: Intro to Artificial Intelligence Prolog Tutorials 3&4. Hojjat Ghaderi, Fall 2006, University of Toronto

CSC384: Intro to Artificial Intelligence Prolog Tutorials 3&4. Hojjat Ghaderi, Fall 2006, University of Toronto CSC384: Intro to Artificial Intelligence Prolog Tutorials 3&4 1 Debugging Programs in Prolog We talked about the graphical debugger under Windows. Now, the text-based debugger: You can put a breakpoint

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

ACSC300: Logic Programming

ACSC300: Logic Programming ACSC300: Logic Programming Lecture 1: Introduction to Logic Programming and Prolog Harris Papadopoulos Course Aims This course aims to help you to: Understand a radically different programming paradigm:

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

Overview. Declarative Languages. operation of del. Deleting an element from a list. functions using del. inserting elements with del

Overview. Declarative Languages. operation of del. Deleting an element from a list. functions using del. inserting elements with del Overview Declarative Languages D7012E: Arithmetic and Backtracking Fredrik Bengtsson Some standard functions Operators Arithmetic The eight queens problem Controlling backtracking cut Deleting an element

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

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

Automated Reasoning PROLOG and Automated Reasoning 13.4 Further Issues in Automated Reasoning 13.5 Epilogue and References 13.

Automated Reasoning PROLOG and Automated Reasoning 13.4 Further Issues in Automated Reasoning 13.5 Epilogue and References 13. 13 Automated Reasoning 13.0 Introduction to Weak Methods in Theorem Proving 13.1 The General Problem Solver and Difference Tables 13.2 Resolution Theorem Proving 13.3 PROLOG and Automated Reasoning 13.4

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

CSE 20 DISCRETE MATH. Fall

CSE 20 DISCRETE MATH. Fall CSE 20 DISCRETE MATH Fall 2017 http://cseweb.ucsd.edu/classes/fa17/cse20-ab/ Final exam The final exam is Saturday December 16 11:30am-2:30pm. Lecture A will take the exam in Lecture B will take the exam

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

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

CSE 20 DISCRETE MATH. Winter

CSE 20 DISCRETE MATH. Winter CSE 20 DISCRETE MATH Winter 2017 http://cseweb.ucsd.edu/classes/wi17/cse20-ab/ Final exam The final exam is Saturday March 18 8am-11am. Lecture A will take the exam in GH 242 Lecture B will take the exam

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

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

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions): CS 70 Discrete Mathematics for CS Fall 2003 Wagner Lecture 7 This lecture returns to the topic of propositional logic. Whereas in Lecture 1 we studied this topic as a way of understanding proper reasoning

More information

(More) Propositional Logic and an Intro to Predicate Logic. CSCI 3202, Fall 2010

(More) Propositional Logic and an Intro to Predicate Logic. CSCI 3202, Fall 2010 (More) Propositional Logic and an Intro to Predicate Logic CSCI 3202, Fall 2010 Assignments Next week: Guest lectures (Jim Martin and Nikolaus Correll); Read Chapter 9 (but you can skip sections on logic

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

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

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

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

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

For next Tuesday. Read chapter 8 No written homework Initial posts due Thursday 1pm and responses due by class time Tuesday

For next Tuesday. Read chapter 8 No written homework Initial posts due Thursday 1pm and responses due by class time Tuesday For next Tuesday Read chapter 8 No written homework Initial posts due Thursday 1pm and responses due by class time Tuesday Any questions? Program 1 Imperfect Knowledge What issues arise when we don t know

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

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

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

Resolution (14A) Young W. Lim 6/14/14

Resolution (14A) Young W. Lim 6/14/14 Copyright (c) 2013-2014. 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 published by the Free

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

Part I CHR tutorial. Cambridge University Press Constraint Handling Rules Thom Fruhwirth Excerpt More information

Part I CHR tutorial. Cambridge University Press Constraint Handling Rules Thom Fruhwirth Excerpt More information Part I CHR tutorial We present the essentials of the Constraint Handling Rules (CHR) programming language by the use of examples in this Tutorial part. The first chapter Getting started is a step-by-step

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

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

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

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

Advanced Logic and Functional Programming

Advanced Logic and Functional Programming Advanced Logic and Functional Programming Lecture 1: Programming paradigms. Declarative programming. From first-order logic to Logic Programming. Programming paradigms Programming paradigm (software engineering)

More information

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions): CS 70 Discrete Mathematics for CS Spring 2005 Clancy/Wagner Notes 7 This lecture returns to the topic of propositional logic. Whereas in Lecture Notes 1 we studied this topic as a way of understanding

More information

First Order Logic Part 1

First Order Logic Part 1 First Order Logic Part 1 Yingyu Liang yliang@cs.wisc.edu Computer Sciences Department University of Wisconsin, Madison [Based on slides from Burr Settles and Jerry Zhu] slide 1 Problems with propositional

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 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

Lecture 6: Arithmetic and Threshold Circuits

Lecture 6: Arithmetic and Threshold Circuits IAS/PCMI Summer Session 2000 Clay Mathematics Undergraduate Program Advanced Course on Computational Complexity Lecture 6: Arithmetic and Threshold Circuits David Mix Barrington and Alexis Maciel July

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

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

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. Reading: Sethi, Chapter 11. Overview. Predicate Calculus. Substitution and Unication. Introduction to Prolog. Prolog Inference Rules

Prolog. Reading: Sethi, Chapter 11. Overview. Predicate Calculus. Substitution and Unication. Introduction to Prolog. Prolog Inference Rules Prolog Reading: Sethi, Chapter 11. Overview Predicate Calculus Substitution and Unication Introduction to Prolog Prolog Inference Rules Programming in Prolog - Recursion - List Processing - Arithmetic

More information

CSEN403 Concepts of Programming Languages. Topics: Logic Programming Paradigm: PROLOG Search Tree Recursion Arithmetic

CSEN403 Concepts of Programming Languages. Topics: Logic Programming Paradigm: PROLOG Search Tree Recursion Arithmetic CSEN403 Concepts of Programming Languages Topics: Logic Programming Paradigm: PROLOG Search Tree Recursion Arithmetic Prof. Dr. Slim Abdennadher 8.2.2015 c S. Abdennadher 1 Logic Programming versus Prolog

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

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

Logic programming I. Henrik Boström Stockholm University. Facts Queries Rules Terms Recursion Lists Negation

Logic programming I. Henrik Boström Stockholm University. Facts Queries Rules Terms Recursion Lists Negation Logic programming I Henrik Boström Stockholm University Facts Queries Rules Terms Recursion Lists Negation Logic programs A logic program consists of facts and rules. A logic program is executed by responding

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

Programming Language Concepts: Lecture 22

Programming Language Concepts: Lecture 22 Programming Language Concepts: Lecture 22 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 22, 15 April 2009 Logic programming

More information

CS 403: Introduction to logic programming

CS 403: Introduction to logic programming CS 403: Introduction to logic programming Stefan D. Bruda Fall 2017 KNOWLEDGE REPRESENTATION A proposition is a logical statement that can be either false or true To work with propositions one needs a

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

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

Artificial Intelligence

Artificial Intelligence CS344: Introduction to Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 11 Prolog Introduction PROgramming in LOGic Emphasis on what rather than how Problem in Declarative Form

More information

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic. Overview CS389L: Automated Logical Reasoning Lecture 6: First Order Logic Syntax and Semantics Işıl Dillig So far: Automated reasoning in propositional logic. Propositional logic is simple and easy to

More information

Knowledge Representation. CS 486/686: Introduction to Artificial Intelligence

Knowledge Representation. CS 486/686: Introduction to Artificial Intelligence Knowledge Representation CS 486/686: Introduction to Artificial Intelligence 1 Outline Knowledge-based agents Logics in general Propositional Logic& Reasoning First Order Logic 2 Introduction So far we

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

Chapter 2 & 3: Representations & Reasoning Systems (2.2)

Chapter 2 & 3: Representations & Reasoning Systems (2.2) Chapter 2 & 3: A Representation & Reasoning System & Using Definite Knowledge Representations & Reasoning Systems (RRS) (2.2) Simplifying Assumptions of the Initial RRS (2.3) Datalog (2.4) Semantics (2.5)

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

Logic Programming and Resolution Lecture notes for INF3170/4171

Logic Programming and Resolution Lecture notes for INF3170/4171 Logic Programming and Resolution Lecture notes for INF3170/4171 Leif Harald Karlsen Autumn 2015 1 Introduction This note will explain the connection between logic and computer programming using Horn Clauses

More information

Practice Problems: All Computer Science majors are people. Some computer science majors are logical thinkers. Some people are logical thinkers.

Practice Problems: All Computer Science majors are people. Some computer science majors are logical thinkers. Some people are logical thinkers. CSE 240, Fall, 2013 Homework 2 Due, Tuesday September 17. Can turn in class, at the beginning of class, or earlier in the mailbox labelled Pless in Bryan Hall, room 509c. Practice Problems: 1. Consider

More information