Softwaretechnik. Lecture 03: Types and Type Soundness. Peter Thiemann. University of Freiburg, Germany SS 2008

Size: px
Start display at page:

Download "Softwaretechnik. Lecture 03: Types and Type Soundness. Peter Thiemann. University of Freiburg, Germany SS 2008"

Transcription

1 Softwaretechnik Lecture 03: Types and Type Soundness Peter Thiemann University of Freiburg, Germany SS 2008 Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 1 / 35

2 Table of Contents Types and Type correctness JAUS: Java-Expressions (Ausdrücke) Evaluation of expressions Type correctness Result Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 2 / 35

3 Types and Type correctness big software systems : many involved people project manager, designer, programmer,... essential : divide into components with clear defined interfaces and specifications How to divide the problem? How to divide the work? How to divide the tests? problems Are suitable libraries available? Do the components match each other? Do the components fulfill their specification? Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 3 / 35

4 Requirements Programming language/-environment has to ensure: each component implements their interfaces the implementation fulfills the specification each component is used correctly Main Problem : meet the interfaces and specifications: simplest interface : management of names Which operations does the component offer? simplest specification: types Which types do the arguments and the result of the operations have? see interfaces in Java Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 4 / 35

5 Questions Which kind of security do types provide? Which kind of errors can be detected by using types? How do we provide type safety? How can we formalize type safety? Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 5 / 35

6 JAUS: Java-Expressions (Ausdrücke) JAUS: Java-Expressions (Ausdrücke) The language specifies a subset of Java expressions x ::=... variables n ::= numbers b ::= true false truth values e ::= x n b e+e!e expressions Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 6 / 35

7 JAUS: Java-Expressions (Ausdrücke) Correct and incorrect expressions type correct expressions boolean flag;... 0 true 17+4!flag expressions with type errors int rain since April20; boolean flag;...!rain since April20 flag+1 17+(!false)!(2+3) Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 7 / 35

8 JAUS: Java-Expressions (Ausdrücke) Typing Rules for each kind of expression there exists a typing rule, that defines: if an expression is type correct how to obtain the result type of the expression from the types of the subexpressions. five kinds of expressions (at first using words): Constant numbers have type int. truth values have type boolean. The expression e 1 +e 2 has type int, if e 1 and e 2 have type int. The expression!e has type boolean, if e has type boolean. A variable x has the type, with which it was declared. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 8 / 35

9 JAUS: Java-Expressions (Ausdrücke) Formalization of type correct expressions The language of types t ::= int boolean types Type judgment : expression e has type t e : t Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 9 / 35

10 JAUS: Java-Expressions (Ausdrücke) Formalization of Typing rules A type judgment is valid, if it is derivable according to the typing rules. To infer a valid type judgment J we use a deduction system. A deduction system consists of a set of type judgments and a set of typing rules. A typing rule (inference rule) is a pair (J 1... J n, J 0 ) which consists of a list of judgments (assumptions, J 1... J n ) and a judgment (conclusion, J 0 ) that is written as If n = 0, a rule (ε, J 0 ) is an axiom. J 1... J n J 0 Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 10 / 35

11 JAUS: Java-Expressions (Ausdrücke) Example: typing rules for JAUS numbers n has type int. (INT) truth values has type boolean. n : int (BOOL) b : boolean an expression e 1 +e 2 has type int if e 1 and e 2 has type int. (ADD) e 1 : int e 2 : int e 1 +e 2 : int an expression!e has type boolean, if e has type boolean. (NOT) e : boolean!e : boolean Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 11 / 35

12 JAUS: Java-Expressions (Ausdrücke) Derivation trees and validity A judgment is valid if a suitable derivation tree exists. A derivation tree for the judgment J is defined by J, if is an axiom J J 1... J n J, if 1... J n J J suitable for J k. is a rule and each J k is a derivation tree Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 12 / 35

13 JAUS: Java-Expressions (Ausdrücke) Example: derivation trees (INT) 0 : int is a derivation tree with judgment 0 : int. (BOOL) true : boolean is a derivation tree for true : boolean. The judgment : int holds, because of the derivation tree (ADD) (INT) (INT) 17 : int : int 4 : int Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 13 / 35

14 JAUS: Java-Expressions (Ausdrücke) Variable Programs declare variables Programs use them according to the declaration Declarations are collected in a type environment. A ::= A, x : t type environment An extended type judgment contains a type environment: The expression e has the type t in the type environment A. A e : t typing rule for variables: A variable has the type, with which it is declared. (VAR) x : t A A x : t Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 14 / 35

15 JAUS: Java-Expressions (Ausdrücke) Extension of the remaining typing rules The typing rules forward the environment. (INT) A n : int (BOOL) A b : int (ADD) A e 1 : int A e 2 : int A e 1 +e 2 : int (NOT) A!e : boolean A e : boolean Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 15 / 35

