Organization of Programming Languages

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 4 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Substitution & Evaluation Order cos 441 David Walker.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
1 Dependent Types for Termination Verification Hongwei Xi University of Cincinnati.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
Termination Analysis Math Foundations of Computer Science.
1 CPS Transform for Dependent ML Hongwei Xi University of Cincinnati and Carsten Schürmann Yale University.
6. Introduction to the Lambda Calculus. © O. Nierstrasz PS — Introduction to the Lambda Calculus 6.2 Roadmap  What is Computability? — Church’s Thesis.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Misc. Announcements Assignment available end of the day today –Due back in 11/03 (after break) Will also update slides on website –Today Midterm next week.
TR1413: INTRO TO DISCRETE MATHEMATICS LECTURE 2: MATHEMATICAL INDUCTION.
MinML: an idealized programming language CS 510 David Walker.
1 Semantics Q S EMANTICS (Q1,’07) Week 4 Jacob Andersen PhD student
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Tim Sheard Oregon Graduate Institute Lecture 11: A Reduction Semantics for MetaML CS510 Section FSC Winter 2005 Winter 2005.
Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
9.4 Mathematical Induction
Lesson 4 Typed Arithmetic Typed Lambda Calculus 1/21/02 Chapters 8, 9, 10.
Type Safety Kangwon National University 임현승 Programming Languages.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L06-1 September 26, 2006http:// Type Inference September.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
Types and Programming Languages Lecture 12 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
October 3, 2001CSE 373, Autumn Mathematical Background Exponents X A X B = X A+B X A / X B = X A-B (X A ) B = X AB X N +X N = 2X N 2 N +2 N = 2 N+1.
Types and Programming Languages
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
Definition of Limit, Properties of Limits Section 2.1a.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
CMSC 330: Organization of Programming Languages Operational Semantics.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L03-1 September 14, 2006http:// -calculus: A Basis for.
Chapter 2: Lambda Calculus
CS5205: Foundations in Programming Languages
CS 550 Programming Languages Jeremy Johnson
CSE-321 Programming Languages Simply Typed -Calculus
Carlos Varela Rennselaer Polytechnic Institute September 5, 2017
CS 611: Lecture 9 More Lambda Calculus: Recursion, Scope, and Substitution September 17, 1999 Cornell University Computer Science Department Andrew Myers.
Env. Model Implementation
Lesson 4 Typed Arithmetic Typed Lambda Calculus
Typed Arithmetic Expressions
Carlos Varela Rennselaer Polytechnic Institute September 6, 2016
Carlos Varela Rennselaer Polytechnic Institute September 4, 2015
Programming Languages and Compilers (CS 421)
Carlos Varela Rennselaer Polytechnic Institute September 8, 2017
Organization of Programming Languages (Final Review)
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Computer Security: Art and Science, 2nd Edition
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Copyright © Cengage Learning. All rights reserved.
Program correctness Axiomatic semantics
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Programming Languages Dan Grossman 2013
Carlos Varela Rennselaer Polytechnic Institute September 8, 2015
Relating Static and Dynamic Semantics
Carlos Varela Rennselaer Polytechnic Institute September 6, 2019
Carlos Varela Rennselaer Polytechnic Institute September 10, 2019
Presentation transcript:

Organization of Programming Languages (Midterm Review) Hongwei Xi 2/16/2019 Hongwei Xi

Inductive Reasoning Mathematical Induction Base step: establishing P(0) Inductive Step: establishing that P(n) implies P(n+1) for every natural number n Conclusion: P(n) holds for every natural number n 2/16/2019 Hongwei Xi

Inductive Reasoning Inductive definition Rule based Each rule has one conclusion and finitely many (possibly zero) premisses 2/16/2019 Hongwei Xi

Inductive Reasoning Structural Induction Proving properties on inductively defined structures Inductive step: establishing P for a term t while assuming that P holds for each *immediate* substructure of t 2/16/2019 Hongwei Xi

UFPL An Untyped Functional Programming Language Booleans b := true | false Integers i := . . . | -2 | -1 | 0 |1 | 2 | . . . Expressions e := x | b | I | op (e1,…, en) | if e then e1 else e2 fi | <> | <e1, e2> | fst(e) | snd (e) | fun f(x) is e | app(e1, e2) | let x = e1 in e2 end 2/16/2019 Hongwei Xi

UFPL Free variables: FV(e) Bound variables: Substitution: fun f(x) is e let x = e1 in e2 end Substitution: Protect bound variables from being substituted for Avoid capturing free variables 2/16/2019 Hongwei Xi

UFPL alpha-conversion fun f(x) is e  fun f’(x’) is e[f->f’][x->x’] let x = e1 in e2 end  let x’ = e1 in e2[x->x’] end Values v := x | b | i | <> | <v, v> | fun f(x) is v 2/16/2019 Hongwei Xi

UFPL Dynamic Semantics Evaluation Semantics (big-step) Presentation is straightforward Cannot distinguish non-termination from type errors Not suitable for compilation Reduction Semantics (small-step) Presentation is more involved Can distinguish non-termination from type errors Can lead to efficient implementation 2/16/2019 Hongwei Xi

