Types and Programming Languages (15-814), Fall 2018 Assignment 4: Data Representation (Sample Solutions)

Size: px
Start display at page:

Download "Types and Programming Languages (15-814), Fall 2018 Assignment 4: Data Representation (Sample Solutions)"

Transcription

1 Types and Programming Languages (15-814), Fall 2018 Assignment 4: Data Representation (Sample Solutions) Contact: Course Staff Due Tuesday, October 16, 2018, 10:30am This assignment is due by 10:30am on the above date and it must be submitted electronically as a PDF file on Canvas. Please use the attached template to typeset your assignment and make sure to include your full name and Andrew ID. As before, problems marked WB are subject to the whiteboard policy; all other problems must be done individually. We have again provided you the syntax, statics, and dynamics for our simple language from class. Please ensure that your terms are syntactically correct and that they have the right type! General hint. Consider whether the results from a given task can be used to solve subsequent tasks! Task 1 (0 points). How long did you spend on this assignment? Please list the questions that you discussed with classmates using the whiteboard policy. 1 Natural Numbers in Binary Form Recall the definition of natural numbers in binary representation in the first line below and the isomorphism satisfied by this type. bin = ρ(α. (b0 : α) + (b1 : α) + (ɛ : 1)) bin = (b0 : bin) + (b1 : bin) + (ɛ : 1) 1

2 We also defined the constants and functions bzero, dbl0, and dbl1 encapsulating the constructors for binary numbers. bzero : bin = fold (ɛ ) dbl0 : bin bin = λx. fold (b0 x) dbl1 : bin bin = λx. fold (b1 x) Also recall the increment function from lecture: inc : bin bin = fix(i. λx. case (unfold x) { b0 y fold (b1 y) b1 y fold (b0 (i y)) ɛ fold (b1 (fold (ɛ ))) }) In order to simplify the typesetting task and make the code easier to write and read, we encourage you to use verbatim code 1 that exploits pattern matching, recursive definitions of functions by name, and constructor functions with implicit fold and unfold operations. For example, the definitions above might be written as bzero = eps () dbl0 x = b0 x dlb1 x = b1 x inc (b0 y) = b1 y inc (b1 y) = b0 (inc y) inc (eps _) = b1 (eps ()) Task 2 (5 points, WB). Define a function plus : bin bin bin that adds two natural numbers in binary form. You may use the functions and constants defined above. Solution 2: plus (b0 x) (b0 y) = b0 (plus x y) plus (b0 x) (b1 y) = b1 (plus x y) plus (b0 x) (eps _) = b0 x plus (b1 x) (b0 y) = b1 (plus x y) plus (b1 x) (b1 y) = b0 (inc (plus x y)) plus (b1 x) (eps _) = b1 x plus eps y = y 1 Use the verbatim environment. 2

3 Task 3 (5 points, WB). Define a function eqbits : bin bin bool that returns true if the two arguments are the exact same sequence of bits and false otherwise. Solution 3: eqbits (b0 x) (b0 y) = eqbits x y eqbits (b0 x) (b1 y) = false eqbits (b0 x) (eps _) = false eqbits (b1 x) (b0 y) = false eqbits (b1 x) (b1 y) = eqbits x y eqbits (b1 x) (eps _) = false eqbits (eps _) (b0 y) = false eqbits (eps _) (b1 y) = false eqbits (eps _) (eps _) = true Task 4 (5 points, WB). Demonstrate that eqbits is not a correct implementation of equality of natural numbers in binary representation. Summarize what you see as the source of the issue. Solution 4: or, in short form eqbits bzero (dbl0 bzero) eqbits (fold (ɛ )) (fold (b0 (fold (ɛ )))) false eqbits bzero (b0 bzero) ->* false The source of the issue is that a number in binary form may have leading 0 bits, so there are multiple different representations of every natural number. The bitwise equality does not account for this. Task 5 (10 points, WB). The problem exhibited in previous task can be addressed in several ways. Explain at least two approaches of how the problem in the previous section may be addressed, and provide the details for two different solutions. Provide definitions and code in each case as appropriate, including a function eq : bin bin bool that correctly implements equality of natural numbers in binary form. Solution 5: We sketch three approaches. 1. Change the definition of equality so that leading zero bits are ignored. 3

4 eq (b0 x) (b0 y) = eq x y eq (b0 x) (b1 y) = false eq (b0 x) (eps _) = eq x (eps ()) eq (b1 x) (b0 y) = false eq (b1 x) (b1 y) = eq x y eq (b1 x) (eps _) = false eq (eps _) (b0 y) = eq (eps ()) y eq (eps _) (b1 y) = false eq (eps _) (eps _) = true Now we have to be careful that any functions we write on type bin work correctly no matter how many leading zeros there might be. 2. Change the definition of the constructor function dbl0 so it avoids constructing terms with leading zero bits. We would then have to agree not to build terms with leading zero bits directly, but go only through the constructor functions. Or, in an appropriately extended language, we could enforce these abstractions. dbl (b0 x) = b0 (b0 x) dbl (b1 x) = b0 (b1 x) dbl (eps _) = eps () eq x = eqbits x 3. Change the type definition of to satisfy the following isomorphisms: bin = (b0 : pos) + (b1 : bin) + (ɛ : 1) pos = (b0 : pos) + (b1 : bin) bin = ρ α. (b0 : ρ β. (b0 : β) + (b1 : α)) + (b1 : α) + (ɛ : 1) pos = ρ β. (b0 : β) + (b1 : ρ α. (b0 : β) + (b1 : α) + (ɛ : 1)) Now dbl0 is ill-typed and will have to distinguish the case of the empty bit string. eq can then be the same as eqbits. 2 Representing Integers We can represent integers a as pairs x, y of natural numbers x and y in binary form where a = x y. We ll use this as an example of a recursive type that is not 4

