src/HOL/Subst/Unify.ML
changeset 5069 3ea049f7979d
parent 4686 74a12e86b20b
child 5119 58d267fc8630
equal deleted inserted replaced
5068:fb28eaa07e01 5069:3ea049f7979d
    55 
    55 
    56 (*---------------------------------------------------------------------------
    56 (*---------------------------------------------------------------------------
    57  * Termination proof.
    57  * Termination proof.
    58  *---------------------------------------------------------------------------*)
    58  *---------------------------------------------------------------------------*)
    59 
    59 
    60 goalw Unify.thy [unifyRel_def, measure_def] "trans unifyRel";
    60 Goalw [unifyRel_def, measure_def] "trans unifyRel";
    61 by (REPEAT (resolve_tac [trans_inv_image, trans_lex_prod, 
    61 by (REPEAT (resolve_tac [trans_inv_image, trans_lex_prod, 
    62 			 trans_finite_psubset, trans_less_than,
    62 			 trans_finite_psubset, trans_less_than,
    63 			 trans_inv_image] 1));
    63 			 trans_inv_image] 1));
    64 qed "trans_unifyRel";
    64 qed "trans_unifyRel";
    65 
    65 
    67 (*---------------------------------------------------------------------------
    67 (*---------------------------------------------------------------------------
    68  * The following lemma is used in the last step of the termination proof for 
    68  * The following lemma is used in the last step of the termination proof for 
    69  * the nested call in Unify.  Loosely, it says that unifyRel doesn't care
    69  * the nested call in Unify.  Loosely, it says that unifyRel doesn't care
    70  * about term structure.
    70  * about term structure.
    71  *---------------------------------------------------------------------------*)
    71  *---------------------------------------------------------------------------*)
    72 goalw Unify.thy [unifyRel_def,lex_prod_def, inv_image_def]
    72 Goalw [unifyRel_def,lex_prod_def, inv_image_def]
    73      "!!x. ((X,Y), (Comb A (Comb B C), Comb D (Comb E F))) : unifyRel  ==> \
    73      "!!x. ((X,Y), (Comb A (Comb B C), Comb D (Comb E F))) : unifyRel  ==> \
    74     \      ((X,Y), (Comb (Comb A B) C, Comb (Comb D E) F)) : unifyRel";
    74     \      ((X,Y), (Comb (Comb A B) C, Comb (Comb D E) F)) : unifyRel";
    75 by (asm_full_simp_tac (simpset() addsimps [measure_def, 
    75 by (asm_full_simp_tac (simpset() addsimps [measure_def, 
    76                           less_eq, inv_image_def,add_assoc]) 1);
    76                           less_eq, inv_image_def,add_assoc]) 1);
    77 by (subgoal_tac "(vars_of A Un vars_of B Un vars_of C Un \
    77 by (subgoal_tac "(vars_of A Un vars_of B Un vars_of C Un \
    85 
    85 
    86 (*---------------------------------------------------------------------------
    86 (*---------------------------------------------------------------------------
    87  * This lemma proves the nested termination condition for the base cases 
    87  * This lemma proves the nested termination condition for the base cases 
    88  * 3, 4, and 6. 
    88  * 3, 4, and 6. 
    89  *---------------------------------------------------------------------------*)
    89  *---------------------------------------------------------------------------*)
    90 goal Unify.thy
    90 Goal
    91  "!!x. ~(Var x <: M) ==>        \
    91  "!!x. ~(Var x <: M) ==>        \
    92 \   ((N1 <| [(x,M)], N2 <| [(x,M)]), (Comb M N1, Comb(Var x) N2)) : unifyRel \
    92 \   ((N1 <| [(x,M)], N2 <| [(x,M)]), (Comb M N1, Comb(Var x) N2)) : unifyRel \
    93 \ & ((N1 <| [(x,M)], N2 <| [(x,M)]), (Comb(Var x) N1, Comb M N2)) : unifyRel";
    93 \ & ((N1 <| [(x,M)], N2 <| [(x,M)]), (Comb(Var x) N1, Comb M N2)) : unifyRel";
    94 by (case_tac "Var x = M" 1);
    94 by (case_tac "Var x = M" 1);
    95 by (hyp_subst_tac 1);
    95 by (hyp_subst_tac 1);
   173 (*---------------------------------------------------------------------------
   173 (*---------------------------------------------------------------------------
   174  * Now for elimination of nested TC from unify.rules and induction. 
   174  * Now for elimination of nested TC from unify.rules and induction. 
   175  *---------------------------------------------------------------------------*)
   175  *---------------------------------------------------------------------------*)
   176 
   176 
   177 (*Desired rule, copied from the theory file.  Could it be made available?*)
   177 (*Desired rule, copied from the theory file.  Could it be made available?*)
   178 goal Unify.thy 
   178 Goal 
   179   "unify(Comb M1 N1, Comb M2 N2) =      \
   179   "unify(Comb M1 N1, Comb M2 N2) =      \
   180 \      (case unify(M1,M2)               \
   180 \      (case unify(M1,M2)               \
   181 \        of None => None                \
   181 \        of None => None                \
   182 \         | Some theta => (case unify(N1 <| theta, N2 <| theta)        \
   182 \         | Some theta => (case unify(N1 <| theta, N2 <| theta)        \
   183 \                            of None => None    \
   183 \                            of None => None    \
   202  * algorithm terminates and is not needed to prove the algorithm correct, 
   202  * algorithm terminates and is not needed to prove the algorithm correct, 
   203  * if you are only interested in an MGU.  This is in contrast to the
   203  * if you are only interested in an MGU.  This is in contrast to the
   204  * approach of M&W, who used idempotence and MGU-ness in the termination proof.
   204  * approach of M&W, who used idempotence and MGU-ness in the termination proof.
   205  *---------------------------------------------------------------------------*)
   205  *---------------------------------------------------------------------------*)
   206 
   206 
   207 goal Unify.thy "!theta. unify(M,N) = Some theta --> MGUnifier theta M N";
   207 Goal "!theta. unify(M,N) = Some theta --> MGUnifier theta M N";
   208 by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
   208 by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
   209 by (ALLGOALS Asm_simp_tac);
   209 by (ALLGOALS Asm_simp_tac);
   210 (*Const-Const case*)
   210 (*Const-Const case*)
   211 by (simp_tac (simpset() addsimps [MGUnifier_def,Unifier_def]) 1);
   211 by (simp_tac (simpset() addsimps [MGUnifier_def,Unifier_def]) 1);
   212 (*Const-Var case*)
   212 (*Const-Var case*)
   238 
   238 
   239 
   239 
   240 (*---------------------------------------------------------------------------
   240 (*---------------------------------------------------------------------------
   241  * Unify returns idempotent substitutions, when it succeeds.
   241  * Unify returns idempotent substitutions, when it succeeds.
   242  *---------------------------------------------------------------------------*)
   242  *---------------------------------------------------------------------------*)
   243 goal Unify.thy "!theta. unify(M,N) = Some theta --> Idem theta";
   243 Goal "!theta. unify(M,N) = Some theta --> Idem theta";
   244 by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
   244 by (res_inst_tac [("u","M"),("v","N")] unifyInduct 1);
   245 by (ALLGOALS 
   245 by (ALLGOALS 
   246     (asm_simp_tac 
   246     (asm_simp_tac 
   247        (simpset() addsimps [Var_Idem] addsplits [split_option_case])));
   247        (simpset() addsimps [Var_Idem] addsplits [split_option_case])));
   248 (*Comb-Comb case*)
   248 (*Comb-Comb case*)