src/HOL/Subst/Unify.ML
author berghofe
Fri, 24 Jul 1998 13:19:38 +0200
changeset 5184 9b8547a9496a
parent 5119 58d267fc8630
child 5278 a903b66822e2
permissions -rw-r--r--
Adapted to new datatype package.
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
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
    60
Goalw [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
 *---------------------------------------------------------------------------*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
    72
Goalw [unifyRel_def,lex_prod_def, inv_image_def]
5119
58d267fc8630 Removed leading !! in goals
nipkow
parents: 5069
diff changeset
    73
  "((X,Y), (Comb A (Comb B C), Comb D (Comb E F))) : unifyRel  ==> \
58d267fc8630 Removed leading !! in goals
nipkow
parents: 5069
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
 *---------------------------------------------------------------------------*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
    90
Goal
5119
58d267fc8630 Removed leading !! in goals
nipkow
parents: 5069
diff changeset
    91
 "~(Var x <: M) ==> \
3192
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 
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4153
diff changeset
   156
    (asm_simp_tac (simpset() addsimps (var_elimR::unifyRules0))));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   157
(*Const-Const case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   158
by (simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   159
    (simpset() addsimps [unifyRel_def, lex_prod_def, measure_def,
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   160
			inv_image_def, less_eq]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   161
(** LEVEL 7 **)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   162
(*Comb-Comb case*)
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5119
diff changeset
   163
by (asm_simp_tac (simpset() addsplits [option.split]) 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   164
by (strip_tac 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   165
by (rtac (trans_unifyRel RS transD) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   166
by (Blast_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   167
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
   168
by (rtac Rassoc 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   169
by (Blast_tac 1);
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   170
qed_spec_mp "unify_TC";
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   171
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
 * 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
   175
 *---------------------------------------------------------------------------*)
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
(*Desired rule, copied from the theory file.  Could it be made available?*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
   178
Goal 
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   179
  "unify(Comb M1 N1, Comb M2 N2) =      \
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   180
\      (case unify(M1,M2)               \
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   181
\        of None => None                \
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   182
\         | Some theta => (case unify(N1 <| theta, N2 <| theta)        \
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   183
\                            of None => None    \
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   184
\                             | Some sigma => Some (theta <> sigma)))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   185
by (asm_simp_tac (simpset() addsimps (unify_TC::unifyRules0)
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5119
diff changeset
   186
			   addsplits [option.split]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   187
qed "unifyCombComb";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   188
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
val unifyRules = rev (unifyCombComb :: tl (rev unifyRules0));
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   191
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   192
Addsimps unifyRules;
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   193
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   194
bind_thm ("unifyInduct",
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   195
	  rule_by_tactic
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   196
	     (ALLGOALS (full_simp_tac (simpset() addsimps [unify_TC])))
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   197
	     unifyInduct0);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   198
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
 * 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
   202
 * 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
   203
 * 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
   204
 * 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
   205
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   206
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
   207
Goal "!theta. unify(M,N) = Some theta --> MGUnifier theta M N";
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   208
by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4153
diff changeset
   209
by (ALLGOALS Asm_simp_tac);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   210
(*Const-Const case*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   211
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
   212
(*Const-Var case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   213
by (stac mgu_sym 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   214
by (simp_tac (simpset() addsimps [MGUnifier_Var]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   215
(*Var-M case*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   216
by (simp_tac (simpset() addsimps [MGUnifier_Var]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   217
(*Comb-Var case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   218
by (stac mgu_sym 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   219
by (simp_tac (simpset() addsimps [MGUnifier_Var]) 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   220
(** LEVEL 8 **)
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   221
(*Comb-Comb case*)
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5119
diff changeset
   222
by (asm_simp_tac (simpset() addsplits [option.split]) 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   223
by (strip_tac 1);
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   224
by (rotate_tac ~2 1);
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   225
by (asm_full_simp_tac 
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   226
    (simpset() addsimps [MGUnifier_def, Unifier_def, MoreGeneral_def]) 1);
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4089
diff changeset
   227
by (Safe_tac THEN rename_tac "theta sigma gamma" 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   228
by (eres_inst_tac [("x","gamma")] allE 1 THEN mp_tac 1);
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   229
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
   230
by (eres_inst_tac [("x","delta")] allE 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   231
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
   232
(*Proving the subgoal*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   233
by (full_simp_tac (simpset() addsimps [subst_eq_iff]) 2
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   234
    THEN blast_tac (claset() addIs [trans,sym] delrules [impCE]) 2);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   235
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
   236
			      comp_assoc RS subst_sym]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   237
qed_spec_mp "unify_gives_MGU";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   238
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
 * Unify returns idempotent substitutions, when it succeeds.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   242
 *---------------------------------------------------------------------------*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
   243
Goal "!theta. unify(M,N) = Some theta --> Idem theta";
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   244
by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   245
by (ALLGOALS 
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   246
    (asm_simp_tac 
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5119
diff changeset
   247
       (simpset() addsimps [Var_Idem] addsplits [option.split])));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   248
(*Comb-Comb case*)
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4089
diff changeset
   249
by Safe_tac;
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   250
by (REPEAT (dtac spec 1 THEN mp_tac 1));
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   251
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
   252
by (rtac Idem_comp 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   253
by (atac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   254
by (atac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   255
by (best_tac (claset() addss (simpset() addsimps 
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   256
			     [MoreGeneral_def, subst_eq_iff, Idem_def])) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   257
qed_spec_mp "unify_gives_Idem";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   258