16 JAUS: Java-Expressions (Ausdrücke) Example: derivation with variable The declaration boolean flag; matches the type assumption A =, flag : boolean Hence flag : boolean A A flag : boolean A! flag : boolean Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 16 / 35

17 JAUS: Java-Expressions (Ausdrücke) Intermediate result Formal system for syntax of expressions and types (CFG, BNF) type judgments validity of type judgments Open Questions How to evaluate expressions? coherence between evaluation and type judgments Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 17 / 35

18 Evaluation of expressions Evaluation of expressions Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 18 / 35

19 Evaluation of expressions (One possible) Approach Define a binary reduction relation e e over expressions e is in relation to e (e e ) if one computational step leads from e to e. example: (5+2) Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 19 / 35

20 Evaluation of expressions Result of computations A value v is a number or a truth value. An expression can reach a value in many steps: 0 steps: 0 1 step: steps: (5+2) but! false (1+2)+false 3+false These expressions can not perform a reduction step. They correspond to runtime errors. Observation: these errors are type errors! Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 20 / 35

21 Evaluation of expressions Formalization: results and reduction steps A value is a number or a truth value. v ::= n b values one reduction step If the two operands are number, we can add the two numbers to obtain a number as result. (B-ADD) n1 + n 2 n 1 + n 2 n represents the syntactic representation of the number n. If the operand of a negation is a truth value, the negation can be performed. (B-TRUE)!true false (B-FALSE)!false true Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 21 / 35

22 Evaluation of expressions Formalization: nested expressions What happens if the operands of operations are not values? At first evaluate the subexpressions. The negation addition, first operand (B-NEG) e e!e!e (B-ADD-L) e 1 e 1 e 1 +e 2 e 1 +e 2 addition, second operand (only evaluate the second, if the first is a value) e e (B-ADD-R) v+e v+e Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 22 / 35

23 Evaluation of expressions Variable An expression that contains variables cannot be evaluated with the reduction steps. But we can eliminate the variable using substitution. This replaces the variable with a value, and then reduction is possible. Apply a substitution [v 1 /x 1,... v n /x n ] to an expression e, written as e[v 1 /x 1,... v n /x n ] changes in e each occurrence of x i to the corresponding value v i. example: (!flag)[false/flag]!false (m+n)[25/m, 17/n] Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 23 / 35

24 Type correctness Type correctness informally Type correctness: If there exists a type for an expression e, then e evaluates to a value in a finite number of steps. In particular, no runtime error happens. For the language JAUS the converse also holds (this is not correct in general, like in full Java) Prove in two steps (after Wright and Felleisen) Assume e has a type, then it holds: Progress: Either e is a value or there exists a reduction step for e. Preservation: If e e, then e and e have the same types. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 24 / 35

25 Type correctness Progress If e : t is derivable, then e is a value or there exists e with e e. Prove Induction over the derivation tree of J = e : t. If (INT) n : int is the final step of J, then e n is a value (and t int). If (BOOL) b : boolean is the last step of J, then e b is a value (and t boolean). Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 25 / 35

26 Type correctness Progress: Addition If (ADD) e 1 : int e 2 : int is the final step of J, then it holds e 1 +e 2 : int that e e 1 +e 2 and t int. Moreover, it is derivable that e 1 : int and e 2 : int. The induction hypothesis tells us that e 1 is a value or there exists an e 1 with e 1 e 1. If e 1 e 1 holds, we obtain that e e 1+e 2 e e 1 +e 2 cause of rule (B-ADD-L). This is the desired result. In the case e 1 v 1 is a value, we concentrate on e 2 : int. The induction hypothesis says that e 2 is either a value or there exists an e 2 with e 2 e 2. In the second case we can use rule (B-ADD-R) and get: e v 1 +e 2 e v 1 +e 2. In the first case (e 2 = v 1 ), we can prove easily that v 1 n 1 and v 2 n 2 are both numbers. Hence, we can apply the rule (B-ADD) and obtain the desired e. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 26 / 35

27 Type correctness Progress: Negation e If (NOT) 1 : boolean!e 1 : boolean is the last step of J, it holds that e!e 1 and t boolean and e 1 : boolean is derivable. Using the induction hypothesis (e 1 is a value or there exists e with e e ) there are two cases. In the case that e 1 e 1, we conclude that there exists e with e e using rule (B-NEG). If e 1 v is a value, it s easy to prove that v is a truth value. Hence, we can apply the rule (B-TRUE) or (B-FALSE). QED Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 27 / 35

