Logic Programming Paradigm

Size: px
Start display at page:

Download "Logic Programming Paradigm"

Transcription

1 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 consists of a collection of logic statements describing a certain state of affairs. In order to write a program in such a language, the programmer must first describe all the relevant logical relationships between the various entities. A computation in essence, amounts to determining whether a particular conclusion follows from those logical statements. The implementation of a logic programming language provides an automatic theorem prove which is used to establish the validity of the conclusion. An important point to writing logic programs is to model the domain (or state of affairs) in terms of logical relations. The relative ease with which this can be done depends on the domain itself. The following section provides some insights on how to represent "ordinary" statements in logic programming. A Logical Data Model operates with so-called Facts. Generally speaking, fact is any expression which can be interpreted as True or False. Examples: Alex is a nice guy. 25 > = 66 Smith is a student and he got "2" for examination on Software Paradigms Facts are presented as so-called structured terms that are made of several components. 1 Predicates (Structured Terms) file:///e /LV_CD/wbtmaster/main_library/swp4.htm (1 of 32) [10/16/2002 4:15:41 PM]

2 A structured term is syntactically formed by a functor (also called a predicate symbol) and a list of arguments. The list of arguments appears between parentheses. Each argument is separated from the following one by a comma. Examples: Functor Arguments Alex is a nice guy. niceguy (Alex) 25 > 36 greaterthan (25,36) = 66 plus (25,41,66) Smith is a student and he got "2" for examination on Software Paradigms exam ('Smith','Software Paradigms',2) A structured term is syntactically formed by a functor (also called a predicate symbol) and a list of arguments. The list of arguments appears between parentheses. Each argument is separated from the following one by a comma. Each argument of a predicate is a so-called term, for example, it can be another predicate (structured term). The number of arguments of a structured term is called its arity. Examples: greaterthan(9, 6) exam(a, b, h(c,d)) plus(2, 3, 5) An important point to mention is that a structure is simply a mechanism for combining terms together, thus forming more complex ones but without performing any implicit evaluation. So for instance, in the last example above, the integers 2, 3, and 5 are combined with the functor plus. An equally valid combination, albeit a slightly misleading one, could be plus(2, 3, 7). If evaluated, plus(2,3,5) is True plus(2,3,7) is False file:///e /LV_CD/wbtmaster/main_library/swp4.htm (2 of 32) [10/16/2002 4:15:41 PM]

3 An atom can be formed in four ways: A letter, which can possibly be followed by other letters (either case), digits, and the underscore character. Examples: a greaterthan two_b_or_not_2_b A string of special characters such as: + - * / \ = ^ < > :. # $ & Examples: <> ##&& ::= A string of any characters enclosed within single quotes. Examples: 'ABC' '1234' 'a<>b' In the third case above, if what appears between the single quotes is a valid atom as specified by one of the first two cases, then the quotes are optional. Thus, 'abc' and abc represent the same atom. Applications involving heavy numerical calculations are rarely written in Logic Programming Languages. In fact, Logic Paradigm is not particularly well suited to write such applications. Nevertheless, the paradigm provides representation for integers and real numbers. The following examples illustrate integer representation: Examples: Real numbers can be written in standard or scientific notation. A decimal point must appear in all real numbers and there must be at least one digit on either side of it. Several points with respect to the representation of numbers are implementation dependent. A brief list of some of these points follows. The actual range of numbers (real and integer) that can be represented. Examples: e e-3-2.6e-2 file:///e /LV_CD/wbtmaster/main_library/swp4.htm (3 of 32) [10/16/2002 4:15:41 PM]

4 A variable is a name for value which can change while an evaluation is running. Examples: StudentName may be 'Johns', 'Mayer', 'Ivanov', etc. ExaminationMark may be 1, 2, 3, 4 and 5 GoodGuy may be True and False Set of all possible values which may have a particular variable is called a variable scope or a variable range. Please note the following (!) A predicate (structured term) having all arguments as constants is called a fact. A particular Fact can be either true or false. Example: greaterthan (25,36) is False plus (25,41,66) is True Why? Because we know formal rules to validate the facts and can communicate these rules to computers, i.e. an algorithm can be defined. Such terms are called computational terms. niceguy(alex) is True exam('smith','software Paradigms') is False Why? Because we know that from our own experience which cannot be formalized as an algorithm. We can simply put such knowledge into a computer's memory by listing all facts which are valid. For example, we can list all guys who considered to be nice or list all students who pass an examination on software paradigms. Such facts are called basic facts or database facts. Formally speaking, a logic programming paradigm heavily rely on a database of persistent data objects which list all basic facts which are valid. If a particular basic fact cannot be found in such database, it is considered to be false. A predicate (structured term) having at least one variable argument is called a file:///e /LV_CD/wbtmaster/main_library/swp4.htm (4 of 32) [10/16/2002 4:15:41 PM]

5 logical function or simply predicate. All variables used for definition of such predicate are called free variables. A particular logical function maps each combination of free variable values onto True/False boolean value. In other words, predicate can be true or false depending on a particular combination of free variable values. Example: greaterthan (25,X) is a function of variable "X" F(X) greaterthan(25,x) is True if X = 26, 27, etc. the same predicate is false if X = 25, 24, etc. Example: plus (X,Y,66) is a function of variables "X and Y" F(X,Y) plus(x,y,66) is True if {X,Y} = {1,65}, {2,64}, {3,63}, etc. the same predicate is false if, for example, {X,Y} = {30,45} or {X,Y} = {55,55}. Example: niceguy(x) is is a function of variable "X" F(X) niceguy(x) is True if X = "Alex" and "Alex" can be found among persistent database objects "niceguy". Example: exam(studentname,vo) is a function of variables "StudentName and VO" F(StudentName,VO) exam(studentname,vo) True if StudentName = "Alex", VO = "Software Paradigm" and ("Alex","Software Paradigms" can be found among persistent database objects "exam"), 2 Logical Operations and Composite Predicates In order to specify a computation in terms of logical relations between entities, we need a mechanism to compose a new predicate of one or more simple predicates. Moreover, we need to define special rules for evaluating such composite predicates. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (5 of 32) [10/16/2002 4:15:41 PM]

