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