Refined Environment Classifiers

Size: px
Start display at page:

Download "Refined Environment Classifiers"

Transcription

1 Refined Environment Classifiers Type- and Scope-safe Code Generation with Mutable Cells Oleg Kiselyov Yukiyoshi Kameyama Yuto Sudo Tohoku University University of Tsukuba APLAS 2016 November 22, 2016

2 Region Memory Management for Free Variables Type- and Scope-safe Code Generation with Mutable Cells Oleg Kiselyov Yukiyoshi Kameyama Yuto Sudo Tohoku University University of Tsukuba APLAS 2016 November 22,

3 3 Summary First stage calculus <NJ> for imperative code generators without ad hoc restrictions Store open code and retrieve in a different binding environment Proven sound type system: generated code is always well-typed and well-scoped Distillation of StagedHaskell Practical Justification of (of a part of) StagedHaskell Easily embeddable (in OCaml) and can actually be used Insightful

4 Insights Region-based memory management Contextual Modal Type Theory ML F Overcoming the bureaucracy of syntax for names What is lexical scope, after all 4

5 Why code generation Program like y k = N 1 j=0 x j e 2πijk/N k = 0..N 1 but run like fun x 35 let t 36 = x 35.(0) +. x 35.(4) in let t 37 = x 35.(1) +. x 35.(5) in let t 38 = x 35.(0). x 35.(4) in let t 39 = x 35.(1). x 35.(5) in let t 40 = x 35.(2) +. x 35.(6) in let t 41 = x 35.(3) +. x 35.(7) in let t 42 = x 35.(2). x 35.(6) in let t 43 = x 35.(3). x 35.(7) in let t 44 = t t 40 in let t 45 = t t 41 in let t 46 = t 36. t 40 in let t 47 = t 37. t 41 in... 5

6 Why code generation fun x 35 let t 36 = x 35.(0) +. x 35.(4) in let t 37 = x 35.(1) +. x 35.(5) in let t 38 = x 35.(0). x 35.(4) in let t 39 = x 35.(1). x 35.(5) in let t 40 = x 35.(2) +. x 35.(6) in let t 41 = x 35.(3) +. x 35.(7) in let t 42 = x 35.(2). x 35.(6) in let t 43 = x 35.(3). x 35.(7) in let t 44 = t t 40 in let t 45 = t t 41 in let t 46 = t 36. t 40 in let t 47 = t 37. t 41 in... write and re-write, and re-write,... generators some degree of correctness is needed: well-typedness and well-boundness 5

7 Is well-scopedness so important? The re-factor solved performance issues in our use case of LMS which appeared due to the huge size of code we tend to generate. While we were able to resolve the performance issues, we introduced new bugs... [that] would manifest in errors such as: forward reference extends over definition of value x1620 [error] val x1343 = x1232(x1123, x1124, x1180, x1181, x1223, x1224, x1223, x1229, x1216, x1120, x1122, x1121) Note that variables are indexed in ascending order starting at zero, meaning that a large piece of code is processed before we hit this error. The root cause of bugs such as this one often proved to be very simple but heavily obfuscated in the code it manifested in. The concrete example was triggered by the code motion... RandIR: Differential Testing for Embedded Compilers. Ofenbeck, Rompf, Püschel. Scala Symposium

8 Calculi for Code generation λ (1996), λ α (2003),... MiniML meta ref (2000), Mint (2010),... pure freshml (2007),... 7

9 Calculi for Code generation λ (1996), λ α (2003),... MiniML meta ref (2000), Mint (2010),... pure freshml (2007),... No effects 7

10 Calculi for Code generation λ (1996), λ α (2003),... MiniML meta ref (2000), Mint (2010),... pure freshml (2007),... Only closed code can be stored 7

11 Calculi for Code generation λ (1996), λ α (2003),... MiniML meta ref (2000), Mint (2010),... pure freshml (2007),... So complex it is not even implemented 7

12 Calculi for Code generation λ (1996), λ α (2003),... MiniML meta ref (2000), Mint (2010),... pure freshml (2007),... Can emulate mutation/control effects with state-passing, CPS? 7

13 Calculi for Code generation λ (1996), λ α (2003),... MiniML meta ref (2000), Mint (2010),... pure freshml (2007),... Can emulate mutation/control effects with state-passing, CPS? Yes, but we can t do code movement across binders 7

