Assignment 4 - Solution

Size: px
Start display at page:

Download "Assignment 4 - Solution"

Transcription

1 Assignment 4 - Solution Question 1 // The key point to take into account is that the values can be obtained from the promises // in any order but we still want to resolve an array of values where all the // values vali appear in position i. function all(promises : Array<Promise<any>>) : Promise<Array<any>> { return new Promise((resolve, reject) => { let values = new Array(promises.length), pending = promises.length; if (promises.length === 0) resolve(values); // The foreach function argument receives an optional arg i // which is the position of the element in the array promises.foreach((promise: Promise<any>, i: number) => { // Trigger the internal promise i promise.then(value => { values[i] = value; pending -= 1; if (pending === 0) resolve(values); ).catch(err => { reject(err); ); ); ); 1

2 Question 2 A1 We say that two given lazy lists / generators are equivalent if their i th application yields the same value for any i > 0. A2 In the first chapter ( p. 24), we proved that f 1 and g 1 functions are equivalent: f 1 = compose(filter(iseven),map(cube)) g 1 = compose(map(cube), filter(iseven)) Since i N, iseven(i) = iseven(square(i)), the proof also holds for the functions f 2,g 2 f 2 = compose(filter(iseven),map(square)) g 2 = compose(map(square), filter(iseven)) It is sufficient to show that for each i>0, the i-th application of evensquares1 yields the i-th item in the list provided by f2, and that for each i>0, the i-th application of evensquares2 returns the i-th item in the list provided by g2. i.e, it is enough to show that: The i-th application of mapgen(square) yields the i-th item in the list provided by map(square) for the natural numbers. The i-th application of mapgen(square) yields the i-th item in the list provided by map(square) for the even numbers. The i-th application of filtergen(iseven) yields the i-th item in the list provided by filter(iseven) for the natural numbers. The i-th application of filtergen(iseven) yields the i-th item in the list provided by filter(iseven) for the squared numbers. The above four claims are established by induction on the number of generator applications. A3 We show that both fibs1 and fibs2 yield in the i-th application the i-th Fibonacci number: Proposition 1: In the n-th application of fibs1, the parameters a and b are the n-th and (n+1)-th Fibonacci numbers. Base i=1: fibs1 is instantiated with a = 0 = fib 1, b = 1 = fib 2 Induction step: if the proposition holds for i=n, in the n-th application a = fib n and b= fib n+1. According to the code of fibs1, the n+1 application will yield b [(cons b ( ))], which is, according to the induction assumption, fib n+1 Proposition 2: In the i-th application of fibs2 the number yield is the i-th Fibonacci number. Base i=1, i=2: in the first application fibs2 yields 0 = fib 1. in the second application fibs2 yields 1 = fib 2. Induction step: the (n+1)-th application of fibs2 yields the sum of the (n-1)-th and (n-2)-th applications, which are according to the induction assumption fib n-1 and fib n-2, which is by definition fib n 2

