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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 informationRelations: their uses in programming and computational specifications
PEPS Relations, 15 December 2008 1/27 Relations: their uses in programming and computational specifications Dale Miller INRIA  Saclay & LIX, Ecole Polytechnique 1. Logic and computation Outline 2. Comparing
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 information198:211 Computer Architecture
198:211 Computer Architecture Topics: Lecture 8 (W5) Fall 2012 Data representation 2.1 and 2.2 of the book Floating point 2.4 of the book 1 Computer Architecture What do computers do? Manipulate stored
More informationContext free grammars and predictive parsing
Context free grammars and predictive parsing Programming Language Concepts and Implementation Fall 2012, Lecture 6 Context free grammars Next week: LR parsing Describing programming language syntax Ambiguities
More information13 Infinite Sets. 13.1 Injections, Surjections, and Bijections. mcsftl 2010/9/8 0:40 page 379 #385
mcsftl 2010/9/8 0:40 page 379 #385 13 Infinite Sets So you might be wondering how much is there to say about an infinite set other than, well, it has an infinite number of elements. Of course, an infinite
More informationCSE 135: Introduction to Theory of Computation Decidability and Recognizability
CSE 135: Introduction to Theory of Computation Decidability and Recognizability Sungjin Im University of California, Merced 0428, 302014 HighLevel Descriptions of Computation Instead of giving a Turing
More information6.170 Tutorial 3  Ruby Basics
6.170 Tutorial 3  Ruby Basics Prerequisites 1. Have Ruby installed on your computer a. If you use Mac/Linux, Ruby should already be preinstalled on your machine. b. If you have a Windows Machine, you
More information6 Creating the Animation
6 Creating the Animation Now that the animation can be represented, stored, and played back, all that is left to do is understand how it is created. This is where we will use genetic algorithms, and this
More informationThe Prolog to Mercury transition guide
The Prolog to Mercury transition guide Version rotd20160606 Thomas Conway Zoltan Somogyi Fergus Henderson Copyright c 1995 2012 The University of Melbourne. Copyright c 2013 2016 The Mercury team. Permission
More information15150 Lecture 11: Tail Recursion; Continuations
15150 Lecture 11: Tail Recursion; Continuations Lecture by Dan Licata February 21, 2011 In this lecture we will discuss space usage: analyzing the memory it takes your program to run tail calls and tail
More informationA Scala Tutorial for Java programmers
A Scala Tutorial for Java programmers Version 1.3 January 16, 2014 Michel Schinz, Philipp Haller PROGRAMMING METHODS LABORATORY EPFL SWITZERLAND 2 1 Introduction This document gives a quick introduction
More information2. Abstract State Machines
2. Abstract State Machines The notion of Abstract State Machines (ASMs), defined in [20], captures in mathematically rigorous yet transparent form some fundamental operational intuitions of computing,
More informationFirstOrder Theories
FirstOrder Theories Ruzica Piskac Max Planck Institute for Software Systems, Germany piskac@mpisws.org Seminar on Decision Procedures 2012 Ruzica Piskac FirstOrder Theories 1 / 39 Acknowledgments Theories
More informationSoftware Analysis (POPA Sec , )
Software Analysis (POPA Sec. 2.2.2, 2.52.5.2) Klaus Ostermann Based on slides by Jurriaan Hage Overview Correctness proof Live Variables Analysis The While language with procedures Live Variables Analysis
More informationAn important theme in this book is to give constructive definitions of mathematical objects. Thus, for instance, if you needed to evaluate.
Chapter 10 Series and Approximations An important theme in this book is to give constructive definitions of mathematical objects. Thus, for instance, if you needed to evaluate 1 0 e x2 dx, you could set
More informationToday s Outline. Exercise. Binary Search Analysis. Linear Search Analysis. Asymptotic Analysis. Analyzing Code. Announcements. Asymptotic Analysis
Today s Outline Announcements Assignment #1 due Thurs, Oct 7 at 11:45pm Asymptotic Analysis Asymptotic Analysis CSE 7 Data Structures & Algorithms Ruth Anderson Autumn 2010 Exercise Analyzing Code bool
More informationPOWER SETS AND RELATIONS
POWER SETS AND RELATIONS L. MARIZZA A. BAILEY 1. The Power Set Now that we have defined sets as best we can, we can consider a sets of sets. If we were to assume nothing, except the existence of the empty
More informationLecture 1: Time Complexity
Computational Complexity Theory, Fall 2010 August 25 Lecture 1: Time Complexity Lecturer: Peter Bro Miltersen Scribe: Søren Valentin Haagerup 1 Introduction to the course The field of Computational Complexity
More informationArithmetic Coding: Introduction
Data Compression Arithmetic coding Arithmetic Coding: Introduction Allows using fractional parts of bits!! Used in PPM, JPEG/MPEG (as option), Bzip More time costly than Huffman, but integer implementation
More informationSoftware Engineering
Software Engineering Lecture 04: The B Specification Method Peter Thiemann University of Freiburg, Germany SS 2013 Peter Thiemann (Univ. Freiburg) Software Engineering SWT 1 / 50 The B specification method
More informationLanguage. Johann Eder. Universitat Klagenfurt. Institut fur Informatik. Universiatsstr. 65. A9020 Klagenfurt / AUSTRIA
PLOP: A Polymorphic Logic Database Programming Language Johann Eder Universitat Klagenfurt Institut fur Informatik Universiatsstr. 65 A9020 Klagenfurt / AUSTRIA February 12, 1993 Extended Abstract The
More informationSJÄLVSTÄNDIGA ARBETEN I MATEMATIK
SJÄLVSTÄNDIGA ARBETEN I MATEMATIK MATEMATISKA INSTITUTIONEN, STOCKHOLMS UNIVERSITET Automated Theorem Proving av Tom Everitt 2010  No 8 MATEMATISKA INSTITUTIONEN, STOCKHOLMS UNIVERSITET, 106 91 STOCKHOLM
More informationRepetition and Loops. Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed.
New Topic Repetition and Loops Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed. These constructs are the 1. while loop and
More informationStacks. The stack ADT Stack Implementation. Stack Examples. using arrays using generic linked lists using List ADT. EECS 268 Programming II 1
Stacks The stack ADT Stack Implementation using arrays using generic linked lists using List ADT Stack Examples 1 Stacks and Queues Linear data structures each item has specific first, next, and previous
More informationCompiler I: Syntax Analysis Human Thought
Course map Compiler I: Syntax Analysis Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 1011 Virtual Machine Software hierarchy Translator Chapters 78 Assembly
More informationAutomata and Formal Languages
Automata and Formal Languages Winter 20092010 Yacov HelOr 1 What this course is all about This course is about mathematical models of computation We ll study different machine models (finite automata,
More informationComputational Models Lecture 8, Spring 2009
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown Univ. p. 1 Computational Models Lecture 8, Spring 2009 Encoding of TMs Universal Turing Machines The Halting/Acceptance
More informationFIRST YEAR CALCULUS. Chapter 7 CONTINUITY. It is a parabola, and we can draw this parabola without lifting our pencil from the paper.
FIRST YEAR CALCULUS WWLCHENW L c WWWL W L Chen, 1982, 2008. 2006. This chapter originates from material used by the author at Imperial College, University of London, between 1981 and 1990. It It is is
More informationThe following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).
CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical
More informationOBJECT ORIENTED PROGRAMMING IN C++
OBJECT ORIENTED PROGRAMMING IN C++ For Off Campus BSc Computer Science Programme UNIT 1 1. The goal of programmers is to develop software that are. A. Correct B. Reliable and maintainable C. Satisfy all
More information24 Uses of Turing Machines
Formal Language and Automata Theory: CS2004 24 Uses of Turing Machines 24 Introduction We have previously covered the application of Turing Machine as a recognizer and decider In this lecture we will discuss
More information