# Introduction to type systems

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Introduction to type systems p. 1/5 Introductory Course on Logic and Automata Theory Introduction to type systems Based on slides by Jeff Foster, UMD

2 Introduction to type systems p. 2/5 The need for types Consider the lambda calculus terms: false = λx.λy.x 0 = λx.λy.x (Scott encoding) Everything is encoded using functions One can easily misuse combinators false 0, or if 0 then..., etc... It s no better than assembly language!

3 Introduction to type systems p. 3/5 Type system A type system is some mechanism for distinguishing good programs from bad Good programs are well typed Bad programs are ill typed or not typeable Examples: is well typed false 0 is ill typed: booleans cannot be applied to numbers 1 + (if true then 0 else false) is ill typed: cannot add a boolean to an integer

4 Introduction to type systems p. 4/5 A definition A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute. Benjamin Pierce, Types and Programming Languages

5 Introduction to type systems p. 5/5 Simply-typed lambda calculus e ::= n x λx : τ.e e e Functions include the type of their argument We don t need this yet, but it will be useful later τ ::= int τ τ τ 1 τ 2 is a the type of a function that, given an argument of type τ 1, returns a result of type τ 2 We say τ 1 is the domain, and τ 2 is the range

6 Introduction to type systems p. 6/5 Typing judgements The type system will prove judgments of the form Γ e : τ In type environment Γ, expression e has type τ

7 Introduction to type systems p. 7/5 Type environments A type environment is a map from variables to types (similar to a symbol table) is the empty type environment A closed term e is well-typed if e : τ for some τ Also written as e : τ Γ,x : τ is just like Γ except x has type τ The type of x in Γ is τ For z x, the type of z in Γ,x : τ is the type of z in Γ (we look up variables from the end) When we see a variable in a program, we look in the type environment to find its type

8 Introduction to type systems p. 8/5 Type rules Γ n : int Γ,x : τ e : τ Γ λx : τ.e : τ τ x dom(γ) Γ x : Γ(x) Γ e 1 : τ τ Γ e 2 : τ Γ e 1 e 2 : τ

9 Introduction to type systems p. 9/5 Example Assume Γ = ( : int int) dom(γ) Γ : int int Γ 3 : int Γ 3 : int

10 Introduction to type systems p. 10/5 An algorithm for type checking The above type rules are deterministic For each syntactic form of a term e, only one rule is possible They define a natural type checking algorithm TypeCheck : (type_env expression) type TypeCheck(Γ, n) = int TypeCheck(Γ, x) = if x dom(γ) then Γ(x) else fail TypeCheck(Γ, λx : τ.e) = TypeCheck((Γ,x : τ), e) TypeCheck(Γ, e 1 e 2 ) = let τ 1 = TypeCheck(Γ, e 1 ) in let τ 2 = TypeCheck(Γ, e 2 ) in if dom(τ 1 ) = τ 2 then range(τ 1 ) else fail

11 Introduction to type systems p. 11/5 Reminder: semantics Small-step, call-by-value semantics If an expression is not a value, and cannot evaluate any more, we say it is stuck, e.g. 0 1 (λx : τ.e 1 ) v 2 e 1 [v 2 /x] e 1 e 1 e 1 e 2 e 1 e 2 e 2 e 2 where v 1 e 2 v 1 e 2 e ::= v x e e v ::= n λx : τ.e

12 Introduction to type systems p. 12/5 Progress theorem If e : τ then either e is a value, or there exists e such that e e Proof by induction on e Base cases (values): n,λx : τ.e, trivially true Case x: impossible, untypeable in empty environment Inductive case: e 1 e 2 If e 1 is not a value, apply the theorem inductively and then second semantic rule. If e 1 is a value but e 2 is not, similar (using the third semantic rule) If e 1 and e 2 are values, then e 1 has function type, and the only value with a function type is a lambda term, so we apply the first semantic rule

13 Introduction to type systems p. 13/5 Preservation theorem If e : τ and e e then e : τ Proof by induction on e e In all cases (one for each rule), e has the form e = e 1 e 2 Inversion: from e 1 e 2 : τ we get e 1 : τ τ and e 2 : τ Three semantic rules: Second or third rule: apply induction on e 1 or e 2 respectively, and type-rule for application Remaining case: (λx : τ.e) v e[v/x]

14 Introduction to type systems p. 14/5 Preservation continued Case (λx : τ.e) v e[v/x] From hypothesis: x : τ e : τ λx : τ.e : τ τ To finish preservation proof, we must prove e[v/x] : τ. Susbstitution lemma

15 Introduction to type systems p. 15/5 Substitution lemma If Γ v : τ and Γ,x : τ e : τ, then Γ e[v/x] : τ Proof by induction on e (not shown) For lazy (call by name) semantics, substitution lemma is If Γ e 1 : τ and Γ,x : τ e : τ, then Γ e[e 1 /x] : τ

16 Introduction to type systems p. 16/5 Soundness So far: Progress: If e : τ, then either e is a value, or there exists e such that e e Preservation: If e : τ and e e then e : τ Putting these together, we get soundness If e : τ then either there exists a value v such that e v or e doesn t terminate What does this mean? Well-typed programs don t go wrong Evaluation never gets stuck

17 Introduction to type systems p. 17/5 Product types (tuples) e ::=... fst e snd e τ ::=... τ τ Γ e 1 : τ Γ e 2 : τ Γ (e 1,e 2 ) : τ τ Γ e : τ τ Γ fst e : τ Γ e : τ τ Γ snd e : τ Alternatively, using function signatures pair : τ τ τ τ fst : τ τ τ snd : τ τ τ

