Presentation is loading. Please wait.

Presentation is loading. Please wait.

Room Change!!!! Starting Wednesday Room 302. Inductive Definitions COS 441 Princeton University Fall 2004.

Similar presentations


Presentation on theme: "Room Change!!!! Starting Wednesday Room 302. Inductive Definitions COS 441 Princeton University Fall 2004."— Presentation transcript:

1 Room Change!!!! Starting Wednesday Room 302

2 Inductive Definitions COS 441 Princeton University Fall 2004

3 Reminder If you are not on the official class list send me email

4 Relations A relation is set of tuples Odd = {1, 3, 5, … } Line = { (0.0, 0.0), (1.5,1.5), (x, x), …} Circle = { (x, y) | x 2 + y 2 = 1.0 } Odd is a predicate on natural numbers Line, Circle, and Sphere are relations on real numbers Line is a function

5 Judgments Given a relation R on objects x 1,…,x n we say R(x 1,…,x n ) or (x 1,…,x n ) R to mean (x 1,…,x n ) 2 R The assertion R(x 1,…,x n ) or (x 1,…,x n )R is a judgment The tuple (x 1,…,x n ) is an instance of the judgment form R

6 Example Judgments Valid judgments: Odd(7), Line( ,  ), Circle(0.0,1.0), Sphere(1.0,0.0,0.0) Invalid judgments: Odd(2), Line(0.0,0.5) How do we determine if a judgment is valid or invalid? –From the definition of the relation How can we define relations?

7 Defining Relations Enumerate –Nice if you happen to be talking about finite relations Directly via mathematical constraints –e.g. Circle = { (x,y) | x 2 + y 2 = 1.0 } Use inductive definitions –Not all relations have nice inductive definitions –Most of what we need for programming languages fortunately do

8 Rules and Derivations Inductive definitions consist of a set of inference rules Inference rules are combined to form derivations trees A valid derivation leads to a conclusion which asserts a certain judgment is valid The set of all valid judgments for a relation implicitly defines the relation

9 Anatomy of a Rule conclusion name proper rule (x 1,X,…,x n ) R (y 1,X,…, y n ) S … (z 1,X,…,z n ) T axiom conclusion premises name rule schema schematic variable

10 Rule Schemas Schematic rules represent rule templates Schematic variables can be substituted with a primitive terms or other schematic variables All occurrences of a variable must be substituted with the same term or variable

11 Reasoning with Rules We can find derivations for a judgment via goal-directed search or enumeration Both approaches will eventually find derivations for valid judgments Neither approach knows when to stop Invalid judgments cause our algorithm to non-terminate

12 Example: Natural Numbers succ( X ) nat X nat S zero nat Z succ(succ(zero)) nat Goal:

13 Example: Natural Numbers succ( X ) nat X nat S zero nat Z succ(succ(zero)) nat Goal succ(zero) nat S X = succ(zero) Substitution

14 Example: Natural Numbers succ( X ) nat X nat S zero nat Z succ(succ(zero)) nat Goal succ(zero) nat S zero nat S X = zero Substitution

15 Example: Natural Numbers succ( X ) nat X nat S zero nat Z succ(succ(zero)) nat Done succ(zero) nat S zero nat SZ

16 Example: Natural Numbers succ(succ(zero)) nat Goal: Derivable Judgments: {}

17 Example: Natural Numbers succ(succ(zero)) nat Goal: Derivable Judgments: { zero nat} Because: zero nat Z

18 Example: Natural Numbers succ(succ(zero)) nat Goal: Derivable Judgments: { zero nat, succ(zero) nat} Because: succ(zero) nat zero nat SZ

19 Example: Natural Numbers succ(succ(zero)) nat Goal: Derivable Judgments: { zero nat, succ(zero) nat, succ(succ(zero)) nat } Because: succ(succ(zero)) nat succ(zero) nat S zero nat SZ