5 actually recursive. int = ρ α. bin bin int = bin bin In the tasks below, you should look for opportunities to use the functions defined in the previous problem on natural numbers in binary form. Task 6 (5 points, WB). Define a function bintoint : bin int that, when given a representation of a the natural number n, returns an integer representing n. Solution 6: bintoint x = (x, 0) Task 7 (5 points, WB). Define a constant izero : int representing the integer 0 as well as functions iplus and iminus of type int int int representing addition and subtraction on integers. Solution 7: izero = (0, 0) iplus (x1,y1) (x2,y2) = (plus x1 x2, plus y1 y2) iminus (x1,y1) (x2,y2) = (plus x1 y2, plus x2 y1) Task 8 (5 points, WB). Propose an alternative representation of integers using sums instead of products and define how mathematical integers are represented. You do not need to implement any functions on this representation, but please explain in a few sentences which one you would prefer and why. Solution 8: We can define signed integers as sint = (pos : nat) + (neg : nat). Let n be the representation of n in binary form (so that n val and n : bin. Then the integer representation of n is pos n, while the integer representation of n for n > 0 is neg n. The representation as pairs could be less efficient unless we normalize it back to n, 0 for positive numbers n (including 0) and 0, n for negative numbers. On the other hand, operations on signed integers may have to distinguish cases. Personally, I like the elegance of the difference representation. 5

6 3 Reasoning Inductively with Data The values of so-called purely positive types only contain other values but not arbitrary expression. They follow this grammar: Positive types τ + ::= τ + 1 τ i I (i : τ + i ) ρ(α+. τ + ) α + We can now specialize the typing rules to values of purely positive type, giving us both an easy way to reason about canonical forms and inductively prove properties of programs. The rules for the judgment v :: τ + establish simultaneously that v is a value and that it has type τ +. v :: τ + i i v :: i I (i :: τ + i ) (I-+) v 1 :: τ + 1 v 2 :: τ + 2 v 1, v 2 :: τ + 1 τ + 2 (I- ) :: 1 (I-1) v :: [ρ(α +. τ + )/α + ]τ + fold v :: ρ(α +. τ + ) (I-ρ) Observe that there are no elimination rules (since they don t form values), and that there are no variables or contexts. Theorem. For any expression v and purely positive type τ +, we have that v :: τ + iff v : τ + and v val. Proof. In each direction, by rule induction on the given derivation. From right to left we also use inversion on v val to conclude that the given rules are the only applicable ones. Task 9 (5 points, WB). Give a detailed proof showing that there are no closed values of type ρ(α +. α + α + ) by assuming v :: ρ(α +. α + α + ) and deriving a contradiction. Solution 9: Assume v :: ρ α +. α + α +. We prove a contradiction by rule induction on the value typing judgment. v :: ρ α +. α + α + Assumption v = fold v with v :: (ρ α +. α + α + ) (ρ α +. α + α + ) By inversion v = v 1, v 2 with v 1 :: (ρ α+. α + α + ) and v 2 :: (ρ α+. α + α + ) By inversion Contradiction By ind.hyp. on the value typing of v 1. 6

7 Here, we can apply the induction hypothesis to the value typing derivation of v 1 because it is a subderivation of the typing of v. We can further specialize the rules to particular types, such as the type of bin of bit strings from Problem 1: bin fold (ɛ ) :: bin bin = ρ α. (b0 : α) + (b1 : α) + (ɛ : 1) bin = (b0 : bin) + (b1 : bin) + (ɛ : 1) bin v :: bin bin fold (b0 v) :: bin bin v :: bin bin fold (b1 v) :: bin These rules are complete for closed values of type bin (which we do not prove, but is straightforward). They are interesting because they give rise to an induction principle for bit strings which is just a rule induction over this new judgment. Task 10 (5 points, WB). Prove that for all closed values v of type bin, inc v w for some value w Solution 10: The proof is by rule induction of the value typing bin v :: bin. Case: Case: Case: bin fold (ɛ ) :: bin where v = fold (ɛ ). Then with w = fold (b1 (fold (ɛ y))) we have inc v w. bin v :: bin bin fold (b0 v ) :: bin where v = fold (b0 v ). Then with w = fold (b1 v ) we have inc v w. were v = fold (b1 v ). Then bin v :: bin bin fold (b1 v ) :: bin inc v w for some w By ind. hyp. inc v = inc (fold (b1 v )) fold (b0 (inc v )) fold (b0 w ) So for w = fold (b0 w ) we have inc v w. 7

8 We now define a decrement function on numbers in binary representation. dec : bin bin = fix d. λx. case unfold x { b0 y b1 (d y) b1 y b0 y ɛ u ɛ u } In surface syntax, using data constructors, pattern matching and recursive definitions: dec (b0 y) = b1 (dec y) dec (b1 y) = b0 y dec (eps _) = eps () Task 11 (10 points, WB). Attempt to prove that for all closed values v of type bin dec (inc v) v by using rule induction on the value typing bin v :: bin. This proof will fail in one case. Indicate how this failure might be addressed in light of Problem 1. You do not need to write new code or carry out a revised proof. Solution 11: The proof attmempt is by rule induction over the value typing bin v :: bin. Case: Case: where v = fold (b0 v ). Then bin v :: bin bin fold (b0 v ) :: bin dec (inc v) = dec (inc (b0 v )) ->* dec (b1 v ) ->* b0 v = v were v = fold (b1 v ). Then bin v :: bin bin fold (b1 v ) :: bin 8

9 dec (inc v) = dec (inc (b1 v )) ->* dec (b0 (inc v )) ->* dec (b0 w ) (since inc v ->* w for some w by Task 11) ->* b1 (dec w ) dec (inc v ) ->* dec w dec (inc v ) ->* v dec w ->* v (since inc v ->* w ) (by ind.hyp.) (by determinacy of evaluation) dec (inv v) ->* b1 (dec w ) (see above) ->* b1 v (by computation rules) = v Case: where v = fold (ɛ ). Then bin fold (ɛ ) :: bin dec (inc v) = dec (inc (eps ())) ->* dec (b1 (eps ())) ->* b0 (eps ()) The proof attempt fails here, since fold (ɛ ) fold (b0 fold (ɛ )). We can salvage this proof in several ways. One is to change the decrement function so it avoids introducing leading 0 bits. Another is to state the theorem in terms of the fixed equality function from Problem 1: eq (dec (inc v)) v true 9

10 A Syntax Types τ and terms e are given by the following grammars, where I ranges over finite index sets: τ ::= α τ 1 τ 2 τ 1 τ 2 1 i I (i : τ i) &i I (i : τ i) ρ(α. τ) e ::= x λx. e e 1 e 2 i e case e {i x i e i } i I e 1, e 2 case e 0 { x 1, x 2 e } case e 0 { e } i e i i I e i fold(e) unfold(e) fix(x.e) As discussed in class, the 0 is a special case of sums with I =. 10

11 B Statics For any type constructor %, we use the name (I-%) for a rule that introduces (constructs) an expression of type % and (E-%) for a rule that eliminates (destructs) an expression of type %. Variables and fixed points are special, since they are not tied to any particular type. x : τ Γ Γ x : τ (VAR) Γ, x : τ e : τ (I- ) Γ λx.e : τ τ Γ e 1 : τ τ Γ e 1 e 2 : τ Γ e 2 : τ (E- ) Γ e : τ j (j I) Γ j e : i I (i : τ i) (I-+) Γ e : i I (i : τ i) Γ, x i : τ i e i : τ ( i I) Γ case e {i x i e i } i I : τ (E-+) Γ e 1 : τ 1 Γ e 2 : τ 2 Γ e 1, e 2 : τ 1 τ 2 (I- ) Γ e 0 : τ 1 τ 2 Γ, x 1 : τ 1, x 2 : τ 2 e : τ Γ case e 0 { x 1, x 2 e } : τ (E- ) Γ : 1 (I-1) Γ e 0 : 1 Γ e : τ Γ case e 0 { e } : τ (E-1) Γ e i : τ i ( i I) Γ i e i i I : &i I (i : τ i) (I-&) Γ e : &i I (i : τ i) (j I) Γ e j : τ j Γ e : [ρ(α. τ)/α]τ Γ fold(e) : ρ(α. τ) (I-ρ) Γ e : ρ(α. τ) Γ unfold(e) : [ρ(α. τ)/α]τ (E-ρ) Γ, x : τ e : τ Γ fix(x.e) : τ (FIX) (E-&) 11

12 C Dynamics For any type constructor % we write (V-%) for defining a value of type %, (R-%) for a reduction where a destructor meets a constructor, and (CI-%) and (CE-%) for the congruence rules for constructors and destructors for the type %. λx.e val (V- ) v 2 val (λx. e 1 ) v 2 [v 2 /x]e 1 (R- ) e 1 e 1 e 1 e 2 e 1 e 2 (CE- 1 ) v 1 val e 2 e 2 v 1 e 2 e 1 e 2 (CE- 2 ) v val i v val (V-+) e e (CI-+) i e i e e e case e {i x i e i } i I case e {i x i e i } i I (CE-+) v j val case (j v j ) {i x i e i } i I [v j /x j ]e j (R-+) v 1 val v 2 val v 1, v 2 val (V- ) e 1 e 1 e 1, e 2 e 1, e 2 (CI- 1) v 1 val e 2 e 2 v 1, e 2 v 1, e 2 (CI- 2) e 0 e 0 case e 0 { x 1, x 2 e } case e 0 { x 1, x 2 e } (CE- ) v 1 val v 2 val (R- ) case v 1, v 2 { x 1, x 2 e } [v 1 /x 1, v 2 /x 2 ]e val (V-1) e 0 e 0 case e 0 { e } case e 0 { e } (CE-1) case { e } e (R-1) i e i i I val (V-&) e e e j e j (CI-&) i e i i I j e j (R-&) v val fold(v) val (V-ρ) e e fold(e) fold(e ) (CI-ρ) e e unfold(e) unfold(e ) (CE-ρ) v val unfold(fold(v)) v (R-ρ) fix(x.e) [fix(x.e)/x]e (R-FIX) 12

Midterm Exam Types and Programming Languages Frank Pfenning. October 18, 2018

Midterm Exam Types and Programming Languages Frank Pfenning. October 18, 2018 Midterm Exam 15-814 Types and Programming Languages Frank Pfenning October 18, 2018 Name: Andrew ID: Instructions This exam is closed-book, closed-notes. You have 80 minutes to complete the exam. There

More information

Lecture Notes on Data Abstraction

Lecture Notes on Data Abstraction Lecture Notes on Data Abstraction 15-814: Types and Programming Languages Frank Pfenning Lecture 14 October 23, 2018 1 Introduction Since we have moved from the pure λ-calculus to functional programming

More information

Element x is R-minimal in X if y X. R(y, x).

Element x is R-minimal in X if y X. R(y, x). CMSC 22100/32100: Programming Languages Final Exam M. Blume December 11, 2008 1. (Well-founded sets and induction principles) (a) State the mathematical induction principle and justify it informally. 1

More information

Lecture Notes on Inductive Definitions

Lecture Notes on Inductive Definitions Lecture Notes on Inductive Definitions 15-312: Foundations of Programming Languages Frank Pfenning Lecture 2 September 2, 2004 These supplementary notes review the notion of an inductive definition and

More information

Lecture Notes on Inductive Definitions

Lecture Notes on Inductive Definitions Lecture Notes on Inductive Definitions 15-312: Foundations of Programming Languages Frank Pfenning Lecture 2 August 28, 2003 These supplementary notes review the notion of an inductive definition and give

More information

Supplementary Notes on Inductive Definitions

Supplementary Notes on Inductive Definitions Supplementary Notes on Inductive Definitions 15-312: Foundations of Programming Languages Frank Pfenning Lecture 2 August 29, 2002 These supplementary notes review the notion of an inductive definition

More information

COM S 330 Homework 08 Solutions. Type your answers to the following questions and submit a PDF file to Blackboard. One page per problem.

COM S 330 Homework 08 Solutions. Type your answers to the following questions and submit a PDF file to Blackboard. One page per problem. COM S 0 Homework 08 Solutions Type your answers to the following questions and submit a PDF file to Blackboard. One page per problem. Problem 1. [10pts] Let M = (S, T, s 0 ) be the state machine where

More information

Discrete Mathematics for CS Fall 2003 Wagner Lecture 3. Strong induction

Discrete Mathematics for CS Fall 2003 Wagner Lecture 3. Strong induction CS 70 Discrete Mathematics for CS Fall 2003 Wagner Lecture 3 This lecture covers further variants of induction, including strong induction and the closely related wellordering axiom. We then apply these

More information

CS411 Notes 3 Induction and Recursion

CS411 Notes 3 Induction and Recursion CS411 Notes 3 Induction and Recursion A. Demers 5 Feb 2001 These notes present inductive techniques for defining sets and subsets, for defining functions over sets, and for proving that a property holds

More information

E.g. The set RE of regular expressions is given by the following rules:

E.g. The set RE of regular expressions is given by the following rules: 1 Lecture Summary We gave a brief overview of inductively defined sets, inductively defined functions, and proofs by structural induction We showed how to prove that a machine is correct using induction

More information

Homework 5: Parallelism and Control Flow : Types and Programming Languages Fall 2015 TA: Evan Cavallo

Homework 5: Parallelism and Control Flow : Types and Programming Languages Fall 2015 TA: Evan Cavallo Homework 5: Parallelism and Control Flow 15-814: Types and Programming Languages Fall 2015 TA: Evan Cavallo (ecavallo@cs.cmu.edu) Out: 11/5/15 Due: 11/17/15, 10:30am 1 Cost Dynamics In this section, we

More information

State-Dependent Representation Independence (Technical Appendix)

State-Dependent Representation Independence (Technical Appendix) State-Dependent Representation Independence (Technical Appendix) Amal Ahmed Derek Dreyer Andreas Rossberg TTI-C MPI-SWS MPI-SWS amal@tti-c.org dreyer@mpi-sws.mpg.de rossberg@mpi-sws.mpg.de Contents August

More information

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures CS 6110 S18 Lecture 21 Products, Sums, and Other Datatypes 1 Introduction In this lecture, we add constructs to the typed λ-calculus that allow working with more complicated data structures, such as pairs,

More information

CSE 505, Fall 2008, Midterm Examination 29 October Please do not turn the page until everyone is ready.

CSE 505, Fall 2008, Midterm Examination 29 October Please do not turn the page until everyone is ready. CSE 505, Fall 2008, Midterm Examination 29 October 2008 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper.

More information

CS 6110 Lecture 35 Solving Domain Equations 19 April 2013 Lecturer: Andrew Myers

CS 6110 Lecture 35 Solving Domain Equations 19 April 2013 Lecturer: Andrew Myers CS 6110 Lecture 35 Solving Domain Equations 19 April 2013 Lecturer: Andrew Myers To develop a denotational semantics for a language with recursive types, or to give a denotational semantics for the untyped

More information

CS 151 Complexity Theory Spring Solution Set 5

CS 151 Complexity Theory Spring Solution Set 5 CS 151 Complexity Theory Spring 2017 Solution Set 5 Posted: May 17 Chris Umans 1. We are given a Boolean circuit C on n variables x 1, x 2,..., x n with m, and gates. Our 3-CNF formula will have m auxiliary

More information

COMP4141 Theory of Computation

COMP4141 Theory of Computation COMP4141 Theory of Computation Lecture 4 Regular Languages cont. Ron van der Meyden CSE, UNSW Revision: 2013/03/14 (Credits: David Dill, Thomas Wilke, Kai Engelhardt, Peter Höfner, Rob van Glabbeek) Regular

More information

CS481F01 Solutions 8

CS481F01 Solutions 8 CS481F01 Solutions 8 A. Demers 7 Dec 2001 1. Prob. 111 from p. 344 of the text. One of the following sets is r.e. and the other is not. Which is which? (a) { i L(M i ) contains at least 481 elements }

More information

An Introduction to Logical Relations Proving Program Properties Using Logical Relations

An Introduction to Logical Relations Proving Program Properties Using Logical Relations An Introduction to Logical Relations Proving Program Properties Using Logical Relations Lau Skorstengaard lask@cs.au.dk July 27, 2018 Contents 1 Introduction 2 1.1 Simply Typed Lambda Calculus....................

More information

CSCI 490 problem set 6

CSCI 490 problem set 6 CSCI 490 problem set 6 Due Tuesday, March 1 Revision 1: compiled Tuesday 23 rd February, 2016 at 21:21 Rubric For full credit, your solutions should demonstrate a proficient understanding of the following

More information

MATH 341, Section 001 FALL 2014 Introduction to the Language and Practice of Mathematics

MATH 341, Section 001 FALL 2014 Introduction to the Language and Practice of Mathematics MATH 341, Section 001 FALL 2014 Introduction to the Language and Practice of Mathematics Class Meetings: MW 9:30-10:45 am in EMS E424A, September 3 to December 10 [Thanksgiving break November 26 30; final

More information

CSE 355 Test 2, Fall 2016

CSE 355 Test 2, Fall 2016 CSE 355 Test 2, Fall 2016 28 October 2016, 8:35-9:25 a.m., LSA 191 Last Name SAMPLE ASU ID 1357924680 First Name(s) Ima Regrading of Midterms If you believe that your grade has not been added up correctly,

More information

Lectures Notes on Progress

Lectures Notes on Progress Lectures Notes on Progress 15-312: Foundations of Programming Languages Frank Pfenning Lecture 7 September 21, 2004 In this lecture we prove the progress property for MinML, discuss type safety, and consider

More information

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus Course 2D1453, 200607 Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Typing λterms The uptyped λcalculus

More information

COMPUTER SCIENCE TRIPOS

COMPUTER SCIENCE TRIPOS CST.2016.6.1 COMPUTER SCIENCE TRIPOS Part IB Thursday 2 June 2016 1.30 to 4.30 COMPUTER SCIENCE Paper 6 Answer five questions. Submit the answers in five separate bundles, each with its own cover sheet.

More information

Lecture Notes on Subject Reduction and Normal Forms

Lecture Notes on Subject Reduction and Normal Forms Lecture Notes on Subject Reduction and Normal Forms 15-814: Types and Programming Languages Frank Pfenning Lecture 4 September 13, 2018 1 Introduction In the last lecture we proved some key aspect of a

More information

Extensions to the Logic of All x are y: Verbs, Relative Clauses, and Only

Extensions to the Logic of All x are y: Verbs, Relative Clauses, and Only 1/53 Extensions to the Logic of All x are y: Verbs, Relative Clauses, and Only Larry Moss Indiana University Nordic Logic School August 7-11, 2017 2/53 An example that we ll see a few times Consider the

More information

Probability Models of Information Exchange on Networks Lecture 5

Probability Models of Information Exchange on Networks Lecture 5 Probability Models of Information Exchange on Networks Lecture 5 Elchanan Mossel (UC Berkeley) July 25, 2013 1 / 22 Informational Framework Each agent receives a private signal X i which depends on S.

More information

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers ALGEBRA CHRISTIAN REMLING 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers by Z = {..., 2, 1, 0, 1,...}. Given a, b Z, we write a b if b = ac for some

More information

Structural Induction

Structural Induction Structural Induction In this lecture we ll extend the applicability of induction to many universes, ones where we can define certain kinds of objects by induction, in addition to proving their properties

More information

CS 154, Lecture 4: Limitations on DFAs (I), Pumping Lemma, Minimizing DFAs

CS 154, Lecture 4: Limitations on DFAs (I), Pumping Lemma, Minimizing DFAs CS 154, Lecture 4: Limitations on FAs (I), Pumping Lemma, Minimizing FAs Regular or Not? Non-Regular Languages = { w w has equal number of occurrences of 01 and 10 } REGULAR! C = { w w has equal number

More information

Notes on Proving Arithmetic Equations

Notes on Proving Arithmetic Equations Massachusetts Institute of Technology Course Notes 1 6.844, Spring 03: Computability Theory of and with Scheme February 10 Prof. Albert Meyer revised February 25, 2003, 1300 minutes Notes on Proving Arithmetic

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

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculteit Wiskunde en Informatica. Final examination Logic & Set Theory (2IT61/2IT07/2IHT10) (correction model)

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculteit Wiskunde en Informatica. Final examination Logic & Set Theory (2IT61/2IT07/2IHT10) (correction model) TECHNISCHE UNIVERSITEIT EINDHOVEN Faculteit Wiskunde en Informatica Final examination Logic & Set Theory (2IT61/2IT07/2IHT10) (correction model) Thursday October 29, 2015, 9:00 12:00 hrs. (2) 1. Determine

More information

CIS 500: Software Foundations

CIS 500: Software Foundations CIS 500: Software Foundations Midterm I October 3, 2017 Directions: This exam booklet contains both the standard and advanced track questions. Questions with no annotation are for both tracks. Other questions

More information

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers.

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers. MATH 4 Summer 011 Elementary Number Theory Notes on Mathematical Induction Principle of Mathematical Induction Recall the following axiom for the set of integers. Well-Ordering Axiom for the Integers If

More information

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction Math 4 Summer 01 Elementary Number Theory Notes on Mathematical Induction Principle of Mathematical Induction Recall the following axiom for the set of integers. Well-Ordering Axiom for the Integers If

More information

Principles of Program Analysis: Control Flow Analysis

Principles of Program Analysis: Control Flow Analysis Principles of Program Analysis: Control Flow Analysis Transparencies based on Chapter 3 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis. Springer Verlag

More information

Proof Techniques (Review of Math 271)

Proof Techniques (Review of Math 271) Chapter 2 Proof Techniques (Review of Math 271) 2.1 Overview This chapter reviews proof techniques that were probably introduced in Math 271 and that may also have been used in a different way in Phil

More information

a. See the textbook for examples of proving logical equivalence using truth tables. b. There is a real number x for which f (x) < 0. (x 1) 2 > 0.

a. See the textbook for examples of proving logical equivalence using truth tables. b. There is a real number x for which f (x) < 0. (x 1) 2 > 0. For some problems, several sample proofs are given here. Problem 1. a. See the textbook for examples of proving logical equivalence using truth tables. b. There is a real number x for which f (x) < 0.

More information

Lecture Notes on Certifying Theorem Provers

Lecture Notes on Certifying Theorem Provers Lecture Notes on Certifying Theorem Provers 15-317: Constructive Logic Frank Pfenning Lecture 13 October 17, 2017 1 Introduction How do we trust a theorem prover or decision procedure for a logic? Ideally,

More information

CSE 311: Foundations of Computing I Autumn 2014 Practice Final: Section X. Closed book, closed notes, no cell phones, no calculators.

CSE 311: Foundations of Computing I Autumn 2014 Practice Final: Section X. Closed book, closed notes, no cell phones, no calculators. CSE 311: Foundations of Computing I Autumn 014 Practice Final: Section X YY ZZ Name: UW ID: Instructions: Closed book, closed notes, no cell phones, no calculators. You have 110 minutes to complete the

More information

Lecture Notes on The Curry-Howard Isomorphism

Lecture Notes on The Curry-Howard Isomorphism Lecture Notes on The Curry-Howard Isomorphism 15-312: Foundations of Programming Languages Frank Pfenning Lecture 27 ecember 4, 2003 In this lecture we explore an interesting connection between logic and

More information

7 RC Simulates RA. Lemma: For every RA expression E(A 1... A k ) there exists a DRC formula F with F V (F ) = {A 1,..., A k } and

7 RC Simulates RA. Lemma: For every RA expression E(A 1... A k ) there exists a DRC formula F with F V (F ) = {A 1,..., A k } and 7 RC Simulates RA. We now show that DRC (and hence TRC) is at least as expressive as RA. That is, given an RA expression E that mentions at most C, there is an equivalent DRC expression E that mentions

More information

CS611 Lecture 25 Solving Domain Equations 22 October 2007 Lecturer: Andrew Myers

CS611 Lecture 25 Solving Domain Equations 22 October 2007 Lecturer: Andrew Myers CS611 Lecture 25 Solving Domain Equations 22 October 2007 Lecturer: Andrew Myers To develop a denotational semantics for a language with recursive types, or to give a denotational semantics for the untyped

More information

COMP 3161/9161 Week 2

COMP 3161/9161 Week 2 Concepts of Programming Languages Judgements, Inference Rules & Proofs Lecturer: Gabriele Keller Tutor: Liam O Connor University of New South Wales School of Computer Sciences & Engineering Sydney, Australia

More information

CS522 - Programming Language Semantics

CS522 - Programming Language Semantics 1 CS522 - Programming Language Semantics Simply Typed Lambda Calculus Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 We now discuss a non-trivial extension of

More information

Equational Logic and Term Rewriting: Lecture I

Equational Logic and Term Rewriting: Lecture I Why so many logics? You all know classical propositional logic. Why would we want anything more? Equational Logic and Term Rewriting: Lecture I One reason is that we might want to change some basic logical

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

Focusing on Binding and Computation

Focusing on Binding and Computation Focusing on Binding and Computation Dan Licata Joint work with Noam Zeilberger and Robert Harper Carnegie Mellon University 1 Programming with Proofs Represent syntax, judgements, and proofs Reason about

More information

Contribution of Problems

Contribution of Problems Exam topics 1. Basic structures: sets, lists, functions (a) Sets { }: write all elements, or define by condition (b) Set operations: A B, A B, A\B, A c (c) Lists ( ): Cartesian product A B (d) Functions

More information

CS261: Problem Set #3

CS261: Problem Set #3 CS261: Problem Set #3 Due by 11:59 PM on Tuesday, February 23, 2016 Instructions: (1) Form a group of 1-3 students. You should turn in only one write-up for your entire group. (2) Submission instructions:

More information

Turing Machines Part Three

Turing Machines Part Three Turing Machines Part Three What problems can we solve with a computer? What kind of computer? Very Important Terminology Let M be a Turing machine. M accepts a string w if it enters an accept state when

More information

CIS 500 Software Foundations Midterm II Answer key November 17, 2004

CIS 500 Software Foundations Midterm II Answer key November 17, 2004 CIS 500 Software Foundations Midterm II Answer key November 17, 2004 Simply typed lambda-calculus The following questions refer to the simply typed lambda-calculus with booleans and error. The syntax,

More information

State-Dependent Representation Independence

State-Dependent Representation Independence State-Dependent Representation Independence Amal Ahmed TTI-C amal@tti-c.org Derek Dreyer MPI-SWS dreyer@mpi-sws.mpg.de Andreas Rossberg MPI-SWS rossberg@mpi-sws.mpg.de Abstract Mitchell s notion of representation

More information

State-Dependent Representation Independence

State-Dependent Representation Independence State-Dependent Representation Independence Amal Ahmed TTI-C amal@tti-c.org Derek Dreyer MPI-SWS dreyer@mpi-sws.mpg.de Andreas Rossberg MPI-SWS rossberg@mpi-sws.mpg.de Abstract Mitchell s notion of representation

More information

Safety Analysis versus Type Inference

Safety Analysis versus Type Inference Information and Computation, 118(1):128 141, 1995. Safety Analysis versus Type Inference Jens Palsberg palsberg@daimi.aau.dk Michael I. Schwartzbach mis@daimi.aau.dk Computer Science Department, Aarhus

More information

Algorithms Exam TIN093 /DIT602

Algorithms Exam TIN093 /DIT602 Algorithms Exam TIN093 /DIT602 Course: Algorithms Course code: TIN 093, TIN 092 (CTH), DIT 602 (GU) Date, time: 21st October 2017, 14:00 18:00 Building: SBM Responsible teacher: Peter Damaschke, Tel. 5405

More information

Basics of Model Theory

Basics of Model Theory Chapter udf Basics of Model Theory bas.1 Reducts and Expansions mod:bas:red: defn:reduct mod:bas:red: prop:reduct Often it is useful or necessary to compare languages which have symbols in common, as well

More information

Fall 2017 Test II review problems

Fall 2017 Test II review problems Fall 2017 Test II review problems Dr. Holmes October 18, 2017 This is a quite miscellaneous grab bag of relevant problems from old tests. Some are certainly repeated. 1. Give the complete addition and

More information

CSE 555 Homework Three Sample Solutions

CSE 555 Homework Three Sample Solutions CSE 555 Homework Three Sample Solutions Question 1 Let Σ be a fixed alphabet. A PDA M with n states and stack alphabet of size σ may recognize the empty language; if its language is non-empty then denote

More information

Recitation 2: Binding, Semantics, and Safety : Foundations of Programming Languages

Recitation 2: Binding, Semantics, and Safety : Foundations of Programming Languages Recitation 2: Binding, Semantics, and Safety 15-312: Foundations of Programming Languages Charles Yuan, Jeanne Luning Prak September 5, 2018 1 Abstract Binding Trees The abstract syntax trees we saw previously

More information

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus CS 4110 Programming Languages & Logics Lecture 16 Programming in the λ-calculus 30 September 2016 Review: Church Booleans 2 We can encode TRUE, FALSE, and IF, as: TRUE λx. λy. x FALSE λx. λy. y IF λb.

More information

CS156: The Calculus of Computation

CS156: The Calculus of Computation CS156: The Calculus of Computation Zohar Manna Winter 2010 It is reasonable to hope that the relationship between computation and mathematical logic will be as fruitful in the next century as that between

More information

Lecture Notes on From Rules to Propositions

Lecture Notes on From Rules to Propositions Lecture Notes on From Rules to Propositions 15-816: Substructural Logics Frank Pfenning Lecture 2 September 1, 2016 We review the ideas of ephemeral truth and linear inference with another example from

More information

Discrete Mathematics and Probability Theory Fall 2018 Alistair Sinclair and Yun Song Note 6

Discrete Mathematics and Probability Theory Fall 2018 Alistair Sinclair and Yun Song Note 6 CS 70 Discrete Mathematics and Probability Theory Fall 2018 Alistair Sinclair and Yun Song Note 6 1 Modular Arithmetic In several settings, such as error-correcting codes and cryptography, we sometimes

More information

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications NICTA Advanced Course Theorem Proving Principles, Techniques, Applications λ 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic, natural

More information

Programming Assignment 4: Image Completion using Mixture of Bernoullis

Programming Assignment 4: Image Completion using Mixture of Bernoullis Programming Assignment 4: Image Completion using Mixture of Bernoullis Deadline: Tuesday, April 4, at 11:59pm TA: Renie Liao (csc321ta@cs.toronto.edu) Submission: You must submit two files through MarkUs

More information

Recursion: Introduction and Correctness

Recursion: Introduction and Correctness Recursion: Introduction and Correctness CSE21 Winter 2017, Day 7 (B00), Day 4-5 (A00) January 25, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Today s Plan From last time: intersecting sorted lists and

More information

Name: Student ID: Instructions:

Name: Student ID: Instructions: Instructions: Name: CSE 322 Autumn 2001: Midterm Exam (closed book, closed notes except for 1-page summary) Total: 100 points, 5 questions, 20 points each. Time: 50 minutes 1. Write your name and student

More information

Computer Science Introductory Course MSc - Introduction to Java

Computer Science Introductory Course MSc - Introduction to Java Computer Science Introductory Course MSc - Introduction to Java Lecture 1: Diving into java Pablo Oliveira ENST Outline 1 Introduction 2 Primitive types 3 Operators 4 5 Control Flow

More information

Lecture Notes: Axiomatic Semantics and Hoare-style Verification

Lecture Notes: Axiomatic Semantics and Hoare-style Verification Lecture Notes: Axiomatic Semantics and Hoare-style Verification 17-355/17-665/17-819O: Program Analysis (Spring 2018) Claire Le Goues and Jonathan Aldrich clegoues@cs.cmu.edu, aldrich@cs.cmu.edu It has

More information

Basic Logic and Proof Techniques

Basic Logic and Proof Techniques Chapter 3 Basic Logic and Proof Techniques Now that we have introduced a number of mathematical objects to study and have a few proof techniques at our disposal, we pause to look a little more closely

More information

Depending on equations

Depending on equations Depending on equations A proof-relevant framework for unification in dependent type theory Jesper Cockx DistriNet KU Leuven 3 September 2017 Unification for dependent types Unification is used for many

More information

Lecture 11: Gödel s Second Incompleteness Theorem, and Tarski s Theorem

Lecture 11: Gödel s Second Incompleteness Theorem, and Tarski s Theorem Lecture 11: Gödel s Second Incompleteness Theorem, and Tarski s Theorem Valentine Kabanets October 27, 2016 1 Gödel s Second Incompleteness Theorem 1.1 Consistency We say that a proof system P is consistent

More information

Lecture 7: More Arithmetic and Fun With Primes

Lecture 7: More Arithmetic and Fun With Primes IAS/PCMI Summer Session 2000 Clay Mathematics Undergraduate Program Advanced Course on Computational Complexity Lecture 7: More Arithmetic and Fun With Primes David Mix Barrington and Alexis Maciel July

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

Proofs. Chapter 2 P P Q Q

Proofs. Chapter 2 P P Q Q Chapter Proofs In this chapter we develop three methods for proving a statement. To start let s suppose the statement is of the form P Q or if P, then Q. Direct: This method typically starts with P. Then,

More information

CSE 546 Final Exam, Autumn 2013

CSE 546 Final Exam, Autumn 2013 CSE 546 Final Exam, Autumn 0. Personal info: Name: Student ID: E-mail address:. There should be 5 numbered pages in this exam (including this cover sheet).. You can use any material you brought: any book,

More information

CSE 311: Foundations of Computing. Lecture 26: Cardinality

CSE 311: Foundations of Computing. Lecture 26: Cardinality CSE 311: Foundations of Computing Lecture 26: Cardinality Cardinality and Computability Computers as we know them grew out of a desire to avoid bugs in mathematical reasoning A brief history of reasoning

More information

Announcements. Problem Set 1 out. Checkpoint due Monday, September 30. Remaining problems due Friday, October 4.

Announcements. Problem Set 1 out. Checkpoint due Monday, September 30. Remaining problems due Friday, October 4. Indirect Proofs Announcements Problem Set 1 out. Checkpoint due Monday, September 30. Grade determined by attempt rather than accuracy. It's okay to make mistakes we want you to give it your best effort,

More information

CS1800: Mathematical Induction. Professor Kevin Gold

CS1800: Mathematical Induction. Professor Kevin Gold CS1800: Mathematical Induction Professor Kevin Gold Induction: Used to Prove Patterns Just Keep Going For an algorithm, we may want to prove that it just keeps working, no matter how big the input size

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

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

Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010

Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010 Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010 Midterm Problem 1: Recall that for two functions g : N N + and h : N N +, h = Θ(g) iff for some positive integer N and positive real

More information

Mathematics 114L Spring 2018 D.A. Martin. Mathematical Logic

Mathematics 114L Spring 2018 D.A. Martin. Mathematical Logic Mathematics 114L Spring 2018 D.A. Martin Mathematical Logic 1 First-Order Languages. Symbols. All first-order languages we consider will have the following symbols: (i) variables v 1, v 2, v 3,... ; (ii)

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17 12.1 Introduction Today we re going to do a couple more examples of dynamic programming. While

More information

Sample Problems. Lecture Notes Proof by Induction page 1. Prove each of the following statements by induction.

Sample Problems. Lecture Notes Proof by Induction page 1. Prove each of the following statements by induction. Lecture Notes Proof by Induction page Sample Problems Prove each of the following statements by induction.. For all natural numbers n; n (n + ) a) + + 3 + ::: + n. b) + + 3 + ::: + n n (n + ) (n + ). c)

