1
play

1 Higher-Order Unification First Order Unification In Isabelle: - PDF document

Isabelles Metalogic Course 2D1453, 2006-07 Basic constructs: t = s Equations on terms Advanced Formal Methods A 1 A 2 Implication Lecture 5: Isabelle Proofs and Rewriting Example: x = y append x xs = append y xs If A 1


  1. Isabelle’s Metalogic Course 2D1453, 2006-07 Basic constructs: • t = s Equations on terms Advanced Formal Methods • A 1 � A 2 Implication Lecture 5: Isabelle – Proofs and Rewriting Example: x = y � append x xs = append y xs If A 1 is valid then so is A 2 Mads Dam � x. A KTH/CSC Universal quantification A[t/x] is valid for all t (of appropriate type) These are meta-connectives, not object-logic connectives Some slides from Paulson Isabelle Proof Goals Global Proof State An Isabelle proof state consists of number of unproven Proof goals, or judgments: judgments • The basic shape of proof goal handled by Isabelle 1. � x 1,1 ,...,x m,1 . � A 1,1 ; ... ; A n,1 � � A 1 • Local proof state, subgoal .... k. � x 1,k ,...,x m,k . � A 1,k ; ... ; A n,k � � A k General shape: � x 1 ,...,x m . � A 1 ; ... ; A n � � A • x 1 ,...,x m : Local variables If k = 0 proof is complete • A 1 ,...,A n : Local assumptions • A: local proof goal Judgment #1 is the one currently being worked on Meaning: For all terms t 1 ,...,t m , if all A i [t 1 /x 1 ,...,t m /x m ] are Commands to list subgoals, toggle between subgoals, to apply rules to numbered subgoals, etc. provable then so is A[t 1 /x 1 ,...,t m /x m ] Goal-Driven Proof - Intuition Unification Proof goal: Substitution: * � x 1 ,...,x m . � A 1 ; ... ; A n � � A Mapping σ from variables to terms Find some ”given fact” B, under assumptions B 1 ,...,B k such [t/x]: Substitution mapping x to t, otherwise the identity that A ”is” B t σ : Capture-avoiding substitution σ applied to t Replace subgoal * by subgoals � x 1 ,...,x m . � A 1 ; ... ; A n � � B_1 Unification: ... � x 1 ,...,x m . � A 1 ; ... ; A n � � B_k Try to make terms t and s equal Unifier: Substitution σ on terms s, t such that s σ = t σ But, ”is” is really ”is an instance of” so story must be refined Unification problem: Given t, s, is there a unifier on s, t 1

  2. Higher-Order Unification First Order Unification In Isabelle: Decidable Terms are terms in Isabelle = extended λ � Terms Equality on terms are modulo α , β , η Most general unifiers (mgu’s) exist: Variables to be unified are schematic σ is mgu for t and s if σ unifies t and s Schematic variables can have function type Whenever σ ’ unifies t and s then t σ , t σ ’, and s σ , s σ ’ (= higher order) are both unifiable Examples: Exercise 1: Show that [h(?Y)/?X,g(h(?Y))/?Z] is mgu for ?X � ?Y = αβη x � x under [x/?X,x/?Y] f(?X,g(?X)) and f(h(?Y),?Z). under [ λ x.x � x/?P] ?P x = αβη x � x under [ λ x.x/?f,P/Y] P (?f x) = αβη ?Y x Applications in e.g. logic programming Higher Order Unification Exercises HO unification modulo α , β is semi-decidable Exercise 2: Determine whether each pair of terms is HO unification modulo α , β , η is undecidable unifiable or not. If it is, exhibit a unifier. If it is not, show why. 1. f(x 1 , ?x 2 , ?x 2 ) and f(?y 1 , ?y 2 , k) Higher order pattern: 2. f(x 1 , ?x 2 , ?x 2 ) and f(y 1 , g ?x 2 , k) Term t in β normal form ( value in slides for lecture 3) 3. f (?p x y (h z)) and ?q (g(x,y),h(?r)) Schematic variables only in head position 4. ?p (g x 1 ) (h x 2 ) and ?q (g y 2 ) (h y 1 ) ?f t 1 ... t n 5. ?p (g ?q, h z) and f(h ?r, h ?r) Each t i η -convertible to n distinct bound variables Unification on HO patterns is decidable Term Rewriting More Formally Rewrite rule l = r is applicable to term t[s/x] if: Use equations t = s as rewrite rules from left to right • There is a substitution σ such that l σ = αβη s Example: Use equations: σ unifies l and s • 1. 0 + n = n Result of rewrite is t[s σ /x] 2. (suc m) + n = suc(m + n) 3. (suc m � suc n) = (m � n) Note: t[s/x] = t[s σ /x] 4. (0 � m) = true Then: Example: 0 + suc 0 � (suc 0) + x (by (1)) Equation: 0 + n = n = suc 0 � (suc 0) + x (by (2)) = suc 0 � suc (0 + x) Term: a + (0 + (b + c)) (by (3)) = 0 � 0 + x (by (4)) Substitution: [b+c/n] = true Result: a + (b + c) 2

  3. Conditional Rewriting Basic Simplification Assume conditional rewrite rule Goal: � A 1 ; ... ; A m � � B RId: A 1 � ... � A n � l = r Apply(simp add: eq 1 , ... , eq n ) Rule RId is applicable to term t[s/x] if: Simplify B using • There is a substitution σ such that l σ = αβη s • Lemmas with attribute simp σ unifies l and s • Rules from primrec and datatype declarations • • A 1 σ ,..., A n σ are provable • Additional lemmas eq 1 ,...,eq n • Assumptions A 1 , ... , A m Again result of rewrite is t[s σ /x] Variation: • (simp ... del: ...) removes lemmas from simplification set • add, del are optional Termination Case Splitting Isabelle uses simp-rules (almost) blindly from left to right P(if A then s else t) = (A � P(s)) � ( � A � P(t)) Termination is the big issue Included in simp by default Example: f(x) = g(x), g(x) = f(x) P(case t of 0 � s 1 | Suc n � s 2 ) = (t = 0 � P(s 1 )) � ( � n. t = Suc n � P(s 2 )) Rewrite rule � A 1 ; ... ; A n � � l = r Not included – use (simp split: nat.split) suitable for inclusion in simplification set only if rewrite from l to r reduces overall complexity of the global proof state So: l must be ”bigger” than r and each A i Similar for other datatypes T: T.split n < m = true � (n < suc m) = true (may be good) (suc n < m) = true � n < m = true (not good) Ordered Rewriting Preprocessing Problem: ?x + ?y = ?y + ?x does not terminate Simplification rules are preprocessed recursively: Isabelle: Use permutative rewrite rules only when term � A � A = False becomes lexicographically smaller Example: ?b + ?a � ?a + ?b but not ?a + ?b � ?b + ?a A � B � A � B A � B � A, B � x. A(x) � A(?x) For types nat, int, etc. A � A = True • Lemmas add ac sort any sum • Lemmas times ac sort any product Example: Example: (simp add:add ac) yields (p � q � � r) � s (b + c) + a � a + (b + c) � p = True � q = True, p = True � r = False, s = True 3

Recommend


More recommend