14 8 <NJ> by Example <NJ> is the standard CBV λ-calculus with constants for code-generation power x n = x n let body = λf n x. if n=0 then cint 1 else x f (n 1) x in let power = λn. λx. ( fix body) n x in power 2

15 8 <NJ> by Example let body = λf n x. if n=0 then cint 1 else x f (n 1) x in let power = λn. λx. ( fix body) n x in power 2 let body =... in λx. (fix body) 2 x

16 8 <NJ> by Example let body = λf n x. if n=0 then cint 1 else x f (n 1) x in let power = λn. λx. ( fix body) n x in power 2 let body =... in λx. (fix body) 2 x let body =... in λy.( fix body) 2 y

17 8 <NJ> by Example let body = λf n x. if n=0 then cint 1 else x f (n 1) x in let power = λn. λx. ( fix body) n x in power 2 let body =... in λx. (fix body) 2 x let body =... in λy.( fix body) 2 y let body =... in λy. if 2=0 then cint 1 else y ( fix body) 1 y

18 8 <NJ> by Example let body = λf n x. if n=0 then cint 1 else x f (n 1) x in let power = λn. λx. ( fix body) n x in power 2 let body =... in λx. (fix body) 2 x let body =... in λy.( fix body) 2 y let body =... in λy. if 2=0 then cint 1 else y ( fix body) 1 y λy. y y cint 1

19 8 <NJ> by Example let body = λf n x. if n=0 then cint 1 else x f (n 1) x in let power = λn. λx. ( fix body) n x in power 2 let body =... in λx. (fix body) 2 x let body =... in λy.( fix body) 2 y let body =... in λy. if 2=0 then cint 1 else y ( fix body) 1 y λy. y y cint 1 λy. y y 1

20 8 <NJ> by Example let body = λf n x. if n=0 then cint 1 else x f (n 1) x in let power = λn. λx. ( fix body) n x in power 2 let body =... in λx. (fix body) 2 x let body =... in λy.( fix body) 2 y let body =... in λy. if 2=0 then cint 1 else y ( fix body) 1 y λy. y y cint 1 λy. y y 1 λy. y y 1 λy. y y 1

21 <NJ> by Example let body = λf n x. if n=0 then cint 1 else x f (n 1) x in let power = λn. λx. ( fix body) n x in power 2 let body =... in λx. (fix body) 2 x let body =... in λy.( fix body) 2 y let body =... in λy. if 2=0 then cint 1 else y ( fix body) 1 y λy. y y cint 1 λy. y y 1 λy. y y 1 λy. y y 1 λy. y y 1 Generating a function takes two steps: Generate a variable name eventually, generate a binder for it 8

22 9 State Power let body = λn.λx. let r = ref ( cint 1) in fix (λf.λn. if n = 0 then 0 else (r :=!r x; f (n 1))) n;!r in let power = λn. λx. body n x in power 2

23 9 State Power let body = λn.λx. let r = ref ( cint 1) in fix (λf.λn. if n = 0 then 0 else (r :=!r x; f (n 1))) n;!r in let power = λn. λx. body n x in power 2 let r = ref 1 in λy. ( if 2 = 0 then 0 else (r :=!r y ; fix f 1);!r)

24 9 State Power let body = λn.λx. let r = ref ( cint 1) in fix (λf.λn. if n = 0 then 0 else (r :=!r x; f (n 1))) n;!r in let power = λn. λx. body n x in power 2 let r = ref 1 in λy. ( if 2 = 0 then 0 else (r :=!r y ; fix f 1);!r) let r = ref 1 y in λy. ( if 1 = 0 then 0 else (r :=!r y ; fix f 1);!r)

25 9 State Power let body = λn.λx. let r = ref ( cint 1) in fix (λf.λn. if n = 0 then 0 else (r :=!r x; f (n 1))) n;!r in let power = λn. λx. body n x in power 2 let r = ref 1 in λy. ( if 2 = 0 then 0 else (r :=!r y ; fix f 1);!r) let r = ref 1 y in λy. ( if 1 = 0 then 0 else (r :=!r y ; fix f 1);!r) let r = ref 1 y y in λy.!r

