(2) (15pts) Using Prolog, implement a type-checker for the following small subset of System F:

Size: px
Start display at page:

Download "(2) (15pts) Using Prolog, implement a type-checker for the following small subset of System F:"

Transcription

1 CS 6371 Advanced Programming Languages Sample Spring 2018 Final Exam This sample final exam is LONGER than a real final exam (to give you more practice problems) and has a medium difficulty level. You may take two, two-sided sheets of notes with you into the exam. All other books or notes must remain closed throughout the exam. You will have 2 hours and 45 minutes to complete the exam; all papers must be turned in by 1:45pm. 1 Problem Set (1) (15 pts) A metric is a function m : α α int that computes some notion of distance between two values. The path-length of a list is the sum of the distances between each consecutive pair of elements. For example, if the data has type α = int and the metric is absolute difference, then the path-length of list [7; 10; 6] is = 7. Using only List.fold left for recursion, implement a function (pathlen m l) that computes the path-length of l using metric function m. If l has less than 2 elements, the path-length is 0. Do not use any other List library functions in your implementation. (2) (15pts) Using Prolog, implement a type-checker for the following small subset of System F: e ::= () λv:τ.e Λα.e v τ ::= unit τ 1 τ 2 α.τ α In particular, implement a predicate typ(e, T ) that succeeds if and only if expression E has type T, where expressions and types are represented as the following Prolog structures: V ::= arbitrary Prolog atoms E ::= uval lam(v,t,e) poly(v,e) var(v ) T ::= unit arr(t 1,T 2 ) forall(v,t ) tvar(v ) Your typ/2 predicate should fail (reject) if E has free variables. If you use any helper Prolog predicates that we defined in class, give their exact definitions (since the exact definition you use might affect the correctness of your implementation). (3) Consider the following recursive definition of function f: f(x) = ( x=100 0 x>100 f(x 1) + 1 x<100 f(x + 1) + 1 ) (a) (1 pt) Define a non-recursive functional F whose least fixed point is f. (b) (4 pts) Give a closed-form function definition h such that h = f. (c) (15 pts) Prove by fixed point induction that h = fix(f ). (4) For each of the following System F types, say whether the type is inhabited or not. If the type is inhabited, give an example of a System F term that inhabits it. (Do not prove that your term inhabits the type, just state it.) If the type is not inhabited, just write uninhabited. 1

2 (a) (3 pts) α. β. η. ((α β) η) (α β η) (b) (3 pts) α.(α + unit) (c) (4 pts) α. β.(α + β) (α β) (d) (7 pts) α. β.((α + β) ((α β) + (β α))) (5) (5 pts) Encode an iseven function in the untyped λ-calculus so that (iseven n N ) evaluates to true whenever n is even and to false whenever n is odd. (6) (15 pts) Consider the untyped λ-calculus expression foo defined as follows: foo = Y ( λf.λx.((iszero x)? x : (f (pred N x))) ) Prove by fixed-point induction that P (foo) holds, where P is the property defined by P (g) (x N, y N ) g. y N = 0 N In your proof when you claim that an expression e 1 evaluates to another expression e 2, you may do so without a formal proof of e 1 e 2. That is, it is not necessary to write out all the small-step derivations. (7) (5 pts) Derive the following typing judgment using the typing rules for the simply-typed λ-calculus: {} (λx:int. x) 3 : int (8) (20 pts) Derive the following partial correctness assertion using Hoare Logic: {x = n}while x<= 1 do x:=x + 1{x = max( n, 0)} 2 Solutions (1) let pathlen m = function [] -> 0 h::t -> fst (List.fold_left (fun (s,p) x -> (s+(m p x),x)) (0,h) t);; (2) % the pick/2 predicate defined in class... pick([x _],X). pick([x T],Y) :- X \= Y, pick(t,y). % succeed if type T in context C has No Free Type Variables nftv(_,unit). nftv(c,arr(t1,t2)) :- nftv(c,t1), nftv(c,t2). nftv(c,forall(a,t)) :- nftv([a C],T). nftv(c,tvar(a)) :- pick(c,a). % type-checker typ(_,_,uval,unit). typ(_,g,var(v),t) :- pick(g,(v,t)). typ(c,g,lam(v,vt,e),arr(vt,t)) :- nftv(c,vt), typ(c,[(v,vt) G],E,T). typ(c,g,poly(a,e),forall(a,t)) :- typ([a C],G,E,T). typ(e,t) :- typ([],[],e,t). 2

