Hans Hüttel LOGIC PROGRAMMING IN PROLOG. (original slides by Claus Brabrand, IT University of Copenhagen)
|
|
- Nigel Greer
- 8 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: "Non-termination 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 Non-termination 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) - non-termination: inherent risk (same- / bigger-and-bigger- / more-and-more -goals)
5 LISTS Keywords: (Encoded) lists, (built-in) lists, efficiency issues,... Hans Hüttel/ Claus Brabrand PROGRAMMING PARADIGMS Autumn 2010
6 Lists (home-made) 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 built-in lists
8 Lists (built-in) 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 Head-Tail Constructor PROLOG (like many other languages) has: [ H T ] // "head-tail 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 non-homogeneous 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 left-to-right 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 ("big-o 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?- 2-2 = 0 false?- 2/2 = 1 false What is going on...?!? The symbols {+,-,*,/} are just: (Binary) infix functors: i.e., "2+2" is just a short-hand 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 1-2/3+4*5*6 (1-(2/3))+((4*5)*6) precedence: {*,/} stronger-than {+,-} associativity: {+,-,*,/} left-associative...and is thus just a short-hand 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_succ-1.?- 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 side-effects): "<" "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(f-g, Df-Dg) :- 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*G-F*Dg)/(G*G)) :- dx(f, Df), dx(g, Dg). // div [...] dx(cos(x), 0-sin(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): Side-effect, Backtracking, Cut, Fail, Cut-Fail, 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 re-evaluation of max Cut, "!", (locally) is a goal that always succeeds and disables backtracking Cut version: max(x,y,y) :- X =< Y,!. % commit (throw away max-backtracking) 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 built-in "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 Cut-Fail Combination The "cut-fail combination"... enjoys(vincent, X) :- big_kahuna_burger(x),!, fail enjoys(vincent, X) :- burger(x)....expresses negation...and is so common that it is built-in: not/1; equivalent to: not(goal) :- Goal,!, fail. not(goal). It's better to use "not" it is a higher level abstraction (than cut-fail); However...: Isn't always "well-defined": _ P(x) _ P(x) Cut has operationally which relation Inf. Sys. vs. PROLOG (well-)defined semantics?! p(x) :- not(p(x)).
38 If-then-else: "( A -> B ; C )" PROLOG has an if-then-else construction: Syntax: ( A -> B ; C ) Semantics: "if A; then B, else C" Alternative version of max/3:...using if-then-else: 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] Big-step 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 (call-by-value) 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 NON-TERMINATION Keywords: Turing-Completeness, Reduction, Self-referentiality, 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,..., N-ary,...) 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 informationHow To Program In Scheme (Prolog)
The current topic: Scheme! Introduction! Object-oriented 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 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 object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
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 informationRigorous Software Development CSCI-GA 3033-009
Rigorous Software Development CSCI-GA 3033-009 Instructor: Thomas Wies Spring 2013 Lecture 11 Semantics of Programming Languages Denotational Semantics Meaning of a program is defined as the mathematical
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 informationON FUNCTIONAL SYMBOL-FREE LOGIC PROGRAMS
PROCEEDINGS OF THE YEREVAN STATE UNIVERSITY Physical and Mathematical Sciences 2012 1 p. 43 48 ON FUNCTIONAL SYMBOL-FREE LOGIC PROGRAMS I nf or m at i cs L. A. HAYKAZYAN * Chair of Programming and Information
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 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: Object-oriented 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 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 informationAlgorithms and Data Structures
Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2
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 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 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 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 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 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 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 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 informationThe Halting Problem is Undecidable
185 Corollary G = { M, w w L(M) } is not Turing-recognizable. 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 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 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 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 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 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 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 1-10.
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 informationAn Agda Tutorial. Makoto Takeyama makoto.takeyama@aist.go.jp
An Agda Tutorial Misao Nagayama m-nagayama@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 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 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 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 informationINTRODUCTORY SET THEORY
M.Sc. program in mathematics INTRODUCTORY SET THEORY Katalin Károlyi Department of Applied Analysis, Eötvös Loránd University H-1088 Budapest, Múzeum krt. 6-8. CONTENTS 1. SETS Set, equal sets, subset,
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 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 Shannon-Fano-Elias 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 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 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 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 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 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 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 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 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 Church-Turing thesis Let s recap how it all started. In 1990, Hilbert stated a
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 implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics
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 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 informationCertified PHP Developer VS-1054
Certified PHP Developer VS-1054 Certification Code VS-1054 Certified PHP Developer Vskills certification for PHP Developers assesses the candidate for developing PHP based applications. The certification
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 informationPretty-big-step semantics
Pretty-big-step semantics Arthur Charguéraud INRIA October 2012 1 / 34 Motivation Formalization of JavaScript with Sergio Maeis, Daniele Filaretti, Alan Schmitt, Martin Bodin. Previous work: Semi-formal
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 10-11 Virtual Machine Software hierarchy Translator Chapters 7-8 Assembly
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 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 informationSoftware quality improvement via pattern matching
Software quality improvement via pattern matching Radu Kopetz and Pierre-Etienne Moreau INRIA & LORIA {Radu.Kopetz, Pierre-Etienne.Moreau@loria.fr Abstract. Nested if-then-else statements is the most common
More informationProgramming Language Concepts for Software Developers
Programming Language Concepts for Software Developers Peter Sestoft IT University of Copenhagen, Denmark sestoft@itu.dk Abstract This note describes and motivates our current plans for an undergraduate
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 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 04-28, 30-2014 High-Level Descriptions of Computation Instead of giving a Turing
More informationFirst-Order Theories
First-Order Theories Ruzica Piskac Max Planck Institute for Software Systems, Germany piskac@mpi-sws.org Seminar on Decision Procedures 2012 Ruzica Piskac First-Order Theories 1 / 39 Acknowledgments Theories
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 information15-150 Lecture 11: Tail Recursion; Continuations
15-150 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 informationParametric Domain-theoretic models of Linear Abadi & Plotkin Logic
Parametric Domain-theoretic models of Linear Abadi & Plotkin Logic Lars Birkedal Rasmus Ejlers Møgelberg Rasmus Lerchedahl Petersen IT University Technical Report Series TR-00-7 ISSN 600 600 February 00
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 informationLogic in general. Inference rules and theorem proving
Logical Agents Knowledge-based agents Logic in general Propositional logic Inference rules and theorem proving First order logic Knowledge-based agents Inference engine Knowledge base Domain-independent
More informationExSched: Solving Constraint Satisfaction Problems with the Spreadsheet Paradigm
ExSched: Solving Constraint Satisfaction Problems with the Spreadsheet Paradigm Siddharth Chitnis, Madhu Yennamani, Gopal Gupta Department of Computer Science The University of Texas at Dallas Richardson,
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 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 informationAutomata and Formal Languages
Automata and Formal Languages Winter 2009-2010 Yacov Hel-Or 1 What this course is all about This course is about mathematical models of computation We ll study different machine models (finite automata,
More informationSimulation-Based Security with Inexhaustible Interactive Turing Machines
Simulation-Based Security with Inexhaustible Interactive Turing Machines Ralf Küsters Institut für Informatik Christian-Albrechts-Universität zu Kiel 24098 Kiel, Germany kuesters@ti.informatik.uni-kiel.de
More informationGlossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
More informationNonlinear Algebraic Equations. Lectures INF2320 p. 1/88
Nonlinear Algebraic Equations Lectures INF2320 p. 1/88 Lectures INF2320 p. 2/88 Nonlinear algebraic equations When solving the system u (t) = g(u), u(0) = u 0, (1) with an implicit Euler scheme we have
More informationChapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
More informationMicrophone Modem Model, and MinML Modification
Programming Languages: Theory and Practice (WORKING DRAFT OF SEPTEMBER 19, 2005.) Robert Harper Carnegie Mellon University Spring Semester, 2005 Copyright c 2005. All Rights Reserved. Preface This is a
More informationA Classification Framework for Pointcut Languages in Runtime Monitoring
A Classification Framework for Pointcut Languages in Runtime Monitoring Karl Klose and Klaus Ostermann University of Aarhus, Denmark {klose,ko}@cs.au.dk Abstract. In runtime monitoring and aspect-oriented
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 informationLanguage. Johann Eder. Universitat Klagenfurt. Institut fur Informatik. Universiatsstr. 65. A-9020 Klagenfurt / AUSTRIA
PLOP: A Polymorphic Logic Database Programming Language Johann Eder Universitat Klagenfurt Institut fur Informatik Universiatsstr. 65 A-9020 Klagenfurt / AUSTRIA February 12, 1993 Extended Abstract The
More informationDebugging Prolog Programs. Contents The basic Prolog debugger Tracing program execution Spying on problem predicates
Debugging Prolog Programs Prof. Geraint A. Wiggins Centre for Cognition, Computation and Culture Goldsmiths College, University of London Contents The basic Prolog debugger Tracing program execution Spying
More informationLanguage Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages
ICOM 4036 Programming Languages Preliminaries Dr. Amirhossein Chinaei Dept. of Electrical & Computer Engineering UPRM Spring 2010 Language Evaluation Criteria Readability: the ease with which programs
More informationCompiler Construction
Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from
More informationOrganization of DSLE part. Overview of DSLE. Model driven software engineering. Engineering. Tooling. Topics:
Organization of DSLE part Domain Specific Language Engineering Tooling Eclipse plus EMF Xtext, Xtend, Xpand, QVTo and ATL Prof.dr. Mark van den Brand GLT 2010/11 Topics: Meta-modeling Model transformations
More informationJava Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More information1 Introduction. 2 An Interpreter. 2.1 Handling Source Code
1 Introduction The purpose of this assignment is to write an interpreter for a small subset of the Lisp programming language. The interpreter should be able to perform simple arithmetic and comparisons
More informationUnit 8: Immutability & Actors
SPP (Synchro et Prog Parallèle) Unit 8: Immutability & Actors François Taïani Questioning Locks Why do we need locks on data? because concurrent accesses can lead to wrong outcome But not all concurrent
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 informationCassandra. References:
Cassandra References: Becker, Moritz; Sewell, Peter. Cassandra: Flexible Trust Management, Applied to Electronic Health Records. 2004. Li, Ninghui; Mitchell, John. Datalog with Constraints: A Foundation
More informationMath 223 Abstract Algebra Lecture Notes
Math 223 Abstract Algebra Lecture Notes Steven Tschantz Spring 2001 (Apr. 23 version) Preamble These notes are intended to supplement the lectures and make up for the lack of a textbook for the course
More informationThe Habit Programming Language: The Revised Preliminary Report
The Habit Programming Language: The Revised Preliminary Report The High Assurance Systems Programming Project (Hasp) Department of Computer Science, Portland State University Portland, Oregon 97207, USA
More informationFunctional programming languages
Functional programming languages Part II: abstract machines Xavier Leroy INRIA Rocquencourt MPRI 2-4-2, 2007 X. Leroy (INRIA) Functional programming languages MPRI 2-4-2, 2007 1 / 73 Execution models for
More informationIntroduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages
Introduction Compiler esign CSE 504 1 Overview 2 3 Phases of Translation ast modifled: Mon Jan 28 2013 at 17:19:57 EST Version: 1.5 23:45:54 2013/01/28 Compiled at 11:48 on 2015/01/28 Compiler esign Introduction
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 informationComputer Programming I
Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,
More information