28 Type correctness Preservation If e : t and e e, then e : t. Prove Induction on the derivation e e. If (B-ADD) is the reduction step, then it n1 + n 2 n 1 + n 2 holds that t int because of (ADD). We can apply (INT) to e = n 1 + n 2 and obtain the desired result n 1 + n 2 : int. If (B-TRUE)!true false is the reduction step it holds that t boolean because of (NOT). We can apply (BOOL) to e = false and get the desired result false : boolean. The case for rule B-FALSE is analoguous. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 28 / 35

29 Type correctness Preservation: Addition e If (B-ADD-L) 1 e 1 e 1 +e 2 e 1 +e 2 obtain through e : t that is the occasion for the last step, we (ADD) e 1 : int e 2 : int e 1 +e 2 : int holds with e e 1 +e 2 and t int. From e 1 : int and e 1 e 1 it follows by induction that e 1 : int holds. Another application of (ADD) on e 1 : int and e 2 : int yields e 1 +e 2 : int. The case of rule (B-ADD-R) is analoguous. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 29 / 35

30 Type correctness Preservation: Negation e If (B-NEG) 1 e 1!e 1!e 1 is the occasion for the last step, we get through e : t, that (NOT) e 1 : boolean!e 1 : boolean holds with e!e 1 and t boolean. From e 1 : boolean and e 1 e 1 we conclude (using induction) that e 1 : boolean holds. Another application of rule (NOT) to e 1 : boolean yields!e 1 : boolean. QED Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 30 / 35

31 Type correctness Elimination of variables throw substitution Intention If x 1 : t 1,..., x n : t n e : t and v i : t i (for all i), then it holds e[v 1 /x 1,..., v 1 /x 1 ] : t. Assertion If A, x 0 : t 0 e : t and A e 0 : t 0, then it holds A e[e 0 /x 0 ] : t. Prove Induction over derivation of A e : t with A A, x 0 : t 0. If (VAR) x : t A is the latest step of the derivation, there are two A x : t cases: Either x x 0 or not. If x x 0 holds, then e[e 0 /x 0 ] e 0. Because of the rule (VAR) is holds t t 0. Hence it holds A e 0 : t 0 (use the assumption). If x x 0, then e[e 0 /x 0 ] x and it holds x : t A. Due to (VAR) it holds A x : t. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 31 / 35

32 Type correctness Substitution: Constants If (INT) is the latest step, it holds (INT) A n : int A n : int. If (BOOL) is the latest step, it holds A b : boolean (BOOL) A b : boolean. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 32 / 35

33 Type correctness Substitution: Addition If (ADD) A e 1 : int A e 2 : int is the latest step, then the A e 1 +e 2 : int induction hypothesis yields A e 1 [e 0 /x 0 ] : int and A e 2 [e 0 /x 0 ] : int. Apply rule (ADD) yields A (e 1 +e 2 )[e 0 /x 0 ] : int. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 33 / 35

34 Type correctness Substitution: Negation A e If (NOT) 1 : boolean is the latest step, the induction hypothesis A!e 1 : boolean yields A e 1 [e 0 /x 0 ] : boolean. Apply rule (NOT) yields A (!e 1 )[e 0 /x 0 ] : boolean. QED Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 34 / 35

35 Result Theorem: Soundness of JAUS If e : t, then there exists a value v with v : t and reduction steps with e e 0 and e n v. e 0 e 1, e 1 e 2,..., e n 1 e n If e contains variables, then we have to substitute them with suitable values (choose values with same types as the variables). Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 35 / 35

Contents. Softwaretechnik. Type Safety of Java. Featherweight Java. Lecture 21: Featherweight Java

Contents. Softwaretechnik. Type Safety of Java. Featherweight Java. Lecture 21: Featherweight Java Contents Softwaretechnik Lecture 21: Peter Thiemann Universität Freiburg, Germany Operational Semantics SS 2011 Peter Thiemann (Univ. Freiburg) Softwaretechnik (english draft) SWT 1 / 40 Type Safety of

More information

Softwaretechnik. Lecture 18: Featherweight Java. Peter Thiemann. University of Freiburg, Germany

Softwaretechnik. Lecture 18: Featherweight Java. Peter Thiemann. University of Freiburg, Germany Softwaretechnik Lecture 18: Peter Thiemann University of Freiburg, Germany 19.07.2012 Peter Thiemann (Univ. Freiburg) Softwaretechnik 19.07.2012 1 / 40 Contents The language shown in examples Formal Definition

More information

COS 320. Compiling Techniques

COS 320. Compiling Techniques Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly

More information

The Substitution Model

The Substitution Model The Substitution Model Prof. Clarkson Fall 2017 Today s music: Substitute by The Who Review Previously in 3110: simple interpreter for expression language abstract syntax tree (AST) evaluation based on

More information

Formal Semantics. Prof. Clarkson Fall Today s music: Down to Earth by Peter Gabriel from the WALL-E soundtrack