More information

Introduction to lambda calculus Part 6

Introduction to lambda calculus Part 6 Introduction to lambda calculus Part 6 Antti-Juhani Kaijanaho 2017-02-16 1 Untyped lambda calculus 2 Typed lambda calculi 2.1 Dynamically typed lambda calculus with integers 2.2 A model of Lisp 2.3 Simply

More information

Completeness of Star-Continuity

Completeness of Star-Continuity Introduction to Kleene Algebra Lecture 5 CS786 Spring 2004 February 9, 2004 Completeness of Star-Continuity We argued in the previous lecture that the equational theory of each of the following classes

More information

Operationally-Based Theories of Program Equivalence

Operationally-Based Theories of Program Equivalence Operationally-Based Theories of Program Equivalence Andrew Pitts Contents 1 Introduction : : : : : : : : : : : : : : : : : : : : : : : : : : : : 241 2 Contextual Equivalence : : : : : : : : : : : : : :

More information

Inductive Predicates

Inductive Predicates Inductive Predicates Gert Smolka, Saarland University June 12, 2017 We introduce inductive predicates as they are accommodated in Coq s type theory. Our prime example is the ordering predicate for numbers,

More information

HW8. Due: November 1, 2018

HW8. Due: November 1, 2018 CSCI 1010 Theory of Computation HW8 Due: November 1, 2018 Attach a fully filled-in cover sheet to the front of your printed homework Your name should not appear anywhere; the cover sheet and each individual

