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

Similar documents
Gerwin Klein, June Andronick, Ramana Kumar S2/2016

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

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

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

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus

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

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications. Gerwin Klein Formal Methods

COMP6463: λ-calculus

Models of computation

Typed Arithmetic Expressions

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth

Lambda Calculus. Andrés Sicard-Ramírez. Semester Universidad EAFIT

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007

Programming Languages

Church s undecidability result

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

Logic in Computer Science. Frank Wolter

Origin in Mathematical Logic

Lecture 14 Rosser s Theorem, the length of proofs, Robinson s Arithmetic, and Church s theorem. Michael Beeson

1. Object Calculus. Object calculus is to OO languages what lambda calculus is to functional languages

Introduction to lambda calculus Part 2

Lectures on The Lambda Calculus (I)

First Order Logic vs Propositional Logic CS477 Formal Software Dev Methods

Kleene realizability and negative translations

Beyond First-Order Logic

Type Systems Winter Semester 2006

The λ-calculus and Curry s Paradox Drew McDermott , revised

Propositional and Predicate Logic. jean/gbooks/logic.html

Automata Theory. Definition. Computational Complexity Theory. Computability Theory

Simply Typed λ-calculus

Functional Programming with Coq. Yuxin Deng East China Normal University

The Curry-Howard Isomorphism

Introduction to Turing Machines

Nameless Representation of Terms

Type Theory and Constructive Mathematics. Type Theory and Constructive Mathematics Thierry Coquand. University of Gothenburg

Gödel s Theorem: Limits of logic and computation

Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky. Radboud University Nijmegen. March 5, 2012

Normalization by Evaluation

The Locally Nameless Representation

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

What is logic, the topic of this course? There are at least two answers to that question.

Predicate Logic - Undecidability

HORSes: format, termination and confluence

Program verification using Hoare Logic¹

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

Type Systems Winter Semester 2006

Origin in Mathematical Logic

Categories, Proofs and Programs

Advanced Lambda Calculus Lecture 5

Investigation of Prawitz s completeness conjecture in phase semantic framework

Lambda-Calculus (cont): Fixpoints, Naming. Lecture 10 CS 565 2/10/08

Programming Language Concepts: Lecture 18

Automated Reasoning Lecture 5: First-Order Logic

3.2 Equivalence, Evaluation and Reduction Strategies

Consequence Relations and Natural Deduction

07 Equational Logic and Algebraic Reasoning

Classical First-Order Logic

Peano Arithmetic. CSC 438F/2404F Notes (S. Cook) Fall, Goals Now

The Calculus of Inductive Constructions

Lecture 3. Lambda calculus. Iztok Savnik, FAMNIT. October, 2015.

Formal Techniques for Software Engineering: Denotational Semantics

Local Representations of Binding

Models of Computation,

Creative Objectivism, a powerful alternative to Constructivism

Lecture 2: Self-interpretation in the Lambda-calculus

Recursion Theorem. Ziv Scully Ziv Scully Recursion Theorem / 28

Lecture 2. Lambda calculus. Iztok Savnik, FAMNIT. March, 2018.

Programming Languages and Types

Propositions as Types

ITP Programming Languages Lambda Calculus Lesson 0 Functional Programming and Lambda Calculus Lesson 1 Introduction to the Lambda Calculus

Typed Lambda Calculi. Nikos Tzeveλekos Queen Mary, University of London 1 / 23

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig

3. The λ-calculus and Implication

02 The Axiomatic Method

07 Practical Application of The Axiomatic Method

A λ-calculus with Constants and Let-blocks

Programming Language Concepts: Lecture 16

CS522 - Programming Language Semantics

Simply Typed Lambda-Calculi (II)

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

Notation for Logical Operators:

Induction; Operational Semantics. Fall Software Foundations CIS 500

Non deterministic classical logic: the λµ ++ -calculus

The Lambda-Calculus Reduction System

(a) Definition of TMs. First Problem of URMs

Nominal Completion for Rewrite Systems with Binders

Bootstrapping Mathematics

Provably Total Functions of Arithmetic with Basic Terms

Lecture 9: The Recursion Theorem. Michael Beeson

Introduction to Computational Logic

Equivalent Computers. Lecture 39: Lambda Calculus. Lambda Calculus. What is Calculus? Real Definition. Why?

Computational Soundness of a Call by Name Calculus of Recursively-scoped Records. UMM Working Papers Series, Volume 2, Num. 3.

3.17 Semantic Tableaux for First-Order Logic

Extending the Lambda Calculus: An Eager Functional Language

Jacques Fleuriot. Automated Reasoning Rewrite Rules

Propositions and Proofs

Advanced Topics in LP and FP

Static Program Analysis

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