6 This section describes the predicate composition techniques and rules necessary to evaluate composite predicates. 2.1 Logical Operations Syntactically, a predicate can be composed of one or more simple predicates using logical operation "&" logical "and", " " logical "or", " " logical "not" and brackets. Example: greaterthan(25,36) & plus(55,11,66) is True because greaterthan(25,36) is True and plus(55,11,66) is True Example: niceguy('alex') exam('alex','software Paradigms') is True if one of the facts: niceguy('alex') or exam('alex','software Paradigms') can be found in the database. The operator precedence for the '&' and ' ', operators follow the standard precedence rules, i.e. '&' binds stronger than ' '. Thus, F1 & F2 F3 == ( F1 & F2 ) F3 Explicit use of parenthesis, as in predicate above, is required to override this default precedence. Thus if the intention is for the ' ' operator to bind stronger in the above expression, it has to be written as F1 & (F2 F3) Example: niceguy('alex') & niceguy('tom') exam('tom', 'Software Paradigm',1) is True if both basic facts: niceguy('alex') and niceguy('tom') are True or the other fact exam('tom','software Paradigms',1) is true. In other words, if the fact exam('tom','software Paradigms',1) is true, it is already sufficient for the whole expression to be valid (true). Example: file:///e /LV_CD/wbtmaster/main_library/swp4.htm (6 of 32) [10/16/2002 4:15:41 PM]

7 niceguy('alex') & (niceguy('tom') exam('tom', 'Software Paradigm',1)) is True if basic fact: niceguy('alex') is true and the composite predicate niceguy('tom') or exam('tom','software Paradigms',1) is true. In other words, if the fact exam('tom','software Paradigms',1) is true, it is not sufficient for the whole expression to be valid (true). 2.2 Quantifiers Predicates may also include variable quantifiers, specifically: the existential quantifier, denoted by the symbol, and the universal quantifier, denoted by the symbol These quantifiers quantify variables. An existentially quantified variable, say X, is written " " and is read as "there exists an X such that...". A universally quantified variable is written as " " and is read as "for all X...". Quantification is applied to a formula and is written preceding it. For example, x (greaterthan(y,x) & greaterthan(12,y)) would be read as "there exists an X such that X is less than Y and Y is less than 12". The formula to which the quantification is applied is called the scope of quantification. Occurrences of quantified variables in the scope of quantification are said to be bound (existentially or universally). The scope is normally obvious from the written expressions, but if ambiguities might otherwise arise, we will use parenthesis to delimit scope. Informally, the formula " X ( <expr> )" asserts that there exists at least one value of X (from among its range of values) such that is true. This assertion is false only when no value of X can be found to satisfy. On the other hand, if the assertion is true, there may be more than one such value file:///e /LV_CD/wbtmaster/main_library/swp4.htm (7 of 32) [10/16/2002 4:15:41 PM]

8 of X, but we don't care which (!). Thus, the truth of an existentially quantified expression is not a function of the quantified variable(s). As an example, consider the unquantified expression greaterthan(y,x) & greaterthan(12,y) == F(X,Y) and suppose X ranges over {4,15} and Y over {7,14}. The truth table for the expression is: X Y F(X,Y) 4 7 true 15 7 false 4 14 false false Now consider the same expression but with X existentially quantified: X(greaterThan(Y,X) & greaterthan(12,y)) == F(Y) Since we don't care which value of X makes the expression true as long as there is at least one, its truth depends only on the unbound variable Y: The truth table for the expression is: Y F(Y) 7 true 14 false The truth of a quantified expression does depend, of course, on the range of permitted values of the quantified variables. Let's turn now to the universal quantifier. Informally, the formula " X ( <expr> )" asserts that for every value of X(from among its range of values) <expr> is true. Like the existential quantifier, the truth of an existentially quantified expression is not a function of the quantified variable(s). As an example, consider the unquantified expression greaterthan(y,x) greaterthan(12,y) == F(X,Y) and suppose X ranges over {4,15} and Y over {7,14}. The truth table for the expression is: X Y F(X,Y) 4 7 true 15 7 true 4 14 true false file:///e /LV_CD/wbtmaster/main_library/swp4.htm (8 of 32) [10/16/2002 4:15:41 PM]

9 Now consider the same expression but with X universally quantified: X(greaterThan(Y,X) greaterthan(12,y)) == F(Y) In a sense, like the existentially quantified variable, we don't care what the values of X are, as long as every one of them makes the expression true for any given Y. Thus its truth table is: The truth table for the expression is: Y F(Y) 7 true 14 false Note that the different types of quantifiers can be mixed. But note also that their order is significant, i.e. x y ( <expr> ) is not the same as y x ( <expr> ). Suppose, for example, a predicate is_a_mother(m,ch) defines a set of database facts " M is the mother of Ch". Ch M (is_a_mother(m,ch)) asserts that everyone has a mother. Whereas, M Ch (is_a_mother(m,ch)) asserts that there is a single individual (M) who is the mother of everyone! Let us now be more precise about the valid forms of predicates involving variables. Such valid forms are called well-formed formulae (WFF) and are defined as follows: 1. F(X1,... Xn) is a WFF where X1, X2,.. are called free variables Example: niceguy(x), exam(x,y,m), greaterthan(a,b) 2. F1 & F2 and F1 F2 are WFFs if F1 and F2 are WFFs Example: niceguy(x) & niceguy(y) exam(x, S, "1") 3. (F) is a WFF if F is a WFF Example: niceguy(x) & (niceguy(y) exam(x, S, "1")) 4. x (F(X)) and x (F(X)) are WFFs if F(X) is a WFF with a free occurrence of the file:///e /LV_CD/wbtmaster/main_library/swp4.htm (9 of 32) [10/16/2002 4:15:41 PM]

10 variable X. In this case, X is called a bound variable in the scope of F(x). Example: x(niceguy(x) & exam(x, S, "1")) 3 Rules of Inference Any programming paradigm deals with organizing computations. In logic programming paradigm computation are defined in a form of rules of inference. Rules of inference, in turn, are defined in a form of so-called clauses. 3.1 Head and Body The general form of clauses is as follows: [head] :- [body] Note, these two component (body and head) may be also called conclusion and premise respectively. [conclusion] :- [premise] where body (premise) is a WFF (logical expression) head (conclusion) is a predicate If we do not use variables, both components (i.e. head and body) are facts. The rule is interpreted as follows: "If a body is valid (true) then head is also valid (true) by definition" file:///e /LV_CD/wbtmaster/main_library/swp4.htm (10 of 32) [10/16/2002 4:15:41 PM]