3 (3) (a) F (g) = λx. ( x=100 0 x>100 g(x 1) + 1 x<100 g(x + 1) + 1 ) (b) h(x) = x 100 (c) Proof. Define proposition P (g) = x g. g(x) = x 100. We wish to prove that P (fix(f )) holds. Base Case: P ( ) holds vacuously. Inductive Case: As the inductive hypothesis, assume that P (g) holds. We must prove that P (F (g)) holds. Let x F (g) be given. Case 1: Suppose x = 100. Then by definition of F, F (g)(x) = 0 = x 100. Case 2: Suppose x > 100. Then by definition of F, F (g)(x) = g(x 1) + 1. By inductive hypothesis, g(x 1) = x Since x > 100, x = x = x 100 = x 100. Case 3: Suppose x < 100. Then by definition of F, F (g)(x) = g(x + 1) + 1. Since x < 100, x = (x ) + 1 = (x 100) = x 100. (4) (a) Λα.Λβ.Λη.λf:((α β) η).λx:α.λy:β.f(x, y) (b) Λα. in α+unit 2 () (c) uninhabited (d) The type is inhabited. The following is a term that inhabits it: Λα.Λβ.λx:α+β. case x of in 1 (y) in (α β)+(β α) 2 (λz :β.y) (5) The iseven function can be encoded this way: (6) Proof. Define functional Γ by iseven = Y (λf.λn.((iszero N n)? true : in 2 (y) in (α β)+(β α) 1 (λz :α.y) ((iszero N (pred N n))? false : (f (pred N (pred N n)))))) Γ(f) = λx.((iszero N x)? x : (f (pred N x))) Since foo = Y Γ = fix(γ), we can prove the theorem by fixed-point induction on Γ. Base Case: P ( ) holds vacuously. Inductive Case: We must prove that P (g) implies P (Γ(g)). Therefore, assume P (g) holds and let (x N, y N ) Γ(g) be given. We wish to prove that y N = 0 N. Case 1: Suppose x N = 0 N. By the definition of Γ, Γ(x N ) = x N = 0 N, so y N = 0 N. Case 2: Suppose x N 0 N. Then by definition of Γ, y N = (g (pred N x N )) = (g (x 1) N ). This is the same as saying ((x 1) N, y N ) g. Since we assumed P (g) holds, it follows that y N = 0 N. 3

4 (7) The following typing derivation proves the typing judgment: (10) {(x, int)} x : int (11) {} (λx:int.x) : int int {} (λx:int.x)3 : int (9) {} 3 : int (12) (8) Choose loop invariant I = ((x 0) (x = n)) (x n) and derive the following: = I b C = A I (4) {C}x:=x + 1{I} = I I (6) {I b}x:=x + 1{I} (5) {I}p{ b I} = b I B (6) {A}p{B} where p = while x<= 1 do x:=x + 1 b (x 1) I ((x 0) (x = n)) (x n) A (x = n) B (x = max( n, 0)) C I[x + 1/x] ((x + 1 0) (x + 1 = n)) (x + 1 n) 3 Reference In addition to the material in this reference section, you will also be provided any relevant material from the reference section of the sample midterm exam. 3.1 Syntax of SIMPL commands c ::= skip c 1 ; c 2 v:=a if b then c 1 else c 2 while b do c boolean expressions b ::= true false a 1 <=a 2 b 1 && b 2 b 1 b 2!b arithmetic expressions a ::= n v a 1 + a 2 a 1 - a 2 a 1 * a 2 variable names v integer constants n 4

