src/HOL/Subst/Subst.ML
changeset 3192 a75558a4ed37
parent 2087 6405a3bb490b
child 3268 012c43174664
equal deleted inserted replaced
3191:14bd6e5985f1 3192:a75558a4ed37
     6 For subst.thy.  
     6 For subst.thy.  
     7 *)
     7 *)
     8 
     8 
     9 open Subst;
     9 open Subst;
    10 
    10 
    11 (***********)
       
    12 
       
    13 val subst_defs = [subst_def,comp_def,sdom_def];
       
    14 
       
    15 val raw_subst_ss = simpset_of "UTLemmas" addsimps al_rews;
       
    16 
       
    17 local fun mk_thm s = prove_goalw Subst.thy subst_defs s 
       
    18                                  (fn _ => [simp_tac raw_subst_ss 1])
       
    19 in val subst_rews = map mk_thm 
       
    20 ["Const(c) <| al = Const(c)",
       
    21  "Comb t u <| al = Comb (t <| al) (u <| al)",
       
    22  "[] <> bl = bl",
       
    23  "((a,b)#al) <> bl = (a,b <| bl) # (al <> bl)",
       
    24  "sdom([]) = {}",
       
    25  "sdom((a,b)#al) = (if Var(a)=b then (sdom al) Int Compl({a}) \
       
    26 \                               else (sdom al) Un {a})"
       
    27 ];
       
    28    (* This rewrite isn't always desired *)
       
    29    val Var_subst = mk_thm "Var(x) <| al = assoc x (Var x) al";
       
    30 end;
       
    31 
       
    32 val subst_ss = raw_subst_ss addsimps subst_rews 
       
    33                             delsimps [de_Morgan_conj, de_Morgan_disj];
       
    34 
    11 
    35 (**** Substitutions ****)
    12 (**** Substitutions ****)
    36 
    13 
    37 goal Subst.thy "t <| [] = t";
    14 goal Subst.thy "t <| [] = t";
    38 by (uterm_ind_tac "t" 1);
    15 by (induct_tac "t" 1);
    39 by (ALLGOALS (asm_simp_tac (subst_ss addsimps [Var_subst])));
    16 by (ALLGOALS Asm_simp_tac);
    40 qed "subst_Nil";
    17 qed "subst_Nil";
    41 
    18 
       
    19 Addsimps [subst_Nil];
       
    20 
    42 goal Subst.thy "t <: u --> t <| s <: u <| s";
    21 goal Subst.thy "t <: u --> t <| s <: u <| s";
    43 by (uterm_ind_tac "u" 1);
    22 by (induct_tac "u" 1);
    44 by (ALLGOALS (asm_simp_tac subst_ss));
    23 by (ALLGOALS Asm_simp_tac);
    45 val subst_mono  = store_thm("subst_mono", result() RS mp);
    24 qed_spec_mp "subst_mono";
    46 
    25 
    47 goal Subst.thy  "~ (Var(v) <: t) --> t <| (v,t <| s)#s = t <| s";
    26 goal Subst.thy  "~ (Var(v) <: t) --> t <| (v,t <| s) # s = t <| s";
    48 by (imp_excluded_middle_tac "t = Var(v)" 1);
    27 by (case_tac "t = Var(v)" 1);
       
    28 be rev_mp 2;
    49 by (res_inst_tac [("P",
    29 by (res_inst_tac [("P",
    50     "%x.~x=Var(v) --> ~(Var(v) <: x) --> x <| (v,t<|s)#s=x<|s")]
    30     "%x.~x=Var(v) --> ~(Var(v) <: x) --> x <| (v,t<|s)#s=x<|s")]
    51     uterm_induct 2);
    31     uterm.induct 2);
    52 by (ALLGOALS (simp_tac (subst_ss addsimps [Var_subst])));
    32 by (ALLGOALS Asm_simp_tac);
    53 by (fast_tac HOL_cs 1);
    33 by (Blast_tac 1);
    54 val Var_not_occs  = store_thm("Var_not_occs", result() RS mp);
    34 qed_spec_mp "Var_not_occs";
    55 
    35 
    56 goal Subst.thy
    36 goal Subst.thy
    57     "(t <|r = t <|s) = (! v.v : vars_of(t) --> Var(v) <|r = Var(v) <|s)";
    37     "(t <|r = t <|s) = (! v.v : vars_of(t) --> Var(v) <|r = Var(v) <|s)";
    58 by (uterm_ind_tac "t" 1);
    38 by (induct_tac "t" 1);
    59 by (REPEAT (etac rev_mp 3));
    39 by (ALLGOALS Asm_full_simp_tac);
    60 by (ALLGOALS (asm_simp_tac subst_ss));
    40 by (ALLGOALS Blast_tac);
    61 by (ALLGOALS (fast_tac HOL_cs));
       
    62 qed "agreement";
    41 qed "agreement";
    63 
    42 
    64 goal Subst.thy   "~ v: vars_of(t) --> t <| (v,u)#s = t <| s";
    43 goal Subst.thy   "~ v: vars_of(t) --> t <| (v,u)#s = t <| s";
    65 by(simp_tac(subst_ss addsimps [agreement,Var_subst]
    44 by(simp_tac (!simpset addsimps [agreement]
    66                      setloop (split_tac [expand_if])) 1);
    45                       setloop (split_tac [expand_if])) 1);
    67 val repl_invariance  = store_thm("repl_invariance", result() RS mp);
    46 qed_spec_mp"repl_invariance";
    68 
    47 
    69 val asms = goal Subst.thy 
    48 val asms = goal Subst.thy 
    70      "v : vars_of(t) --> w : vars_of(t <| (v,Var(w))#s)";
    49      "v : vars_of(t) --> w : vars_of(t <| (v,Var(w))#s)";
    71 by (uterm_ind_tac "t" 1);
    50 by (induct_tac "t" 1);
    72 by (ALLGOALS (asm_simp_tac (subst_ss addsimps [Var_subst])));
    51 by (ALLGOALS Asm_simp_tac);
    73 val Var_in_subst  = store_thm("Var_in_subst", result() RS mp);
    52 qed_spec_mp"Var_in_subst";
       
    53 
    74 
    54 
    75 (**** Equality between Substitutions ****)
    55 (**** Equality between Substitutions ****)
    76 
    56 
    77 goalw Subst.thy [subst_eq_def] "r =s= s = (! t.t <| r = t <| s)";
    57 goalw Subst.thy [subst_eq_def] "r =$= s = (! t.t <| r = t <| s)";
    78 by (simp_tac subst_ss 1);
    58 by (Simp_tac 1);
    79 qed "subst_eq_iff";
    59 qed "subst_eq_iff";
    80 
    60 
    81 local fun mk_thm s = prove_goal Subst.thy s
    61 
       
    62 local fun prove s = prove_goal Subst.thy s
    82                   (fn prems => [cut_facts_tac prems 1,
    63                   (fn prems => [cut_facts_tac prems 1,
    83                                 REPEAT (etac rev_mp 1),
    64                                 REPEAT (etac rev_mp 1),
    84                                 simp_tac (subst_ss addsimps [subst_eq_iff]) 1])
    65                                 simp_tac (!simpset addsimps [subst_eq_iff]) 1])
    85 in 
    66 in 
    86   val subst_refl      = mk_thm "r = s ==> r =s= s";
    67   val subst_refl      = prove "r =$= r";
    87   val subst_sym       = mk_thm "r =s= s ==> s =s= r";
    68   val subst_sym       = prove "r =$= s ==> s =$= r";
    88   val subst_trans     = mk_thm "[| q =s= r; r =s= s |] ==> q =s= s";
    69   val subst_trans     = prove "[| q =$= r; r =$= s |] ==> q =$= s";
    89 end;
    70 end;
    90 
    71 
       
    72 
       
    73 AddIffs [subst_refl];
       
    74 
       
    75 
    91 val eq::prems = goalw Subst.thy [subst_eq_def] 
    76 val eq::prems = goalw Subst.thy [subst_eq_def] 
    92     "[| r =s= s; P (t <| r) (u <| r) |] ==> P (t <| s) (u <| s)";
    77     "[| r =$= s; P (t <| r) (u <| r) |] ==> P (t <| s) (u <| s)";
    93 by (resolve_tac [eq RS spec RS subst] 1);
    78 by (resolve_tac [eq RS spec RS subst] 1);
    94 by (resolve_tac (prems RL [eq RS spec RS subst]) 1);
    79 by (resolve_tac (prems RL [eq RS spec RS subst]) 1);
    95 qed "subst_subst2";
    80 qed "subst_subst2";
    96 
    81 
    97 val ssubst_subst2 = subst_sym RS subst_subst2;
    82 val ssubst_subst2 = subst_sym RS subst_subst2;
    98 
    83 
    99 (**** Composition of Substitutions ****)
    84 (**** Composition of Substitutions ****)
   100 
    85 
       
    86 let fun prove s = 
       
    87  prove_goalw Subst.thy [comp_def,sdom_def] s (fn _ => [Simp_tac 1])
       
    88 in 
       
    89 Addsimps
       
    90  (
       
    91    map prove 
       
    92    [ "[] <> bl = bl",
       
    93      "((a,b)#al) <> bl = (a,b <| bl) # (al <> bl)",
       
    94      "sdom([]) = {}",
       
    95      "sdom((a,b)#al) = (if Var(a)=b then (sdom al) - {a} else sdom al Un {a})"]
       
    96  )
       
    97 end;
       
    98 
       
    99 
   101 goal Subst.thy "s <> [] = s";
   100 goal Subst.thy "s <> [] = s";
   102 by (alist_ind_tac "s" 1);
   101 by (alist_ind_tac "s" 1);
   103 by (ALLGOALS (asm_simp_tac (subst_ss addsimps [subst_Nil])));
   102 by (ALLGOALS Asm_simp_tac);
   104 qed "comp_Nil";
   103 qed "comp_Nil";
   105 
   104 
       
   105 Addsimps [comp_Nil];
       
   106 
       
   107 goal Subst.thy "s =$= s <> []";
       
   108 by (Simp_tac 1);
       
   109 qed "subst_comp_Nil";
       
   110 
   106 goal Subst.thy "(t <| r <> s) = (t <| r <| s)";
   111 goal Subst.thy "(t <| r <> s) = (t <| r <| s)";
   107 by (uterm_ind_tac "t" 1);
   112 by (induct_tac "t" 1);
   108 by (ALLGOALS (asm_simp_tac (subst_ss addsimps [Var_subst])));
   113 by (ALLGOALS Asm_simp_tac);
   109 by (alist_ind_tac "r" 1);
   114 by (alist_ind_tac "r" 1);
   110 by (ALLGOALS (asm_simp_tac (subst_ss addsimps [Var_subst,subst_Nil]
   115 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
   111                                      setloop (split_tac [expand_if]))));
       
   112 qed "subst_comp";
   116 qed "subst_comp";
   113 
   117 
   114 goal Subst.thy "(q <> r) <> s =s= q <> (r <> s)";
   118 Addsimps [subst_comp];
   115 by (simp_tac (subst_ss addsimps [subst_eq_iff,subst_comp]) 1);
   119 
       
   120 goal Subst.thy "(q <> r) <> s =$= q <> (r <> s)";
       
   121 by (simp_tac (!simpset addsimps [subst_eq_iff]) 1);
   116 qed "comp_assoc";
   122 qed "comp_assoc";
   117 
   123 
   118 goal Subst.thy "(w,Var(w) <| s)#s =s= s"; 
   124 goal Subst.thy "!!s. [| theta =$= theta1; sigma =$= sigma1|] ==> \
   119 by (rtac (allI RS (subst_eq_iff RS iffD2)) 1);
   125              \       (theta <> sigma) =$= (theta1 <> sigma1)";
   120 by (uterm_ind_tac "t" 1);
   126 by (asm_full_simp_tac (!simpset addsimps [subst_eq_def]) 1);
   121 by (REPEAT (etac rev_mp 3));
   127 qed "subst_cong";
   122 by (ALLGOALS (simp_tac (subst_ss addsimps[Var_subst]
   128 
   123                                  setloop (split_tac [expand_if]))));
   129 
       
   130 goal Subst.thy "(w, Var(w) <| s) # s =$= s"; 
       
   131 by (simp_tac (!simpset addsimps [subst_eq_iff]) 1);
       
   132 by (rtac allI 1);
       
   133 by (induct_tac "t" 1);
       
   134 by (ALLGOALS (asm_full_simp_tac (!simpset setloop (split_tac [expand_if]))));
   124 qed "Cons_trivial";
   135 qed "Cons_trivial";
   125 
   136 
   126 val [prem] = goal Subst.thy "q <> r =s= s ==>  t <| q <| r = t <| s";
   137 
   127 by (simp_tac (subst_ss addsimps [prem RS (subst_eq_iff RS iffD1),
   138 goal Subst.thy "!!s. q <> r =$= s ==>  t <| q <| r = t <| s";
   128                                 subst_comp RS sym]) 1);
   139 by (asm_full_simp_tac (!simpset addsimps [subst_eq_iff]) 1);
   129 qed "comp_subst_subst";
   140 qed "comp_subst_subst";
   130 
   141 
       
   142 
   131 (****  Domain and range of Substitutions ****)
   143 (****  Domain and range of Substitutions ****)
   132 
   144 
   133 goal Subst.thy  "(v : sdom(s)) = (~ Var(v) <| s = Var(v))";
   145 goal Subst.thy  "(v : sdom(s)) = (Var(v) <| s ~= Var(v))";
   134 by (alist_ind_tac "s" 1);
   146 by (alist_ind_tac "s" 1);
   135 by (ALLGOALS (asm_simp_tac (subst_ss addsimps [Var_subst]
   147 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac[expand_if]))));
   136                             setloop (split_tac[expand_if]))));
   148 by (Blast_tac 1);
   137 by (fast_tac HOL_cs 1);
       
   138 qed "sdom_iff";
   149 qed "sdom_iff";
       
   150 
   139 
   151 
   140 goalw Subst.thy [srange_def]  
   152 goalw Subst.thy [srange_def]  
   141    "v : srange(s) = (? w.w : sdom(s) & v : vars_of(Var(w) <| s))";
   153    "v : srange(s) = (? w.w : sdom(s) & v : vars_of(Var(w) <| s))";
   142 by (fast_tac set_cs 1);
   154 by (Blast_tac 1);
   143 qed "srange_iff";
   155 qed "srange_iff";
   144 
   156 
       
   157 goalw Set.thy [empty_def] "(A = {}) = (ALL a.~ a:A)";
       
   158 by (Blast_tac 1);
       
   159 qed "empty_iff_all_not";
       
   160 
   145 goal Subst.thy  "(t <| s = t) = (sdom(s) Int vars_of(t) = {})";
   161 goal Subst.thy  "(t <| s = t) = (sdom(s) Int vars_of(t) = {})";
   146 by (uterm_ind_tac "t" 1);
   162 by (induct_tac "t" 1);
   147 by (REPEAT (etac rev_mp 3));
   163 by (ALLGOALS
   148 by (ALLGOALS (simp_tac (subst_ss addsimps [sdom_iff,Var_subst])));
   164     (asm_full_simp_tac (!simpset addsimps [empty_iff_all_not, sdom_iff])));
   149 by (ALLGOALS (fast_tac set_cs));
   165 by (ALLGOALS Blast_tac);
   150 qed "invariance";
   166 qed "invariance";
   151 
   167 
   152 goal Subst.thy  "v : sdom(s) -->  ~v : srange(s) --> ~v : vars_of(t <| s)";
   168 goal Subst.thy  "v : sdom(s) -->  v : vars_of(t <| s) --> v : srange(s)";
   153 by (uterm_ind_tac "t" 1);
   169 by (induct_tac "t" 1);
   154 by (imp_excluded_middle_tac "x : sdom(s)" 1);
   170 by (case_tac "a : sdom(s)" 1);
   155 by (ALLGOALS (asm_simp_tac (subst_ss addsimps [sdom_iff,srange_iff])));
   171 by (ALLGOALS (asm_full_simp_tac (!simpset addsimps [sdom_iff, srange_iff])));
   156 by (ALLGOALS (fast_tac set_cs));
   172 by (ALLGOALS Blast_tac);
   157 val Var_elim  = store_thm("Var_elim", result() RS mp RS mp);
   173 qed_spec_mp "Var_in_srange";
   158 
   174 
   159 val asms = goal Subst.thy 
   175 goal Subst.thy 
   160      "[| v : sdom(s); v : vars_of(t <| s) |] ==>  v : srange(s)";
   176      "!!v. [| v : sdom(s); v ~: srange(s) |] ==>  v ~: vars_of(t <| s)";
   161 by (REPEAT (ares_tac (asms @ [Var_elim RS swap RS classical]) 1));
   177 by (blast_tac (!claset addIs [Var_in_srange]) 1);
   162 qed "Var_elim2";
   178 qed "Var_elim";
   163 
   179 
   164 goal Subst.thy  "v : vars_of(t <| s) --> v : srange(s) | v : vars_of(t)";
   180 goal Subst.thy  "v : vars_of(t <| s) --> v : srange(s) | v : vars_of(t)";
   165 by (uterm_ind_tac "t" 1);
   181 by (induct_tac "t" 1);
   166 by (REPEAT_SOME (etac rev_mp ));
   182 by (ALLGOALS (asm_full_simp_tac (!simpset addsimps [sdom_iff,srange_iff])));
   167 by (ALLGOALS (simp_tac (subst_ss addsimps [sdom_iff,srange_iff])));
   183 by (Blast_tac 2);
   168 by (REPEAT (step_tac (set_cs addIs [vars_var_iff RS iffD1 RS sym]) 1));
   184 by (REPEAT (step_tac (!claset addIs [vars_var_iff RS iffD1 RS sym]) 1));
   169 by (etac notE 1);
   185 by (Auto_tac());
   170 by (etac subst 1);
   186 qed_spec_mp "Var_intro";
   171 by (ALLGOALS (fast_tac set_cs));
       
   172 val Var_intro  = store_thm("Var_intro", result() RS mp);
       
   173 
   187 
   174 goal Subst.thy
   188 goal Subst.thy
   175     "v : srange(s) --> (? w.w : sdom(s) & v : vars_of(Var(w) <| s))";
   189     "v : srange(s) --> (? w.w : sdom(s) & v : vars_of(Var(w) <| s))";
   176 by (simp_tac (subst_ss addsimps [srange_iff]) 1);
   190 by (simp_tac (!simpset addsimps [srange_iff]) 1);
   177 val srangeE  = store_thm("srangeE", make_elim (result() RS mp));
   191 qed_spec_mp "srangeD";
   178 
   192 
   179 val asms = goal Subst.thy
   193 goal Subst.thy
   180    "sdom(s) Int srange(s) = {} = (! t.sdom(s) Int vars_of(t <| s) = {})";
   194    "sdom(s) Int srange(s) = {} = (! t.sdom(s) Int vars_of(t <| s) = {})";
   181 by (simp_tac subst_ss 1);
   195 by (simp_tac (!simpset addsimps [empty_iff_all_not]) 1);
   182 by (fast_tac (set_cs addIs [Var_elim2] addEs [srangeE]) 1);
   196 by (fast_tac (!claset addIs [Var_in_srange] addDs [srangeD]) 1);
   183 qed "dom_range_disjoint";
   197 qed "dom_range_disjoint";
   184 
   198 
   185 val asms = goal Subst.thy "~ u <| s = u --> (? x.x : sdom(s))";
   199 goal Subst.thy "!!u. ~ u <| s = u ==> (? x. x : sdom(s))";
   186 by (simp_tac (subst_ss addsimps [invariance]) 1);
   200 by (full_simp_tac (!simpset addsimps [empty_iff_all_not, invariance]) 1);
   187 by (fast_tac set_cs 1);
   201 by (Blast_tac 1);
   188 val subst_not_empty  = store_thm("subst_not_empty", result() RS mp);
   202 qed "subst_not_empty";
       
   203 
       
   204 
       
   205 goal Subst.thy "(M <| [(x, Var x)]) = M";
       
   206 by (induct_tac "M" 1);
       
   207 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
       
   208 qed "id_subst_lemma";
       
   209 
       
   210 Addsimps [id_subst_lemma];