src/HOL/MiniML/W.ML
author nipkow
Mon, 03 Nov 1997 09:58:06 +0100
changeset 4072 d0d32dd77440
parent 4033 43ec35b5054d
child 4089 96fba19bcbe2
permissions -rw-r--r--
expand_option_bind -> split_option_bind
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     1
(* Title:     HOL/MiniML/W.ML
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     2
   ID:        $Id$
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     3
   Author:    Dieter Nazareth and Tobias Nipkow
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     4
   Copyright  1995 TU Muenchen
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     5
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     6
Correctness and completeness of type inference algorithm W
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     7
*)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     8
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     9
open W;
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    10
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    11
Addsimps [diff_add_inverse,diff_add_inverse2,Suc_le_lessD];
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    12
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    13
val has_type_casesE = map(has_type.mk_cases expr.simps)
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    14
        [" A |- Var n :: t"," A |- Abs e :: t","A |- App e1 e2 ::t","A |- LET e1 e2 ::t" ];
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    15
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    16
(* the resulting type variable is always greater or equal than the given one *)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    17
goal thy
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    18
        "!A n S t m. W e A n  = Some (S,t,m) --> n<=m";
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    19
by (expr.induct_tac "e" 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    20
(* case Var(n) *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
    21
by (simp_tac (!simpset addsplits [split_option_bind,expand_if]) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    22
(* case Abs e *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
    23
by (simp_tac (!simpset addsplits [split_option_bind]) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    24
by (fast_tac (HOL_cs addDs [Suc_leD]) 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    25
(* case App e1 e2 *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
    26
by (simp_tac (!simpset addsplits [split_option_bind]) 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
    27
by(blast_tac (!claset addIs [le_SucI,le_trans]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    28
(* case LET e1 e2 *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
    29
by (simp_tac (!simpset addsplits [split_option_bind]) 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
    30
by(blast_tac (!claset addIs [le_trans]) 1);
1486
7b95d7b49f7a Introduced qed_spec_mp.
nipkow
parents: 1465
diff changeset
    31
qed_spec_mp "W_var_ge";
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    32
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    33
Addsimps [W_var_ge];
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    34
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    35
goal thy
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    36
        "!! s. Some (S,t,m) = W e A n ==> n<=m";
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    37
by (asm_full_simp_tac (!simpset addsimps [eq_sym_conv]) 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    38
qed "W_var_geD";
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    39
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    40
goal thy "!! s. new_tv n A ==> Some (S,t,m) = W e A n ==> new_tv m A";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    41
by (dtac W_var_geD 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    42
by (rtac new_scheme_list_le 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
    43
by (assume_tac 1);
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
    44
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    45
qed "new_tv_compatible_W";
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    46
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    47
goal thy "!!sch. new_tv n sch --> new_tv (n + (min_new_bound_tv sch)) (bound_typ_inst (%b. TVar (b + n)) sch)";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    48
by (type_scheme.induct_tac "sch" 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    49
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    50
by (asm_full_simp_tac (!simpset addsimps [add_commute]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    51
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    52
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    53
by (etac conjE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    54
by (rtac conjI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    55
by (rtac new_tv_le 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    56
by (mp_tac 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    57
by (mp_tac 2);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
    58
by (assume_tac 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    59
by (rtac add_le_mono 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    60
by (Simp_tac 1);
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
    61
by (simp_tac (!simpset addsplits [expand_if] addsimps [max_def]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    62
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    63
by (rtac new_tv_le 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    64
by (mp_tac 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    65
by (mp_tac 2);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
    66
by (assume_tac 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    67
by (rtac add_le_mono 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    68
by (Simp_tac 1);
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
    69
by (simp_tac (!simpset addsplits [expand_if] addsimps [max_def]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    70
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    71
by (dtac not_leE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    72
by (rtac less_or_eq_imp_le 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    73
by (Fast_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    74
qed_spec_mp "new_tv_bound_typ_inst_sch";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    75
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    76
Addsimps [new_tv_bound_typ_inst_sch];
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    77
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    78
(* resulting type variable is new *)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    79
goal thy
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    80
     "!n A S t m. new_tv n A --> W e A n = Some (S,t,m) -->    \
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    81
\                 new_tv m S & new_tv m t";
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    82
by (expr.induct_tac "e" 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    83
(* case Var n *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
    84
by (simp_tac (!simpset addsplits [split_option_bind,expand_if]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    85
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    86
by (dtac new_tv_nth_nat_A 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
    87
by (assume_tac 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
    88
by (Asm_simp_tac 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    89
(* case Abs e *)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    90
by (simp_tac (!simpset addsimps [new_tv_subst,new_tv_Suc_list] 
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
    91
    addsplits [split_option_bind]) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    92
by (strip_tac 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    93
by (eres_inst_tac [("x","Suc n")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
    94
by (eres_inst_tac [("x","(FVar n)#A")] allE 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    95
by (fast_tac (HOL_cs addss (!simpset
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
    96
              addsimps [new_tv_subst,new_tv_Suc_list])) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    97
(* case App e1 e2 *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
    98
by (simp_tac (!simpset addsplits [split_option_bind]) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    99
by (strip_tac 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   100
by (rename_tac "S1 t1 n1 S2 t2 n2 S3" 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   101
by (eres_inst_tac [("x","n")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   102
by (eres_inst_tac [("x","A")] allE 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   103
by (eres_inst_tac [("x","S1")] allE 1);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   104
by (eres_inst_tac [("x","t1")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   105
by (eres_inst_tac [("x","n1")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   106
by (eres_inst_tac [("x","n1")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   107
by (asm_full_simp_tac (!simpset addsimps [eq_sym_conv] delsimps all_simps) 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   108
by (eres_inst_tac [("x","$S1 A")] allE 1);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   109
by (eres_inst_tac [("x","S2")] allE 1);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   110
by (eres_inst_tac [("x","t2")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   111
by (eres_inst_tac [("x","n2")] allE 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   112
by ( asm_full_simp_tac (!simpset addsimps [o_def,rotate_Some]) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   113
by (rtac conjI 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   114
by (rtac new_tv_subst_comp_2 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   115
by (rtac new_tv_subst_comp_2 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   116
by (rtac (lessI RS less_imp_le RS new_tv_le) 1); 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   117
by (res_inst_tac [("n","n1")] new_tv_subst_le 1); 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   118
by (asm_full_simp_tac (!simpset addsimps [rotate_Some]) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   119
by (Asm_simp_tac 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   120
by (fast_tac (HOL_cs addDs [W_var_geD] addIs
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   121
     [new_scheme_list_le,new_tv_subst_scheme_list,lessI RS less_imp_le RS new_tv_subst_le])
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   122
    1);
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   123
by (etac (sym RS mgu_new) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   124
by (best_tac (HOL_cs addDs [W_var_geD] addIs [new_tv_subst_te,new_scheme_list_le,
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   125
   new_tv_subst_scheme_list,lessI RS less_imp_le RS new_tv_le,lessI RS less_imp_le RS 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   126
   new_tv_subst_le,new_tv_le]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   127
by (fast_tac (HOL_cs addDs [W_var_geD] addIs
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   128
     [new_scheme_list_le,new_tv_subst_scheme_list,new_tv_le] 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   129
        addss (!simpset)) 1);
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   130
by (rtac (lessI RS new_tv_subst_var) 1);
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   131
by (etac (sym RS mgu_new) 1);
1925
1150f128c7fe Some tidying. This brittle proof depends upon
paulson
parents: 1910
diff changeset
   132
by (best_tac (HOL_cs addSIs [lessI RS less_imp_le RS new_tv_le,new_tv_subst_te]
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   133
   addDs [W_var_geD] addIs
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   134
   [new_scheme_list_le,new_tv_subst_scheme_list,lessI RS less_imp_le RS
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   135
   new_tv_subst_le,new_tv_le] addss !simpset) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   136
by (fast_tac (HOL_cs addDs [W_var_geD] addIs
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   137
     [new_scheme_list_le,new_tv_subst_scheme_list,new_tv_le]
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   138
     addss (!simpset)) 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   139
(* 41: case LET e1 e2 *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   140
by (simp_tac (!simpset addsplits [split_option_bind]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   141
by (strip_tac 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   142
by(EVERY1[etac allE,etac allE,etac allE,etac allE,etac allE,mp_tac,mp_tac]);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   143
by (etac conjE 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   144
by(EVERY[etac allE 1,etac allE 1,etac allE 1,etac allE 1,etac allE 1,
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   145
         etac impE 1, mp_tac 2]);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   146
by (SELECT_GOAL(rewtac new_tv_def)1);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   147
by (Asm_simp_tac 1);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   148
by (REPEAT(dtac W_var_ge 1));
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   149
by (rtac allI 1);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   150
by (strip_tac 1);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   151
by (SELECT_GOAL(rewtac free_tv_subst) 1);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   152
by (dtac (free_tv_app_subst_scheme_list RS subsetD) 1);
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   153
by (best_tac (!claset addEs [less_le_trans]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   154
by (etac conjE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   155
by (rtac conjI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   156
by (rtac new_tv_subst_comp_2 1);
4033
43ec35b5054d Updated proofs
nipkow
parents: 3919
diff changeset
   157
by (etac (W_var_ge RS new_tv_subst_le) 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   158
by (assume_tac 1);
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   159
by (assume_tac 1);
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   160
by (assume_tac 1);
1486
7b95d7b49f7a Introduced qed_spec_mp.
nipkow
parents: 1465
diff changeset
   161
qed_spec_mp "new_tv_W";
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   162
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   163
goal thy "!!sch. (v ~: free_tv sch) --> (v : free_tv (bound_typ_inst (TVar o S) sch)) --> (? x. v = S x)";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   164
by (type_scheme.induct_tac "sch" 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   165
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   166
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   167
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   168
by (rtac exI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   169
by (rtac refl 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   170
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   171
qed_spec_mp "free_tv_bound_typ_inst1";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   172
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   173
Addsimps [free_tv_bound_typ_inst1];
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   174
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   175
goal thy
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   176
     "!n A S t m v. W e A n = Some (S,t,m) -->            \
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   177
\         (v:free_tv S | v:free_tv t) --> v<n --> v:free_tv A";
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   178
by (expr.induct_tac "e" 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   179
(* case Var n *)
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   180
by (simp_tac (!simpset addsimps
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   181
    [free_tv_subst] addsplits [split_option_bind,expand_if]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   182
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   183
by (case_tac "v : free_tv (nth nat A)" 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   184
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   185
by (dtac free_tv_bound_typ_inst1 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   186
by (simp_tac (!simpset addsimps [o_def]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   187
by (etac exE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   188
by (rotate_tac 3 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   189
by (Asm_full_simp_tac 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   190
(* case Abs e *)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   191
by (asm_full_simp_tac (!simpset addsimps
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   192
    [free_tv_subst] addsplits [split_option_bind] delsimps all_simps) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   193
by (strip_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   194
by (rename_tac "S t n1 S1 t1 m v" 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   195
by (eres_inst_tac [("x","Suc n")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   196
by (eres_inst_tac [("x","FVar n # A")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   197
by (eres_inst_tac [("x","S")] allE 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   198
by (eres_inst_tac [("x","t")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   199
by (eres_inst_tac [("x","n1")] allE 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   200
by (eres_inst_tac [("x","v")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   201
by (best_tac (HOL_cs addIs [cod_app_subst]
1669
e56cdf711729 inserted Suc_less_eq explictly in a few proofs.
nipkow
parents: 1525
diff changeset
   202
                     addss (!simpset addsimps [less_Suc_eq])) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   203
(* case App e1 e2 *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   204
by (simp_tac (!simpset addsplits [split_option_bind] delsimps all_simps) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   205
by (strip_tac 1); 
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   206
by (rename_tac "S t n1 S1 t1 n2 S2 S3 t2 m v" 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   207
by (eres_inst_tac [("x","n")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   208
by (eres_inst_tac [("x","A")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   209
by (eres_inst_tac [("x","S")] allE 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   210
by (eres_inst_tac [("x","t")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   211
by (eres_inst_tac [("x","n1")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   212
by (eres_inst_tac [("x","n1")] allE 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   213
by (eres_inst_tac [("x","v")] allE 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   214
(* second case *)
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   215
by (eres_inst_tac [("x","$ S A")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   216
by (eres_inst_tac [("x","S1")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   217
by (eres_inst_tac [("x","t1")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   218
by (eres_inst_tac [("x","n2")] allE 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   219
by (eres_inst_tac [("x","v")] allE 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   220
by (safe_tac (empty_cs addSIs [conjI,impI] addSEs [conjE]) ); 
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   221
by (asm_full_simp_tac (!simpset addsimps [rotate_Some,o_def]) 1);
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   222
by (dtac W_var_geD 1);
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   223
by (dtac W_var_geD 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   224
by ( (forward_tac [less_le_trans] 1) THEN (assume_tac 1) );
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   225
by (fast_tac (HOL_cs addDs [free_tv_comp_subst RS subsetD,sym RS mgu_free, 
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   226
    codD,free_tv_app_subst_te RS subsetD,free_tv_app_subst_scheme_list RS subsetD,
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   227
    less_le_trans,less_not_refl2,subsetD]
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   228
  addEs [UnE] 
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   229
  addss !simpset) 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   230
by (Asm_full_simp_tac 1); 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   231
by (dtac (sym RS W_var_geD) 1);
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   232
by (dtac (sym RS W_var_geD) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   233
by ( (forward_tac [less_le_trans] 1) THEN (assume_tac 1) );
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   234
by (fast_tac (HOL_cs addDs [mgu_free, codD,free_tv_subst_var RS subsetD,
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   235
    free_tv_app_subst_te RS subsetD,free_tv_app_subst_scheme_list RS subsetD,
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   236
    less_le_trans,subsetD]
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   237
  addEs [UnE]
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   238
  addss !simpset) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   239
(* LET e1 e2 *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   240
by (simp_tac (!simpset addsplits [split_option_bind] delsimps all_simps) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   241
by (strip_tac 1); 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   242
by (rename_tac "nat A S1 t1 n2 S2 t2 m2 S t m v" 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   243
by (eres_inst_tac [("x","nat")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   244
by (eres_inst_tac [("x","A")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   245
by (eres_inst_tac [("x","S1")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   246
by (eres_inst_tac [("x","t1")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   247
by (rotate_tac 1 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   248
by (eres_inst_tac [("x","n2")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   249
by (rotate_tac 4 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   250
by (eres_inst_tac [("x","v")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   251
by (mp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   252
by (EVERY1 [etac allE,etac allE,etac allE,etac allE,etac allE,eres_inst_tac [("x","v")] allE]);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   253
by (mp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   254
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   255
by (rtac conjI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   256
by (fast_tac (!claset addSDs [codD,free_tv_app_subst_scheme_list RS subsetD,free_tv_o_subst RS subsetD,W_var_ge] 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   257
              addDs [less_le_trans]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   258
by (fast_tac (!claset addSDs [codD,free_tv_app_subst_scheme_list RS subsetD,W_var_ge] 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   259
              addDs [less_le_trans]) 1);
1486
7b95d7b49f7a Introduced qed_spec_mp.
nipkow
parents: 1465
diff changeset
   260
qed_spec_mp "free_tv_W"; 
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   261
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   262
goal thy "!!A. (!x. x : A --> x ~: B) ==> A Int B = {}";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   263
by (Fast_tac 1);
2625
69c1b8a493de Some lemmas changed to valuesd
narasche
parents: 2525
diff changeset
   264
val weaken_A_Int_B_eq_empty = result();
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   265
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   266
goal thy "!!A. x ~: A | x : B ==> x ~: A - B";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   267
by (Fast_tac 1);
2625
69c1b8a493de Some lemmas changed to valuesd
narasche
parents: 2525
diff changeset
   268
val weaken_not_elem_A_minus_B = result();
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   269
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   270
(* correctness of W with respect to has_type *)
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   271
goal W.thy
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   272
        "!A S t m n . new_tv n A --> Some (S,t,m) = W e A n --> $S A |- e :: t";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   273
by (expr.induct_tac "e" 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   274
(* case Var n *)
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
   275
by (asm_full_simp_tac (!simpset addsplits [expand_if]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   276
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   277
by (rtac has_type.VarI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   278
by (Simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   279
by (simp_tac (!simpset addsimps [is_bound_typ_instance]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   280
by (rtac exI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   281
by (rtac refl 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   282
(* case Abs e *)
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   283
by (asm_full_simp_tac (!simpset addsimps [app_subst_list]
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   284
                        addsplits [split_option_bind]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   285
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   286
by (eres_inst_tac [("x","(mk_scheme (TVar n)) # A")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   287
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   288
by (rtac has_type.AbsI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   289
by (dtac (le_refl RS le_SucI RS new_scheme_list_le) 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   290
by (dtac sym 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   291
by (REPEAT (etac allE 1));
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   292
by (etac impE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   293
by (mp_tac 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   294
by (Asm_simp_tac 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   295
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   296
(* case App e1 e2 *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   297
by (simp_tac (!simpset addsplits [split_option_bind]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   298
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   299
by (rename_tac "S1 t1 n1 S2 t2 n2 S3" 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   300
by (res_inst_tac [("t2.0","$ S3 t2")] has_type.AppI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   301
by (res_inst_tac [("S1","S3")] (app_subst_TVar RS subst) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   302
by (rtac (app_subst_Fun RS subst) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   303
by (res_inst_tac [("t","$S3 (t2 -> (TVar n2))"),("s","$S3 ($S2 t1)")] subst 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   304
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   305
by (simp_tac (HOL_ss addsimps [subst_comp_scheme_list RS sym]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   306
by ((rtac (has_type_cl_sub RS spec) 1) THEN (rtac (has_type_cl_sub RS spec) 1));
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   307
by (asm_full_simp_tac (!simpset addsimps [eq_sym_conv]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   308
by (asm_full_simp_tac (!simpset addsimps [subst_comp_scheme_list RS sym,o_def,has_type_cl_sub,eq_sym_conv]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   309
by (rtac (has_type_cl_sub RS spec) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   310
by (forward_tac [new_tv_W] 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   311
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   312
by (dtac conjunct1 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   313
by (dtac conjunct1 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   314
by (forward_tac [new_tv_subst_scheme_list] 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   315
by (rtac new_scheme_list_le 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   316
by (rtac W_var_ge 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   317
by (assume_tac 1);
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   318
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   319
by (etac thin_rl 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   320
by (REPEAT (etac allE 1));
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   321
by (dtac sym 1);
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   322
by (dtac sym 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   323
by (etac thin_rl 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   324
by (etac thin_rl 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   325
by (mp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   326
by (mp_tac 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   327
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   328
(* case Let e1 e2 *)
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   329
by (simp_tac (!simpset addsplits [split_option_bind]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   330
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   331
by (rename_tac "w q m1 S1 t1 m2 S2 t n2" 1); 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   332
by (res_inst_tac [("t1.0","$ S2 t1")] has_type.LETI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   333
by (simp_tac (!simpset addsimps [o_def]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   334
by (simp_tac (HOL_ss addsimps [subst_comp_scheme_list RS sym]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   335
by (rtac (has_type_cl_sub RS spec) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   336
by (dres_inst_tac [("x","A")] spec 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   337
by (dres_inst_tac [("x","S1")] spec 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   338
by (dres_inst_tac [("x","t1")] spec 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   339
by (dres_inst_tac [("x","m2")] spec 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   340
by (rotate_tac 4 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   341
by (dres_inst_tac [("x","m1")] spec 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   342
by (mp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   343
by (asm_full_simp_tac (!simpset addsimps [eq_sym_conv]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   344
by (simp_tac (!simpset addsimps [o_def]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   345
by (simp_tac (HOL_ss addsimps [subst_comp_scheme_list RS sym]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   346
by (rtac (gen_subst_commutes RS sym RS subst) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   347
by (rtac (app_subst_Cons RS subst) 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   348
by (etac thin_rl 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   349
by (dres_inst_tac [("x","gen ($S1 A) t1 # $ S1 A")] spec 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   350
by (dres_inst_tac [("x","S2")] spec 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   351
by (dres_inst_tac [("x","t")] spec 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   352
by (dres_inst_tac [("x","n2")] spec 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   353
by (dres_inst_tac [("x","m2")] spec 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   354
by (forward_tac [new_tv_W] 2);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   355
by (assume_tac 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   356
by (dtac conjunct1 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   357
by (dtac conjunct1 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   358
by (forward_tac [new_tv_subst_scheme_list] 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   359
by (rtac new_scheme_list_le 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   360
by (rtac W_var_ge 2);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   361
by (assume_tac 2);
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   362
by (assume_tac 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   363
by (etac impE 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   364
by (res_inst_tac [("A","$ S1 A")] new_tv_only_depends_on_free_tv_scheme_list 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   365
by (Simp_tac 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   366
by (Fast_tac 2);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   367
by (assume_tac 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   368
by (Asm_full_simp_tac 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   369
by (rtac weaken_A_Int_B_eq_empty 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   370
by (rtac allI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   371
by (strip_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   372
by (rtac weaken_not_elem_A_minus_B 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   373
by (case_tac "x < m2" 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   374
by (rtac disjI2 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   375
by (rtac (free_tv_gen_cons RS subst) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   376
by (rtac free_tv_W 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   377
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   378
by (Asm_full_simp_tac 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   379
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   380
by (rtac disjI1 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   381
by (dtac new_tv_W 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   382
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   383
by (dtac conjunct2 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   384
by (dtac conjunct2 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   385
by (rtac new_tv_not_free_tv 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   386
by (rtac new_tv_le 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   387
by (assume_tac 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   388
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   389
qed_spec_mp "W_correct_lemma";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   390
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   391
goal Arith.thy "!!n::nat. ~ k+n < n";
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   392
by (nat_ind_tac "k" 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   393
by (ALLGOALS Asm_simp_tac);
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   394
by (trans_tac 1);
2625
69c1b8a493de Some lemmas changed to valuesd
narasche
parents: 2525
diff changeset
   395
val not_add_less1 = result();
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   396
Addsimps [not_add_less1];
2083
b56425a385b9 Tidied some proofs: changed needed for de Morgan laws
paulson
parents: 2058
diff changeset
   397
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   398
(* Completeness of W w.r.t. has_type *)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   399
goal thy
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   400
 "!S' A t' n. $S' A |- e :: t' --> new_tv n A -->     \
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   401
\             (? S t. (? m. W e A n = Some (S,t,m)) &  \
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   402
\                     (? R. $S' A = $R ($S A) & t' = $R t))";
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   403
by (expr.induct_tac "e" 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   404
(* case Var n *)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   405
by (strip_tac 1);
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
   406
by (simp_tac (!simpset addcongs [conj_cong] addsplits [expand_if]) 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   407
by (eresolve_tac has_type_casesE 1); 
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   408
by (asm_full_simp_tac (!simpset addsimps [is_bound_typ_instance]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   409
by (etac exE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   410
by (hyp_subst_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   411
by (rename_tac "S" 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   412
by (res_inst_tac [("x","%x. (if x < n then S' x else S (x - n))")] exI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   413
by (rtac conjI 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   414
by (Asm_simp_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   415
by (asm_simp_tac (!simpset addsimps [(bound_typ_inst_composed_subst RS sym),new_tv_nth_nat_A,o_def,nth_subst] 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   416
                           delsimps [bound_typ_inst_composed_subst]) 1);
2749
2f477a0e690d Deleted steps made redundant by the stronger eq_assume_tac
paulson
parents: 2637
diff changeset
   417
(** LEVEL 12 **)
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   418
(* case Abs e *)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   419
by (strip_tac 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   420
by (eresolve_tac has_type_casesE 1);
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3240
diff changeset
   421
by (eres_inst_tac [("x","%x. if x=n then t1 else (S' x)")] allE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   422
by (eres_inst_tac [("x","(FVar n)#A")] allE 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   423
by (eres_inst_tac [("x","t2")] allE 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   424
by (eres_inst_tac [("x","Suc n")] allE 1);
2749
2f477a0e690d Deleted steps made redundant by the stronger eq_assume_tac
paulson
parents: 2637
diff changeset
   425
by (best_tac (HOL_cs addSDs [mk_scheme_injective] 
3207
fe79ad367d77 renamed unsafe_addss to addss
oheimb
parents: 3018
diff changeset
   426
                  addss (!simpset addcongs [conj_cong] 
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   427
                                addsplits [split_option_bind])) 1);
2749
2f477a0e690d Deleted steps made redundant by the stronger eq_assume_tac
paulson
parents: 2637
diff changeset
   428
(** LEVEL 19 **)
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   429
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   430
(* case App e1 e2 *)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   431
by (strip_tac 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   432
by (eresolve_tac has_type_casesE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   433
by (eres_inst_tac [("x","S'")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   434
by (eres_inst_tac [("x","A")] allE 1);
1400
5d909faf0e04 Introduced Monad syntax Pat := Val; Cont
nipkow
parents: 1300
diff changeset
   435
by (eres_inst_tac [("x","t2 -> t'")] allE 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   436
by (eres_inst_tac [("x","n")] allE 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   437
by (safe_tac HOL_cs);
2749
2f477a0e690d Deleted steps made redundant by the stronger eq_assume_tac
paulson
parents: 2637
diff changeset
   438
(** LEVEL 26 **)
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   439
by (eres_inst_tac [("x","R")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   440
by (eres_inst_tac [("x","$ S A")] allE 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   441
by (eres_inst_tac [("x","t2")] allE 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   442
by (eres_inst_tac [("x","m")] allE 1);
2749
2f477a0e690d Deleted steps made redundant by the stronger eq_assume_tac
paulson
parents: 2637
diff changeset
   443
by (rotate_tac ~3 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   444
by (Asm_full_simp_tac 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   445
by (safe_tac HOL_cs);
2779
9c42ae57b5f4 The contr_tac, which replaces a fast_tac, is needed only because eq_assume_tac
paulson
parents: 2749
diff changeset
   446
by (contr_tac 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   447
by (fast_tac (HOL_cs addIs [sym RS W_var_geD,new_tv_W RS
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   448
        conjunct1,new_scheme_list_le,new_tv_subst_scheme_list]) 1);
2779
9c42ae57b5f4 The contr_tac, which replaces a fast_tac, is needed only because eq_assume_tac
paulson
parents: 2749
diff changeset
   449
(** LEVEL 35 **)
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   450
by (subgoal_tac
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3240
diff changeset
   451
  "$ (%x. if x=ma then t' else (if x:(free_tv t - free_tv Sa) then R x \
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   452
\        else Ra x)) ($ Sa t) = \
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3240
diff changeset
   453
\  $ (%x. if x=ma then t' else (if x:(free_tv t - free_tv Sa) then R x \
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   454
\        else Ra x)) (ta -> (TVar ma))" 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   455
by (res_inst_tac [("t","$ (%x. if x = ma then t' else \
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   456
\   (if x:(free_tv t - free_tv Sa) then R x else Ra x)) ($ Sa t)"),
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   457
    ("s","($ Ra ta) -> t'")] ssubst 2);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   458
by (asm_simp_tac (!simpset addsimps [subst_comp_te]) 2);
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   459
by (rtac eq_free_eq_subst_te 2);  
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   460
by (strip_tac 2);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   461
by (subgoal_tac "na ~=ma" 2);
2749
2f477a0e690d Deleted steps made redundant by the stronger eq_assume_tac
paulson
parents: 2637
diff changeset
   462
by (best_tac (HOL_cs addDs [new_tv_W,sym RS W_var_geD,
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   463
    new_tv_not_free_tv,new_tv_le]) 3);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   464
by (case_tac "na:free_tv Sa" 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   465
(* n1 ~: free_tv S1 *)
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   466
by (forward_tac [not_free_impl_id] 3);
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
   467
by (asm_simp_tac (!simpset addsplits [expand_if]) 3);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   468
(* na : free_tv Sa *)
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   469
by (dres_inst_tac [("A1","$ S A")] (subst_comp_scheme_list RSN (2,trans)) 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   470
by (dtac eq_subst_scheme_list_eq_free 2);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   471
by (fast_tac (HOL_cs addIs [free_tv_W,free_tv_le_new_tv] addDs [new_tv_W]) 2);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   472
by (Asm_simp_tac 2); 
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   473
by (case_tac "na:dom Sa" 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   474
(* na ~: dom Sa *)
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
   475
by (asm_full_simp_tac (!simpset addsimps [dom_def] addsplits [expand_if]) 3);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   476
(* na : dom Sa *)
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   477
by (rtac eq_free_eq_subst_te 2);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   478
by (strip_tac 2);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   479
by (subgoal_tac "nb ~= ma" 2);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   480
by ((forward_tac [new_tv_W] 3) THEN (atac 3));
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   481
by (etac conjE 3);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   482
by (dtac new_tv_subst_scheme_list 3);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   483
by (fast_tac (HOL_cs addIs [new_scheme_list_le] addDs [sym RS W_var_geD]) 3);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   484
by (fast_tac (set_cs addDs [new_tv_W,new_tv_not_free_tv] addss 
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   485
    (!simpset addsimps [cod_def,free_tv_subst])) 3);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   486
by (fast_tac (set_cs addss (!simpset addsimps [cod_def,free_tv_subst] 
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
   487
                                     addsplits [expand_if])) 2);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   488
by (Simp_tac 2);  
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   489
by (rtac eq_free_eq_subst_te 2);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   490
by (strip_tac 2 );
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   491
by (subgoal_tac "na ~= ma" 2);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   492
by ((forward_tac [new_tv_W] 3) THEN (atac 3));
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   493
by (etac conjE 3);
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   494
by (dtac (sym RS W_var_geD) 3);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   495
by (fast_tac (HOL_cs addDs [new_scheme_list_le,new_tv_subst_scheme_list,new_tv_W,new_tv_not_free_tv]) 3);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   496
by (case_tac "na: free_tv t - free_tv Sa" 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   497
(* case na ~: free_tv t - free_tv Sa *)
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
   498
by ( asm_full_simp_tac (!simpset addsplits [expand_if]) 3);
2793
b30c41754c86 Modified proofs because simplifier does not eta-contract any longer.
nipkow
parents: 2779
diff changeset
   499
by (Fast_tac 3);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   500
(* case na : free_tv t - free_tv Sa *)
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
   501
by ( asm_full_simp_tac (!simpset addsplits [expand_if]) 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   502
by (dres_inst_tac [("A1","$ S A")] (subst_comp_scheme_list RSN (2,trans)) 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   503
by (dtac eq_subst_scheme_list_eq_free 2);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   504
by (fast_tac (HOL_cs addIs [free_tv_W,free_tv_le_new_tv] addDs [new_tv_W]) 2);
2793
b30c41754c86 Modified proofs because simplifier does not eta-contract any longer.
nipkow
parents: 2779
diff changeset
   505
(** LEVEL 75 **)
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   506
by (asm_full_simp_tac (!simpset addsimps [free_tv_subst,dom_def]) 2);
4072
d0d32dd77440 expand_option_bind -> split_option_bind
nipkow
parents: 4033
diff changeset
   507
by (asm_simp_tac (!simpset addsplits [split_option_bind]) 1); 
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   508
by (safe_tac HOL_cs );
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   509
by (dtac mgu_Some 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   510
by ( fast_tac (HOL_cs addss !simpset) 1);
2793
b30c41754c86 Modified proofs because simplifier does not eta-contract any longer.
nipkow
parents: 2779
diff changeset
   511
(** LEVEL 80 *)
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   512
by ((dtac mgu_mg 1) THEN (atac 1));
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   513
by (etac exE 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   514
by (res_inst_tac [("x","Rb")] exI 1);
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   515
by (rtac conjI 1);
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   516
by (dres_inst_tac [("x","ma")] fun_cong 2);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   517
by ( asm_full_simp_tac (!simpset addsimps [eq_sym_conv]) 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   518
by (simp_tac (!simpset addsimps [subst_comp_scheme_list]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   519
by (simp_tac (!simpset addsimps [subst_comp_scheme_list RS sym]) 1);
2793
b30c41754c86 Modified proofs because simplifier does not eta-contract any longer.
nipkow
parents: 2779
diff changeset
   520
by (res_inst_tac [("A2","($ Sa ($ S A))")]
b30c41754c86 Modified proofs because simplifier does not eta-contract any longer.
nipkow
parents: 2779
diff changeset
   521
       ((subst_comp_scheme_list RS sym) RSN (2,trans)) 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   522
by ( asm_full_simp_tac (!simpset addsimps [o_def,eq_sym_conv]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   523
by (rtac eq_free_eq_subst_scheme_list 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   524
by ( safe_tac HOL_cs );
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   525
by (subgoal_tac "ma ~= na" 1);
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   526
by ((forward_tac [new_tv_W] 2) THEN (atac 2));
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   527
by (etac conjE 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   528
by (dtac new_tv_subst_scheme_list 2);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   529
by (fast_tac (HOL_cs addIs [new_scheme_list_le] addDs [sym RS W_var_geD]) 2);
2793
b30c41754c86 Modified proofs because simplifier does not eta-contract any longer.
nipkow
parents: 2779
diff changeset
   530
by (forw_inst_tac [("n","m")] new_tv_W 2  THEN  atac 2);
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1400
diff changeset
   531
by (etac conjE 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   532
by (dtac (free_tv_app_subst_scheme_list RS subsetD) 2);
2793
b30c41754c86 Modified proofs because simplifier does not eta-contract any longer.
nipkow
parents: 2779
diff changeset
   533
by (fast_tac (set_cs addDs [sym RS W_var_geD,new_scheme_list_le,codD,
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
   534
    new_tv_not_free_tv]) 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   535
by (case_tac "na: free_tv t - free_tv Sa" 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   536
(* case na ~: free_tv t - free_tv Sa *)
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
   537
by (asm_full_simp_tac (!simpset addsplits [expand_if]) 2);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   538
(* case na : free_tv t - free_tv Sa *)
3919
c036caebfc75 setloop split_tac -> addsplits
nipkow
parents: 3842
diff changeset
   539
by (asm_full_simp_tac (!simpset addsplits [expand_if]) 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   540
by (dtac (free_tv_app_subst_scheme_list RS subsetD) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   541
by (fast_tac (set_cs addDs [codD,subst_comp_scheme_list RSN (2,trans),
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   542
    eq_subst_scheme_list_eq_free] addss ((!simpset addsimps 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   543
    [free_tv_subst,dom_def]))) 1);
2083
b56425a385b9 Tidied some proofs: changed needed for de Morgan laws
paulson
parents: 2058
diff changeset
   544
by (Fast_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   545
(* case Let e1 e2 *)
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   546
by (eresolve_tac has_type_casesE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   547
by (eres_inst_tac [("x","S'")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   548
by (eres_inst_tac [("x","A")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   549
by (eres_inst_tac [("x","t1")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   550
by (eres_inst_tac [("x","n")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   551
by (mp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   552
by (mp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   553
by (safe_tac HOL_cs);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   554
by (Asm_simp_tac 1); 
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   555
by (eres_inst_tac [("x","R")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   556
by (eres_inst_tac [("x","gen ($ S A) t # $ S A")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   557
by (eres_inst_tac [("x","t'")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   558
by (eres_inst_tac [("x","m")] allE 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   559
by (rotate_tac 4 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   560
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   561
by (dtac mp 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   562
by (rtac has_type_le_env 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   563
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   564
by (Simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   565
by (rtac gen_bound_typ_instance 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   566
by (dtac mp 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   567
by (forward_tac [new_tv_compatible_W] 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   568
by (rtac sym 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   569
by (assume_tac 1);
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   570
by (fast_tac (!claset addDs [new_tv_compatible_gen,new_tv_subst_scheme_list,new_tv_W]) 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   571
by (safe_tac HOL_cs);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   572
by (Asm_full_simp_tac 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   573
by (res_inst_tac [("x","Ra")] exI 1);
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   574
by (simp_tac (!simpset addsimps [o_def,subst_comp_scheme_list RS sym]) 1);
1525
d127436567d0 modified priorities in syntax
nipkow
parents: 1486
diff changeset
   575
qed_spec_mp "W_complete_lemma";
d127436567d0 modified priorities in syntax
nipkow
parents: 1486
diff changeset
   576
d127436567d0 modified priorities in syntax
nipkow
parents: 1486
diff changeset
   577
goal W.thy
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   578
 "!!e. [] |- e :: t' ==>  (? S t. (? m. W e [] n = Some(S,t,m)) &  \
477c05586286 The new version of MiniML including "let".
nipkow
parents: 2513
diff changeset
   579
\                                 (? R. t' = $ R t))";
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   580
by (cut_inst_tac [("A","[]"),("S'","id_subst"),("e","e"),("t'","t'")]
1525
d127436567d0 modified priorities in syntax
nipkow
parents: 1486
diff changeset
   581
                W_complete_lemma 1);
3018
e65b60b28341 Ran expandshort
paulson
parents: 3008
diff changeset
   582
by (ALLGOALS Asm_full_simp_tac);
1525
d127436567d0 modified priorities in syntax
nipkow
parents: 1486
diff changeset
   583
qed "W_complete";