Formal Semantics. Prof. Clarkson Fall Today s music: Down to Earth by Peter Gabriel from the WALL-E soundtrack Formal Semantics Prof. Clarkson Fall 2015 Today s music: Down to Earth by Peter Gabriel from the WALL-E soundtrack Review Previously in 3110: simple interpreter for expression language: abstract syntax

More information

Software Engineering

Software Engineering Software Engineering Lecture 18: Featherweight Java Peter Thiemann University of Freiburg, Germany 15.07.2013 Peter Thiemann (Univ. Freiburg) Software Engineering 15.07.2013 1 / 41 Contents Featherweight

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 19 Tuesday, April 3, 2018 1 Introduction to axiomatic semantics The idea in axiomatic semantics is to give specifications

More information

Boolean expressions. Elements of Programming Languages. Conditionals. What use is this?

Boolean expressions. Elements of Programming Languages. Conditionals. What use is this? Boolean expressions Elements of Programming Languages Lecture 3: Booleans, conditionals, and types James Cheney So far we ve considered only a trivial arithmetic language L Arith Let s extend L Arith with

More information

Programming Languages Fall 2014

Programming Languages Fall 2014 Programming Languages Fall 2014 Lecture 7: Simple Types and Simply-Typed Lambda Calculus Prof. Liang Huang huang@qc.cs.cuny.edu 1 Types stuck terms? how to fix it? 2 Plan First I For today, we ll go back

More information

The Substitution Model. Nate Foster Spring 2018

The Substitution Model. Nate Foster Spring 2018 The Substitution Model Nate Foster Spring 2018 Review Previously in 3110: simple interpreter for expression language abstract syntax tree (AST) evaluation based on single steps parser and lexer (in lab)

More information

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic

More information

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m. CS 6110 S18 Lecture 8 Structural Operational Semantics and IMP Today we introduce a very simple imperative language, IMP, along with two systems of rules for evaluation called small-step and big-step semantics.

More information

1 Introduction. 3 Syntax

1 Introduction. 3 Syntax CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,

More information

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End

More information

Induction and Semantics in Dafny

Induction and Semantics in Dafny 15-414 Lecture 11 1 Instructor: Matt Fredrikson Induction and Semantics in Dafny TA: Ryan Wagner Encoding the syntax of Imp Recall the abstract syntax of Imp: a AExp ::= n Z x Var a 1 + a 2 b BExp ::=

More information

Pierce Ch. 3, 8, 11, 15. Type Systems

Pierce Ch. 3, 8, 11, 15. Type Systems Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using

More information

Topic 6: Types COS 320. Compiling Techniques. Princeton University Spring Prof. David August. Adapted from slides by Aarne Ranta

Topic 6: Types COS 320. Compiling Techniques. Princeton University Spring Prof. David August. Adapted from slides by Aarne Ranta Topic 6: Types COS 320 Compiling Techniques Princeton University Spring 2015 Prof. David August 1 Adapted from slides by Aarne Ranta Types What is a type? Type Checking: Helps find language-level errors:

More information

CS4215 Programming Language Implementation. Martin Henz

CS4215 Programming Language Implementation. Martin Henz CS4215 Programming Language Implementation Martin Henz Thursday 26 January, 2012 2 Chapter 4 The Language simpl In this chapter, we are exting the language epl in order to provide a more powerful programming

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lesson 14 Type Checking Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Type Checking We return to the issue of type safety we discussed informally,

More information

Typed Lambda Calculus and Exception Handling

Typed Lambda Calculus and Exception Handling Typed Lambda Calculus and Exception Handling Dan Zingaro zingard@mcmaster.ca McMaster University Typed Lambda Calculus and Exception Handling p. 1/2 Untyped Lambda Calculus Goal is to introduce typing

More information

Lecture 15 CIS 341: COMPILERS

Lecture 15 CIS 341: COMPILERS Lecture 15 CIS 341: COMPILERS Announcements HW4: OAT v. 1.0 Parsing & basic code generation Due: March 28 th No lecture on Thursday, March 22 Dr. Z will be away Zdancewic CIS 341: Compilers 2 Adding Integers

More information

The three faces of homotopy type theory. Type theory and category theory. Minicourse plan. Typing judgments. Michael Shulman.

The three faces of homotopy type theory. Type theory and category theory. Minicourse plan. Typing judgments. Michael Shulman. The three faces of homotopy type theory Type theory and category theory Michael Shulman 1 A programming language. 2 A foundation for mathematics based on homotopy theory. 3 A calculus for (, 1)-category

More information

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413 Type Inference Systems CS412/CS413 Introduction to Compilers Tim Teitelbaum Type inference systems define types for all legal programs in a language Type inference systems are to type-checking: As regular

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language

