Slides 05 1 The Principal-Type Algorithm In general a typable term has an infinite set of types in TA. For example, it is possible to assign to I  x 

Slides:



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

Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Completeness and Expressiveness
Some important properties Lectures of Prof. Doron Peled, Bar Ilan University.
5.4 Basis And Dimension.
Finite-state Recognizers
Biointelligence Lab School of Computer Sci. & Eng.
10 October 2006 Foundations of Logic and Constraint Programming 1 Unification ­An overview Need for Unification Ranked alfabeths and terms. Substitutions.
AR for Horn clause logic Introducing: Unification.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
First Order Logic Resolution
Copyright © Cengage Learning. All rights reserved.
Basic properties of the integers
1.  Detailed Study of groups is a fundamental concept in the study of abstract algebra. To define the notion of groups,we require the concept of binary.
1.2 Row Reduction and Echelon Forms
Linear Equations in Linear Algebra
Chapter 4 Normal Forms for CFGs Chomsky Normal Form n Defn A CFG G = (V, , P, S) is in chomsky normal form if each rule in G has one of.
1 Applied Computer Science II Resolution in FOL Luc De Raedt.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CS5371 Theory of Computation
Slides 07 1 Restricted -terms and logics Definition (1D1) A -term P is called a I-term iff, for each subterm with the form x  M in P, x occurs free in.
Catriel Beeri Pls/Winter 2004/5 type reconstruction 1 Type Reconstruction & Parametric Polymorphism  Introduction  Unification and type reconstruction.
Validating Streaming XML Documents Luc Segoufin & Victor Vianu Presented by Harel Paz.
Slides 09 1 Counting the Inhabitants of a Type Given a type , how many closed -terms in  - normal form can receive the type  in TA ? There exists an.
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Type Inference David Walker CS 510, Fall Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Monadic Predicate Logic is Decidable Boolos et al, Computability and Logic (textbook, 4 th Ed.)
Slides 04 1 Deducibility in TA λ Definition (2A9) Let  be a type-context. If there is a TA -deduction of a formula  ' ↦ M:  for some  '   we shall.
12 INFINITE SEQUENCES AND SERIES The Comparison Tests In this section, we will learn: How to find the value of a series by comparing it with a known.
9.1 Solving Systems of Linear Equations by Substitution BobsMathClass.Com Copyright © 2010 All Rights Reserved. 1 Two linear equations in two variables.
Relations Chapter 9.
Deciding a Combination of Theories - Decision Procedure - Changki pswlab Combination of Theories Daniel Kroening, Ofer Strichman Presented by Changki.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
1 Preliminaries Precalculus Review I Precalculus Review II
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
Linear Algebra Chapter 4 Vector Spaces.
Database Systems Normal Forms. Decomposition Suppose we have a relation R[U] with a schema U={A 1,…,A n } – A decomposition of U is a set of schemas.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
1 2. Independence and Bernoulli Trials Independence: Events A and B are independent if It is easy to show that A, B independent implies are all independent.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Chapter 9. Section 9.1 Binary Relations Definition: A binary relation R from a set A to a set B is a subset R ⊆ A × B. Example: Let A = { 0, 1,2 } and.
Advanced Topics in Propositional Logic Chapter 17 Language, Proof and Logic.
First Order Predicate Logic
Chapter 5 – Relations and Functions. 5.1Cartesian Products and Relations Definition 5.1: For sets A, B  U, the Cartesian product, or cross product, of.
Section 2.3 Properties of Solution Sets
第 1 6 章 谓词演算中的归结. 2 Outline Unification Predicate-Calculus Resolution Completeness and Soundness Converting Arbitrary wffs to Clause Form Using Resolution.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
UNIT - 2.  A binary operation on a set combines two elements of the set to produce another element of the set. a*b  G,  a, b  G e.g. +, -, ,  are.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Other Access Control Models
NP-Completness Turing Machine. Hard problems There are many many important problems for which no polynomial algorithms is known. We show that a polynomial-time.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding Combined Theories.
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
FUNCTIONS COSC-1321 Discrete Structures 1. Function. Definition Let X and Y be sets. A function f from X to Y is a relation from X to Y with the property.
Converting arbitrary wffs to CNF A wff is in prenex form iff it consists of a string of quantifiers (called a prefix) followed by a quantifier free formula.
1 1.2 Linear Equations in Linear Algebra Row Reduction and Echelon Forms © 2016 Pearson Education, Ltd.
1 Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially.
1 Recap lecture 28 Examples of Myhill Nerode theorem, Quotient of a language, examples, Pseudo theorem: Quotient of a language is regular, prefixes of.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
 2004 SDU Uniquely Decodable Code 1.Related Notions 2.Determining UDC 3.Kraft Inequality.