Propositional Logic: Syntax

Transcription:

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 Calculus, natural deduction [1,2] Higher Order Logic [3 a ] Term rewriting [4] Proof & Specification Techniques Inductively defined sets, rule induction [5] Datatypes, recursion, induction [6, 7] Hoare logic, proofs about programs, C verification [8 b,9] (mid-semester break) Writing Automated Proof Methods [10] Isar, codegen, typeclasses, locales [11 c,12] a a1 due; b a2 due; c a3 due Slide 3 Exercises from last time Download and install Isabelle from http://mirror.cse.unsw.edu.au/pub/isabelle/ Step through the demo files from the lecture web page Write your own theory file, look at some theorems in the library, try find theorems How many theorems can help you if you need to prove something like Suc(Suc x))? What is the name of the theorem for associativity of addition of natural numbers in the library? λ-calculus Alonzo Church lived 1903 1995 supervised people like Alan Turing, Stephen Kleene famous for Church-Turing thesis, lambda calculus, first undecidability results invented λ calculus in 1930 s λ-calculus originally meant as foundation of mathematics important applications in theoretical computer science foundation of computability and functional programming Slide 2 Slide 4 Copyright NICTA 2014, provided under Creative Commons Attribution License 1 Copyright NICTA 2014, provided under Creative Commons Attribution License 2

untyped λ-calculus turing complete model of computation a simple way of writing down functions Basic intuition: instead of f(x) = x+5 write f = λx. x+5 λx. x+5 a term a nameless function that adds 5 to its parameter THAT S IT! Slide 5 Slide 7 Function Application For applying arguments to functions instead of write f(a) f a Example: (λx. x+5) a Evaluating: (computation!) in(λx. t) a replace x by a in t NOW FORMAL Example: (λx. x+5) (a+b) evaluates to (a+b)+5 Slide 6 Slide 8 Copyright NICTA 2014, provided under Creative Commons Attribution License 3 Copyright NICTA 2014, provided under Creative Commons Attribution License 4

Syntax Getting used to the Syntax Terms: t ::= v c (t t) (λx. t) v,x V, c C, V,C sets of names v, x variables c constants (t t) application (λx. t) abstraction Example: λx y z. x z (y z) = λx y z. (x z) (y z) = λx y z. ((x z) (y z)) = λx. λy. λz.((x z) (y z)) = (λx. (λy. (λz. ((x z) (y z))))) Slide 9 Slide 11 Conventions Computation leave out parentheses where possible list variables instead of multiple λ Intuition: replace parameter by argument this is called β-reduction Example: instead of (λy. (λx. (x y))) write λy x. x y Example Rules: list variables: λx. (λy. t) = λx y. t application binds to the left: x y z = (x y) z x (y z) abstraction binds to the right: λx. x y = λx. (x y) (λx. x) y leave out outermost parentheses (λx y. f (y x)) 5 (λx. x) β (λy. f (y 5)) (λx. x) β f ((λx. x) 5) β f 5 Slide 10 Slide 12 Copyright NICTA 2014, provided under Creative Commons Attribution License 5 Copyright NICTA 2014, provided under Creative Commons Attribution License 6

Defining Computation β reduction: (λx. s) t β s[x t] s β s = (s t) β (s t) t β t = (s t) β (s t ) s β s = (λx. s) β (λx. s ) Still to do: define s[x t] Free Variables Bound variables: in (λx. t), x is a bound variable. Free variables FV of a term: FV (x) = {x} FV (c) = {} FV (s t) = FV(s) FV(t) FV (λx. t) = FV(t) \ {x} Example: FV( λx. (λy. (λx. x) y) y x ) = {y} Term t is called closed if FV(t) = {} The substitution example, (λx. x z)[z x], is problematic because the bound variable x is a free variable of the replacement term x. Slide 13 Slide 15 Defining Substitution Easy concept. Small problem: variable capture. Example: (λx. x z)[z x] We do not want: (λx. x x) as result. What do we want? In (λy. y z) [z x] = (λy. y x) there would be no problem. So, solution is: rename bound variables. Substitution x [x t] = t y [x t] = y if x y c [x t] = c (s 1 s 2 ) [x t] = (s 1 [x t] s 2 [x t]) (λx. s) [x t] = (λx. s) (λy. s) [x t] = (λy. s[x t]) if x y and y / FV(t) (λy. s) [x t] = (λz. s[y z][x t]) if x y and z / FV(t) FV(s) Slide 14 Slide 16 Copyright NICTA 2014, provided under Creative Commons Attribution License 7 Copyright NICTA 2014, provided under Creative Commons Attribution License 8