18 Introduction to type systems p. 18/5 Sum types e ::=... inl τ2 e inr τ1 e (case e of x 1 : τ 1 e 1 x 2 : τ 2 e 2 ) τ ::=... τ + τ Γ e : τ 1 Γ inl τ2 e : τ 1 + τ 2 Γ e : τ 2 Γ inr τ1 e : τ 1 + τ 2 Γ e : τ 1 + τ 2 Γ,x 1 : τ 1 e 1 : τ Γ,x 2 : τ 2 e 2 : τ Γ (case e of x 1 : τ 1 e 1 x 2 : τ 2 e 2 ) : τ

19 Introduction to type systems p. 19/5 Self application and types Self application is not typeable in this system Γ,x :? x : τ τ Γ,x :? x : τ Γ,x :? x x :... Γ λx :?.x x :... We need a type τ such that τ = τ τ The simply-typed lambda calculus is strongly normalizing Every program has a normal form Or, every program halts!

20 Introduction to type systems p. 20/5 Recursive types We can type self application if we have a type to represent the solution to equations like τ = τ τ We define the type µα.τ to be the solution to the (recursive) equation α = τ Example: µα.int α

21 Introduction to type systems p. 21/5 Folding/unfolding recursive types Inferred: We can check type equivalence with the previous definition Standard unification, omit occurs checks (explained later) Alternative method: explicit fold/unfold The programmer inserts explicit fold and unfold operations to expand/contract a level of the type unfold µα.τ = τ[µα.τ/α] fold τ[µα.τ/α] = µα.τ

22 Introduction to type systems p. 22/5 Fold-based recursive types e ::=... fold e unfold e τ ::=... µα.τ Γ e : τ[µα.τ/α] Γ fold e : µα.τ Γ e : µα.τ Γ unfold e : τ[µα.τ/α]

23 Introduction to type systems p. 23/5 ML Datatypes Combines fold/unfold-style recursive and sum types Each occurence of a type constructor when producing a value corresponds to inr/inl and (if recursive,) also fold Each occurence of a type constructor in a pattern match corresponds to a case and (if recursive,) at least one unfold

24 Introduction to type systems p. 24/5 ML Datatypes examples type intlist = Int of int Cons of int intlist is equivalent to µα.int + (int α) ( Int 3) is equivalent to fold (inl int µα.int+(int α) 3)

25 Introduction to type systems p. 25/5 More ML Datatype examples (Cons (42, (Int 3))) is equivalent to fold (inr int (2, fold (inl int µα.int+(int α) 3))) match e with Int x e 1 Cons x e 2 is equivalent to case (unfold e) of x : int e 1 x : int (µα.int + (int α)) e 2

26 Introduction to type systems p. 26/5 Discussion In the pure lambda calculus, every term is typeable with recursive types Pure means only including functions and variables (the calculus from the last class) Most languages have some kind of recursive type Used to encode data structures like e.g. lists, trees,... However, usually two recursive types are differentiated by name, even when they define the same structure For example, struct foo { int x; struct foo *next; } is different from struct bar { int x; struct bar *next; }

27 Introduction to type systems p. 27/5 Intermission Next: Curry-Howard correspondence

28 Introduction to type systems p. 28/5 Classical propositional logic Formulas of the form φ ::= p φ φ φ φ φ φ Where p P is an atomic proposition, e.g. Socrates is a man Convenient abbreviations: φ means φ φ φ means (φ φ ) (φ φ)

29 Introduction to type systems p. 29/5 Semantics of classical logic Interpretation m : P {true, false} p m m φ φ m φ φ m φ φ m = m(p) = false = φ m φ m = φ m φ m = φ m φ m Where,, are the standard boolean operations on {true, false}

30 Introduction to type systems p. 30/5 Terminology A formula φ is valid if φ m = true for all m A formula φ is unsatisfiable if φ m = false for all m Law of excluded middle: Formula φ φ is valid for any φ A proof system attempts to determine the validity of a formula

31 Introduction to type systems p. 31/5 Proof theory for classical logic Proves judgements of the form Γ φ: For any interpretation, under assumption Γ, φ is true Syntactic deduction rules that produce proof trees of Γ φ: Natural deduction Problem: classical proofs only address truth value, not constructive Example: There are two irrational numbers x and y, such that x y is rational Proof does not include much information

32 Introduction to type systems p. 32/5 Intuitionistic logic Get rid of the law of excluded middle Notion of truth is not the same A proposition is true, if we can construct a proof Cannot assume predefined truth values without constructed proofs (no either true or false ) Judgements are not expression of truth, they are constructions φ means there is a proof for φ φ means there is a refutation for φ, not there is no proof (φ ) only means the absense of a refutation for φ, does not imply φ as in classical logic

33 Introduction to type systems p. 33/5 Proofs in intuitionistic logic Γ,φ φ Γ Γ φ Γ φ Γ ψ Γ φ ψ Γ φ ψ Γ φ Γ φ ψ Γ ψ Γ φ Γ φ ψ Γ ψ Γ φ ψ Γ,φ ρ Γ,ψ ρ Γ φ ψ Γ ρ Γ,φ ψ Γ φ ψ Does that resemble anything? Γ φ ψ Γ ψ Γ φ

34 Introduction to type systems p. 34/5 Curry-Howard correspondence We can mechanically translate formulas φ into type τ for every φ and the reverse E.g. replace with, with +,... If Γ e : τ in simply-typed lambda calculus, and τ translates to φ, then range(γ) φ in intuistionistic logic If Γ φ in intuitionistic logic, and φ translates to τ, then there exists e and Γ such that range(γ ) = Γ and Γ e : τ Proof by induction on the derivation Γ φ Can be simplified by fixing the logic and type languages to match