26 9 State Power let body = λn.λx. let r = ref ( cint 1) in fix (λf.λn. if n = 0 then 0 else (r :=!r x; f (n 1))) n;!r in let power = λn. λx. body n x in power 2 let r = ref 1 in λy. ( if 2 = 0 then 0 else (r :=!r y ; fix f 1);!r) let r = ref 1 y in λy. ( if 1 = 0 then 0 else (r :=!r y ; fix f 1);!r) let r = ref 1 y y in λy.!r λy. 1 y y λy. 1 y y

27 10 Too much of the State Power let r = ref cint 0 in (λx. r := x);!r

28 10 Too much of the State Power let r = ref cint 0 in (λx. r := x);!r let r = ref cint 0 in (λy. r := y );!r

29 10 Too much of the State Power let r = ref cint 0 in (λx. r := x);!r let r = ref cint 0 in (λy. r := y );!r let r = ref y in (λy. y );!r

30 10 Too much of the State Power let r = ref cint 0 in (λx. r := x);!r let r = ref cint 0 in (λy. r := y );!r let r = ref y in (λy. y );!r let r = ref y in! r

31 10 Too much of the State Power let r = ref cint 0 in (λx. r := x);!r let r = ref cint 0 in (λy. r := y );!r let r = ref y in (λy. y );!r let r = ref y in! r let r = ref y in y

32 11 Type System (outline) y :??

33 11 Type System (outline) Γ y : int?? where y:int Γ We are manipulating open code: cf. Open CBV yesterday Annotate the type of a code value with some form of Γ size of Γ Γ itself (CMTT) Γ (without names, just a sequence of types)

34 12 Annotated code types by example let r = ref cint 0 in (λz. λx. r := x);!r : <int> (int,(bool,())) Γ z: <bool> (bool,()) Γ x: <int> (int,(bool,())) Γ r: <int> (int,(bool,())) ref

35 12 Annotated code types by example let r = ref cint 0 in (λz. λx. r := x);!r : <int> (int,(bool,())) Γ z: <bool> (bool,()) Γ x: <int> (int,(bool,())) Γ r: <int> (int,(bool,())) ref However, let r = ref cint 0 in (λz. λx. r := x); (λy. λu.!r) λy. λu. x : <int int int> () According to the type system, the result is closed.

36 13 Taste of a Type System γ Γ γ 1 Γ Γ, γ 1, (γ 1 γ), (x: t 1 γ 1 ) e: t 2 γ 1 Γ λx.e: t 1 t 2 γ CAbs

37 14 Taste of a Type System Γ 2 x 1 : int γ 1 Γ 2 = γ 2 γ 1 Γ 2 x 1: int γ 2 Γ 2 x 2: int γ 2 Γ 2 x 1 + x 2 : int γ 2 γ 1, (γ 1 γ 0 ), (x 1 : int γ 1 ) λx 2. x 1 + x 2 : int int γ 1 [] λx 1.λx 2. x 1 + x 2 : int int int γ 0

38 15 Taste of a Type System r : int γ 1, γ 2,γ 2 γ, x: int γ 2 r := x: int γ 2 r : int γ 1 ref (λx. r := x) : int int γ [] let r = ref cint 0 in (λx. r := x) : int int γ Region memory management

39 16 Summary First stage calculus <NJ> for imperative code generators without ad hoc restrictions Store open code and retrieve in a different binding environment Sound type system: generated code is always well-typed and well-scoped Distillation of StagedHaskell Practical Justification of (of a part of) StagedHaskell Easily embeddable (in OCaml) and can actually be used Insightful

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

Typed metaprogramming with effects

Typed metaprogramming with effects Typed metaprogramming with effects Chung-chieh Shan (Rutgers University) with Chris Barker, Yukiyoshi Kameyama, Oleg Kiselyov LFMTP 14 July 2010 2/32 Accidental language design Documents Fonts T E X Pages

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

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

Static Program Analysis

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

More information

Information Flow Inference for ML

Information Flow Inference for ML Information Flow Inference for ML Vincent Simonet INRIA Rocquencourt Projet Cristal MIMOSA September 27, 2001 Information flow account number bank applet order vendor account H order L bank H vendor L

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

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

Fully-Abstract Compilation by Approximate Back-Translation Technical Appendix

Fully-Abstract Compilation by Approximate Back-Translation Technical Appendix Fully-Abstract Compilation by Approximate Back-Translation Technical Appendix Abstract This technical appendix provides the full formalisation and proofs for its paper 1 Contents 1 The Source Language