5 3.2 Axiomatic Semantics of SIMPL {A}skip{A} (1) {A}c 1 {C} {C}c{B} {A}c 1 ; c 2 {B} (2) {A b}c 1 {B} {A b}c 2 {B} {A}if b then c 1 else c 2 {B} (3) {B[a/v]}v:=a{B} (4) {I b}c{i} {I}while b do c{ b I} (5) = A A {A }c{b } = B B {A}c{B} (6) 3.3 Untyped Lambda Calculus Syntax and Semantics of Untyped λ-calculus e ::= v λv.e e 1 e 2 e 1 1 e 1 e 1 e 2 1 e 1 e 2 (7) (λv.e 1 )e 2 1 e 1 [e 2 /v] (8) Abbreviations in Untyped λ-calculus true = (λx.λy.x) pair = (λx.λy.λb.(b?e 1 :e 2 )) false = (λx.λy.y) π 1 = (λx. x true) e 1?e 2 :e 3 = (e 1 e 2 e 3 ) π 2 = (λx. x false) not = (λb.(b?false:true)) 0 N = (λx.x) and = (λa.λb.(a?b:false)) succ N = (pair false) or = (λa.λb.(a?true:b)) pred N = π 2 Y = (λf.(λx.f(xx))(λx.f(xx))) iszero N = π 1 add N = (Y (λf.λm.λn.((iszero N m)? n : (f(pred N m)(succ N n))))) sub N = (Y (λf.λm.λn.((iszero N n)? m : (f(pred N m)(pred N n)))) mult N = (Y (λf.λm.λn.((iszero N m)? 0 N : (add N (f (pred N m) n) n)))) 5

6 3.4 Simply-typed Lambda Calculus Syntax of λ expressions e ::= n v λv :τ.e e 1 e 2 true false e 1 aop e 2 e 1 bop e 2 types arithmetic ops aop ::= + - * boolean ops e 1 cmp e 2 (e 1, e 2 ) π 1 e π 2 e () in τ 1+τ 2 1 e in τ 1+τ 2 2 e (case e of in 1 (v 1 ) e 1 in 2 (v 2 ) e 2 ) τ ::= int bool τ 1 τ 2 τ 1 τ 2 unit τ 1 + τ 2 void bop ::= comparisons cmp ::= < > = Static Semantics of λ Γ n : int (9) Γ v : Γ(v) (10) Γ[v τ 1 ] e : τ 2 Γ (λv :τ 1. e) : τ 1 τ 2 (11) Γ e 1 : τ τ Γ e 2 : τ Γ e 1 e 2 : τ (12) Γ true : bool (13) Γ false : bool (14) Γ e 1 : int Γ e 2 : int Γ e 1 aop e 2 : int (15) Γ e 1 : bool Γ e 2 : bool Γ e 1 bop e 2 : bool Γ e 1 : int Γ e 2 : int Γ e 1 cmp e 2 : bool (16) (17) Γ e 1 : τ 1 Γ e 2 : τ 2 Γ (e 1, e 2 ) : τ 1 τ 2 (18) Γ e : τ 1 τ 2 i {1, 2} Γ π i e : τ i (19) Γ () : unit (20) Γ e : τ i i {1, 2} Γ in τ 1+τ 2 (21) i e : τ 1 + τ 2 Γ e : τ 1 + τ 2 Γ[v 1 τ 1 ] e 1 : τ Γ[v 2 τ 2 ] e 2 : τ Γ (case e of in 1 (v 1 ) e 1 in 2 (v 2 ) e 2 ) : τ (22) 3.5 System F expressions types e ::= Λα.e e[τ] τ ::= α α.τ (Λα.e)[τ] 1 e[τ/α] Γ e : τ Γ Λα.e : α.τ (23) Γ e : α.τ Γ e[τ] : τ [τ/α] (24) 6

CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008

CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008 CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008 Contents 1 Polymorphism 1 2 Polymorphic λ-calculus: Syntax 1 3 Static Semantics 2 4 Dynamic Semantics

More information

CSE 505, Fall 2009, Midterm Examination 5 November Please do not turn the page until everyone is ready.

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

More information

Typed Arithmetic Expressions

Typed Arithmetic Expressions Typed Arithmetic Expressions CS 550 Programming Languages Jeremy Johnson TAPL Chapters 3 and 5 1 Types and Safety Evaluation rules provide operational semantics for programming languages. The rules provide

More information

CMSC 631 Program Analysis and Understanding Fall Type Systems

CMSC 631 Program Analysis and Understanding Fall Type Systems Program Analysis and Understanding Fall 2017 Type Systems Type Systems A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according

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

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

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

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

CSE 505, Fall 2005, Midterm Examination 8 November Please do not turn the page until everyone is ready.

CSE 505, Fall 2005, Midterm Examination 8 November Please do not turn the page until everyone is ready. CSE 505, Fall 2005, Midterm Examination 8 November 2005 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

Dynamic Semantics. Dynamic Semantics. Operational Semantics Axiomatic Semantics Denotational Semantic. Operational Semantics

Dynamic Semantics. Dynamic Semantics. Operational Semantics Axiomatic Semantics Denotational Semantic. Operational Semantics Dynamic Semantics Operational Semantics Denotational Semantic Dynamic Semantics Operational Semantics Operational Semantics Describe meaning by executing program on machine Machine can be actual or simulated

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

CSE505, Fall 2012, Final Examination December 10, 2012

CSE505, Fall 2012, Final Examination December 10, 2012 CSE505, Fall 2012, Final Examination December 10, 2012 Rules: The exam is closed-book, closed-notes, except for one side of one 8.5x11in piece of paper. Please stop promptly at 12:20. You can rip apart

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

Axiomatic Semantics. Lecture 9 CS 565 2/12/08

Axiomatic Semantics. Lecture 9 CS 565 2/12/08 Axiomatic Semantics Lecture 9 CS 565 2/12/08 Axiomatic Semantics Operational semantics describes the meaning of programs in terms of the execution steps taken by an abstract machine Denotational semantics

More information

Simply Typed Lambda-Calculi (II)

Simply Typed Lambda-Calculi (II) THEORY AND PRACTICE OF FUNCTIONAL PROGRAMMING Simply Typed Lambda-Calculi (II) Dr. ZHANG Yu Institute of Software, Chinese Academy of Sciences Fall term, 2011 GUCAS, Beijing Introduction PCF Programming

More information

Foundations of Programming Languages. Paul Downen

Foundations of Programming Languages. Paul Downen Foundations of Programming Languages Paul Downen July 3 8, 2018 2 Contents 1 Static and Dynamic Semantics of a Little Language 7 1.1 Syntax................................. 7 1.2 Static Scope..............................

More information

Introduction to λ-calculus

Introduction to λ-calculus p.1/65 Introduction to λ-calculus Ken-etsu FUJITA fujita@cs.gunma-u.ac.jp http://www.comp.cs.gunma-u.ac.jp/ fujita/ Department of Computer Science Gunma University :Church 32, 36, 40; Curry 34 1. Universal

More information

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 2: Axiomatic semantics

Lecture 2: Axiomatic semantics Chair of Software Engineering Trusted Components Prof. Dr. Bertrand Meyer Lecture 2: Axiomatic semantics Reading assignment for next week Ariane paper and response (see course page) Axiomatic semantics

More information

CSE-433 Logic in Computer Science 2007 Final exam Sample Solution

CSE-433 Logic in Computer Science 2007 Final exam Sample Solution Name: Hemos ID: CSE-433 Logic in Computer Science 2007 Final exam Sample Solution This is a closed-book exam No other material is permitted It consists of 4 problems worth a total of 175 points There are

More information

Mathematical Induction. How does discrete math help us. How does discrete math help (CS160)? How does discrete math help (CS161)?

Mathematical Induction. How does discrete math help us. How does discrete math help (CS160)? How does discrete math help (CS161)? How does discrete math help us Helps create a solution (program) Helps analyze a program How does discrete math help (CS160)? Helps create a solution (program) q Logic helps you understand conditionals

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

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

Lambda-Calculus (I) 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010

Lambda-Calculus (I) 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010 Lambda-Calculus (I) jean-jacques.levy@inria.fr 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010 Plan computation models lambda-notation bound variables conversion

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

Deductive Verification

Deductive Verification Deductive Verification Mooly Sagiv Slides from Zvonimir Rakamaric First-Order Logic A formal notation for mathematics, with expressions involving Propositional symbols Predicates Functions and constant

More information

Formal Techniques for Software Engineering: Denotational Semantics

Formal Techniques for Software Engineering: Denotational Semantics Formal Techniques for Software Engineering: Denotational Semantics Rocco De Nicola IMT Institute for Advanced Studies, Lucca rocco.denicola@imtlucca.it May 2013 Lesson 4 R. De Nicola (IMT-Lucca) FoTSE@LMU

More information

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions Chapter 1 Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions 1.1 The IMP Language IMP is a programming language with an extensible syntax that was developed in the late 1960s. We will

More information

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Content COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Toby Murray, June Andronick, Gerwin Klein λ Slide 1 Intro & motivation, getting started [1] Foundations & Principles Lambda

More information

Models of computation

Models of computation Lambda-Calculus (I) jean-jacques.levy@inria.fr 2nd Asian-Pacific Summer School on Formal ethods Tsinghua University, August 23, 2010 Plan computation models lambda-notation bound variables odels of computation

More information

Theories of Programming Languages Assignment 5

Theories of Programming Languages Assignment 5 Theories of Programming Languages Assignment 5 December 17, 2012 1. Lambda-Calculus (see Fig. 1 for initions of = β, normal order evaluation and eager evaluation). (a) Let Ω = ((λx. x x) (λx. x x)), and

More information

The Lambda Calculus. Stephen A. Edwards. Fall Columbia University

The Lambda Calculus. Stephen A. Edwards. Fall Columbia University The Lambda Calculus Stephen A. Edwards Columbia University Fall 2014 Lambda Expressions Function application written in prefix form. Add four and five is (+ 4 5) Evaluation: select a redex and evaluate

More information

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages )

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages ) Formal Methods Lecture 6 (B. Pierce's slides for the book Types and Programming Languages ) This Saturday, 10 November 2018, room 335 (FSEGA), we will recover the following activities: 1 Formal Methods

More information

Consistency of a Programming Logic for a Version of PCF Using Domain Theory

Consistency of a Programming Logic for a Version of PCF Using Domain Theory Consistency of a Programming Logic for a Version of PCF Using Domain Theory Andrés Sicard-Ramírez EAFIT University Logic and Computation Seminar EAFIT University 5 April, 3 May 2013 A Core Functional Programming

More information

Formal Methods Lecture 8. (B. Pierce's slides for the book Types and Programming Languages )

Formal Methods Lecture 8. (B. Pierce's slides for the book Types and Programming Languages ) Formal Methods Lecture 8 (B. Pierce's slides for the book Types and Programming Languages ) Erasure and Typability Erasure We can transform terms in λ to terms of the untyped lambda-calculus simply by

More information

CS156: The Calculus of Computation Zohar Manna Autumn 2008

CS156: The Calculus of Computation Zohar Manna Autumn 2008 Page 3 of 52 Page 4 of 52 CS156: The Calculus of Computation Zohar Manna Autumn 2008 Lecturer: Zohar Manna (manna@cs.stanford.edu) Office Hours: MW 12:30-1:00 at Gates 481 TAs: Boyu Wang (wangboyu@stanford.edu)

More information

Categories, Proofs and Programs

Categories, Proofs and Programs Categories, Proofs and Programs Samson Abramsky and Nikos Tzevelekos Lecture 4: Curry-Howard Correspondence and Cartesian Closed Categories In A Nutshell Logic Computation 555555555555555555 5 Categories

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

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

A Calculus for Dynamic Loading

A Calculus for Dynamic Loading A Calculus for Dynamic Loading Michael Hicks University of Pennsylvania Stephanie Weirich Cornell University February 6, 2001 Abstract We present the load-calculus, used to model dynamic loading, and prove

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

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

A Short Introduction to Hoare Logic

A Short Introduction to Hoare Logic A Short Introduction to Hoare Logic Supratik Chakraborty I.I.T. Bombay June 23, 2008 Supratik Chakraborty (I.I.T. Bombay) A Short Introduction to Hoare Logic June 23, 2008 1 / 34 Motivation Assertion checking

More information

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages )

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages ) Formal Methods Lecture 6 (B. Pierce's slides for the book Types and Programming Languages ) Programming in the Lambda-Calculus, Continued Testing booleans Recall: tru = λt. λf. t fls = λt. λf. f We showed

More information

Type Systems Winter Semester 2006

Type Systems Winter Semester 2006 Type Systems Winter Semester 2006 Week 5 November 15 November 15, 2006 - version 1.0 Programming in the Lambda-Calculus, Continued Testing booleans Recall: tru = λt. λf. t fls = λt. λf. f We showed last

More information

COMP6463: λ-calculus

COMP6463: λ-calculus COMP6463: λ-calculus 1. Basics Michael Norrish Michael.Norrish@nicta.com.au Canberra Research Lab., NICTA Semester 2, 2015 Outline Introduction Lambda Calculus Terms Alpha Equivalence Substitution Dynamics

More information

Propositional Logic: Syntax

Propositional Logic: Syntax Logic Logic is a tool for formalizing reasoning. There are lots of different logics: probabilistic logic: for reasoning about probability temporal logic: for reasoning about time (and programs) epistemic

More information

Domain theory and denotational semantics of functional programming

Domain theory and denotational semantics of functional programming Domain theory and denotational semantics of functional programming Martín Escardó School of Computer Science, Birmingham University MGS 2007, Nottingham, version of April 20, 2007 17:26 What is denotational

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

Predicate Logic - Undecidability

Predicate Logic - Undecidability CS402, Spring 2016 Undecidable Problems Does the following program halts? (1) N : n, total, x, y, z (2) n GetUserInput() (3) total 3 (4) while true (5) for x 1 to total 2 (6) for y 1 to total x 1 (7) z

More information

Denotational Semantics

Denotational Semantics Q Lecture Notes on Denotational Semantics Part II of the Computer Science Tripos 2010/11 Dr Marcelo Fiore Cambridge University Computer Laboratory c A. M. Pitts, G. Winskel, M. Fiore Contents Notes ii

More information

Hoare Logic and Model Checking

Hoare Logic and Model Checking Hoare Logic and Model Checking Kasper Svendsen University of Cambridge CST Part II 2016/17 Acknowledgement: slides heavily based on previous versions by Mike Gordon and Alan Mycroft Introduction In the

More information

Induction; Operational Semantics. Fall Software Foundations CIS 500

Induction; Operational Semantics. Fall Software Foundations CIS 500 CIS 500 Software Foundations Fall 2005 Induction; Operational Semantics CIS 500, Induction; Operational Semantics 1 Announcements Review recitations start this week. You may go to any recitation section

More information

Tutorial on Semantics Part I

Tutorial on Semantics Part I Tutorial on Semantics Part I Basic Concepts Prakash Panangaden 1 1 School of Computer Science McGill University on sabbatical leave at Department of Computer Science Oxford University Fields Institute,

More information

About Typed Algebraic Lambda-calculi

About Typed Algebraic Lambda-calculi About Typed Algebraic Lambda-calculi Benoît Valiron INRIA Saclay/LIX Palaiseau, France valiron@lix.polytechnique.fr Abstract Arrighi and Dowek (2008) introduce an untyped lambdacalculus together with a

More information

CIS 500: Software Foundations. November 8, Solutions

CIS 500: Software Foundations. November 8, Solutions CIS 500: Software Foundations Midterm II November 8, 2018 Solutions 1. (8 points) Put an X in the True or False box for each statement. (1) For every b : bexp and c1, c2 : com, either the command IFB b

More information

Program verification. Hoare triples. Assertional semantics (cont) Example: Semantics of assignment. Assertional semantics of a program

Program verification. Hoare triples. Assertional semantics (cont) Example: Semantics of assignment. Assertional semantics of a program Program verification Assertional semantics of a program Meaning of a program: relation between its inputs and outputs; specified by input assertions (pre-conditions) and output assertions (post-conditions)

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

Beyond First-Order Logic

Beyond First-Order Logic Beyond First-Order Logic Software Formal Verification Maria João Frade Departmento de Informática Universidade do Minho 2008/2009 Maria João Frade (DI-UM) Beyond First-Order Logic MFES 2008/09 1 / 37 FOL

More information

Lecture 2: Syntax. January 24, 2018

Lecture 2: Syntax. January 24, 2018 Lecture 2: Syntax January 24, 2018 We now review the basic definitions of first-order logic in more detail. Recall that a language consists of a collection of symbols {P i }, each of which has some specified

More information

CIS 500: Software Foundations

CIS 500: Software Foundations CIS 500: Software Foundations Solutions Final Exam December 15, 2017 1. Inductive relations (11 points) Complete the definition at the bottom of the page of an Inductive relation count that relates a list

More information

Logic and Probability Lecture 3: Beyond Boolean Logic

Logic and Probability Lecture 3: Beyond Boolean Logic Logic and Probability Lecture 3: Beyond Boolean Logic Wesley Holliday & Thomas Icard UC Berkeley & Stanford August 13, 2014 ESSLLI, Tübingen Wesley Holliday & Thomas Icard: Logic and Probability, Lecture

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

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

Introduction to lambda calculus Part 2

Introduction to lambda calculus Part 2 Introduction to lambda calculus Part 2 Antti-Juhani Kaijanaho 2017-01-24... 1 Untyped lambda calculus 1.1 Syntax... x, y, z Var t, u Term t, u ::= x t u λx t... In this document, I will be using the following

More information

Section 2.2 Set Operations. Propositional calculus and set theory are both instances of an algebraic system called a. Boolean Algebra.

Section 2.2 Set Operations. Propositional calculus and set theory are both instances of an algebraic system called a. Boolean Algebra. Section 2.2 Set Operations Propositional calculus and set theory are both instances of an algebraic system called a Boolean Algebra. The operators in set theory are defined in terms of the corresponding

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 2010 COMP2600 (Formal Methods for Software Engineering) Writing Period: 3 hours duration Study Period: 15 minutes duration Permitted Materials: One A4

More information

September 14. Fall Software Foundations CIS 500

September 14. Fall Software Foundations CIS 500 CIS 500 Software Foundations Fall 2005 September 14 CIS 500, September 14 1 Announcements I will be away September 19-October 5. I will be reachable by email. Fastest response cis500@cis.upenn.edu No office

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

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 2b Andrew Tolmach Portland State University 1994-2017 Semantics Informal vs. Formal Informal semantics Descriptions in English (or other natural language)

More information

Math 10850, fall 2017, University of Notre Dame

Math 10850, fall 2017, University of Notre Dame Math 10850, fall 2017, University of Notre Dame Notes on first exam September 22, 2017 The key facts The first midterm will be on Thursday, September 28, 6.15pm-7.45pm in Hayes-Healy 127. What you need

More information

Spring 2016 Program Analysis and Verification. Lecture 3: Axiomatic Semantics I. Roman Manevich Ben-Gurion University

Spring 2016 Program Analysis and Verification. Lecture 3: Axiomatic Semantics I. Roman Manevich Ben-Gurion University Spring 2016 Program Analysis and Verification Lecture 3: Axiomatic Semantics I Roman Manevich Ben-Gurion University Warm-up exercises 1. Define program state: 2. Define structural semantics configurations:

More information

Floyd-Hoare Style Program Verification

Floyd-Hoare Style Program Verification Floyd-Hoare Style Program Verification Deepak D Souza Department of Computer Science and Automation Indian Institute of Science, Bangalore. 9 Feb 2017 Outline of this talk 1 Overview 2 Hoare Triples 3

More information

REVIEW FOR THIRD 3200 MIDTERM

REVIEW FOR THIRD 3200 MIDTERM REVIEW FOR THIRD 3200 MIDTERM PETE L. CLARK 1) Show that for all integers n 2 we have 1 3 +... + (n 1) 3 < 1 n < 1 3 +... + n 3. Solution: We go by induction on n. Base Case (n = 2): We have (2 1) 3 =

