src/HOL/Subst/Unify.ML
author nipkow
Mon, 09 Feb 1998 14:40:59 +0100
changeset 4612 26764de50c74
parent 4153 e534c4c32d54
child 4686 74a12e86b20b
permissions -rw-r--r--
Used THEN_ALL_NEW.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     1
(*  Title:      Subst/Unify
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
     2
    ID:         $Id$
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     3
    Author:     Konrad Slind, Cambridge University Computer Laboratory
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     4
    Copyright   1997  University of Cambridge
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     5
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     6
Unification algorithm
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     7
*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     8
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     9
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    10
 * This file defines a nested unification algorithm, then proves that it 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    11
 * terminates, then proves 2 correctness theorems: that when the algorithm
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    12
 * succeeds, it 1) returns an MGU; and 2) returns an idempotent substitution.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    13
 * Although the proofs may seem long, they are actually quite direct, in that
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    14
 * the correctness and termination properties are not mingled as much as in 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    15
 * previous proofs of this algorithm. 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    16
 *
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    17
 * Our approach for nested recursive functions is as follows: 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    18
 *
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    19
 *    0. Prove the wellfoundedness of the termination relation.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    20
 *    1. Prove the non-nested termination conditions.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    21
 *    2. Eliminate (0) and (1) from the recursion equations and the 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    22
 *       induction theorem.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    23
 *    3. Prove the nested termination conditions by using the induction 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    24
 *       theorem from (2) and by using the recursion equations from (2). 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    25
 *       These are constrained by the nested termination conditions, but 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    26
 *       things work out magically (by wellfoundedness of the termination 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    27
 *       relation).
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    28
 *    4. Eliminate the nested TCs from the results of (2).
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    29
 *    5. Prove further correctness properties using the results of (4).
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    30
 *
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    31
 * Deeper nestings require iteration of steps (3) and (4).
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    32
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    33
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    34
open Unify;
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    35
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    36
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    37
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    38
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    39
 * The non-nested TC plus the wellfoundedness of unifyRel.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    40
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    41
Tfl.tgoalw Unify.thy [] unify.rules;
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    42
(* Wellfoundedness of unifyRel *)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
    43