More information

Normalization by Evaluation

Normalization by Evaluation Normalization by Evaluation Andreas Abel Department of Computer Science and Engineering Chalmers and Gothenburg University PhD Seminar in Mathematical Engineering EAFIT University, Medellin, Colombia 9

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

Quantum Functional Programming Language & Its Denotational Semantics

Quantum Functional Programming Language & Its Denotational Semantics Quantum Functional Programming Language & Its Denotational Semantics Ichiro Hasuo Dept. Computer Science University of Tokyo Naohiko Hoshino Research Inst. for Math. Sci. Kyoto University Talk based on:

More information

Operational Semantics

Operational Semantics Operational Semantics Semantics and applications to verification Xavier Rival École Normale Supérieure Xavier Rival Operational Semantics 1 / 50 Program of this first lecture Operational semantics Mathematical

More information

Simply Typed Lambda Calculus

Simply Typed Lambda Calculus Simply Typed Lambda Calculus Language (ver1) Lambda calculus with boolean values t ::= x variable x : T.t abstraction tt application true false boolean values if ttt conditional expression Values v ::=

More information

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth.

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth. Type Systems Lecture 2 Oct. 27th, 2004 Sebastian Maneth http://lampwww.epfl.ch/teaching/typesystems/2004 Today 1. What is the Lambda Calculus? 2. Its Syntax and Semantics 3. Church Booleans and Church

More information

A Call-by-Name CPS Hierarchy

A Call-by-Name CPS Hierarchy A Call-by-Name CPS Hierarchy Asami Tanaka and Yukiyoshi Kameyama University of Tsukuba, Japan asami@logic.cs.tsukuba.ac.jp,kameyama@acm.org Abstract. The Continuation-Passing-Style (CPS) translation gives

More information

Information Flow Inference for ML

Information Flow Inference for ML POPL 02 INRIA Rocquencourt Projet Cristal Francois.Pottier@inria.fr http://cristal.inria.fr/~fpottier/ Vincent.Simonet@inria.fr http://cristal.inria.fr/~simonet/ Information flow analysis account number

More information

1 Problem 1. (20 pts)

1 Problem 1. (20 pts) CS 336 Programming Languages Homework Solution 4 Winter 2005 Due 2/24/05 1 Problem 1. (20 pts) Do Exercise 18.6.2. We define a meta-operation + on types as follows: If R is a record type with labels given

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

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

Monads for Relations. Jeremy G. Siek University of Colorado at Boulder SPLS, June Jeremy Siek Monads for Relations 1 / 20

Monads for Relations. Jeremy G. Siek University of Colorado at Boulder SPLS, June Jeremy Siek Monads for Relations 1 / 20 Monads for Relations Jeremy G. Siek University of Colorado at Boulder SPLS, June 2010 Jeremy Siek Monads for Relations 1 / 20 Natural (Big-Step) Semantics for CBV Lambda ρ e v Env Expr Value ρ x ρ x ρ

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

A Concurrent Logical Framework

A Concurrent Logical Framework A Concurrent Logical Framework Frank Pfenning Carnegie Mellon University Types Workshop Torino, Italy, April 2003 Joint work with Iliano Cervesato, David Walker, and Kevin Watkins Types 03, Torino, April

More information

The Locally Nameless Representation

The Locally Nameless Representation Noname manuscript No. (will be inserted by the editor) The Locally Nameless Representation Arthur Charguéraud Received: date / Accepted: date Abstract This paper provides an introduction to the locally

More information

3.2 Reduction 29. Truth. The constructor just forms the unit element,. Since there is no destructor, there is no reduction rule.

3.2 Reduction 29. Truth. The constructor just forms the unit element,. Since there is no destructor, there is no reduction rule. 32 Reduction 29 32 Reduction In the preceding section, we have introduced the assignment of proof terms to natural deductions If proofs are programs then we need to explain how proofs are to be executed,

More information

Continuations, Processes, and Sharing. Paul Downen, Luke Maurer, Zena M. Ariola, Daniele Varacca. September 8, 2014

Continuations, Processes, and Sharing. Paul Downen, Luke Maurer, Zena M. Ariola, Daniele Varacca. September 8, 2014 Continuations, Processes, and Sharing Paul Downen, Luke Maurer, Zena M. Ariola, Daniele Varacca University of Oregon, Université Paris Diderot September 8, 2014 The plethora of semantic artifacts Many

