TFL/examples/Subst/Unify.ML
author wenzelm
Mon, 16 Dec 1996 09:58:16 +0100
changeset 2399 6719b465198b
parent 2113 21266526ac42
child 2597 8b523426e1a4
permissions -rw-r--r--
symbolinput - translate symbols into \<...> sequences;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2113
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     1
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     2
 * This file defines a nested unification algorithm, then proves that it 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     3
 * terminates, then proves 2 correctness theorems: that when the algorithm
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     4
 * succeeds, it 1) returns an MGU; and 2) returns an idempotent substitution.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     5
 * Although the proofs may seem long, they are actually quite direct, in that
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     6
 * the correctness and termination properties are not mingled as much as in 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     7
 * previous proofs of this algorithm. 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     8
 *
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     9
 * Our approach for nested recursive functions is as follows: 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    10
 *
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    11
 *    0. Prove the wellfoundedness of the termination relation.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    12
 *    1. Prove the non-nested termination conditions.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    13
 *    2. Eliminate (0) and (1) from the recursion equations and the 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    14
 *       induction theorem.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    15
 *    3. Prove the nested termination conditions by using the induction 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    16
 *       theorem from (2) and by using the recursion equations from (2). 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    17
 *       These are constrained by the nested termination conditions, but 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    18
 *       things work out magically (by wellfoundedness of the termination 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    19
 *       relation).
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    20
 *    4. Eliminate the nested TCs from the results of (2).
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    21
 *    5. Prove further correctness properties using the results of (4).
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    22
 *
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    23
 * Deeper nestings require iteration of steps (3) and (4).
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    24
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    25
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    26
(* This is just a wrapper for the definition mechanism. *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    27
local fun cread thy s = read_cterm (sign_of thy) (s, (TVar(("DUMMY",0),[])));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    28
in
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    29
fun Rfunc thy R eqs =
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    30
   let val read = term_of o cread thy;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    31
    in Tfl.Rfunction thy (read R) (read eqs)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    32
    end
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    33
end;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    34
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    35
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    36
 * The algorithm.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    37
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    38
val {theory,induction,rules,tcs} =
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    39
Rfunc Unify.thy "R"
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    40
  "(Unify(Const m, Const n)  = (if (m=n) then Subst[] else Fail))    & \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    41
\  (Unify(Const m, Comb M N) = Fail)                                 & \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    42
\  (Unify(Const m, Var v)    = Subst[(v,Const m)])                   & \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    43
\  (Unify(Var v, M) = (if (Var v <: M) then Fail else Subst[(v,M)])) & \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    44
\  (Unify(Comb M N, Const x) = Fail)                                 & \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    45
\  (Unify(Comb M N, Var v) = (if (Var v <: Comb M N) then Fail  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    46
\                             else Subst[(v,Comb M N)]))             & \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    47
\  (Unify(Comb M1 N1, Comb M2 N2) =  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    48
\     (case Unify(M1,M2) \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    49
\       of Fail => Fail \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    50
\        | Subst theta => (case Unify(N1 <| theta, N2 <| theta) \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    51
\                           of Fail => Fail \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    52
\                             | Subst sigma => Subst (theta <> sigma))))";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    53
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    54
open Unify;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    55
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    56
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    57
 * A slightly augmented strip_tac. 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    58
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    59
fun my_strip_tac i = 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    60
   CHANGED (strip_tac i 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    61
             THEN REPEAT ((etac exE ORELSE' etac conjE) i)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    62
             THEN TRY (hyp_subst_tac i));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    63
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    64
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    65
 * A slightly augmented fast_tac for sets. It handles the case where the 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    66
 * top connective is "=".
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    67
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    68
fun my_fast_set_tac i = (TRY(rtac set_ext i) THEN fast_tac set_cs i);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    69
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    70
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    71
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    72
 * Wellfoundedness of proper subset on finite sets.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    73
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    74
goalw Unify.thy [R0_def] "wf(R0)";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    75
by (rtac ((wf_subset RS mp) RS mp) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    76
by (rtac wf_measure 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    77
by(simp_tac(!simpset addsimps[measure_def,inv_image_def,symmetric less_def])1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    78
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    79
by (forward_tac[ssubset_card] 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    80
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    81
val wf_R0 = result();
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    82
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    83
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    84
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    85
 * Tactic for selecting and working on the first projection of R.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    86
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    87
fun R0_tac thms i =
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    88
  (simp_tac (!simpset addsimps (thms@[R_def,lex_prod_def,
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    89
               measure_def,inv_image_def,point_to_prod_def])) i THEN
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    90
   REPEAT (rtac exI i) THEN
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    91
   REPEAT ((rtac conjI THEN' rtac refl) i) THEN
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    92
   rtac disjI1 i THEN
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    93
   simp_tac (!simpset addsimps [R0_def,finite_vars_of]) i);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    94
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    95
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    96
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    97
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    98
 * Tactic for selecting and working on the second projection of R.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    99
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   100
fun R1_tac thms i = 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   101
   (simp_tac (!simpset addsimps (thms@[R_def,lex_prod_def,
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   102
                 measure_def,inv_image_def,point_to_prod_def])) i THEN 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   103
    REPEAT (rtac exI i) THEN 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   104
    REPEAT ((rtac conjI THEN' rtac refl) i) THEN
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   105
    rtac disjI2 i THEN
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   106
    asm_simp_tac (!simpset addsimps [R1_def,rprod_def]) i);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   107
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   108
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   109
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   110
 * The non-nested TC plus the wellfoundedness of R.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   111
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   112
Tfl.tgoalw Unify.thy [] rules;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   113
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   114
(* TC *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   115
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   116
by (cut_facts_tac [monotone_vars_of] 1); 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   117
by (asm_full_simp_tac(!simpset addsimps [subseteq_iff_subset_eq]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   118
by (etac disjE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   119
by (R0_tac[] 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   120
by (R1_tac[] 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   121
by (simp_tac
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   122
     (!simpset addsimps [measure_def,inv_image_def,less_eq,less_add_Suc1]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   123
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   124
(* Wellfoundedness of R *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   125
by (simp_tac (!simpset addsimps [Unify.R_def,Unify.R1_def]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   126
by (REPEAT (resolve_tac [wf_inv_image,wf_lex_prod,wf_R0,
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   127
                         wf_rel_prod, wf_measure] 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   128
val tc0 = result();
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   129
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   130
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   131
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   132
 * Eliminate tc0 from the recursion equations and the induction theorem.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   133
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   134
val [tc,wfr] = Prim.Rules.CONJUNCTS tc0;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   135
val rules1 = implies_intr_hyps rules;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   136
val rules2 = wfr RS rules1;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   137
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   138
val [a,b,c,d,e,f,g] = Prim.Rules.CONJUNCTS rules2;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   139
val g' = tc RS (g RS mp);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   140
val rules4 = standard (Prim.Rules.LIST_CONJ[a,b,c,d,e,f,g']);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   141
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   142
val induction1 = implies_intr_hyps induction;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   143
val induction2 = wfr RS induction1;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   144
val induction3 = tc RS induction2;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   145
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   146
val induction4 = standard
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   147
 (rewrite_rule[fst_conv RS eq_reflection, snd_conv RS eq_reflection]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   148
   (induction3 RS (read_instantiate_sg (sign_of theory)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   149
      [("x","%p. Phi (fst p) (snd p)")] spec)));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   150
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   151
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   152
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   153
 * Some theorems about transitivity of WF combinators. Only the last
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   154
 * (transR) is used, in the proof of termination. The others are generic and
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   155
 * should maybe go somewhere.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   156
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   157
goalw WF1.thy [trans_def,lex_prod_def,mem_Collect_eq RS eq_reflection]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   158
           "trans R1 & trans R2 --> trans (R1 ** R2)";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   159
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   160
by (res_inst_tac [("x","a")] exI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   161
by (res_inst_tac [("x","a'a")] exI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   162
by (res_inst_tac [("x","b")] exI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   163
by (res_inst_tac [("x","b'a")] exI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   164
by (REPEAT (rewrite_tac [Pair_eq RS eq_reflection] THEN my_strip_tac 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   165
by (Simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   166
by (REPEAT (etac disjE 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   167
by (rtac disjI1 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   168
by (ALLGOALS (fast_tac set_cs));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   169
val trans_lex_prod = result() RS mp;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   170
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   171
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   172
goalw WF1.thy [trans_def,rprod_def,mem_Collect_eq RS eq_reflection]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   173
           "trans R1 & trans R2 --> trans (rprod R1  R2)";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   174
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   175
by (res_inst_tac [("x","a")] exI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   176
by (res_inst_tac [("x","a'a")] exI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   177
by (res_inst_tac [("x","b")] exI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   178
by (res_inst_tac [("x","b'a")] exI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   179
by (REPEAT (rewrite_tac [Pair_eq RS eq_reflection] THEN my_strip_tac 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   180
by (Simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   181
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   182
val trans_rprod = result() RS mp;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   183
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   184
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   185
goalw Unify.thy [trans_def,inv_image_def,mem_Collect_eq RS eq_reflection]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   186
 "trans r --> trans (inv_image r f)";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   187
by (rewrite_tac [fst_conv RS eq_reflection, snd_conv RS eq_reflection]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   188
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   189
val trans_inv_image = result() RS mp;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   190
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   191
goalw Unify.thy [R0_def, trans_def, mem_Collect_eq RS eq_reflection]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   192
 "trans R0";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   193
by (rewrite_tac [fst_conv RS eq_reflection,snd_conv RS eq_reflection,
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   194
                 ssubset_def, set_eq_subset RS eq_reflection]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   195
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   196
val trans_R0 = result();
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   197
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   198
goalw Unify.thy [R_def,R1_def,measure_def] "trans R";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   199
by (REPEAT (resolve_tac[trans_inv_image,trans_lex_prod,conjI, trans_R0,
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   200
                        trans_rprod, trans_inv_image, trans_trancl] 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   201
val transR = result();
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   202
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   203
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   204
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   205
 * The following lemma is used in the last step of the termination proof for 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   206
 * the nested call in Unify. Loosely, it says that R doesn't care so much
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   207
 * about term structure.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   208
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   209
goalw Unify.thy [R_def,lex_prod_def, inv_image_def,point_to_prod_def]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   210
     "((X,Y), (Comb A (Comb B C), Comb D (Comb E F))) : R --> \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   211
    \ ((X,Y), (Comb (Comb A B) C, Comb (Comb D E) F)) : R";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   212
by (Simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   213
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   214
by (strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   215
by (rtac disjI1 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   216
by (subgoal_tac "(vars_of A Un vars_of B Un vars_of C Un \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   217
                \  (vars_of D Un vars_of E Un vars_of F)) = \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   218
                \ (vars_of A Un (vars_of B Un vars_of C) Un \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   219
                \  (vars_of D Un (vars_of E Un vars_of F)))" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   220
by (my_fast_set_tac 2);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   221
by (Asm_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   222
by (strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   223
by (rtac disjI2 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   224
by (etac conjE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   225
by (Asm_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   226
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   227
by (my_fast_set_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   228
by (asm_full_simp_tac (!simpset addsimps [R1_def, measure_def, rprod_def,
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   229
                          less_eq, inv_image_def,add_assoc]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   230
val Rassoc = result() RS mp;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   231
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   232
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   233
 * Rewriting support.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   234
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   235
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   236
val termin_ss = (!simpset addsimps (srange_iff::(subst_rews@al_rews)));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   237
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   238
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   239
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   240
 * This lemma proves the nested termination condition for the base cases 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   241
 * 3, 4, and 6. It's a clumsy formulation (requiring two conjuncts, each with
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   242
 * exactly the same proof) of a more general theorem.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   243
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   244
goal theory "(~(Var x <: M)) --> [(x, M)] = theta -->       \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   245
\ (! N1 N2. (((N1 <| theta, N2 <| theta), (Comb M N1, Comb (Var x) N2)) : R) \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   246
\       &   (((N1 <| theta, N2 <| theta), (Comb(Var x) N1, Comb M N2)) : R))";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   247
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   248
by (case_tac "Var x = M" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   249
by (hyp_subst_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   250
by (case_tac "x:(vars_of N1 Un vars_of N2)" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   251
let val case1 = 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   252
   EVERY1[R1_tac[id_subst_lemma], rtac conjI, my_fast_set_tac,
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   253
          REPEAT o (rtac exI), REPEAT o (rtac conjI THEN' rtac refl),
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   254
          simp_tac (!simpset addsimps [measure_def,inv_image_def,less_eq])];
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   255
in by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   256
   by case1;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   257
   by case1
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   258
end;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   259
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   260
let val case2 = 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   261
   EVERY1[R0_tac[id_subst_lemma],
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   262
          simp_tac (!simpset addsimps [ssubset_def,set_eq_subset]),
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   263
          fast_tac set_cs]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   264
in by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   265
   by case2;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   266
   by case2
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   267
end;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   268
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   269
let val case3 =  
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   270
 EVERY1 [R0_tac[],
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   271
        cut_inst_tac [("s2","[(x, M)]"), ("v2", "x"), ("t2","N1")] Var_elim] 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   272
 THEN ALLGOALS(asm_simp_tac(termin_ss addsimps [vars_iff_occseq]))
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   273
 THEN cut_inst_tac [("s2","[(x, M)]"),("v2", "x"), ("t2","N2")] Var_elim 1
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   274
 THEN ALLGOALS(asm_simp_tac(termin_ss addsimps [vars_iff_occseq]))
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   275
 THEN EVERY1 [simp_tac (HOL_ss addsimps [ssubset_def]),
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   276
             rtac conjI, simp_tac (HOL_ss addsimps [subset_iff]),
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   277
             my_strip_tac, etac UnE, dtac Var_intro] 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   278
 THEN dtac Var_intro 2
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   279
 THEN ALLGOALS (asm_full_simp_tac (termin_ss addsimps [set_eq_subset])) 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   280
 THEN TRYALL (fast_tac set_cs)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   281
in 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   282
  by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   283
  by case3;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   284
  by case3
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   285
end;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   286
val var_elimR = result() RS mp RS mp RS spec RS spec;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   287
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   288
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   289
val Some{nchotomy = subst_nchotomy,...} = assoc(!datatypes,"subst");
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   290
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   291
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   292
 * Do a case analysis on something of type 'a subst. 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   293
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   294
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   295
fun Subst_case_tac theta =
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   296
(cut_inst_tac theta (standard (Prim.Rules.SPEC_ALL subst_nchotomy)) 1 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   297
  THEN etac disjE 1 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   298
  THEN rotate_tac ~1 1 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   299
  THEN Asm_full_simp_tac 1 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   300
  THEN etac exE 1
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   301
  THEN rotate_tac ~1 1 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   302
  THEN Asm_full_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   303
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   304
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   305
goals_limit := 1;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   306
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   307
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   308
 * The nested TC. Proved by recursion induction.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   309
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   310
goalw_cterm [] 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   311
     (hd(tl(tl(map (cterm_of (sign_of theory) o USyntax.mk_prop) tcs))));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   312
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   313
 * The extracted TC needs the scope of its quantifiers adjusted, so our 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   314
 * first step is to restrict the scopes of N1 and N2.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   315
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   316
by (subgoal_tac "!M1 M2 theta.  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   317
 \     Unify (M1, M2) = Subst theta --> \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   318
 \    (!N1 N2. ((N1 <| theta, N2 <| theta), Comb M1 N1, Comb M2 N2) : R)" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   319
by (fast_tac HOL_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   320
by (rtac allI 1); 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   321
by (rtac allI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   322
(* Apply induction *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   323
by (res_inst_tac [("xa","M1"),("x","M2")] 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   324
                 (standard (induction4 RS mp RS spec RS spec)) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   325
by (simp_tac (!simpset addsimps (rules4::(subst_rews@al_rews))
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   326
                       setloop (split_tac [expand_if])) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   327
(* 1 *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   328
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   329
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   330
by (R1_tac[subst_Nil] 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   331
by (REPEAT (rtac exI 1) THEN REPEAT ((rtac conjI THEN' rtac refl) 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   332
by (simp_tac (!simpset addsimps [measure_def,inv_image_def,less_eq]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   333
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   334
(* 3 *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   335
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   336
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   337
by (rtac (Prim.Rules.CONJUNCT1 var_elimR) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   338
by (Simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   339
by (rtac refl 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   340
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   341
(* 4 *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   342
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   343
by (strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   344
by (rtac (Prim.Rules.CONJUNCT2 var_elimR) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   345
by (assume_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   346
by (rtac refl 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   347
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   348
(* 6 *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   349
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   350
by (rewrite_tac [symmetric (occs_Comb RS eq_reflection)]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   351
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   352
by (rtac (Prim.Rules.CONJUNCT1 var_elimR) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   353
by (Asm_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   354
by (rtac refl 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   355
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   356
(* 7 *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   357
by (REPEAT (rtac allI 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   358
by (rtac impI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   359
by (etac conjE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   360
by (rename_tac "foo bar M1 N1 M2 N2" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   361
by (Subst_case_tac [("v","Unify(M1, M2)")]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   362
by (rename_tac "foo bar M1 N1 M2 N2 theta" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   363
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   364
by (Subst_case_tac [("v","Unify(N1 <| theta, N2 <| theta)")]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   365
by (rename_tac "foo bar M1 N1 M2 N2 theta sigma" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   366
by (REPEAT (rtac allI 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   367
by (rename_tac "foo bar M1 N1 M2 N2 theta sigma P Q" 1); 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   368
by (simp_tac (HOL_ss addsimps [subst_comp]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   369
by(rtac(rewrite_rule[trans_def] transR RS spec RS spec RS spec RS mp RS mp) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   370
by (fast_tac HOL_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   371
by (simp_tac (HOL_ss addsimps [symmetric (subst_Comb RS eq_reflection)]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   372
by (subgoal_tac "((Comb N1 P <| theta, Comb N2 Q <| theta), \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   373
                \ (Comb M1 (Comb N1 P), Comb M2 (Comb N2 Q))) :R" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   374
by (asm_simp_tac HOL_ss 2);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   375
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   376
by (rtac Rassoc 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   377
by (assume_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   378
val Unify_TC2 = result();
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   379
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   380
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   381
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   382
 * Now for elimination of nested TC from rules and induction. This step 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   383
 * would be easier if "rewrite_rule" used context.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   384
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   385
goal theory 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   386
 "(Unify (Comb M1 N1, Comb M2 N2) =  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   387
\   (case Unify (M1, M2) of Fail => Fail \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   388
\    | Subst theta => \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   389
\        (case if ((N1 <| theta, N2 <| theta), Comb M1 N1, Comb M2 N2) : R \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   390
\              then Unify (N1 <| theta, N2 <| theta) else @ z. True of \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   391
\        Fail => Fail | Subst sigma => Subst (theta <> sigma)))) \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   392
\  = \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   393
\ (Unify (Comb M1 N1, Comb M2 N2) = \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   394
\   (case Unify (M1, M2)  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   395
\      of Fail => Fail \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   396
\      | Subst theta => (case Unify (N1 <| theta, N2 <| theta) \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   397
\                          of Fail => Fail  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   398
\                           | Subst sigma => Subst (theta <> sigma))))";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   399
by (cut_inst_tac [("v","Unify(M1, M2)")]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   400
                 (standard (Prim.Rules.SPEC_ALL subst_nchotomy)) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   401
by (etac disjE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   402
by (Asm_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   403
by (etac exE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   404
by (Asm_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   405
by (cut_inst_tac 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   406
     [("x","list"), ("xb","N1"), ("xa","N2"),("xc","M2"), ("xd","M1")]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   407
     (standard(Unify_TC2 RS spec RS spec RS spec RS spec RS spec)) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   408
by (Asm_full_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   409
val Unify_rec_simpl = result() RS eq_reflection;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   410
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   411
val Unify_rules = rewrite_rule[Unify_rec_simpl] rules4;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   412
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   413
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   414
goal theory 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   415
 "(! M1 N1 M2 N2.  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   416
\       (! theta.  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   417
\           Unify (M1, M2) = Subst theta -->  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   418
\           ((N1 <| theta, N2 <| theta), Comb M1 N1, Comb M2 N2) : R -->  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   419
\           ?Phi (N1 <| theta) (N2 <| theta)) & ?Phi M1 M2 -->  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   420
\       ?Phi (Comb M1 N1) (Comb M2 N2))  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   421
\    =  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   422
\ (! M1 N1 M2 N2.  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   423
\       (! theta.  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   424
\           Unify (M1, M2) = Subst theta -->  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   425
\           ?Phi (N1 <| theta) (N2 <| theta)) & ?Phi M1 M2 -->  \
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   426
\       ?Phi (Comb M1 N1) (Comb M2 N2))";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   427
by (simp_tac (HOL_ss addsimps [Unify_TC2]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   428
val Unify_induction = rewrite_rule[result() RS eq_reflection] induction4;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   429
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   430
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   431
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   432
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   433
 * Correctness. Notice that idempotence is not needed to prove that the 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   434
 * algorithm terminates and is not needed to prove the algorithm correct, 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   435
 * if you are only interested in an MGU. This is in contrast to the
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   436
 * approach of M&W, who used idempotence and MGU-ness in the termination proof.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   437
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   438
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   439
goal theory "!theta. Unify (P,Q) = Subst theta --> MGUnifier theta P Q";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   440
by (res_inst_tac [("xa","P"),("x","Q")] 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   441
                 (standard (Unify_induction RS mp RS spec RS spec)) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   442
by (simp_tac (!simpset addsimps [Unify_rules] 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   443
                       setloop (split_tac [expand_if])) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   444
(*1*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   445
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   446
by (REPEAT (rtac allI 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   447
by (simp_tac (!simpset addsimps [MGUnifier_def,Unifier_def]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   448
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   449
by (rtac MoreGen_Nil 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   450
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   451
(*3*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   452
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   453
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   454
by (rtac (mgu_sym RS iffD1) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   455
by (rtac MGUnifier_Var 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   456
by (Simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   457
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   458
(*4*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   459
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   460
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   461
by (rtac MGUnifier_Var 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   462
by (assume_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   463
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   464
(*6*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   465
by (rtac conjI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   466
by (rewrite_tac NNF_rews);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   467
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   468
by (rtac (mgu_sym RS iffD1) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   469
by (rtac MGUnifier_Var 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   470
by (Asm_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   471
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   472
(*7*) 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   473
by (safe_tac HOL_cs);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   474
by (Subst_case_tac [("v","Unify(M1, M2)")]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   475
by (Subst_case_tac [("v","Unify(N1 <| list, N2 <| list)")]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   476
by (hyp_subst_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   477
by (asm_full_simp_tac(HOL_ss addsimps [MGUnifier_def,Unifier_def])1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   478
by (asm_simp_tac (!simpset addsimps [subst_comp]) 1); (* It's a unifier.*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   479
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   480
by (prune_params_tac);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   481
by (safe_tac HOL_cs);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   482
by (rename_tac "M1 N1 M2 N2 theta sigma gamma" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   483
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   484
by (rewrite_tac [MoreGeneral_def]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   485
by (rotate_tac ~3 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   486
by (eres_inst_tac [("x","gamma")] allE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   487
by (Asm_full_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   488
by (etac exE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   489
by (rename_tac "M1 N1 M2 N2 theta sigma gamma delta" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   490
by (eres_inst_tac [("x","delta")] allE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   491
by (subgoal_tac "N1 <| theta <| delta = N2 <| theta <| delta" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   492
by (dtac mp 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   493
by (atac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   494
by (etac exE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   495
by (rename_tac "M1 N1 M2 N2 theta sigma gamma delta rho" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   496
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   497
by (rtac exI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   498
by (rtac subst_trans 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   499
by (assume_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   500
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   501
by (rtac subst_trans 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   502
by (rtac (comp_assoc RS subst_sym) 2);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   503
by (rtac subst_cong 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   504
by (rtac (refl RS subst_refl) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   505
by (assume_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   506
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   507
by (asm_full_simp_tac (!simpset addsimps [subst_eq_iff,subst_comp]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   508
by (forw_inst_tac [("x","N1")] spec 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   509
by (dres_inst_tac [("x","N2")] spec 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   510
by (Asm_full_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   511
val Unify_gives_MGU = standard(result() RS spec RS mp);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   512
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   513
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   514
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   515
 * Unify returns idempotent substitutions, when it succeeds.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   516
 *---------------------------------------------------------------------------*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   517
goal theory "!theta. Unify (P,Q) = Subst theta --> Idem theta";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   518
by (res_inst_tac [("xa","P"),("x","Q")] 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   519
                 (standard (Unify_induction RS mp RS spec RS spec)) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   520
(* Blows away all base cases automatically *)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   521
by (simp_tac (!simpset addsimps [Unify_rules,Idem_Nil,Var_Idem] 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   522
                       setloop (split_tac [expand_if])) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   523
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   524
(*7*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   525
by (safe_tac HOL_cs);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   526
by (Subst_case_tac [("v","Unify(M1, M2)")]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   527
by (Subst_case_tac [("v","Unify(N1 <| list, N2 <| list)")]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   528
by (hyp_subst_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   529
by prune_params_tac;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   530
by (rename_tac "M1 N1 M2 N2 theta sigma" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   531
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   532
by (dtac Unify_gives_MGU 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   533
by (dtac Unify_gives_MGU 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   534
by (rewrite_tac [MGUnifier_def]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   535
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   536
by (rtac Idem_comp 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   537
by (atac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   538
by (atac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   539
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   540
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   541
by (eres_inst_tac [("x","q")] allE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   542
by (Asm_full_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   543
by (rewrite_tac [MoreGeneral_def]);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   544
by (my_strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   545
by (asm_full_simp_tac(termin_ss addsimps [subst_eq_iff,subst_comp,Idem_def])1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   546
val Unify_gives_Idem = result() RS spec RS mp;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   547
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   548
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   549
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   550
(*---------------------------------------------------------------------------
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   551
 * Exercise. The given algorithm is a bit inelegant. What about the
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   552
 * following "improvement", which adds a few recursive calls in former
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   553
 * base cases? It seems that the termination relation needs another
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   554
 * case in the lexico. product.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   555
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   556
val {theory,induction,rules,tcs,typechecks} =
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   557
Rfunc Unify.thy ??
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   558
  `(Unify(Const m, Const n)  = (if (m=n) then Subst[] else Fail))    &
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   559
   (Unify(Const m, Comb M N) = Fail)                                 &
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   560
   (Unify(Const m, Var v)    = Unify(Var v, Const m))                &
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   561
   (Unify(Var v, M) = (if (Var v <: M) then Fail else Subst[(v,M)])) &
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   562
   (Unify(Comb M N, Const x) = Fail)                                 &
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   563
   (Unify(Comb M N, Var v) = Unify(Var v, Comb M N))                 &
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   564
   (Unify(Comb M1 N1, Comb M2 N2) = 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   565
      (case Unify(M1,M2)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   566
        of Fail => Fail
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   567
         | Subst theta => (case Unify(N1 <| theta, N2 <| theta)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   568
                            of Fail => Fail
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   569
                             | Subst sigma => Subst (theta <> sigma))))`;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   570
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   571
 *---------------------------------------------------------------------------*)