530 likes | 655 Views
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) , …}
E N D
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) , …} 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 Ron objects x1,…,xn we say R(x1,…,xn) or (x1,…,xn) R to mean (x1,…,xn) 2R • The assertion R(x1,…,xn) or (x1,…,xn)Ris a judgment • The tuple (x1,…,xn) is an instance of the judgment formR
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
name name (y1,X,…, yn) S … (z1,X,…,zn) T premises conclusion (x1,X,…,xn) R conclusion Anatomy of a Rule proper rule axiom rule schema name 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
S Z Xnat succ(X)nat zeronat Example: Natural Numbers succ(succ(zero))nat Goal:
S Z S Xnat succ(zero)nat succ(X)nat zeronat Example: Natural Numbers Substitution X = succ(zero) Goal succ(succ(zero))nat
S Z S S Xnat succ(zero)nat zeronat succ(X)nat zeronat Example: Natural Numbers Substitution X = zero Goal succ(succ(zero))nat
S Z S S Z Xnat succ(zero)nat zeronat succ(X)nat zeronat Example: Natural Numbers Done succ(succ(zero))nat
Example: Natural Numbers Derivable Judgments: {} succ(succ(zero))nat Goal:
Z Example: Natural Numbers Derivable Judgments: {zeronat} Because: zeronat succ(succ(zero))nat Goal:
S Z zeronat Example: Natural Numbers Derivable Judgments: {zeronat, succ(zero)nat} Because: succ(zero)nat succ(succ(zero))nat Goal:
S S Z succ(zero)nat zeronat Example: Natural Numbers Derivable Judgments: {zeronat, succ(zero)nat, succ(succ(zero))nat } Because: succ(succ(zero))nat succ(succ(zero))nat Goal:
S-O Z-E S-E Xeven Xodd succ(X)odd zeroeven succ(X)even Odd and Even Numbers Derivable Judgments: {zeroeven, succ(zero)odd, succ(succ(zero))even, … }
Some Theorems about Numbers • Theorems: • If Xnat then Xodd or Xeven • If Xeven then Xnat • If Xodd then Xnat • 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 IfXnat, P(zero), and ifP(Y) thenP(succ(Y)) thenP(X). Notice that P is a schematic variable for an arbitrary relation or proposition
Proof:If Xnat then Xodd or Xeven. IfXnat, P(zero), and ifP(Y) thenP(succ(Y)) thenP(X).
Proof:If Xnat then Xodd or Xeven. IfXnat, zerooddorzeroeven, and ifP(Y) thenP(succ(Y)) thenP(X). Substitution P(x) = x oddor x even
Proof:If Xnat then Xoddor Xeven. IfXnat, zerooddorzeroeven, and if (YoddorYeven)thenP(succ(Y)) thenP(X). Substitution P(x) = x oddor x even
Proof:If Xnat then Xoddor Xeven. IfXnat, zerooddorzeroeven, and if (YoddorYeven)then succ(Y)oddor succ(Y)even thenP(X). Substitution P(x) = x oddor x even
Proof:If Xnat then Xodd or Xeven. IfXnat, zerooddorzeroeven, and if (YoddorYeven)then succ(Y)oddor succ(Y)even thenX oddorXeven. Substitution P(x) = x odd or x even
Proof:If Xnat then Xoddor Xeven. Subgoal 1 IfXnat, zeroodd orzeroeven, and if (YoddorYeven)then succ(Y)oddor succ(Y)even thenXoddorXeven. Subgoal 2
Proof:zerooddorzeroeven • zeroeven by axiom Z-E
Proof:zerooddorzeroeven • zeroeven by axiom Z-E • zerooddorzeroeven by (1)
Proof:if (YoddorYeven)thensucc(Y)oddor succ(Y)even • Yodd orYeven by assumption • 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 (YoddorYeven)thensucc(Y)oddor succ(Y)even • YoddorYeven by assumption • succ(Y)oddor 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 (YoddorYeven)thensucc(Y)oddor succ(Y)even • Yodd orYeven by assumption • succ(Y)oddor succ(Y)even from (1) caseYodd 2.1. succ(Y) even by rule S-E 2.2. succ(Y) odd or succ(Y) even by (2.1) caseYeven 2.1. succ(Y) odd by rule S-O 2.2. succ(Y) odd or succ(Y) even by (2.1)
Proof:if (Y oddorYeven)thensucc(Y)odd or succ(Y)even • YoddorYeven by assumption • succ(Y)oddor succ(Y)even from (1) caseYodd 2.1. succ(Y)even by rule S-E 2.2. succ(Y) odd or succ(Y)even by (2.1) caseYeven 2.1. succ(Y) odd by rule S-O 2.2. succ(Y) odd or succ(Y) even by (2.1)
Proof:if (YoddorYeven)thensucc(Y)odd or succ(Y)even • YoddorYeven by assumption • succ(Y)oddor succ(Y)even from (1) caseYodd 2.1. succ(Y)even by rule S-E 2.2. succ(Y)odd or succ(Y) even by (2.1) caseYeven 2.1. succ(Y) odd by rule S-O 2.2. succ(Y)odd or succ(Y)even by (2.1)
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
S-O Z-E S-E Xeven Xodd succ(X)odd zeroeven succ(X)even Reminder about Odd and Even These are the only primitive rules for odd and even judgments.
S-E S-O S-S-E succ(succ(X))even succ(X)odd Xeven X even succ(succ(X))even A Derivable Rule The rule is derivable because
bogus1 bogus2 X even zero odd succ(X) even Underivable Rules These rules are not derivable or admissible
bogus1 bogus2 invert-S-O X even succ(X)odd zero odd succ(X) even X even Underivable Rules These rules are not derivable or admissible The rule is not derivable
bogus1 bogus2 invert-S-O X even succ(X)odd zero odd succ(X) even X even Underivable Rules These rules are not derivable or admissible The rule is not derivable but is admissible
invert-S-O succ(X)odd X even Admissible Rule The rule invert-S-O is admissible because because ???
invert-S-O succ(X)odd X even Admissible Rule The rule invert-S-O is admissible because because any completederivation of succ(X)odd must have ??? X even
invert-S-O succ(X)odd X even Admissible Rule The rule invert-S-O is admissible because because any completederivation of succ(X)odd must have used the rule S-O which requires X even as a premise
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
S-N-O invert-S-O succ(X)odd succ(neg(zero))odd X even 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
N-Z-E S-N-O invert-S-O succ(X)odd neg(X) even X even succ(neg(X))odd neg(zero)even Fixing an Admissible Rule 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
Z-O invert-S-O succ(X)odd X even zero odd Be Careful! If we add this primitive rules to Z-E, S-O, and S-E The rule below is ??
Z-O invert-S-O succ(X)odd X even zero odd Be Careful! 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 invert-S-O silly1 silly2 succ(X)odd X odd X even zero odd X even succ(one) even Be Careful! 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 The rules below are also admissible or derivable