src/HOL/MicroJava/J/WellForm.ML
changeset 10613 78b1d6c3ee9c
parent 10138 412a3ced6efd
child 10925 5ffe7ed8899a
equal deleted inserted replaced
10612:779af7c58743 10613:78b1d6c3ee9c
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author:     David von Oheimb
     3     Author:     David von Oheimb
     4     Copyright   1999 Technische Universitaet Muenchen
     4     Copyright   1999 Technische Universitaet Muenchen
     5 *)
     5 *)
     6 
     6 
     7 val class_wf = prove_goalw thy [wf_prog_def, Let_def, class_def]
     7 Goalw [wf_prog_def]
     8  "!!X. [|class G C = Some c; wf_prog wf_mb G|] ==> wf_cdecl wf_mb G (C,c)" (K [
     8  "[|class G C = Some c; wf_prog wf_mb G|] ==> wf_cdecl wf_mb G (C,c)";
     9 	Asm_full_simp_tac 1,
     9 by (Asm_full_simp_tac 1);
    10 	fast_tac (set_cs addDs [get_in_set]) 1]);
    10 by (fast_tac (set_cs addDs [map_of_SomeD]) 1);
    11 
    11 qed "class_wf";
    12 val class_Object = prove_goalw thy [wf_prog_def, Let_def, ObjectC_def,class_def]
    12 
    13 	"!!X. wf_prog wf_mb G ==> class G Object = Some (None, [], [])" (K [
    13 Goalw [wf_prog_def, ObjectC_def]
    14 	safe_tac set_cs,
    14 	"wf_prog wf_mb G ==> class G Object = Some (arbitrary, [], [])";
    15 	dtac in_set_get 1,
    15 by (auto_tac (claset() addIs [map_of_SomeI], simpset()));
    16 	 Auto_tac]);
    16 qed "class_Object";
    17 Addsimps [class_Object];
    17 Addsimps [class_Object];
    18 
    18 
    19 val is_class_Object = prove_goalw thy [is_class_def] 
    19 Goal "wf_prog wf_mb G ==> is_class G Object";
    20 	"!!X. wf_prog wf_mb G ==> is_class G Object" (K [Asm_simp_tac 1]);
    20 by (Asm_simp_tac 1);
       
    21 qed "is_class_Object";
    21 Addsimps [is_class_Object];
    22 Addsimps [is_class_Object];
    22 
    23 
    23 Goal "[|G\\<turnstile>C\\<prec>C1D; wf_prog wf_mb G|] ==> D \\<noteq> C \\<and> \\<not>(D,C)\\<in>(subcls1 G)^+";
    24 Goal "[|G\\<turnstile>C\\<prec>C1D; wf_prog wf_mb G|] ==> D \\<noteq> C \\<and> \\<not>(D,C)\\<in>(subcls1 G)^+";
    24 by( forward_tac [r_into_trancl] 1);
    25 by( forward_tac [r_into_trancl] 1);
    25 by( dtac subcls1D 1);
    26 by( dtac subcls1D 1);
    26 by( strip_tac1 1);
    27 by(Clarify_tac 1);
    27 by( datac class_wf 1 1);
    28 by( datac class_wf 1 1);
    28 by( rewtac wf_cdecl_def);
    29 by( rewtac wf_cdecl_def);
    29 by(force_tac (claset(), simpset() addsimps [reflcl_trancl RS sym] 
    30 by(force_tac (claset(), simpset() addsimps [reflcl_trancl RS sym] 
    30 				  delsimps [reflcl_trancl]) 1);
    31 				  delsimps [reflcl_trancl]) 1);
    31 qed "subcls1_wfD";
    32 qed "subcls1_wfD";
    32 
    33 
    33 val wf_cdecl_supD = prove_goalw thy [wf_cdecl_def] 
    34 Goalw [wf_cdecl_def] 
    34 "!!X. [|wf_cdecl wf_mb G (C, sc, r); C \\<noteq> Object|] ==> \\<exists>D. sc = Some D \\<and> is_class G D" (K [
    35 "!!r. \\<lbrakk>wf_cdecl wf_mb G (C,D,r); C \\<noteq> Object\\<rbrakk> \\<Longrightarrow> is_class G D";
    35 	pair_tac "r" 1,
    36 by (auto_tac (claset(), simpset() addsplits [option.split_asm]));
    36 	asm_full_simp_tac (simpset() addsplits [option.split_asm]) 1]);
    37 qed "wf_cdecl_supD";
    37 
    38 
    38 Goal "[|wf_prog wf_mb G; (C,D)\\<in>(subcls1 G)^+|] ==> \\<not>(D,C)\\<in>(subcls1 G)^+";
    39 Goal "[|wf_prog wf_mb G; (C,D)\\<in>(subcls1 G)^+|] ==> \\<not>(D,C)\\<in>(subcls1 G)^+";
    39 by(etac tranclE 1);
    40 by(etac tranclE 1);
    40 by(TRYALL(fast_tac (HOL_cs addSDs [subcls1_wfD] addIs [trancl_trans])));
    41 by(TRYALL(fast_tac (claset() addSDs [subcls1_wfD] addIs [trancl_trans])));
    41 qed "subcls_asym";
    42 qed "subcls_asym";
    42 
    43 
    43 val subcls_irrefl = prove_goal thy "!!X. [|wf_prog wf_mb G; (C,D)\\<in>(subcls1 G)^+|] ==> C \\<noteq> D" (K [
    44 Goal "[|wf_prog wf_mb G; (C,D)\\<in>(subcls1 G)^+|] ==> C \\<noteq> D";
    44 	etac trancl_trans_induct 1,
    45 by (etac trancl_trans_induct 1);
    45 	 fast_tac (HOL_cs addDs [subcls1_wfD]) 1,
    46 by  (auto_tac (claset() addDs [subcls1_wfD,subcls_asym],simpset()));
    46 	fast_tac (HOL_cs addDs [subcls_asym]) 1]);
    47 qed "subcls_irrefl";
    47 
    48 
    48 val acyclic_subcls1 = prove_goalw thy [acyclic_def] 
    49 Goalw [acyclic_def] "wf_prog wf_mb G ==> acyclic (subcls1 G)";
    49 	"!!X. wf_prog wf_mb G ==> acyclic (subcls1 G)" (K [
    50 by (fast_tac (claset() addDs [subcls_irrefl]) 1);
    50 	strip_tac1 1,
    51 qed "acyclic_subcls1";
    51 	fast_tac (HOL_cs addDs [subcls_irrefl]) 1]);
    52 
    52 
    53 Goal "wf_prog wf_mb G ==> wf ((subcls1 G)^-1)";
    53 val wf_subcls1 = prove_goal thy "!!X. wf_prog wf_mb G ==> wf ((subcls1 G)^-1)" (K [
    54 by (rtac finite_acyclic_wf 1);
    54 	rtac finite_acyclic_wf 1,
    55 by ( stac finite_converse 1);
    55 	 stac finite_converse 1,
    56 by ( rtac finite_subcls1 1);
    56 	 rtac finite_subcls1 1,
    57 by (stac acyclic_converse 1);
    57 	stac acyclic_converse 1,
    58 by (etac acyclic_subcls1 1);
    58 	etac acyclic_subcls1 1]);
    59 qed "wf_subcls1";
    59 
    60 
    60 val major::prems = goal thy
    61 val major::prems = goal thy
    61   "[|wf_prog wf_mb G; !!C. \\<forall>D. (C,D)\\<in>(subcls1 G)^+ --> P D ==> P C|] ==> P C";
    62   "[|wf_prog wf_mb G; !!C. \\<forall>D. (C,D)\\<in>(subcls1 G)^+ --> P D ==> P C|] ==> P C";
    62 by(cut_facts_tac [major RS wf_subcls1] 1);
    63 by(cut_facts_tac [major RS wf_subcls1] 1);
    63 by(dtac wf_trancl 1);
    64 by(dtac wf_trancl 1);
    66 by(resolve_tac prems 1);
    67 by(resolve_tac prems 1);
    67 by(Auto_tac);
    68 by(Auto_tac);
    68 qed "subcls_induct";
    69 qed "subcls_induct";
    69 
    70 
    70 val prems = goal thy "[|is_class G C; wf_prog wf_mb G; P Object; \
    71 val prems = goal thy "[|is_class G C; wf_prog wf_mb G; P Object; \
    71 \!!C D fs ms. [|C \\<noteq> Object; is_class G C; class G C = Some (Some D,fs,ms) \\<and> \
    72 \!!C D fs ms. [|C \\<noteq> Object; is_class G C; class G C = Some (D,fs,ms) \\<and> \
    72 \   wf_cdecl wf_mb G (C, Some D,fs,ms) \\<and> G\\<turnstile>C\\<prec>C1D \\<and> is_class G D \\<and> P D|] ==> P C\
    73 \   wf_cdecl wf_mb G (C,D,fs,ms) \\<and> G\\<turnstile>C\\<prec>C1D \\<and> is_class G D \\<and> P D|] ==> P C\
    73 \ |] ==> P C";
    74 \ |] ==> P C";
    74 by( cut_facts_tac prems 1);
    75 by( cut_facts_tac prems 1);
    75 by( rtac impE 1);
    76 by( rtac impE 1);
    76 by(   atac 2);
    77 by(   atac 2);
    77 by(  atac 2);
    78 by(  atac 2);
    79 by( rtac subcls_induct 1);
    80 by( rtac subcls_induct 1);
    80 by(  atac 1);
    81 by(  atac 1);
    81 by( rtac impI 1);
    82 by( rtac impI 1);
    82 by( case_tac "C = Object" 1);
    83 by( case_tac "C = Object" 1);
    83 by(  Fast_tac 1);
    84 by(  Fast_tac 1);
    84 by( ex_ftac is_classD 1);
    85 by Safe_tac;
    85 by( forward_tac [class_wf] 1);
    86 by( forward_tac [class_wf] 1);
    86 by(  atac 1);
    87 by(  atac 1);
    87 by( forward_tac [wf_cdecl_supD] 1);
    88 by( forward_tac [wf_cdecl_supD] 1);
    88 by(  atac 1);
    89 by(  atac 1);
    89 by( strip_tac1 1);
    90 
       
    91 by( subgoal_tac "G\\<turnstile>C\\<prec>C1a" 1);
       
    92 by( etac subcls1I 2);
    90 by( rtac (hd (tl (tl (tl prems)))) 1);
    93 by( rtac (hd (tl (tl (tl prems)))) 1);
    91 by(   atac 1);
    94 by Auto_tac;
    92 by(  atac 1);
       
    93 by( subgoal_tac "G\\<turnstile>C\\<prec>C1D" 1);
       
    94 by(  fast_tac (HOL_cs addIs [r_into_trancl]) 1);
       
    95 by( etac subcls1I 1);
       
    96 qed "subcls1_induct";
    95 qed "subcls1_induct";
    97 
    96 
    98 Goal "[|wf ((subcls1 G)^-1); \\<forall>D fs ms. class G C = Some (Some D,fs,ms) --> is_class G D|] ==> method (G,C) = \
    97 Goal "[|wf ((subcls1 G)^-1); \\<forall>D fs ms. class G C = Some (D,fs,ms) \\<longrightarrow> C \\<noteq> Object --> is_class G D|] ==> method (G,C) = \
    99 \ (case class G C of None => empty | Some (sc,fs,ms) => \
    98 \ (case class G C of None => arbitrary | Some (D,fs,ms) => \
   100 \ (case sc of None => empty | Some D => method (G,D)) ++ \
    99 \ (if C = Object then empty else method (G,D)) ++ \
   101 \ map_of (map (\\<lambda>(s,m). (s,(C,m))) ms))";
   100 \ map_of (map (\\<lambda>(s,m). (s,(C,m))) ms))";
   102 by( stac (method_TC RS (wf_subcls1_rel RS (hd method.simps))) 1);
   101 by( stac (method_TC RS (wf_subcls1_rel RS (hd method.simps))) 1);
   103 by( asm_simp_tac (simpset() addsplits[option.split]) 1);
   102 by( asm_simp_tac (simpset() addsplits[option.split]) 1);
   104 auto();
   103 by Auto_tac;
   105 qed "method_rec_lemma";
   104 qed "method_rec_lemma";
   106 
   105 
   107 Goal "wf_prog wf_mb G ==> method (G,C) = \
   106 Goal "wf_prog wf_mb G ==> method (G,C) = \
   108 \ (case class G C of None => empty | Some (sc,fs,ms) => \
   107 \ (case class G C of None => arbitrary | Some (D,fs,ms) => \
   109 \ (case sc of None => empty | Some D => method (G,D)) ++ \
   108 \ (if C = Object then empty else method (G,D)) ++ \
   110 \ map_of (map (\\<lambda>(s,m). (s,(C,m))) ms))";
   109 \ map_of (map (\\<lambda>(s,m). (s,(C,m))) ms))";
   111 by(rtac method_rec_lemma 1);
   110 by(rtac method_rec_lemma 1);
   112 by( clarsimp_tac (claset(), simpset() addsimps [wf_subcls1,empty_def] 
   111 by( clarsimp_tac (claset(), simpset() addsimps [wf_subcls1,empty_def] 
   113 		addsplits [option.split]) 1);
   112 		addsplits [option.split]) 1);
   114 by( case_tac "C = Object" 1);
   113 by( case_tac "C = Object" 1);
   117 by( datac class_wf 1 1);
   116 by( datac class_wf 1 1);
   118 by( datac wf_cdecl_supD 1 1);
   117 by( datac wf_cdecl_supD 1 1);
   119 by( Asm_full_simp_tac 1);
   118 by( Asm_full_simp_tac 1);
   120 qed "method_rec";
   119 qed "method_rec";
   121 
   120 
   122 Goal "[|wf ((subcls1 G)^-1); class G C = Some (sc,fs,ms); \\<forall>C. sc = Some C --> is_class G C|] ==> fields (G,C) = \
   121 Goal "[|wf ((subcls1 G)^-1); class G C = Some (D,fs,ms); C \\<noteq> Object \\<longrightarrow> is_class G D|] ==> fields (G,C) = \
   123 \ map (\\<lambda>(fn,ft). ((fn,C),ft)) fs @ \
   122 \ map (\\<lambda>(fn,ft). ((fn,C),ft)) fs @ (if C = Object then [] else fields (G,D))";
   124 \ (case sc of None => [] | Some D => fields (G,D))";
   123 by(rtac trans 1);
   125 by( stac (fields_TC RS (wf_subcls1_rel RS (hd fields.simps))) 1);
   124 by(rtac (fields_TC RS (wf_subcls1_rel RS (hd fields.simps))) 1);
   126 by( asm_simp_tac (simpset() addsplits[option.split]) 1);
   125 by( asm_simp_tac (simpset() addsplits[option.split]) 1);
   127 qed "fields_rec_lemma";
   126 qed "fields_rec_lemma";
   128 
   127 
   129 Goal "[|class G C = Some (sc,fs,ms); wf_prog wf_mb G|] ==> fields (G,C) = \
   128 Goal "[|class G C = Some (D,fs,ms); wf_prog wf_mb G|] ==> fields (G,C) = \
   130 \ map (\\<lambda>(fn,ft). ((fn,C),ft)) fs @ \
   129 \ map (\\<lambda>(fn,ft). ((fn,C),ft)) fs @ (if C = Object then [] else fields (G,D))";
   131 \ (case sc of None => [] | Some D => fields (G,D))";
   130 by(rtac trans 1);
   132 by(rtac fields_rec_lemma 1);
   131 by(rtac fields_rec_lemma 1);
   133 by(   asm_simp_tac (simpset() addsimps [wf_subcls1,empty_def]) 1);
   132 by(   asm_simp_tac (simpset() addsimps [wf_subcls1]) 1);
   134 ba  1;
   133 ba  1;
   135 by( option_case_tac2 "sc" 1);
   134 br refl 2;
   136 by(  Asm_simp_tac 1);
       
   137 by( case_tac "C = Object" 1);
       
   138 by(  rotate_tac 2 1);
       
   139 by(  Asm_full_simp_tac 1);
       
   140 by( datac class_wf 1 1);
   135 by( datac class_wf 1 1);
   141 by( datac wf_cdecl_supD 1 1);
   136 by(rtac impI 1);
   142 by( Asm_full_simp_tac 1);
   137 by( eatac wf_cdecl_supD 1 1);
   143 qed "fields_rec";
   138 qed "fields_rec";
   144 
   139 
   145 val method_Object = prove_goal thy "!!X. wf_prog wf_mb G ==> method (G,Object) = empty"
   140 Goal "wf_prog wf_mb G ==> method (G,Object) = empty";
   146 	(K [stac method_rec 1,Auto_tac]);
   141 by(stac method_rec 1);
   147 val fields_Object = prove_goal thy "!!X. wf_prog wf_mb G ==> fields (G,Object) = []"(K [
   142 by Auto_tac;
   148 	stac fields_rec 1,Auto_tac]);
   143 qed "method_Object";
       
   144 
       
   145 Goal "wf_prog wf_mb G ==> fields (G,Object) = []";
       
   146 by(stac fields_rec 1);
       
   147 by Auto_tac;
       
   148 qed "fields_Object";
       
   149 
   149 Addsimps [method_Object, fields_Object];
   150 Addsimps [method_Object, fields_Object];
   150 val field_Object = prove_goalw thy [field_def]
   151 
   151  "!!X. wf_prog wf_mb G ==> field (G,Object) = empty" (K [Asm_simp_tac 1]);
   152 Goalw [field_def] "wf_prog wf_mb G ==> field (G,Object) = empty";
       
   153 by(Asm_simp_tac 1);
       
   154 qed "field_Object";
   152 Addsimps [field_Object];
   155 Addsimps [field_Object];
   153 
   156 
   154 Goal "[|is_class G C; wf_prog wf_mb G|] ==> G\\<turnstile>C\\<preceq>C Object";
   157 Goal "[|is_class G C; wf_prog wf_mb G|] ==> G\\<turnstile>C\\<preceq>C Object";
   155 by(etac subcls1_induct 1);
   158 by(etac subcls1_induct 1);
   156 by(  atac 1);
   159 by(  atac 1);
   157 by( Fast_tac 1);
   160 by( Fast_tac 1);
   158 by(auto_tac (HOL_cs addSDs [wf_cdecl_supD], simpset()));
   161 by(auto_tac (HOL_cs addSDs [wf_cdecl_supD], simpset()));
   159 by(eatac rtrancl_into_rtrancl2 1 1);
   162 by(eatac rtrancl_into_rtrancl2 1 1);
   160 qed "subcls_C_Object";
   163 qed "subcls_C_Object";
   161 
   164 
   162 val is_type_rTI = prove_goalw thy [wf_mhead_def]
   165 Goalw [wf_mhead_def] "wf_mhead G sig rT ==> is_type G rT";
   163 	"!!sig. wf_mhead G sig rT ==> is_type G rT"
   166 by Auto_tac;
   164 	(K [split_all_tac 1, Auto_tac]);
   167 qed "is_type_rTI";
   165 
       
   166 Goal "[|(C',C)\\<in>(subcls1 G)^+; wf_prog wf_mb G|] ==> \
       
   167 \ x \\<in> set (fields (G,C)) --> x \\<in> set (fields (G,C'))";
       
   168 by(etac trancl_trans_induct 1);
       
   169 by( safe_tac (HOL_cs addSDs [subcls1D]));
       
   170 by(stac fields_rec 1);
       
   171 by(  Auto_tac);
       
   172 qed_spec_mp "fields_mono";
       
   173 
   168 
   174 Goal "[|is_class G C; wf_prog wf_mb G|] ==> \
   169 Goal "[|is_class G C; wf_prog wf_mb G|] ==> \
   175 \ \\<forall>((fn,fd),fT)\\<in>set (fields (G,C)). G\\<turnstile>C\\<preceq>C fd";
   170 \ \\<forall>((fn,fd),fT)\\<in>set (fields (G,C)). G\\<turnstile>C\\<preceq>C fd";
   176 by( etac subcls1_induct 1);
   171 by( etac subcls1_induct 1);
   177 by(   atac 1);
   172 by(   atac 1);
   178 by(  Asm_simp_tac 1);
   173 by(  Asm_simp_tac 1);
   179 by( safe_tac HOL_cs);
   174 by( safe_tac HOL_cs);
   180 by( stac fields_rec 1);
   175 by( stac fields_rec 1);
   181 by(   atac 1);
   176 by(   atac 1);
   182 by(  atac 1);
   177 by(  atac 1);
   183 by( Simp_tac 1);
   178 by( simp_tac (simpset() delsplits [split_if]) 1);
   184 by( rtac ballI 1);
   179 by( rtac ballI 1);
   185 by( split_all_tac 1);
   180 by( split_all_tac 1);
   186 by( Simp_tac 1);
   181 by( Simp_tac 1);
   187 by( etac UnE 1);
   182 by( etac UnE 1);
   188 by(  dtac split_Pair_eq 1);
   183 by(  Force_tac 1);
   189 by(  SELECT_GOAL (Auto_tac) 1);
       
   190 by( etac (r_into_rtrancl RS rtrancl_trans) 1);
   184 by( etac (r_into_rtrancl RS rtrancl_trans) 1);
   191 by( etac BallE 1);
   185 by Auto_tac;
   192 by(  contr_tac 1);
       
   193 by( Asm_full_simp_tac 1);
       
   194 qed "widen_fields_defpl'";
   186 qed "widen_fields_defpl'";
   195 
   187 
   196 Goal "[|is_class G C; wf_prog wf_mb G; ((fn,fd),fT) \\<in> set (fields (G,C))|] ==> \
   188 Goal "[|((fn,fd),fT) \\<in> set (fields (G,C)); wf_prog wf_mb G; is_class G C|] ==> \
   197 \ G\\<turnstile>C\\<preceq>C fd";
   189 \ G\\<turnstile>C\\<preceq>C fd";
   198 by( datac widen_fields_defpl' 1 1);
   190 by( datac widen_fields_defpl' 1 1);
   199 (*###################*)
   191 by (Fast_tac 1);
   200 by( dtac bspec 1);
       
   201 auto();
       
   202 qed "widen_fields_defpl";
   192 qed "widen_fields_defpl";
   203 
       
   204 
   193 
   205 Goal "[|is_class G C; wf_prog wf_mb G|] ==> unique (fields (G,C))";
   194 Goal "[|is_class G C; wf_prog wf_mb G|] ==> unique (fields (G,C))";
   206 by( etac subcls1_induct 1);
   195 by( etac subcls1_induct 1);
   207 by(   atac 1);
   196 by(   atac 1);
   208 by(  safe_tac (HOL_cs addSDs [wf_cdecl_supD]));
   197 by(  safe_tac (HOL_cs addSDs [wf_cdecl_supD]));
   210 by( dtac subcls1_wfD 1);
   199 by( dtac subcls1_wfD 1);
   211 by(  atac 1);
   200 by(  atac 1);
   212 by( stac fields_rec 1);
   201 by( stac fields_rec 1);
   213 by   Auto_tac;
   202 by   Auto_tac;
   214 by( rotate_tac ~1 1);
   203 by( rotate_tac ~1 1);
   215 by( ex_ftac is_classD 1);
       
   216 by( forward_tac [class_wf] 1);
   204 by( forward_tac [class_wf] 1);
   217 by  Auto_tac;
   205 by  Auto_tac;
   218 by( asm_full_simp_tac (simpset() addsimps [wf_cdecl_def]) 1);
   206 by( asm_full_simp_tac (simpset() addsimps [wf_cdecl_def]) 1);
   219 by( etac unique_append 1);
   207 by( etac unique_append 1);
   220 by(  rtac unique_map_Pair 1);
   208 by(  rtac unique_map_inj 1);
   221 by(  Step_tac 1);
   209 by(   Clarsimp_tac 1);
   222 by (EVERY1[dtac widen_fields_defpl, atac, atac]);
   210 by  (rtac injI 1);
   223 by( Asm_full_simp_tac 1);
   211 by(  Asm_full_simp_tac 1);
   224 by( dtac split_Pair_eq 1);
   212 by(auto_tac (claset() addSDs [widen_fields_defpl], simpset()));
   225 by( Asm_full_simp_tac 1);
       
   226 qed "unique_fields";
   213 qed "unique_fields";
   227 
   214 
       
   215 Goal "[|wf_prog wf_mb G; (C',C)\\<in>(subcls1 G)^*|] ==> \
       
   216 \ x \\<in> set (fields (G,C)) --> x \\<in> set (fields (G,C'))";
       
   217 by(etac converse_rtrancl_induct 1);
       
   218 by( safe_tac (HOL_cs addSDs [subcls1D]));
       
   219 by(stac fields_rec 1);
       
   220 by(  Auto_tac);
       
   221 qed_spec_mp "fields_mono_lemma";
       
   222 
   228 Goal
   223 Goal
   229 "[|wf_prog wf_mb G; G\\<turnstile>C'\\<preceq>C C; map_of(fields (G,C )) f = Some ft|] ==> \
   224 "\\<lbrakk>map_of (fields (G,C)) fn = Some f; G\\<turnstile>D\\<preceq>C C; is_class G D; wf_prog wf_mb G\\<rbrakk>\
   230 \                          map_of (fields (G,C')) f = Some ft";
   225 \ \\<Longrightarrow> map_of (fields (G,D)) fn = Some f";
   231 by( dtac rtranclD 1);
   226 by (rtac map_of_SomeI 1);
   232 by( Auto_tac);
   227 by  (eatac unique_fields 1 1);
   233 by( rtac table_mono 1);
   228 by (eatac fields_mono_lemma 1 1);
   234 by(   atac 3);
   229 by (etac map_of_SomeD 1);
   235 by(  rtac unique_fields 1);
   230 qed "fields_mono";
   236 by(   etac subcls_is_class 1);
   231 
   237 by(  atac 1);
   232 Goal 
   238 by( fast_tac (HOL_cs addEs [fields_mono]) 1);
   233 "[|field (G,C) fn = Some (fd, fT); G\\<turnstile>D\\<preceq>C C; wf_prog wf_mb G|]==> \
   239 qed "widen_fields_mono";
   234 \ map_of (fields (G,D)) (fn, fd) = Some fT";
   240 
   235 by (dtac field_fields 1);
   241 
   236 by (dtac rtranclD 1);
   242 val cfs_fields_lemma = prove_goalw thy [field_def] 
   237 by Safe_tac;
   243 "!!X. field (G,C) fn = Some (fd, fT) ==> map_of(fields (G,C)) (fn, fd) = Some fT"
   238 by (ftac subcls_is_class 1);
   244 (K [rtac table_map_Some 1, Asm_full_simp_tac 1]);
   239 by (dtac trancl_into_rtrancl 1);
   245 
   240 by (fast_tac (HOL_cs addDs [fields_mono]) 1);
   246 val widen_cfs_fields = prove_goal thy "!!X. [|field (G,C) fn = Some (fd, fT);\
   241 qed "widen_cfs_fields";
   247 \  G\\<turnstile>C'\\<preceq>C C; wf_prog wf_mb G|] ==> map_of (fields (G,C')) (fn, fd) = Some fT" (K[
   242 
   248 fast_tac (HOL_cs addIs [widen_fields_mono, cfs_fields_lemma]) 1]);
   243 Goal "wf_prog wf_mb G ==> is_class G C \\<Longrightarrow>  \
   249 bind_thm ("widen_cfs_fields",widen_cfs_fields);
   244 \    method (G,C) sig = Some (md,mh,m)\
   250 
       
   251 
       
   252 Goal "wf_prog wf_mb G ==> method (G,C) sig = Some (md,mh,m)\
       
   253 \  --> G\\<turnstile>C\\<preceq>C md \\<and> wf_mdecl wf_mb G md (sig,(mh,m))";
   245 \  --> G\\<turnstile>C\\<preceq>C md \\<and> wf_mdecl wf_mb G md (sig,(mh,m))";
   254 by( case_tac "is_class G C" 1);
       
   255 by(  forw_inst_tac [("C","C")] method_rec 2);
       
   256 by(    asm_full_simp_tac (simpset() addsimps [is_class_def] 
       
   257 	delsimps [not_None_eq]) 2);
       
   258 by( etac subcls1_induct 1);
   246 by( etac subcls1_induct 1);
   259 by(   atac 1);
   247 by(   atac 1);
   260 by(  Force_tac 1);
   248 by(  Force_tac 1);
   261 by( forw_inst_tac [("C","C")] method_rec 1);
   249 by( forw_inst_tac [("C","C")] method_rec 1);
   262 by( strip_tac1 1);
   250 by( Clarify_tac 1);
   263 by( rotate_tac ~1 1);
   251 by( rotate_tac ~1 1);
   264 by( Asm_full_simp_tac 1);
   252 by( Asm_full_simp_tac 1);
   265 by( dtac override_SomeD 1);
   253 by( dtac override_SomeD 1);
   266 by( etac disjE 1);
   254 by( etac disjE 1);
   267 by(  thin_tac "?P --> ?Q" 1);
   255 by(  thin_tac "?P --> ?Q" 1);
   268 by(  Clarify_tac 2);
   256 by(  Clarify_tac 2);
   269 by(  rtac rtrancl_trans 2);
   257 by(  rtac rtrancl_trans 2);
   270 by(   atac 3);
   258 by(   atac 3);
   271 by(  rtac r_into_rtrancl 2);
   259 by(  rtac r_into_rtrancl 2);
   272 by(  fast_tac (HOL_cs addIs [subcls1I]) 2);
   260 by(  fast_tac (HOL_cs addIs [subcls1I]) 2);
   273 by( forward_tac [table_mapf_SomeD] 1);
   261 by (rotate_tac ~1 1);
   274 by( strip_tac1 1);
   262 by (ftac map_of_SomeD 1);
   275 by( Asm_full_simp_tac 1);
       
   276 by( rewtac wf_cdecl_def);
   263 by( rewtac wf_cdecl_def);
   277 by( Asm_full_simp_tac 1);
   264 by (Clarsimp_tac 1);
   278 qed_spec_mp "method_wf_mdecl";
   265 qed_spec_mp "method_wf_mdecl";
   279 
   266 
   280 Goal "[|G\\<turnstile>T\\<preceq>C T'; wf_prog wf_mb G|] ==> \
   267 Goal "[|G\\<turnstile>T\\<preceq>C T'; wf_prog wf_mb G|] ==> \
   281 \  \\<forall>D rT b. method (G,T') sig = Some (D,rT ,b) -->\
   268 \  \\<forall>D rT b. method (G,T') sig = Some (D,rT ,b) -->\
   282 \ (\\<exists>D' rT' b'. method (G,T) sig = Some (D',rT',b') \\<and> G\\<turnstile>rT'\\<preceq>rT)";
   269 \ (\\<exists>D' rT' b'. method (G,T) sig = Some (D',rT',b') \\<and> G\\<turnstile>rT'\\<preceq>rT)";
   283 by( dtac rtranclD 1);
   270 by( dtac rtranclD 1);
   284 by( etac disjE 1);
   271 by( etac disjE 1);
   285 by(  Fast_tac 1);
   272 by(  Fast_tac 1);
   286 by( etac conjE 1);
   273 by( etac conjE 1);
   287 by( etac trancl_trans_induct 1);
   274 by( etac trancl_trans_induct 1);
   288 by(  strip_tac1 2);
   275 by(  Clarify_tac 2);
   289 by(  EVERY[dtac spec 2, dtac spec 2, dtac spec 2, mp_tac 2]);
   276 by(  EVERY[smp_tac 3 2]);
   290 by(  fast_tac (HOL_cs addEs [widen_trans]) 2);
   277 by(  fast_tac (HOL_cs addEs [widen_trans]) 2);
   291 by( strip_tac1 1);
   278 by( Clarify_tac 1);
   292 by( dtac subcls1D 1);
   279 by( dtac subcls1D 1);
   293 by( strip_tac1 1);
   280 by( Clarify_tac 1);
   294 by( stac method_rec 1);
   281 by( stac method_rec 1);
   295 by(  atac 1);
   282 by(  atac 1);
   296 by( rewtac override_def);
   283 by( rewtac override_def);
   297 by( asm_simp_tac (simpset() delsimps [split_paired_Ex]) 1);
   284 by( asm_simp_tac (simpset() delsimps [split_paired_Ex]) 1);
   298 by( case_tac "\\<exists>z. map_of(map (\\<lambda>(s,m). (s, ?C, m)) ms) sig = Some z" 1);
   285 by( case_tac "\\<exists>z. map_of(map (\\<lambda>(s,m). (s, ?C, m)) ms) sig = Some z" 1);
   302 by(  ALLGOALS (asm_simp_tac (simpset() delsimps [split_paired_Ex])));
   289 by(  ALLGOALS (asm_simp_tac (simpset() delsimps [split_paired_Ex])));
   303 by( dtac class_wf 1);
   290 by( dtac class_wf 1);
   304 by(  atac 1);
   291 by(  atac 1);
   305 by( split_all_tac 1);
   292 by( split_all_tac 1);
   306 by( rewtac wf_cdecl_def);
   293 by( rewtac wf_cdecl_def);
   307 by( dtac table_mapf_Some2 1);
   294 by( dtac map_of_SomeD 1);
   308 by( Clarsimp_tac 1);
       
   309 by( dres_inst_tac [("xys1","ms")] get_in_set 1);
       
   310 by Auto_tac;
   295 by Auto_tac;
   311 qed_spec_mp "subcls_widen_methd";
   296 qed_spec_mp "subcls_widen_methd";
   312 
       
   313 
   297 
   314 Goal
   298 Goal
   315  "[| G\\<turnstile> C\\<preceq>C D; wf_prog wf_mb G; \
   299  "[| G\\<turnstile> C\\<preceq>C D; wf_prog wf_mb G; \
   316 \    method (G,D) sig = Some (md, rT, b) |] \
   300 \    method (G,D) sig = Some (md, rT, b) |] \
   317 \ ==> \\<exists>mD' rT' b'. method (G,C) sig= Some(mD',rT',b') \\<and> G\\<turnstile>rT'\\<preceq>rT";
   301 \ ==> \\<exists>mD' rT' b'. method (G,C) sig= Some(mD',rT',b') \\<and> G\\<turnstile>rT'\\<preceq>rT";
   318 by(auto_tac (claset() addDs [subcls_widen_methd,method_wf_mdecl],
   302 by(auto_tac (claset() addDs [subcls_widen_methd,method_wf_mdecl],
   319              simpset() addsimps [wf_mdecl_def,wf_mhead_def,split_def]));
   303              simpset() addsimps [wf_mdecl_def,wf_mhead_def,split_def]));
   320 qed "subtype_widen_methd";
   304 qed "subtype_widen_methd";
   321 
   305 
   322 
   306 Goal "wf_prog wf_mb G ==> is_class G C \\<Longrightarrow> \\<forall>D. method (G,C) sig = Some(D,mh,code) --> is_class G D \\<and> method (G,D) sig = Some(D,mh,code)";
   323 Goal "wf_prog wf_mb G ==> \\<forall>D. method (G,C) sig = Some(D,mh,code) --> is_class G D \\<and> method (G,D) sig = Some(D,mh,code)";
       
   324 by( case_tac "is_class G C" 1);
       
   325 by(  forw_inst_tac [("C","C")] method_rec 2);
       
   326 by(    asm_full_simp_tac (simpset() addsimps [is_class_def] 
       
   327 	delsimps [not_None_eq]) 2);
       
   328 by (etac subcls1_induct 1);
   307 by (etac subcls1_induct 1);
   329   ba 1;
   308   ba 1;
   330  by (Asm_full_simp_tac 1);
   309  by (Asm_full_simp_tac 1);
   331 by (stac method_rec 1);
   310 by (stac method_rec 1);
   332  ba 1;
   311  ba 1;
   338  by (stac method_rec 1);
   317  by (stac method_rec 1);
   339   ba 1;
   318   ba 1;
   340  by (asm_full_simp_tac (simpset() addsimps [override_def,map_of_map] addsplits [option.split]) 1);
   319  by (asm_full_simp_tac (simpset() addsimps [override_def,map_of_map] addsplits [option.split]) 1);
   341 qed_spec_mp "method_in_md";
   320 qed_spec_mp "method_in_md";
   342 
   321 
   343 
       
   344 Goal "[|is_class G C; wf_prog wf_mb G|] ==> \
   322 Goal "[|is_class G C; wf_prog wf_mb G|] ==> \
   345 \ \\<forall>f\\<in>set (fields (G,C)). is_type G (snd f)";
   323 \ \\<forall>f\\<in>set (fields (G,C)). is_type G (snd f)";
   346 by( etac subcls1_induct 1);
   324 by( etac subcls1_induct 1);
   347 by(   atac 1);
   325 by(   atac 1);
   348 by(  Asm_simp_tac 1);
   326 by(  Asm_simp_tac 1);
   349 by( strip_tac1 1);
       
   350 by( stac fields_rec 1);
   327 by( stac fields_rec 1);
   351 by(   atac 1);
   328 by(   Fast_tac 1);
   352 by(  atac 1);
   329 by(  atac 1);
   353 by( Asm_simp_tac 1);
   330 by( Clarsimp_tac 1);
   354 by( safe_tac set_cs);
   331 by( Safe_tac);
   355 by(  Fast_tac 2);
   332 by(  Force_tac 2);
   356 by( dtac class_wf 1);
   333 by( dtac class_wf 1);
   357 by(  atac 1);
   334 by(  atac 1);
   358 by( rewtac wf_cdecl_def);
   335 by( rewtac wf_cdecl_def);
   359 by( Asm_full_simp_tac 1);
   336 by( Clarsimp_tac 1);
   360 by( strip_tac1 1);
       
   361 by( EVERY[dtac bspec 1, atac 1]);
   337 by( EVERY[dtac bspec 1, atac 1]);
   362 by( rewtac wf_fdecl_def);
   338 by( rewtac wf_fdecl_def);
   363 by( split_all_tac 1);
   339 by Auto_tac;
   364 by( Asm_full_simp_tac 1);
   340 qed_spec_mp "fields_is_type_lemma";
   365 bind_thm ("is_type_fields", result() RS bspec);
   341 
       
   342 Goal "[|map_of (fields (G,C)) fn = Some f; wf_prog wf_mb G; is_class G C|] ==> \
       
   343 \ is_type G f";
       
   344 by(dtac map_of_SomeD 1);
       
   345 by(datac fields_is_type_lemma 2 1);
       
   346 by(Auto_tac);
       
   347 qed "fields_is_type";
       
   348