35 Introduction to type systems p. 35/5 Consequences Lambda terms encode proof trees Evaluation of lambda terms is proof simplification Automated proving by trying to construct a lambda term with the wanted type Verifying a proof is typechecking Increased trust in complicated proofs when machine-verifiable Proof-carrying code Certifying compilers

36 Introduction to type systems p. 36/5 So far... We have discussed simple types Integers, functions, pairs, unions Extension for recursive types Type systems have nice properties Type checking is straightforward (needs annotations) Well-typed programs don t go wrong (get stuck) But..., we cannot type-check all good programs Sound, but not complete Might reject correct programs (have false warnings)

37 Introduction to type systems p. 37/5 Next: improving types How can we build more flexible type systems? More programs type check Type checking is still tractable How can we reduce the annotation burden? Type inference: infer annotations automatically

38 Introduction to type systems p. 38/5 Parametric polymorphism Observation: λx.x returns its argument exactly without any constraints on the type of x The identity function works for any argument type We can express this with universal quantification λx.x : α.α α For any type α the identity function has type α α This is also known as parametric polymorphism

39 Introduction to type systems p. 39/5 System F: annotated polymorphism We extend the previous system: τ ::= int τ τ α α.τ e ::= n x λx.e e e Λα.e e[τ] We add polymorphic types, and we add explicit type abstraction (generalization over all α)... Explicit creation of values ov polymorphic types... and type application (instantiation of generalized types) Explicitly marks code locations where a value of polymorphic type is used System by Girard, concurrently Reynolds

40 Introduction to type systems p. 40/5 Defining polymorphic functions Polymorphic functions map types to terms Normal functions map terms to terms Examples Λα.λx : α.x : α.α α Λα.Λβ.λx : α.λy : β.x : α. β.α β α Λα.Λβ.λx : α.λy : β.y : α. β.α β β

41 Introduction to type systems p. 41/5 Instantiation When we use a parametric polymorphic type, we apply or instantiate it with a particular type In System F this is done by hand (Λα.λx : α.x)[τ 1 ] : τ 1 τ 1 (Λα.λx : α.x)[τ 2 ] : τ 2 τ 2 This is where the term parametric comes from The type α.α α is a function in the domain of types It is given a parameter at instantiation time

42 Introduction to type systems p. 42/5 Type rules Γ,α e : τ Γ Λα.e : α.τ Γ e : α.τ Γ e[τ ] : τ[τ /α] Notice that there are no constructs for manipulating values of polymorphic type This justifies instantiation with any type that s what for all means We add α to Γ: we use this to ensure types are well-formed

43 Introduction to type systems p. 43/5 Small-step semantics rules (Λα.e)[τ] e[τ/α] e e e[τ] e [τ] We have to extend the definition of substitution for types

44 Introduction to type systems p. 44/5 Free variables (again) We need to perform substitutions on quantified types Just like with lambda calculus, we need to think about free variables and avoid capturing with substitution Define the free variables of a type FV (α) = {α} FV (c) = FV (τ τ ) = FV (τ) FV (τ ) FV ( α.τ) = FV (τ) \ {α}