Substitution Example (x (λx. x) (λy. z x))[x y] = (x[x y]) ((λx. x)[x y]) ((λy. z x)[x y]) = y (λx. x) (λy. z y) α Conversion Equality in Isabelle is equality modulo α conversion: if s = α t then s and t are syntactically equal. Examples: x (λx y. x y) = α x (λy x. y x) = α x (λz y. z y) α z (λz y. z y) α x (λx x. x x) Slide 17 Slide 19 α Conversion Bound names are irrelevant: λx. x and λy. y denote the same function. α conversion: s = α t means s = t up to renaming of bound variables. (λx. t) α s α Formally: s = (s t) α (s t) t α t = (s t) α (s t ) s α s = (λx. s) α (λx. s ) (λy. t[x y]) if y / FV(t) Back toβ We have defined β reduction: β Some notation and concepts: β conversion: s = β t iff n. s β n t β n t is reducible if there is an s such that t β s (λx. s) t is called a redex (reducible expression) t is reducible iff it contains a redex if it is not reducible, t is in normal form s = α t iff s α t ( α = transitive, reflexive closure of α = multiple steps) Slide 18 Slide 20 Copyright NICTA 2014, provided under Creative Commons Attribution License 9 Copyright NICTA 2014, provided under Creative Commons Attribution License 10

Does everyλterm have a normal form? No! β reduction is confluent Example: Example: (λx. x x) (λx. x x) β (λx. x x) (λx. x x) β (λx. x x) (λx. x x) β... (λx y. y) ((λx. x x) a) β (λx y. y) (a a) β λy. y (λx y. y) ((λx. x x) a) β λy. y (but: (λx y. y) ((λx. x x) (λx. x x)) β λy. y) λ calculus is not terminating Slide 21 Slide 23 β reduction is confluent η Conversion Confluence: s β x s β y = t. x β t y β t Another case of trivially equal functions: t = (λx. t x) s (λx. t x) η t if x / FV(t) s Definition: η s = (s t) η (s t) t η t = (s t) η (s t ) s η s = (λx. s) η (λx. s ) x y s = η t iff n. s η n t η n Order of reduction does not matter for result Normal forms inλcalculus are unique t Example: (λx. f x) (λy. g y) η (λx. f x) g η f g η reduction is confluent and terminating. βη is confluent. βη means β and η steps are both allowed. Equality in Isabelle is also modulo η conversion. Slide 22 Slide 24 Copyright NICTA 2014, provided under Creative Commons Attribution License 11 Copyright NICTA 2014, provided under Creative Commons Attribution License 12

In fact... Equality in Isabelle is modulo α, β, and η conversion. We will see later why that is possible. More Examples Encoding natural numbers (Church Numerals) 0 λf x. x 1 λf x. f x 2 λf x. f (f x) 3 λf x. f (f (f x))... Numeral n takes arguments f and x, applies f n-times to x. iszero λn. n (λx.false)true succ λn f x. f (n f x) add λm n. λf x. m f (n f x) Slide 25 Slide 27 So, what can you do with λ calculus? λ calculus is very expressive, you can encode: logic, set theory turing machines, functional programs, etc. Examples: true λx y. x false λx y. y if λz x y. z x y Now, not, and, or, etc is easy: not λx.if xfalsetrue and λx y.if x y false or λx y.if xtrue y iftrue x y β x iffalse x y β y Fix Points (λx f. f (x x f)) (λx f. f (x x f)) t β (λf. f ((λx f. f (x x f)) (λx f. f (x x f)) f)) t β t ((λx f. f (x x f)) (λx f. f (x x f)) t) µ = (λxf. f (x x f)) (λxf. f (x x f)) µ t β t (µ t) β t (t (µ t)) β t (t (t (µ t))) β... (λxf. f (x x f)) (λxf. f (x x f)) is Turing s fix point operator Slide 26 Slide 28 Copyright NICTA 2014, provided under Creative Commons Attribution License 13 Copyright NICTA 2014, provided under Creative Commons Attribution License 14

Nice, but... As a mathematical foundation, λ does not work. It is inconsistent. Frege (Predicate Logic, 1879): allows arbitrary quantification over predicates Russell (1901): Paradox R {X X / X} Whitehead & Russell (Principia Mathematica, 1910-1913): Fix the problem Church (1930): λ calculus as logic, true, false,,... as λ terms We have learned so far... λ calculus syntax free variables, substitution β reduction α and η conversion β reduction is confluent λ calculus is very expressive (turing complete) λ calculus is inconsistent Problem: with {x P x} λx. P x x M M x you can write R λx.not (x x) and get (R R) = β not (R R) because (R R) = (λx.not (x x)) R β not (R R) Slide 29 Slide 31 ISABELLE DEMO Slide 30 Copyright NICTA 2014, provided under Creative Commons Attribution License 15 16