Relations Chapter 9 Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill.
Relations Chapter 9.
Copyright © Cengage Learning. All rights reserved.
Chapter 2 Sets and Functions.
Soundness of SLD-Resolution
Presentation transcript:

Slides 05 1 The Principal-Type Algorithm In general a typable term has an infinite set of types in TA. For example, it is possible to assign to I  x  x every type with the form , by the following deduction: x:  ↦ x:   (  I) ↦ ( x  x):  All the types in this infinite set are substitution- instances of the one type a  a.

Slides 05 2 By the subject-construction theorem, every deduction for I must have the simple form shown before. The type a  a is called a principal type for I. The existence of a principal type is a property of all typable terms, not just I. The principal type of a term is the most general type it can receive in TA. We shall learn that every typable term has a principal type.

Slides 05 3 A principal-type (PT) or type-checking algorithm will decide whether a given term M is typable and, if the answer is "yes", will output a principal type for M. The existence of a PT algorithm is what gives TA and its extensions such as Haskell and ML their practical value, since if the typability of a program is regarded as a safety criterion then the programmer will want to be able to decide effectively whether a newly created program satisfies this criterion. In order to understand the PT algorithm, we need the knowledge of substitution and unification.

Slides 05 4 Definition (3A1) A type-substitution s is any expression [  1 /a 1,...,  n /a n ], where a 1,..., a n are distinct type-variables and  1,...,  n are any types. For any  we define s (  ) to be the type obtained by simultaneously substituting  1 for a 1,...,  n for a n throughout . In more detail, we define i.s (a i )   i ii.s (b)  b if b is an atom  {a 1,..., a n } iii.s (  )  s (  )  s (  ). We call s (  ) an instance of .

Slides 05 5 Example: Let s  [(a  b)/c] and   (a  b)  (b  c)  a  c, then s (  )  (a  b)  (b  a  b)  a  a  b.

Slides 05 6 The case n = 0 is called the empty substitution, e. e (  )  . If n = 1, s will be called a single substitution. Each part-expression  i /a i of s will be called a component of s, and called trivial if  i  a i. If all trivial components are deleted from s the resulting substitution will be called the nontrivial kernel of s. {a 1,..., a n }: Dom( s ) Vars(  1,...,  n ): Range( s )

Slides 05 7 Definition (3A2) The action of a substitution s is extended to finite sequences of types, to type-contexts and to TA -formulas, as follows: s ( ) =, s (  ) = {x 1 : s (  1 ),..., x m : s (  m )} if  = {x 1 :  1,..., x m :  m }, s (  ↦ M:  ) = s (  ) ↦ M: s (  ). s (  ) is the result of applying s to every TA -formula in deduction .

Slides 05 8 Besides the concept of substitution s for type-variables just mentioned, we also have the concept of substitution for term- variables. Lemma (2B6) Let  1 be consistent with  2 and let  1, x:  ⊢ M: ,  2 ⊢ N:  then  1   2 ⊢ [N/x]M: .

Slides 05 9 Definition (3A3) In TA, a principal type or PT of a term M is a type  such that i.  ⊢ M:  for some , ii.if  ' ⊢ M:  for some  ' and , then  is an instance of . A PT of M completely characterizes the set of all types assignable to M.

Slides Example: a  b  a is a PT of xy  x Is there a PT for x  xx?