More information

Hoare Logic: Part II

Hoare Logic: Part II Hoare Logic: Part II COMP2600 Formal Methods for Software Engineering Jinbo Huang Australian National University COMP 2600 Hoare Logic II 1 Factorial {n 0} fact := 1; i := n; while (i >0) do fact := fact

More information

First-Order Logic. 1 Syntax. Domain of Discourse. FO Vocabulary. Terms

First-Order Logic. 1 Syntax. Domain of Discourse. FO Vocabulary. Terms First-Order Logic 1 Syntax Domain of Discourse The domain of discourse for first order logic is FO structures or models. A FO structure contains Relations Functions Constants (functions of arity 0) FO

More information

In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and

In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and shows how a program can sometimes be systematically constructed

More information

Hoare Logic: Reasoning About Imperative Programs

Hoare Logic: Reasoning About Imperative Programs Hoare Logic: Reasoning About Imperative Programs COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2018 Programming Paradigms Functional. (Haskell, SML, OCaml,... ) main paradigm:

More information

Denotational Semantics of Programs. : SimpleExp N.

Denotational Semantics of Programs. : SimpleExp N. Models of Computation, 2010 1 Denotational Semantics of Programs Denotational Semantics of SimpleExp We will define the denotational semantics of simple expressions using a function : SimpleExp N. Denotational

