src/HOL/MiniML/Type.ML
changeset 5184 9b8547a9496a
parent 5118 6b995dad8a9d
child 5446 506259e4e546
equal deleted inserted replaced
5183:89f162de39cf 5184:9b8547a9496a
     8 
     8 
     9 
     9 
    10 (* lemmata for make scheme *)
    10 (* lemmata for make scheme *)
    11 
    11 
    12 Goal "mk_scheme t = sch1 =-> sch2 --> (? t1 t2. sch1 = mk_scheme t1 & sch2 = mk_scheme t2)";
    12 Goal "mk_scheme t = sch1 =-> sch2 --> (? t1 t2. sch1 = mk_scheme t1 & sch2 = mk_scheme t2)";
    13 by (typ.induct_tac "t" 1);
    13 by (induct_tac "t" 1);
    14 by (Simp_tac 1);
    14 by (Simp_tac 1);
    15 by (Asm_full_simp_tac 1);
    15 by (Asm_full_simp_tac 1);
    16 by (Fast_tac 1);
    16 by (Fast_tac 1);
    17 qed_spec_mp "mk_scheme_Fun";
    17 qed_spec_mp "mk_scheme_Fun";
    18 
    18 
    19 Goal "!t'. mk_scheme t = mk_scheme t' --> t=t'";
    19 Goal "!t'. mk_scheme t = mk_scheme t' --> t=t'";
    20 by (typ.induct_tac "t" 1);
    20 by (induct_tac "t" 1);
    21  by (rtac allI 1);
    21  by (rtac allI 1);
    22  by (typ.induct_tac "t'" 1);
    22  by (induct_tac "t'" 1);
    23   by (Simp_tac 1);
    23   by (Simp_tac 1);
    24  by (Asm_full_simp_tac 1);
    24  by (Asm_full_simp_tac 1);
    25 by (rtac allI 1);
    25 by (rtac allI 1);
    26 by (typ.induct_tac "t'" 1);
    26 by (induct_tac "t'" 1);
    27  by (Simp_tac 1);
    27  by (Simp_tac 1);
    28 by (Asm_full_simp_tac 1);
    28 by (Asm_full_simp_tac 1);
    29 qed_spec_mp "mk_scheme_injective";
    29 qed_spec_mp "mk_scheme_injective";
    30 
    30 
    31 Goal "free_tv (mk_scheme t) = free_tv t";
    31 Goal "free_tv (mk_scheme t) = free_tv t";
    32 by (typ.induct_tac "t" 1);
    32 by (induct_tac "t" 1);
    33 by (ALLGOALS Asm_simp_tac);
    33 by (ALLGOALS Asm_simp_tac);
    34 qed "free_tv_mk_scheme";
    34 qed "free_tv_mk_scheme";
    35 
    35 
    36 Addsimps [free_tv_mk_scheme];
    36 Addsimps [free_tv_mk_scheme];
    37 
    37 
    38 Goal "$ S (mk_scheme t) = mk_scheme ($ S t)";
    38 Goal "$ S (mk_scheme t) = mk_scheme ($ S t)";
    39 by (typ.induct_tac "t" 1);
    39 by (induct_tac "t" 1);
    40 by (ALLGOALS Asm_simp_tac);
    40 by (ALLGOALS Asm_simp_tac);
    41 qed "subst_mk_scheme";
    41 qed "subst_mk_scheme";
    42 
    42 
    43 Addsimps [subst_mk_scheme];
    43 Addsimps [subst_mk_scheme];
    44 
    44 
   108 qed "new_tv_id_subst";
   108 qed "new_tv_id_subst";
   109 Addsimps[new_tv_id_subst];
   109 Addsimps[new_tv_id_subst];
   110 
   110 
   111 Goal "new_tv n (sch::type_scheme) --> \
   111 Goal "new_tv n (sch::type_scheme) --> \
   112 \     $(%k. if k<n then S k else S' k) sch = $S sch";
   112 \     $(%k. if k<n then S k else S' k) sch = $S sch";
   113 by (type_scheme.induct_tac "sch" 1);
   113 by (induct_tac "sch" 1);
   114 by (ALLGOALS Asm_simp_tac);
   114 by (ALLGOALS Asm_simp_tac);
   115 qed "new_if_subst_type_scheme";
   115 qed "new_if_subst_type_scheme";
   116 Addsimps [new_if_subst_type_scheme];
   116 Addsimps [new_if_subst_type_scheme];
   117 
   117 
   118 Goal "new_tv n (A::type_scheme list) --> \
   118 Goal "new_tv n (A::type_scheme list) --> \
   119 \     $(%k. if k<n then S k else S' k) A = $S A";
   119 \     $(%k. if k<n then S k else S' k) A = $S A";
   120 by (list.induct_tac "A" 1);
   120 by (induct_tac "A" 1);
   121 by (ALLGOALS Asm_simp_tac);
   121 by (ALLGOALS Asm_simp_tac);
   122 qed "new_if_subst_type_scheme_list";
   122 qed "new_if_subst_type_scheme_list";
   123 Addsimps [new_if_subst_type_scheme_list];
   123 Addsimps [new_if_subst_type_scheme_list];
   124 
   124 
   125 
   125 
   145 by (Simp_tac 1);
   145 by (Simp_tac 1);
   146 qed "free_tv_id_subst";
   146 qed "free_tv_id_subst";
   147 Addsimps [free_tv_id_subst];
   147 Addsimps [free_tv_id_subst];
   148 
   148 
   149 Goal "!n. n < length A --> x : free_tv (A!n) --> x : free_tv A";
   149 Goal "!n. n < length A --> x : free_tv (A!n) --> x : free_tv A";
   150 by (list.induct_tac "A" 1);
   150 by (induct_tac "A" 1);
   151 by (Asm_full_simp_tac 1);
   151 by (Asm_full_simp_tac 1);
   152 by (rtac allI 1);
   152 by (rtac allI 1);
   153 by (res_inst_tac [("n","n")] nat_induct 1);
   153 by (res_inst_tac [("n","n")] nat_induct 1);
   154 by (Asm_full_simp_tac 1);
   154 by (Asm_full_simp_tac 1);
   155 by (Asm_full_simp_tac 1);
   155 by (Asm_full_simp_tac 1);
   156 qed_spec_mp "free_tv_nth_A_impl_free_tv_A";
   156 qed_spec_mp "free_tv_nth_A_impl_free_tv_A";
   157 
   157 
   158 Addsimps [free_tv_nth_A_impl_free_tv_A];
   158 Addsimps [free_tv_nth_A_impl_free_tv_A];
   159 
   159 
   160 Goal "!nat. nat < length A --> x : free_tv (A!nat) --> x : free_tv A";
   160 Goal "!nat. nat < length A --> x : free_tv (A!nat) --> x : free_tv A";
   161 by (list.induct_tac "A" 1);
   161 by (induct_tac "A" 1);
   162 by (Asm_full_simp_tac 1);
   162 by (Asm_full_simp_tac 1);
   163 by (rtac allI 1);
   163 by (rtac allI 1);
   164 by (res_inst_tac [("n","nat")] nat_induct 1);
   164 by (res_inst_tac [("n","nat")] nat_induct 1);
   165 by (strip_tac 1);
   165 by (strip_tac 1);
   166 by (Asm_full_simp_tac 1);
   166 by (Asm_full_simp_tac 1);
   171 (* if two substitutions yield the same result if applied to a type
   171 (* if two substitutions yield the same result if applied to a type
   172    structure the substitutions coincide on the free type variables
   172    structure the substitutions coincide on the free type variables
   173    occurring in the type structure *)
   173    occurring in the type structure *)
   174 
   174 
   175 Goal "(!x:free_tv t. (S x) = (S' x)) --> $ S (t::typ) = $ S' t";
   175 Goal "(!x:free_tv t. (S x) = (S' x)) --> $ S (t::typ) = $ S' t";
   176 by (typ.induct_tac "t" 1);
   176 by (induct_tac "t" 1);
   177 by (Simp_tac 1);
   177 by (Simp_tac 1);
   178 by (Asm_full_simp_tac 1);
   178 by (Asm_full_simp_tac 1);
   179 qed_spec_mp "typ_substitutions_only_on_free_variables";
   179 qed_spec_mp "typ_substitutions_only_on_free_variables";
   180 
   180 
   181 Goal  "(!n. n:(free_tv t) --> S1 n = S2 n) ==> $ S1 (t::typ) = $ S2 t";
   181 Goal  "(!n. n:(free_tv t) --> S1 n = S2 n) ==> $ S1 (t::typ) = $ S2 t";
   182 by (rtac typ_substitutions_only_on_free_variables 1);
   182 by (rtac typ_substitutions_only_on_free_variables 1);
   183 by (simp_tac (simpset() addsimps [Ball_def]) 1);
   183 by (simp_tac (simpset() addsimps [Ball_def]) 1);
   184 qed "eq_free_eq_subst_te";
   184 qed "eq_free_eq_subst_te";
   185 
   185 
   186 Goal "(!x:free_tv sch. (S x) = (S' x)) --> $ S (sch::type_scheme) = $ S' sch";
   186 Goal "(!x:free_tv sch. (S x) = (S' x)) --> $ S (sch::type_scheme) = $ S' sch";
   187 by (type_scheme.induct_tac "sch" 1);
   187 by (induct_tac "sch" 1);
   188 by (Simp_tac 1);
   188 by (Simp_tac 1);
   189 by (Simp_tac 1);
   189 by (Simp_tac 1);
   190 by (Asm_full_simp_tac 1);
   190 by (Asm_full_simp_tac 1);
   191 qed_spec_mp "scheme_substitutions_only_on_free_variables";
   191 qed_spec_mp "scheme_substitutions_only_on_free_variables";
   192 
   192 
   196 by (simp_tac (simpset() addsimps [Ball_def]) 1);
   196 by (simp_tac (simpset() addsimps [Ball_def]) 1);
   197 qed "eq_free_eq_subst_type_scheme";
   197 qed "eq_free_eq_subst_type_scheme";
   198 
   198 
   199 Goal
   199 Goal
   200   "(!n. n:(free_tv A) --> S1 n = S2 n) --> $S1 (A::type_scheme list) = $S2 A";
   200   "(!n. n:(free_tv A) --> S1 n = S2 n) --> $S1 (A::type_scheme list) = $S2 A";
   201 by (list.induct_tac "A" 1); 
   201 by (induct_tac "A" 1); 
   202 (* case [] *)
   202 (* case [] *)
   203 by (fast_tac (HOL_cs addss simpset()) 1);
   203 by (fast_tac (HOL_cs addss simpset()) 1);
   204 (* case x#xl *)
   204 (* case x#xl *)
   205 by (fast_tac (HOL_cs addIs [eq_free_eq_subst_type_scheme] addss (simpset())) 1);
   205 by (fast_tac (HOL_cs addIs [eq_free_eq_subst_type_scheme] addss (simpset())) 1);
   206 qed_spec_mp "eq_free_eq_subst_scheme_list";
   206 qed_spec_mp "eq_free_eq_subst_scheme_list";
   208 Goal "((!x:A. (P x)) --> Q) ==> ((!x:A Un B. (P x)) --> Q)";
   208 Goal "((!x:A. (P x)) --> Q) ==> ((!x:A Un B. (P x)) --> Q)";
   209 by (Fast_tac 1);
   209 by (Fast_tac 1);
   210 val weaken_asm_Un = result ();
   210 val weaken_asm_Un = result ();
   211 
   211 
   212 Goal "(!x:free_tv A. (S x) = (S' x)) --> $ S (A::type_scheme list) = $ S' A";
   212 Goal "(!x:free_tv A. (S x) = (S' x)) --> $ S (A::type_scheme list) = $ S' A";
   213 by (list.induct_tac "A" 1);
   213 by (induct_tac "A" 1);
   214 by (Simp_tac 1);
   214 by (Simp_tac 1);
   215 by (Asm_full_simp_tac 1);
   215 by (Asm_full_simp_tac 1);
   216 by (rtac weaken_asm_Un 1);
   216 by (rtac weaken_asm_Un 1);
   217 by (strip_tac 1);
   217 by (strip_tac 1);
   218 by (etac scheme_substitutions_only_on_free_variables 1);
   218 by (etac scheme_substitutions_only_on_free_variables 1);
   219 qed_spec_mp "scheme_list_substitutions_only_on_free_variables";
   219 qed_spec_mp "scheme_list_substitutions_only_on_free_variables";
   220 
   220 
   221 Goal
   221 Goal
   222   "$ S1 (t::typ) = $ S2 t --> n:(free_tv t) --> S1 n = S2 n";
   222   "$ S1 (t::typ) = $ S2 t --> n:(free_tv t) --> S1 n = S2 n";
   223 by (typ.induct_tac "t" 1);
   223 by (induct_tac "t" 1);
   224 (* case TVar n *)
   224 (* case TVar n *)
   225 by (fast_tac (HOL_cs addss simpset()) 1);
   225 by (fast_tac (HOL_cs addss simpset()) 1);
   226 (* case Fun t1 t2 *)
   226 (* case Fun t1 t2 *)
   227 by (fast_tac (HOL_cs addss simpset()) 1);
   227 by (fast_tac (HOL_cs addss simpset()) 1);
   228 qed_spec_mp "eq_subst_te_eq_free";
   228 qed_spec_mp "eq_subst_te_eq_free";
   229 
   229 
   230 Goal
   230 Goal
   231   "$ S1 (sch::type_scheme) = $ S2 sch --> n:(free_tv sch) --> S1 n = S2 n";
   231   "$ S1 (sch::type_scheme) = $ S2 sch --> n:(free_tv sch) --> S1 n = S2 n";
   232 by (type_scheme.induct_tac "sch" 1);
   232 by (induct_tac "sch" 1);
   233 (* case TVar n *)
   233 (* case TVar n *)
   234 by (Asm_simp_tac 1);
   234 by (Asm_simp_tac 1);
   235 (* case BVar n *)
   235 (* case BVar n *)
   236 by (strip_tac 1);
   236 by (strip_tac 1);
   237 by (etac mk_scheme_injective 1);
   237 by (etac mk_scheme_injective 1);
   240 by (Asm_full_simp_tac 1);
   240 by (Asm_full_simp_tac 1);
   241 qed_spec_mp "eq_subst_type_scheme_eq_free";
   241 qed_spec_mp "eq_subst_type_scheme_eq_free";
   242 
   242 
   243 Goal
   243 Goal
   244   "$S1 (A::type_scheme list) = $S2 A --> n:(free_tv A) --> S1 n = S2 n";
   244   "$S1 (A::type_scheme list) = $S2 A --> n:(free_tv A) --> S1 n = S2 n";
   245 by (list.induct_tac "A" 1);
   245 by (induct_tac "A" 1);
   246 (* case [] *)
   246 (* case [] *)
   247 by (fast_tac (HOL_cs addss simpset()) 1);
   247 by (fast_tac (HOL_cs addss simpset()) 1);
   248 (* case x#xl *)
   248 (* case x#xl *)
   249 by (fast_tac (HOL_cs addIs [eq_subst_type_scheme_eq_free] addss (simpset())) 1);
   249 by (fast_tac (HOL_cs addIs [eq_subst_type_scheme_eq_free] addss (simpset())) 1);
   250 qed_spec_mp "eq_subst_scheme_list_eq_free";
   250 qed_spec_mp "eq_subst_scheme_list_eq_free";
   279 by (fast_tac (set_cs addss (simpset() addsimps [cod_def])) 1);
   279 by (fast_tac (set_cs addss (simpset() addsimps [cod_def])) 1);
   280 by (fast_tac (set_cs addss (simpset() addsimps [dom_def])) 1);
   280 by (fast_tac (set_cs addss (simpset() addsimps [dom_def])) 1);
   281 qed "free_tv_subst_var";
   281 qed "free_tv_subst_var";
   282 
   282 
   283 Goal "free_tv ($ S (t::typ)) <= cod S Un free_tv t";
   283 Goal "free_tv ($ S (t::typ)) <= cod S Un free_tv t";
   284 by (typ.induct_tac "t" 1);
   284 by (induct_tac "t" 1);
   285 (* case TVar n *)
   285 (* case TVar n *)
   286 by (simp_tac (simpset() addsimps [free_tv_subst_var]) 1);
   286 by (simp_tac (simpset() addsimps [free_tv_subst_var]) 1);
   287 (* case Fun t1 t2 *)
   287 (* case Fun t1 t2 *)
   288 by (fast_tac (set_cs addss simpset()) 1);
   288 by (fast_tac (set_cs addss simpset()) 1);
   289 qed "free_tv_app_subst_te";     
   289 qed "free_tv_app_subst_te";     
   290 
   290 
   291 Goal "free_tv ($ S (sch::type_scheme)) <= cod S Un free_tv sch";
   291 Goal "free_tv ($ S (sch::type_scheme)) <= cod S Un free_tv sch";
   292 by (type_scheme.induct_tac "sch" 1);
   292 by (induct_tac "sch" 1);
   293 (* case FVar n *)
   293 (* case FVar n *)
   294 by (simp_tac (simpset() addsimps [free_tv_subst_var]) 1);
   294 by (simp_tac (simpset() addsimps [free_tv_subst_var]) 1);
   295 (* case BVar n *)
   295 (* case BVar n *)
   296 by (Simp_tac 1);
   296 by (Simp_tac 1);
   297 (* case Fun t1 t2 *)
   297 (* case Fun t1 t2 *)
   298 by (fast_tac (set_cs addss simpset()) 1);
   298 by (fast_tac (set_cs addss simpset()) 1);
   299 qed "free_tv_app_subst_type_scheme";  
   299 qed "free_tv_app_subst_type_scheme";  
   300 
   300 
   301 Goal "free_tv ($ S (A::type_scheme list)) <= cod S Un free_tv A";
   301 Goal "free_tv ($ S (A::type_scheme list)) <= cod S Un free_tv A";
   302 by (list.induct_tac "A" 1);
   302 by (induct_tac "A" 1);
   303 (* case [] *)
   303 (* case [] *)
   304 by (Simp_tac 1);
   304 by (Simp_tac 1);
   305 (* case a#al *)
   305 (* case a#al *)
   306 by (cut_facts_tac [free_tv_app_subst_type_scheme] 1);
   306 by (cut_facts_tac [free_tv_app_subst_type_scheme] 1);
   307 by (fast_tac (set_cs addss simpset()) 1);
   307 by (fast_tac (set_cs addss simpset()) 1);
   320      "free_tv ($ S1 o S2) <= free_tv S1 Un free_tv (S2 :: nat => typ)";
   320      "free_tv ($ S1 o S2) <= free_tv S1 Un free_tv (S2 :: nat => typ)";
   321 by (rtac free_tv_comp_subst 1);
   321 by (rtac free_tv_comp_subst 1);
   322 qed "free_tv_o_subst";
   322 qed "free_tv_o_subst";
   323 
   323 
   324 Goal "n : free_tv t --> free_tv (S n) <= free_tv ($ S t::typ)";
   324 Goal "n : free_tv t --> free_tv (S n) <= free_tv ($ S t::typ)";
   325 by (typ.induct_tac "t" 1);
   325 by (induct_tac "t" 1);
   326 by (Simp_tac 1);
   326 by (Simp_tac 1);
   327 by (Simp_tac 1);
   327 by (Simp_tac 1);
   328 by (Fast_tac 1);
   328 by (Fast_tac 1);
   329 qed_spec_mp "free_tv_of_substitutions_extend_to_types";
   329 qed_spec_mp "free_tv_of_substitutions_extend_to_types";
   330 
   330 
   331 Goal "n : free_tv sch --> free_tv (S n) <= free_tv ($ S sch::type_scheme)";
   331 Goal "n : free_tv sch --> free_tv (S n) <= free_tv ($ S sch::type_scheme)";
   332 by (type_scheme.induct_tac "sch" 1);
   332 by (induct_tac "sch" 1);
   333 by (Simp_tac 1);
   333 by (Simp_tac 1);
   334 by (Simp_tac 1);
   334 by (Simp_tac 1);
   335 by (Simp_tac 1);
   335 by (Simp_tac 1);
   336 by (Fast_tac 1);
   336 by (Fast_tac 1);
   337 qed_spec_mp "free_tv_of_substitutions_extend_to_schemes";
   337 qed_spec_mp "free_tv_of_substitutions_extend_to_schemes";
   338 
   338 
   339 Goal "n : free_tv A --> free_tv (S n) <= free_tv ($ S A::type_scheme list)";
   339 Goal "n : free_tv A --> free_tv (S n) <= free_tv ($ S A::type_scheme list)";
   340 by (list.induct_tac "A" 1);
   340 by (induct_tac "A" 1);
   341 by (Simp_tac 1);
   341 by (Simp_tac 1);
   342 by (Simp_tac 1);
   342 by (Simp_tac 1);
   343 by (fast_tac (claset() addDs [free_tv_of_substitutions_extend_to_schemes]) 1);
   343 by (fast_tac (claset() addDs [free_tv_of_substitutions_extend_to_schemes]) 1);
   344 qed_spec_mp "free_tv_of_substitutions_extend_to_scheme_lists";
   344 qed_spec_mp "free_tv_of_substitutions_extend_to_scheme_lists";
   345 
   345 
   346 Addsimps [free_tv_of_substitutions_extend_to_scheme_lists];
   346 Addsimps [free_tv_of_substitutions_extend_to_scheme_lists];
   347 
   347 
   348 Goal "!!sch::type_scheme. (n : free_tv sch) = (n mem free_tv_ML sch)";
   348 Goal "!!sch::type_scheme. (n : free_tv sch) = (n mem free_tv_ML sch)";
   349 by (type_scheme.induct_tac "sch" 1);
   349 by (induct_tac "sch" 1);
   350 by (ALLGOALS Asm_simp_tac);
   350 by (ALLGOALS Asm_simp_tac);
   351 by (strip_tac 1);
   351 by (strip_tac 1);
   352 by (Fast_tac 1);
   352 by (Fast_tac 1);
   353 qed "free_tv_ML_scheme";
   353 qed "free_tv_ML_scheme";
   354 
   354 
   355 Goal "!!A::type_scheme list. (n : free_tv A) = (n mem free_tv_ML A)";
   355 Goal "!!A::type_scheme list. (n : free_tv A) = (n mem free_tv_ML A)";
   356 by (list.induct_tac "A" 1);
   356 by (induct_tac "A" 1);
   357 by (Simp_tac 1);
   357 by (Simp_tac 1);
   358 by (asm_simp_tac (simpset() addsimps [free_tv_ML_scheme]) 1);
   358 by (asm_simp_tac (simpset() addsimps [free_tv_ML_scheme]) 1);
   359 qed "free_tv_ML_scheme_list";
   359 qed "free_tv_ML_scheme_list";
   360 
   360 
   361 
   361 
   362 (* lemmata for bound_tv *)
   362 (* lemmata for bound_tv *)
   363 
   363 
   364 Goal "bound_tv (mk_scheme t) = {}";
   364 Goal "bound_tv (mk_scheme t) = {}";
   365 by (typ.induct_tac "t" 1);
   365 by (induct_tac "t" 1);
   366 by (ALLGOALS Asm_simp_tac);
   366 by (ALLGOALS Asm_simp_tac);
   367 qed "bound_tv_mk_scheme";
   367 qed "bound_tv_mk_scheme";
   368 
   368 
   369 Addsimps [bound_tv_mk_scheme];
   369 Addsimps [bound_tv_mk_scheme];
   370 
   370 
   371 Goal "!!sch::type_scheme. bound_tv ($ S sch) = bound_tv sch";
   371 Goal "!!sch::type_scheme. bound_tv ($ S sch) = bound_tv sch";
   372 by (type_scheme.induct_tac "sch" 1);
   372 by (induct_tac "sch" 1);
   373 by (ALLGOALS Asm_simp_tac);
   373 by (ALLGOALS Asm_simp_tac);
   374 qed "bound_tv_subst_scheme";
   374 qed "bound_tv_subst_scheme";
   375 
   375 
   376 Addsimps [bound_tv_subst_scheme];
   376 Addsimps [bound_tv_subst_scheme];
   377 
   377 
   408 qed "new_tv_subst";
   408 qed "new_tv_subst";
   409 
   409 
   410 Goal 
   410 Goal 
   411   "new_tv n  = list_all (new_tv n)";
   411   "new_tv n  = list_all (new_tv n)";
   412 by (rtac ext 1);
   412 by (rtac ext 1);
   413 by (list.induct_tac "x" 1);
   413 by (induct_tac "x" 1);
   414 by (ALLGOALS Asm_simp_tac);
   414 by (ALLGOALS Asm_simp_tac);
   415 qed "new_tv_list";
   415 qed "new_tv_list";
   416 
   416 
   417 (* substitution affects only variables occurring freely *)
   417 (* substitution affects only variables occurring freely *)
   418 Goal
   418 Goal
   419   "new_tv n (t::typ) --> $(%x. if x=n then t' else S x) t = $S t";
   419   "new_tv n (t::typ) --> $(%x. if x=n then t' else S x) t = $S t";
   420 by (typ.induct_tac "t" 1);
   420 by (induct_tac "t" 1);
   421 by (ALLGOALS Asm_simp_tac);
   421 by (ALLGOALS Asm_simp_tac);
   422 qed "subst_te_new_tv";
   422 qed "subst_te_new_tv";
   423 Addsimps [subst_te_new_tv];
   423 Addsimps [subst_te_new_tv];
   424 
   424 
   425 Goal
   425 Goal
   426   "new_tv n (sch::type_scheme) --> $(%x. if x=n then sch' else S x) sch = $S sch";
   426   "new_tv n (sch::type_scheme) --> $(%x. if x=n then sch' else S x) sch = $S sch";
   427 by (type_scheme.induct_tac "sch" 1);
   427 by (induct_tac "sch" 1);
   428 by (ALLGOALS Asm_simp_tac);
   428 by (ALLGOALS Asm_simp_tac);
   429 qed_spec_mp "subst_te_new_type_scheme";
   429 qed_spec_mp "subst_te_new_type_scheme";
   430 Addsimps [subst_te_new_type_scheme];
   430 Addsimps [subst_te_new_type_scheme];
   431 
   431 
   432 Goal
   432 Goal
   433   "new_tv n (A::type_scheme list) --> $(%x. if x=n then t else S x) A = $S A";
   433   "new_tv n (A::type_scheme list) --> $(%x. if x=n then t else S x) A = $S A";
   434 by (list.induct_tac "A" 1);
   434 by (induct_tac "A" 1);
   435 by (ALLGOALS Asm_full_simp_tac);
   435 by (ALLGOALS Asm_full_simp_tac);
   436 qed_spec_mp "subst_tel_new_scheme_list";
   436 qed_spec_mp "subst_tel_new_scheme_list";
   437 Addsimps [subst_tel_new_scheme_list];
   437 Addsimps [subst_tel_new_scheme_list];
   438 
   438 
   439 (* all greater variables are also new *)
   439 (* all greater variables are also new *)
   464 by (asm_full_simp_tac (simpset() addsimps [new_tv_subst]) 1);
   464 by (asm_full_simp_tac (simpset() addsimps [new_tv_subst]) 1);
   465 qed "new_tv_subst_var";
   465 qed "new_tv_subst_var";
   466 
   466 
   467 Goal
   467 Goal
   468   "new_tv n S --> new_tv n (t::typ) --> new_tv n ($ S t)";
   468   "new_tv n S --> new_tv n (t::typ) --> new_tv n ($ S t)";
   469 by (typ.induct_tac "t" 1);
   469 by (induct_tac "t" 1);
   470 by (ALLGOALS(fast_tac (HOL_cs addss (simpset() addsimps [new_tv_subst]))));
   470 by (ALLGOALS(fast_tac (HOL_cs addss (simpset() addsimps [new_tv_subst]))));
   471 qed_spec_mp "new_tv_subst_te";
   471 qed_spec_mp "new_tv_subst_te";
   472 Addsimps [new_tv_subst_te];
   472 Addsimps [new_tv_subst_te];
   473 
   473 
   474 Goal "new_tv n S --> new_tv n (sch::type_scheme) --> new_tv n ($ S sch)";
   474 Goal "new_tv n S --> new_tv n (sch::type_scheme) --> new_tv n ($ S sch)";
   475 by (type_scheme.induct_tac "sch" 1);
   475 by (induct_tac "sch" 1);
   476 by (ALLGOALS (Asm_full_simp_tac));
   476 by (ALLGOALS (Asm_full_simp_tac));
   477 by (rewtac new_tv_def);
   477 by (rewtac new_tv_def);
   478 by (simp_tac (simpset() addsimps [free_tv_subst,dom_def,cod_def]) 1);
   478 by (simp_tac (simpset() addsimps [free_tv_subst,dom_def,cod_def]) 1);
   479 by (strip_tac 1);
   479 by (strip_tac 1);
   480 by (case_tac "S nat = TVar nat" 1);
   480 by (case_tac "S nat = TVar nat" 1);
   485 qed_spec_mp "new_tv_subst_type_scheme";
   485 qed_spec_mp "new_tv_subst_type_scheme";
   486 Addsimps [new_tv_subst_type_scheme];
   486 Addsimps [new_tv_subst_type_scheme];
   487 
   487 
   488 Goal
   488 Goal
   489   "new_tv n S --> new_tv n (A::type_scheme list) --> new_tv n ($ S A)";
   489   "new_tv n S --> new_tv n (A::type_scheme list) --> new_tv n ($ S A)";
   490 by (list.induct_tac "A" 1);
   490 by (induct_tac "A" 1);
   491 by (ALLGOALS(fast_tac (HOL_cs addss (simpset()))));
   491 by (ALLGOALS(fast_tac (HOL_cs addss (simpset()))));
   492 qed_spec_mp "new_tv_subst_scheme_list";
   492 qed_spec_mp "new_tv_subst_scheme_list";
   493 Addsimps [new_tv_subst_scheme_list];
   493 Addsimps [new_tv_subst_scheme_list];
   494 
   494 
   495 Goal
   495 Goal
   496   "new_tv n A --> new_tv (Suc n) ((TVar n)#A)";
   496   "new_tv n A --> new_tv (Suc n) ((TVar n)#A)";
   497 by (simp_tac (simpset() addsimps [new_tv_list]) 1);
   497 by (simp_tac (simpset() addsimps [new_tv_list]) 1);
   498 by (list.induct_tac "A" 1);
   498 by (induct_tac "A" 1);
   499 by (ALLGOALS Asm_full_simp_tac);
   499 by (ALLGOALS Asm_full_simp_tac);
   500 qed "new_tv_Suc_list";
   500 qed "new_tv_Suc_list";
   501 
   501 
   502 Goalw [new_tv_def] "!!sch::type_scheme. (free_tv sch) = (free_tv sch') --> (new_tv n sch --> new_tv n sch')";
   502 Goalw [new_tv_def] "!!sch::type_scheme. (free_tv sch) = (free_tv sch') --> (new_tv n sch --> new_tv n sch')";
   503 by (Asm_simp_tac 1);
   503 by (Asm_simp_tac 1);
   507 by (Asm_simp_tac 1);
   507 by (Asm_simp_tac 1);
   508 qed_spec_mp "new_tv_only_depends_on_free_tv_scheme_list";
   508 qed_spec_mp "new_tv_only_depends_on_free_tv_scheme_list";
   509 
   509 
   510 Goalw [new_tv_def]
   510 Goalw [new_tv_def]
   511   "!nat. nat < length A --> new_tv n A --> (new_tv n (A!nat))";
   511   "!nat. nat < length A --> new_tv n A --> (new_tv n (A!nat))";
   512 by (list.induct_tac "A" 1);
   512 by (induct_tac "A" 1);
   513 by (Asm_full_simp_tac 1);
   513 by (Asm_full_simp_tac 1);
   514 by (rtac allI 1);
   514 by (rtac allI 1);
   515 by (res_inst_tac [("n","nat")] nat_induct 1);
   515 by (res_inst_tac [("n","nat")] nat_induct 1);
   516 by (strip_tac 1);
   516 by (strip_tac 1);
   517 by (Asm_full_simp_tac 1);
   517 by (Asm_full_simp_tac 1);
   547 by (Simp_tac 1);
   547 by (Simp_tac 1);
   548 by (fast_tac (claset() addDs [not_leE] addIs [less_trans]) 1);
   548 by (fast_tac (claset() addDs [not_leE] addIs [less_trans]) 1);
   549 val less_maxR = result();
   549 val less_maxR = result();
   550 
   550 
   551 Goalw [new_tv_def] "!!t::typ. ? n. (new_tv n t)";
   551 Goalw [new_tv_def] "!!t::typ. ? n. (new_tv n t)";
   552 by (typ.induct_tac "t" 1);
   552 by (induct_tac "t" 1);
   553 by (res_inst_tac [("x","Suc nat")] exI 1);
   553 by (res_inst_tac [("x","Suc nat")] exI 1);
   554 by (Asm_simp_tac 1);
   554 by (Asm_simp_tac 1);
   555 by (REPEAT (etac exE 1));
   555 by (REPEAT (etac exE 1));
   556 by (rename_tac "n'" 1);
   556 by (rename_tac "n'" 1);
   557 by (res_inst_tac [("x","max n n'")] exI 1);
   557 by (res_inst_tac [("x","max n n'")] exI 1);
   560 qed "fresh_variable_types";
   560 qed "fresh_variable_types";
   561 
   561 
   562 Addsimps [fresh_variable_types];
   562 Addsimps [fresh_variable_types];
   563 
   563 
   564 Goalw [new_tv_def] "!!sch::type_scheme. ? n. (new_tv n sch)";
   564 Goalw [new_tv_def] "!!sch::type_scheme. ? n. (new_tv n sch)";
   565 by (type_scheme.induct_tac "sch" 1);
   565 by (induct_tac "sch" 1);
   566 by (res_inst_tac [("x","Suc nat")] exI 1);
   566 by (res_inst_tac [("x","Suc nat")] exI 1);
   567 by (Simp_tac 1);
   567 by (Simp_tac 1);
   568 by (res_inst_tac [("x","Suc nat")] exI 1);
   568 by (res_inst_tac [("x","Suc nat")] exI 1);
   569 by (Simp_tac 1);
   569 by (Simp_tac 1);
   570 by (REPEAT (etac exE 1));
   570 by (REPEAT (etac exE 1));
   584 by (Simp_tac 1);
   584 by (Simp_tac 1);
   585 by (fast_tac (claset() addDs [not_leE] addIs [less_or_eq_imp_le]) 1);
   585 by (fast_tac (claset() addDs [not_leE] addIs [less_or_eq_imp_le]) 1);
   586 val le_maxR = result();
   586 val le_maxR = result();
   587 
   587 
   588 Goal "!!A::type_scheme list. ? n. (new_tv n A)";
   588 Goal "!!A::type_scheme list. ? n. (new_tv n A)";
   589 by (list.induct_tac "A" 1);
   589 by (induct_tac "A" 1);
   590 by (Simp_tac 1);
   590 by (Simp_tac 1);
   591 by (Simp_tac 1);
   591 by (Simp_tac 1);
   592 by (etac exE 1);
   592 by (etac exE 1);
   593 by (cut_inst_tac [("sch","a")] fresh_variable_type_schemes 1);
   593 by (cut_inst_tac [("sch","a")] fresh_variable_type_schemes 1);
   594 by (etac exE 1);
   594 by (etac exE 1);
   646 by (Simp_tac 1);
   646 by (Simp_tac 1);
   647 qed "length_app_subst_list";
   647 qed "length_app_subst_list";
   648 Addsimps [length_app_subst_list];
   648 Addsimps [length_app_subst_list];
   649 
   649 
   650 Goal "!!sch::type_scheme. $ TVar sch = sch";
   650 Goal "!!sch::type_scheme. $ TVar sch = sch";
   651 by (type_scheme.induct_tac "sch" 1);
   651 by (induct_tac "sch" 1);
   652 by (ALLGOALS Asm_simp_tac);
   652 by (ALLGOALS Asm_simp_tac);
   653 qed "subst_TVar_scheme";
   653 qed "subst_TVar_scheme";
   654 
   654 
   655 Addsimps [subst_TVar_scheme];
   655 Addsimps [subst_TVar_scheme];
   656 
   656 
   663 
   663 
   664 (* application of id_subst does not change type expression *)
   664 (* application of id_subst does not change type expression *)
   665 Goalw [id_subst_def]
   665 Goalw [id_subst_def]
   666   "$ id_subst = (%t::typ. t)";
   666   "$ id_subst = (%t::typ. t)";
   667 by (rtac ext 1);
   667 by (rtac ext 1);
   668 by (typ.induct_tac "t" 1);
   668 by (induct_tac "t" 1);
   669 by (ALLGOALS Asm_simp_tac);
   669 by (ALLGOALS Asm_simp_tac);
   670 qed "app_subst_id_te";
   670 qed "app_subst_id_te";
   671 Addsimps [app_subst_id_te];
   671 Addsimps [app_subst_id_te];
   672 
   672 
   673 Goalw [id_subst_def]
   673 Goalw [id_subst_def]
   674   "$ id_subst = (%sch::type_scheme. sch)";
   674   "$ id_subst = (%sch::type_scheme. sch)";
   675 by (rtac ext 1);
   675 by (rtac ext 1);
   676 by (type_scheme.induct_tac "t" 1);
   676 by (induct_tac "sch" 1);
   677 by (ALLGOALS Asm_simp_tac);
   677 by (ALLGOALS Asm_simp_tac);
   678 qed "app_subst_id_type_scheme";
   678 qed "app_subst_id_type_scheme";
   679 Addsimps [app_subst_id_type_scheme];
   679 Addsimps [app_subst_id_type_scheme];
   680 
   680 
   681 (* application of id_subst does not change list of type expressions *)
   681 (* application of id_subst does not change list of type expressions *)
   682 Goalw [app_subst_list]
   682 Goalw [app_subst_list]
   683   "$ id_subst = (%A::type_scheme list. A)";
   683   "$ id_subst = (%A::type_scheme list. A)";
   684 by (rtac ext 1); 
   684 by (rtac ext 1); 
   685 by (list.induct_tac "A" 1);
   685 by (induct_tac "A" 1);
   686 by (ALLGOALS Asm_simp_tac);
   686 by (ALLGOALS Asm_simp_tac);
   687 qed "app_subst_id_tel";
   687 qed "app_subst_id_tel";
   688 Addsimps [app_subst_id_tel];
   688 Addsimps [app_subst_id_tel];
   689 
   689 
   690 Goal "!!sch::type_scheme. $ id_subst sch = sch";
   690 Goal "!!sch::type_scheme. $ id_subst sch = sch";
   691 by (type_scheme.induct_tac "sch" 1);
   691 by (induct_tac "sch" 1);
   692 by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [id_subst_def])));
   692 by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [id_subst_def])));
   693 qed "id_subst_sch";
   693 qed "id_subst_sch";
   694 
   694 
   695 Addsimps [id_subst_sch];
   695 Addsimps [id_subst_sch];
   696 
   696 
   697 Goal "!!A::type_scheme list. $ id_subst A = A";
   697 Goal "!!A::type_scheme list. $ id_subst A = A";
   698 by (list.induct_tac "A" 1);
   698 by (induct_tac "A" 1);
   699 by (Asm_full_simp_tac 1);
   699 by (Asm_full_simp_tac 1);
   700 by (Asm_full_simp_tac 1);
   700 by (Asm_full_simp_tac 1);
   701 qed "id_subst_A";
   701 qed "id_subst_A";
   702 
   702 
   703 Addsimps [id_subst_A];
   703 Addsimps [id_subst_A];
   708 by (Simp_tac 1);
   708 by (Simp_tac 1);
   709 qed "o_id_subst";
   709 qed "o_id_subst";
   710 Addsimps[o_id_subst];
   710 Addsimps[o_id_subst];
   711 
   711 
   712 Goal "$ R ($ S t::typ) = $ (%x. $ R (S x) ) t";
   712 Goal "$ R ($ S t::typ) = $ (%x. $ R (S x) ) t";
   713 by (typ.induct_tac "t" 1);
   713 by (induct_tac "t" 1);
   714 by (ALLGOALS Asm_simp_tac);
   714 by (ALLGOALS Asm_simp_tac);
   715 qed "subst_comp_te";
   715 qed "subst_comp_te";
   716 
   716 
   717 Goal "$ R ($ S sch::type_scheme) = $ (%x. $ R (S x) ) sch";
   717 Goal "$ R ($ S sch::type_scheme) = $ (%x. $ R (S x) ) sch";
   718 by (type_scheme.induct_tac "sch" 1);
   718 by (induct_tac "sch" 1);
   719 by (ALLGOALS Asm_full_simp_tac);
   719 by (ALLGOALS Asm_full_simp_tac);
   720 qed "subst_comp_type_scheme";
   720 qed "subst_comp_type_scheme";
   721 
   721 
   722 Goalw [app_subst_list]
   722 Goalw [app_subst_list]
   723   "$ R ($ S A::type_scheme list) = $ (%x. $ R (S x)) A";
   723   "$ R ($ S A::type_scheme list) = $ (%x. $ R (S x)) A";
   724 by (list.induct_tac "A" 1);
   724 by (induct_tac "A" 1);
   725 (* case [] *)
   725 (* case [] *)
   726 by (Simp_tac 1);
   726 by (Simp_tac 1);
   727 (* case x#xl *)
   727 (* case x#xl *)
   728 by (asm_full_simp_tac (simpset() addsimps [subst_comp_type_scheme]) 1);
   728 by (asm_full_simp_tac (simpset() addsimps [subst_comp_type_scheme]) 1);
   729 qed "subst_comp_scheme_list";
   729 qed "subst_comp_scheme_list";
   738 by (assume_tac 1);
   738 by (assume_tac 1);
   739 by (Simp_tac 1);
   739 by (Simp_tac 1);
   740 qed "subst_id_on_type_scheme_list";
   740 qed "subst_id_on_type_scheme_list";
   741 
   741 
   742 Goal "!n. n < length A --> ($ S A)!n = $S (A!n)";
   742 Goal "!n. n < length A --> ($ S A)!n = $S (A!n)";
   743 by (list.induct_tac "A" 1);
   743 by (induct_tac "A" 1);
   744 by (Asm_full_simp_tac 1);
   744 by (Asm_full_simp_tac 1);
   745 by (rtac allI 1);
   745 by (rtac allI 1);
   746 by (rename_tac "n1" 1);
   746 by (rename_tac "n1" 1);
   747 by (res_inst_tac[("n","n1")] nat_induct 1);
   747 by (res_inst_tac[("n","n1")] nat_induct 1);
   748 by (Asm_full_simp_tac 1);
   748 by (Asm_full_simp_tac 1);