Type Safety Kangwon National University 임현승 Programming Languages.

Slides:



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

Functional Programming Lecture 13 - induction on lists.
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Semantics Static semantics Dynamic semantics attribute grammars
Chapter Three: Closure Properties for Regular Languages
- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
© M. Winter COSC 4P41 – Functional Programming Testing vs Proving Testing –uses a set of “typical” examples, –symbolic testing, –may find errors,
Chapter 11 Proof by Induction. Induction and Recursion Two sides of the same coin.  Induction usually starts with small things, and then generalizes.
Functional Design and Programming Lecture 11: Functional reasoning.
Proving Facts About Programs With a Proof Assistant John Wallerius An Example From: Isabelle/HOL, A Proof Assistant for Higher Order Logic, By T. Nipkow,
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
CSE115/ENGR160 Discrete Mathematics 04/03/12 Ming-Hsuan Yang UC Merced 1.
0 PROGRAMMING IN HASKELL Chapter 6 - Recursive Functions.
Catriel Beeri Pls/Winter 2004/5 inductive-revisited 1 Inductive definitions revisited  Generated and Freely generated sets oPattern match, unification.
Catriel Beeri Pls/Winter 2004/05 types 65  A type-checking algorithm The task: (since we start with empty H, why is the goal not just E?) The rule set.
MinML: an idealized programming language CS 510 David Walker.
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Sparkle A theorem prover for the functional language Clean Maarten de Mol University of Nijmegen February 2002.
Type Inference David Walker CS 510, Fall Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs.
1 Section 3.3 Mathematical Induction. 2 Technique used extensively to prove results about large variety of discrete objects Can only be used to prove.
Algorithm Design and Analysis (ADA)
College Algebra Sixth Edition James Stewart Lothar Redlin Saleem Watson.
Discrete Maths Objective to introduce mathematical induction through examples , Semester 2, Mathematical Induction 1.
Induction Schemes Math Foundations of Computer Science.
Cs7120 (Prasad)L9-RECUR-IND1 Recursion and Induction.
Lesson 4 Typed Arithmetic Typed Lambda Calculus 1/21/02 Chapters 8, 9, 10.
CS 611: Lecture 6 Rule Induction September 8, 1999 Cornell University Computer Science Department Andrew Myers.
ELIMINATING LEFT RECURSIVENESS. Abbreviation. “cfg” stands for “context free grammar” Definition. A cfg is left recursive if it contains a production.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction Spring
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Chapter 3 Part II Describing Syntax and Semantics.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Types and Programming Languages Lecture 12 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of an FSA is easy for us to understand, but difficult.
(Finite) Mathematical Induction In our first lesson on sequences and series, you were told that How can we be certain that this will be true for all counting.
Chapter Integration of substitution and integration by parts of the definite integral.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.
Types and Programming Languages
Inductive Proofs Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
Inductive Definitions Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Cs466(Prasad)L6Proof1 Induction Proofs Equivalent Statements in Proofs.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Mathematical Induction I Lecture 5: Sep 20 (chapter of the textbook and chapter of the course notes)
CSE-321 Programming Languages Abstract Machine E POSTECH May 1, 2006 박성우.
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
1 Proving Properties of Recursive Functions and Data Structures CS 270 Math Foundations of CS Jeremy Johnson.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
CS5205: Foundations in Programming Languages
CSE-321 Programming Languages Simply Typed -Calculus
PROGRAMMING IN HASKELL
CSE 311 Foundations of Computing I
PROGRAMMING IN HASKELL
Programming Languages 2nd edition Tucker and Noonan
Lesson 4 Typed Arithmetic Typed Lambda Calculus
Proving Properties of Recursive List Functions
Typed Arithmetic Expressions
CSE 311: Foundations of Computing
Simplification of Boolean Expressions
Organization of Programming Languages
PROGRAMMING IN HASKELL
Recursion and Fixed-Point Theory
CSCE 314: Programming Languages Dr. Dylan Shell
Testing vs Proving Testing uses a set of “typical” examples,
Copyright © Cengage Learning. All rights reserved.
Proving Statements about Segments
Presentation transcript:

