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