45 Introduction to type systems p. 45/5 Substitution (again) We define τ[u/α] as α[u/α] = u β[u/α] = β where β α (τ τ )[u/α] = τ[u/α] τ [u/α] ( β.τ)[u/α] = β.(τ[u/α]) where β α β / FV (u) We define e[u/α] as (λx : τ.e)[u/α] = (λx : τ[u/α].e[u/α] (Λβ.e)[u/α] = Λβ.e[u/α] where β α β / FV (u) (e 1 e 2 )[u/α] = e 1 [u/α] e 2 [u/α] x[u/α] = x n[u/α] = n

46 Introduction to type systems p. 46/5 Type inference Consider the simply typed lambda calculus with integers e ::= n x λx.τ e e Simple, no polymorphism Type inference: Given a bare term (no annotations), can we reconstruct a valid typing if there is one?

47 Introduction to type systems p. 47/5 Type language Problem: consider the rule for functions Γ,x : τ e : τ Γ λx : τ.e : τ τ Without type annotations on λ terms, where do we find τ? We use type variables in place of as-yet-unknown types τ ::= α int τ τ We generate equality constraints τ = τ among types and type variables We solve the constraints to compute a typing

48 Introduction to type systems p. 48/5 Type inference rules Γ n : int x dom(γ) Γ x : Γ(x) Γ,x : α e : τ α fresh Γ λx.e : α τ Γ e 1 : τ 1 Γ e 2 : τ 2 τ 1 = τ 2 β β fresh Γ e 1 e 2 : β

49 Introduction to type systems p. 49/5 Example Γ,x : α x : α Γ (λx.x) : α α Γ 3 : int α α = int β Γ (λx.x) 3 : β We collect all constraints appearing in the derivation into a set C to be solved Here C contains α α = int β Solution: α = β = int So, this program is typeable We can create a typing by replacing variables in the derivation

50 Introduction to type systems p. 50/5 Solving equality constraints We can solve the equality constraints using the following rewrite rules, which reduce a larger set of constraints to a smaller set C {int = int} C C {α = τ} C[τ/α] C {τ = α} C[τ/α] C {τ 1 τ 2 = τ 1 τ 2 } C {τ 1 = τ 1 } {τ 2 = τ 2 } C {int = τ 1 τ 2 } unsatisfiable C {τ 1 τ 2 = int} unsatisfiable

51 Introduction to type systems p. 51/5 Termination We can prove that the constraint solving algorithm terminates For each rewriting rule, either We reduce the size of the constraint set We reduce the number of arrow constructors in the constraint set As a result, the constraint always gets smaller and eventually becomes empty A similar argument is made for strong normalization of the simply-typed lambda calculus

52 Introduction to type systems p. 52/5 Occurs check We don t have recursive types, so we don t infer them In the operation C[τ/α] we require that α / FV (τ) In practice, it may be better to allow α FV (τ) and perform an occurs check at the end Could be difficult to implement Unification might not terminate without occurs check

53 Introduction to type systems p. 53/5 Unifying a variable and a type Computing C[τ/α] by substitution is inefficient Instead, use a union-find data structure to represent equal types The terms are in a union-find forest When a variable and a term are equated, we union them so they have the same equivalence class If there is a concrete type in an equivalence class, use it to represent the class Solution is the representative of each class at the end

54 Introduction to type systems p. 54/5 Example α = int β γ = int int α = γ

55 Introduction to type systems p. 55/5 Unification The process of finding a solution to a set of equality constraints is called unification Original algorithm by Robinson (inefficient) Often written in different form (algorithm W) Usually solved on-line as type rules are applied

56 Introduction to type systems p. 56/5 Discussion The algorithm we ve given finds the most general type of a term Any other type is more specific Formally, any other valid type can be created from the most general type by applying a substitution on type variables All this is for a monomorphic type system, no quantification Variables α stand for some particular type

57 Introduction to type systems p. 57/5 Inference for polymorphism We would like to have the power of System F, and the ease of use of type inference In short: given an untyped lambda calculus term, can we discover the annotations necessary for typing the term in System F, if such a typing is possible? Unfortunately, no. This problem has been shown to be undecidable. Can we at least perform some kind of parametric polymorphism Yes, a sweet spot was found by Hindley and Milner Abstraction at let-statements, instantiation on each variable use Used in ML

58 Introduction to type systems p. 58/5 Curry-Howard extension Does the equivalent logic get extended using polymorphism? More than enough to encode first-order logic A subset of System F (with several restrictions) is equivalent to First Order Logic Actually, we can use System F as a common language for polymorphic lambda calculus and for second-order propositional logic!

59 Introduction to type systems p. 59/5 Other extensions Higher-order logic is encodable in System F ω Further extension using the Calculus of Constructions can encode even more complex logics Inductive types can encode algebraic data types, inductive proofs Combining the calculus of constructions with inductive types: The Calculus of Inductive Constructions: Proof language used in the Coq theorem prover Can encode and reason about other logics, type systems Can also be used to reason about Classical Logic Just make the law of excluded middle an axiom

### 3. Mathematical Induction

3. MATHEMATICAL INDUCTION 83 3. Mathematical Induction 3.1. First Principle of Mathematical Induction. Let P (n) be a predicate with domain of discourse (over) the natural numbers N = {0, 1,,...}. If (1)

### Parametric Domain-theoretic models of Linear Abadi & Plotkin Logic

Parametric Domain-theoretic models of Linear Abadi & Plotkin Logic Lars Birkedal Rasmus Ejlers Møgelberg Rasmus Lerchedahl Petersen IT University Technical Report Series TR-00-7 ISSN 600 600 February 00

### The Foundations: Logic and Proofs. Chapter 1, Part III: Proofs

The Foundations: Logic and Proofs Chapter 1, Part III: Proofs Rules of Inference Section 1.6 Section Summary Valid Arguments Inference Rules for Propositional Logic Using Rules of Inference to Build Arguments

### Types, Polymorphism, and Type Reconstruction

Types, Polymorphism, and Type Reconstruction Sources This material is based on the following sources: Pierce, B.C., Types and Programming Languages. MIT Press, 2002. Kanellakis, P.C., Mairson, H.G. and

### CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

CHAPTER 3 Methods of Proofs 1. Logical Arguments and Formal Proofs 1.1. Basic Terminology. An axiom is a statement that is given to be true. A rule of inference is a logical rule that is used to deduce

### Summary Last Lecture. Automated Reasoning. Outline of the Lecture. Definition sequent calculus. Theorem (Normalisation and Strong Normalisation)

Summary Summary Last Lecture sequent calculus Automated Reasoning Georg Moser Institute of Computer Science @ UIBK Winter 013 (Normalisation and Strong Normalisation) let Π be a proof in minimal logic

### CHAPTER 7 GENERAL PROOF SYSTEMS

CHAPTER 7 GENERAL PROOF SYSTEMS 1 Introduction Proof systems are built to prove statements. They can be thought as an inference machine with special statements, called provable statements, or sometimes

### Deterministic Discrete Modeling

Deterministic Discrete Modeling Formal Semantics of Firewalls in Isabelle/HOL Cornelius Diekmann, M.Sc. Dr. Heiko Niedermayer Prof. Dr.-Ing. Georg Carle Lehrstuhl für Netzarchitekturen und Netzdienste

### MAT2400 Analysis I. A brief introduction to proofs, sets, and functions

MAT2400 Analysis I A brief introduction to proofs, sets, and functions In Analysis I there is a lot of manipulations with sets and functions. It is probably also the first course where you have to take

### ML for the Working Programmer

ML for the Working Programmer 2nd edition Lawrence C. Paulson University of Cambridge CAMBRIDGE UNIVERSITY PRESS CONTENTS Preface to the Second Edition Preface xiii xv 1 Standard ML 1 Functional Programming

### Fundamentals of Mathematics Lecture 6: Propositional Logic

Fundamentals of Mathematics Lecture 6: Propositional Logic Guan-Shieng Huang National Chi Nan University, Taiwan Spring, 2008 1 / 39 Connectives Propositional Connectives I 1 Negation: (not A) A A T F

### Deductive Systems. Marco Piastra. Artificial Intelligence. Artificial Intelligence - A.A Deductive Systems [1]

Artificial Intelligence Deductive Systems Marco Piastra Artificial Intelligence - A.A. 2012- Deductive Systems 1] Symbolic calculus? A wff is entailed by a set of wff iff every model of is also model of

