src/HOL/W0/W.ML
changeset 5069 3ea049f7979d
parent 4831 dae4d63a1318
child 5148 74919e8f221c
equal deleted inserted replaced
5068:fb28eaa07e01 5069:3ea049f7979d
     8 
     8 
     9 Addsimps [Suc_le_lessD];
     9 Addsimps [Suc_le_lessD];
    10 Delsimps (ex_simps @ all_simps);
    10 Delsimps (ex_simps @ all_simps);
    11 
    11 
    12 (* correctness of W with respect to has_type *)
    12 (* correctness of W with respect to has_type *)
    13 goal W.thy
    13 Goal
    14         "!a s t m n . Ok (s,t,m) = W e a n --> $s a |- e :: t";
    14         "!a s t m n . Ok (s,t,m) = W e a n --> $s a |- e :: t";
    15 by (expr.induct_tac "e" 1);
    15 by (expr.induct_tac "e" 1);
    16 (* case Var n *)
    16 (* case Var n *)
    17 by (Asm_simp_tac 1);
    17 by (Asm_simp_tac 1);
    18 (* case Abs e *)
    18 (* case Abs e *)
    39 val has_type_casesE = map(has_type.mk_cases expr.simps)
    39 val has_type_casesE = map(has_type.mk_cases expr.simps)
    40         [" s |- Var n :: t"," s |- Abs e :: t","s |- App e1 e2 ::t"];
    40         [" s |- Var n :: t"," s |- Abs e :: t","s |- App e1 e2 ::t"];
    41 
    41 
    42 
    42 
    43 (* the resulting type variable is always greater or equal than the given one *)
    43 (* the resulting type variable is always greater or equal than the given one *)
    44 goal thy
    44 Goal
    45         "!a n s t m. W e a n  = Ok (s,t,m) --> n<=m";
    45         "!a n s t m. W e a n  = Ok (s,t,m) --> n<=m";
    46 by (expr.induct_tac "e" 1);
    46 by (expr.induct_tac "e" 1);
    47 (* case Var(n) *)
    47 (* case Var(n) *)
    48 by (fast_tac (HOL_cs addss simpset()) 1);
    48 by (fast_tac (HOL_cs addss simpset()) 1);
    49 (* case Abs e *)
    49 (* case Abs e *)
    70 by (Asm_simp_tac 1);
    70 by (Asm_simp_tac 1);
    71 qed_spec_mp "W_var_ge";
    71 qed_spec_mp "W_var_ge";
    72 
    72 
    73 Addsimps [W_var_ge];
    73 Addsimps [W_var_ge];
    74 
    74 
    75 goal thy
    75 Goal
    76         "!! s. Ok (s,t,m) = W e a n ==> n<=m";
    76         "!! s. Ok (s,t,m) = W e a n ==> n<=m";
    77 by (asm_full_simp_tac (simpset() addsimps [eq_sym_conv]) 1);
    77 by (asm_full_simp_tac (simpset() addsimps [eq_sym_conv]) 1);
    78 qed "W_var_geD";
    78 qed "W_var_geD";
    79 
    79 
    80 
    80 
    83 by ( simp_tac (simpset() addsimps [eq_sym_conv]) 1);
    83 by ( simp_tac (simpset() addsimps [eq_sym_conv]) 1);
    84 qed "rotate_Ok";
    84 qed "rotate_Ok";
    85 
    85 
    86 
    86 
    87 (* resulting type variable is new *)
    87 (* resulting type variable is new *)
    88 goal thy
    88 Goal
    89      "!n a s t m. new_tv n a --> W e a n = Ok (s,t,m) -->    \
    89      "!n a s t m. new_tv n a --> W e a n = Ok (s,t,m) -->    \
    90 \                 new_tv m s & new_tv m t";
    90 \                 new_tv m s & new_tv m t";
    91 by (expr.induct_tac "e" 1);
    91 by (expr.induct_tac "e" 1);
    92 (* case Var n *)
    92 (* case Var n *)
    93 by (fast_tac (HOL_cs addDs [list_all_nth] addss (simpset() 
    93 by (fast_tac (HOL_cs addDs [list_all_nth] addss (simpset() 
   150                      addIs [new_tv_list_le,new_tv_subst_tel,new_tv_le]
   150                      addIs [new_tv_list_le,new_tv_subst_tel,new_tv_le]
   151                      addss (simpset())) 1);
   151                      addss (simpset())) 1);
   152 qed_spec_mp "new_tv_W";
   152 qed_spec_mp "new_tv_W";
   153 
   153 
   154 
   154 
   155 goal thy
   155 Goal
   156      "!n a s t m v. W e a n = Ok (s,t,m) -->            \
   156      "!n a s t m v. W e a n = Ok (s,t,m) -->            \
   157 \         (v:free_tv s | v:free_tv t) --> v<n --> v:free_tv a";
   157 \         (v:free_tv s | v:free_tv t) --> v<n --> v:free_tv a";
   158 by (expr.induct_tac "e" 1);
   158 by (expr.induct_tac "e" 1);
   159 (* case Var n *)
   159 (* case Var n *)
   160 by (fast_tac (HOL_cs addIs [nth_mem,subsetD,ftv_mem_sub_ftv_list] 
   160 by (fast_tac (HOL_cs addIs [nth_mem,subsetD,ftv_mem_sub_ftv_list] 
   215                      addSEs [UnE]
   215                      addSEs [UnE]
   216                      addss simpset()) 1); 
   216                      addss simpset()) 1); 
   217 qed_spec_mp "free_tv_W"; 
   217 qed_spec_mp "free_tv_W"; 
   218 
   218 
   219 (* Completeness of W w.r.t. has_type *)
   219 (* Completeness of W w.r.t. has_type *)
   220 goal thy
   220 Goal
   221  "!s' a t' n. $s' a |- e :: t' --> new_tv n a -->     \
   221  "!s' a t' n. $s' a |- e :: t' --> new_tv n a -->     \
   222 \             (? s t. (? m. W e a n = Ok (s,t,m)) &  \
   222 \             (? s t. (? m. W e a n = Ok (s,t,m)) &  \
   223 \                     (? r. $s' a = $r ($s a) & t' = $r t))";
   223 \                     (? r. $s' a = $r ($s a) & t' = $r t))";
   224 by (expr.induct_tac "e" 1);
   224 by (expr.induct_tac "e" 1);
   225 (* case Var n *)
   225 (* case Var n *)
   359        addss ((simpset() addsimps [free_tv_subst,dom_def]))) 1);
   359        addss ((simpset() addsimps [free_tv_subst,dom_def]))) 1);
   360 (** LEVEL 106 **)
   360 (** LEVEL 106 **)
   361 by (Fast_tac 1);
   361 by (Fast_tac 1);
   362 qed_spec_mp "W_complete_lemma";
   362 qed_spec_mp "W_complete_lemma";
   363 
   363 
   364 goal W.thy
   364 Goal
   365  "!!e. [] |- e :: t' ==>  (? s t. (? m. W e [] n = Ok(s,t,m)) &  \
   365  "!!e. [] |- e :: t' ==>  (? s t. (? m. W e [] n = Ok(s,t,m)) &  \
   366 \                                 (? r. t' = $r t))";
   366 \                                 (? r. t' = $r t))";
   367 by (cut_inst_tac [("a","[]"),("s'","id_subst"),("e","e"),("t'","t'")]
   367 by (cut_inst_tac [("a","[]"),("s'","id_subst"),("e","e"),("t'","t'")]
   368                 W_complete_lemma 1);
   368                 W_complete_lemma 1);
   369 by (ALLGOALS Asm_full_simp_tac);
   369 by (ALLGOALS Asm_full_simp_tac);