by (simp_tac (simpset() addsimps [unifyRel_def,
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    44
				 wf_inv_image, wf_lex_prod, wf_finite_psubset,
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
    45
				 wf_measure]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    46
(* TC *)
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3392
diff changeset
    47
by Safe_tac;
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
    48
by (simp_tac (simpset() addsimps [finite_psubset_def, finite_vars_of,
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
    49
				 lex_prod_def, measure_def, inv_image_def]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    50
by (rtac (monotone_vars_of RS (subset_iff_psubset_eq RS iffD1) RS disjE) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    51
by (Blast_tac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
    52
by (asm_simp_tac (simpset() addsimps [less_eq, less_add_Suc1]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    53
qed "tc0";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    54
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    55
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    56
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    57
 * Termination proof.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    58
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    59
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
    60
goalw Unify.thy [unifyRel_def, measure_def] "trans unifyRel";
3241
91b543ab091b Removal of duplicate code from TFL
paulson
parents: 3209
diff changeset
    61
by (REPEAT (resolve_tac [trans_inv_image, trans_lex_prod, 
91b543ab091b Removal of duplicate code from TFL
paulson
parents: 3209
diff changeset
    62
			 trans_finite_psubset, trans_less_than,
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
    63
			 trans_inv_image] 1));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    64
qed "trans_unifyRel";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    65
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    66
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    67
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    68
 * The following lemma is used in the last step of the termination proof for 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    69
 * the nested call in Unify.  Loosely, it says that unifyRel doesn't care
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    70
 * about term structure.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    71
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    72
goalw Unify.thy [unifyRel_def,lex_prod_def, inv_image_def]
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    73
     "!!x. ((X,Y), (Comb A (Comb B C), Comb D (Comb E F))) : unifyRel  ==> \
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    74
    \      ((X,Y), (Comb (Comb A B) C, Comb (Comb D E) F)) : unifyRel";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
    75
by (asm_full_simp_tac (simpset() addsimps [measure_def, 
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    76
                          less_eq, inv_image_def,add_assoc]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    77
by (subgoal_tac "(vars_of A Un vars_of B Un vars_of C Un \
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    78
                \  (vars_of D Un vars_of E Un vars_of F)) = \
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    79
                \ (vars_of A Un (vars_of B Un vars_of C) Un \
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    80
                \  (vars_of D Un (vars_of E Un vars_of F)))" 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    81
by (Blast_tac 2);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    82
by (Asm_simp_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    83
qed "Rassoc";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    84
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    85
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    86
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    87
 * This lemma proves the nested termination condition for the base cases 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    88
 * 3, 4, and 6. 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    89
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    90
goal Unify.thy
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    91
 "!!x. ~(Var x <: M) ==>        \
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    92
\   ((N1 <| [(x,M)], N2 <| [(x,M)]), (Comb M N1, Comb(Var x) N2)) : unifyRel \
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    93
\ & ((N1 <| [(x,M)], N2 <| [(x,M)]), (Comb(Var x) N1, Comb M N2)) : unifyRel";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    94
by (case_tac "Var x = M" 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    95
by (hyp_subst_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    96
by (Simp_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    97
by (case_tac "x: (vars_of N1 Un vars_of N2)" 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    98
(*uterm_less case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    99
by (asm_simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   100
    (simpset() addsimps [less_eq, unifyRel_def, lex_prod_def,
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   101
			measure_def, inv_image_def]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   102
by (Blast_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   103
(*finite_psubset case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   104
by (simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   105
    (simpset() addsimps [unifyRel_def, lex_prod_def,
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   106
			measure_def, inv_image_def]) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   107
by (simp_tac (simpset() addsimps [finite_psubset_def, finite_vars_of,
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   108
				 psubset_def, set_eq_subset]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   109
by (Blast_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   110
(** LEVEL 9 **)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   111
(*Final case, also finite_psubset*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   112
by (simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   113
    (simpset() addsimps [finite_vars_of, unifyRel_def, finite_psubset_def,
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   114
			lex_prod_def, measure_def, inv_image_def]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   115
by (cut_inst_tac [("s","[(x,M)]"), ("v", "x"), ("t","N2")] Var_elim 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   116
by (cut_inst_tac [("s","[(x,M)]"), ("v", "x"), ("t","N1")] Var_elim 3);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   117
by (ALLGOALS (asm_simp_tac(simpset() addsimps [srange_iff, vars_iff_occseq])));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   118
by (REPEAT_FIRST (resolve_tac [conjI, disjI1, psubsetI]));
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   119
by (ALLGOALS (asm_full_simp_tac 
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   120
	      (simpset() addsimps [srange_iff, set_eq_subset]))); 
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   121
by (ALLGOALS
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   122
    (fast_tac (claset() addEs [Var_intro RS disjE]
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   123
	               addss (simpset() addsimps [srange_iff]))));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   124
qed "var_elimR";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   125
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   126
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   127
(*---------------------------------------------------------------------------
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   128
 * Eliminate tc0 from the recursion equations and the induction theorem.
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   129
 *---------------------------------------------------------------------------*)
3392
d0d86b96aa96 No longer refers to internal TFL structures
paulson
parents: 3334
diff changeset
   130
val wfr = tc0 RS conjunct1
d0d86b96aa96 No longer refers to internal TFL structures
paulson
parents: 3334
diff changeset
   131
and tc  = tc0 RS conjunct2;
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   132
val unifyRules0 = map (normalize_thm [fn th => wfr RS th, fn th => tc RS th]) 
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   133
                     unify.rules;
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   134
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   135
val unifyInduct0 = [wfr,tc] MRS unify.induct;
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   136
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   137
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   138
(*---------------------------------------------------------------------------
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   139
 * The nested TC. Proved by recursion induction.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   140
 *---------------------------------------------------------------------------*)
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   141
val [_,_,tc3] = unify.tcs;
3241
91b543ab091b Removal of duplicate code from TFL
paulson
parents: 3209
diff changeset
   142
goalw_cterm [] (cterm_of (sign_of Unify.thy) (HOLogic.mk_Trueprop tc3));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   143
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   144
 * The extracted TC needs the scope of its quantifiers adjusted, so our 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   145
 * first step is to restrict the scopes of N1 and N2.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   146
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   147
by (subgoal_tac "!M1 M2 theta.  \
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   148
 \   unify(M1, M2) = Some theta --> \
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   149
 \   (!N1 N2. ((N1<|theta, N2<|theta), Comb M1 N1, Comb M2 N2) : unifyRel)" 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   150
by (Blast_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   151
by (rtac allI 1); 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   152
by (rtac allI 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   153
(* Apply induction *)
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   154
by (res_inst_tac [("u","M1"),("v","M2")] unifyInduct0 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   155
by (ALLGOALS 
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   156
    (asm_simp_tac (simpset() addsimps (var_elimR::unifyRules0)
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3724
diff changeset
   157
			    addsplits [expand_if])));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   158
(*Const-Const case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   159
by (simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   160
    (simpset() addsimps [unifyRel_def, lex_prod_def, measure_def,
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   161
			inv_image_def, less_eq]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   162
(** LEVEL 7 **)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   163
(*Comb-Comb case*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   164
by (asm_simp_tac (simpset() addsplits [split_option_case]) 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   165
by (strip_tac 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   166
by (rtac (trans_unifyRel RS transD) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   167
by (Blast_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   168
by (simp_tac (HOL_ss addsimps [subst_Comb RS sym]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   169
by (rtac Rassoc 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   170
by (Blast_tac 1);
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   171
qed_spec_mp "unify_TC";
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   172
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   173
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   174
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   175
 * Now for elimination of nested TC from unify.rules and induction. 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   176
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   177
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   178
(*Desired rule, copied from the theory file.  Could it be made available?*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   179
goal Unify.thy 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   180
  "unify(Comb M1 N1, Comb M2 N2) =      \
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   181
\      (case unify(M1,M2)               \
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   182
\        of None => None                \
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   183
\         | Some theta => (case unify(N1 <| theta, N2 <| theta)        \
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   184
\                            of None => None    \
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   185
\                             | Some sigma => Some (theta <> sigma)))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   186
by (asm_simp_tac (simpset() addsimps (unify_TC::unifyRules0)
4071
4747aefbbc52 expand_option_case -> split_option_case
nipkow
parents: 3919
diff changeset
   187
			   addsplits [split_option_case]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   188
qed "unifyCombComb";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   189
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   190
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   191
val unifyRules = rev (unifyCombComb :: tl (rev unifyRules0));
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   193
Addsimps unifyRules;
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   194
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   195
bind_thm ("unifyInduct",
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   196
	  rule_by_tactic
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   197
	     (ALLGOALS (full_simp_tac (simpset() addsimps [unify_TC])))
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   198
	     unifyInduct0);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   199
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   200
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   201
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   202
 * Correctness. Notice that idempotence is not needed to prove that the 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   203
 * algorithm terminates and is not needed to prove the algorithm correct, 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   204
 * if you are only interested in an MGU.  This is in contrast to the
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   205
 * approach of M&W, who used idempotence and MGU-ness in the termination proof.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   206
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   207
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   208
goal Unify.thy "!theta. unify(M,N) = Some theta --> MGUnifier theta M N";
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   209
by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   210
by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   211
(*Const-Const case*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   212
by (simp_tac (simpset() addsimps [MGUnifier_def,Unifier_def]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   213
(*Const-Var case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   214
by (stac mgu_sym 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   215
by (simp_tac (simpset() addsimps [MGUnifier_Var]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   216
(*Var-M case*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   217
by (simp_tac (simpset() addsimps [MGUnifier_Var]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   218
(*Comb-Var case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   219
by (stac mgu_sym 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   220
by (simp_tac (simpset() addsimps [MGUnifier_Var]) 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   221
(** LEVEL 8 **)
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   222
(*Comb-Comb case*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   223
by (asm_simp_tac (simpset() addsplits [split_option_case]) 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   224
by (strip_tac 1);
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   225
by (rotate_tac ~2 1);
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   226
by (asm_full_simp_tac 
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   227
    (simpset() addsimps [MGUnifier_def, Unifier_def, MoreGeneral_def]) 1);
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4089
diff changeset
   228
by (Safe_tac THEN rename_tac "theta sigma gamma" 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   229
by (eres_inst_tac [("x","gamma")] allE 1 THEN mp_tac 1);
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   230
by (etac exE 1 THEN rename_tac "delta" 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   231
by (eres_inst_tac [("x","delta")] allE 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   232
by (subgoal_tac "N1 <| theta <| delta = N2 <| theta <| delta" 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   233
(*Proving the subgoal*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   234
by (full_simp_tac (simpset() addsimps [subst_eq_iff]) 2
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   235
    THEN blast_tac (claset() addIs [trans,sym] delrules [impCE]) 2);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   236
by (blast_tac (claset() addIs [subst_trans, subst_cong, 
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   237
			      comp_assoc RS subst_sym]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   238
qed_spec_mp "unify_gives_MGU";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   239
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   240
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   241
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   242
 * Unify returns idempotent substitutions, when it succeeds.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   243
 *---------------------------------------------------------------------------*)
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   244
goal Unify.thy "!theta. unify(M,N) = Some theta --> Idem theta";
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   245
by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   246
by (ALLGOALS 
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   247
    (asm_simp_tac 
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   248
       (simpset() addsimps [Var_Idem] 
4071
4747aefbbc52 expand_option_case -> split_option_case
nipkow
parents: 3919
diff changeset
   249
	         addsplits [expand_if,split_option_case])));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   250
(*Comb-Comb case*)
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4089
diff changeset
   251
by Safe_tac;
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   252
by (REPEAT (dtac spec 1 THEN mp_tac 1));
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   253
by (safe_tac (claset() addSDs [rewrite_rule [MGUnifier_def] unify_gives_MGU]));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   254
by (rtac Idem_comp 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   255
by (atac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   256
by (atac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   257
by (best_tac (claset() addss (simpset() addsimps 
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   258
			     [MoreGeneral_def, subst_eq_iff, Idem_def])) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   259
qed_spec_mp "unify_gives_Idem";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   260