More information

Spring 2015 Program Analysis and Verification. Lecture 4: Axiomatic Semantics I. Roman Manevich Ben-Gurion University

Spring 2015 Program Analysis and Verification. Lecture 4: Axiomatic Semantics I. Roman Manevich Ben-Gurion University Spring 2015 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University Agenda Basic concepts of correctness Axiomatic semantics (pages 175-183) Hoare Logic

More information

MATH 13 SAMPLE FINAL EXAM SOLUTIONS

MATH 13 SAMPLE FINAL EXAM SOLUTIONS MATH 13 SAMPLE FINAL EXAM SOLUTIONS WINTER 2014 Problem 1 (15 points). For each statement below, circle T or F according to whether the statement is true or false. You do NOT need to justify your answers.

More information

Simply Typed λ-calculus

Simply Typed λ-calculus Simply Typed λ-calculus Lecture 1 Jeremy Dawson The Australian National University Semester 2, 2017 Jeremy Dawson (ANU) COMP4630,Lecture 1 Semester 2, 2017 1 / 23 A Brief History of Type Theory First developed

More information

MATH FINAL EXAM REVIEW HINTS

MATH FINAL EXAM REVIEW HINTS MATH 109 - FINAL EXAM REVIEW HINTS Answer: Answer: 1. Cardinality (1) Let a < b be two real numbers and define f : (0, 1) (a, b) by f(t) = (1 t)a + tb. (a) Prove that f is a bijection. (b) Prove that any

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 17 Tuesday, April 2, 2013 1 There is a strong connection between types in programming languages and propositions