UFPL: Evaluation Semantics Evaluation Rules ------- ----- b | b i | i e1 | v1 … en | vn op (v1,…,vn) = v ----------------------------------- op (e1,…,en) | v 2/16/2019 Hongwei Xi

UFPL: Evaluation Semantics Evaluation Rules e | true e1 | v --------------------------- if e then e1 else e2 fi | v e | false e2 | v --------------------------- if e then e1 else e2 fi | v 2/16/2019 Hongwei Xi

UFPL: Evaluation Semantics Evaluation Rules e1 | v1 e2 | v2 -------- ------------------ <> | <> <e1, e2> | <v1, v2> e | <v1, v2> e | <v1, v2> ------------ ------------ fst(e) | v1 snd(e) | v2 2/16/2019 Hongwei Xi

UFPL: Evaluation Semantics Evaluation Rules -------------------------------- fun f(x) is e | fun f(x) is e e1 | fun f(x) is e e2 | v2 e[f -> fun f(x) is e, x -> v2] ------------------------------- app(e1, e2) | v 2/16/2019 Hongwei Xi

UFPL: Evaluation Semantics Evaluation Rules e1 | v1 e2[x -> v1] --------------------------- let x = e1 in e2 end | v 2/16/2019 Hongwei Xi

UFPL: Reduction Semantics Redexes: op(v1,…,vn) -> v (v is the result of op(v1,…,vn)) if true then e1 else e2 fi -> e1 if false then e1 else e2 fi -> e2 fst(<v1, v2>) -> v1 snd(<v1, v2>) -> v2 2/16/2019 Hongwei Xi

UFPL: Reduction Semantics Redexes: app(fun f(x) is e, v) -> e[f -> fun f(x) is e, x -> v] let x = v in e end -> e[x -> v] 2/16/2019 Hongwei Xi

UFPL: Reduction Semantics Evaluation Contexts E := [] | op (v,…,v,E, e1,…,en) | if E then e else e | <E, e> | <v, E> | fst(E) | snd(E) | app(E, e) | app(v, E) | let x=E in e end e1 -> e2 if e1 = E[r] and e2 = E[e], where e is the reduction of r. 2/16/2019 Hongwei Xi

UFPL: Reduction Semantics Splitting: (E, r) is a splitting of e if E[r] = e. A value cannot have a splitting Each expression can have at most one splitting Many-step reduction ->*: e | v if and only if e ->* v 2/16/2019 Hongwei Xi

TFPL Typed functional programming language Types tau := bool | int | unit | tau * tau | tau -> tau Expressions e := … | fun f(x:tau):tau is e Type erasure: |e| is the result from erasing all the types in e 2/16/2019 Hongwei Xi

TFPL Dynamic Semantics Types are needed to be carried around during evaluation and reduction Types are indifferent to evaluation and reduction: e | v if and only if |e| | |v| e ->* v if and only if |e| ->* |v| 2/16/2019 Hongwei Xi

TFPL: Static Semantics Typing rules: ---------------------- Gamma |- b : bool --------------------- Gamma |- i : int Gamma(x) = tau ---------------------- Gamma |- x : tau 2/16/2019 Hongwei Xi

TFPL: Static Semantics Typing rules: Sigma(op) = tau1 * … * taun -> tau Gamma |- e1: tau1 … Gamma |- en : taun --------------------------------------------- Gamma |- op(e1,…,en) : tau ----------------- Gamma |- <> : 1 2/16/2019 Hongwei Xi

TFPL: Static Semantics Typing rules: Gamma |- e: bool Gamma |- e1: tau Gamma |- e2: tau --------------------------------------------- Gamma |- if e then e1 else e2 fi: tau Gamma |- e1: tau1 Gamma |- e2: tau2 ----------------------------------------------- Gamma |- <e1, e2>: tau1 * tau2 2/16/2019 Hongwei Xi

TFPL: Static Semantics Typing rules: Gamma |- e: tau1 * tau2 ------------------------------- Gamma |- fst(e): tau1 Gamma |- e: tau1 * tau2 ------------------------------- Gamma |- snd(e): tau2 2/16/2019 Hongwei Xi

TFPL: Static Semantics Typing rules: Gamma, f:tau1 -> tau2, x: tau1 |- e: tau2 -------------------------------------------- Gamma |- fun f(x) is e: tau1 -> tau2 Gamma |- e1: tau1 -> tau2 Gamma |- e2: tau1 ----------------------------------------------- Gamma |- app(e1, e2): tau2 2/16/2019 Hongwei Xi

TFPL: Static Semantics Typing rules: Gamma |- e1: tau1 Gamma, x: tau1 |- e2: tau2 ----------------------------------------------- Gamma |- let x = e1 in e2 end: tau2 2/16/2019 Hongwei Xi

TFPL Subject Reduction: If Gamma |- e1: tau is derivable and e1 -> e2 holds, then Gamma |- e2: tau is also derivable. Type Preservation: If Gamma |- e: tau is derivable and e | v holds, then Gamma |- v: tau is also derivable. 2/16/2019 Hongwei Xi

TFPL Progress Theorem: Suppose that |- e: tau is derivable. Then e is either a value or e -> e’ holds for some e’. Milner’s Slogan: Well-typed Programs can never go wrong! 2/16/2019 Hongwei Xi