src/HOL/Subst/Unify.ML
author nipkow
Wed, 30 Apr 2003 17:53:47 +0200
changeset 13937 e9d57517c9b1
parent 13630 a013a9dd370f
child 15197 19e735596e51
permissions -rw-r--r--
added a thm
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
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    35
 * The non-nested TC plus the wellfoundedness of unifyRel.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    36
 *---------------------------------------------------------------------------*)
8624
69619f870939 recdef.rules -> recdef.simps
nipkow
parents: 5278
diff changeset
    37
Tfl.tgoalw Unify.thy [] unify.simps;
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    38
(* Wellfoundedness of unifyRel *)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
    39
by (simp_tac (simpset() addsimps [unifyRel_def,
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    40
				 wf_inv_image, wf_lex_prod, wf_finite_psubset,
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
    41
				 wf_measure]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    42
(* TC *)
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3392
diff changeset
    43
by Safe_tac;
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
    44
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
    45
				 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
    46
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
    47
by (Blast_tac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
    48
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
    49
qed "tc0";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    50
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    51
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    52
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    53
 * Termination proof.
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
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
    56
Goalw [unifyRel_def, measure_def] "trans unifyRel";
3241
91b543ab091b Removal of duplicate code from TFL
paulson
parents: 3209
diff changeset
    57
by (REPEAT (resolve_tac [trans_inv_image, trans_lex_prod, 
91b543ab091b Removal of duplicate code from TFL
paulson
parents: 3209
diff changeset
    58
			 trans_finite_psubset, trans_less_than,
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
    59
			 trans_inv_image] 1));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    60
qed "trans_unifyRel";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    61
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    62
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    63
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    64
 * 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
    65
 * 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
    66
 * about term structure.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    67
 *---------------------------------------------------------------------------*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
    68
Goalw [unifyRel_def,lex_prod_def, inv_image_def]
5119
58d267fc8630 Removed leading !! in goals
nipkow
parents: 5069
diff changeset
    69
  "((X,Y), (Comb A (Comb B C), Comb D (Comb E F))) : unifyRel  ==> \
58d267fc8630 Removed leading !! in goals
nipkow
parents: 5069
diff changeset
    70
\  ((X,Y), (Comb (Comb A B) C, Comb (Comb D E) F)) : unifyRel";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
    71
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
    72
                          less_eq, inv_image_def,add_assoc]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    73
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
    74
                \  (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
    75
                \ (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
    76
                \  (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
    77
by (Blast_tac 2);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    78
by (Asm_simp_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    79
qed "Rassoc";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    80
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    81
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    82
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    83
 * 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
    84
 * 3, 4, and 6. 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    85
 *---------------------------------------------------------------------------*)
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
    86
Goal "~(Var x <: M) ==> \
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    87
\   ((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
    88
\ & ((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
    89
by (case_tac "Var x = M" 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    90
by (hyp_subst_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    91
by (Simp_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    92
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
    93
(*uterm_less case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    94
by (asm_simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
    95
    (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
    96
			measure_def, inv_image_def]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    97
by (Blast_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    98
(*finite_psubset case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    99
by (simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   100
    (simpset() addsimps [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);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   102
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
   103
				 psubset_def, set_eq_subset]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   104
by (Blast_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   105
(** LEVEL 9 **)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   106
(*Final case, also finite_psubset*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   107
by (simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   108
    (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
   109
			lex_prod_def, measure_def, inv_image_def]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   110
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
   111
by (cut_inst_tac [("s","[(x,M)]"), ("v", "x"), ("t","N1")] Var_elim 3);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   112
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
   113
by (REPEAT_FIRST (resolve_tac [conjI, disjI1, psubsetI]));
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   114
by (ALLGOALS (asm_full_simp_tac 
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   115
	      (simpset() addsimps [srange_iff, set_eq_subset]))); 
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   116
by (ALLGOALS
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   117
    (fast_tac (claset() addEs [Var_intro RS disjE]
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   118
	               addss (simpset() addsimps [srange_iff]))));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   119
qed "var_elimR";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   120
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   121
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   122
(*---------------------------------------------------------------------------
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   123
 * Eliminate tc0 from the recursion equations and the induction theorem.
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   124
 *---------------------------------------------------------------------------*)
3392
d0d86b96aa96 No longer refers to internal TFL structures
paulson
parents: 3334
diff changeset
   125
val wfr = tc0 RS conjunct1
d0d86b96aa96 No longer refers to internal TFL structures
paulson
parents: 3334
diff changeset
   126
and tc  = tc0 RS conjunct2;
9736
332fab43628f Fixed rulify.
nipkow
parents: 9371
diff changeset
   127
val unifyRules0 = map (rule_by_tactic (rtac wfr 1 THEN TRY(rtac tc 1)))
8624
69619f870939 recdef.rules -> recdef.simps
nipkow
parents: 5278
diff changeset
   128
                     unify.simps;
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   129
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   130
val unifyInduct0 = [wfr,tc] MRS unify.induct;
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   131
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   132
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   133
(*---------------------------------------------------------------------------
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   134
 * The nested TC. Proved by recursion induction.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   135
 *---------------------------------------------------------------------------*)
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   136
val [_,_,tc3] = unify.tcs;
3241
91b543ab091b Removal of duplicate code from TFL
paulson
parents: 3209
diff changeset
   137
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
   138
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   139
 * 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
   140
 * 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
   141
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   142
by (subgoal_tac "!M1 M2 theta.  \
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   143
 \   unify(M1, M2) = Some theta --> \
9371
2f06293f291a fixed nested prod syntax;
wenzelm
parents: 8624
diff changeset
   144
 \   (!N1 N2. ((N1<|theta, N2<|theta), (Comb M1 N1, Comb M2 N2)) : unifyRel)" 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   145
by (Blast_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   146
by (rtac allI 1); 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   147
by (rtac allI 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   148
(* Apply induction *)
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   149
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
   150
by (ALLGOALS 
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4153
diff changeset
   151
    (asm_simp_tac (simpset() addsimps (var_elimR::unifyRules0))));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   152
(*Const-Const case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   153
by (simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   154
    (simpset() addsimps [unifyRel_def, lex_prod_def, measure_def,
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   155
			inv_image_def, less_eq]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   156
(** LEVEL 7 **)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   157
(*Comb-Comb case*)
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5119
diff changeset
   158
by (asm_simp_tac (simpset() addsplits [option.split]) 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   159
by (strip_tac 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   160
by (rtac (trans_unifyRel RS transD) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   161
by (Blast_tac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   162
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
   163
by (rtac Rassoc 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   164
by (Blast_tac 1);
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   165
qed_spec_mp "unify_TC";
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   166
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   167
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   168
(*---------------------------------------------------------------------------
8624
69619f870939 recdef.rules -> recdef.simps
nipkow
parents: 5278
diff changeset
   169
 * Now for elimination of nested TC from unify.simps and induction. 
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   170
 *---------------------------------------------------------------------------*)
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
(*Desired rule, copied from the theory file.  Could it be made available?*)
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
   173
Goal "unify(Comb M1 N1, Comb M2 N2) =      \
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   174
\      (case unify(M1,M2)               \
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   175
\        of None => None                \
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   176
\         | Some theta => (case unify(N1 <| theta, N2 <| theta)        \
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   177
\                            of None => None    \
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   178
\                             | Some sigma => Some (theta <> sigma)))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   179
by (asm_simp_tac (simpset() addsimps (unify_TC::unifyRules0)
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5119
diff changeset
   180
			   addsplits [option.split]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   181
qed "unifyCombComb";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   182
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   183
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   184
val unifyRules = rev (unifyCombComb :: tl (rev unifyRules0));
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   185
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   186
Addsimps unifyRules;
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   187
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   188
bind_thm ("unifyInduct",
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   189
	  rule_by_tactic
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   190
	     (ALLGOALS (full_simp_tac (simpset() addsimps [unify_TC])))
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   191
	     unifyInduct0);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   193
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   194
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   195
 * 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
   196
 * 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
   197
 * 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
   198
 * 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
   199
 *---------------------------------------------------------------------------*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   200
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
   201
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
   202
by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4153
diff changeset
   203
by (ALLGOALS Asm_simp_tac);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   204
(*Const-Const case*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   205
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
   206
(*Const-Var case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   207
by (stac mgu_sym 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   208
by (simp_tac (simpset() addsimps [MGUnifier_Var]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   209
(*Var-M case*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   210
by (simp_tac (simpset() addsimps [MGUnifier_Var]) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   211
(*Comb-Var case*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   212
by (stac mgu_sym 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   213
by (simp_tac (simpset() addsimps [MGUnifier_Var]) 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   214
(** LEVEL 8 **)
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   215
(*Comb-Comb case*)
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5119
diff changeset
   216
by (asm_simp_tac (simpset() addsplits [option.split]) 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   217
by (strip_tac 1);
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   218
by (asm_full_simp_tac 
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   219
    (simpset() addsimps [MGUnifier_def, Unifier_def, MoreGeneral_def]) 1);
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4089
diff changeset
   220
by (Safe_tac THEN rename_tac "theta sigma gamma" 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   221
by (eres_inst_tac [("x","gamma")] allE 1 THEN mp_tac 1);
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   222
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
   223
by (eres_inst_tac [("x","delta")] allE 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   224
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
   225
(*Proving the subgoal*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   226
by (full_simp_tac (simpset() addsimps [subst_eq_iff]) 2
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   227
    THEN blast_tac (claset() addIs [trans,sym] delrules [impCE]) 2);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   228
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
   229
			      comp_assoc RS subst_sym]) 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   230
qed_spec_mp "unify_gives_MGU";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   231
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   232
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   233
(*---------------------------------------------------------------------------
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   234
 * Unify returns idempotent substitutions, when it succeeds.
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   235
 *---------------------------------------------------------------------------*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
   236
Goal "!theta. unify(M,N) = Some theta --> Idem theta";
3299
8adf24153732 Now uses type option instead of Fail/Subst
paulson
parents: 3266
diff changeset
   237
by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   238
by (ALLGOALS 
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   239
    (asm_simp_tac 
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5119
diff changeset
   240
       (simpset() addsimps [Var_Idem] addsplits [option.split])));
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   241
(*Comb-Comb case*)
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4089
diff changeset
   242
by Safe_tac;
3334
ec558598ee1d Simplified proofs using expand_option_case
paulson
parents: 3299
diff changeset
   243
by (REPEAT (dtac spec 1 THEN mp_tac 1));
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   244
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
   245
by (rtac Idem_comp 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   246
by (atac 1);
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   247
by (atac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4071
diff changeset
   248
by (best_tac (claset() addss (simpset() addsimps 
3266
89e5f4163663 Removed rprod from the WF relation; simplified proofs;
paulson
parents: 3241
diff changeset
   249
			     [MoreGeneral_def, subst_eq_iff, Idem_def])) 1);
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   250
qed_spec_mp "unify_gives_Idem";
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
   251