Slides Definition (3A4) A principal pair for a term M is a pair such that the formula  ↦ M:  is TA -deducible and every other TA -deducible formula  ' ↦ M:  is an instance of  ↦ M: . Example: is a principal pair for xy  x.

Slides Definition (3A5) A principal deduction for a term M is a deduction  of a formula  ↦ M:  such that every other deduction, whose conclusion's subject is M, is an instance of . To abbreviate "there exists a principal deduction of  ↦ M:  ", we shall write  ⊢ p M: . We will see that a typable term M has not only a most general type but also a deduction whose every step is most general.

Slides Principal-Type Theorem (3A6) Every typable term has a principal deduction and a principal type in TA. Further, there is an algorithm that will decide whether a given -term M is typable in TA, and if the answer is "yes", will output a principal deduction and principal type for M.

Slides More details on type-substitution Definition (3B2) Substitutions s and t are extensionally equivalent ( s = ext t ) iff s (  )  t (  ) for all . Lemma (3B2.1) (i) b  Dom( s )  s (b)  b. (ii) s = ext t iff s and t have the same non-trivial kernel.

Slides Definition (3B3) If s  [  1 /a 1,...,  n /a n ] and V is a given set of variables, the restriction s ↾V of s to V is the substitution consisting of the components  i /a i of s such that a i  V. Lemma (3B3.1) ( s ↾Vars(  ))(  )  s (  ).

Slides Definition (3B4) If s  [  1 /a 1,...,  n /a n ] and t  [  1 /b 1,...,  p /b p ] and either a 1,..., a n, b 1,..., b p are all distinct or a i  b j   i   j, we define s  t  [  1 /a 1,...,  n /a n,  1 /b 1,...,  p /b p ] with repetitions omitted. Lemma (3B4.1) (i) Dom( s  t ) = Dom( s )  Dom( t ). (ii) If s = ext s' and t = ext t' and s  t is defined, then so is s '  t' and s  t = ext s'  t'.

Slides The composition of two substitutions s and t is a simultaneous substitution that will have the same effect as applying t and s in succession. Definition (3B5) If s and t are any substitutions, say s  [  1 /a 1,...,  n /a n ] and t  [  1 /b 1,...,  p /b p ], we define s ∘ t  [  i1 /a i1,...,  ih /a ih, s (  1 )/b 1,..., s (  p )/b p ] where {a i1,..., a ih } = Dom( s )-Dom( t ) and 0  h  n.

Slides Example: s  [(c  d)/a,(b  a)/b], t  [(b  a)/b]   a  b s ( t (  ))  (c  d)  (b  a)  (c  d) s ∘ t  [(c  d)/a,( s (b  a))/b]  [(c  d)/a,((b  a)  (c  d))/b] ( s ∘ t )(  )  (c  d)  (b  a)  (c  d) But ( s  t )(  )  s (  )  (c  d)  b  a

Slides [a/b] ∘ [b/a]  ?   a  b ([a/b] ∘ [b/a])(  )  ? [a/b]([b/a](  ))  ?

Slides Lemma (3B5.1) 1.Dom(s∘t) = Dom(s) ∪ Dom(t). 2.(s∘t)(  )  s(t(  )). This also means an instance of an instance of  is an instance of . 3.r∘(s∘t) = ext (r∘s)∘t. 4.s = ext s', t = ext t'  s∘t = ext s'∘t'.

Slides The next lemma, which is important in the correctness proof of the PT algorithm, says that if a composition s∘t is extended to r  (s∘t), the extended substitution can also be expressed as a composition with t, under certain conditions on r to prevent clashes. Lemma (3B6:composition-extension) Let r, s, t be substitutions such that (i)Dom(r)  (Dom(s)  Dom(t)) = , (ii)Dom(r)  Range(t) = . Then r  (s∘t) and (r  s)∘t are both defined and r  (s∘t)  (r  s)∘t.

