Principles of Programming Languages
|
|
- Leo Conley
- 5 years ago
- Views:
Transcription
1 Principles of Programming Languages Lesson Collaboration 22 An Introduction and Management to Logic Programming Dana Fisman Logic Programming ( Pure Prolog ) 1
2 Review of Last Lecture How does it look like? What is the meaning? What is the execution alg? Relational Logic Programming Logic Programming Prolog
3 Operational Semantics for LP Interpreter of LP uses two main procedures: o Answer-query(P,Q) Builds a proof tree for Q wrt. P aka ProofTree(P,Q) returns a substitution s to the variables of Q showing Q holds (or true if there are no variables) or fail if no substitution will make the formula true (or false if there are no variables) o Unify(A,B) returns a substitution s such that s = mgu(a,b) or Fail if A and B cannot be unified
4 Unify Goal of Unify(A,B): find the most general unifier. Example: Unify( p(x,3,x,w), p(y,z,4,w) ) ==> {X=4, Y=4, Z=3} Indeed: p(x, 3, X, W) {X=4, Y=4, Z=3} = p(4, 3, 4, W) p(y, Z, 4, W) {X=4, Y=4, Z=3} = p(4, 3, 4, W)
5 Disagreement Set The disagreement set of two atomic formulas A and B is the set of left most symbols on which the formulas disagree. Examples: d-s(p(x,3,x,w), p(y,z,4,w)) = {X,Y}. d-s(p(5,3,x,w), p(5,3,4,w)) = {X,4}.
6 Unify - A unification algorithm Signature: unify(a, B) Type: [atomic-formula * atomic-formula -> a substitution or FAIL] Postcondition: result = mgu(a, B) if A and B are unifiable or FAIL, otherwise unify(a, B) return unify_h(a, B, {}) unify_h(a, B, s) if A s top pred is different than A s top pred (in name or arity) return FAIL Let A = A s Let B = B s if A = B return s else let D = disagreement-set(a, B ) if D = {X, t} /* X is a variable; t is a term */ let s = s {X = t} unify_h(a, B, s ) else return FAIL
7 Unify - example unify[ p(x, 3, X, W), p(y, Y, Z, Z) ] ==> unify_h[p(x, 3, X, W), p(y, Y, Z, Z), {} ] ==> D = {X, Y} unify_h[p(y, 3, Y, W), p(y, Y, Z, Z), {X = Y} ] ==> D = {Y, 3} unify_h[p(3, 3, 3, W), p(3, 3, Z, Z), {X = 3, Y= 3} ] ==> D = {Z, 3} unify_h[p(3, 3, 3, W), p(3, 3, 3, 3), {X = 3, Y= 3, Z = 3} ] ==> D = {W, 3} unify_h[p(3, 3, 3, 3), p(3, 3, 3, 3), {X = 3, Y= 3, Z:= 3, W = 3} ] ==> {X = 3, Y = 3, Z = 3, W = 3}
8 answer-query: an interpretation algorithm for LP Input: A query Q?- Q 1,..., Q n. Each component is called goal A program P, with numbered rules A goal selection policy G sel A rule selection policy R sel Output: A set of (possibly partial) substitutions for variables of Q.
9 Operational Semantics for LP Method: Build a node N for the given query Q From current node N: If it is a success leaf (N = true), o extract answer and return it o Backtrack to obtain more answers Input: a program P and a query Q Output: partial subs to query variables (or true/false) If it is a failure leaf (N =false) o Backtrack If it is not a leaf node and N = (G1,,Gn) o o select a goal Gi and select a rule H :- B1,, Bk If H can be unified with Gi unifier Subs then create a new node N = (G1, Gi-1, B1,, Bk, Gi+1, Gn) Subs Otherwise, create a new node N = false. o Make N the current node.
10 Applying Answer-Query parent(abraham, isaac). %p1 parent(isaac, jacob). %p2 parent(sarah, isaac). %p3 parent(jacob, joseph). %p4 male(abraham). %m1 male(isaac). %m2 male(jacob). %m3 male(joseph). %m4 ancestor(a,d) :- parent(a,d). %a1 ancestor(a,d) :- parent(a,p), %a2 ancestor(p,d).?- ancestor(isaac,d). %a1 {A1=isaac,D1=D} D=joseph par(isaac, D1) %p2 {D1=jacob} par(jacob, D2) %p4 {D2=joseph} true anc(isaac,d) %a2 {A1=isaac,D1=D} par(isaac, P1), anc(p1,d1) %p2 {P1=jacob} true anc(jacob,d1) D=jacob %a1 {A2=jacob, D2=D1} %a2 {A2=jacob, D2=D1} %a1 {A3=joseph, D3=D2} par(jacob, P2), anc(p2,d2) %p4 {P2=joseph} anc(joseph,d2) %a2 {A3=joseph,D3=D2} par(joseph, D3) false par(joseph, P3), anc(p3,d3) false
11 Applying Answer-Query parent(abraham, isaac). %p1 parent(isaac, jacob). %p2 parent(sarah, isaac). %p3 parent(jacob, joseph). %p4 male(abraham). %m1 male(isaac). %m2 male(jacob). %m3 male(joseph). %m4 %a1 anc(isaac,d) %a1 {A2=P1,D2=D} %a2 {A1=isaac,D1=D} anc(p1,d), par(isaac, P1) %a2 {A2=P2,D2=D} ancestor(a,d) :- parent(a,d). %a1 ancestor(a,d) :- parent(a,p), %a2 ancestor(p,d).?- ancestor(isaac,d). par(p1,d), par(isaac, P1) anc(p2,d), par(p2, P1), par(isaac, P1) %a2 {A3=P3,D3=D} par(isaac, abraham) par(isaac, issac) par(isaac, sarah) par(isaac, jacob) anc(p3,d), par(p3, P2), par(p2, P1), par(isaac, P1) %a1 %a2 fail fail fail true
12 Significant kinds of proof trees Finite success proof tree: A finite tree with a successful path. Finite failure proof tree: A finite tree with no successful path. Infinite success proof tree: An infinite tree with a successful path. Infinite failure proof tree: An infinite tree with no successful path.
13 Decidability of Relational LP Proof: Claim: Given a program P and a query Q in RLP, the problem "Is Q provable from P ", denoted P ` Q is decidable. The number of terms (constants/variables) and predicates appearing in P and Q is finite. Thus, the number of possible atomic formula (i.e. goals appearing in a node of the proof tree) is finite (except for renaming). Let N(P,Q) be that number. Then, any path that is longer than N(P,Q) is infinite. QED
14 Prolog and subsets of interest Relational Logic Programming Datalog Logic Programming Prolog
15 Modeling SQL in RLP o RLP naturally represents structured databases (tables with static columns). o A procedure consisting of facts can represent a table in the database. o Often databases are access via elementary SQL operations such as: select, project, union, Cartesian product and join.
16 Modeling SQL in RLP Select (rows from table r, fitting some criteria): r1(x1, X2, X3) :- r(x1, X2, X3), X2 \= X3. Project (some columns from table r): r1(x1, X3) :- r(x1, X2, X3). Union (unite tables r and s, with identical columns): r_union_s(x1,..., Xn) :- r(x1,..., Xn). r_union_s(x1,..., Xn) :- s(x1,..., Xn).
17 Modeling SQL in RLP Cartesian product (all combinations of rows from r and s): r_x_s(x1,..., Xn, Y1,..., Ym) :- r(x1,..., Xn ), s(y1,..., Ym). Natural Join (join tables r and s, with mutual column X): r_join_s(x1,..., Xn, X, Y1,..., Ym) :- r(x1,..., Xn, X ), s(x, Y1,..., Ym).
18 Prolog and its subsets Relational Logic Programming Logic Programming Prolog
19 Logic Programming The only difference between RLP and LP is that a functor symbol is added to the syntax Functors are used to represent composite data structures. course(ppl, Sun, 14, 16, 35, 310). course(ppl, Mon, 14, 16, 32, 307). course(ppl, time(sun,14,16), location(35,310)). course(ppl, time(mon,14,16), location(32,307)).
20 Logic Programming This addition of functors has significant implication: the resulting logic is Turing Complete (recursively enumerable). and thus partially decidable. Implementation requires a more complex unification algorithm.
21 Logic Programming Terms Syntax Terms are now define inductively: Base A constant is a term A variables is a term Inductive step If t 1,..., t n are terms and f is a functor symbol then f(t 1,..., t n ) is a term.
22 Atomic formula in FLP - examples parent(juliet, Child) Constants: ppl, Mon, 14, 16, 32, 307 Functors: time, location, course course(ppl, time(mon,14,16), location(32,307)). member(cube(red(x)), Lst) Functors: cube, red, member Variables: X, Lst ancestor(mary, sister_of(john)) Constants: john, mary Functors: sister_of, ancestor p(f(f(f(g(a,g(b,c)))))) Constants: a, b, c Functors: f,g,p
23 LP Concrete Syntax Extension <term> ==> <constant> <variable> <composite-term> <composite-term> ==> <functor> ( (<term>, )* <term> ) <functor> ==> <constant>
24 LP Abstract Syntax Extension <term>: Kinds: <constant>, <variable>, <composite-term> <composite-term>: Components: Functor: <constant> Term: <term>. Amount: >=1. Ordered.
25 Example power of functors To show the power of functors, we will write a small program in pure Prolog that o defines what are formulas in conjunctive normal form (CNF) o provides a procedure to transform a formula not in CNF to an equivalent formula in CNF Credit for the example: Marcin Judinski
26 PL CNF Example o: OR a: AND n: NEG
27 Example: Defining CNF monomial(x) :- atom(x). monomial(neg(x)) :- atom(x). disjunction(x) :- monomial(x). disjunction(or(x,y)) :- disjunction(x), disjunction(y). cnf(x) :- disjunction(x). cnf(and(x,y)) :- disjunction(x), disjunction(y). cnf(and(x,y)) :- cnf(x), cnf(y).?- atom(foo). true?- monomial(bar). true?- monomial(neg(bar)). true?- monomial(and(bar)). false
28 Example: Defining CNF monomial(x) :- atom(x). monomial(neg(x)) :- atom(x). disjunction(x) :- monomial(x). disjunction(or(x,y)) :- disjunction(x), disjunction(y). cnf(x) :- disjunction(x). cnf(and(x,y)) :- disjunction(x), disjunction(y). cnf(and(x,y)) :- cnf(x), cnf(y).?- disjunction(foo). true?- disjunction(neg(foo)). true?- disjunction(or(neg(foo),bar)). true?- disjunction(and(neg(foo),bar)). false
29 Example: Defining CNF monomial(x) :- atom(x). monomial(neg(x)) :- atom(x). disjunction(x) :- monomial(x). disjunction(or(x,y)) :- disjunction(x), disjunction(y). cnf(x) :- disjunction(x). cnf(and(x,y)) :- disjunction(x), disjunction(y). cnf(and(x,y)) :- cnf(x), cnf(y).?- cnf(and(neg(foo),bar)). true?- cnf(or(neg(foo),bar)). true?- cnf(or(neg(foo),and(bar,moo))). false?- cnf(and(neg(foo),or(bar,moo))). true
30 PL CNF Example Now we would like to define a procedure with input: a boolean formula (using and,or,neg) output: an equivalent formula in CNF % Signature: givecnfequiv(boolform)/1 % Purpose: Prints a formula cnf that is equivalent % to boolform is in CNF This procedure will invoke % Signature: cnfequiv(boolform, cnf)/2 % Purpose: Transforms a boolean formula to an equivalent % one in CNF % Postcondition: cnf is equivalent to boolform in CNF % Precondition: boolform is a boolean formula % and cnf is a variable
31 Ex. Defining givecnfequiv givecnfequiv(x) :- cnfequiv(x,y), write(y). cnfequiv(x,y) :- transform(x,z), cnfequiv(z,y). cnfequiv(x,x).?- cnfequiv(or(neg(foo),and(bar,moo)), X). X = and(or(neg(foo), bar), or(neg(foo), moo))?- givecnfequiv(or(neg(foo),and(bar,moo))). and(or(neg(foo), bar), or(neg(foo), moo)) true
32 Ex. Defining transform transform(neg(neg(x)),x). % eliminate double negation transform(neg(and(x,y)), or(neg(x),neg(y))). % De Morgan transform(neg(or(x,y)), and(neg(x),neg(y))). % De Morgan % distribution transform(or(x,and(y,z)), and(or(x,y),or(x,z))). transform(or(and(x,y),z), and(or(x,z),or(y,z))). % recursion to transform sub terms transform(or(x1,y), or(x2,y)) :- transform(x1,x2). transform(or(x,y1), or(x,y2)) :- transform(y1,y2). transform(and(x1,y), and(x2,y)) :- transform(x1,x2). transform(and(x,y1), and(x,y2)) :- transform(y1,y2). transform(neg(x1),neg(x2)) :- transform(x1,x2).
33 Ex. Defining transform transform(neg(neg(x)),x). % eliminate double negation transform(neg(and(x,y)), or(neg(x),neg(y))). % De Morgan transform(neg(or(x,y)), and(neg(x),neg(y))). % De Morgan % distribution transform(or(x,and(y,z)), and(or(x,y),or(x,z))). transform(or(and(x,y),z), and(or(x,z),or(y,z))). % recursion to transform sub terms transform(or(x1,y), or(x2,y)) :- transform(x1,x2). transform(or(x,y1), or(x,y2)) :- transform(y1,y2). transform(and(x1,y), and(x2,y)) :- transform(x1,x2). transform(and(x,y1), and(x,y2)) :- transform(y1,y2). transform(neg(x1),neg(x2)) :- transform(x1,x2).
34 PL Operational Semantics The abstract interpreter AnswerQuery(P,Q) for RLP applies to LP as well. The only difference is that the unification algorithm has to be extended to handle the richer term structure, which now includes functors that can be nested within other functors.
35 LP - Unification - unify(member(x,tree(x,left,right)), member(y,tree(9,void,tree(3,void,void)))) ==> {Y=9, X=9, Left=void, Right=tree(3,void,void)} unify(t(x, f(a), X), t(g(u), U, W)) ==> {X=g(f(a)), U=f(a), W=g(f(a))} unify(t(x, f(x), X), t(g(u), U, W)) ==> fails
36 Unify in LP Signature: unify(a, B) Type: [atomic-formula * atomic-formula -> a substitution or FAIL] Postcondition: result = mgu(a, B) if A and B are unifiable or FAIL, otherwise unify(a, B) return unify_h(a, B, {}) unify_h(a, B, s) if A s top pred is different than A s top pred (in name or arity) return FAIL Let A = A s Let B = B s if A = B The occur check return s constraint else let D = disagreement-set(a, B ) if D = {X, t} and X does not occur in t let s = s {X = t} unify_h(a, B, s ) else return FAIL
37 LP as Programming Language? Can we call Pure Prolog a programming language? o It has the required 3: Syntax, Semantics, Operational semantics To be called a general purpose programming logic it also has to be Turing Complete. o We should be able to implement any RE function in it.
38 Expressivity and Decidability LP Claim: LP is Turing-Complete. How can this be proven? One can write a short LP program that implements a Turing Machine. Claim: LP is only partially decidable. The finiteness algorithm we used for RLP does no longer hold. In the presence of functors that can be nested within each other, the number of different atomic formulas is unbounded.
39 Expressivity of Prolog and its subsets Not Turing Complete Turing Complete Turing Complete Relational Logic Programming Logic Programming Prolog
40 What about our Scheme Subsets? Which is the smallest one which is Turing Complete? Scheme L4 define L1 only primitive ops and types L2 L3 cond lambda cons car cdr '() list letrec Turing Complete L5
41 Expressivity of Prolog and its subsets Not Turing Complete Turing Complete Turing Complete Relational Logic Programming Logic Programming Prolog So, why do we need to extend Pure Prolog? Before we go into Full Prolog, let s try to implement some of these ourselves.
Principles of Programming Languages, Spring 2016 Assignment 5 Logic Programming
Principles of Programming Languages, Spring 2016 Assignment 5 Logic Programming Submission instructions: a. Submit an archive file named id1_id2.zip where id1 and id2 are the IDs of the students responsible
More informationPrinciples of Programming Languages
Principles of Programming Languages Lesson 14 Type Checking Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Type Checking We return to the issue of type safety we discussed informally,
More informationPrinciples of Programming Languages
Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Lesson 6 - Defining a Programming Language Bottom Up Collaboration and Management - Elements of Programming Dana Fisman 1 What we accomplished
More informationPrinciples of Programming Languages
Principles of Programming Languages Slides by Dana Fisman based on book by Mira Balaban and lecuture notes by Michael Elhadad Lesson 15 Type Inference Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172
More informationDenotational Semantics. Domain Theory
Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 17: Functional Programming Zheng (Eddy Zhang Rutgers University April 4, 2018 Class Information Homework 6 will be posted later today. All test cases
More informationLecture 1: Conjunctive Queries
CS 784: Foundations of Data Management Spring 2017 Instructor: Paris Koutris Lecture 1: Conjunctive Queries A database schema R is a set of relations: we will typically use the symbols R, S, T,... to denote
More informationConstraint Solving. Systems and Internet Infrastructure Security
Systems and Internet Infrastructure Security Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA Constraint Solving Systems
More informationDATABASE THEORY. Lecture 11: Introduction to Datalog. TU Dresden, 12th June Markus Krötzsch Knowledge-Based Systems
DATABASE THEORY Lecture 11: Introduction to Datalog Markus Krötzsch Knowledge-Based Systems TU Dresden, 12th June 2018 Announcement All lectures and the exercise on 19 June 2018 will be in room APB 1004
More informationFP Foundations, Scheme
FP Foundations, Scheme In Text: Chapter 15 1 Functional Programming -- Prelude We have been discussing imperative languages C/C++, Java, Fortran, Pascal etc. are imperative languages Imperative languages
More informationFoundations 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 informationModule 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 informationComputation Club: Gödel s theorem
Computation Club: Gödel s theorem The big picture mathematicians do a lot of reasoning and write a lot of proofs formal systems try to capture the ideas of reasoning and proof in a purely mechanical set
More informationAnnouncements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.
The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction! Numeric operators, REPL, quotes, functions, conditionals! Function examples, helper
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 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 informationCopyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and
Chapter 6 The Relational Algebra and Relational Calculus Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Outline Unary Relational Operations: SELECT and PROJECT Relational
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.
More informationLOGIC 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 informationCS 314 Principles of Programming Languages. Lecture 16
CS 314 Principles of Programming Languages Lecture 16 Zheng Zhang Department of Computer Science Rutgers University Friday 28 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:
More informationPrinciples of Programming Languages
Principles of Programming Languages Slides by Yaron Gonen and Dana Fisman Based on Book by Mira Balaban and Lesson 20 Lazy Lists Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Lazy
More informationLECTURE 16. Functional Programming
LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative
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 informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 18: Functional Programming Zheng (Eddy) Zhang Rutgers University April 9, 2018 Review: Defining Scheme Functions (define ( lambda (
More informationData Integration: Logic Query Languages
Data Integration: Logic Query Languages Jan Chomicki University at Buffalo Datalog Datalog A logic language Datalog programs consist of logical facts and rules Datalog is a subset of Prolog (no data structures)
More informationModule 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur
Module 6 Knowledge Representation and Logic (First Order Logic) Lesson 15 Inference in FOL - I 6.2.8 Resolution We have introduced the inference rule Modus Ponens. Now we introduce another inference rule
More informationMixed Integer Linear Programming
Mixed Integer Linear Programming Part I Prof. Davide M. Raimondo A linear program.. A linear program.. A linear program.. Does not take into account possible fixed costs related to the acquisition of new
More information}Optimization Formalisms for recursive queries. Module 11: Optimization of Recursive Queries. Module Outline Datalog
Module 11: Optimization of Recursive Queries 11.1 Formalisms for recursive queries Examples for problems requiring recursion: Module Outline 11.1 Formalisms for recursive queries 11.2 Computing recursive
More information}Optimization. Module 11: Optimization of Recursive Queries. Module Outline
Module 11: Optimization of Recursive Queries Module Outline 11.1 Formalisms for recursive queries 11.2 Computing recursive queries 11.3 Partial transitive closures User Query Transformation & Optimization
More information11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT
Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the
More informationExample problems. Combinatorial auction. Towers of Hanoi Rectangle packing Shortest route. 8 queens Soduko Maximizing (minimizing) costs
FunLog Example problems Combinatorial auction sell all the items Towers of Hanoi Rectangle packing Shortest route. 8 queens Soduko Maximizing (minimizing) costs Finding a solution with given property The
More informationCOP4020 Programming Languages. Functional Programming Prof. Robert van Engelen
COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts
More informationDatabase Theory VU , SS Codd s Theorem. Reinhard Pichler
Database Theory Database Theory VU 181.140, SS 2011 3. Codd s Theorem Reinhard Pichler Institut für Informationssysteme Arbeitsbereich DBAI Technische Universität Wien 29 March, 2011 Pichler 29 March,
More informationINTRODUCTION TO PROLOG
INTRODUCTION TO PROLOG PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/44 STRUCTURE OF A PROLOG PROGRAM Where, declaratively, Haskell expresses a computation as a system
More informationLogic 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 informationPlan of the lecture. G53RDB: Theory of Relational Databases Lecture 14. Example. Datalog syntax: rules. Datalog query. Meaning of Datalog rules
Plan of the lecture G53RDB: Theory of Relational Databases Lecture 14 Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk More Datalog: Safe queries Datalog and relational algebra Recursive
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 informationHoare 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 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 informationIntroduction to Logic Programming. Ambrose
Introduction to Logic Programming Ambrose Bonnaire-Sergeant @ambrosebs abonnairesergeant@gmail.com Introduction to Logic Programming Fundamental Logic Programming concepts Related to FP General implementation
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 informationRecursive Functions of Symbolic Expressions and Their Computation by Machine Part I
Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I by John McCarthy Ik-Soon Kim Winter School 2005 Feb 18, 2005 Overview Interesting paper with By John Mitchell Interesting
More informationUser-defined Functions. Conditional Expressions in Scheme
User-defined Functions The list (lambda (args (body s to a function with (args as its argument list and (body as the function body. No quotes are needed for (args or (body. (lambda (x (+ x 1 s to the increment
More informationCOMP2411 Lecture 20: Logic Programming Examples. (This material not in the book)
COMP2411 Lecture 20: Logic Programming Examples (This material not in the book) There are several distinct but often equivalent ways to think about logic programs 1. As computing logical consequences of
More informationLecture 5 - Axiomatic semantics
Program Verification March 2014 Lecture 5 - Axiomatic semantics Lecturer: Noam Rinetzky Scribes by: Nir Hemed 1.1 Axiomatic semantics The development of the theory is contributed to Robert Floyd, C.A.R
More informationInductive Definitions, continued
1 / 27 Inductive Definitions, continued Assia Mahboubi Jan 7th, 2016 2 / 27 Last lecture Introduction to Coq s inductive types: Introduction, elimination and computation rules; Twofold implementation :
More informationRange Restriction for General Formulas
Range Restriction for General Formulas 1 Range Restriction for General Formulas Stefan Brass Martin-Luther-Universität Halle-Wittenberg Germany Range Restriction for General Formulas 2 Motivation Deductive
More informationSafe Stratified Datalog With Integer Order Does not Have Syntax
Safe Stratified Datalog With Integer Order Does not Have Syntax Alexei P. Stolboushkin Department of Mathematics UCLA Los Angeles, CA 90024-1555 aps@math.ucla.edu Michael A. Taitslin Department of Computer
More informationCSCC24 Functional Programming Scheme Part 2
CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages
More informationA Retrospective on Datalog 1.0
A Retrospective on Datalog 1.0 Phokion G. Kolaitis UC Santa Cruz and IBM Research - Almaden Datalog 2.0 Vienna, September 2012 2 / 79 A Brief History of Datalog In the beginning of time, there was E.F.
More informationFunctional programming with Common Lisp
Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions
More informationLectures 20, 21: Axiomatic Semantics
Lectures 20, 21: Axiomatic Semantics Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Static Analysis Based on slides by George Necula Pratikakis (CSD) Axiomatic Semantics
More informationFall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More information1.3. Conditional expressions To express case distinctions like
Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a
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 informationFunctional Logic Programming. Kristjan Vedel
Functional Logic Programming Kristjan Vedel Imperative vs Declarative Algorithm = Logic + Control Imperative How? Explicit Control Sequences of commands for the computer to execute Declarative What? Implicit
More informationLearning Rules. How to use rules? Known methods to learn rules: Comments: 2.1 Learning association rules: General idea
2. Learning Rules Rule: cond è concl where } cond is a conjunction of predicates (that themselves can be either simple or complex) and } concl is an action (or action sequence) like adding particular knowledge
More informationLecture 4. First order logic is a formal notation for mathematics which involves:
0368.4435 Automatic Software Verification April 14, 2015 Lecture 4 Lecturer: Mooly Sagiv Scribe: Nimrod Busany, Yotam Frank Lesson Plan 1. First order logic recap. 2. The SMT decision problem. 3. Basic
More informationChapter 3: Relational Model
Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational Calculus Extended Relational-Algebra-Operations Modification of the Database
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 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 Scheme
How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free
More informationAutomatic Reasoning (Section 8.3)
Automatic Reasoning (Section 8.3) Automatic Reasoning Can reasoning be automated? Yes, for some logics, including first-order logic. We could try to automate natural deduction, but there are many proof
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 19 Tuesday, April 3, 2018 1 Introduction to axiomatic semantics The idea in axiomatic semantics is to give specifications
More informationKnowledge-Based Systems and Deductive Databases
Knowledge-Based Systems and Deductive Databases Wolf-Tilo Balke Christoph Lofi Institut für Informationssysteme Technische Universität Braunschweig http://www.ifis.cs.tu-bs.de Next Lecture 7.1 Implementation
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 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 informationIntroduction to the Lambda Calculus
Introduction to the Lambda Calculus Overview: What is Computability? Church s Thesis The Lambda Calculus Scope and lexical address The Church-Rosser Property Recursion References: Daniel P. Friedman et
More informationUniversity of Innsbruck
STI INNSBRUCK SEMANTIC TECHNOLOGY INSTITUTE University of Innsbruck Semantic Technology Institute Extension of a Datalog Reasoner with Top-Down Evaluation Bachelor Thesis Christoph Fuchs Ing.-Sigl-Strae
More informationCS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016
CS34800 Information Systems The Relational Model Prof. Walid Aref 29 August, 2016 1 Chapter: The Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational
More informationDatabase Theory VU , SS Introduction: Relational Query Languages. Reinhard Pichler
Database Theory Database Theory VU 181.140, SS 2018 1. Introduction: Relational Query Languages Reinhard Pichler Institut für Informationssysteme Arbeitsbereich DBAI Technische Universität Wien 6 March,
More informationCS 415 Midterm Exam Fall 2003
CS 415 Midterm Exam Fall 2003 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you can to
More informationNegations in Refinement Type Systems
Negations in Refinement Type Systems T. Tsukada (U. Tokyo) 14th March 2016 Shonan, JAPAN This Talk About refinement intersection type systems that refute judgements of other type systems. Background Refinement
More informationCS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.
CS 61A Spring 2019 Guerrilla Section 5: April 20, 2019 1 Interpreters 1.1 Determine the number of calls to scheme eval and the number of calls to scheme apply for the following expressions. > (+ 1 2) 3
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 informationLogic 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 informationCSC Discrete Math I, Spring Sets
CSC 125 - Discrete Math I, Spring 2017 Sets Sets A set is well-defined, unordered collection of objects The objects in a set are called the elements, or members, of the set A set is said to contain its
More informationFunctional Programming. Big Picture. Design of Programming Languages
Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics
More informationKnowledge Representation and Reasoning Logics for Artificial Intelligence
Knowledge Representation and Reasoning Logics for Artificial Intelligence Stuart C. Shapiro Department of Computer Science and Engineering and Center for Cognitive Science University at Buffalo, The State
More informationComp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018
Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters Corky Cartwright January 26, 2018 Denotational Semantics The primary alternative to syntactic semantics is denotational semantics.
More information5. Introduction to the Lambda Calculus. Oscar Nierstrasz
5. Introduction to the Lambda Calculus Oscar Nierstrasz Roadmap > What is Computability? Church s Thesis > Lambda Calculus operational semantics > The Church-Rosser Property > Modelling basic programming
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 informationCOMP4418 Knowledge Representation and Reasoning
COMP4418 Knowledge Representation and Reasoning Week 3 Practical Reasoning David Rajaratnam Click to edit Present s Name Practical Reasoning - My Interests Cognitive Robotics. Connect high level cognition
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More informationData Integration: Datalog
Data Integration: Datalog Jan Chomicki University at Buffalo and Warsaw University Feb. 22, 2007 Jan Chomicki (UB/UW) Data Integration: Datalog Feb. 22, 2007 1 / 12 Plan of the course 1 Datalog 2 Negation
More informationProlog. Logic Programming vs Prolog
Language constructs Prolog Facts, rules, queries through examples Horn clauses Goal-oriented semantics Procedural semantics How computation is performed? Comparison to logic programming 1 Logic Programming
More informationKnowledge Representation and Reasoning Logics for Artificial Intelligence
Knowledge Representation and Reasoning Logics for Artificial Intelligence Stuart C. Shapiro Department of Computer Science and Engineering and Center for Cognitive Science University at Buffalo, The State
More informationThe Metalanguage λprolog and Its Implementation
The Metalanguage λprolog and Its Implementation Gopalan Nadathur Computer Science Department University of Minnesota (currently visiting INRIA and LIX) 1 The Role of Metalanguages Many computational tasks
More informationLecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference
Lecture #13: Type Inference and Unification Typing In the Language ML Examples from the language ML: fun map f [] = [] map f (a :: y) = (f a) :: (map f y) fun reduce f init [] = init reduce f init (a ::
More informationResolution (14A) Young W. Lim 6/14/14
Copyright (c) 2013-2014. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free
More informationSummer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define
CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationProlog. 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 informationFull Clausal Logic - Syntax: clauses
Full Clausal Logic - Syntax: clauses compound terms aggregate objects Add function symbols (functors), with an arity; constants are 0-ary functors. object proposition functor : single word starting with
More informationCOMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples:
COMP80 Programming Languages Slides Courtesy of Prof. Sam Guyer Lambda Calculus Formal system with three parts Notation for functions Proof system for equations Calculation rules called reduction Idea:
More informationOrganization of Programming Languages CS3200/5200N. Lecture 11
Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages
More informationInfinite Derivations as Failures
Infinite Derivations as Failures Andrea Corradi and Federico Frassetto DIBRIS, Università di Genova, Italy name.surname@dibris.unige.it Abstract. When operating on cyclic data, programmers have to take
More informationA Pearl on SAT Solving in Prolog (extended abstract)
A Pearl on SAT Solving in Prolog (extended abstract) Jacob M. Howe and Andy King 1 Introduction The Boolean satisfiability problem, SAT, is of continuing interest because a variety of problems are naturally
More informationProlog 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 informationDecision Procedures in the Theory of Bit-Vectors
Decision Procedures in the Theory of Bit-Vectors Sukanya Basu Guided by: Prof. Supratik Chakraborty Department of Computer Science and Engineering, Indian Institute of Technology, Bombay May 1, 2010 Sukanya
More informationAn introduction to Scheme
An introduction to Scheme Introduction A powerful programming language is more than just a means for instructing a computer to perform tasks. The language also serves as a framework within which we organize
More information