Hans Hüttel LOGIC PROGRAMMING IN PROLOG. (original slides by Claus Brabrand, IT University of Copenhagen)


 Nigel Greer
 2 years ago
 Views:
Transcription
1 "Programming Paradigms", Dept. of Computer Science, Aalborg Uni. (Autumn 2010) LOGIC PROGRAMMING IN PROLOG Hans Hüttel (original slides by Claus Brabrand, IT University of Copenhagen) Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
2 Plan for Today Lecture: "Lists and Arithmetic" (9:00 9:45) Exercise 1, 2, and 3 (10:00 11:00) Lecture: "Reversibility, Cut, Negation, and Language Interpretation" (11:00 12:00) Lunch break (12:00 13:00) Lecture: "Nontermination and Undecidability (13:00 13:45) Exercises 4, 5, and 6 (14:00 15:00)
3 Outline Part 1: Lists Part 2: Part 3: Arithmetic Reversibility Cut and Negation Language Interpretation Nontermination Undecidability
4 Resolution: PROLOG's Search Order f(a). f(b). g(a). g(b). h(b). k(x) : f(x),g(x),h(x). axioms (5x) rule (1x) rule head 1. Search knowledge base (from top to bottom) for (axiom or rule head) matching with (first) goal: Axiom match: remove goal and process next goal [ 1] Rule match: (as in this case): k(x) : f(x),g(x),h(x). [ 2] No match: backtrack (= undo; try next choice in 1.) [ 1] 2. "αconvert" variables (to avoid name clashes, later): Goal α : (record Y = _G225 ) k(_g225) Match α : [ 3] 3. Replace goal with rule body: rule body Now resolve new goals (from left to right); [ 1] k(y) k(_g225) : f(_g225),g(_g225),h(_g225). f(_g225),g(_g225),h(_g225). Possible outcomes:  success: no more goals to match (all matched w/ axioms and removed)  failure: unmatched goal (tried all possibilities: exhaustive backtracking)  nontermination: inherent risk (same / biggerandbigger / moreandmore goals)
5 LISTS Keywords: (Encoded) lists, (builtin) lists, efficiency issues,... Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
6 Lists (homemade) Lists are easily represented: nil cons(e,l) Example: // empty list // construct new list from element and list ~Haskell The list [1,2,3] may be represented as: cons(1, cons(2, cons(3, nil))) i.e., "representation of information" Now, let's look at: "Transformation of representation of information" (= programming)
7 Lists (example "functions") T Length: len(0, nil). len(succ(n), cons(e, cons(_, L)) : len(n, L). Member: member(x, cons(x, L)). member(x, cons(e, L)) : member(x, L). Using underscore '_' (anonymous "ignore" variable) may improve readability PROLOG also has builtin lists
8 Lists (builtin) Constant lists: [] [ X, Y, Z ] // the empty list // constant list ~Haskell Lists are (also) untyped; = finite sequence of (any) terms: [] [ [] ] [ vincent, jules, marcellus ] [ [], mia, 42, 'The Gimp', dead(zed), Z ] [ [], [], [ [] ], [ [ x, X, [] ] ] ] Q: What is the length of the lists?
9 The HeadTail Constructor PROLOG (like many other languages) has: [ H T ] // "headtail constructor" H head (element) of list, T tail of list (rest) for construction and deconstruction: (bigger) list viewed as element and (smaller) list ~Haskell h:t Example: construction :? [ a [b,c] ] = L. L = [a,b,c] Example: deconstruction :? [a,b,c] = [ H T ]. H = a T = [b,c]
10 Examples: [ H T ] Empty list example:? [] = [ H T ]. No Splitting a nonhomogeneous list:? [ [], mia, 42, 'The Gimp', dead(zed), Z ] = [ X Y ]. X = [] Y = [ mia, 42, 'The Gimp', dead(zed), Z ] A slightly tricky one? [ [], [] ] = [ X Y ]. X = [] Y = [ [] ]
11 Length and Member (revisited) Length/2: ~ Haskell len(0, []). len(succ(n), [ _ L ]) : len(n, L). Member/2: member(x, [ X _ ]). member(x, [ _ L ]) : member(x, L). Usage:? member(2, [1,2,3]). Yes? member(x, [1,2,3]). // gimme elements from list X=1 ; // next... X=2 ; X=3 ; No
12 Append T Append/3: Search tree for: append([], L, L). append([x L 1 ], L 2, [X L 3 ]) : append(l 1,L 2,L 3 ).? append([a,b,c], [d,e,f], R) R = [a,b,c,d,e,f] append([a,b,c],[d,e,f],_g1) append([a,b,c],[d,e,f],[a,b,c,d,e,f]) _G1 = [a _G2] rule append([b,c],[d,e,f],_g2) append([b,c],[d,e,f],[b,c,d,e,f]) _G2 = [b _G3] rule append([c],[d,e,f],_g3) append([c],[d,e,f],[c,d,e,f]) _G3 = [c _G4] rule append([],[d,e,f],_g4) append([],[d,e,f],[d,e,f]) _G4 = [d,e,f] axiom
13 Using Append Prefix/2: Suffix/2: prefix(p, L) : append(p, _, L). suffix(s, L) : append(_, S, L). SubList/2: sublist(l sub, L) : suffix(s, L), prefix(l sub, S)....or, alternatively...: sublist(l sub, L) : prefix(p, L), suffix(l sub, P).
14 Reverse (and efficiency issues) Reverse/2: Idea; exploit property: (x L) R = L R x rev([], []). rev([x L], R) : rev(l, L_rev), [L_rev X] = R. Problem: [X L] is asymmetrically lefttoright biased we cannot put the list in front and write: [ L X ] Let's use append: rev([x L], R) : rev(l, L_rev), append(l_rev, [X], R). Q: What about efficiency? 1) of append? ; 2) of reverse?
15 Efficiency Efficiency(append): app([], L, L). app([x L 1 ], L 2, [X L 3 ]) : app(l 1,L 2,L 3 ). Recall ("bigo definition"): Efficiency(reverse): arg 1 +1 O( arg 1 ) f O(g) def n,k>0: N>n => f(n) k g(n) "f is dominated by g for large values (larger than n)" rev([], []). rev([h T], R) : rev(t,t R ), app(t R,[H],R). Q: Efficiency(reverse)...?
16 Search Tree: rev rev([], []). rev([h T], R) : rev(t,t R ), app(t R,[H],R). rev([1, 2, 3], _G1) rev rule rev([2, 3], _G2), app(_g2, [1], _G1) rev rule rev([3], _G3), app(_g3, [2], _G2), app(_g2, [1], _G1) L +1 invocations (of rev) O( L ) rev rule rev([], _G4), app(_g4, [3], _G3), app(_g3, [2], _G2), app(_g2, [1], _G1) _G4 = [] rev axiom app([], [3], _G3), app(_g3, [2], _G2), app(_g2, [1], _G1) + _G3 = [3] (1 step of append) app([3], [2], _G2), app(_g2, [1], _G1) _G2 = [3,2] (2 steps of append) app([3,2], [1], _G1) invocations (of append) O( L 2 ) _G1 = [3,2,1] (3' append)
17 Accumulator T Let's use an accumulator: ~ Haskell accrev([h T], A, R) : accrev(t, [H A], R). accrev([], A, A). rev(l, R) : accrev(l, [], R). rev([1,2,3], _G1) rev rule accrev([1,2,3], [], _G1) accrev rule accrev([2,3], [1], _G1) accrev rule accrev([3], [2,1], _G1) accrev rule accrev([], [3,2,1], _G1) 1 step (of rev) oldrev vs. newrev: + L steps (of accrev) O( L ) steps O(n 2 ) oldrev O(n) newrev L
18 ARITHMETIC Keywords: Evaluation,... Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
19 Binary Infix Functors: {+,,*,/} Consider:? 2+2 = 4 false? 2*2 = 4 false? 22 = 0 false? 2/2 = 1 false What is going on...?!? The symbols {+,,*,/} are just: (Binary) infix functors: i.e., "2+2" is just a shorthand for "+(2,2)"; in fact:? 2+2 = +(2,2) true ~ Haskell
20 Binary Infix Functors (cont'd) The symbols {+,,*,/} just (conveniently) represent structured information: is understood as 12/3+4*5*6 (1(2/3))+((4*5)*6) precedence: {*,/} strongerthan {+,} associativity: {+,,*,/} leftassociative...and is thus just a shorthand for: "standard" precedence/ associativity rules +((1,/(2,3)),*(*(4,5),6)...which is, structurally, no different than: a(b(1,c(2,3)),d(d(4,5),6) However, their interpretation may be very different; e.g., "represents" an expression that may be evaluated ~ Haskell
21 The "is/2" Predicate is/2 TERM TERM: Evaluates its right argument (as arithmetic expression)...provided all variables are instantiated!? 4 is 2+2 true? X is 2+2 X=4? 2+2 is 4 false Example (in predicate definition):? 2+2 is X X=2+2 % 2+2 is not evaluated! sq(x,y) : Y is X*X.? sq(5,y). Y=25? sq(x,25). ERROR: is/2: Arguments are not sufficiently instantiated
22 Careful with Arithmetic Evaluation!! T Recall "len/2": Arithmetic version(s): len([], 0)....with unary encoding of numerals: len([_ L], succ(n)) : len(l, N). len 1 ([], 0). len 1 ([_ L], N_succ) : len 1 (L, N), N is N_succ1.? len 1 ([1,2,3], R). *** ERROR: is/2: uninstantiated argument len 2 ([], 0). len 2 ([_ L], N) : len 2 (L, N_pred), N is N_pred+1.? len 2 ([1,2,3], R). R=3 len 3 ([], 0). len 3 ([_ L], N) : N is N_pred+1, len 3 (L, N_pred). ? len 3 ([1,2,3], R). *** ERROR: is/2: uninstantiated argument
23 Accumulators (revisited) "len/2": Version with accumulator: len([], 0). len([_ T], N) : len(t, X), N is X+1. acclen([], A, A). acclen([_ T], A, N) : A new is A+1, acclen(t, A new,n) N) len(list, Length) : acclen(list, 0, Length). len([1,2,3], _G1) len rule len([2,3], _G2), _G1 is _G2+1 len rule Same #steps (both 7x) However; NOT tail recursive: "calculation after recursion" acclen([1,2,3], 0, _G1) acclen rule; then "is" acclen([2,3], 1, _G1) acclen rule; then "is" len([3], _G3), _G2 is _G3+1, _G1 is _G2+1 len rule O(n) wide! acclen([3], 2, _G1) acclen rule; then "is" len([], _G4), _G3 is _G4+1, _G2 is _G3+1, _G1 is _G2+1 acclen([], 3, _G1) len axiom _G3 is 0+1, _G2 is _G3+1, _G1 is _G2+1 is is is acclen axiom Tail recursive! "calculation during recursion" ~ Haskell
24 Comparison Operators More integer comparison operators (with arithmetic evaluation sideeffects): "<" "less than" "<=" "less than or equal to" ">" "greater than" ">=" "greater than or equal to" "=:=" "equal to" "=\=" "not equal to" Evaluate both arguments Again, all variables have to be instantiated Otherwise no surprises...
25 Exercise 1, 2, and 3: 10:00 11:00 Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
26 1.... Purpose: Learn how to...
27 2.... Purpose: Learn how to...
28 3.... Purpose: Learn how to...
29 REVERSIBILITY Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
30 Ex: Symbolic Differentiation d dx (k) = 0 d dx (x) = 1 d d (f + g) = dx dx (f)+ d dx (g) d d (f g) = dx dx (f) d dx (g) d dx (f g) = g d dx (f)+f d dx (g) d dx (f g ) = g d dx f f d g 2 dx g d dx (xn ) = n x n 1 d dx (ex ) = e x d dx (ln x) = 1 x d sin x dx = cos x d cos x = sin x dx d d (f g) = dx dx f d df (x) g(f(x))
31 ...in PROLOG e x In PROLOG: dx(k, 0) : number(k). dx(x, 1). dx(f+g, Df+Dg) : dx(f,df), dx(g,dg). dx(fg, DfDg) : dx(f,df), dx(g,dg). dx(f*g, Df*G+F*Dg) : dx(f, Df), dx(g, Dg). // constant // variable // add // sub // mul dx(f/g, (Df*GF*Dg)/(G*G)) : dx(f, Df), dx(g, Dg). // div [...] dx(cos(x), 0sin(x)). dx(f;g, (F;Dg)*Df) : dx(f,df), dx(g,dg). // cos // compose
32 Differentiation Interaction:? dx(x/exp(x), Df). Df = (1*exp(x)x*exp(x)) / (exp(x)*exp(x)) Reverse:? dx(f,(1*exp(x)x*exp(x)) / (exp(x)*exp(x))). F = x/exp(x) Does this mean we can do integration? ANF f' No, just certain functions in "anti  normal form" (ANF); i.e., functions that are in the image of the differentiation f
33 CUT AND NEGATION Keywords (chapter 10): Sideeffect, Backtracking, Cut, Fail, CutFail, Negation,... Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
34 The Cut Operator: '!' Consider max/3: max(x,y,y) : X =< Y. max(x,y,x) : X > Y. Note: mutually exclusive conditions? max(3,4,m). M = 4? ; % backtracking now causes futile reevaluation of max Cut, "!", (locally) is a goal that always succeeds and disables backtracking Cut version: max(x,y,y) : X =< Y,!. % commit (throw away maxbacktracking) max(x,y,x) : X > Y. Note: this cut changes only efficiency properties = "Green Cut"
35 "Green Cuts" vs. "Red Cuts" "Green cut" version: max(x,y,y) : X =< Y,!. max(x,y,x) : X > Y. Alternative "Red cut" version (= relying on cut): max(x,y,y) : X =< Y,!. max(x,y,x). % only succeeds if above fails (...or?) Seems okay...:? max(99,100,x). X = 100? max(100,99,x). X = 100 % ok! % ok! Advice: "cut down on cut"...but:? max(1,100,1). true % Oops! (evaluation never made it to the cut)
36 Fail and exception predicating Consider: enjoys(vincent, X) : burger(x)....but maybe Vincent likes all burgers, except "Big Kahuna burgers". PROLOG features a builtin "fail/0"predicate: Syntax: fail Semantics: "always fails (and forces backtracking)" enjoys(vincent, X) : big_kahuna_burger(x),!, fail enjoys(vincent, X) : burger(x). big_mac(b 0 ). big_kahuna_burger(b 1 ). the rule relies (operationally) on the cut = red cut? enjoys(vincent, b 0 ). true? enjoys(vincent, b 1 ). false
37 The CutFail Combination The "cutfail combination"... enjoys(vincent, X) : big_kahuna_burger(x),!, fail enjoys(vincent, X) : burger(x)....expresses negation...and is so common that it is builtin: not/1; equivalent to: not(goal) : Goal,!, fail. not(goal). It's better to use "not" it is a higher level abstraction (than cutfail); However...: Isn't always "welldefined": _ P(x) _ P(x) Cut has operationally which relation Inf. Sys. vs. PROLOG (well)defined semantics?! p(x) : not(p(x)).
38 Ifthenelse: "( A > B ; C )" PROLOG has an ifthenelse construction: Syntax: ( A > B ; C ) Semantics: "if A; then B, else C" Alternative version of max/3:...using ifthenelse: max(x,y,z) : ( X =< Y > Z = Y ; Z = X ).
39 LANGUAGE INTERPRETATION Keywords: Interpretation, Evaluation, Syntax, Semantics,... Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
40 Expressions (and syntax vs. semantics) Expressions: Syntax: Exp : N [const] : +(Exp,Exp) [add] : *(Exp,Exp) [mul] Bigstep semantics (via transition relation: "  eval Exp N "): here in prefix notation just to emphasize difference between syntax and semantics [const] _ eval N N [add] _ eval E 1 N 1 _ eval E 2 N 2 _ eval +(E 1,E 2 ) N N = N 1 N 2 syntactic "+" semantic [mul] _ eval E 1 N 1 _ eval E 2 N 2 _ eval *(E 1,E 2 ) N N = N 1 N 2 multiple levels of abstraction...!
41 Expressions (in PROLOG) Syntax: exp(con(n)) : number(n). exp(add(e 1,E 2 )) : exp(e 1 ), exp(e 2 ). exp(mul(e 1,E 2 )) : exp(e 1 ), exp(e 2 ). Semantics:? exp(mul(add(con(2),con(4)),con(7))). Yes eval(con(n), N). eval(add(e 1,E 2 ),N) : eval(e 1,N 1 ), eval(e 2,N 2 ), N is N 1 + N 2. eval(mul(e 1,E 2 ),N) : eval(e 1,N 1 ), eval(e 2,N 2 ), N is N 1 * N 2.? eval(mul(add(con(2),con(4)),con(7)),x). X = 42 eval(n, N) : number(n). binary infix syntax eval(e 1 +E 2,N) : eval(e 1,N 1 ), eval(e 2,N 2 ), N is N 1 + N 2. eval(e 1 *E 2,N) : eval(e 1,N 1 ), eval(e 2,N 2 ), N is N 1 * N 2.? eval((2+4)*7,x). X = 42 binary infix syntax
42 The Bims Language Bims is a language of simple imperative constructs: Syntax: Semantics: A ::= N // const X // var A A, {+,,*,/} // binop S ::= skip // skip X := A // assign if ( A ) then S else S // if while ( A = A ) do S // while S ; S // sequence Similar techniques (albeit somewhat more complicated)...
43 The Lambda Calculus Syntax e ::= x λx.e e 1 e 2 Semantics (callbyvalue) You only have to understand here that The Lambda Calculus can be encoded in PROLOG (Var) env x v where env(x) =v (Apply) env e 2 v 2 env e 1 v 1 env[x v 2 ] e v env e 1 e 2 v
44 The Lambda Calculus (in PROLOG) Syntax: << Exercise 4 >> Semantics: Similar techniques (as with the expression language)? eval(apply(lambda(x,variable(x)), lambda(y,variable(y)), Res). Res = lambda(y,variable(y))
45 NONTERMINATION Keywords: TuringCompleteness, Reduction, Selfreferentiality, Undecidability,... Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
46 Turing machines in Prolog It is straightforward to represent a Turing machine (Q, Σ,δ,q 0,q accept,q reject ) The tape is represented by two lists: a b b b b b a b a a L1 (reversed!) L2 So here L1 = [b,b,b,b,a,b,b] and L2 = [B,b,b,a,b,a,a] The transition function is implemented by a predicate move that describes how L1 and L2 should be updated. We can use this to implement a predicate accept to check if M accepts input w.
47 Undecidability (of failure in Prolog) Assume failure was decidable (in Java); i.e. some Java program, fails: PROLOG BOOL, can answer if a Prolog query will fail. But then the acceptance problem is decidable; encode a Turing machine M in Prolog and pose the query accepts(m,w). This query fails if and only if M does not accept w. Hence: Failure is undecidable A TM
48 Exercise 4, 5, and (6): 14:00 15:15 Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
49 4.... Purpose: Learn how to...
50 5....
51 (6).... Purpose: Learn how to...
52 The End Questions? Good luck at the exam (!) Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
53 Terminology Predicates vs. Structured data: vertical(line(point(x,y),point(x,z)). odd(succ(0)). Predicate/relation (being defined) structured data predicate structured data (being defined) Arities and Signatures: "Arity" "Signature" #arguments of a function/relation: (unary, binary, ternary,..., Nary,...) type of a function/relation: (e.g.: "+ fun ": Z Z Z ; "= rel " Z Z )
Chapter 7: Functional Programming Languages
Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language
More informationLecture 4: Lists. Theory
Lecture 4: Lists Theory Introduce lists, an important recursive data structure often used in Prolog programming Define the member/2 predicate, a fundamental Prolog tool for manipulating lists Illustrate
More informationThe current topic: Scheme. Announcements. Numeric operators. Review: car, cdr, and cons
The current topic: Scheme! Introduction! Objectoriented programming: Python Functional programming: Scheme! Introduction Next up: Numeric operators, REPL, quotes, functions, conditionals Types and values
More informationUtility programs In utilities.pro discussed at various times throughout rest of the course
Utility programs In utilities.pro discussed at various times throughout rest of the course UT1 member ( I, L ) Item I is a member of the list L. > Reduce the list second rule until first in list first
More informationProgramming Languages in Artificial Intelligence
Programming Languages in Artificial Intelligence Günter Neumann, German Research Center for Artificial Intelligence (LT Lab, DFKI) I. AI programming languages II. Functional programming III. Functional
More informationCS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 18: Intermediate Code 29 Feb 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 18: Intermediate Code 29 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Summary: Semantic Analysis Check errors not detected by lexical
More information1 Some mathematical preliminaries: sets, relations and functions
Bengt Nordström, November 4, 2013 Department of Computing Science, Chalmers and University of Göteborg, Göteborg, Sweden 1 Some mathematical preliminaries: sets, relations and functions 1.1 Propositions,
More informationThe countdown problem
JFP 12 (6): 609 616, November 2002. c 2002 Cambridge University Press DOI: 10.1017/S0956796801004300 Printed in the United Kingdom 609 F U N C T I O N A L P E A R L The countdown problem GRAHAM HUTTON
More informationMoving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an objectoriented language. This document describes some of the differences between objectoriented programming in Scheme (which we hope you
More informationDefinite Clause Grammar with Prolog. Lecture 13
Definite Clause Grammar with Prolog Lecture 13 Definite Clause Grammar The most popular approach to parsing in Prolog is Definite Clause Grammar (DCG) which is a generalization of Context Free Grammar
More informationON FUNCTIONAL SYMBOLFREE LOGIC PROGRAMS
PROCEEDINGS OF THE YEREVAN STATE UNIVERSITY Physical and Mathematical Sciences 2012 1 p. 43 48 ON FUNCTIONAL SYMBOLFREE LOGIC PROGRAMS I nf or m at i cs L. A. HAYKAZYAN * Chair of Programming and Information
More informationChapter 15 Functional Programming Languages
Chapter 15 Functional Programming Languages Introduction  The design of the imperative languages is based directly on the von Neumann architecture Efficiency (at least at first) is the primary concern,
More informationSatisfiability Checking
Satisfiability Checking FirstOrder Logic Prof. Dr. Erika Ábrahám RWTH Aachen University Informatik 2 LuFG Theory of Hybrid Systems WS 14/15 Satisfiability Checking Prof. Dr. Erika Ábrahám (RWTH Aachen
More informationInduction and Recursion
Induction and Recursion Jan van Eijck June 3, 2003 Abstract A very important proof method that is not covered by the recipes from Chapter 3 is the method of proof by Mathematical Induction. Roughly speaking,
More informationRigorous Software Development CSCIGA 3033009
Rigorous Software Development CSCIGA 3033009 Instructor: Thomas Wies Spring 2013 Lecture 11 Semantics of Programming Languages Denotational Semantics Meaning of a program is defined as the mathematical
More information+ addition  subtraction and unary minus * multiplication / division mod modulo
Chapter 4 Basic types We examine in this chapter the Caml basic types. 4.1 Numbers Caml Light provides two numeric types: integers (type int) and floatingpoint numbers (type float). Integers are limited
More informationCHAPTER 7 GENERAL PROOF SYSTEMS
CHAPTER 7 GENERAL PROOF SYSTEMS 1 Introduction Proof systems are built to prove statements. They can be thought as an inference machine with special statements, called provable statements, or sometimes
More informationInf1A: Deterministic Finite State Machines
Lecture 2 InfA: Deterministic Finite State Machines 2. Introduction In this lecture we will focus a little more on deterministic Finite State Machines. Also, we will be mostly concerned with Finite State
More information[Refer Slide Time: 05:10]
Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture
More informationCOMPUTER SCIENCE TRIPOS
CST.98.5.1 COMPUTER SCIENCE TRIPOS Part IB Wednesday 3 June 1998 1.30 to 4.30 Paper 5 Answer five questions. No more than two questions from any one section are to be answered. Submit the answers in five
More informationOverview. Elements of Programming Languages. Advanced constructs. Motivating inner class example
Overview Elements of Programming Languages Lecture 12: Objectoriented functional programming James Cheney University of Edinburgh November 6, 2015 We ve now covered: basics of functional and imperative
More informationCompilers I  Chapter 2: An introduction to syntax analysis (and a complete toy compiler)
Compilers I  Chapter 2: An introduction to syntax analysis (and a complete toy compiler) Lecturers: Part I: Paul Kelly (phjk@doc.ic.ac.uk) Office: room 423 Part II: Naranker Dulay (nd@doc.ic.ac.uk) Office:
More informationChapter 2 Mathematical Background
Chapter 2 Mathematical Background We start this chapter with a summary of basic concepts and notations for sets and firstorder logic formulas, which will be used in the rest of the book. Our aim is to
More information1.1 WHAT IS A PROGRAMMING LANGUAGE?
1 INTRODUCTION 1.1 What is a Programming Language? 1.2 Abstractions in Programming Languages 1.3 Computational Paradigms 1.4 Language Definition 1.5 Language Translation 1.6 Language Design How we communicate
More informationCSCI 3136 Principles of Programming Languages
CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2013 CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University
More informationProofs by induction, Alphabet, Strings [1] Proofs by Induction
Proofs by induction, Alphabet, Strings [1] Proofs by Induction Proposition: If f(0) = 0 and f(n + 1) = f(n) + n + 1 then, for all n N, we have f(n) = n(n + 1)/2 Let S(n) be f(n) = n(n + 1)/2 We prove S(0)
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 (revised October 8, 2004) 1 Introduction The PCAT language (Pascal Clone
More informationFunctional Programming
FP 2005 1.1 3 Functional Programming WOLFRAM KAHL kahl@mcmaster.ca Department of Computing and Software McMaster University FP 2005 1.2 4 What Kinds of Programming Languages are There? Imperative telling
More informationIntroducing Functions
Functions 1 Introducing Functions A function f from a set A to a set B, written f : A B, is a relation f A B such that every element of A is related to one element of B; in logical notation 1. (a, b 1
More informationLogic Programming using Prolog an Introductory Exercise
Logic Programming using Prolog an Introductory Exercise Brandon Bennett The purpose of this exercise is for you to see some examples of the Prolog logic programming language in action. Prolog is very different
More informationNRI Institute of Technology Principles of Programming Languages III B.Tech I Sem (R09)CSE
Unit4 Expressions and Assignment Statements Introduction Expressions are the fundamental means of specifying computations in a programming language. To understand expression evaluation, need to be familiar
More information1 Operational Semantics for While
Models of Computation, 2010 1 1 Operational Semantics for While The language While of simple while programs has a grammar consisting of three syntactic categories: numeric expressions, which represent
More informationTermination Checking: Comparing Structural Recursion and Sized Types by Examples
Termination Checking: Comparing Structural Recursion and Sized Types by Examples David Thibodeau Decemer 3, 2011 Abstract Termination is an important property for programs and is necessary for formal proofs
More informationDeterministic Discrete Modeling
Deterministic Discrete Modeling Formal Semantics of Firewalls in Isabelle/HOL Cornelius Diekmann, M.Sc. Dr. Heiko Niedermayer Prof. Dr.Ing. Georg Carle Lehrstuhl für Netzarchitekturen und Netzdienste
More informationsimplicity hides complexity
flow of control backtracking reasoning in logic and in Prolog 1 simplicity hides complexity simple and/or connections of goals conceal very complex control patterns Prolog programs are not easily represented
More informationThe previous chapter provided a definition of the semantics of a programming
Chapter 7 TRANSLATIONAL SEMANTICS The previous chapter provided a definition of the semantics of a programming language in terms of the programming language itself. The primary example was based on a Lisp
More informationIntroduction to Python
Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment
More informationPredicate Calculus. There are certain arguments that seem to be perfectly logical, yet they cannot be expressed by using propositional calculus.
Predicate Calculus (Alternative names: predicate logic, first order logic, elementary logic, restricted predicate calculus, restricted functional calculus, relational calculus, theory of quantification,
More information6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011
6.096 Lab 1 Due: 7 January 1:30:00 September 0, 011 1 Additional Material 1.1 Constants A constant is an expressions with a fixed value. Kinds of constants: Literals: used to express particular values
More informationDiagonalization. Ahto Buldas. Lecture 3 of Complexity Theory October 8, 2009. Slides based on S.Aurora, B.Barak. Complexity Theory: A Modern Approach.
Diagonalization Slides based on S.Aurora, B.Barak. Complexity Theory: A Modern Approach. Ahto Buldas Ahto.Buldas@ut.ee Background One basic goal in complexity theory is to separate interesting complexity
More informationAlgorithms and Data Structures
Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. RalfPeter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2
More informationSemester Review. CSC 301, Fall 2015
Semester Review CSC 301, Fall 2015 Programming Language Classes There are many different programming language classes, but four classes or paradigms stand out:! Imperative Languages! assignment and iteration!
More informationThe Halting Problem is Undecidable
185 Corollary G = { M, w w L(M) } is not Turingrecognizable. Proof. = ERR, where ERR is the easy to decide language: ERR = { x { 0, 1 }* x does not have a prefix that is a valid code for a Turing machine
More informationIntroduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
More informationTheory of Computation Prof. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras
Theory of Computation Prof. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture No. # 31 Recursive Sets, Recursively Innumerable Sets, Encoding
More informationProgramming Languages
Programming Languages Qing Yi Course web site: www.cs.utsa.edu/~qingyi/cs3723 cs3723 1 A little about myself Qing Yi Ph.D. Rice University, USA. Assistant Professor, Department of Computer Science Office:
More informationSources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
More informationComputability Theory
CSC 438F/2404F Notes (S. Cook and T. Pitassi) Fall, 2014 Computability Theory This section is partly inspired by the material in A Course in Mathematical Logic by Bell and Machover, Chap 6, sections 110.
More informationEncoding Mathematics in FirstOrder Logic
Applied Logic Lecture 19 CS 486 Spring 2005 Thursday, April 14, 2005 Encoding Mathematics in FirstOrder Logic Over the past few lectures, we have seen the syntax and the semantics of firstorder logic,
More informationCartesian Products and Relations
Cartesian Products and Relations Definition (Cartesian product) If A and B are sets, the Cartesian product of A and B is the set A B = {(a, b) :(a A) and (b B)}. The following points are worth special
More informationAn Agda Tutorial. Makoto Takeyama makoto.takeyama@aist.go.jp
An Agda Tutorial Misao Nagayama mnagayama@aist.go.jp Hideaki Nishihara hide.a.kit@ni.aist.go.jp Makoto Takeyama makoto.takeyama@aist.go.jp Research Center for Verification and Semantics (CVS) National
More informationSchool of Informatics, University of Edinburgh
CS1Ah Lecture Note 5 Java Expressions Many Java statements can contain expressions, which are program phrases that tell how to compute a data value. Expressions can involve arithmetic calculation and method
More informationArtificial Intelligence through Prolog by Neil C. Rowe
Calhoun: The NPS Institutional Archive Faculty and Researcher Publications Faculty and Researcher Publications Collection 1988 Artificial Intelligence through Prolog by Neil C. Rowe Rowe, Neil C. PrenticeHall
More informationINTRODUCTORY SET THEORY
M.Sc. program in mathematics INTRODUCTORY SET THEORY Katalin Károlyi Department of Applied Analysis, Eötvös Loránd University H1088 Budapest, Múzeum krt. 68. CONTENTS 1. SETS Set, equal sets, subset,
More informationCompilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.
Compilers Spring term Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.es Lecture 1 to Compilers 1 Topic 1: What is a Compiler? 3 What is a Compiler? A compiler is a computer
More informationLecture Set 2: Starting Java
Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables CMSC 131  Lecture Outlines  set
More informationCOMP2121: Microprocessors and Interfacing
Interfacing Lecture 3: Number Systems (I) http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2005 Overview Positional notation Decimal, hexadecimal and binary One complement Two s complement
More informationTaylor and Maclaurin Series
Taylor and Maclaurin Series In the preceding section we were able to find power series representations for a certain restricted class of functions. Here we investigate more general problems: Which functions
More informationComputer is a binary digital system. Data. Unsigned Integers (cont.) Unsigned Integers. Binary (base two) system: Has two states: 0 and 1
Computer Programming Programming Language Is telling the computer how to do something Wikipedia Definition: Applies specific programming languages to solve specific computational problems with solutions
More informationWe give a basic overview of the mathematical background required for this course.
1 Background We give a basic overview of the mathematical background required for this course. 1.1 Set Theory We introduce some concepts from naive set theory (as opposed to axiomatic set theory). The
More informationContextFree Grammars
ContextFree Grammars Describing Languages We've seen two models for the regular languages: Automata accept precisely the strings in the language. Regular expressions describe precisely the strings in
More informationMaster of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006
Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006 Final Examination January 24 th, 2006 NAME: Please read all instructions carefully before start answering. The exam will be
More informationCIS 500 Software Foundations Midterm I, Review Questions
CIS 500 Software Foundations Midterm I, Review Questions Untyped lambda calculus 1. (2 points) We have seen that a linear expression likeλx.λy.xyx is shorthand for an abstract syntax tree that can be drawn
More informationCertified PHP Developer VS1054
Certified PHP Developer VS1054 Certification Code VS1054 Certified PHP Developer Vskills certification for PHP Developers assesses the candidate for developing PHP based applications. The certification
More informationProlog A Tutorial Introduction James Lu Jerud J. Mead
Prolog A Tutorial Introduction James Lu Jerud J. Mead Computer Science Department Bucknell University Lewisburg, PA 17387 1 Contents 1 Introduction 1 2 Easing into Prolog 2 2.1 Logic Programming.........................................
More informationAppendix... B. The Object Constraint
UML 2.0 in a Nutshell Appendix B. The Object Constraint Pub Date: June 2005 Language The Object Constraint Language 2.0 (OCL) is an addition to the UML 2.0 specification that provides you with a way to
More informationProlog 3. Junli Tao. Rm , Tamaki Campus (Wed. 1:00pm2:00pm) Based on tutorial notes from Mike
Prolog 3 Junli Tao jtao076@aucklanduni.ac.nz Rm 321723, Tamaki Campus (Wed. 1:00pm2:00pm) Based on tutorial notes from Mike Outline Arithmetic Operations in Prolog Input/Output Streams Prolog Control
More informationChapter 6: Programming Languages
Chapter 6: Programming Languages Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Copyright 2012 Pearson Education, Inc. Chapter 6: Programming Languages 6.1 Historical Perspective
More informationOutline. Database Theory. Perfect Query Optimization. Turing Machines. Question. Definition VU , SS Trakhtenbrot s Theorem
Database Theory Database Theory Outline Database Theory VU 181.140, SS 2016 4. Trakhtenbrot s Theorem Reinhard Pichler Institut für Informationssysteme Arbeitsbereich DBAI Technische Universität Wien 4.
More informationML for the Working Programmer
ML for the Working Programmer 2nd edition Lawrence C. Paulson University of Cambridge CAMBRIDGE UNIVERSITY PRESS CONTENTS Preface to the Second Edition Preface xiii xv 1 Standard ML 1 Functional Programming
More informationMidlands Graduate School in the Foundations of Computer Science
Midlands Graduate chool in the Foundations of omputer cience Operational emantics, Abstract Machines, and orrectness Roy L. role University of Leicester, 8th to 12th April 2006 University of Nottingham,
More information1. R In this and the next section we are going to study the properties of sequences of real numbers.
+a 1. R In this and the next section we are going to study the properties of sequences of real numbers. Definition 1.1. (Sequence) A sequence is a function with domain N. Example 1.2. A sequence of real
More informationHigherOrder Logic. Specification and Verification with HigherOrder Logic
HigherOrder Logic Specification and Verification with HigherOrder Logic Arnd PoetzschHeffter Software Technology Group Fachbereich Informatik Technische Universität Kaiserslautern Sommersemester 2010
More informationInference Rules and Proof Methods
Inference Rules and Proof Methods Winter 2010 Introduction Rules of Inference and Formal Proofs Proofs in mathematics are valid arguments that establish the truth of mathematical statements. An argument
More informationDomain Theory: An Introduction
Domain Theory: An Introduction Robert Cartwright Rebecca Parsons Rice University This monograph is an unauthorized revision of Lectures On A Mathematical Theory of Computation by Dana Scott [3]. Scott
More informationThe IC Language Specification. Spring 2006 Cornell University
The IC Language Specification Spring 2006 Cornell University The IC language is a simple objectoriented language that we will use in the CS413 project. The goal is to build a complete optimizing compiler
More informationChapter 5 Parser Combinators
Part II Chapter 5 Parser Combinators 5.1 The type of parsers 5.2 Elementary parsers 5.3 Grammars 5.4 Parser combinators 5.5 Parser transformers 5.6 Matching parentheses 5.7 More parser combinators 5.8
More informationChapter 7 Uncomputability
Chapter 7 Uncomputability 190 7.1 Introduction Undecidability of concrete problems. First undecidable problem obtained by diagonalisation. Other undecidable problems obtained by means of the reduction
More informationInformation Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay
Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay Lecture  17 ShannonFanoElias Coding and Introduction to Arithmetic Coding
More informationParty Time! Computer Science I. Signature Examples PAIR OBJ. The Signature of a Procedure. Building a Set. Testing for Membership in a Set
Computer Science I Professor Tom Ellman Lecture 21 Party Time! Whom shall you invite? We will write the Party Planner program. It will select SETS of guests. By reasoning with RELATIONS. Before we party,
More informationLogic and Discrete Mathematics for Computer Scientists. James Caldwell Department of Computer Science University of Wyoming Laramie, Wyoming
Logic and Discrete Mathematics for Computer Scientists James Caldwell Department of Computer Science University of Wyoming Laramie, Wyoming Draft of August 26, 2011 c James Caldwell 1 2011 ALL RIGHTS RESERVED
More informationCS 3719 (Theory of Computation and Algorithms) Lecture 4
CS 3719 (Theory of Computation and Algorithms) Lecture 4 Antonina Kolokolova January 18, 2012 1 Undecidable languages 1.1 ChurchTuring thesis Let s recap how it all started. In 1990, Hilbert stated a
More informationThe Predicate Calculus in AI
Last time, we: The Predicate Calculus in AI Motivated the use of Logic as a representational language for AI (Can derive new facts syntactically  simply by pushing symbols around) Described propositional
More informationSemantic Analysis: Types and Type Checking
Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors
More informationUniversitetet i Linköping Institutionen för datavetenskap Anders Haraldsson
list functions TDDC65 Artificial intelligence and Lisp Lecture 2 in Lisp Recursion, symbols and lists (chapter 4, 5, 6 Haraldssons book) local variables and local functions recursion over sequences * patterns
More informationPOLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful
POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: ralf@cs.uu.nl Homepage: http://www.cs.uu.nl/~ralf/
More informationFunctional Programming. Functional Programming Languages. Chapter 14. Introduction
Functional Programming Languages Chapter 14 Introduction Functional programming paradigm History Features and concepts Examples: Lisp ML 1 2 Functional Programming Functional Programming Languages The
More informationSoftware quality improvement via pattern matching
Software quality improvement via pattern matching Radu Kopetz and PierreEtienne Moreau INRIA & LORIA {Radu.Kopetz, PierreEtienne.Moreau@loria.fr Abstract. Nested ifthenelse statements is the most common
More informationJournal of Functional Programming, volume 3 number 4, 1993. Dynamics in ML
Journal of Functional Programming, volume 3 number 4, 1993. Dynamics in ML Xavier Leroy École Normale Supérieure Michel Mauny INRIA Rocquencourt Abstract Objects with dynamic types allow the integration
More informationLogic in general. Inference rules and theorem proving
Logical Agents Knowledgebased agents Logic in general Propositional logic Inference rules and theorem proving First order logic Knowledgebased agents Inference engine Knowledge base Domainindependent
More informationOperator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax  First Example
Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementerdefined classes to specify classspecific function for operators Benefits allows classes to provide natural semantics
More informationIntegrating Formal Models into the Programming Languages Course
Integrating Formal Models into the Programming Languages Course Allen B. Tucker Robert E. Noonan Computer Science Department Computer Science Department Bowdoin College College of William and Mary Brunswick,
More informationThe Consistency of the Continuum Hypothesis Annals of Mathematical Studies, No. 3 Princeton University Press Princeton, N.J., 1940.
TWO COMPUTATIONAL IDEAS Computations with Sets Union, intersection: computable Powerset: not computable Basic operations Absoluteness of Formulas A formula in the language of set theory is absolute if
More informationAnatomy of Programming Languages. William R. Cook
Anatomy of Programming Languages William R. Cook Copyright (C) 2013 2 Chapter 1 Preliminaries Preface What? This document is a series of notes about programming languages, originally written for students
More informationHelmut Seidl. Virtual Machines. München. Summer 2011
Helmut Seidl Virtual Machines München Summer 2011 1 0 Introduction Principle of Interpretation: Program + Input Interpreter Output Advantage: No precomputation on the program text startuptime == no/short
More informationWhy? A central concept in Computer Science. Algorithms are ubiquitous.
Analysis of Algorithms: A Brief Introduction Why? A central concept in Computer Science. Algorithms are ubiquitous. Using the Internet (sending email, transferring files, use of search engines, online
More informationLecture 7: Definite Clause Grammars
Lecture 7: Definite Clause Grammars Theory Introduce context free grammars and some related concepts Introduce definite clause grammars, the Prolog way of working with context free grammars (and other
More informationPrettybigstep semantics
Prettybigstep semantics Arthur Charguéraud INRIA October 2012 1 / 34 Motivation Formalization of JavaScript with Sergio Maeis, Daniele Filaretti, Alan Schmitt, Martin Bodin. Previous work: Semiformal
More informationIt is not immediately obvious that this should even give an integer. Since 1 < 1 5
Math 163  Introductory Seminar Lehigh University Spring 8 Notes on Fibonacci numbers, binomial coefficients and mathematical induction These are mostly notes from a previous class and thus include some
More informationParametric Domaintheoretic models of Linear Abadi & Plotkin Logic
Parametric Domaintheoretic models of Linear Abadi & Plotkin Logic Lars Birkedal Rasmus Ejlers Møgelberg Rasmus Lerchedahl Petersen IT University Technical Report Series TR007 ISSN 600 600 February 00
More information