Slides Definition (3B7) A variables-for-variables substitution is a substitution s  [b 1 /a 1,..., b n /a n ] where b 1,..., b n are variables (not necessarily distinct). If b 1,..., b n are distinct, s is called one-to-one, and if also {a 1,..., a n } = Vars(  ) for a given , s is called a renaming in . Note: A one-to-one substitution may be a renaming in one type but not in another. For example, [b/a] is a renaming in a  a but not in a  b.

Slides Definition (3B8) We say  is an alphabetic variant of , or  and  are identical modulo renaming, iff   s(  ) for some renaming s in . Lemma (3B8.2: Uniqueness) Let  be a principal type of a term M. Then  is unique modulo renaming.

Slides Main ideas for the PT algorithm The two main steps in the PT algorithm: 1.the computation of PT( x  M) from PT(M), 2.the computation of PT(PQ) from PT(P) and PT(Q). The first is easy, the second needs more work which is the core of the PT algorithm.

Slides Suppose we are trying to decide whether an application PQ is typable in TA, and we already know that PT(P)  ,PT(Q)  . For simplicity suppose PQ has no free variables. Then the types assignable to P are generated from  by substitution and those assignable to Q are generated from . Hence, if we can find substitutions s 1 and s 2 such that s 1 (  )  s 2 (  ), we will be able to deduce a type for PQ by rule (  E), as follows: ↦ P:s 1 (  )  s 1 (  ) ↦ Q:s 2 (  )  (  E) ↦ PQ:s 1 (  )

Slides Thus the problem of deciding whether PQ is typable reduces to that of finding substitutions s 1 and s 2 such that s 1 (  )  s 2 (  ). This suggests the next two definitions.

Slides Definition (3C2) (i) If  s 1 (  )  s 2 (  ) we call a common instance (c.i.) of the pair, and we call a pair of converging substitutions for. (ii)If  s 1 ( )  s 2 ( ) we call a common instance of and. Example: A c.i. of is the type ((  )  )  (  ), and the corresponding converging substitutions are s 1  [((  )  )/a,  /b,  /c], s 2  [(  )/a,  /b].

Slides Does every pair of types has a common instance? No. For example the pair has none.

Slides Definition (3C3) A most general common instance (m.g.c.i) of is a common instance 0 such that every other common instance is an instance of 0. If 0 is an m.g.c.i. of we call any pair such that s 1 (  )  s 2 (  )  0 an m.g.c.i.-generator for. M.g.c.i.'s are unique modulo renaming.

Slides Example: The pair has an m.g.c.i m 0  ((  )  )  (  ). Proof: Let   a  (b  c),   (a  b)  a. In slide 27 we have shown that m 0 is a c.i. of  and . To show that m 0 is most general, let m be any other c.i., then we have m  s 1 (a)  (s 1 (b)  s 1 (c))  (s 2 (a)  s 2 (b))  s 2 (a), which gives s 1 (a)  s 2 (a)  s 2 (b), s 2 (a)  s 1 (b)  s 1 (c). Therefore, s 1 (a)  (s 1 (b)  s 1 (c))  s 2 (b) and m  ((s 1 (b)  s 1 (c))  s 2 (b))  (s 1 (b)  s 1 (c)). Thus, m is an instance of m 0. 

Slides The problem of finding PT(PQ) reduces to that of finding an m.g.c.i of. We will need Robinson's unification algorithm.

Slides Definition (3D1) (i) If there is a substitution s such that s(  )  s(  ) we say is unifiable; we call any such s a unifier of and call s(  ) a unification of. (ii)A unifier of a pair of sequences, > is a substitution s such that s( )  s( ).

Slides Note: A unification of is just a c.i. obtained by making the same substitution in  as in . But not every c.i. is a unification. A pair may have a c.i. but no unifier. For example, consider   a  (b  c),   (a  b)  a. We have seen in slide 27 that this pair has a c.i.; but no substitution s can exist such that s(  )  s(  ), because this would imply s(a)  s(a)  s(b) which is impossible.

Slides Definition (3D2) A most general unifier (m.g.u.) of is a unifier u such that for every other unifier s of we have s(  )  s'(u(  )) for some s'. If  u(  ) for some m.g.u. u of we call a most general unification of. Lemma If u is an m.g.u. of and v is a renaming of variables in u(  ), then v∘u is an m.g.u. of.