### This asserts two sets are equal iff they have the same elements, that is, a set is determined by its elements.

3. Axioms of Set theory Before presenting the axioms of set theory, we first make a few basic comments about the relevant first order logic. We will give a somewhat more detailed discussion later, but

### 1.3 Induction and Other Proof Techniques

4CHAPTER 1. INTRODUCTORY MATERIAL: SETS, FUNCTIONS AND MATHEMATICAL INDU 1.3 Induction and Other Proof Techniques The purpose of this section is to study the proof technique known as mathematical induction.

### Inference Rules and Proof Methods

Inference Rules and Proof Methods Winter 2010 Introduction Rules of Inference and Formal Proofs Proofs in mathematics are valid arguments that establish the truth of mathematical statements. An argument

### Automated Theorem Proving - summary of lecture 1

Automated Theorem Proving - summary of lecture 1 1 Introduction Automated Theorem Proving (ATP) deals with the development of computer programs that show that some statement is a logical consequence of

### POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful

POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: ralf@cs.uu.nl Homepage: http://www.cs.uu.nl/~ralf/

### Mathematical Logic. Tableaux Reasoning for Propositional Logic. Chiara Ghidini. FBK-IRST, Trento, Italy

Tableaux Reasoning for Propositional Logic FBK-IRST, Trento, Italy Outline of this lecture An introduction to Automated Reasoning with Analytic Tableaux; Today we will be looking into tableau methods for

### Introduction to mathematical arguments

Introduction to mathematical arguments (background handout for courses requiring proofs) by Michael Hutchings A mathematical proof is an argument which convinces other people that something is true. Math

### Higher-Order Logic. Specification and Verification with Higher-Order Logic

Higher-Order Logic Specification and Verification with Higher-Order Logic Arnd Poetzsch-Heffter Software Technology Group Fachbereich Informatik Technische Universität Kaiserslautern Sommersemester 2010

### 2. Methods of Proof Types of Proofs. Suppose we wish to prove an implication p q. Here are some strategies we have available to try.

2. METHODS OF PROOF 69 2. Methods of Proof 2.1. Types of Proofs. Suppose we wish to prove an implication p q. Here are some strategies we have available to try. Trivial Proof: If we know q is true then

### 4 Domain Relational Calculus

4 Domain Relational Calculus We now present two relational calculi that we will compare to RA. First, what is the difference between an algebra and a calculus? The usual story is that the algebra RA is

### The Predicate Calculus in AI

Last time, we: The Predicate Calculus in AI Motivated the use of Logic as a representational language for AI (Can derive new facts syntactically - simply by pushing symbols around) Described propositional

### Testing LTL Formula Translation into Büchi Automata

Testing LTL Formula Translation into Büchi Automata Heikki Tauriainen and Keijo Heljanko Helsinki University of Technology, Laboratory for Theoretical Computer Science, P. O. Box 5400, FIN-02015 HUT, Finland

### Termination Checking: Comparing Structural Recursion and Sized Types by Examples

Termination Checking: Comparing Structural Recursion and Sized Types by Examples David Thibodeau Decemer 3, 2011 Abstract Termination is an important property for programs and is necessary for formal proofs

### System Description: Delphin A Functional Programming Language for Deductive Systems

System Description: Delphin A Functional Programming Language for Deductive Systems Adam Poswolsky 1 and Carsten Schürmann 2 1 Yale University poswolsky@cs.yale.edu 2 IT University of Copenhagen carsten@itu.dk

### Likewise, we have contradictions: formulas that can only be false, e.g. (p p).

CHAPTER 4. STATEMENT LOGIC 59 The rightmost column of this truth table contains instances of T and instances of F. Notice that there are no degrees of contingency. If both values are possible, the formula

### A Propositional Dynamic Logic for CCS Programs

A Propositional Dynamic Logic for CCS Programs Mario R. F. Benevides and L. Menasché Schechter {mario,luis}@cos.ufrj.br Abstract This work presents a Propositional Dynamic Logic in which the programs are

### Encoding Mathematics in First-Order Logic

Applied Logic Lecture 19 CS 486 Spring 2005 Thursday, April 14, 2005 Encoding Mathematics in First-Order Logic Over the past few lectures, we have seen the syntax and the semantics of first-order logic,

### Predicate Logic Review

Predicate Logic Review UC Berkeley, Philosophy 142, Spring 2016 John MacFarlane 1 Grammar A term is an individual constant or a variable. An individual constant is a lowercase letter from the beginning

### CS510 Software Engineering

CS510 Software Engineering Propositional Logic Asst. Prof. Mathias Payer Department of Computer Science Purdue University TA: Scott A. Carr Slides inspired by Xiangyu Zhang http://nebelwelt.net/teaching/15-cs510-se

### Foundations of Artificial Intelligence

Foundations of Artificial Intelligence 7. Propositional Logic Rational Thinking, Logic, Resolution Wolfram Burgard, Bernhard Nebel and Martin Riedmiller Albert-Ludwigs-Universität Freiburg Contents 1 Agents