11 For example, we can define the following rule of inference: humanbeing('alex'):-goodguy('alex') if Alex is a good guy, then he is a human being. Suppose, fact enrollvo('alex', 'Programming') is true if a student "Alex" is enrolled for the course "Programming". Suppose also, the fact locvo('programming', 'Thursady, 'Room 22') is true if the classes on Programming take place in room 22 on Thursday. For example, we can define the following rule of inference: mustgo('alex', 'Thursday','Room 22') :- enrollvo('alex', 'Programming') & locvo('programming', 'Thursday', 'Room 22') meaning that the fact mustgo('alex', 'Thursday', 'Room 22') is true if both facts enrollvo('alex', 'Programming') and locvo('programming', 'Thursday', 'Room 22') are true. Actually, all the examples above are not very illustrative because rules of inference are almost never defined without variables. If we use variables, both components (i.e. head and body) are predicates. The rule is interpreted as follows: "If a body is valid (true) for a particular combination of values of free variables then the head is also valid (true) for the same combination of values of free variables" For example, we can define the following rule of inference: humanbeing(x):-goodguy(x) any (!) good guy is a human being. Suppose, predicate enrollvo(student, Subject) is true if a student is enrolled for a course on this particular subject. Suppose also, the predicate locvo(subject, Day, Room) is true if classes on this particular subject takes place in this room and on this day. For example, we can define the following rule of inference: mustgo(student, Room, Day, Subject) :- enrollvo(student, Subject) & locvo(subject, Day, Room) file:///e /LV_CD/wbtmaster/main_library/swp4.htm (11 of 32) [10/16/2002 4:15:41 PM]

12 meaning that a particular student should be in a particular room on a stipulated day, if he/she enrolled for a classes and this classes take place in this room on that day. Predicates enrollvo and locvo definitely operates on database facts, i.e. system should search an internal database to find whether, for example, the fact enrollvo('alex', 'Programming') is true or false. Suppose, the database looks as follows: locvo( Subject Day Room) Hypermedia Monday Room 22 Databases Tuesday Room 23 Programming Thursday Room 22 enrollvo( Student Subject) Palina Hypermedia Palina Programming Alex Databases Alex Programming Result of application the following rule of inference: mustgo(student, Room, Day, Subject) :- enrollvo(student, Subject) & locvo(subject, Day, Room) to the above mentioned basic facts is a number of inferred facts (!) can be seen as the following table: mustgo( Student Room Day Subject) Palina Room 22 Monday Hypermedia Palina Room 22 Thursday Programming Alex Room 23 Tuesday Databases Alex Room 22 Thursday Programming In other words, the system automatically infer such facts as mustgo(palina,room 22, Monday, Hypermedia) is true: "Palina should go to Room 22 on Monday to participate in classes on Hypermedia" mustgo('alex','room 22', 'Monday', 'Hypermedia') is false: "Alex has nothing to do in Room 22 on Monday" The last example suggest that perhaps we should simplify the rule by removing the Subject variable from the head: mustgo(student, Room, Day) :- enrollvo(student, Subject) & locvo(subject, Day, Room) file:///e /LV_CD/wbtmaster/main_library/swp4.htm (12 of 32) [10/16/2002 4:15:41 PM]

13 and inferring the following facts: mustgo( Student Room Day) Palina Room 22 Monday Palina Room 22 Thursday Alex Room 23 Tuesday Alex Room 22 Thursday Actually, this rule mustgo(student, Room, Day) :- enrollvo(student, Subject) & locvo(subject, Day, Room) is erroneous because free variables in the head of the rule are not identical to the variables in the body. Following to the formal definition of a rule of inference: "If a body is valid (true) for a particular combination of values of free variables then the head is also valid (true) for the same combination of values of free variables" the system simply cannot make conclusion on whether the expression mustgo('alex','room 22', 'Thursday') is true or false. In order to verify the fact: mustgo('alex','room 22', 'Thursday'), the system should evaluate the following expression: enrollvo('alex', Subject) & locvo(subject, 'Room 22', 'Thursday') Obviously the expression is not a fact and depends on a particular value of variable "Subject". For example, it is true, if subject is "programming" and false for any other value. enrollvo('alex', 'Programming') & locvo('programming', 'Room 22', 'Thursday') is true enrollvo('alex', 'Databases') & locvo('databases', 'Room 22', 'Thursday') is false There is of course an obvious solution for the problem: existential quantifier ( ). Thus, we can define the rule as the following: mustgo(student, Room, Day) :- Subject (enrollvo(student, Subject) & locvo(subject, Day, Room)) The above predicate (body) is true if there exists at least one subject such that the condition file:///e /LV_CD/wbtmaster/main_library/swp4.htm (13 of 32) [10/16/2002 4:15:41 PM]

14 enrollvo(student, Subject) & locvo(subject, Day, Room) is true. In other words, the fact mustgo('alex','room 22', 'Thursday') is definitely true since there exists a subject, for example, "Programming" such that enrollvo('alex', 'Programming') & locvo('programming', 'Room 22', 'Thursday') is true. mustgo( Student Room Day) Palina Room 22 Monday Palina Room 22 Thursday Alex Room 23 Tuesday Alex Room 22 Thursday 3.2 Recursion Recursive definition of rules of inference is a very powerful and commonly used method of logic programming. Suppose, we have a predicate parent(g,d) the predicate identifies whether a person D is a child of person G. We can easily define a new predicate descendent(g,d) that identifies whether a person D is a descendent of person G as descendent(g,d):-parent(g,d) X (parent(g,x) & descendent(x,d)) Note that rules like this one, can be defined more clearly using a number of rules of inference with one and the same head. descendent(g,d):-parent(g,d) descendent(g,d):- X (parent(g,x) & descendent(x,d)) first rule for finding direct descendent just copy all facts "parent" as facts "descendent" the second rule uses the same head predicate (i.e., recursion) to find indirect descendent. Here, if the inferred fact is true in accordance with one of the rules, it is considered file:///e /LV_CD/wbtmaster/main_library/swp4.htm (14 of 32) [10/16/2002 4:15:41 PM]

15 to be true generally. Consider the following genealogy tree: It may be described as the following facts: parent( G D) Nick Pauline Pauline Alex Pauline Paul Alex Tom Application of the rule: descendent(g,d):-parent(g,d) results in the following inferred facts descendent( G D) Nick Pauline Pauline Alex Pauline Paul Alex Tom Application of the rule: descendent(g,d):- X (parent(g,x) & descendent(x,d)) results in the following inferred facts descendent( G D) X Nick Alex Pauline parent('nick','pauline') & descendent('pauline','alex') Nick Paul Pauline parent('nick','pauline') & descendent('pauline','paul') Pauline Tom Alex parent('pauline','alex') & descendent('alex','tom') Nick Tom Pauline parent('nick','pauline') & descendent('pauline','tom') file:///e /LV_CD/wbtmaster/main_library/swp4.htm (15 of 32) [10/16/2002 4:15:41 PM]

16 3.3 Inferred Calculations In Logic Programming, calculation are performed by means of computational terms looking as, for example, follows: plus(v1,v2,r) the predicate is true if R = V1 + V2; mult(v1,v2,r) the predicate is true if R = V1 * V2; etc. For example, plus(10,20,30) is true; plus(12,14,30) is false; plus(10,20,200) is true; plus(12,14,300) is false; Consider, for example, a well-known example of a so-called bill of materials that identify which components and in which amount are needed to assembly a particular product / another component: It may be described as the following facts: need( P C Q) D_A D_B 5 D_B D_D 3 D_B D_C 8 D_D D_E 4 The following rules identify how many direct and indirect components are needed to assembly a particular product / component need+(p,c,q):-need(p,c,q) need+( P,C,Q):- X Q1 Q2(need(P,X,Q1) & need+(x,c,q2) & mult(q1,q2,q)) file:///e /LV_CD/wbtmaster/main_library/swp4.htm (16 of 32) [10/16/2002 4:15:41 PM]

17 Application of the rule: need+(p,c,q):-need(p,c,q) results in the following inferred facts need+( P C Q) D_A D_B 5 D_B D_D 3 D_B D_C 8 D_D D_E 4 Application of the rule: need+( P,C,Q):- X Q1 Q2(need(P,X,Q1) & need+(x,c,q2) & mult(q1,q2,q)) results in the following inferred facts need+( P C Q) X Q1 Q2 D_A D_D 15 D_B 5 3 need(d_a,d_b,5) & need+(d_b,d_d,3) & mult(5,3,15) D_A D_C 40 D_B 5 8 need(d_a,d_b,5) & need+(d_b,d_c,8) & mult(5,8,40) D_B D_E 12 D_C 3 4 need(d_b,d_c,3) & need+(d_c,d_e,4) & mult(3,4,12) D_A D_E 60 D_B 5 12 need(d_a,d_b,5) & need+(d_b,d_e,12) & mult(5,12,60) 3.4 Functions and Variables Defining calculations as computational predicates involving multiple bound variable as, for example, need+( P,C,Q):- X Q1 Q2(need(P,X,Q1) & need+(x,c,q2) & mult(q1,q2,q)) may constitute a serious problem. Functions provide much more straight and simple way to define calculations. A particular function may be applied to a number of free variables and be reused further as a variable. For example, the previously defined rule of inference need+ may be defined in much more clear way as: need+( P,C,(Q1 * Q2)):- X (need(p,x,q1) & need+(x,c,q2) ) where notation (Q1 * Q2) is used in a normal mathematical way file:///e /LV_CD/wbtmaster/main_library/swp4.htm (17 of 32) [10/16/2002 4:15:41 PM]

18 Application of this rule need+( P,C,(Q1 * Q2)):- X (need(p,x,q1) & need+(x,c,q2) ) results in the same list of inferred facts, but the inference procedure is much simple need+( P C Q) X Q1 Q2 D_A D_D 15 D_B 5 3 need(d_a,d_b, 5) & need+(d_b,d_d, 3) D_A D_C 40 D_B 5 8 need(d_a,d_b, 5) & need+(d_b,d_c, 8) D_B D_E 12 D_C 3 4 need(d_b,d_c,3) & need+(d_c,d_e,4) D_A D_E 60 D_B 5 12 need(d_a,d_b,5) & need+(d_b,d_e,12) 4 Goals (Queries) The term "executing programs" in logic programming typically refers to verification of one or a collection of predicates with respect to a given set of rules of inference and basic facts. Thus, a calculation in logic programming is identified by the following components: database of basic facts set of rules of inference a given goal A computation in logic programming is initiated by a goal. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (18 of 32) [10/16/2002 4:15:41 PM]

19 In a general case we should distinguish between three different types of goals: Verifier Goal Finder Goal Doer Goal 4.1 Verifier Goal Example Database of basic facts: locvo( Subject Day Room) Hypermedia Monday Room 22 Databases Tuesday Room 23 Programming Thursday Room 22 enrollvo( Student Subject) Palina Hypermedia Palina Programming Alex Databases Alex Programming Rules of inference: mustgo(student, Room, Day) :- Subject (enrollvo(student, Subject) & locvo(subject, Day, Room)) Goal (Query): file:///e /LV_CD/wbtmaster/main_library/swp4.htm (19 of 32) [10/16/2002 4:15:41 PM]

20 ? mustgo('alex', 'Room 22', 'Thursday') The output will be success or failure, depending whether the validity of this predicate (fact) could be verified or not. In this particular case, the calculation will produce a true value as a result. Example A verifier goal is a predicate without free variables, i.e. it is a fact which can be true or false depending on a given set of basic facts and rules of inference. For instance, given that we have facts and rules describing a genealogy tree, Consider the following genealogy tree: Rules of Inference: descendent(g,d):-parent(g,d) descendent(g,d):- X (parent(g,x) & descendent(x,d)) we could issue the following verifier goal:? descendent('nick','tom') This verifier goal can be paraphrased as "Is Tom a descendent of Nick?" In this case, the engine would simply return yes or no depending on the predicates of the program. Another verifier goal may look as follows:? X (parent(x,'alex') & parent(x,'paul')) The second verifier goal corresponds to the question "Are Alex and Paul siblings?". The last query is somewhat more complicated. It is composed of a conjunction of two goals which basically attempt to verify the following: "Is there a single person (X) who is a parent of Alex and parent of Paul?". Note, here we use variables to define a verifier goal, but this variable is bound with the existential quantifier. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (20 of 32) [10/16/2002 4:15:41 PM]

21 Of course, goals are interpreted in a certain environment. Consider, for example, facts and rules describing a bill of materials: Rulees of Inference need+(p,c,q):-need(p,c,q) need+( P,C,(Q1*Q2)):- X Q1 Q2(need(P,X,Q1) & need+(x,c,q2)) In this environment, we could issue the following verifier goals:? X (need+('d_a','d_e',x) This verifier goal can be paraphrased as "Do we need a component "D_E" to assembly "D_A"?". Another verifier goal may look as follows:? X Y (need+(y,'d_e',x) & greaterthan(x,100)) "Are there any components where the component 'D_E' is reused in amount greater than 100?" 4.2 Finder Goal In cases in which a goal contains unbound variables, such goal is called a finder goal. A finder goal requests the logic programming system to show particular values of free variables that make this goal. To clarify this last point, let's consider some sample queries. Database of basic facts: file:///e /LV_CD/wbtmaster/main_library/swp4.htm (21 of 32) [10/16/2002 4:15:41 PM]

22 locvo( Subject Day Room) Hypermedia Monday Room 22 Databases Tuesday Room 23 Programming Thursday Room 22 enrollvo( Student Subject) Palina Hypermedia Palina Programming Alex Databases Alex Programming Rules of inference: mustgo(student, Room, Day) :- Subject (enrollvo(student, Subject) & locvo(subject, Day, Room)) Finder Goal:? mustgo('alex', X, 'Thursday') The engine is requested to show all the values satisfying the mustgo. In this particular case, the calculation will produce X = "Room 22" as a result. Finder Goal:? mustgo('alex', X, Y) The engine is requested to display all paars of values (X,Y) such that the predicate mustgo ('Alex',X,Y) is valid. In this particular case, the calculation will produce {<X,Y>} = {<Room 23, Tuesday>,<Room 22, Thursday>} as a result. Example Example "genealogy tree" Rules of Inference: descendent(g,d):-parent(g,d) descendent(g,d):- X (parent(g,x) & descendent(x,d)) Finder Goal: file:///e /LV_CD/wbtmaster/main_library/swp4.htm (22 of 32) [10/16/2002 4:15:41 PM]

23 ? descendent('nick',x) In this case, the engine will show all values for the variable X that satisfy the descendent('nick',x) predicate. X = {Pauline,Alex,Paul,Tom} Finder Goal:? X (parent(x, 'Alex') & parent(x, Y)) This goal can be paraphrased as "Get all siblings of a person "Alex"". This is interesting to note, despite the fact that we use two variables to define the goal X and Y, the system is requested to show just values for the variable Y that satisfy the X (parent(x, 'Alex') & parent(x, Y)) predicate. Variable X is bound with the existential quantifier and we do not care which particular value of the variable X satisfy the conditions parent(x, 'Alex') & parent(x, Y). Example Example "Bill of Materials": Rulees of Inference need+(p,c,q):-need(p,c,q) need+( P,C,(Q1*Q2)):- X Q1 Q2(need(P,X,Q1) & need+(x,c,q2)) Finder Goal:? need+('d_b',x, Y) Actually, we are asking systems to display list of materials needed to produce a component "D_B" and to provide additional information on quantity of the materials. <X,Y> = {<D_D, 3>, <D_C, 8>, <D_D, 12>} 4.3 Doer Goal file:///e /LV_CD/wbtmaster/main_library/swp4.htm (23 of 32) [10/16/2002 4:15:41 PM]

24 Another kind of goals in logical programming is called a Doer Goal. As the name suggests, these statements are used to communicate specific information to modify environment for other goals. In a simplest case, a doer goal simply adds/deletes basic facts. Database of basic facts: locvo( Subject Day Room) Hypermedia Monday Room 22 Databases Tuesday Room 23 Programming Thursday Room 22 enrollvo( Student Subject) Palina Hypermedia Palina Programming Alex Databases Alex Programming Rules of inference: mustgo(student, Room, Day) :- Subject (enrollvo(student, Subject) & locvo(subject, Day, Room)) Doer Goals:? delete(locvo('programming', 'Thursday', 'Room 22'))? add(locvo('software Paradigms', 'Thursday', 'Room 21')) Database of basic facts (Modified): locvo( Subject Day Room) Hypermedia Monday Room 22 Databases Tuesday Room 23 Software Paradigms Thursday Room 21 enrollvo( Student Subject) Palina Hypermedia Palina Programming Alex Databases Alex Programming Database of basic facts: file:///e /LV_CD/wbtmaster/main_library/swp4.htm (24 of 32) [10/16/2002 4:15:41 PM]

25 locvo( Subject Day Room) Hypermedia Monday Room 22 Databases Tuesday Room 23 Software Paradigms Thursday Room 21 enrollvo( Student Subject) Palina Hypermedia Palina Programming Alex Databases Alex Programming Doer Goals:? add(enrollvo('alex', 'Software Paradigms'))? delete(enrollvo('alex', 'Programming'))? add(enrollvo('palina', 'Software Paradigms')) Database of basic facts (Modified): locvo( Subject Day Room) Hypermedia Monday Room 22 Databases Tuesday Room 23 Software Paradigms Thursday Room 21 enrollvo( Student Subject) Palina Hypermedia Palina Programming Alex Databases Alex Software Paradigms Palina Software Paradigms 5 Some Implementation Issues The term "executing programs" in logic programming typically refers to verification of one or a collection of predicates with respect to a given set of rules of inference and basic facts. This verification is done according to a specific algorithm which will be presented in the next section. The term resolution mechanism is often used to refer to this algorithm. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (25 of 32) [10/16/2002 4:15:41 PM]

26 5.1 Backtracking Resolution Algorithm How do deductive DBMS infer a response to a given goal? Given a program and an initial query, the resolution algorithm to verify this query can be described as follows. Phase 1: A given goal is reduced to simple sub-goals corresponding to basic facts or procedures. The process is repeated until the goal is represented as a tree having only simple sub-goals corresponding to basic facts or procedures as leaves. Such tree is called a tree on inference or resolution tree (see example below). Phase 2: Searching for values for (Verifying) the simple sub-goals and putting them together to form the response. This process is actually called a backtracking. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (26 of 32) [10/16/2002 4:15:41 PM]

27 Finder goals are interpreted in a similar way. Consider the Finder Goal:? P1(X) Phase 1: The system built a resolution tree as above: Phase 2: A particularily selected term is used to select a number of basic facts which define all potentially possible values of the free variables. Such selected values are called hypothesis. Phase 3: All hypothesis are checked out as Verifier Goals to select valid values of free variables All hypothesis which are proved to be valid, are considered as a result of the finder goal. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (27 of 32) [10/16/2002 4:15:41 PM]

28 5.2 Forward Resolution Algorithm Counterpart for the Backward Chaining Procedure is called Forward Chaining Procedure. The Forward Chaining Procedure deals with putting basic facts together to infer all possible new facts. Note that the Backward Chaining Procedure needs to be invoked every time when the user issues a Verifier or Finder Goal. The responce is infered dynamically and NO infered data are stored into the database. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (28 of 32) [10/16/2002 4:15:41 PM]

29 On the contrary, the Forward Chaining Procedure needs to be invoked only when the database is modified (i.e. when the user issues a Doer Goal). All facts defined by means of rules of inference are infered and stored into the database. Thus, forthcoming Verifier or Finder Goals can be interpreted by means of searching such previously stored infered fact. Since, interpreting a Finder goal may take considerable time, the Backward Chaining Procedure is normally applied for database systems which are not critical to responce time. Deductive systems which are supposed to control processes in real time (say, an oil refinery process), normally supports Forward Chaining Procedure to minimize a responce time. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (29 of 32) [10/16/2002 4:15:41 PM]

30 5.3 Discussion We can view the task of executing a logic program as a search problem. The representation of goals in terms of a tree, and the algorithm itself support this analogy. Hence, the objective of the algorithm is to find a solution if one exists in the search space. The depth-first nature and the backtracking of the algorithm introduced, are simply computational features to deal with the non-determinism of the task at hand. In theory, any other (correct) means of dealing with such non-determinism could be used. For instance, the search of the tree could be done breadth- first manner instead. Since predicates can be recursive, breadth-first search would have the advantage of always finding a solution whenever one exists. On the other hand, a depth-first search of the same tree might not terminate, when for instance recursive clauses are attempted first. Since breadth-first search seems to avoid this problem of infinite recursion, one might wonder why it is not used for searching at the first place. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (30 of 32) [10/16/2002 4:15:41 PM]

31 The answer is due to efficiency considerations. Much more information would have to be kept at runtime (in fact all the information of the tree up to that point) with breadth-first search. Depth-first search can be implemented much more efficiently in this respect. But, as is often the case, the gain in efficiency comes at a cost. In this case, the cost is considerable in that it forces programmers to be careful and aware of how programs are executed and arrange their programs accordingly. The order of in which clauses of a predicate appear will matter (depth-first). In particular, the possibility of infinite recursion must be avoided either by placing at least one non-recursive clause before the recursive one(s), or by ensuring that the head of the recursive clause(s) will at some point not unify with a goal. One might think of predicates and facts in several ways. One natural way (perhaps especially so for non-programmers) to look at rules of inference is to think of them as declarative sentences in natural language. As stated earlier, predicates describe relationships between entities (e.g., grandparenthood, parenthood, etc.). Some relationships can be stated in one sentence, other relationships require more than one sentence (rule of inference) in order to specify the relationship fully. Programmers might find similarities between a predicate and a procedure. In that sense, a predicate specifies how to "compute" something (e.g., finding a ascendant to an individual). In this context, rules would correspond to a procedure call and file:///e /LV_CD/wbtmaster/main_library/swp4.htm (31 of 32) [10/16/2002 4:15:41 PM]

32 general directives would correspond to calls involving built-in procedures (this last analogy is weaker than the others). To regard predicates and queries in this way is certainly accurate, however, it constitutes a restricted view. file:///e /LV_CD/wbtmaster/main_library/swp4.htm (32 of 32) [10/16/2002 4:15:42 PM]

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

Software Paradigms (Lesson 7) Logic Programming & Software Engineering

Software Paradigms (Lesson 7) Logic Programming & Software Engineering Software Paradigms (Lesson 7) Logic Programming & Software Engineering Table of Contents 1 Goals (Queries)... 2 1.1 Verifier Goal... 3 1.2 Finder Goals... 4 1.3 Doer Goals... 5 2 Some Implementation Issues...

More information

7. Relational Calculus (Part I) 7.1 Introduction

7. Relational Calculus (Part I) 7.1 Introduction 7. Relational Calculus (Part I) 7.1 Introduction We established earlier the fundamental role of relational algebra and calculus in relational databases (see 5.1). More specifically, relational calculus

More information

8. Relational Calculus (Part II)

8. Relational Calculus (Part II) 8. Relational Calculus (Part II) Relational Calculus, as defined in the previous chapter, provides the theoretical foundations for the design of practical data sub-languages (DSL). In this chapter, we

More information

Programming Languages Third Edition

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

More information

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

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

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

Chapter 3. Describing Syntax and Semantics

Chapter 3. Describing Syntax and Semantics Chapter 3 Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the Meanings of Programs:

More information

Going beyond propositional logic

Going beyond propositional logic Going beyond propositional logic Consider the following statements: p: Ling took CS245 q: Ling passed CS245 r: Ling failed CS245 Taken literally, these are all atomic statements, and formally they have

More information

Quantification. Using the suggested notation, symbolize the statements expressed by the following sentences.

Quantification. Using the suggested notation, symbolize the statements expressed by the following sentences. Quantification In this and subsequent chapters, we will develop a more formal system of dealing with categorical statements, one that will be much more flexible than traditional logic, allow a deeper analysis

More information

Software Paradigms (Lesson 4) Functional Programming Paradigm

Software Paradigms (Lesson 4) Functional Programming Paradigm Software Paradigms (Lesson 4) Functional Programming Paradigm Table of Contents 1 Introduction... 2 2 Evaluation of Functions... 3 3 Compositional (Construct) Operators... 4 4 Some Implementation Issues...

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS 1 THE FORMALIZATION OF MATHEMATICS by Harvey M. Friedman Ohio State University Department of Mathematics friedman@math.ohio-state.edu www.math.ohio-state.edu/~friedman/ May 21, 1997 Can mathematics be

More information

Recursively Enumerable Languages, Turing Machines, and Decidability

Recursively Enumerable Languages, Turing Machines, and Decidability Recursively Enumerable Languages, Turing Machines, and Decidability 1 Problem Reduction: Basic Concepts and Analogies The concept of problem reduction is simple at a high level. You simply take an algorithm

More information

Chapter 1.3 Quantifiers, Predicates, and Validity. Reading: 1.3 Next Class: 1.4. Motivation

Chapter 1.3 Quantifiers, Predicates, and Validity. Reading: 1.3 Next Class: 1.4. Motivation Chapter 1.3 Quantifiers, Predicates, and Validity Reading: 1.3 Next Class: 1.4 1 Motivation Propositional logic allows to translate and prove certain arguments from natural language If John s wallet was

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

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

CITS2211 Discrete Structures Logic

CITS2211 Discrete Structures Logic CITS2211 Discrete Structures Logic Unit coordinator: Rachel Cardell-Oliver August 6, 2017 Highlights All men are mortal, Socrates is a man, therefore Socrates is mortal. Reading Chapter 3: Logical Formulas

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

Logic as a framework for NL semantics. Outline. Syntax of FOL [1] Semantic Theory Type Theory

Logic as a framework for NL semantics. Outline. Syntax of FOL [1] Semantic Theory Type Theory Logic as a framework for NL semantics Semantic Theory Type Theory Manfred Pinkal Stefan Thater Summer 2007 Approximate NL meaning as truth conditions. Logic supports precise, consistent and controlled

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

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 [talking head] Formal Methods of Software Engineering means the use of mathematics as an aid to writing programs. Before we can

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

CS Bootcamp Boolean Logic Autumn 2015 A B A B T T T T F F F T F F F F T T T T F T F T T F F F

CS Bootcamp Boolean Logic Autumn 2015 A B A B T T T T F F F T F F F F T T T T F T F T T F F F 1 Logical Operations 1.1 And The and operator is a binary operator, denoted as, &,, or sometimes by just concatenating symbols, is true only if both parameters are true. A B A B F T F F F F The expression

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

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

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

Chapter 3. Set Theory. 3.1 What is a Set?

Chapter 3. Set Theory. 3.1 What is a Set? Chapter 3 Set Theory 3.1 What is a Set? A set is a well-defined collection of objects called elements or members of the set. Here, well-defined means accurately and unambiguously stated or described. Any

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

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

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 Natural Semantics Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 1 Natural deduction is an instance of first-order logic; that is, it is the formal

More information

SOFTWARE ENGINEERING DESIGN I

SOFTWARE ENGINEERING DESIGN I 2 SOFTWARE ENGINEERING DESIGN I 3. Schemas and Theories The aim of this course is to learn how to write formal specifications of computer systems, using classical logic. The key descriptional technique

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

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor COSC252: Programming Languages: Semantic Specification Jeremy Bolton, PhD Adjunct Professor Outline I. What happens after syntactic analysis (parsing)? II. Attribute Grammars: bridging the gap III. Semantic

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

Scheme: Expressions & Procedures

Scheme: Expressions & Procedures Scheme: Expressions & Procedures CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, March 31, 2017 Glenn G. Chappell Department of Computer Science University

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Module 3. Requirements Analysis and Specification. Version 2 CSE IIT, Kharagpur

Module 3. Requirements Analysis and Specification. Version 2 CSE IIT, Kharagpur Module 3 Requirements Analysis and Specification Lesson 6 Formal Requirements Specification Specific Instructional Objectives At the end of this lesson the student will be able to: Explain what a formal

More information

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G. Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu

More information

Predicate Logic CHAPTER What This Chapter Is About

Predicate Logic CHAPTER What This Chapter Is About CHAPTER 14 Predicate Logic We now turn our attention to a generalization of propositional logic, called predicate, or first-order, logic. Predicates are functions of zero or more variables that return

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

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

STABILITY AND PARADOX IN ALGORITHMIC LOGIC

STABILITY AND PARADOX IN ALGORITHMIC LOGIC STABILITY AND PARADOX IN ALGORITHMIC LOGIC WAYNE AITKEN, JEFFREY A. BARRETT Abstract. Algorithmic logic is the logic of basic statements concerning algorithms and the algorithmic rules of deduction between

More information

Lecture 5: Predicate Calculus. ffl Predicate Logic ffl The Language ffl Semantics: Structures

Lecture 5: Predicate Calculus. ffl Predicate Logic ffl The Language ffl Semantics: Structures Lecture 5: Predicate Calculus ffl Predicate Logic ffl The Language ffl Semantics: Structures 1 Why Predicate Logic? Propositional logic is not powerful enough to express statements such as ffl For every

More information

Introduction to Programming, Aug-Dec 2008

Introduction to Programming, Aug-Dec 2008 Introduction to Programming, Aug-Dec 2008 Lecture 1, Monday 4 Aug 2008 Administrative matters Resource material Textbooks and other resource material for the course: The Craft of Functional Programming

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

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics 400 lecture note #4 [Ch 6] Set Theory 1. Basic Concepts and Definitions 1) Basics Element: ; A is a set consisting of elements x which is in a/another set S such that P(x) is true. Empty set: notated {

More information

It can be confusing when you type something like the expressions below and get an error message. a range variable definition a vector of sine values

It can be confusing when you type something like the expressions below and get an error message. a range variable definition a vector of sine values 7_april_ranges_.mcd Understanding Ranges, Sequences, and Vectors Introduction New Mathcad users are sometimes confused by the difference between range variables and vectors. This is particularly true considering

More information

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 37 Resolution Rules

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 37 Resolution Rules Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras Lecture - 37 Resolution Rules If some literals can be unified, the same algorithm should be able

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

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

THE PREDICATE CALCULUS

THE PREDICATE CALCULUS 2 THE PREDICATE CALCULUS Slide 2.1 2.0 Introduction 2.1 The Propositional Calculus 2.2 The Predicate Calculus 2.3 Using Inference Rules to Produce Predicate Calculus Expressions 2.4 Application: A Logic-Based

More information

Axiomatic Specification. Al-Said, Apcar, Jerejian

Axiomatic Specification. Al-Said, Apcar, Jerejian Axiomatic Specification Al-Said, Apcar, Jerejian 1 Axioms: Wffs that can be written down without any reference to any other Wffs. Wffs that are stipulated as unproved premises for the proof of other wffs

More information

IEEE LANGUAGE REFERENCE MANUAL Std P1076a /D3

IEEE LANGUAGE REFERENCE MANUAL Std P1076a /D3 LANGUAGE REFERENCE MANUAL Std P1076a-1999 2000/D3 Clause 10 Scope and visibility The rules defining the scope of declarations and the rules defining which identifiers are visible at various points in the

More information

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur Module 6 Knowledge Representation and Logic (First Order Logic) 6.1 Instructional Objective Students should understand the advantages of first order logic as a knowledge representation language Students

More information

CSC 501 Semantics of Programming Languages

CSC 501 Semantics of Programming Languages CSC 501 Semantics of Programming Languages Subtitle: An Introduction to Formal Methods. Instructor: Dr. Lutz Hamel Email: hamel@cs.uri.edu Office: Tyler, Rm 251 Books There are no required books in this

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

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic

More information

Chapter 1. Fundamentals of Higher Order Programming

Chapter 1. Fundamentals of Higher Order Programming Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme

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

Automated Reasoning. Natural Deduction in First-Order Logic

Automated Reasoning. Natural Deduction in First-Order Logic Automated Reasoning Natural Deduction in First-Order Logic Jacques Fleuriot Automated Reasoning Lecture 4, page 1 Problem Consider the following problem: Every person has a heart. George Bush is a person.

More information

First Order Predicate Logic CIS 32

First Order Predicate Logic CIS 32 First Order Predicate Logic CIS 32 Functionalia Demos? HW 3 is out on the web-page. Today: Predicate Logic Constructing the Logical Agent Predicate Logic First-order predicate logic More expressive than

More information

logic with quantifiers (informally)

logic with quantifiers (informally) EDAA40 Discrete Structures in Computer Science 8: Quantificational logic Jörn W. Janneck, Dept. of Computer Science, Lund University logic with quantifiers (informally) Given a logical formula that depends

More information

Z Notation. June 21, 2018

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

More information

CSL105: Discrete Mathematical Structures. Ragesh Jaiswal, CSE, IIT Delhi

CSL105: Discrete Mathematical Structures. Ragesh Jaiswal, CSE, IIT Delhi is another way of showing that an argument is correct. Definitions: Literal: A variable or a negation of a variable is called a literal. Sum and Product: A disjunction of literals is called a sum and a

More information

Arbori Starter Manual Eugene Perkov

Arbori Starter Manual Eugene Perkov Arbori Starter Manual Eugene Perkov What is Arbori? Arbori is a query language that takes a parse tree as an input and builds a result set 1 per specifications defined in a query. What is Parse Tree? A

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology Intermediate Algebra Gregg Waterman Oregon Institute of Technology c 2017 Gregg Waterman This work is licensed under the Creative Commons Attribution 4.0 International license. The essence of the license

More information

CPSC 121: Models of Computation. Module 5: Predicate Logic

CPSC 121: Models of Computation. Module 5: Predicate Logic CPSC 121: Models of Computation Module 5: Predicate Logic Module 5: Predicate Logic Midterm 1: Friday February 9 th, 17:00 to 18:15 A to C (by last name): room DMP 310 D to K: room MATH 100 L to P: room

More information

Sets. Margaret M. Fleck. 15 September 2010

Sets. Margaret M. Fleck. 15 September 2010 Sets Margaret M. Fleck 15 September 2010 These notes cover set notation, operations on sets, and how to prove claims involving sets (Rosen sections 2.1 and 2.2). They also cover some logic subtleties that

More information

Propositional Logic. Part I

Propositional Logic. Part I Part I Propositional Logic 1 Classical Logic and the Material Conditional 1.1 Introduction 1.1.1 The first purpose of this chapter is to review classical propositional logic, including semantic tableaux.

More information

CS 6110 S14 Lecture 1 Introduction 24 January 2014

CS 6110 S14 Lecture 1 Introduction 24 January 2014 CS 6110 S14 Lecture 1 Introduction 24 January 2014 1 Introduction What is a program? Is it just something that tells the computer what to do? Yes, but there is much more to it than that. The basic expressions

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

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

An Interesting Way to Combine Numbers

An Interesting Way to Combine Numbers An Interesting Way to Combine Numbers Joshua Zucker and Tom Davis October 12, 2016 Abstract This exercise can be used for middle school students and older. The original problem seems almost impossibly

More information

To figure this out we need a more precise understanding of how ML works

To figure this out we need a more precise understanding of how ML works Announcements: What are the following numbers: 74/2/70/17 (2:30,2:30,3:35,7:30) PS2 due Thursday 9/20 11:59PM Guest lecture on Tuesday 9/25 o No RDZ office hours next Friday, I am on travel A brief comment

More information

Parsing Combinators: Introduction & Tutorial

Parsing Combinators: Introduction & Tutorial Parsing Combinators: Introduction & Tutorial Mayer Goldberg October 21, 2017 Contents 1 Synopsis 1 2 Backus-Naur Form (BNF) 2 3 Parsing Combinators 3 4 Simple constructors 4 5 The parser stack 6 6 Recursive

More information

Formal Predicate Calculus. Michael Meyling

Formal Predicate Calculus. Michael Meyling Formal Predicate Calculus Michael Meyling May 24, 2013 2 The source for this document can be found here: http://www.qedeq.org/0_04_07/doc/math/qedeq_formal_logic_v1.xml Copyright by the authors. All rights

More information

Unit 4 Relational Algebra (Using SQL DML Syntax): Data Manipulation Language For Relations Zvi M. Kedem 1

Unit 4 Relational Algebra (Using SQL DML Syntax): Data Manipulation Language For Relations Zvi M. Kedem 1 Unit 4 Relational Algebra (Using SQL DML Syntax): Data Manipulation Language For Relations 2016 Zvi M. Kedem 1 Relational Algebra in Context User Level (View Level) Community Level (Base Level) Physical

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

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

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

More information

Propositional Logic Formal Syntax and Semantics. Computability and Logic

Propositional Logic Formal Syntax and Semantics. Computability and Logic Propositional Logic Formal Syntax and Semantics Computability and Logic Syntax and Semantics Syntax: The study of how expressions are structured (think: grammar) Semantics: The study of the relationship

More information

Intro to Haskell Notes: Part 5

Intro to Haskell Notes: Part 5 Intro to Haskell Notes: Part 5 Adrian Brasoveanu October 5, 2013 Contents 1 Curried functions and related issues 1 1.1 Curried functions......................................... 1 1.2 Partially applied

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

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

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

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

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

2.2 Syntax Definition

2.2 Syntax Definition 42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions

More information

Dr. Relja Vulanovic Professor of Mathematics Kent State University at Stark c 2008

Dr. Relja Vulanovic Professor of Mathematics Kent State University at Stark c 2008 MATH-LITERACY MANUAL Dr. Relja Vulanovic Professor of Mathematics Kent State University at Stark c 2008 1 Real Numbers 1.1 Sets 1 1.2 Constants and Variables; Real Numbers 7 1.3 Operations with Numbers

More information

Notes on Predicate Calculus

Notes on Predicate Calculus Notes on Predicate Calculus by Charles Lin c Charles Lin 2000 All rights reserved 1 Propositional Calculus Enough Propositional calculus is good enough to describe certain kinds of reasoning, but it is

More information

Introductory logic and sets for Computer scientists

Introductory logic and sets for Computer scientists Introductory logic and sets for Computer scientists Nimal Nissanke University of Reading ADDISON WESLEY LONGMAN Harlow, England II Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario

More information

Chapter 12. Computability Mechanizing Reasoning

Chapter 12. Computability Mechanizing Reasoning Chapter 12 Computability Gödel s paper has reached me at last. I am very suspicious of it now but will have to swot up the Zermelo-van Neumann system a bit before I can put objections down in black & white.

More information

Lecture 3: Recursion; Structural Induction

Lecture 3: Recursion; Structural Induction 15-150 Lecture 3: Recursion; Structural Induction Lecture by Dan Licata January 24, 2012 Today, we are going to talk about one of the most important ideas in functional programming, structural recursion

More information

Hoare Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré

Hoare Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré Hoare Logic COMP2600 Formal Methods for Software Engineering Rajeev Goré Australian National University Semester 2, 2016 (Slides courtesy of Ranald Clouston) COMP 2600 Hoare Logic 1 Australian Capital

More information

Propositional Calculus: Boolean Functions and Expressions. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Propositional Calculus: Boolean Functions and Expressions. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson Propositional Calculus: Boolean Functions and Expressions CS 270: Mathematical Foundations of Computer Science Jeremy Johnson Propositional Calculus Objective: To provide students with the concepts and

More information

Lecture Notes on Contracts

Lecture Notes on Contracts Lecture Notes on Contracts 15-122: Principles of Imperative Computation Frank Pfenning Lecture 2 August 30, 2012 1 Introduction For an overview the course goals and the mechanics and schedule of the course,

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information