More information

Sound and Efficient Language-Integrated Query

Sound and Efficient Language-Integrated Query Sound and Efficient Language-Integrated Query Maintaining the ORDER Oleg Kiselyov Tatsuya Katsushima Tohoku University, Japan APLAS 2017 November, 2017 2 Outline Motivation Core SQUR Core SQUR with Ranking

More information

Congruence of Bisimulation in a Non-Deterministic Call-By-Need Lambda Calculus

Congruence of Bisimulation in a Non-Deterministic Call-By-Need Lambda Calculus Congruence of Bisimulation in a Non-Deterministic Call-By-Need Lambda Calculus Matthias Mann Johann Wolfgang Goethe-Universität, Frankfurt, Germany Congruence of Bisimulation p. 1/21 Lambda Calculi and

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

Embedded probabilistic programming

Embedded probabilistic programming Embedded probabilistic programming Oleg Kiselyov FNMOC oleg@pobox.com Chung-chieh Shan Rutgers University ccshan@cs.rutgers.edu 17 July 2009 Probabilistic inference Model (what) Pr(Reality) Pr(Obs j Reality)

More information

Limitations of OCAML records

Limitations of OCAML records Limitations of OCAML records The record types must be declared before they are used; a label e can belong to only one record type (otherwise fun x x.e) would have several incompatible types; we cannot

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

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

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg Type Inference For the Simply-Typed Lambda Calculus Albert-Ludwigs-Universität Freiburg Peter Thiemann, Manuel Geffken University of Freiburg 24. Januar 2013 Outline 1 Introduction 2 Applied Lambda Calculus

More information

Embedding Classical and Quantum Circuits in Haskell