More information

Lecture Notes on Computational Interpretations of Modalities

Lecture Notes on Computational Interpretations of Modalities Lecture Notes on Computational Interpretations of Modalities 15-816: Modal Logic Frank Pfenning Lecture 4 January 21, 2010 1 Introduction In this lecture we present the first two of many possible computational

More information

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 2.1-2.7 p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer

More information

Proving Theorems with Athena

Proving Theorems with Athena Proving Theorems with Athena David R. Musser Aytekin Vargun August 28, 2003, revised January 26, 2005 Contents 1 Introduction 1 2 Proofs about order relations 2 3 Proofs about natural numbers 7 3.1 Term

More information

Chapter 3 (part 3) Describing Syntax and Semantics

Chapter 3 (part 3) Describing Syntax and Semantics Chapter 3 (part 3) Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the Meanings

More information

Basic concepts. Chapter Toplevel loop

Basic concepts. Chapter Toplevel loop Chapter 3 Basic concepts We examine in this chapter some fundamental concepts which we will use and study in the following chapters. Some of them are specific to the interface with the Caml language (toplevel,

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 24 Thursday, April 19, 2018 1 Error-propagating semantics For the last few weeks, we have been studying type systems.

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 18 Thursday, April 3, 2014 1 Error-propagating semantics For the last few weeks, we have been studying type systems.

More information

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic 3.4 Deduction and Evaluation: Tools 3.4.1 Conditional-Equational Logic The general definition of a formal specification from above was based on the existence of a precisely defined semantics for the syntax

More information

(Not Quite) Minijava

(Not Quite) Minijava (Not Quite) Minijava CMCS22620, Spring 2004 April 5, 2004 1 Syntax program mainclass classdecl mainclass class identifier { public static void main ( String [] identifier ) block } classdecl class identifier

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

Mutable References. Chapter 1

Mutable References. Chapter 1 Chapter 1 Mutable References In the (typed or untyped) λ-calculus, or in pure functional languages, a variable is immutable in that once bound to a value as the result of a substitution, its contents never

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 7a Andrew Tolmach Portland State University 1994-2016 Values and Types We divide the universe of values according to types A type is a set of values and a

More information

Formal Semantics of Programming Languages

Formal Semantics of Programming Languages Formal Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html Benefits of formal

More information

3.2 Big-Step Structural Operational Semantics (Big-Step SOS)

3.2 Big-Step Structural Operational Semantics (Big-Step SOS) 3.2 Big-Step Structural Operational Semantics (Big-Step SOS) Known also under the names natural semantics, relational semantics, and evaluation semantics, big-step structural operational semantics, or

More information

A Type System for Functional Traversal-Based Aspects

A Type System for Functional Traversal-Based Aspects A Type System for Functional Traversal-Based Aspects Bryan Chadwick College of Computer & Information Science Northeastern University, 360 Huntington Avenue Boston, Massachusetts 02115 USA chadwick@ccs.neu.edu

More information

Programming Languages

Programming Languages CSE 230: Winter 2008 Principles of Programming Languages Ocaml/HW #3 Q-A Session Push deadline = Mar 10 Session Mon 3pm? Lecture 15: Type Systems Ranjit Jhala UC San Diego Why Typed Languages? Development

More information

Formal Semantics of Programming Languages

Formal Semantics of Programming Languages Formal Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html Benefits of formal

More information

Semantics. A. Demers Jan This material is primarily from Ch. 2 of the text. We present an imperative

Semantics. A. Demers Jan This material is primarily from Ch. 2 of the text. We present an imperative CS411 Notes 1: IMP and Large Step Operational Semantics A. Demers 23-25 Jan 2001 This material is primarily from Ch. 2 of the text. We present an imperative language called IMP; wegive a formal definition

More information

Costly software bugs that could have been averted with type checking

Costly software bugs that could have been averted with type checking Type Checking Class Notes from Lectures 6 and 7 Lahav Yeffet and Ori Folger The material in these lectures is based on the textbook Types and Programming Languages by Benjamin Pierce. Here is a list of

More information

Principles of AI Planning. Principles of AI Planning. 7.1 How to obtain a heuristic. 7.2 Relaxed planning tasks. 7.1 How to obtain a heuristic

Principles of AI Planning. Principles of AI Planning. 7.1 How to obtain a heuristic. 7.2 Relaxed planning tasks. 7.1 How to obtain a heuristic Principles of AI Planning June 8th, 2010 7. Planning as search: relaxed planning tasks Principles of AI Planning 7. Planning as search: relaxed planning tasks Malte Helmert and Bernhard Nebel 7.1 How to

More information

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany Softwaretechnik Lecture 08: Testing and Debugging Overview Peter Thiemann University of Freiburg, Germany SS 2012 Literature Essential Reading Why Programs Fail: A Guide to Systematic Debugging, A Zeller

More information

Operational Semantics 1 / 13

Operational Semantics 1 / 13 Operational Semantics 1 / 13 Outline What is semantics? Operational Semantics What is semantics? 2 / 13 What is the meaning of a program? Recall: aspects of a language syntax: the structure of its programs

More information

In Our Last Exciting Episode

In Our Last Exciting Episode In Our Last Exciting Episode #1 Lessons From Model Checking To find bugs, we need specifications What are some good specifications? To convert a program into a model, we need predicates/invariants and

More information

Fall Lecture 3 September 4. Stephen Brookes

Fall Lecture 3 September 4. Stephen Brookes 15-150 Fall 2018 Lecture 3 September 4 Stephen Brookes Today A brief remark about equality types Using patterns Specifying what a function does equality in ML e1 = e2 Only for expressions whose type is

More information

Last class. CS Principles of Programming Languages. Introduction. Outline

Last class. CS Principles of Programming Languages. Introduction. Outline Last class CS6848 - Principles of Programming Languages Principles of Programming Languages V. Krishna Nandivada IIT Madras Interpreters A Environment B Cells C Closures D Recursive environments E Interpreting

More information

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules. Outline Type Checking General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time

More information

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals Review CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics e ::= λx. e x ee c v ::= λx. e c (λx. e) v e[v/x] e 1 e 2 e 1 e 2 τ ::= int τ τ Γ ::= Γ,x : τ e 2 e 2 ve 2 ve 2 e[e /x]:

More information

Binary Decision Diagrams

Binary Decision Diagrams Logic and roof Hilary 2016 James Worrell Binary Decision Diagrams A propositional formula is determined up to logical equivalence by its truth table. If the formula has n variables then its truth table

More information

HOL DEFINING HIGHER ORDER LOGIC LAST TIME ON HOL CONTENT. Slide 3. Slide 1. Slide 4. Slide 2 WHAT IS HIGHER ORDER LOGIC? 2 LAST TIME ON HOL 1

HOL DEFINING HIGHER ORDER LOGIC LAST TIME ON HOL CONTENT. Slide 3. Slide 1. Slide 4. Slide 2 WHAT IS HIGHER ORDER LOGIC? 2 LAST TIME ON HOL 1 LAST TIME ON HOL Proof rules for propositional and predicate logic Safe and unsafe rules NICTA Advanced Course Forward Proof Slide 1 Theorem Proving Principles, Techniques, Applications Slide 3 The Epsilon

More information

An Annotated Language

An Annotated Language Hoare Logic An Annotated Language State and Semantics Expressions are interpreted as functions from states to the corresponding domain of interpretation Operators have the obvious interpretation Free of

More information

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference Type Checking Outline General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time

More information

CSE505, Fall 2012, Midterm Examination October 30, 2012

CSE505, Fall 2012, Midterm Examination October 30, 2012 CSE505, Fall 2012, Midterm Examination October 30, 2012 Rules: The exam is closed-book, closed-notes, except for one side of one 8.5x11in piece of paper. Please stop promptly at Noon. You can rip apart

More information

Behavioral Equivalence

Behavioral Equivalence Behavioral Equivalence Prof. Clarkson Fall 2016 Today s music: Soul Bossa Nova by Quincy Jones Review Previously in 3110: Functional programming Modular programming & software engineering Interpreters

More information

Programming Languages Lecture 14: Sum, Product, Recursive Types

Programming Languages Lecture 14: Sum, Product, Recursive Types CSE 230: Winter 200 Principles of Programming Languages Lecture 4: Sum, Product, Recursive Types The end is nigh HW 3 No HW 4 (= Final) Project (Meeting + Talk) Ranjit Jhala UC San Diego Recap Goal: Relate

More information

Lesson 4 Typed Arithmetic Typed Lambda Calculus

Lesson 4 Typed Arithmetic Typed Lambda Calculus Lesson 4 Typed Arithmetic Typed Lambda 1/28/03 Chapters 8, 9, 10 Outline Types for Arithmetic types the typing relation safety = progress + preservation The simply typed lambda calculus Function types

More information

CMSC 330: Organization of Programming Languages. OCaml Expressions and Functions

CMSC 330: Organization of Programming Languages. OCaml Expressions and Functions CMSC 330: Organization of Programming Languages OCaml Expressions and Functions CMSC330 Spring 2018 1 Lecture Presentation Style Our focus: semantics and idioms for OCaml Semantics is what the language

More information

Propositional Logic. Andreas Klappenecker

Propositional Logic. Andreas Klappenecker Propositional Logic Andreas Klappenecker Propositions A proposition is a declarative sentence that is either true or false (but not both). Examples: College Station is the capital of the USA. There are

More information

Behavioral Equivalence

Behavioral Equivalence Behavioral Equivalence Prof. Clarkson Fall 2015 Today s music: Soul Bossa Nova by Quincy Jones Review Previously in 3110: Functional programming Modular programming Interpreters Imperative and concurrent

More information

Computing Fundamentals 2 Introduction to CafeOBJ

Computing Fundamentals 2 Introduction to CafeOBJ Computing Fundamentals 2 Introduction to CafeOBJ Lecturer: Patrick Browne Lecture Room: K408 Lab Room: A308 Based on work by: Nakamura Masaki, João Pascoal Faria, Prof. Heinrich Hußmann. See notes on slides

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany Softwaretechnik Lecture 08: Testing and Debugging Overview Peter Thiemann University of Freiburg, Germany SS 2012 Literature Essential Reading Why Programs Fail: A Guide to Systematic Debugging, A Zeller

More information

Operational Semantics of Cool

Operational Semantics of Cool Operational Semantics of Cool Key Concepts semantics: the meaning of a program, what does program do? how the code is executed? operational semantics: high level code generation steps of calculating values

More information

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions): CS 70 Discrete Mathematics for CS Spring 2005 Clancy/Wagner Notes 7 This lecture returns to the topic of propositional logic. Whereas in Lecture Notes 1 we studied this topic as a way of understanding