20 Odd and Even Numbers succ( X ) odd X even S-O zero even Z-E succ( X ) even X odd S-E Derivable Judgments: { zero even, succ(zero) odd, succ(succ(zero)) even, … }

21 Some Theorems about Numbers Theorems: –If X nat then X odd or X even –If X even then X nat –If X odd then X nat How do we prove the theorems above? –Note this is for the schematic variable X –The principal of rule inductions is what we use to show a property for any instantiation of X

22 Rule Induction for Naturals If X nat, P( zero ), and if P(Y) then P( succ( Y ) ) then P(X). Notice that P is a schematic variable for an arbitrary relation or proposition

23 Proof: If X nat then X odd or X even. If X nat, P( zero ), and if P(Y) then P( succ( Y ) ) then P(X).

24 Proof: If X nat then X odd or X even. If X nat, zero odd or zero even, and if P(Y) then P( succ( Y ) ) then P(X). Substitution P(x) = x odd or x even

25 Proof: If X nat then X odd or X even. If X nat, zero odd or zero even, and if (Y odd or Y even) then P( succ( Y ) ) then P(X). Substitution P(x) = x odd or x even

26 Proof: If X nat then X odd or X even. If X nat, zero odd or zero even, and if (Y odd or Y even) then succ( Y ) odd or succ( Y ) even then P(X). Substitution P(x) = x odd or x even

27 Proof: If X nat then X odd or X even. If X nat, zero odd or zero even, and if (Y odd or Y even) then succ( Y ) odd or succ( Y ) even then X odd or X even. Substitution P(x) = x odd or x even

28 If X nat, zero odd or zero even, and if (Y odd or Y even) then succ( Y ) odd or succ( Y ) even then X odd or X even. Proof: If X nat then X odd or X even. Subgoal 1 Subgoal 2

29 1. zero even by axiom Z-E Proof: zero odd or zero even

30 1. zero even by axiom Z-E 2. zero odd or zero even by (1) Proof: zero odd or zero even

31 1. Y odd or Y even by assumption 2. succ( Y ) odd or succ( Y ) even from (1) case Y odd 2.1. succ( Y ) even by rule S-E 2.2. succ( Y ) odd or succ(Y ) even by (2.1) case Y even 2.1. succ( Y ) odd by rule S-O 2.2. succ( Y ) odd or succ( Y ) even by (2.1) Proof: if (Y odd or Y even) then succ( Y ) odd or succ( Y ) even

32 1. Y odd or Y even by assumption 2. succ( Y ) odd or succ( Y ) even from (1) case Y odd 2.1. succ( Y ) even by rule S-E 2.2. succ( Y ) odd or succ(Y ) even by (2.1) case Y even 2.1. succ( Y ) odd by rule S-O 2.2. succ( Y ) odd or succ( Y ) even by (2.1) Proof: if (Y odd or Y even) then succ( Y ) odd or succ( Y ) even

33 1. Y odd or Y even by assumption 2. succ( Y ) odd or succ( Y ) even from (1) case Y odd 2.1. succ( Y ) even by rule S-E 2.2. succ( Y ) odd or succ(Y ) even by (2.1) case Y even 2.1. succ( Y ) odd by rule S-O 2.2. succ( Y ) odd or succ( Y ) even by (2.1) Proof: if (Y odd or Y even) then succ( Y ) odd or succ( Y ) even

34 1. Y odd or Y even by assumption 2. succ( Y ) odd or succ( Y ) even from (1) case Y odd 2.1. succ( Y ) even by rule S-E 2.2. succ( Y ) odd or succ( Y ) even by (2.1) case Y even 2.1. succ( Y ) odd by rule S-O 2.2. succ( Y ) odd or succ( Y ) even by (2.1) Proof: if (Y odd or Y even) then succ( Y ) odd or succ( Y ) even

35 1. Y odd or Y even by assumption 2. succ( Y ) odd or succ( Y ) even from (1) case Y odd 2.1. succ( Y ) even by rule S-E 2.2. succ( Y ) odd or succ( Y ) even by (2.1) case Y even 2.1. succ( Y ) odd by rule S-O 2.2. succ( Y ) odd or succ( Y ) even by (2.1) Proof: if (Y odd or Y even) then succ( Y ) odd or succ( Y ) even