More information

Programming Languages and Types

Programming Languages and Types Programming Languages and Types Klaus Ostermann based on slides by Benjamin C. Pierce Where we re going Type Systems... Type systems are one of the most fascinating and powerful aspects of programming

More information

MODEL-CHECKING IN DENSE REAL-TIME SHANT HARUTUNIAN

MODEL-CHECKING IN DENSE REAL-TIME SHANT HARUTUNIAN MODEL-CHECKING IN DENSE REAL-TIME SHANT HARUTUNIAN 1. Introduction These slides are for a talk based on the paper Model-Checking in Dense Real- Time, by Rajeev Alur, Costas Courcoubetis, and David Dill.

More information

CS 4110 Programming Languages & Logics. Lecture 25 Records and Subtyping

CS 4110 Programming Languages & Logics. Lecture 25 Records and Subtyping CS 4110 Programming Languages & Logics Lecture 25 Records and Subtyping 31 October 2016 Announcements 2 Homework 6 returned: x = 34 of 37, σ = 3.8 Preliminary Exam II in class on Wednesday, November 16

More information

Notation for Logical Operators:

Notation for Logical Operators: Notation for Logical Operators: always true always false... and...... or... if... then...... if-and-only-if... x:x p(x) x:x p(x) for all x of type X, p(x) there exists an x of type X, s.t. p(x) = is equal