More information

Formal Systems and their Applications

Formal Systems and their Applications Formal Systems and their Applications Dave Clarke (Dave.Clarke@cs.kuleuven.be) Acknowledgment: these slides are based in part on slides from Benjamin Pierce and Frank Piessens 1 Course Overview Introduction

More information

The Typed λ Calculus and Type Inferencing in ML

The Typed λ Calculus and Type Inferencing in ML Notes on Types S. Arun-Kumar Department of Computer Science and Engineering Indian Institute of Technology New Delhi, 110016 email: sak@cse.iitd.ernet.in April 14, 2002 2 Chapter 1 The Typed λ Calculus

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

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION Alessandro Artale UniBZ - http://www.inf.unibz.it/ artale/ SECTION 5.5 Application: Correctness of Algorithms Copyright Cengage Learning. All

More information

Typed Lambda Calculus. Chapter 9 Benjamin Pierce Types and Programming Languages

Typed Lambda Calculus. Chapter 9 Benjamin Pierce Types and Programming Languages Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages t ::= x x. t t t Call-by-value small step perational Semantics terms variable v ::= values abstraction x. t abstraction values

More information

Operational Semantics. One-Slide Summary. Lecture Outline

Operational Semantics. One-Slide Summary. Lecture Outline Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:

More information

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 Natural Semantics Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 1 Natural deduction is an instance of first-order logic; that is, it is the formal

