src/HOL/MiniML/Instance.ML
author wenzelm
Thu Jan 23 14:19:16 1997 +0100 (1997-01-23)
changeset 2545 d10abc8c11fb
parent 2525 477c05586286
child 2625 69c1b8a493de
permissions -rw-r--r--
added AxClasses test;
     1 (* Title:     HOL/MiniML/Instance.ML
     2    ID:        $Id$
     3    Author:    Wolfgang Naraschewski and Tobias Nipkow
     4    Copyright  1996 TU Muenchen
     5 *)
     6 
     7 (* lemmatas for instatiation *)
     8 
     9 
    10 (* lemmatas for bound_typ_inst *)
    11 
    12 goal thy "bound_typ_inst S (mk_scheme t) = t";
    13 by (typ.induct_tac "t" 1);
    14 by (ALLGOALS Asm_simp_tac);
    15 qed "bound_typ_inst_mk_scheme";
    16 
    17 Addsimps [bound_typ_inst_mk_scheme];
    18 goal thy "!!S. bound_typ_inst ($S o R) ($S sch) = $S (bound_typ_inst R sch)";
    19 by (type_scheme.induct_tac "sch" 1);
    20 by (ALLGOALS Asm_full_simp_tac);
    21 qed "bound_typ_inst_composed_subst";
    22 
    23 Addsimps [bound_typ_inst_composed_subst];
    24 
    25 goal thy "!!S. S = S' ==> sch = sch' ==> bound_typ_inst S sch = bound_typ_inst S' sch'";
    26 by (Asm_full_simp_tac 1);
    27 qed "bound_typ_inst_eq";
    28 
    29 
    30 (* lemmatas for bound_scheme_inst *)
    31 
    32 goal thy "!!t. bound_scheme_inst B (mk_scheme t) = mk_scheme t";
    33 by (typ.induct_tac "t" 1);
    34 by (Simp_tac 1);
    35 by (Asm_simp_tac 1);
    36 qed "bound_scheme_inst_mk_scheme";
    37 
    38 Addsimps [bound_scheme_inst_mk_scheme];
    39 
    40 goal thy "!!S. $S (bound_scheme_inst B sch) = (bound_scheme_inst ($S o B) ($ S sch))";
    41 by (type_scheme.induct_tac "sch" 1);
    42 by (Simp_tac 1);
    43 by (Simp_tac 1);
    44 by (Asm_simp_tac 1);
    45 qed "substitution_lemma";
    46 
    47 goal thy "!t. mk_scheme t = bound_scheme_inst B sch --> \
    48 \         (? S. !x:bound_tv sch. B x = mk_scheme (S x))";
    49 by (type_scheme.induct_tac "sch" 1);
    50 by (Simp_tac 1);
    51 by (safe_tac (!claset));
    52 by (rtac exI 1);
    53 by (rtac ballI 1);
    54 by (rtac sym 1);
    55 by (Asm_full_simp_tac 1);
    56 by (Asm_full_simp_tac 1);
    57 by (dtac mk_scheme_Fun 1);
    58 by (REPEAT (etac exE 1));
    59 by (etac conjE 1);
    60 by (dtac sym 1);
    61 by (dtac sym 1);
    62 by (REPEAT ((dtac mp 1) THEN (Fast_tac 1)));
    63 by (safe_tac (!claset));
    64 by (rename_tac "S1 S2" 1);
    65 by (res_inst_tac [("x","%x. if x:bound_tv type_scheme1 then (S1 x) else (S2 x)")] exI 1);
    66 by (safe_tac (!claset));
    67 by (asm_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
    68 by (asm_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
    69 by (strip_tac 1);
    70 by (dres_inst_tac [("x","x")] bspec 1);
    71 ba 1;
    72 by (dres_inst_tac [("x","x")] bspec 1);
    73 by (Asm_simp_tac 1);
    74 by (Asm_full_simp_tac 1);
    75 qed_spec_mp "bound_scheme_inst_type";
    76 
    77 
    78 (* lemmatas for subst_to_scheme *)
    79 
    80 goal thy "!!sch. new_tv n sch --> subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) \
    81 \                                                 (bound_typ_inst (%k. TVar (k + n)) sch) = sch";
    82 by (type_scheme.induct_tac "sch" 1);
    83 by (simp_tac (!simpset setloop (split_tac [expand_if]) addsimps [leD]) 1);
    84 by (simp_tac (!simpset setloop (split_tac [expand_if]) addsimps [le_add2,diff_add_inverse2]) 1);
    85 by (Asm_simp_tac 1);
    86 qed_spec_mp "subst_to_scheme_inverse";
    87 
    88 goal thy "!!t t'. t = t' ==> subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) t = \
    89 \                            subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) t'";
    90 by (Fast_tac 1);
    91 val aux = result ();
    92 
    93 goal thy "new_tv n sch --> \
    94 \        (subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) (bound_typ_inst S sch) = \
    95 \                         bound_scheme_inst ((subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k)) o S) sch)";
    96 by (type_scheme.induct_tac "sch" 1);
    97 by (simp_tac (!simpset setloop (split_tac [expand_if]) addsimps [leD]) 1);
    98 by (Asm_simp_tac 1);
    99 by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if]) addsimps [leD]) 1);
   100 val aux2 = result () RS mp;
   101 
   102 
   103 (* lemmata for <= *)
   104 
   105 goalw thy [le_type_scheme_def,is_bound_typ_instance]
   106       "!!(sch::type_scheme) sch'. (sch' <= sch) = (? B. sch' = bound_scheme_inst B sch)";
   107 by (rtac iffI 1);
   108 by (cut_inst_tac [("sch","sch")] fresh_variable_type_schemes 1); 
   109 by (cut_inst_tac [("sch","sch'")] fresh_variable_type_schemes 1);
   110 by (dtac make_one_new_out_of_two 1);
   111 ba 1;
   112 by (thin_tac "? n. new_tv n sch'" 1); 
   113 by (etac exE 1);
   114 by (etac allE 1);
   115 by (dtac mp 1);
   116 by (res_inst_tac [("x","(%k. TVar (k + n))")] exI 1);
   117 by (rtac refl 1);
   118 by (etac exE 1);
   119 by (REPEAT (etac conjE 1));
   120 by (dres_inst_tac [("n","n")] aux 1);
   121 by (asm_full_simp_tac (!simpset addsimps [subst_to_scheme_inverse]) 1);
   122 by (res_inst_tac [("x","(subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k)) o S")] exI 1);
   123 by (asm_simp_tac (!simpset addsimps [aux2]) 1);
   124 by (safe_tac (!claset));
   125 by (res_inst_tac [("x","%n. bound_typ_inst S (B n)")] exI 1);
   126 by (type_scheme.induct_tac "sch" 1);
   127 by (Simp_tac 1);
   128 by (Simp_tac 1);
   129 by (Asm_simp_tac 1);
   130 qed "le_type_scheme_def2";
   131 
   132 goalw thy [is_bound_typ_instance] "(mk_scheme t) <= sch = t <| sch";
   133 by (simp_tac (!simpset addsimps [le_type_scheme_def2]) 1); 
   134 by (rtac iffI 1); 
   135 by (etac exE 1); 
   136 by (forward_tac [bound_scheme_inst_type] 1);
   137 by (etac exE 1);
   138 by (rtac exI 1);
   139 by (rtac mk_scheme_injective 1); 
   140 by (Asm_full_simp_tac 1);
   141 by (rotate_tac 1 1);
   142 by (rtac mp 1);
   143 ba 2;
   144 by (type_scheme.induct_tac "sch" 1);
   145 by (Simp_tac 1);
   146 by (Asm_full_simp_tac 1);
   147 by (Fast_tac 1);
   148 by (strip_tac 1);
   149 by (Asm_full_simp_tac 1);
   150 by (etac exE 1);
   151 by (Asm_full_simp_tac 1);
   152 by (rtac exI 1);
   153 by (type_scheme.induct_tac "sch" 1);
   154 by (Simp_tac 1);
   155 by (Simp_tac 1);
   156 by (Asm_full_simp_tac 1);
   157 qed_spec_mp "le_type_eq_is_bound_typ_instance";
   158 
   159 goalw thy [le_env_def]
   160   "(sch # A <= sch' # B) = (sch <= (sch'::type_scheme) & A <= B)";
   161 by(Simp_tac 1);
   162 br iffI 1;
   163  by(SELECT_GOAL(safe_tac (!claset))1);
   164   by(eres_inst_tac [("x","0")] allE 1);
   165   by(Asm_full_simp_tac 1);
   166  by(eres_inst_tac [("x","Suc i")] allE 1);
   167  by(Asm_full_simp_tac 1);
   168 br conjI 1;
   169  by(Fast_tac 1);
   170 br allI 1;
   171 by(nat_ind_tac "i" 1);
   172 by(ALLGOALS Asm_simp_tac);
   173 qed "le_env_Cons";
   174 AddIffs [le_env_Cons];
   175 
   176 goalw thy [is_bound_typ_instance]"!!t. t <| sch ==> $S t <| $S sch";
   177 by (etac exE 1);
   178 by (rename_tac "SA" 1);
   179 by (hyp_subst_tac 1);
   180 by (res_inst_tac [("x","$S o SA")] exI 1);
   181 by (Simp_tac 1);
   182 qed "is_bound_typ_instance_closed_subst";
   183 
   184 goal thy "!!(sch::type_scheme) sch'. sch' <= sch ==> $S sch' <= $ S sch";
   185 by (asm_full_simp_tac (!simpset addsimps [le_type_scheme_def2]) 1);
   186 by (etac exE 1);
   187 by (asm_full_simp_tac (!simpset addsimps [substitution_lemma]) 1);
   188 by (Fast_tac 1);
   189 qed "S_compatible_le_scheme";
   190 
   191 goalw thy [le_env_def,app_subst_list] "!!(A::type_scheme list) A'. A' <= A ==> $S A' <= $ S A";
   192 by (simp_tac (!simpset addcongs [conj_cong]) 1);
   193 by (fast_tac (!claset addSIs [S_compatible_le_scheme]) 1);
   194 qed "S_compatible_le_scheme_lists";
   195 
   196 goalw thy [le_type_scheme_def] "!!t.[| t <| sch; sch <= sch' |] ==> t <| sch'";
   197 by(Fast_tac 1);
   198 qed "bound_typ_instance_trans";
   199 
   200 goalw thy [le_type_scheme_def] "sch <= (sch::type_scheme)";
   201 by(Fast_tac 1);
   202 qed "le_type_scheme_refl";
   203 AddIffs [le_type_scheme_refl];
   204 
   205 goalw thy [le_env_def] "A <= (A::type_scheme list)";
   206 by(Fast_tac 1);
   207 qed "le_env_refl";
   208 AddIffs [le_env_refl];
   209 
   210 goalw thy [le_type_scheme_def,is_bound_typ_instance] "sch <= BVar n";
   211 by(strip_tac 1);
   212 by(res_inst_tac [("x","%a.t")]exI 1);
   213 by(Simp_tac 1);
   214 qed "bound_typ_instance_BVar";
   215 AddIffs [bound_typ_instance_BVar];
   216 
   217 goalw thy [le_type_scheme_def,is_bound_typ_instance] "(sch <= FVar n) = (sch = FVar n)";
   218 by(type_scheme.induct_tac "sch" 1);
   219   by(Simp_tac 1);
   220  by(Simp_tac 1);
   221  by(SELECT_GOAL(safe_tac(!claset))1);
   222  by(eres_inst_tac [("x","TVar n -> TVar n")] allE 1);
   223  by(Asm_full_simp_tac 1);
   224  by(Fast_tac 1);
   225 by(Asm_full_simp_tac 1);
   226 br iffI 1;
   227  by(eres_inst_tac [("x","bound_typ_inst S type_scheme1 -> bound_typ_inst S type_scheme2")] allE 1);
   228  by(Asm_full_simp_tac 1);
   229  by(Fast_tac 1);
   230 by(Fast_tac 1);
   231 qed "le_FVar";
   232 Addsimps [le_FVar];
   233 
   234 goalw thy [le_type_scheme_def,is_bound_typ_instance] "~(FVar n <= sch1 =-> sch2)";
   235 by(Simp_tac 1);
   236 qed "not_FVar_le_Fun";
   237 AddIffs [not_FVar_le_Fun];
   238 
   239 goalw thy [le_type_scheme_def,is_bound_typ_instance] "~(BVar n <= sch1 =-> sch2)";
   240 by(Simp_tac 1);
   241 by(res_inst_tac [("x","TVar n")] exI 1);
   242 by(Simp_tac 1);
   243 by(Fast_tac 1);
   244 qed "not_BVar_le_Fun";
   245 AddIffs [not_BVar_le_Fun];
   246 
   247 goalw thy [le_type_scheme_def,is_bound_typ_instance]
   248   "!!sch1. (sch1 =-> sch2 <= sch1' =-> sch2') ==> sch1 <= sch1' & sch2 <= sch2'";
   249 by(fast_tac (!claset addss !simpset) 1);
   250 qed "Fun_le_FunD";
   251 
   252 goal thy "(sch' <= sch1 =-> sch2) --> (? sch'1 sch'2. sch' = sch'1 =-> sch'2)";
   253 by (type_scheme.induct_tac "sch'" 1);
   254 by (Asm_simp_tac 1);
   255 by (Asm_simp_tac 1);
   256 by (Fast_tac 1);
   257 qed_spec_mp "scheme_le_Fun";
   258 
   259 goal thy "!sch'::type_scheme. sch <= sch' --> free_tv sch' <= free_tv sch";
   260 by(type_scheme.induct_tac "sch" 1);
   261   br allI 1;
   262   by(type_scheme.induct_tac "sch'" 1);
   263     by(Simp_tac 1);
   264    by(Simp_tac 1);
   265   by(Simp_tac 1);
   266  br allI 1;
   267  by(type_scheme.induct_tac "sch'" 1);
   268    by(Simp_tac 1);
   269   by(Simp_tac 1);
   270  by(Simp_tac 1);
   271 br allI 1;
   272 by(type_scheme.induct_tac "sch'" 1);
   273   by(Simp_tac 1);
   274  by(Simp_tac 1);
   275 by(Asm_full_simp_tac 1);
   276 by(strip_tac 1);
   277 bd Fun_le_FunD 1;
   278 by(Fast_tac 1);
   279 qed_spec_mp "le_type_scheme_free_tv";
   280 
   281 goal thy "!A::type_scheme list. A <= B --> free_tv B <= free_tv A";
   282 by(list.induct_tac "B" 1);
   283  by(Simp_tac 1);
   284 br allI 1;
   285 by(list.induct_tac "A" 1);
   286  by(simp_tac (!simpset addsimps [le_env_def]) 1);
   287 by(Simp_tac 1);
   288 by(fast_tac (!claset addDs [le_type_scheme_free_tv]) 1);
   289 qed_spec_mp "le_env_free_tv";