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

53
Room Change!!!! Starting Wednesday Room 302
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    214
  • download

    0

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

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

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

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?

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

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

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

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

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

Example: Natural Numbers

succ(X)natX nat

Szero nat

Z

succ(succ(zero))natGoal:

Example: Natural Numbers

succ(X)natX nat

Szero nat

Z

succ(succ(zero))nat

Goal succ(zero)natS

X = succ(zero)Substitution

Example: Natural Numbers

succ(X)natX nat

Szero nat

Z

succ(succ(zero))nat

Goal

succ(zero)natS

zero natS

X = zeroSubstitution

Example: Natural Numbers

succ(X)natX nat

Szero nat

Z

succ(succ(zero))nat

Done

succ(zero)natS

zero natS

Z

Example: Natural Numbers

succ(succ(zero))natGoal:

Derivable Judgments:

{}

Example: Natural Numbers

succ(succ(zero))natGoal:

Derivable Judgments:

{zero nat}

Because:zero nat

Z

Example: Natural Numbers

succ(succ(zero))natGoal:

Derivable Judgments:

{zero nat, succ(zero)nat}

Because:

succ(zero)natzero nat

S

Z

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

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, … }

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

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

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

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

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

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

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

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

1. zero even by axiom Z-E

Proof: zero odd or zero even

1. zero even by axiom Z-E

2. zero odd or zero even by (1)

Proof: zero odd or zero even

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

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

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

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

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

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

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.

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

Underivable Rules

bogus1

zero odd

These rules are not derivable or admissible

X evenbogus2

succ(X) even

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

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

Admissible Rule

The rule invert-S-O is admissible because

because ???

succ(X)oddinvert-S-O

X even

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

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

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

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

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

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

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

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

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

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

Next Lecture

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

• Converting mathematical functions into functions in Standard ML