More information

Gradual Typing for Functional Languages. Jeremy Siek and Walid Taha (presented by Lindsey Kuper)

Gradual Typing for Functional Languages. Jeremy Siek and Walid Taha (presented by Lindsey Kuper) Gradual Typing for Functional Languages Jeremy Siek and Walid Taha (presented by Lindsey Kuper) 1 Introduction 2 What we want Static and dynamic typing: both are useful! (If you re here, I assume you agree.)

More information

Checks and Balances - Constraint Solving without Surprises in Object-Constraint Programming Languages: Full Formal Development

Checks and Balances - Constraint Solving without Surprises in Object-Constraint Programming Languages: Full Formal Development Checks and Balances - Constraint Solving without Surprises in Object-Constraint Programming Languages: Full Formal Development Tim Felgentreff, Todd Millstein, Alan Borning and Robert Hirschfeld Viewpoints

More information

Intermediate Code Generation Part II

Intermediate Code Generation Part II Intermediate Code Generation Part II Chapter 6: Type checking, Control Flow Slides adapted from : Robert van Engelen, Florida State University Static versus Dynamic Checking Static checking: the compiler

More information

Type checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39

Type checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39 Type checking Jianguo Lu November 27, 2014 slides adapted from Sean Treichler and Alex Aiken s Jianguo Lu November 27, 2014 1 / 39 Outline 1 Language translation 2 Type checking 3 optimization Jianguo

More information

Computation Club: Gödel s theorem

Computation Club: Gödel s theorem Computation Club: Gödel s theorem The big picture mathematicians do a lot of reasoning and write a lot of proofs formal systems try to capture the ideas of reasoning and proof in a purely mechanical set

More information

Automated Reasoning. Natural Deduction in First-Order Logic

Automated Reasoning. Natural Deduction in First-Order Logic Automated Reasoning Natural Deduction in First-Order Logic Jacques Fleuriot Automated Reasoning Lecture 4, page 1 Problem Consider the following problem: Every person has a heart. George Bush is a person.