Embedding Classical and Quantum Circuits in Haskell Embedding Classical and Quantum Circuits in Haskell Amr Sabry School of Informatics and Computing Indiana University July 26, 2012 Amr Sabry ( School of Informatics and Computing Embedding Indiana University

More information

Principal types Robustness to program transformations Practice. Type constraints for simple types Type constraints for ML Type inference in ML F

Principal types Robustness to program transformations Practice. Type constraints for simple types Type constraints for ML Type inference in ML F 1 Design iml F : an implicity-typed extension of System F Types explained eml F : an explicitly-typed version of iml F 2 Results Principal types Robustness to program transformations Practice 3 Type inference

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

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017 Verified Characteristic Formulae for CakeML Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017 CakeML Has: references, modules, datatypes, exceptions, a FFI,... Doesn t have:

More information

Cylindrical Algebraic Decomposition in Coq

Cylindrical Algebraic Decomposition in Coq Cylindrical Algebraic Decomposition in Coq MAP 2010 - Logroño 13-16 November 2010 Assia Mahboubi INRIA Microsoft Research Joint Centre (France) INRIA Saclay Île-de-France École Polytechnique, Palaiseau

More information

Staged Notational Definitions

Staged Notational Definitions Staged Notational Definitions Walid Taha 1 and Patricia Johann 2 1 Department of Computer Science, Rice University, taha@cs.rice.edu 2 Department of Computer Science, Rutgers University, pjohann@crab.rutgers.edu

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

Functional Programming with F# Overview and Basic Concepts

Functional Programming with F# Overview and Basic Concepts Functional Programming with F# Overview and Basic Concepts Radu Nicolescu Department of Computer Science University of Auckland 27 Sep 2017 1 / 52 1 Background 2 Overview 3 Type System and Type Inference

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

A Bisimulation-Like Proof Method for Contextual Properties in Untyped λ-calculus with References and Deallocation

A Bisimulation-Like Proof Method for Contextual Properties in Untyped λ-calculus with References and Deallocation A Bisimulation-Like Proof Method for Contextual Properties in Untyped λ-calculus with References and Deallocation Eijiro Sumii Graduate School of Information Sciences, Tohoku University, Aoba-ku Aramki

More information

Structural recursion with locally scoped names

Structural recursion with locally scoped names JFP 21 (3): 235 286, 2011. c Cambridge University Press 2011 doi:10.1017/s0956796811000116 235 Structural recursion with locally scoped names ANDREW M. PITTS University of Cambridge Computer Laboratory

More information

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 11: Subtyping Prof Liang Huang huang@qccscunyedu Big Picture Part I: Fundamentals Functional Programming and Basic Haskell Proof by Induction and Structural Induction

More information

Algorithmic Reasoning about Böhm Trees

Algorithmic Reasoning about Böhm Trees Algorithmic Reasoning about Böhm Trees Luke Ong University of Oxford (Joint with Bahareh Afshari, Matthew Hague, Graham Leigh, Steven Ramsay, and Takeshi Tsukada) IMS Workshop on Higher-Order Model Checking

More information

Lecture Notes on Intuitionistic Kripke Semantics

Lecture Notes on Intuitionistic Kripke Semantics Lecture Notes on Intuitionistic Kripke Semantics 15-816: Modal Logic Frank Pfenning Lecture 15 March 18, 2010 1 Introduction In this lecture we present an intuitionistic approach to describing a multipleworld

More information

The Spirit of Ghost Code

The Spirit of Ghost Code The Spirit of Ghost Code Jean-Christophe Filliâtre, Léon Gondelman, Andrei Paskevich To cite this version: Jean-Christophe Filliâtre, Léon Gondelman, Andrei Paskevich. The Spirit of Ghost Code. Formal

More information

Notes from Yesterday s Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons.

Notes from Yesterday s  Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons. CIS 500 Software Foundations Fall 2006 Notes from Yesterday s Email Discussion November 1 Some lessons This is generally a crunch-time in the semester Slow down a little and give people a chance to catch

More information

CS 611 Advanced Programming Languages. Andrew Myers Cornell University. Lecture 26 Type reconstruction. 1 Nov 04. Type reconstruction

CS 611 Advanced Programming Languages. Andrew Myers Cornell University. Lecture 26 Type reconstruction. 1 Nov 04. Type reconstruction CS 611 Advanced Programming Languages Andrew Myers Cornell University Lecture 26 Type reconstruction 1 Nov 04 Type reconstruction Simple typed language: e ::= x b λx:τ. e e 1 e 2 e 1 + e 2 if e 0 then

More information

The lambda calculus with constructors

The lambda calculus with constructors The lambda calculus with constructors Categorical semantic and Continuations Barbara Petit Focus - Univ. Bologna CaCos 2012 Barbara Petit (Focus - Univ. Bologna) The lambda calculus with constructors 1

More information

Encoding security protocols in the cryptographic λ-calculus. Eijiro Sumii Joint work with Benjamin Pierce University of Pennsylvania

Encoding security protocols in the cryptographic λ-calculus. Eijiro Sumii Joint work with Benjamin Pierce University of Pennsylvania Encoding security protocols in the cryptographic λ-calculus Eijiro Sumii Joint work with Benjamin Pierce University of Pennsylvania An obvious fact Security is important Cryptography is a major way to

More information

A Polymorphic Type and System for Multi-Staged Exceptions

A Polymorphic Type and System for Multi-Staged Exceptions A Polymorphic Type System for Multi-Staged Exceptions Seoul National University 08/04/2006 This is a joint work with In-Sook Kim and Kwangkeun Yi Outlie 1. Introduction and Examples 2. Operational Semantics

More information

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types

More information

Typing-by-encoding. A reductionistic approach to building type systems. François Pottier.

Typing-by-encoding. A reductionistic approach to building type systems. François Pottier. Typing-by-encoding A reductionistic approach to building type systems François Pottier Francois.Pottier@inria.fr Overview What is typing-by-encoding? Encoding exceptions into sums (folklore). Encoding

More information

Jones-Optimal Partial Evaluation by Specialization-Safe Normalization

Jones-Optimal Partial Evaluation by Specialization-Safe Normalization Jones-Optimal Partial Evaluation by Specialization-Safe Normalization MATT BROWN, University of California Los Angeles, USA JENS PALSBERG, University of California Los Angeles, USA We present partial evaluation

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

GOTO the past / programs choose their own adventure. CSE 505: Programming Languages

GOTO the past / programs choose their own adventure. CSE 505: Programming Languages GOTO the past / programs choose their own adventure. CSE 505: Programming Languages Lecture 13 Evaluation Contexts First-Class Continuations Continuation-Passing Style Zach Tatlock Fall 2013 Zach Tatlock

More information

Names and Symmetry in Computer Science

Names and Symmetry in Computer Science 1/27 Names and Symmetry in Computer Science Andrew Pitts Computer Laboratory LICS 2015 Tutorial 2/27 An introduction to nominal techniques motivated by Programming language semantics Automata theory Constructive

More information

Operational reasoning for functions with local state

Operational reasoning for functions with local state Operational reasoning for functions with local state Andrew Pitts and Ian Stark Abstract Languages such as ML or Lisp permit the use of recursively defined function expressions with locally declared storage

More information

Inducing syntactic cut-elimination for indexed nested sequents

Inducing syntactic cut-elimination for indexed nested sequents Inducing syntactic cut-elimination for indexed nested sequents Revantha Ramanayake Technische Universität Wien (Austria) IJCAR 2016 June 28, 2016 Revantha Ramanayake (TU Wien) Inducing syntactic cut-elimination

More information

Structure. Background. them to their higher order equivalents. functionals in Standard ML source code and converts

Structure. Background. them to their higher order equivalents. functionals in Standard ML source code and converts Introduction 3 Background functionals factor out common behaviour map applies a function to every element of a list fun map [ ] = [ ] map f ( x : : xs ) = f x : : map f xs filter keeps only those elements

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

A Modular Rewriting Semantics for CML

A Modular Rewriting Semantics for CML A Modular Rewriting Semantics for CML Fabricio Chalub Barbosa do Rosário frosario@ic.uff.br 19 de março de 2004 0-0 Outline A closer look at MSOS Mapping MSOS to MRS Executing and model checking CML programs

More information

Deriving structural labelled transitions for mobile ambients

Deriving structural labelled transitions for mobile ambients Deriving structural labelled transitions for mobile ambients Julian Rathke, awe l Sobociński,1 ECS, University of Southampton Abstract We present a new labelled transition system (lts) for the ambient

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

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

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

Semantics and Generative Grammar. Quantificational DPs, Part 2: Quantificational DPs in Non-Subject Position and Pronominal Binding 1

Semantics and Generative Grammar. Quantificational DPs, Part 2: Quantificational DPs in Non-Subject Position and Pronominal Binding 1 Quantificational DPs, Part 2: Quantificational DPs in Non-Subject Position and Pronominal Binding 1 1. Introduction (1) Our Current System a. The Ds no, some, and every are type (Quantificational

More information

First class reflection for shorter proofs

First class reflection for shorter proofs First class reflection for shorter proofs Mathieu Boespflug McGill University 20 January 2012 Plan Part 1: Palindromes Part 2: higher-order programming Part 3: contextual programming Formal systems Example

More information

Functional Object Calculus

Functional Object Calculus Notations a, b Ter terms d D, e E iterators over some finite sets f, g, h F field names i, j, k N indices (usually i < j < k) l Loc locations m, m d, m e M method names u, v, w Val values x, y, z Var variables

More information

Mechanics of Static Analysis

Mechanics of Static Analysis Escuela 03 III / 1 Mechanics of Static Analysis David Schmidt Kansas State University www.cis.ksu.edu/~schmidt Escuela 03 III / 2 Outline 1. Small-step semantics: trace generation 2. State generation and

More information

Type Systems Winter Semester 2006

Type Systems Winter Semester 2006 Type Systems Winter Semester 2006 Week 7 November 29 November 29, 2006 - version 1.0 Plan PREVIOUSLY: 1. type safety as progress and preservation 2. typed arithmetic expressions 3. simply typed lambda

More information

Contextual equivalence

Contextual equivalence Techniques 16/22 ACS L16, lecture 2 4/10 Contextual equivalence Two phrases of a programming language are ( Morris style ) contextually equivalent ( = ctx ) if occurrences of the first phrase in any program

More information

Predicate Logic. Xinyu Feng 11/20/2013. University of Science and Technology of China (USTC)

Predicate Logic. Xinyu Feng 11/20/2013. University of Science and Technology of China (USTC) University of Science and Technology of China (USTC) 11/20/2013 Overview Predicate logic over integer expressions: a language of logical assertions, for example x. x + 0 = x Why discuss predicate logic?

More information

564 Lecture 25 Nov. 23, Continuing note on presuppositional vs. nonpresuppositional dets.

564 Lecture 25 Nov. 23, Continuing note on presuppositional vs. nonpresuppositional dets. 564 Lecture 25 Nov. 23, 1999 1 Continuing note on presuppositional vs. nonpresuppositional dets. Here's the argument about the nonpresupp vs. presupp analysis of "every" that I couldn't reconstruct last

More information

CBV and CBN. Eduardo Bonelli. TP para LP 2012C1 1/55

CBV and CBN. Eduardo Bonelli. TP para LP 2012C1 1/55 CBV and CBN Eduardo Bonelli TP para LP 2012C1 1/55 Reduction Strategies Call-By-Value Call-by-Name Relating CBN and CBV λ-calculus Continuation Passing Style Bibliography 2/55 Reduction Strategies Reduction

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

Verifying Relational Properties of Functional Programs by First-Order Refinement

Verifying Relational Properties of Functional Programs by First-Order Refinement Verifying Relational Properties of Functional Programs by First-Order Refinement Kazuyuki Asada a, Ryosuke Sato a, Naoki Kobayashi a a University of okyo Abstract Much progress has been made recently on

More information

Techniques. Contextual equivalence

Techniques. Contextual equivalence Techniques 16/22 Contextual equivalence Two phrases of a programming language are ( Morris style ) contextually equivalent ( = ctx )if occurrences of the first phrase in any program can be replaced by

More information

A bisimulation for dynamic sealing

A bisimulation for dynamic sealing Theoretical Computer Science 375 (2007) 169 192 www.elsevier.com/locate/tcs A bisimulation for dynamic sealing Eijiro Sumii a,, enjamin C. Pierce b a Graduate School of Information Sciences, Tohoku University,

More information

Axiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE

Axiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE Axiomatic Semantics Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE 6341 1 Outline Introduction What are axiomatic semantics? First-order logic & assertions about states Results (triples)

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

An Introduction to Z3

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

More information

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC)

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC) University of Science and Technology of China (USTC) 09/26/2011 Overview Predicate logic over integer expressions: a language of logical assertions, for example x. x + 0 = x Why discuss predicate logic?

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

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