Slides The m.g.u. of a pair may differ from its m.g.c.i. However, in the special case that  and  have no common variables, every c.i. is also a unification. Why? Because if  s 1 (  )  s 2 (  ) and Dom(s 1 )  Vars(  ) and Dom(s 2 )  Vars(  ) then s 1  s 2 is defined and  (s 1  s 2 )(  )  (s 1  s 2 )(  ).

Slides Lemma (3D3) (i)If  and  have no common variables, has an m.g.u. iff it has an m.g.c.i., and the two are identical. (ii)For all  and  : if we change  to an alphabetic variant  * with no variables in common with , the unifications of will be exactly the common instances of and the most general unification of will be the m.g.c.i. of. Thus the problem of finding m.g.c.i.'s has been reduced to that of finding most general unifications of pairs with no variables in common.

Slides Unification Theorem (3D4) (i)There is an algorithm which decides whether a pair of types has a unifier, and, if the answer is "yes", constructs its m.g.u. (ii)If a pair has a unifier it has an m.g.u. (iii)Parts (i) and (ii) hold also for pairs of deductions and for pairs of finite type- sequences.

Slides Unification Algorithm (Robinson 1965) Input: any pair of types. Output: either a correct statement that is not unifiable or an m.g.u. u of. Step 0. Choose k = 0 and u 0  e (the empty substitution). Step k+1. Given k and u k, construct  k  u k (  ) and  k  u k (  ), and apply the comparison procedure to. That procedure will output either a correct statement that  k   k or a disagreement pair such that  ≢ a. If  k   k, choose u  u k. If  k ≢  k and the output of the comparison procedure is, decide whether a  Vars(  ). If a  Vars(  ), state that is not unifiable and stop. If a  Vars(  ), then replace k by k+1, choose u k+1  [  /a]∘u k, and go to Step k+2.

Slides Comparison Procedure Given a pair of types, write  and as symbol-strings, say   s 1...s m,  t 1...t n (m, n  1) where each of s 1,..., s m, t 1,..., t n is an occurrence of a parenthesis, arrow or variable. If  , then state that   and stop. If  ≢, choose the least p  Min{m,n} such that s p ≢ t p. One of s p, t p must be a variable and the other must be a left parenthesis or a different variable. Further, s p is the leftmost symbol of a unique subtype  * of . (If s p is a variable,  *  s p.) Similarly t p is the leftmost symbol of a unique subtype * of. Choose one of  *, * that is a variable and call it "a". (If both are variables, choose the one that is first in the alphabet.) Then call the remaining member of "  "; the pair is called the disagreement pair for.

Slides the PT algorithm Input: any -term M, closed or not. Output: either a principal deduction  M for M or a correct statement that M is not typable. Case I. If M is a variable, say M  x, choose  M to be the one- formula deduction x:a ↦ x:a, where a is any type-variable. Case II. If M  x  P and x  FV(P), say FV(P) = {x, x 1,..., x t }, apply the algorithm to P. If P is not typable, neither is M. If P has a principal deduction  P its conclusion must have the form x: , x 1 :  1,..., x t :  t ↦ P:  for some types ,  1,...,  t, . Apply rule (  I) main to make a deduction of x 1 :  1,..., x t :  t ↦ ( x  P): . Call this deduction  xP.

Slides Case III. If M  x  P and x  FV(P), say FV(P) = {x 1,..., x t }, apply the algorithm to P. If P is not typable, neither is M. If P has a principal deduction  P its conclusion must have the form x 1 :  1,..., x t :  t ↦ P:  for some types  1,...,  t, . Choose a new type-variable d not in  P and apply (  I) vac, vacuously discharging x:d, to get a deduction of x 1 :  1,..., x t :  t ↦ ( x  P):d . Call this deduction  xP.

