Room Change!!!!

53
Room Change!!!! Starting Wednesday Room 302

description

Room Change!!!!. Starting Wednesday Room 302. Inductive Definitions. COS 441 Princeton University Fall 2004. Reminder. If you are not on the official class list send me email. Relations. A relation is set of tuples Odd = {1, 3, 5, … } Line = { (0.0, 0.0), (1.5,1.5), (x, x) , …} - PowerPoint PPT Presentation

Transcript of Room Change!!!!

Page 1: Room Change!!!!

Room Change!!!!

Starting Wednesday

Room 302

Page 2: Room Change!!!!

Inductive Definitions

COS 441

Princeton University

Fall 2004

Page 3: Room Change!!!!

Reminder

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

Page 4: Room Change!!!!

Relations

• A relation is set of tuplesOdd = {1, 3, 5, … }

Line = { (0.0, 0.0), (1.5,1.5), (x, x) , …}

Circle = { (x, y) | x2 + y2 = 1.0 }

• Odd is a predicate on natural numbers

• Line, Circle, and Sphere are relations on real numbers

• Line is a function

Page 5: Room Change!!!!

Judgments

• Given a relation R on objects x1,…,xn we say R(x1,…,xn) or (x1,…,xn) R to mean (x1,…,xn) 2 R

• The assertion R(x1,…,xn) or (x1,…,xn)R is a judgment

• The tuple (x1,…,xn) is an instance of the judgment form R

Page 6: Room Change!!!!

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?

Page 7: Room Change!!!!

Defining Relations

• Enumerate– Nice if you happen to be talking about finite

relations

• Directly via mathematical constraints– e.g. Circle = { (x,y) | x2 + y2 = 1.0 }

• Use inductive definitions– Not all relations have nice inductive definitions– Most of what we need for programming

languages fortunately do

Page 8: Room Change!!!!

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

Page 9: Room Change!!!!

Anatomy of a Rule

conclusionname

proper rule

(x1,X,…,xn) R(y1,X,…, yn) S … (z1,X,…,zn) T

axiom

conclusionpremises

name

name

rule schema

schematic variable

Page 10: Room Change!!!!

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

Page 11: Room Change!!!!

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

Page 12: Room Change!!!!

Example: Natural Numbers

succ(X)natX nat

Szero nat

Z

succ(succ(zero))natGoal:

Page 13: Room Change!!!!

Example: Natural Numbers

succ(X)natX nat

Szero nat

Z

succ(succ(zero))nat

Goal succ(zero)natS

X = succ(zero)Substitution

Page 14: Room Change!!!!

Example: Natural Numbers

succ(X)natX nat

Szero nat

Z

succ(succ(zero))nat

Goal

succ(zero)natS

zero natS

X = zeroSubstitution

Page 15: Room Change!!!!

Example: Natural Numbers

succ(X)natX nat

Szero nat

Z

succ(succ(zero))nat

Done

succ(zero)natS

zero natS

Z

Page 16: Room Change!!!!

Example: Natural Numbers

succ(succ(zero))natGoal:

Derivable Judgments:

{}

Page 17: Room Change!!!!

Example: Natural Numbers

succ(succ(zero))natGoal:

Derivable Judgments:

{zero nat}

Because:zero nat

Z

Page 18: Room Change!!!!

Example: Natural Numbers

succ(succ(zero))natGoal:

Derivable Judgments:

{zero nat, succ(zero)nat}

Because:

succ(zero)natzero nat

S

Z

Page 19: Room Change!!!!

Example: Natural Numbers

succ(succ(zero))natGoal:

Derivable Judgments:

{zero nat, succ(zero)nat,succ(succ(zero))nat }

Because:

succ(succ(zero))natsucc(zero)nat

S

zero natS

Z

Page 20: Room Change!!!!

Odd and Even Numbers

succ(X)oddX even

S-O

zero evenZ-E

succ(X)evenX odd

S-E

Derivable Judgments:

{zero even, succ(zero)odd,succ(succ(zero))even, … }

Page 21: Room Change!!!!

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

Page 22: Room Change!!!!

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

Page 23: Room Change!!!!

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).

Page 24: Room Change!!!!

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

Page 25: Room Change!!!!

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

Page 26: Room Change!!!!

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

Page 27: Room Change!!!!

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

Page 28: Room Change!!!!

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

Page 29: Room Change!!!!

1. zero even by axiom Z-E

Proof: zero odd or zero even

Page 30: Room Change!!!!

1. zero even by axiom Z-E

2. zero odd or zero even by (1)

Proof: zero odd or zero even

Page 31: Room Change!!!!

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

Page 32: Room Change!!!!

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

Page 33: Room Change!!!!

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

Page 34: Room Change!!!!

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

Page 35: Room Change!!!!

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

Page 36: Room Change!!!!

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

Page 37: Room Change!!!!

Reminder about Odd and Even

succ(X)oddX even

S-O

zero evenZ-E

succ(X)evenX odd

S-E

These are the only primitive rules for odd and even judgments.

Page 38: Room Change!!!!

A Derivable Rule

succ(succ(X))evensucc(X)odd

S-E

X evenS-O

X evenS-S-E

succ(succ(X))even

The rule

is derivable because

Page 39: Room Change!!!!

Underivable Rules

bogus1

zero odd

These rules are not derivable or admissible

X evenbogus2

succ(X) even

Page 40: Room Change!!!!

Underivable Rules

bogus1

zero odd

These rules are not derivable or admissible

The rule is not derivable

X evenbogus2

succ(X) even

succ(X)oddinvert-S-O

X even

Page 41: Room Change!!!!

Underivable Rules

bogus1

zero odd

These rules are not derivable or admissible

The rule is not derivable but is admissible

X evenbogus2

succ(X) even

succ(X)oddinvert-S-O

X even

Page 42: Room Change!!!!

Admissible Rule

The rule invert-S-O is admissible because

because ???

succ(X)oddinvert-S-O

X even

Page 43: Room Change!!!!

Admissible Rule

The rule invert-S-O is admissible because

because any complete derivation of succ(X)odd must

have ??? X even

succ(X)oddinvert-S-O

X even

Page 44: Room Change!!!!

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)oddinvert-S-O

X even

Page 45: Room Change!!!!

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

Page 46: Room Change!!!!

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)oddinvert-S-O

X even

Page 47: Room Change!!!!

Fixing an Admissible Rule

succ(X)oddinvert-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) evenS-N-O

succ(neg(X)) odd

N-Z-E

neg(zero) even

Page 48: Room Change!!!!

Be Careful!

succ(X)oddinvert-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

Page 49: Room Change!!!!

Be Careful!

succ(X)oddinvert-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

Page 50: Room Change!!!!

Be Careful!

succ(X)oddinvert-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 oddsilly1

X even

The rules below are also admissible or derivable

silly2

succ(one) even

Page 51: Room Change!!!!

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

Page 52: Room Change!!!!

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

Page 53: Room Change!!!!

Next Lecture

• Showing that a inductively defined relation is in fact a function

• Converting mathematical functions into functions in Standard ML