### Chapter 6 Finite sets and infinite sets. Copyright 2013, 2005, 2001 Pearson Education, Inc. Section 3.1, Slide 1

Chapter 6 Finite sets and infinite sets Copyright 013, 005, 001 Pearson Education, Inc. Section 3.1, Slide 1 Section 6. PROPERTIES OF THE NATURE NUMBERS 013 Pearson Education, Inc.1 Slide Recall that denotes

### It is time to prove some theorems. There are various strategies for doing

CHAPTER 4 Direct Proof It is time to prove some theorems. There are various strategies for doing this; we now examine the most straightforward approach, a technique called direct proof. As we begin, it

### LOGICAL INFERENCE & PROOFs. Debdeep Mukhopadhyay Dept of CSE, IIT Madras

LOGICAL INFERENCE & PROOFs Debdeep Mukhopadhyay Dept of CSE, IIT Madras Defn A theorem is a mathematical assertion which can be shown to be true. A proof is an argument which establishes the truth of a

### Foundational Proof Certificates

An application of proof theory to computer science INRIA-Saclay & LIX, École Polytechnique CUSO Winter School, Proof and Computation 30 January 2013 Can we standardize, communicate, and trust formal proofs?

### Parametric polymorphism through run-time sealing

Parametric polymorphism through run-time sealing or, Theorems for low, low prices! Jacob Matthews 1 and Amal Ahmed 2 1 University of Chicago jacobm@cs.uchicago.edu 2 Toyota Technological Institute at Chicago

### Programming Languages Featherweight Java David Walker

Programming Languages Featherweight Java David Walker Overview Featherweight Java (FJ), a minimal Javalike language. Models inheritance and subtyping. Immutable objects: no mutation of fields. Trivialized

### Semantics for the Predicate Calculus: Part I

Semantics for the Predicate Calculus: Part I (Version 0.3, revised 6:15pm, April 14, 2005. Please report typos to hhalvors@princeton.edu.) The study of formal logic is based on the fact that the validity

### Predicate Logic. For example, consider the following argument:

Predicate Logic The analysis of compound statements covers key aspects of human reasoning but does not capture many important, and common, instances of reasoning that are also logically valid. For example,

### Discrete Mathematics

Slides for Part IA CST 2014/15 Discrete Mathematics Prof Marcelo Fiore Marcelo.Fiore@cl.cam.ac.uk What are we up to? Learn to read and write, and also work with, mathematical

### Bindings, mobility of bindings, and the -quantifier

ICMS, 26 May 2007 1/17 Bindings, mobility of bindings, and the -quantifier Dale Miller, INRIA-Saclay and LIX, École Polytechnique This talk is based on papers with Tiu in LICS2003 & ACM ToCL, and experience

### 1. R In this and the next section we are going to study the properties of sequences of real numbers.

+a 1. R In this and the next section we are going to study the properties of sequences of real numbers. Definition 1.1. (Sequence) A sequence is a function with domain N. Example 1.2. A sequence of real

### + addition - subtraction and unary minus * multiplication / division mod modulo

Chapter 4 Basic types We examine in this chapter the Caml basic types. 4.1 Numbers Caml Light provides two numeric types: integers (type int) and floating-point numbers (type float). Integers are limited

### MATHS 315 Mathematical Logic

MATHS 315 Mathematical Logic Second Semester, 2006 Contents 2 Formal Statement Logic 1 2.1 Post production systems................................. 1 2.2 The system L.......................................

### Review Name Rule of Inference

CS311H: Discrete Mathematics Review Name Rule of Inference Modus ponens φ 2 φ 2 Modus tollens φ 2 φ 2 Inference Rules for Quantifiers Işıl Dillig Hypothetical syllogism Or introduction Or elimination And

### Induction. Margaret M. Fleck. 10 October These notes cover mathematical induction and recursive definition

Induction Margaret M. Fleck 10 October 011 These notes cover mathematical induction and recursive definition 1 Introduction to induction At the start of the term, we saw the following formula for computing

### Mathematical Induction

Mathematical Induction MAT30 Discrete Mathematics Fall 016 MAT30 (Discrete Math) Mathematical Induction Fall 016 1 / 19 Outline 1 Mathematical Induction Strong Mathematical Induction MAT30 (Discrete Math)

### OutsideIn(X) Modular type inference with local assumptions

Under consideration for publication in J. Functional Programming 1 OutsideIn(X) Modular type inference with local assumptions 11 April 2011 Dimitrios Vytiniotis Microsoft Research Simon Peyton Jones Microsoft

### Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2

CS 70 Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2 Proofs Intuitively, the concept of proof should already be familiar We all like to assert things, and few of us

### Andrew Pitts chapter for D. Sangorgi and J. Rutten (eds), Advanced Topics in Bisimulation and Coinduction, Cambridge Tracts in Theoretical Computer

Andrew Pitts chapter for D. Sangorgi and J. Rutten (eds), Advanced Topics in Bisimulation and Coinduction, Cambridge Tracts in Theoretical Computer Science No. 52, chapter 5, pages 197 232 ( c 2011 CUP)

### Lecture 3. Mathematical Induction

Lecture 3 Mathematical Induction Induction is a fundamental reasoning process in which general conclusion is based on particular cases It contrasts with deduction, the reasoning process in which conclusion

### Chapter I Logic and Proofs

MATH 1130 1 Discrete Structures Chapter I Logic and Proofs Propositions A proposition is a statement that is either true (T) or false (F), but or both. s Propositions: 1. I am a man.. I am taller than

### CIS 500 Software Foundations Midterm I. Answer key. October 10, 2007

