Software Paradigms (Lesson 6) Logic Programming
|
|
- Kevin Blake
- 5 years ago
- Views:
Transcription
1 Software Paradigms (Lesson 6) Logic Programming Table of Contents 1 Introduction Facts Predicates (Structured Terms) General Structures Predicates (Syntax) Simple Terms Atoms Numbers Variables Logical Operations and Composite Predicates Logical Operations Quantifiers Well-Formed Formulae Rules of Inference Head and Body Recursion Inferred Calculations Functions and Variables Some Analogies... 17
2 1 Introduction 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.
3 2 Facts A Logical Data Model operates with so-called Facts. Generally speaking, fact is any expression which can be interpreted as True or False. Alex is a nice guy. 25 > = 66.Smith is a student and he got 2 for examination on Software Paradigms
4 3 Predicates (Structured Terms) Facts are presented as so-called structured terms that are made of several components. 3.1 General Structures 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. Alex is a nice guy. = = niceguy (Alex) Functor argument 25 > 36. = = greater Than (25,36) Functor arguments = 66. = = plus (25,41,66) Functor arguments.smith is a student and he got 2 for examination on Software Paradigms = = exam( Smith, Software Paradigms,2) 3.2 Predicates (Syntax) Functor arguments 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. 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 3.3 Simple Terms The following subsections describe the three different kinds of simple data objects.
5 3.4 Atoms 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. a greaterthan two_b_or_not_2_b A string of special characters such as: + - * / \ = ^ < > :. # $ & <> ##&& ::= A string of any characters enclosed within single quotes. '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. 3.5 Numbers 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: Real numbers can be written in standard or scientific notation, as illustrated in the following: e e-3-2.6e-2 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. 3.6 Variables A variable is a name for value which can change while an evaluation is running. 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 (!)
6 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 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. plus (X,Y,66) is True 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}. niceguy(x) is True niceguy(x) is True if X = Alex and Alex can be found among persistent database objects niceguy, exam(studentname,vo) is False if StudentName = Alex, VO = Software Paradigm and ( Alex, Software Paradigms can be found among persistent database objects exam ),
7 4 Logical Operations and Composite Predicates 4.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 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). niceguy( Alex ) & (niceguy( Tom ) exam( Tom, Software Paradigm,1)) is True if basic fact: niceguy( Alex ) is true and the composite predicate niceguy( Tom ) and 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). 4.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 " X" and is read as "there exists an X such that...". A universally quantified variable is written as " X" 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
8 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 of X, but we don't care which (!). In other words, 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) and suppose X ranges over {4,15} and Y over {7,14}. The truth table for the expression is: X Y greaterthan(y,x) & greaterthan(12,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)) 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: Y 7 True 14 False X (greaterthan(y,x) & greaterthan(12,y)) 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). Consider, for example, the unquantified expression greaterthan(y,x) greaterthan(12,y) and suppose X ranges over {4,15} and Y over {7,14}. The truth table for the expression is: X Y greaterthan(y,x) greaterthan(12,y) 4 7 True 15 7 True
9 4 14 True False Now consider the same expression but with X universally quantified: X (greaterthan(y,x) & greaterthan(12,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: : Y 7 True 14 False X (greaterthan(y,x) greaterthan(12,y)) 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! 4.3 Well-Formed Formulae 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 2. F1 & F2 and F1 F2 are WFFs if F1 and F2 are WFFs 3. (F) is a WFF if F is a WFF 4. x (F(X)) and x (F(X)) are WFFs if F(X) is a WFF with a free occurrence of the variable X. In this case, X is called a bound variable in the scope of F(x).
10 5 Rules of Inference 5.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 is a WFF (logical expression) head 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 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. 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 are true. enrollvo( Alex, Programming ) and locvo( Programming, Thursday, Room 22 ) 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 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.
11 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. We can define the following rule of inference mustgo(student, Room, Day, Subject) :- enrollvo(student, Subject) & locvo(subject, Day, Room) 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 The table above, just told us that, for example, the fact locvo (Databases,Tuesday,Room 23) is true, at the same time the fact locvo (Databases,Monday,Room 23) is false, etc. In analogy, basic facts enrollvo may be seen as the following table. enrollvo Student Subject Palina Palina Alex Alex Hypermedia Programming Programming Databases 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! All inferred facts are true by definition and can be seen as the following table: mustgo Student Room Day Subject Palina Room 22 Monday Hypermedia Palina Room 22 Thursday Programming Alex Room 22 Thursday Programming Alex Room 23 Tuesday Databases
12 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) and inferring the following facts: mustgo Student Room Day Palina Room 22 Monday Palina Room 22 Thursday Alex Room 22 Thursday Alex Room 23 Tuesday Actually, this rule is erroneous because free variables in the head of the rule are not identical to the variables in the body. Thus, in order to verify a 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 Subject. For example, it is true, if subject is programming and false for any other value. enrollvo( Alex, Programming ) & locvo( Programming, Room 22, Thursday ) true enrollvo( Alex, Databases ) & locvo( Databases, Room 22, Thursday ) false 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. 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 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
13 enrollvo( Alex, Programming ) & locvo( Programming, Room 22, Thursday ) is true. 5.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 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
14 descendent G D Nick Pauline Pauline Alex Application of the rule: Pauline Alex Paul Tom descendent(g,d):- X (parent(g,x) & descendent(x,d)) results in the following inferred facts descendent G D X parent(g,x) & descendent(x,d)) 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 ) 5.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. 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) need P C Q D_A D_B 5 D_B D_D 3 D_B D_C 8 D_D D_E 4
15 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)) Application of the rule: need+(p,c,q):-need(p,c,q) results in the following inferred facts Need+ P C Q Application of the rule: D_A D_B 5 D_B D_D 3 D_B D_C 8 D_D D_E 4 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 need(p,x,q1) & need+(x,c,q2) & mult(q1,q2,q) D_A D_D 15 D_B, 5, 3 D_A D_C 40 D_B, 5, 8 D_B D_E 12 D_C, 3, 4 D_A D_E 60 D_B, 5, Functions and Variables need(d_a,d_b,5) & need+(d_b,d_d,3) & mult(5,3,15) need(d_a,d_b,5) & need+(d_b,d_c,8) & mult(5,8,40) need(d_b,d_c,3) & need+(d_c,d_e,4) & mult(3,4,12) need(d_a,d_b,5) & need+(d_b,d_e,12) & mult(5,12,60) 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 Application of this rule results in the same list of inferred facts, but the inference procedure is much simple
16 need+ P C Q1*Q2 X need(p,x,q1) & need+(x,c,q2) D_A D_D 15 D_B need(d_a,d_b, 5) & need+(d_b,d_d, 3) D_A D_C 40 D_B need(d_a,d_b, 5) & need+(d_b,d_c, 8) D_B D_E 12 D_C need(d_b,d_c,3) & need+(d_c,d_e,4) D_A D_E 60 D_B need(d_a,d_b,5) & need+(d_b,d_e,12)
17 6 Some Analogies 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 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.
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 informationSoftware 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 information7. 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 information8. 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 informationProgramming 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 informationIntroduction 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 informationChapter 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 informationThis 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 informationSoftware 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 informationGoing 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 informationPart 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 information1. 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 informationScheme: 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 informationGoals: 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 informationLogic 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 informationScheme: 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 informationCS 3360 Design and Implementation of Programming Languages. Exam 1
1 Spring 2017 (Thursday, March 9) Name: CS 3360 Design and Implementation of Programming Languages Exam 1 This test has 8 questions and pages numbered 1 through 7. Reminders This test is closed-notes and
More informationThe 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 informationCITS2211 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 informationCS 3360 Design and Implementation of Programming Languages. Exam 1
1 Spring 2016 (Monday, March 21) Name: CS 3360 Design and Implementation of Programming Languages Exam 1 This test has 18 questions and pages numbered 1 through 6. Reminders This test is closed-notes and
More informationOverview. 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 informationITCS 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 informationLecture 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 informationZ 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 informationThis 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 informationChapter 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 informationQuantification. 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 informationCOSC252: 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 informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationPropositional Logic. Andreas Klappenecker
Propositional Logic Andreas Klappenecker Propositions A proposition is a declarative sentence that is either true or false (but not both). Examples: College Station is the capital of the USA. There are
More information1 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 informationLecture 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 informationFunctional 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 informationCSCI.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 informationThe 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(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 informationCPSC 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 informationQuestion 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 informationChapter 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 informationPropositional 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 informationSOFTWARE 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 informationIntro 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 informationAutomated 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 informationPractice 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 informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationChapter 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 informationPROgramming 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 informationlogic 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 informationPropositional 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 informationCPS122 Lecture: From Python to Java last revised January 4, Objectives:
Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.
More information2.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 informationUnit 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 informationNotes. 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 informationIEEE 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 informationCS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)
CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going
More informationUnit 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 2014 Zvi M. Kedem 1 Relational Algebra And SQL SQL is based on relational algebra with many extensions Some necessary
More information6.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 informationProgramming Language Concepts, cs2104 Lecture 04 ( )
Programming Language Concepts, cs2104 Lecture 04 (2003-08-29) Seif Haridi Department of Computer Science, NUS haridi@comp.nus.edu.sg 2003-09-05 S. Haridi, CS2104, L04 (slides: C. Schulte, S. Haridi) 1
More informationSC/MATH Boolean Formulae. Ref: G. Tourlakis, Mathematical Logic, John Wiley & Sons, York University
SC/MATH 1090 1- Boolean Formulae Ref: G. Tourlakis, Mathematical Logic, John Wiley & Sons, 2008. York University Department of Computer Science and Engineering York University- MATH 1090 01-Boolean 1 Overview
More informationCPS122 Lecture: From Python to Java
Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.
More informationIt 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 informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler
More informationChapter 3. Describing Syntax and Semantics ISBN
Chapter 3 Describing Syntax and Semantics ISBN 0-321-49362-1 Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the
More informationChapter 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 informationFirst-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 informationLecture 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 informationTo 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 informationVirtual World Development
ALGEBRAIC SPECIFICATION LANGUAGE The algebraic specification language (ASL) is intended to provide the formal structure needed for modular programming and the flexibility needed for unencumbered design.
More informationCMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics
Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End
More informationScheme 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 informationOUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.
1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN
More informationNOTE: Answer ANY FOUR of the following 6 sections:
A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)
More informationIntroductory 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 informationwill 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 informationThe syntax and semantics of Beginning Student
The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come
More informationThe syntax and semantics of Beginning Student
The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come
More informationRecursively 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 informationPolymorphic 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 informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationLISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits.
LISP Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. From one perspective, sequences of bits can be interpreted as a code for ordinary decimal digits,
More informationFormal Methods in Software Engineering 1
Logic Review First Order Logic Propositional Logic Summary Formal Methods in Software Engineering 1 Logic From Merriam-Webster Online, Logic is the science of the formal principles of reasoning. Mathematical
More informationTHE 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 informationIntroduction & Review
Introduction & Review York University Department of Computer Science and Engineering 1 Why this course? Overview Programming Language Paradigms Brief review of Logic Propositional logic Predicate logic
More informationarxiv: v1 [cs.pl] 1 May 2017
arxiv:1705.00556v1 [cs.pl] 1 May 2017 Mapping Objects to Persistent Predicates. José E. Zalacain Llanes Abstract The Logic Programming through Prolog has been widely used for supply persistence in many
More informationIntroduction to Logic Programming
Introduction to Logic Programming York University CSE 3401 Vida Movahedi York University CSE 3401 V. Movahedi 1 Overview Programming Language Paradigms Logic Programming Functional Programming Brief review
More informationPredicate 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 informationCS 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 informationAxiomatic 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 informationDr. 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 informationSoftware Engineering Lecture Notes
Software Engineering Lecture Notes Paul C. Attie August 30, 2013 c Paul C. Attie. All rights reserved. 2 Contents I Hoare Logic 11 1 Propositional Logic 13 1.1 Introduction and Overview..............................
More informationSprite an animation manipulation language Language Reference Manual
Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3
More informationTowards a Logical Reconstruction of Relational Database Theory
Towards a Logical Reconstruction of Relational Database Theory On Conceptual Modelling, Lecture Notes in Computer Science. 1984 Raymond Reiter Summary by C. Rey November 27, 2008-1 / 63 Foreword DB: 2
More informationCS 512, Spring 2017: Take-Home End-of-Term Examination
CS 512, Spring 2017: Take-Home End-of-Term Examination Out: Tuesday, 9 May 2017, 12:00 noon Due: Wednesday, 10 May 2017, by 11:59 am Turn in your solutions electronically, as a single PDF file, by placing
More informationName: CSCI E-220: Artificial Intelligence Midterm Exam, Fall Term 2001
Name: CSCI E-220: Artificial Intelligence Midterm Exam, Fall Term 2001 This is a 75-minute, open-book exam. Take a minute to look over the exam, and begin by answering the questions you feel most comfortable
More informationTo 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 informationChapter 3. Semantics. Topics. Introduction. Introduction. Introduction. Introduction
Topics Chapter 3 Semantics Introduction Static Semantics Attribute Grammars Dynamic Semantics Operational Semantics Axiomatic Semantics Denotational Semantics 2 Introduction Introduction Language implementors
More informationMathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 9 Normal Forms
Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras Lecture - 9 Normal Forms In the last class we have seen some consequences and some equivalences,
More informationWeek 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 informationAgenda. Database Systems. Session 5 Main Theme. Relational Algebra, Relational Calculus, and SQL. Dr. Jean-Claude Franchitti
Database Systems Session 5 Main Theme Relational Algebra, Relational Calculus, and SQL Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences
More informationMARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012
MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)
More information