DOC PREVIEW
Penn CIS 500 - CIS 500 LECTURE NOTES

This preview shows page 1-2-3-4-29-30-31-32-33-60-61-62-63 out of 63 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Any Questions?More on TypesThe Simply Typed Lambda-CalculusCIS 500Software FoundationsFall 2006October 4Any Questions?More on TypesReview: Typing Rulestrue : Bool(T-True)false : Bool(T-False)t1: Bool t2: T t3: Tif t1then t2else t3: T(T-If)0 : Nat(T-Zero)t1: Natsucc t1: Nat(T-Succ)t1: Natpred t1: Nat(T-Pred)t1: Natiszero t1: Bool(T-IsZero)Review: InversionLemma:1. If true : R, then R = Bool.2. If false : R, then R = Bool.3. If if t1then t2else t3: R, then t1: Bool, t2: R, andt3: R.4. If 0 : R, then R = Nat.5. If succ t1: R, then R = Nat and t1: Nat.6. If pred t1: R, then R = Nat and t1: Nat.7. If iszero t1: R, then R = Bool and t1: Nat.Canonical FormsLemma:1. If v is a value of type Bool, then v is either true or false.2. If v is a value of type Nat, then v is a numeric value.Proof:Recall the syntax of values:v ::= valuestrue true valuefalse false valuenv numeric valuenv ::= numeric values0 zero valuesucc nv successor valueFor part 1, if v is true or false, the result is immediate. But vcannot be 0 or succ nv, since the inversion lemma tells us that vwould then have type Nat, not Bool. Part 2 is similar.Canonical FormsLemma:1. If v is a value of type Bool, then v is either true or false.2. If v is a value of type Nat, then v is a numeric value.Proof: Recall the syntax of values:v ::= valuestrue true valuefalse false valuenv numeric valuenv ::= numeric values0 zero valuesucc nv successor valueFor part 1,if v is true or false, the result is immediate. But vcannot be 0 or succ nv, since the inversion lemma tells us that vwould then have type Nat, not Bool. Part 2 is similar.Canonical FormsLemma:1. If v is a value of type Bool, then v is either true or false.2. If v is a value of type Nat, then v is a numeric value.Proof: Recall the syntax of values:v ::= valuestrue true valuefalse false valuenv numeric valuenv ::= numeric values0 zero valuesucc nv successor valueFor part 1, if v is true or false, the result is immediate.But vcannot be 0 or succ nv, since the inversion lemma tells us that vwould then have type Nat, not Bool. Part 2 is similar.Canonical FormsLemma:1. If v is a value of type Bool, then v is either true or false.2. If v is a value of type Nat, then v is a numeric value.Proof: Recall the syntax of values:v ::= valuestrue true valuefalse false valuenv numeric valuenv ::= numeric values0 zero valuesucc nv successor valueFor part 1, if v is true or false, the result is immediate. But vcannot be 0 or succ nv, since the inversion lemma tells us that vwould then have type Nat, not Bool.Part 2 is similar.Canonical FormsLemma:1. If v is a value of type Bool, then v is either true or false.2. If v is a value of type Nat, then v is a numeric value.Proof: Recall the syntax of values:v ::= valuestrue true valuefalse false valuenv numeric valuenv ::= numeric values0 zero valuesucc nv successor valueFor part 1, if v is true or false, the result is immediate. But vcannot be 0 or succ nv, since the inversion lemma tells us that vwould then have type Nat, not Bool. Part 2 is similar.ProgressTheorem: Suppose t is a well-typed term (that is, t : T for sometype T). Then either t is a value or else there is some t0witht −→ t0.Proof: By induction on a derivation of t : T.The T-True, T-False, and T-Zero cases are immediate, sincet in these cases is a value.Case T-If: t = if t1then t2else t3t1: Bool t2: T t3: TBy the induction hypothesis, either t1is a value or else there issome t01such that t1−→ t01. If t1is a value, then the canonicalforms lemma tells us that it must be e ither true or false, inwhich case either E-IfTrue or E-IfFalse applies to t. On theother hand, if t1−→ t01, then, by E-If,t −→ if t01then t2else t3.ProgressTheorem: Suppose t is a well-typed term (that is, t : T for sometype T). Then either t is a value or else there is some t0witht −→ t0.Proof:By induction on a derivation of t : T.The T-True, T-False, and T-Zero cases are immediate, sincet in these cases is a value.Case T-If: t = if t1then t2else t3t1: Bool t2: T t3: TBy the induction hypothesis, either t1is a value or else there issome t01such that t1−→ t01. If t1is a value, then the canonicalforms lemma tells us that it must be e ither true or false, inwhich case either E-IfTrue or E-IfFalse applies to t. On theother hand, if t1−→ t01, then, by E-If,t −→ if t01then t2else t3.ProgressTheorem: Suppose t is a well-typed term (that is, t : T for sometype T). Then either t is a value or else there is some t0witht −→ t0.Proof: By induction on a derivation of t : T.The T-True, T-False, and T-Zero cases are immediate, sincet in these cases is a value.Case T-If: t = if t1then t2else t3t1: Bool t2: T t3: TBy the induction hypothesis, either t1is a value or else there issome t01such that t1−→ t01. If t1is a value, then the canonicalforms lemma tells us that it must be e ither true or false, inwhich case either E-IfTrue or E-IfFalse applies to t. On theother hand, if t1−→ t01, then, by E-If,t −→ if t01then t2else t3.ProgressTheorem: Suppose t is a well-typed term (that is, t : T for sometype T). Then either t is a value or else there is some t0witht −→ t0.Proof: By induction on a derivation of t : T.The T-True, T-False, and T-Zero cases are immediate, sincet in these cases is a value.Case T-If: t = if t1then t2else t3t1: Bool t2: T t3: TBy the induction hypothesis, either t1is a value or else there issome t01such that t1−→ t01. If t1is a value, then the canonicalforms lemma tells us that it must be e ither true or false, inwhich case either E-IfTrue or E-IfFalse applies to t. On theother hand, if t1−→ t01, then, by E-If,t −→ if t01then t2else t3.ProgressTheorem: Suppose t is a well-typed term (that is, t : T for sometype T). Then either t is a value or else there is some t0witht −→ t0.Proof: By induction on a derivation of t : T.The T-True, T-False, and T-Zero cases are immediate, sincet in these cases is a value.Case T-If: t = if t1then t2else t3t1: Bool t2: T t3: TBy the induction hypothesis, either t1is a value or else there issome t01such that t1−→ t01. If t1is a value, then the canonicalforms lemma tells us that it must be e ither true or false, inwhich case either E-IfTrue or E-IfFalse applies to t. On theother hand, if t1−→ t01, then, by E-If,t −→ if t01then t2else t3.ProgressTheorem: Suppose t is a well-typed term (that is, t : T for sometype T). Then either t is a value or else there is some t0witht −→ t0.Proof: By induction on a derivation


View Full Document

Penn CIS 500 - CIS 500 LECTURE NOTES

Download CIS 500 LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CIS 500 LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CIS 500 LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?