CIS 500 Software Foundations Midterm I Answer key October 10, 2007 Functional Programming 1. (2 points) Consider the following Fixpoint definition in Coq. Fixpoint zip (X Y : Set) (lx : list X) (ly : list

### Logic, Sets, and Proofs

Logic, Sets, and Proofs David A. Cox and Catherine C. McGeoch Amherst College 1 Logic Logical Statements. A logical statement is a mathematical statement that is either true or false. Here we denote logical

### Pythagorean Theorem. Overview. Grade 8 Mathematics, Quarter 3, Unit 3.1. Number of instructional days: 15 (1 day = minutes) Essential questions

Grade 8 Mathematics, Quarter 3, Unit 3.1 Pythagorean Theorem Overview Number of instructional days: 15 (1 day = 45 60 minutes) Content to be learned Prove the Pythagorean Theorem. Given three side lengths,

### Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

Chapter 3 Cartesian Products and Relations The material in this chapter is the first real encounter with abstraction. Relations are very general thing they are a special type of subset. After introducing

### Unboxed Polymorphic Objects for Functional Numerical Programming

Unboxed Polymorphic Objects for Functional Numerical Programming Christopher Rodrigues cirodrig@illinois.edu Wen-Mei Hwu w-hwu@illinois.edu IMPACT Technical Report IMPACT-12-02 University of Illinois at

### Indiana State Core Curriculum Standards updated 2009 Algebra I

Indiana State Core Curriculum Standards updated 2009 Algebra I Strand Description Boardworks High School Algebra presentations Operations With Real Numbers Linear Equations and A1.1 Students simplify and

### SJÄLVSTÄNDIGA ARBETEN I MATEMATIK

SJÄLVSTÄNDIGA ARBETEN I MATEMATIK MATEMATISKA INSTITUTIONEN, STOCKHOLMS UNIVERSITET Automated Theorem Proving av Tom Everitt 2010 - No 8 MATEMATISKA INSTITUTIONEN, STOCKHOLMS UNIVERSITET, 106 91 STOCKHOLM

### Journal of Functional Programming, volume 3 number 4, 1993. Dynamics in ML

Journal of Functional Programming, volume 3 number 4, 1993. Dynamics in ML Xavier Leroy École Normale Supérieure Michel Mauny INRIA Rocquencourt Abstract Objects with dynamic types allow the integration

### Students in their first advanced mathematics classes are often surprised

CHAPTER 8 Proofs Involving Sets Students in their first advanced mathematics classes are often surprised by the extensive role that sets play and by the fact that most of the proofs they encounter are

### Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

Grade 7 Mathematics, Quarter 1, Unit 1.1 Integer Operations Overview Number of Instructional Days: 15 (1 day = 45 minutes) Content to Be Learned Describe situations in which opposites combine to make zero.

### 6.080/6.089 GITCS Feb 12, 2008. Lecture 3

6.8/6.89 GITCS Feb 2, 28 Lecturer: Scott Aaronson Lecture 3 Scribe: Adam Rogal Administrivia. Scribe notes The purpose of scribe notes is to transcribe our lectures. Although I have formal notes of my

### Proof: A logical argument establishing the truth of the theorem given the truth of the axioms and any previously proven theorems.

Math 232 - Discrete Math 2.1 Direct Proofs and Counterexamples Notes Axiom: Proposition that is assumed to be true. Proof: A logical argument establishing the truth of the theorem given the truth of the

### First-Order Predicate Logic (2)

First-Order Predicate Logic (2) Predicate Logic (2) Understanding first-order predicate logic formulas. Satisfiability and undecidability of satisfiability. Tautology, logical consequence, and logical

### Translating a Subset of OCaml into System F. Jonatha Protzenk under the dire ion of François Po ier

Translating a Subset of OCaml into System F Jonatha Protzenk under the dire ion of François Po ier June I Some background 1 Motivations Contents I Some background 2 1 Motivations 2 2 A high-level description

### Artificial Intelligence Automated Reasoning

Artificial Intelligence Automated Reasoning Andrea Torsello Automated Reasoning Very important area of AI research Reasoning usually means deductive reasoning New facts are deduced logically from old ones

### Chapter 7: Functional Programming Languages

Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language

### Satisfiability and Validity

6.825 Techniques in Artificial Intelligence Satisfiability and Validity Lecture 4 1 Last time we talked about propositional logic. There's no better way to empty out a room than to talk about logic. So

### Linearly Used Effects: Monadic and CPS Transformations into the Linear Lambda Calculus

Linearly Used Effects: Monadic and CPS Transformations into the Linear Lambda Calculus Masahito Hasegawa Research Institute for Mathematical Sciences, Kyoto University hassei@kurimskyoto-uacjp Abstract

### Foundations of Computing Discrete Mathematics Solutions to exercises for week 2

Foundations of Computing Discrete Mathematics Solutions to exercises for week 2 Agata Murawska (agmu@itu.dk) September 16, 2013 Note. The solutions presented here are usually one of many possiblities.

facultad de informática universidad politécnica de madrid On the Confluence of CHR Analytical Semantics Rémy Haemmerlé Universidad olitécnica de Madrid & IMDEA Software Institute, Spain TR Number CLI2/2014.0

### It is not immediately obvious that this should even give an integer. Since 1 < 1 5

Math 163 - Introductory Seminar Lehigh University Spring 8 Notes on Fibonacci numbers, binomial coefficients and mathematical induction These are mostly notes from a previous class and thus include some

### Full and Complete Binary Trees

Full and Complete Binary Trees Binary Tree Theorems 1 Here are two important types of binary trees. Note that the definitions, while similar, are logically independent. Definition: a binary tree T is full

### Geometry - Chapter 2 Review

Name: Class: Date: Geometry - Chapter 2 Review Multiple Choice Identify the choice that best completes the statement or answers the question. 1. Determine if the conjecture is valid by the Law of Syllogism.

### Jieh Hsiang Department of Computer Science State University of New York Stony brook, NY 11794

ASSOCIATIVE-COMMUTATIVE REWRITING* Nachum Dershowitz University of Illinois Urbana, IL 61801 N. Alan Josephson University of Illinois Urbana, IL 01801 Jieh Hsiang State University of New York Stony brook,

### Verifying security protocols using theorem provers

1562 2007 79-86 79 Verifying security protocols using theorem provers Miki Tanaka National Institute of Information and Communications Technology Koganei, Tokyo 184-8795, Japan Email: miki.tanaka@nict.go.jp

### DISCRETE MATHEMATICS W W L CHEN

DISCRETE MATHEMATICS W W L CHEN c W W L Chen, 1982, 2008. This chapter originates from material used by the author at Imperial College, University of London, between 1981 and 1990. It is available free

### Semantic Errors in SQL Queries: A Quite Complete List

Semantic Errors in SQL Queries: A Quite Complete List Christian Goldberg, Stefan Brass Martin-Luther-Universität Halle-Wittenberg {goldberg,brass}@informatik.uni-halle.de Abstract We investigate classes

### 2. Propositional Equivalences

2. PROPOSITIONAL EQUIVALENCES 33 2. Propositional Equivalences 2.1. Tautology/Contradiction/Contingency. Definition 2.1.1. A tautology is a proposition that is always true. Example 2.1.1. p p Definition

### Satisfiability Checking

Satisfiability Checking First-Order Logic Prof. Dr. Erika Ábrahám RWTH Aachen University Informatik 2 LuFG Theory of Hybrid Systems WS 14/15 Satisfiability Checking Prof. Dr. Erika Ábrahám (RWTH Aachen

### Relations: their uses in programming and computational specifications

PEPS Relations, 15 December 2008 1/27 Relations: their uses in programming and computational specifications Dale Miller INRIA - Saclay & LIX, Ecole Polytechnique 1. Logic and computation Outline 2. Comparing

### Mathematical Induction

MCS-236: Graph Theory Handout #A5 San Skulrattanakulchai Gustavus Adolphus College Sep 15, 2010 Mathematical Induction The following three principles governing N are equivalent. Ordinary Induction Principle.

### Extraction of certified programs with effects from proofs with monadic types in Coq

Extraction of certified programs with effects from proofs with monadic types in Coq Marino Miculan 1 and Marco Paviotti 2 1 Dept. of Mathematics and Computer Science, University of Udine, Italy 2 IT University

### SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION Alessandro Artale UniBZ - http://www.inf.unibz.it/ artale/ SECTION 5.2 Mathematical Induction I Copyright Cengage Learning. All rights reserved.

### CHAPTER 2. Inequalities

CHAPTER 2 Inequalities In this section we add the axioms describe the behavior of inequalities (the order axioms) to the list of axioms begun in Chapter 1. A thorough mastery of this section is essential

### MATH 55: HOMEWORK #2 SOLUTIONS

MATH 55: HOMEWORK # SOLUTIONS ERIC PETERSON * 1. SECTION 1.5: NESTED QUANTIFIERS 1.1. Problem 1.5.8. Determine the truth value of each of these statements if the domain of each variable consists of all

### For the purposes of this course, the natural numbers are the positive integers. We denote by N, the set of natural numbers.

Lecture 1: Induction and the Natural numbers Math 1a is a somewhat unusual course. It is a proof-based treatment of Calculus, for all of you who have already demonstrated a strong grounding in Calculus

### Mathematics for Computer Science

mcs 01/1/19 1:3 page i #1 Mathematics for Computer Science revised Thursday 19 th January, 01, 1:3 Eric Lehman Google Inc. F Thomson Leighton Department of Mathematics and the Computer Science and AI Laboratory,

### Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Functional Programming Languages Chapter 14 Introduction Functional programming paradigm History Features and concepts Examples: Lisp ML 1 2 Functional Programming Functional Programming Languages The

### o-minimality and Uniformity in n 1 Graphs

o-minimality and Uniformity in n 1 Graphs Reid Dale July 10, 2013 Contents 1 Introduction 2 2 Languages and Structures 2 3 Definability and Tame Geometry 4 4 Applications to n 1 Graphs 6 5 Further Directions

### Section 7.1 First-Order Predicate Calculus predicate Existential Quantifier Universal Quantifier.

Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially or universally. A predicate describes a

### Predicate Logic. PHI 201 Introductory Logic Spring 2011

Predicate Logic PHI 201 Introductory Logic Spring 2011 This is a summary of definitions in Predicate Logic from the text The Logic Book by Bergmann et al. 1 The Language PLE Vocabulary The vocabulary of

### 3. Recurrence Recursive Definitions. To construct a recursively defined function:

3. RECURRENCE 10 3. Recurrence 3.1. Recursive Definitions. To construct a recursively defined function: 1. Initial Condition(s) (or basis): Prescribe initial value(s) of the function.. Recursion: Use a

### (Refer Slide Time 1.50)

Discrete Mathematical Structures Dr. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras Module -2 Lecture #11 Induction Today we shall consider proof

### Introduction to Proofs

Chapter 1 Introduction to Proofs 1.1 Preview of Proof This section previews many of the key ideas of proof and cites [in brackets] the sections where they are discussed thoroughly. All of these ideas are