More information

COP4020 Programming Languages. Introduction to Axiomatic Semantics Prof. Robert van Engelen

COP4020 Programming Languages. Introduction to Axiomatic Semantics Prof. Robert van Engelen COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen Assertions and Preconditions Assertions are used by programmers to verify run-time execution An assertion is a

More information

Propositional and Predicate Logic - XIII

Propositional and Predicate Logic - XIII Propositional and Predicate Logic - XIII Petr Gregor KTIML MFF UK WS 2016/2017 Petr Gregor (KTIML MFF UK) Propositional and Predicate Logic - XIII WS 2016/2017 1 / 22 Undecidability Introduction Recursive

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 6110 Lecture 21 The Fixed-Point Theorem 8 March 2013 Lecturer: Andrew Myers. 1 Complete partial orders (CPOs) 2 Least fixed points of functions

CS 6110 Lecture 21 The Fixed-Point Theorem 8 March 2013 Lecturer: Andrew Myers. 1 Complete partial orders (CPOs) 2 Least fixed points of functions CS 6110 Lecture 21 The Fixed-Point Theorem 8 March 2013 Lecturer: Andrew Myers We saw that the semantics of the while command are a fixed point. We also saw that intuitively, the semantics are the limit

More information

Formal Methods for Probabilistic Systems