More information

Theory of Computation

Theory of Computation Theory of Computation Dr. Sarmad Abbasi Dr. Sarmad Abbasi () Theory of Computation / Lecture 3: Overview Decidability of Logical Theories Presburger arithmetic Decidability of Presburger Arithmetic Dr.

More information

CVO103: Programming Languages. Lecture 2 Inductive Definitions (2)

CVO103: Programming Languages. Lecture 2 Inductive Definitions (2) CVO103: Programming Languages Lecture 2 Inductive Definitions (2) Hakjoo Oh 2018 Spring Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 1 / 20 Contents More examples of inductive definitions natural

More information

Preparing for the CS 173 (A) Fall 2018 Midterm 1

Preparing for the CS 173 (A) Fall 2018 Midterm 1 Preparing for the CS 173 (A) Fall 2018 Midterm 1 1 Basic information Midterm 1 is scheduled from 7:15-8:30 PM. We recommend you arrive early so that you can start exactly at 7:15. Exams will be collected

More information

CS 124 Math Review Section January 29, 2018

CS 124 Math Review Section January 29, 2018 CS 124 Math Review Section CS 124 is more math intensive than most of the introductory courses in the department. You re going to need to be able to do two things: 1. Perform some clever calculations to

More information

Polymorphism, Subtyping, and Type Inference in MLsub

Polymorphism, Subtyping, and Type Inference in MLsub Polymorphism, Subtyping, and Type Inference in MLsub Stephen Dolan and Alan Mycroft November 8, 2016 Computer Laboratory University of Cambridge The select function select p v d = if (p v) then v else

More information

CMPSCI 601: Tarski s Truth Definition Lecture 15. where

CMPSCI 601: Tarski s Truth Definition Lecture 15. where @ CMPSCI 601: Tarski s Truth Definition Lecture 15! "$#&%(') *+,-!".#/%0'!12 43 5 6 7 8:9 4; 9 9 < = 9 = or 5 6?>A@B!9 2 D for all C @B 9 CFE where ) CGE @B-HI LJKK MKK )HG if H ; C if H @ 1 > > > Fitch

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