More information

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF Copyright Cengage Learning. All rights reserved. SECTION 4.6 Indirect Argument: Contradiction and Contraposition Copyright Cengage Learning. All

More information

Exercises on Semantics of Programming Languages

Exercises on Semantics of Programming Languages Technische Universität Wien SS 2014 Fakultät für Informatik Repetition sheet Assist. Prof. Florian Zuleger Tuesday, 8 April 2014 Assist. Prof. Georg Weissenbacher Univ. Prof. Agata Ciabattoni Moritz Sinn,

More information

Formal semantics of loosely typed languages. Joep Verkoelen Vincent Driessen

Formal semantics of loosely typed languages. Joep Verkoelen Vincent Driessen Formal semantics of loosely typed languages Joep Verkoelen Vincent Driessen June, 2004 ii Contents 1 Introduction 3 2 Syntax 5 2.1 Formalities.............................. 5 2.2 Example language LooselyWhile.................

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

NP-Completeness of 3SAT, 1-IN-3SAT and MAX 2SAT

NP-Completeness of 3SAT, 1-IN-3SAT and MAX 2SAT NP-Completeness of 3SAT, 1-IN-3SAT and MAX 2SAT 3SAT The 3SAT problem is the following. INSTANCE : Given a boolean expression E in conjunctive normal form (CNF) that is the conjunction of clauses, each

More information

AXIOMS FOR THE INTEGERS

AXIOMS FOR THE INTEGERS AXIOMS FOR THE INTEGERS BRIAN OSSERMAN We describe the set of axioms for the integers which we will use in the class. The axioms are almost the same as what is presented in Appendix A of the textbook,

More information

Subsumption. Principle of safe substitution

Subsumption. Principle of safe substitution Recap on Subtyping Subsumption Some types are better than others, in the sense that a value of one can always safely be used where a value of the other is expected. Which can be formalized as by introducing:

More information

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

4.5 Pure Linear Functional Programming

4.5 Pure Linear Functional Programming 4.5 Pure Linear Functional Programming 99 4.5 Pure Linear Functional Programming The linear λ-calculus developed in the preceding sections can serve as the basis for a programming language. The step from

More information

CS 242. Fundamentals. Reading: See last slide

CS 242. Fundamentals. Reading: See last slide CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

More information

c constructor P, Q terms used as propositions G, H hypotheses scope identifier for a notation scope M, module identifiers t, u arbitrary terms

c constructor P, Q terms used as propositions G, H hypotheses scope identifier for a notation scope M, module identifiers t, u arbitrary terms Coq quick reference Meta variables Usage Meta variables Usage c constructor P, Q terms used as propositions db identifier for a hint database s string G, H hypotheses scope identifier for a notation scope

More information

Coq quick reference. Category Example Description. Inductive type with instances defined by constructors, including y of type Y. Inductive X : Univ :=

Coq quick reference. Category Example Description. Inductive type with instances defined by constructors, including y of type Y. Inductive X : Univ := Coq quick reference Category Example Description Meta variables Usage Meta variables Usage c constructor P, Q terms used as propositions db identifier for a hint database s string G, H hypotheses scope

More information

Fundamental Concepts. Chapter 1

Fundamental Concepts. Chapter 1 Chapter 1 Fundamental Concepts This book is about the mathematical foundations of programming, with a special attention on computing with infinite objects. How can mathematics help in programming? There

More information

CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008

CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008 CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008 Contents 1 Solution to the Exercise 1 1.1 Semantics for lambda calculus.......................

More information

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 [talking head] Formal Methods of Software Engineering means the use of mathematics as an aid to writing programs. Before we can

More information

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus Types Type checking What is a type? The notion varies from language to language Consensus A set of values A set of operations on those values Classes are one instantiation of the modern notion of type

More information

Semantics. There is no single widely acceptable notation or formalism for describing semantics Operational Semantics

Semantics. There is no single widely acceptable notation or formalism for describing semantics Operational Semantics There is no single widely acceptable notation or formalism for describing semantics Operational Describe the meaning of a program by executing its statements on a machine, either simulated or actual. The

More information

Lecture Notes on Static Semantics

Lecture Notes on Static Semantics Lecture Notes on Static Semantics 15-411: Compiler Design Frank Pfenning Lecture 12 October 8, 2015 1 Introduction After lexing and parsing, a compiler will usually apply elaboration to translate the parse

More information

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 3: Induction Prof. Liang Huang huang@qc.cs.cuny.edu Recursive Data Types (trees) data Ast = ANum Integer APlus Ast Ast ATimes Ast Ast eval (ANum x) = x eval (ATimes

More information