3 B function* integersfrom(n) { for (;; n++) { yield n; function* take(numbertotake, generator) { for (let i = 0; i < numbertotake; ++i) { const {done, value = generator.next(); if (done) return; else yield value; function* filtergen(generator, filterfunc) { for (let x of generator) { if (filterfunc(x)) { yield x; function first(generator) { return generator.next().value; function* sieve(generator) { // At each invocation of the sieve generator, a new prime is returned // and the sieve is wrapped in another filter. for (let sieve = generator, n = first(generator); n = first(sieve);) { sieve = filtergen(sieve, x=> (x % n)!== 0); yield n; for (n of take(10, sieve(integersfrom(2)))) { console.log(n); 3

4 Question 3 A1 1: (define append$ 2: (lambda (x y cont) 3: (if (empty? x) 4: (cont y) 5: (append$ (cdr x) y 6: (lambda (append-res) ; cont2 7: (cont (cons (car x) append-res))))))) A2 Proposition: For any lists lst1 and lst2 and a continuation procedure cont, (append$ lst1 lst2 cont) = (cont (append lst1 lst2)). Proof: By induction on the length of lst1 Base: For the case of a lst1 of length 0 [the empty list], the value of (append lst1 lst2) is lst2, and the value of (append$ lst1 lst2 cont) is (cont lst2), which implies (append$ lst1 lst2 cont) = (cont (append lst1 lst2)). Induction step: We assume the proposition holds for lst1 of length n, and show the proposition holds for lst1 of a length n+1. (a) According to the code, the value of (append lst1 lst2) is (cons (car lst1) (append (cdr lst1) lst2)). (b) According to the code,the value of (append$ lst1 lst2 cont) is (append$ (cdr lst1) lst2 cont2), where cont2 is the continuation procedure defined in lines 6-7. Since the first operand of (append$ (cdr lst1) lst2 cont2) is a list of length n, according to the induction assumption: (cont2 (append (cdr lst1) lst2)) = (append$ (cdr lst1) lst2 cont2). (cont (cons (car lst1) (append (cdr lst1) lst2))) = (append$ (cdr lst1) lst2 cont2) ;;; code of cont 2 (cont (append lst1 lst2)) = (append$ (cdr lst1) lst2 cont2) ;;; (a) (cont (append lst1 lst2)) = (append$ lst1 lst2 cont) ;;; (b) B (define leaf? (lambda (x) (not (list? x)))) ; Type: [Tree * Tree * [Tree ->T1] * [Pair->T2] -> T1 U T2 (define equal-trees$ (lambda (tree1 tree2 succ fail) (cond ((and (empty? tree1) (empty? tree2)) (succ '())) ((and (empty? tree1) (not (empty? tree2))) (fail (cons tree1 tree2)) ; Acceptable alternative 1: (fail (list tree1 tree2)) ; Acceptable alternative 2: (if (leaf? tree2) (fail(cons tree1 tree2)) (fail (cons tree1 (car tree2)))) ; Acceptable alternative 3: (if (leaf? tree2) (fail(list tree1 tree2)) (fail (list tree1 (car tree2)))) ) ((and (not (empty? tree1)) (empty? tree2)) 4

5 (fail (cons tree1 tree2)) ; Acceptable alternative 1: (fail (list tree1 tree2)) ; Acceptable alternative 2: (if (leaf? tree1) (fail (cons tree1 tree2)) (fail (cons (car tree1) tree2))) ; Acceptable alternative 3: (if (leaf? tree1) (fail (list tree1 tree2)) (fail (list (car tree1) tree2))) ) ((and (leaf? tree1) (leaf? tree2)) (succ (cons tree1 tree2))) ((and (leaf? tree1) (not (leaf? tree2))) (fail (cons tree1 tree2))) ((and (not (leaf? tree1)) (leaf? tree2)) (fail (cons tree1 tree2))) (else (equal-trees$ (car tree1) (car tree2) (lambda (suc-car) (equal-trees$ (cdr tree1) (cdr tree2) (lambda (suc-cdr) (succ (cons suc-car suc-cdr))) fail)) fail))))) 5

6 Question 4 A append([], Xs, Xs). append([x Xs], Y, [X Zs] ) :- append(xs, Y, Zs). member(x, [X _]). member(x, [_ Ys]) :- member(x, Ys). not_member(_, []). not_member(x, [Y Ys]):- X \= Y, not_member(x,ys). nodups(l1,l2):- list2set(l1,[],l2). list2set([x Xs],Acc,Ys):-not_member(X,Acc),append(Acc,[X],Z),list2set(Xs,Z,Ys). list2set([x Xs],Acc,Ys):-member(X,Acc),list2set(Xs,Acc,Ys). list2set([],acc,acc). B 1. unify[p(v(v(d(1),m,ntuf3),x)), p(v(d(b),v(b,ntuf3),ktm))] - Same predicates (p), same arity (1) -> equations = { p(v(v(d(1),m,ntuf3),x)) = p(v(d(b),v(b,ntuf3),ktm)) - Compound terms, Same predicate (p), same arity (1) -> split equation -> equations = { v(v(d(1),m,ntuf3),x) = v(d(b),v(b,ntuf3),ktm) - Compound terms, Same predicate (v), Different arities (2,3) -> Failure 2. unify[p(v(v(d(1),m,ntuf3),x)),p(v(d(b),v(b,ntuf3),ntuf3))] - Same predicates (p), same arity (1) -> equations = { p(v(v(d(1),m,ntuf3),x)) = p(v(d(b),v(b,ntuf3),ntuf3)) - Compound terms, Same predicate (p), same arity (1) -> split equation -> equations = { v(v(d(1),m,ntuf3),x) = v(d(b),v(b,ntuf3),ntuf3) - Compound terms, Same predicate (v), Different arities (2,3) -> Failure 6

7 3. unify[p(v(v(d(m),m,ntuf3),x)), p(v(d(b),v(b,ntuf3),ktm))] - Same predicates (p), same arity (1) -> equations = { p(v(v(d(m),m,ntuf3),x)) = p(v(d(b),v(b,ntuf3),ktm)) - Compound terms, Same predicate (p), same arity (1) -> split equation -> equations = { v(v(d(m),m,ntuf3),x) = v(d(b),v(b,ntuf3),ktm) - Compound terms, Same predicate (v), Different arities (2,3) -> Failure 4. unify[p(v(v(d(1),m,p),x)),p(v(d(b),v(b,ntuf3),ktm))] - Same predicates (p), same arity (1) -> equations = { p(v(v(d(1),m,p),x)) = p(v(d(b),v(b,ntuf3),ktm)) - Compound terms, Same predicate (p), same arity (1) -> split equation -> equations = { v(v(d(1),m,p),x) = v(d(b),v(b,ntuf3),ktm) - Compound terms, Same predicate (v), Different arities (2,3) -> Failure 7

8 C1 unary_plus([1 X], [1,1 Y], [1,1,1 X]) 8

9 9

10 C2 Is this a success or a failure proof tree? See definitions from the material (p.352): Finite success proof tree: A finite tree with a successful path. (Finite) Failure proof tree: A finite tree with no successful path. Infinite success proof tree: An infinite tree with a successful path. Infinite failure proof tree: An infinite tree with no successful path. Dangerous to explore. This tree is an infinite success proof tree. C3 Is this tree finite or infinite? This tree has an infinite number of success nodes and an infinite number of failure nodes. The query corresponds to the equation: unary_plus([1 X], [1,1 Y], [1,1,1 X]) X+1 + Y+2 = X+3 which results in: X+Y+3 = X+3 It has an infinite number of success answers: {X=0, Y=0 {X=1, Y=0 {X=2, Y=0... Which are encoded as unary numbers as: X=[], Y=[] X=[1], Y=[] X=[1,1], Y=[]... 10

6.001 Recitation 22: Streams

6.001 Recitation 22: Streams 6.001 Recitation 22: Streams RI: Gerald Dalley, dalleyg@mit.edu, 4 May 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ The three chief virtues of a programmer are: Laziness, Impatience and Hubris

More information

6.001 SICP September? Procedural abstraction example: sqrt (define try (lambda (guess x) (if (good-enuf? guess x) guess (try (improve guess x) x))))

6.001 SICP September? Procedural abstraction example: sqrt (define try (lambda (guess x) (if (good-enuf? guess x) guess (try (improve guess x) x)))) September? 600-Introduction Trevor Darrell trevor@csail.mit.edu -D5 6.00 web page: http://sicp.csail.mit.edu/ section web page: http://www.csail.mit.edu/~trevor/600/ Abstractions Pairs and lists Common

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP Recap: Logic, Sets, Relations, Functions

Finite Automata Theory and Formal Languages TMV027/DIT321 LP Recap: Logic, Sets, Relations, Functions Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017 Formal proofs; Simple/strong induction; Mutual induction; Inductively defined sets; Recursively defined functions. Lecture 3 Ana Bove

More information

Outline. A recursive function follows the structure of inductively-defined data.

Outline. A recursive function follows the structure of inductively-defined data. Outline A recursive function follows the structure of inductively-defined data. With lists as our example, we shall study 1. inductive definitions (to specify data) 2. recursive functions (to process data)

More information

Solutions to EoPL3 Exercises

Solutions to EoPL3 Exercises Solutions to EoPL3 Exercises Release 0.1.0 Cheng Lian May 16, 2017 Contents 1 Contents 3 2 Overview 29 i ii Author Cheng Lian Contents 1 2 Contents CHAPTER 1 Contents Chapter 1.

More information

(Ordinary) mathematical induction is a way to prove things about natural numbers. We can write it as a rule: φ(0) x. φ(x) φ(succ(x)) x.

(Ordinary) mathematical induction is a way to prove things about natural numbers. We can write it as a rule: φ(0) x. φ(x) φ(succ(x)) x. 1 Ordinary Induction (Ordinary) mathematical induction is a way to prove things about natural numbers. We can write it as a rule: φ(0) x. φ(x) φ(succ(x)) x. φ(x) where φ(x) is a statement involving a number

More information

Automated Reasoning Lecture 17: Inductive Proof (in Isabelle)

Automated Reasoning Lecture 17: Inductive Proof (in Isabelle) Automated Reasoning Lecture 17: Inductive Proof (in Isabelle) Jacques Fleuriot jdf@inf.ed.ac.uk Recap Previously: Unification and Rewriting This time: Proof by Induction (in Isabelle) Proof by Mathematical

More information

Chapter 6. Negation: Procedural Interpretation

Chapter 6. Negation: Procedural Interpretation Chapter 6 1 Outline Motivate negation with two examples Extended programs and queries The computation mechanism: SLDNF-derivations Allowed programs and queries Negation in Prolog [Apt and Bol, 1994] Krzysztof

More information

Listing up Combinations of Resistances

Listing up Combinations of Resistances Original Article 1 Listing up Combinations of Resistances ISOKAWA Yukinao* (Received 27 October, 2015) Abstract Circuits, nested connections of resistances in series and/or in parallel, are studied. We

More information

Determinacy Inference for Logic Programs

Determinacy Inference for Logic Programs Determinacy Inference for Logic Programs Lunjin Lu and Andy King Funded by NSF grants CCR-0131862 and INT-0327760 Outline of this talk Motivation Components of our analysis Experimental evaluation Conclusions

More information

Solutions to Exercises. Solution to Exercise 2.4. Solution to Exercise 2.5. D. Sabel and M. Schmidt-Schauß 1

Solutions to Exercises. Solution to Exercise 2.4. Solution to Exercise 2.5. D. Sabel and M. Schmidt-Schauß 1 D. Sabel and M. Schmidt-Schauß 1 A Solutions to Exercises Solution to Exercise 2.4 We calculate the sets of free and bound variables: FV ((λy.(y x)) (λx.(x y)) (λz.(z x y))) = FV ((λy.(y x)) (λx.(x y)))

More information

Dependent types. Paul Stansifer. March 16, 2012

Dependent types. Paul Stansifer. March 16, 2012 Dependent types Paul Stansifer March 16, 2012 1 You ve seen this before I hope you like abstraction, because we re about to use it a lot. Here s the simply-typed lambda calculus with built-in list operations

More information

Tutorial 1: Modern SMT Solvers and Verification

Tutorial 1: Modern SMT Solvers and Verification University of Illinois at Urbana-Champaign Tutorial 1: Modern SMT Solvers and Verification Sayan Mitra Electrical & Computer Engineering Coordinated Science Laboratory University of Illinois at Urbana

More information

Recursion - 1. Recursion. Recursion - 2. A Simple Recursive Example

Recursion - 1. Recursion. Recursion - 2. A Simple Recursive Example Recursion - 1 Only looping method in pure Lisp is recursion Recursion Based on Chapter 6 of Wilensky Recursive function f includes calls to f in its definition For a recursive function to eventually terminate

More information

TDDD08 Tutorial 1. Who? From? When? 6 september Victor Lagerkvist (& Wªodek Drabent)

TDDD08 Tutorial 1. Who? From? When? 6 september Victor Lagerkvist (& Wªodek Drabent) TDDD08 Tutorial 1 Who? From? Victor Lagerkvist (& Wªodek Drabent) Theoretical Computer Science Laboratory, Linköpings Universitet, Sweden When? 6 september 2015 1 / 18 Preparations Before you start with

More information

Induction. Induction. Induction. Induction. Induction. Induction 2/22/2018

Induction. Induction. Induction. Induction. Induction. Induction 2/22/2018 The principle of mathematical induction is a useful tool for proving that a certain predicate is true for all natural numbers. It cannot be used to discover theorems, but only to prove them. If we have

More information

Notes on Inductive Sets and Induction

Notes on Inductive Sets and Induction Notes on Inductive Sets and Induction Finite Automata Theory and Formal Languages TMV027/DIT21 Ana Bove, March 15th 2018 Contents 1 Induction over the Natural Numbers 2 1.1 Mathematical (Simple) Induction........................

More information

Logic as a Tool Chapter 1: Understanding Propositional Logic 1.1 Propositions and logical connectives. Truth tables and tautologies

Logic as a Tool Chapter 1: Understanding Propositional Logic 1.1 Propositions and logical connectives. Truth tables and tautologies Logic as a Tool Chapter 1: Understanding Propositional Logic 1.1 Propositions and logical connectives. Truth tables and tautologies Valentin Stockholm University September 2016 Propositions Proposition:

More information

Introduction to Logic in Computer Science: Autumn 2006

Introduction to Logic in Computer Science: Autumn 2006 Introduction to Logic in Computer Science: Autumn 2006 Ulle Endriss Institute for Logic, Language and Computation University of Amsterdam Ulle Endriss 1 Plan for Today Today s class will be an introduction

More information

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods for Software Engineering)

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods for Software Engineering) THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester 2012 COMP2600 (Formal Methods for Software Engineering) Writing Period: 3 hours duration Study Period: 15 minutes duration Permitted Materials: One A4

More information

A General Method for the Proof of Theorems on Tail-recursive Functions

A General Method for the Proof of Theorems on Tail-recursive Functions A General Method for the Proof of Theorems on Tail-recursive Functions Pasquale Noce Security Certification Specialist at Arjo Systems - Gep S.p.A. pasquale dot noce dot lavoro at gmail dot com pasquale

More information

ICS141: Discrete Mathematics for Computer Science I

ICS141: Discrete Mathematics for Computer Science I ICS141: Discrete Mathematics for Computer Science I Dept. Information & Computer Sci., Jan Stelovsky based on slides by Dr. Baek and Dr. Still Originals by Dr. M. P. Frank and Dr. J.L. Gross Provided by

More information

Propositional and Predicate Logic - V

Propositional and Predicate Logic - V Propositional and Predicate Logic - V Petr Gregor KTIML MFF UK WS 2016/2017 Petr Gregor (KTIML MFF UK) Propositional and Predicate Logic - V WS 2016/2017 1 / 21 Formal proof systems Hilbert s calculus

More information

Lazy Multivariate Higher-Order Forward-Mode AD

Lazy Multivariate Higher-Order Forward-Mode AD To appear in POPL 2007 Lazy Multivariate Higher-Order Forward-Mode AD Barak A. Pearlmutter Hamilton Institute NUI Maynooth, Ireland barak@cs.nuim.ie Jeffrey Mark Siskind School of Electrical and Computer

More information

Examples for program extraction in Higher-Order Logic

Examples for program extraction in Higher-Order Logic Examples for program extraction in Higher-Order Logic Stefan Berghofer October 10, 2011 Contents 1 Auxiliary lemmas used in program extraction examples 1 2 Quotient and remainder 2 3 Greatest common divisor

More information

ACLT: Algebra, Categories, Logic in Topology - Grothendieck's generalized topological spaces (toposes)

ACLT: Algebra, Categories, Logic in Topology - Grothendieck's generalized topological spaces (toposes) ACLT: Algebra, Categories, Logic in Topology - Grothendieck's generalized topological spaces (toposes) Steve Vickers CS Theory Group Birmingham 2. Theories and models Categorical approach to many-sorted

More information

Induction on Failing Derivations

Induction on Failing Derivations Induction on Failing Derivations Technical Report PL-Sep13 September 2013, with addenda from Spring 2016 ay Ligatti Department of Computer Science and Engineering University of South Florida Abstract A

More information

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods in Software Engineering)

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods in Software Engineering) THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester 2007 COMP2600 (Formal Methods in Software Engineering) Writing Period: 3 hours duration Study Period: 15 minutes duration Permitted Materials: None Answer

More information

Lisp Programming! Gunnar Gotshalks! LP-1

Lisp Programming! Gunnar Gotshalks! LP-1 Lisp Programming! LP-1 Boolean Functions! Return T for true and nil for false!» ( atom item )! > is item an atom, i.e. not a cons cell!» ( listp item )! > is item a list, i.e. a cons cell!» ( null item

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 4 Ana Bove March 23rd 2018 Recap: Formal Proofs How formal should a proof be? Depends on its purpose...... but should be convincing......

More information

Organon: A Symbolic Constraint Framework & Solver Isaac Evans and Joseph Lynch

Organon: A Symbolic Constraint Framework & Solver Isaac Evans and Joseph Lynch Computer Science and Artificial Intelligence Laboratory Technical Report MIT-CSAIL-TR-2013-010 May 24, 2013 Organon: A Symbolic Constraint Framework & Solver Isaac Evans and Joseph Lynch massachusetts

More information

4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd

4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd 4.8 Huffman Codes These lecture slides are supplied by Mathijs de Weerd Data Compression Q. Given a text that uses 32 symbols (26 different letters, space, and some punctuation characters), how can we

More information

Induction and Recursion

Induction and Recursion Induction and Recursion Prof. Clarkson Fall 2016 Today s music: Dream within a Dream from the soundtrack to Inception by Hans Zimmer Review Previously in 3110: Behavioral equivalence Proofs of correctness

More information

Discrete Mathematics Review

Discrete Mathematics Review CS 1813 Discrete Mathematics Discrete Mathematics Review or Yes, the Final Will Be Comprehensive 1 Truth Tables for Logical Operators P Q P Q False False False P Q False P Q False P Q True P Q True P True

More information

CS 514, Mathematics for Computer Science Mid-semester Exam, Autumn 2017 Department of Computer Science and Engineering IIT Guwahati

CS 514, Mathematics for Computer Science Mid-semester Exam, Autumn 2017 Department of Computer Science and Engineering IIT Guwahati CS 514, Mathematics for Computer Science Mid-semester Exam, Autumn 2017 Department of Computer Science and Engineering IIT Guwahati Important 1. No questions about the paper will be entertained during

More information

CS 220: Discrete Structures and their Applications. Mathematical Induction in zybooks

CS 220: Discrete Structures and their Applications. Mathematical Induction in zybooks CS 220: Discrete Structures and their Applications Mathematical Induction 6.4 6.6 in zybooks Why induction? Prove algorithm correctness (CS320 is full of it) The inductive proof will sometimes point out

More information

Mathematical Induction

Mathematical Induction Mathematical Induction COM1022 Functional Programming Techniques Professor Steve Schneider University of Surrey Semester 2, 2010 Week 10 Professor Steve Schneider Mathematical Induction Semester 2, 2010

More information

5. The Primitive Recursive Function

5. The Primitive Recursive Function 5. The Primitive Recursive Function URM and TM based on universal programming languages. In this and the next section we introduce a third model of computation. It is given as a set of partial functions

More information

Isomorphism of Finitary Inductive Types

Isomorphism of Finitary Inductive Types Isomorphism of Finitary Inductive Types Christian Sattler joint work (in progress) with Nicolai Kraus University of Nottingham May 2014 Motivating Example Generic data may be represented in a multitude

More information

Notes on Satisfiability-Based Problem Solving. First Order Logic. David Mitchell October 23, 2013

Notes on Satisfiability-Based Problem Solving. First Order Logic. David Mitchell October 23, 2013 Notes on Satisfiability-Based Problem Solving First Order Logic David Mitchell mitchell@cs.sfu.ca October 23, 2013 Preliminary draft. Please do not distribute. Corrections and suggestions welcome. In this

More information

Sequentiality in Kahn- Macqueen nets and the λ-calculus

Sequentiality in Kahn- Macqueen nets and the λ-calculus Sequentiality in Kahn- Macqueen nets and the λ-calculus Jean-Jacques Lévy Macqueen Fest, 11-05-2012 1 Plan Kahn-Macqueen networks Stability in the λ-calculus Stability in Kahn-Macqueen networks Revisiting

More information

Brief Introduction to Prolog

Brief Introduction to Prolog Brief to Prolog Joana Côrte-Real jcr@dcc.fc.up.pt CRACS & INESC TEC Faculty of Sciences University of Porto University of Aizu 5th December 2014 1 / 27 Overview 1 to Prolog Prolog Syntax Tutorial 1 2 Lists

More information

Discrete Mathematics. Spring 2017

Discrete Mathematics. Spring 2017 Discrete Mathematics Spring 2017 Previous Lecture Principle of Mathematical Induction Mathematical Induction: Rule of Inference Mathematical Induction: Conjecturing and Proving Mathematical Induction:

More information

Notes on induction proofs and recursive definitions

Notes on induction proofs and recursive definitions Notes on induction proofs and recursive definitions James Aspnes December 13, 2010 1 Simple induction Most of the proof techniques we ve talked about so far are only really useful for proving a property

More information

Meta-Circularity, and Vice-Versa

Meta-Circularity, and Vice-Versa 1/60, and Vice-Versa didier@lrde.epita.fr http://www.lrde.epita.fr/ didier ACCU 2011 Thursday, April 14th 2/60 Table of contents 1 2 Symbolic Expressions 3 The of LISP 4 5 6 7 8 Dynamic 9 4/60 circularity

More information

Teaching Natural Deduction as a Subversive Activity

Teaching Natural Deduction as a Subversive Activity Teaching Natural Deduction as a Subversive Activity James Caldwell Department of Computer Science University of Wyoming Laramie, WY Third International Congress on Tools for Teaching Logic 3 June 2011

More information

Predicate Logic - Semantic Tableau

Predicate Logic - Semantic Tableau CS402, Spring 2016 Informal Construction of a Valid Formula Example 1 A valid formula: x(p(x) q(x)) ( xp(x) xq(x)) ( x(p(x) q(x)) ( xp(x) xq(x))) x(p(x) q(x)), ( xp(x) xq(x)) x(p(x) q(x)), xp(x), xq(x)

More information

An Abstract Decision Procedure for a Theory of Inductive Data Types

An Abstract Decision Procedure for a Theory of Inductive Data Types An Abstract Decision Procedure for a Theory of Inductive Data Types lark Barrett Igor Shikanian Department of omputer Science ourant Institute of Mathematical Sciences New York University esare Tinelli

More information

DEBUGGING AND TESTING WITH SCALACHECK. Martina Seidl 2017/11/14

DEBUGGING AND TESTING WITH SCALACHECK. Martina Seidl 2017/11/14 DEBUGGING AND TESTING WITH SCALACHECK Martina Seidl 2017/11/14 Some Words on Scala Scala is object-oriented every value is an object classes and traits: types and behavior of objects inheritance Scala

More information

Search Algorithms. Analysis of Algorithms. John Reif, Ph.D. Prepared by

Search Algorithms. Analysis of Algorithms. John Reif, Ph.D. Prepared by Search Algorithms Analysis of Algorithms Prepared by John Reif, Ph.D. Search Algorithms a) Binary Search: average case b) Interpolation Search c) Unbounded Search (Advanced material) Readings Reading Selection:

More information

Using the Prover I: Lee Pike. June 3, NASA Langley Formal Methods Group Using the Prover I:

Using the Prover I: Lee Pike. June 3, NASA Langley Formal Methods Group Using the Prover I: Basic Basic NASA Langley Formal Methods Group lee.s.pike@nasa.gov June 3, 2005 Basic Sequents Basic Sequent semantics: The conjunction of the antecedents above the turnstile implies the disjunction of

More information

An Introduction to Z3

An Introduction to Z3 An Introduction to Z3 Huixing Fang National Trusted Embedded Software Engineering Technology Research Center April 12, 2017 Outline 1 SMT 2 Z3 Huixing Fang (ECNU) An Introduction to Z3 April 12, 2017 2

More information

Every formula evaluates to either \true" or \false." To say that the value of (x = y) is true is to say that the value of the term x is the same as th

Every formula evaluates to either \true or \false. To say that the value of (x = y) is true is to say that the value of the term x is the same as th A Quick and Dirty Sketch of a Toy Logic J Strother Moore January 9, 2001 Abstract For the purposes of this paper, a \logic" consists of a syntax, a set of axioms and some rules of inference. We dene a

More information

Search and Lookahead. Bernhard Nebel, Julien Hué, and Stefan Wölfl. June 4/6, 2012

Search and Lookahead. Bernhard Nebel, Julien Hué, and Stefan Wölfl. June 4/6, 2012 Search and Lookahead Bernhard Nebel, Julien Hué, and Stefan Wölfl Albert-Ludwigs-Universität Freiburg June 4/6, 2012 Search and Lookahead Enforcing consistency is one way of solving constraint networks:

More information

IS 709/809: Computational Methods for IS Research. Math Review: Algorithm Analysis

IS 709/809: Computational Methods for IS Research. Math Review: Algorithm Analysis IS 709/809: Computational Methods for IS Research Math Review: Algorithm Analysis Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Topics Proof techniques

More information

6.001, Fall Semester, 1998 Problem Set 5 2 (define (adjoin-term term series) (cons-stream term series) Since this does not produce an error, he shows

6.001, Fall Semester, 1998 Problem Set 5 2 (define (adjoin-term term series) (cons-stream term series) Since this does not produce an error, he shows 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 1998 Issued: Thursday, October 15,

More information

GENERATING SETS AND DECOMPOSITIONS FOR IDEMPOTENT TREE LANGUAGES

GENERATING SETS AND DECOMPOSITIONS FOR IDEMPOTENT TREE LANGUAGES Atlantic Electronic http://aejm.ca Journal of Mathematics http://aejm.ca/rema Volume 6, Number 1, Summer 2014 pp. 26-37 GENERATING SETS AND DECOMPOSITIONS FOR IDEMPOTENT TREE ANGUAGES MARK THOM AND SHEY

More information

Lifted Inference: Exact Search Based Algorithms

Lifted Inference: Exact Search Based Algorithms Lifted Inference: Exact Search Based Algorithms Vibhav Gogate The University of Texas at Dallas Overview Background and Notation Probabilistic Knowledge Bases Exact Inference in Propositional Models First-order

More information

Algebraic View of Computation. Primitive Recursive Functions. We can assign a term to each partial recursive function. E.g.

Algebraic View of Computation. Primitive Recursive Functions. We can assign a term to each partial recursive function. E.g. 5. The Primitive Recursive Functions Algebraic View of Computation In this module we consider 3 models of computation. The URMs, which captures computation as it happens on a computer. The Turing Machines,

More information

SIGNAL COMPRESSION Lecture 7. Variable to Fix Encoding

SIGNAL COMPRESSION Lecture 7. Variable to Fix Encoding SIGNAL COMPRESSION Lecture 7 Variable to Fix Encoding 1. Tunstall codes 2. Petry codes 3. Generalized Tunstall codes for Markov sources (a presentation of the paper by I. Tabus, G. Korodi, J. Rissanen.

More information

1 Efficient Transformation to CNF Formulas

1 Efficient Transformation to CNF Formulas 1 Efficient Transformation to CNF Formulas We discuss an algorithm, due to Tseitin [?], which efficiently transforms an arbitrary Boolean formula φ to a CNF formula ψ such that ψ has a model if and only

More information

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth Today 1. What is the Lambda Calculus? Type Systems 2. Its Syntax and Semantics 3. Church Booleans and Church Numerals 4. Lazy vs. Eager Evaluation (call-by-name vs. call-by-value) Lecture 2 Oct. 27th,

More information

Preliminaries. Introduction to EF-games. Inexpressivity results for first-order logic. Normal forms for first-order logic

Preliminaries. Introduction to EF-games. Inexpressivity results for first-order logic. Normal forms for first-order logic Introduction to EF-games Inexpressivity results for first-order logic Normal forms for first-order logic Algorithms and complexity for specific classes of structures General complexity bounds Preliminaries

More information

Parts 3-6 are EXAMPLES for cse634

Parts 3-6 are EXAMPLES for cse634 1 Parts 3-6 are EXAMPLES for cse634 FINAL TEST CSE 352 ARTIFICIAL INTELLIGENCE Fall 2008 There are 6 pages in this exam. Please make sure you have all of them INTRODUCTION Philosophical AI Questions Q1.

More information

Nunchaku: Flexible Model Finding for Higher-Order Logic

Nunchaku: Flexible Model Finding for Higher-Order Logic Nunchaku: Flexible Model Finding for Higher-Order Logic Simon Cruanes, Jasmin Blanchette, Andrew Reynolds Veridis, Inria Nancy https://cedeela.fr/~simon/ April 7th, 2016 1 / 21 Summary Introduction Nunchaku

More information

Accumulators More on Arithmetic and Recursion

Accumulators More on Arithmetic and Recursion Accumulators More on Arithmetic and Recursion Shakil M. Khan adapted from Gunnar Gotshalks listlen ( L, N ) L is a list of length N if... listlen ( [], 0 ). listlen ( [ H T ], N ) :- listlen ( T, N1 ),

More information

Algorithms (II) Yu Yu. Shanghai Jiaotong University

Algorithms (II) Yu Yu. Shanghai Jiaotong University Algorithms (II) Yu Yu Shanghai Jiaotong University Chapter 1. Algorithms with Numbers Two seemingly similar problems Factoring: Given a number N, express it as a product of its prime factors. Primality:

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017 Lecture 4 Ana Bove March 24th 2017 Structural induction; Concepts of automata theory. Overview of today s lecture: Recap: Formal Proofs

More information

Analyse et Conception Formelle. Lesson 4. Proofs with a proof assistant

Analyse et Conception Formelle. Lesson 4. Proofs with a proof assistant Analyse et Conception Formelle Lesson 4 Proofs with a proof assistant T. Genet (ISTIC/IRISA) ACF-4 1 / 26 Prove logic formulas... to prove programs fun nth:: "nat => a list => a" where "nth 0 (x#_)=x"

More information

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007 CSE 230: Winter 2007 Principles of Programming Languages Lecture 12: The λ-calculus Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2 Several evaluation

More information

ICS141: Discrete Mathematics for Computer Science I

ICS141: Discrete Mathematics for Computer Science I ICS141: Discrete Mathematics for Computer Science I Dept. Information & Computer Sci., Originals slides by Dr. Baek and Dr. Still, adapted by J. Stelovsky Based on slides Dr. M. P. Frank and Dr. J.L. Gross

More information

Extending the Lambda Calculus: An Eager Functional Language

Extending the Lambda Calculus: An Eager Functional Language Syntax of the basic constructs: Extending the Lambda Calculus: An Eager Functional Language canonical forms z cfm ::= intcfm boolcfm funcfm tuplecfm altcfm intcfm ::= 0 1-1... boolcfm ::= boolconst funcfm

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem

More information

G52DOA - Derivation of Algorithms Predicate Logic

G52DOA - Derivation of Algorithms Predicate Logic G52DOA - Derivation of Algorithms Predicate Logic Venanzio Capretta Predicate Logic So far, we studied propositional logic, in which we started with unspecified propositional variables A, B, C, and combined

More information

Data Structure. Mohsen Arab. January 13, Yazd University. Mohsen Arab (Yazd University ) Data Structure January 13, / 86

Data Structure. Mohsen Arab. January 13, Yazd University. Mohsen Arab (Yazd University ) Data Structure January 13, / 86 Data Structure Mohsen Arab Yazd University January 13, 2015 Mohsen Arab (Yazd University ) Data Structure January 13, 2015 1 / 86 Table of Content Binary Search Tree Treaps Skip Lists Hash Tables Mohsen

More information

Deterministic Finite Automata

Deterministic Finite Automata Deterministic Finite Automata COMP2600 Formal Methods for Software Engineering Ranald Clouston Australian National University Semester 2, 2013 COMP 2600 Deterministic Finite Automata 1 Pop quiz What is

More information

CS5371 Theory of Computation. Lecture 18: Complexity III (Two Classes: P and NP)

CS5371 Theory of Computation. Lecture 18: Complexity III (Two Classes: P and NP) CS5371 Theory of Computation Lecture 18: Complexity III (Two Classes: P and NP) Objectives Define what is the class P Examples of languages in P Define what is the class NP Examples of languages in NP

More information

Backwards Strictness Analysis: Proved and Improved. Kei Davis. Philip Wadler. University of Glasgow. Glasgow G12 8QQ. Abstract

Backwards Strictness Analysis: Proved and Improved. Kei Davis. Philip Wadler. University of Glasgow. Glasgow G12 8QQ. Abstract Backwards Strictness Analysis: Proved and Improved Kei Davis Philip Wadler Dept. of Computing Science University of Glasgow Glasgow G12 8QQ United Kingdom Abstract Given a syntax tree representing an expression,

More information

9. Quantifier-free Equality and Data Structures

9. Quantifier-free Equality and Data Structures 9. Quantifier-free Equality and Data Structures The Theory of Equality T E Σ E : {=, a, b, c,..., f, g, h,..., p, q, r,...} uninterpreted symbols: constants a, b, c,... functions f, g, h,... predicates

More information

F 99 Final Quiz Solutions

F 99 Final Quiz Solutions Massachusetts Institute of Technology Handout 53 6.04J/18.06J: Mathematics for Computer Science May 11, 000 Professors David Karger and Nancy Lynch F 99 Final Quiz Solutions Problem 1 [18 points] Injections

More information

Resolution for Predicate Logic

Resolution for Predicate Logic Logic and Proof Hilary 2016 James Worrell Resolution for Predicate Logic A serious drawback of the ground resolution procedure is that it requires looking ahead to predict which ground instances of clauses

More information

Propositional Logic: Part II - Syntax & Proofs 0-0

Propositional Logic: Part II - Syntax & Proofs 0-0 Propositional Logic: Part II - Syntax & Proofs 0-0 Outline Syntax of Propositional Formulas Motivating Proofs Syntactic Entailment and Proofs Proof Rules for Natural Deduction Axioms, theories and theorems

More information

Foundations of Artificial Intelligence

Foundations of Artificial Intelligence Foundations of Artificial Intelligence 31. Propositional Logic: DPLL Algorithm Malte Helmert and Gabriele Röger University of Basel April 24, 2017 Propositional Logic: Overview Chapter overview: propositional

More information

Advanced Implementations of Tables: Balanced Search Trees and Hashing

Advanced Implementations of Tables: Balanced Search Trees and Hashing Advanced Implementations of Tables: Balanced Search Trees and Hashing Balanced Search Trees Binary search tree operations such as insert, delete, retrieve, etc. depend on the length of the path to the

More information

Programming Languages

Programming Languages CSE 230: Winter 2010 Principles of Programming Languages Lecture 10: Programming in λ-calculusc l l Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2

More information

Mid-Semester Quiz Second Semester, 2012

Mid-Semester Quiz Second Semester, 2012 THE AUSTRALIAN NATIONAL UNIVERSITY Mid-Semester Quiz Second Semester, 2012 COMP2600 (Formal Methods for Software Engineering) Writing Period: 1 hour duration Study Period: 10 minutes duration Permitted

More information

Much Ado about Two. By Sascha Böhme. February 22, 2013

Much Ado about Two. By Sascha Böhme. February 22, 2013 Much Ado about Two By Sascha Böhme February 22, 2013 Abstract This article is an Isabelle formalisation of a paper with the same. In a similar way as Knuth s 0-1-principle for sorting algorithms, that

More information

Formalizing Kruskal s Tree Theorem in Isabelle/HOL

Formalizing Kruskal s Tree Theorem in Isabelle/HOL Formalizing Kruskal s Tree Theorem in Isabelle/HOL Christian Sternagel JAIST July 5, 2012 Kickoff Meeting of Austria-Japan Joint Project Gamagori, Japan Kruskal s Tree Theorem If the set A is well-quasi-ordered

More information

Outline. Computer Science 331. Cost of Binary Search Tree Operations. Bounds on Height: Worst- and Average-Case

Outline. Computer Science 331. Cost of Binary Search Tree Operations. Bounds on Height: Worst- and Average-Case Outline Computer Science Average Case Analysis: Binary Search Trees Mike Jacobson Department of Computer Science University of Calgary Lecture #7 Motivation and Objective Definition 4 Mike Jacobson (University

More information

HOL: Well-founded and Primitive Recursion

HOL: Well-founded and Primitive Recursion Dipl.-Inf. Achim D. Brucker Dr. Burkhart Wolff Computer-supported Modeling and Reasoning http://www.infsec.ethz.ch/ education/permanent/csmr/ (rev. 16814) Submission date: HOL: Well-founded and Primitive

More information

Meta-programming & you

Meta-programming & you Meta-programming & you Robin Message Cambridge Programming Research Group 10 th May 2010 What s meta-programming about? 1 result=somedb. customers. select 2 { first_name+ +last_name } 3 where name LIKE

More information

Induction and recursion. Topics. Induction and Recursion Vojislav Kecman CMSC 302

Induction and recursion. Topics. Induction and Recursion Vojislav Kecman CMSC 302 Induction and recursion are related concepts. VCU, Department of Computer Science CMSC 302 Induction and Recursion Vojislav Kecman Induction is a proof technique, recursion is a related programming concept.

More information

Automatic Deduction for Theories of. Algebraic Data Types. Igor A. Chikanian

Automatic Deduction for Theories of. Algebraic Data Types. Igor A. Chikanian Automatic Deduction for Theories of Algebraic Data Types by Igor A. Chikanian A dissertation submitted in partial fulfillment of the requirements for the degree of Doctor of Philosophy Department of Computer

More information

Lecture 9 CS 1813 Discrete Mathematics. Predicate Calculus. Propositions Plus Plus

Lecture 9 CS 1813 Discrete Mathematics. Predicate Calculus. Propositions Plus Plus Lecture 9 CS 1813 Discrete Mathematics Predicate Calculus Propositions Plus Plus 1 Predicate What is a Predicate? Parameterized collection of propositions P(x) Typically a different proposition for each

More information

Type Soundness for Path Polymorphism

Type Soundness for Path Polymorphism Type Soundness for Path Polymorphism Andrés Ezequiel Viso 1,2 joint work with Eduardo Bonelli 1,3 and Mauricio Ayala-Rincón 4 1 CONICET, Argentina 2 Departamento de Computación, FCEyN, UBA, Argentina 3

More information

Roy L. Crole. Operational Semantics Abstract Machines and Correctness. University of Leicester, UK

Roy L. Crole. Operational Semantics Abstract Machines and Correctness. University of Leicester, UK Midlands Graduate School, University of Birmingham, April 2008 1 Operational Semantics Abstract Machines and Correctness Roy L. Crole University of Leicester, UK Midlands Graduate School, University of

More information

Discrete Math, Spring Solutions to Problems V

Discrete Math, Spring Solutions to Problems V Discrete Math, Spring 202 - Solutions to Problems V Suppose we have statements P, P 2, P 3,, one for each natural number In other words, we have the collection or set of statements {P n n N} a Suppose

More information

COMP Assignment 1 Solutions

COMP Assignment 1 Solutions COMP 409 - Assignment 1 Solutions 1 Show that there are no formulas of length 2,3, or 6, but that every other length is possible. Let p, q and r be atomic propositions. Then p is a formula of length 1,

More information

An Abstract Decision Procedure for Satisfiability in the Theory of Recursive Data Types

An Abstract Decision Procedure for Satisfiability in the Theory of Recursive Data Types An Abstract Decision Procedure for Satisfiability in the Theory of Recursive Data Types Clark Barrett 1 Igor Shikanian 1 Cesare Tinelli 2 1 New York University, barrett igor@cs.nyu.edu 2 The University

More information

A Reduction Approach to Decision Procedures

A Reduction Approach to Decision Procedures A Reduction Approach to Decision Procedures Deepak Kapur and Calogero G. Zarba University of New Mexico Abstract. We present an approach for designing decision procedures based on the reduction of complex

More information