Slides Case IV. If M  PQ, apply the algorithm to P and Q. If P or Q is untypable then so is M. If P and Q are both typable, suppose they have principal deductions  P and  Q. First rename type-variables, if necessary, to ensure that  P and  Q have no common type-variables. Next list the free term-variables in P and those in Q (noting that these lists may overlap); say FV(P) = {u 1,..., u p, w 1,..., w r } (p, r  0), FV(Q) = {v 1,..., v q, w 1,..., w r } (q  0), where u 1,..., u p, v 1,..., v q, w 1,..., w r are distinct.

Slides Subcase IVa. M  PQ and PT(P) is composite, say PT(P)  . Then the conclusions of  P and  Q have the form, respectively, (1)u 1 :  1,..., u p :  p, w 1 :  1,..., w r :  r ↦ P: , (2)v 1 :  1,..., v q :  q, w 1 :  1,..., w r :  r ↦ Q: . Apply the unification algorithm to the pair of sequences (3),. Subcase IVa1. The pair (3) has no unifier. Then PQ is not typable.

Slides Subcase IVa2. The pair (3) has a unifier. Then the unification algorithm gives a most general unifier u; apply a renaming if necessary to ensure that (4) Dom(u) = Vars(  1,...,  r, ,  1,...,  r,  ), (5)Range(u)  V = , where (6) V = (Vars(  P )  Vars(  Q )) – Dom(u). Then apply u to  P and  Q ; this changes their conclusions to, respectively, u 1 :  1 *,..., u p :  p *, w 1 :  1 *,..., w r :  r * ↦ P:  *  *, v 1 :  1 *,..., v q :  q *, w 1 :  1 *,..., w r :  r * ↦ Q:  *, where  1 *  u(  1 ), etc. And by the definition of u we have  1 *   1 *,...,  r *   r *,  *   *. Hence (  E) can be applied to the conclusions of u(  P ) and u(  Q ). Call the resulting combined deduction  PQ ; its conclusion is (7)u 1 :  1 *,..., u p :  p *, v 1 :  1 *,..., v q :  q *, w 1 :  1 *,..., w r :  r * ↦ PQ:  *.

Slides Subcase IVb. M  PQ and PT(P) is atomic, say PT(P)  b. Then the conclusions of  P and  Q have the form, respectively, (8)u 1 :  1,..., u p :  p, w 1 :  1,..., w r :  r ↦ P:b, (9)v 1 :  1,..., v q :  q, w 1 :  1,..., w r :  r ↦ Q: . Choose any variable c  Vars(  P )  Vars(  Q ) and apply the unification algorithm to the pair of sequences (10),. Subcase IVb1. The pair (10) has no unifier. Then PQ is not typable.

Slides Subcase IVb2. The pair (10) has a unifier. Then the unification algorithm gives a most general unifier u; apply a renaming if necessary to ensure that (11) Dom(u) = Vars(  1,...,  r, b,  1,...,  r,  c), (12)Range(u)  V = , where V = (Vars(  P )  Vars(  Q )) – Dom(u). Then apply u to  P and  Q. By the definition of u, u(b)  u(  c)  u(  )  u(c), and thus the conclusions of u(  P ) and u(  Q ) are u 1 :  1 *,..., u p :  p *, w 1 :  1 *,..., w r :  r * ↦ P:  *  c*, v 1 :  1 *,..., v q :  q *, w 1 :  1 *,..., w r :  r * ↦ Q:  *, where * denotes application of the substitution u, and  1 *   1 *,...,  r *   r *. Hence (  E) can be applied to the conclusions of u(  P ) and u(  Q ). Call the resulting combined deduction  PQ ; its conclusion is u 1 :  1 *,..., u p :  p *, v 1 :  1 *,..., v q :  q *, w 1 :  1 *,..., w r :  r * ↦ PQ:c*.

Slides Theorem (3E3) The relation ⊢ M:  is decidable, i.e. there is an algorithm which accepts any M and  and decides whether or not ⊢ M: . Proof: Apply the PT algorithm to M. If M is not closed or not typable we cannot have ⊢ M: . If M is closed and typable, decide whether  is an instance of PT(M).

Slides Example: Apply the PT algorithm to check that the -term W  xy  xyy has the principal type (a  a  b)  a  b.