Type Safety Kangwon National University 임현승 Programming Languages

2 Abstract Syntax

3 Operational Semantics

4 Reduction Rules for Booleans

5 Typing Rules

6 Typing Rules for Booleans

7 Type Safety Slogan "well-typed expressions never go wrong" Two theorems –Type preservation: "A well-typed expression reduces to another expression of the same type." –Progress: "A well-typed expression does not get stuck: either it is a value or reduces to another expression."

8 Type Preservation + Progress A well-typed expression e : –If it is a value, we are finished. –If it is not, it reduces to another e' [Progress] e' has the same type as e.[Type preservation]

Inductive Proof Recap 9

Inductive Definition A technique of defining a set by specifying an element of the set using another element. Needs a base case. Starting from the base elements, builds more elements. –E.g., Recursively defined data structures such as lists and trees can be seen also inductively defined. –E.g., type ‘a list = Nil | Cons of ‘a * ‘a list 10

Inductive Proof A method of proving properties of recursive functions defined on inductively (or recursively) defined data structures. Apply natural (or structural) induction on the argument of the function # let rec fact n = if n = 0 then 1 else n * fact (n – 1) # let rec pow2 n = if n = 0 then 1 else 2 * pow2 (n – 1) Prove fact n >= pow2 nwhen n >= 4! 11

Proof of fact n >= pow2 n By mathematical induction on n Base case: n = 4 fact 4 >= pow2 4by simple calculation Inductive case: n = (k + 1) fact (k + 1) = (k + 1) * fact k by definition of fact >= (k + 1) * pow2 kby induction hypothesis > 2 * pow2 k by simple calculation = pow2 (k + 1)by definition of pow2 12

Proof by Structural Induction let rec concat xs ys = match xs with | [] -> ys | z :: zs -> z :: (concat zs ys) We obtain the following equations: Nil ++ ys = ys (x :: xs) ++ ys = x :: (xs ++ ys) Prove the identity of Nil and associativity of ++ : xs ++ Nil = xs Nil ++ xs = xs (xs ++ ys) ++ zs = xs ++ (ys ++ zs) Can be proved by structural induction on xs 13

Proof of xs ++ Nil = xs By structural induction on xs Base case: xs = Nil Nil ++ Nil = Nilby definition of ++ Inductive case: xs = z :: zs (z :: zs) ++ Nil = z :: (zs ++ Nil)by definition of ++ = z :: zsby induction hypothesis 14

(xs ++ ys) ++ zs = xs ++ (ys ++ zs) By structural induction on xs Base case: xs = Nil LHS: (Nil ++ ys) ++ zs = (ys) ++ zs by definition of ++ RHS: Nil ++ (ys ++ zs) = (ys ++ zs) by definition of ++ 15

Inductive Case: xs = v :: vs We can use induction hypothesis on vs LHS: ((v :: vs) ++ ys) ++ zs = (v :: (vs ++ ys)) ++ zsby definition of ++ = v :: ((vs ++ ys) ++ zs)by definition of ++ = v :: (vs ++ (ys ++ zs))by IH = (v :: vs) ++ (ys ++ zs)by definition of ++ : RHS This inductive reasoning can also be applied to judgments and inference rules as they also define a set in an inductive manner. 16

Back to the Type Safety 17

18 Type Safety Type preservation Progress

19

20

21

22

23

24

25 Canonical Forms Lemma Required by the proof of the progress theorem

"How" is boring. But "what" is not boring.

27 Type Preservation Apply rule induction to:

28 Which case first?

29 Some theorem to prove Case the easiest... Case easy... Case difficult... Case the most difficult Which case first?

30 Some theorem to refute Case the easiest... Case easy... Case difficult... Case the most difficult Which case first?

31 So the most difficult case App first!

32

33 Substitution Lemma Apply rule induction to

Why ? –analyzes the structure of, not. –searches for every occurrence of variable in only to replace it by. –thus, does not need to know the structure of. Proof of substitution lemma –By rule induction on –Proof can be found in Section of POSTECH PL Course Notes. 34