Contracts made manifest

Contracts made manifest JFP: page 1 of 50. c Cambridge University Press 2012 doi:10.1017/s0956796812000135 1 Contracts made manifest MICHAEL GREENBERG, BENJAMIN C. PIERCE and STEPHANIE WEIRICH University of Pennsylvania, Philadelphia,

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lecture 03 Theoretical Foundations 1 Domains Semantic model of a data type: semantic domain! Examples: Integer, Natural, Truth-Value Domains D are more than a set of

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

Contracts Made Manifest

Contracts Made Manifest University of Pennsylvania ScholarlyCommons Departmental Papers (CIS) Department of Computer & Information Science 5-1-2012 Contracts Made Manifest Michael Greenberg University of Pennsylvania Benjamin

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

INTRODUCTION TO PREDICATE LOGIC HUTH AND RYAN 2.1, 2.2, 2.4

INTRODUCTION TO PREDICATE LOGIC HUTH AND RYAN 2.1, 2.2, 2.4 INTRODUCTION TO PREDICATE LOGIC HUTH AND RYAN 2.1, 2.2, 2.4 Neil D. Jones DIKU 2005 Some slides today new, some based on logic 2004 (Nils Andersen), some based on kernebegreber (NJ 2005) PREDICATE LOGIC:

More information

Subtyping and Intersection Types Revisited

Subtyping and Intersection Types Revisited Subtyping and Intersection Types Revisited Frank Pfenning Carnegie Mellon University International Conference on Functional Programming (ICFP 07) Freiburg, Germany, October 1-3, 2007 Joint work with Rowan

More information

Functional Big-step Semantics

Functional Big-step Semantics Functional Big-step Semantics FM talk, 11 Mar 2015 Magnus Myréen Books Big-step semantics are defined as inductively defined relation. Functions are better! me Context: CakeML verified compiler Old compiler:

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

Modal Proofs As Distributed Programs

Modal Proofs As Distributed Programs Modal Proofs As Distributed Programs Limin Jia David Walker Princeton University August 31, 2003 Abstract We develop a new foundation for distributed programming languages by defining an intuitionistic,

More information

Elaborating evaluation-order polymorphism

Elaborating evaluation-order polymorphism Elaborating evaluation-order polymorphism Joshua Dunfield University of British Columbia ICFP 2015 1 (prologue) ICFP in Canada for the first time since 2008 2 (prologue) ICFP in Canada for the first time

More information