src/HOL/MiniML/Instance.ML
author nipkow
Fri Nov 27 17:00:30 1998 +0100 (1998-11-27)
changeset 5983 79e301a6a51b
parent 5521 7970832271cc
child 7499 23e090051cb8
permissions -rw-r--r--
At last: linear arithmetic for nat!
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
wenzelm@5069
    12
Goal "bound_typ_inst S (mk_scheme t) = t";
berghofe@5184
    13
by (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@5118
    19
Goal "bound_typ_inst ($S o R) ($S sch) = $S (bound_typ_inst R sch)";
berghofe@5184
    20
by (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@5118
    26
Goal "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@5118
    34
Goal "bound_scheme_inst B (mk_scheme t) = mk_scheme t";
berghofe@5184
    35
by (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@5118
    42
Goal "$S (bound_scheme_inst B sch) = (bound_scheme_inst ($S o B) ($ S sch))";
berghofe@5184
    43
by (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
wenzelm@5069
    49
Goal "!t. mk_scheme t = bound_scheme_inst B sch --> \
nipkow@2525
    50
\         (? S. !x:bound_tv sch. B x = mk_scheme (S x))";
berghofe@5184
    51
by (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);
oheimb@5521
    68
by (Auto_tac);
nipkow@2525
    69
qed_spec_mp "bound_scheme_inst_type";
nipkow@2525
    70
nipkow@2525
    71
nipkow@5118
    72
(* lemmas for subst_to_scheme *)
nipkow@2525
    73
nipkow@5118
    74
Goal "new_tv n sch --> subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) \
nipkow@2525
    75
\                                                 (bound_typ_inst (%k. TVar (k + n)) sch) = sch";
berghofe@5184
    76
by (induct_tac "sch" 1);
paulson@5350
    77
by (simp_tac (simpset() addsimps [le_def]) 1);
nipkow@4686
    78
by (simp_tac (simpset() addsimps [le_add2,diff_add_inverse2]) 1);
nipkow@2525
    79
by (Asm_simp_tac 1);
nipkow@2525
    80
qed_spec_mp "subst_to_scheme_inverse";
nipkow@2525
    81
nipkow@5118
    82
Goal "t = t' ==> \
nipkow@5118
    83
\     subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) t = \
nipkow@5118
    84
\     subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) t'";
nipkow@2525
    85
by (Fast_tac 1);
nipkow@2525
    86
val aux = result ();
nipkow@2525
    87
wenzelm@5069
    88
Goal "new_tv n sch --> \
nipkow@5118
    89
\     subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k) (bound_typ_inst S sch) = \
nipkow@5118
    90
\      bound_scheme_inst ((subst_to_scheme (%k. if n <= k then BVar (k - n) else FVar k)) o S) sch";
berghofe@5184
    91
by (induct_tac "sch" 1);
paulson@5350
    92
by Auto_tac;
nipkow@2525
    93
val aux2 = result () RS mp;
nipkow@2525
    94
nipkow@2525
    95
nipkow@2525
    96
(* lemmata for <= *)
nipkow@2525
    97
wenzelm@5069
    98
Goalw [le_type_scheme_def,is_bound_typ_instance]
nipkow@5118
    99
  "!!(sch::type_scheme) sch'. \
nipkow@5118
   100
\  (sch' <= sch) = (? B. sch' = bound_scheme_inst B sch)";
nipkow@2525
   101
by (rtac iffI 1);
nipkow@2525
   102
by (cut_inst_tac [("sch","sch")] fresh_variable_type_schemes 1); 
nipkow@2525
   103
by (cut_inst_tac [("sch","sch'")] fresh_variable_type_schemes 1);
nipkow@2525
   104
by (dtac make_one_new_out_of_two 1);
paulson@3018
   105
by (assume_tac 1);
nipkow@2525
   106
by (thin_tac "? n. new_tv n sch'" 1); 
nipkow@2525
   107
by (etac exE 1);
nipkow@2525
   108
by (etac allE 1);
nipkow@2525
   109
by (dtac mp 1);
nipkow@2525
   110
by (res_inst_tac [("x","(%k. TVar (k + n))")] exI 1);
nipkow@2525
   111
by (rtac refl 1);
nipkow@2525
   112
by (etac exE 1);
nipkow@2525
   113
by (REPEAT (etac conjE 1));
nipkow@2525
   114
by (dres_inst_tac [("n","n")] aux 1);
wenzelm@4089
   115
by (asm_full_simp_tac (simpset() addsimps [subst_to_scheme_inverse]) 1);
nipkow@2525
   116
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
   117
by (asm_simp_tac (simpset() addsimps [aux2]) 1);
paulson@4153
   118
by Safe_tac;
nipkow@2525
   119
by (res_inst_tac [("x","%n. bound_typ_inst S (B n)")] exI 1);
berghofe@5184
   120
by (induct_tac "sch" 1);
nipkow@2525
   121
by (Simp_tac 1);
nipkow@2525
   122
by (Simp_tac 1);
nipkow@2525
   123
by (Asm_simp_tac 1);
nipkow@2525
   124
qed "le_type_scheme_def2";
nipkow@2525
   125
wenzelm@5069
   126
Goalw [is_bound_typ_instance] "(mk_scheme t) <= sch = t <| sch";
wenzelm@4089
   127
by (simp_tac (simpset() addsimps [le_type_scheme_def2]) 1); 
nipkow@2525
   128
by (rtac iffI 1); 
nipkow@2525
   129
by (etac exE 1); 
nipkow@2525
   130
by (forward_tac [bound_scheme_inst_type] 1);
nipkow@2525
   131
by (etac exE 1);
nipkow@2525
   132
by (rtac exI 1);
nipkow@2525
   133
by (rtac mk_scheme_injective 1); 
nipkow@2525
   134
by (Asm_full_simp_tac 1);
nipkow@2525
   135
by (rotate_tac 1 1);
nipkow@2525
   136
by (rtac mp 1);
paulson@3018
   137
by (assume_tac 2);
berghofe@5184
   138
by (induct_tac "sch" 1);
nipkow@2525
   139
by (Simp_tac 1);
nipkow@2525
   140
by (Asm_full_simp_tac 1);
nipkow@2525
   141
by (Fast_tac 1);
nipkow@2525
   142
by (strip_tac 1);
nipkow@2525
   143
by (Asm_full_simp_tac 1);
nipkow@2525
   144
by (etac exE 1);
nipkow@2525
   145
by (Asm_full_simp_tac 1);
nipkow@2525
   146
by (rtac exI 1);
berghofe@5184
   147
by (induct_tac "sch" 1);
nipkow@2525
   148
by (Simp_tac 1);
nipkow@2525
   149
by (Simp_tac 1);
nipkow@2525
   150
by (Asm_full_simp_tac 1);
nipkow@2525
   151
qed_spec_mp "le_type_eq_is_bound_typ_instance";
nipkow@2525
   152
wenzelm@5069
   153
Goalw [le_env_def]
nipkow@2525
   154
  "(sch # A <= sch' # B) = (sch <= (sch'::type_scheme) & A <= B)";
paulson@3018
   155
by (Simp_tac 1);
paulson@3018
   156
by (rtac iffI 1);
paulson@4153
   157
 by (SELECT_GOAL Safe_tac 1);
paulson@3018
   158
  by (eres_inst_tac [("x","0")] allE 1);
paulson@3018
   159
  by (Asm_full_simp_tac 1);
paulson@3018
   160
 by (eres_inst_tac [("x","Suc i")] allE 1);
paulson@3018
   161
 by (Asm_full_simp_tac 1);
paulson@3018
   162
by (rtac conjI 1);
paulson@3018
   163
 by (Fast_tac 1);
paulson@3018
   164
by (rtac allI 1);
berghofe@5184
   165
by (induct_tac "i" 1);
paulson@3018
   166
by (ALLGOALS Asm_simp_tac);
nipkow@2525
   167
qed "le_env_Cons";
nipkow@2525
   168
AddIffs [le_env_Cons];
nipkow@2525
   169
nipkow@5118
   170
Goalw [is_bound_typ_instance]"t <| sch ==> $S t <| $S sch";
nipkow@2525
   171
by (etac exE 1);
nipkow@2525
   172
by (rename_tac "SA" 1);
nipkow@2525
   173
by (hyp_subst_tac 1);
nipkow@2525
   174
by (res_inst_tac [("x","$S o SA")] exI 1);
nipkow@2525
   175
by (Simp_tac 1);
nipkow@2525
   176
qed "is_bound_typ_instance_closed_subst";
nipkow@2525
   177
wenzelm@5069
   178
Goal "!!(sch::type_scheme) sch'. sch' <= sch ==> $S sch' <= $ S sch";
wenzelm@4089
   179
by (asm_full_simp_tac (simpset() addsimps [le_type_scheme_def2]) 1);
nipkow@2525
   180
by (etac exE 1);
wenzelm@4089
   181
by (asm_full_simp_tac (simpset() addsimps [substitution_lemma]) 1);
nipkow@2525
   182
by (Fast_tac 1);
nipkow@2525
   183
qed "S_compatible_le_scheme";
nipkow@2525
   184
nipkow@5118
   185
Goalw [le_env_def,app_subst_list]
nipkow@5118
   186
 "!!(A::type_scheme list) A'. A' <= A ==> $S A' <= $ S A";
wenzelm@4089
   187
by (simp_tac (simpset() addcongs [conj_cong]) 1);
wenzelm@4089
   188
by (fast_tac (claset() addSIs [S_compatible_le_scheme]) 1);
nipkow@2525
   189
qed "S_compatible_le_scheme_lists";
nipkow@2525
   190
nipkow@5118
   191
Goalw [le_type_scheme_def] "[| t <| sch; sch <= sch' |] ==> t <| sch'";
paulson@3018
   192
by (Fast_tac 1);
nipkow@2525
   193
qed "bound_typ_instance_trans";
nipkow@2525
   194
wenzelm@5069
   195
Goalw [le_type_scheme_def] "sch <= (sch::type_scheme)";
paulson@3018
   196
by (Fast_tac 1);
nipkow@2525
   197
qed "le_type_scheme_refl";
nipkow@2525
   198
AddIffs [le_type_scheme_refl];
nipkow@2525
   199
wenzelm@5069
   200
Goalw [le_env_def] "A <= (A::type_scheme list)";
paulson@3018
   201
by (Fast_tac 1);
nipkow@2525
   202
qed "le_env_refl";
nipkow@2525
   203
AddIffs [le_env_refl];
nipkow@2525
   204
wenzelm@5069
   205
Goalw [le_type_scheme_def,is_bound_typ_instance] "sch <= BVar n";
paulson@3018
   206
by (strip_tac 1);
wenzelm@3842
   207
by (res_inst_tac [("x","%a. t")]exI 1);
paulson@3018
   208
by (Simp_tac 1);
nipkow@2525
   209
qed "bound_typ_instance_BVar";
nipkow@2525
   210
AddIffs [bound_typ_instance_BVar];
nipkow@2525
   211
nipkow@5118
   212
Goalw [le_type_scheme_def,is_bound_typ_instance]
nipkow@5118
   213
 "(sch <= FVar n) = (sch = FVar n)";
berghofe@5184
   214
by (induct_tac "sch" 1);
paulson@3018
   215
  by (Simp_tac 1);
paulson@3018
   216
 by (Simp_tac 1);
paulson@3018
   217
 by (Fast_tac 1);
paulson@3018
   218
by (Asm_full_simp_tac 1);
paulson@3018
   219
by (Fast_tac 1);
nipkow@2525
   220
qed "le_FVar";
nipkow@2525
   221
Addsimps [le_FVar];
nipkow@2525
   222
wenzelm@5069
   223
Goalw [le_type_scheme_def,is_bound_typ_instance] "~(FVar n <= sch1 =-> sch2)";
paulson@3018
   224
by (Simp_tac 1);
nipkow@2525
   225
qed "not_FVar_le_Fun";
nipkow@2525
   226
AddIffs [not_FVar_le_Fun];
nipkow@2525
   227
wenzelm@5069
   228
Goalw [le_type_scheme_def,is_bound_typ_instance] "~(BVar n <= sch1 =-> sch2)";
paulson@3018
   229
by (Simp_tac 1);
paulson@3018
   230
by (res_inst_tac [("x","TVar n")] exI 1);
paulson@3018
   231
by (Simp_tac 1);
paulson@3018
   232
by (Fast_tac 1);
nipkow@2525
   233
qed "not_BVar_le_Fun";
nipkow@2525
   234
AddIffs [not_BVar_le_Fun];
nipkow@2525
   235
wenzelm@5069
   236
Goalw [le_type_scheme_def,is_bound_typ_instance]
nipkow@5118
   237
  "(sch1 =-> sch2 <= sch1' =-> sch2') ==> sch1 <= sch1' & sch2 <= sch2'";
wenzelm@4089
   238
by (fast_tac (claset() addss simpset()) 1);
nipkow@2525
   239
qed "Fun_le_FunD";
nipkow@2525
   240
wenzelm@5069
   241
Goal "(sch' <= sch1 =-> sch2) --> (? sch'1 sch'2. sch' = sch'1 =-> sch'2)";
berghofe@5184
   242
by (induct_tac "sch'" 1);
nipkow@2525
   243
by (Asm_simp_tac 1);
nipkow@2525
   244
by (Asm_simp_tac 1);
nipkow@2525
   245
by (Fast_tac 1);
nipkow@2525
   246
qed_spec_mp "scheme_le_Fun";
nipkow@2525
   247
wenzelm@5069
   248
Goal "!sch'::type_scheme. sch <= sch' --> free_tv sch' <= free_tv sch";
berghofe@5184
   249
by (induct_tac "sch" 1);
paulson@3018
   250
  by (rtac allI 1);
berghofe@5184
   251
  by (induct_tac "sch'" 1);
paulson@3018
   252
    by (Simp_tac 1);
paulson@3018
   253
   by (Simp_tac 1);
paulson@3018
   254
  by (Simp_tac 1);
paulson@3018
   255
 by (rtac allI 1);
berghofe@5184
   256
 by (induct_tac "sch'" 1);
paulson@3018
   257
   by (Simp_tac 1);
paulson@3018
   258
  by (Simp_tac 1);
paulson@3018
   259
 by (Simp_tac 1);
paulson@3018
   260
by (rtac allI 1);
berghofe@5184
   261
by (induct_tac "sch'" 1);
paulson@3018
   262
  by (Simp_tac 1);
paulson@3018
   263
 by (Simp_tac 1);
paulson@3018
   264
by (Asm_full_simp_tac 1);
paulson@3018
   265
by (strip_tac 1);
paulson@3018
   266
by (dtac Fun_le_FunD 1);
paulson@3018
   267
by (Fast_tac 1);
nipkow@2525
   268
qed_spec_mp "le_type_scheme_free_tv";
nipkow@2525
   269
wenzelm@5069
   270
Goal "!A::type_scheme list. A <= B --> free_tv B <= free_tv A";
berghofe@5184
   271
by (induct_tac "B" 1);
paulson@3018
   272
 by (Simp_tac 1);
paulson@3018
   273
by (rtac allI 1);
berghofe@5184
   274
by (induct_tac "A" 1);
wenzelm@4089
   275
 by (simp_tac (simpset() addsimps [le_env_def]) 1);
paulson@3018
   276
by (Simp_tac 1);
wenzelm@4089
   277
by (fast_tac (claset() addDs [le_type_scheme_free_tv]) 1);
nipkow@2525
   278
qed_spec_mp "le_env_free_tv";