Formal Methods for Probabilistic Systems 1 Formal Methods for Probabilistic Systems Annabelle McIver Carroll Morgan Source-level program logic Introduction to probabilistic-program logic Systematic presentation via structural induction Layout

More information

CIS 500 Software Foundations Final Exam Answer key December 20, 2004

CIS 500 Software Foundations Final Exam Answer key December 20, 2004 CIS 500 Software Foundations Final Exam Answer key December 20, 2004 True/False questions For each of the following statements, circle T if the sentence is true or F otherwise. 1. (10 points) (a) T F The

More information

The Greek Alphabet. (a) The Untyped λ-calculus

The Greek Alphabet. (a) The Untyped λ-calculus 3. The λ-calculus and Implication Greek Letters (a) The untyped λ-calculus. (b) The typed λ-calculus. (c) The λ-calculus in Agda. (d) Logic with Implication (e) Implicational Logic in Agda. (f) More on

More information

CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal

CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal CSE 311 Lecture 28: Undecidability of the Halting Problem Emina Torlak and Kevin Zatloukal 1 Topics Final exam Logistics, format, and topics. Countability and uncomputability A quick recap of Lecture 27.

More information

Blame for All. Amal Ahmed, Robert Bruce Findler, Jeremy Siek, Philip Wadler

Blame for All. Amal Ahmed, Robert Bruce Findler, Jeremy Siek, Philip Wadler Blame for All Amal Ahmed, Robert Bruce Findler, Jeremy Siek, Philip Wadler Vs. Part I The bit you know from before with a twist A simple untyped program let inc = λx. x + 1 in let app = λf. λx. f x in

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

The Lifting Lemma. Ralf Hinze

The Lifting Lemma. Ralf Hinze The Lifting Lemma Ralf Hinze Computing Laboratory, University of Oxford Wolfson Building, Parks Road, Oxford, OX1 3QD, England ralf.hinze@comlab.ox.ac.uk http://www.comlab.ox.ac.uk/ralf.hinze/ June 2009

More information

The Hoare Logic of Deterministic and Nondeterministic Monadic Recursion Schemes

The Hoare Logic of Deterministic and Nondeterministic Monadic Recursion Schemes The Hoare Logic of Deterministic and Nondeterministic Monadic Recursion Schemes Konstantinos Mamouras Cornell University mamouras@cs.cornell.edu December 24, 2014 Abstract The equational theory of deterministic

More information