36 Derivable and Admissible Rules The primitive rules Z and S define the predicate nat Other rules may be shown to be derivable or admissible wrt the primitive rules Derivable rules follow directly from a partial derivations of primitive rules Admissible rules are a consequence of the primitive rules that are not derivable

37 Reminder about Odd and Even succ( X ) odd X even S-O zero even Z-E succ( X ) even X odd S-E These are the only primitive rules for odd and even judgments.

38 A Derivable Rule succ(succ( X )) even succ( X ) odd S-E X even S-O X even S-S-E succ(succ( X )) even The rule is derivable because

39 Underivable Rules bogus1 zero odd These rules are not derivable or admissible X even bogus2 succ( X ) even

40 Underivable Rules bogus1 zero odd These rules are not derivable or admissible The rule is not derivable X even bogus2 succ( X ) even succ( X ) odd invert-S-O X even

41 Underivable Rules bogus1 zero odd These rules are not derivable or admissible The rule is not derivable but is admissible X even bogus2 succ( X ) even succ( X ) odd invert-S-O X even

42 Admissible Rule The rule invert-S-O is admissible because because ??? succ( X ) odd invert-S-O X even

43 Admissible Rule The rule invert-S-O is admissible because because any complete derivation of succ( X ) odd must have ??? X even succ( X ) odd invert-S-O X even

44 Admissible Rule The rule invert-S-O is admissible because because any complete derivation of succ( X ) odd must have used the rule S-O which requires X even as a premise succ( X ) odd invert-S-O X even

45 Admissible Rules Caveat Admissible rules are admissible with respect to a fixed set of primitive rules Adding a new primitive rule can change admissibility of previous rules Adding a new primitive rule does not effect derivability of previous rules

46 Breaking an Admissible Rule If we add this primitive rule to Z-E, S-O, and S-E The rule below is not admissible wrt Z-E,S-O,S-E, and S-N-O S-N-O succ(neg(zero)) odd succ( X ) odd invert-S-O X even

47 Fixing an Admissible Rule succ( X ) odd invert-S-O X even If we add these primitive rules to Z-E, S-O, and S-E The rule below is admissible wrt Z-E,S-O,S-E, S-N-O, and N-Z-E neg( X ) even S-N-O succ(neg( X )) odd N-Z-E neg(zero) even

48 Be Careful! succ( X ) odd invert-S-O X even If we add this primitive rules to Z-E, S-O, and S-E The rule below is ?? Z-O zero odd

49 Be Careful! succ( X ) odd invert-S-O X even If we add this primitive rules to Z-E, S-O, and S-E The rule below is still admissible wrt Z-E,S-O,S-E, and Z-O Z-O zero odd

50 Be Careful! succ( X ) odd invert-S-O X even If we add this primitive rules to Z-E, S-O, and S-E The rule below is still admissible wrt Z-E,S-O,S-E, and Z-O Z-O zero odd X odd silly1 X even The rules below are also admissible or derivable silly2 succ(one) even

51 Formal versus Informal Reasoning There is nothing technically bad about the rule Z-O However, it destroys our intuitions about even and odd numbers –We want to capture all of the intuitive properties and only those intuitive properties of even and odd numbers –Must craft our primitive rules to do this carefully

52 Lessons Learned Inductive definitions provide a concise way of describing mathematical relations Principle of rule induction provides a way of prove properties about inductively defined relations Must be careful about what primitives rules we choose so that the “right” rules are admissible and definable and the “wrong” rules are not

53 Next Lecture Showing that a inductively defined relation is in fact a function Converting mathematical functions into functions in Standard ML


Download ppt "Room Change!!!! Starting Wednesday Room 302. Inductive Definitions COS 441 Princeton University Fall 2004."

Similar presentations


Ads by Google