src/HOL/MicroJava/BV/Correct.ML
author nipkow
Wed, 01 Dec 1999 18:22:28 +0100
changeset 8045 816f566c414f
parent 8032 1eaae1a2f8ff
child 8048 b7f7e18eb584
permissions -rw-r--r--
Fixed a problem with returning from the last frame.

(*  Title:      HOL/MicroJava/BV/Correct.ML
    ID:         $Id$
    Author:     Cornelia Pusch
    Copyright   1999 Technische Universitaet Muenchen
*)

(** sup_heap **)

Goalw [hext_def]
 "hp x = None \\<longrightarrow> hp \\<le>| (hp((newref hp) \\<mapsto> obj))";
by (asm_full_simp_tac (simpset() addsimps []) 1);
by (Clarify_tac 1);
bd newref_None 1;
back();
by (asm_full_simp_tac (simpset() addsimps []) 1);
qed_spec_mp "sup_heap_newref";


Goalw [hext_def]
"hp a = Some (cn,od') \\<longrightarrow> hp \\<le>| (hp(a \\<mapsto> (cn,od)))";
by (asm_full_simp_tac (simpset() addsimps []) 1);
qed_spec_mp "sup_heap_update_value";


(** approx_val **)

Goalw [approx_val_def]
"approx_val G hp x None";
by (Asm_full_simp_tac 1);
qed_spec_mp "approx_val_None";


Goalw [approx_val_def]
"approx_val G hp Null (Some(RefT x))";
by(Simp_tac 1);
by (fast_tac (claset() addIs widen.intrs) 1);
qed_spec_mp "approx_val_Null";


Goal
"\\<lbrakk> wf_prog wt G \\<rbrakk> \
\\\<Longrightarrow> approx_val G hp v (Some T) \\<longrightarrow> G\\<turnstile> T\\<preceq>T' \\<longrightarrow> approx_val G hp v (Some T')";
by (exhaust_tac "T" 1);
 by (Asm_simp_tac 1);
by (fast_tac (claset() addIs [conf_widen] addss (simpset()addsimps[approx_val_def])) 1);
qed_spec_mp "approx_val_imp_approx_val_assConvertible";


Goal
"approx_val G hp val at \\<longrightarrow> hp \\<le>| hp' \\<longrightarrow> approx_val G hp' val at";
by (asm_full_simp_tac (simpset() setloop (split_tac [option.split]) 
	addsimps [approx_val_def]) 1);
by(blast_tac (claset() addIs [conf_hext]) 1);
qed_spec_mp "approx_val_imp_approx_val_sup_heap";

Goal
"\\<lbrakk> hp a = Some obj' ; G,hp\\<turnstile> v\\<Colon>\\<preceq>T ; obj_ty obj = obj_ty obj' \\<rbrakk> \
\\\<Longrightarrow>G,(hp(a\\<mapsto>obj))\\<turnstile> v\\<Colon>\\<preceq>T";
by (exhaust_tac "v" 1);
by (auto_tac (claset() , simpset() addsimps [obj_ty_def,conf_def] addsplits [option.split]));
qed_spec_mp "approx_val_imp_approx_val_heap_update";


Goal
"wf_prog wt G \\<Longrightarrow> approx_val G h val us \\<longrightarrow> G \\<turnstile> us <=o us' \\<longrightarrow> approx_val G h val us'";
by (asm_simp_tac (simpset() addsimps [sup_PTS_eq,approx_val_def] addsplits [option.split,val_.split,ty.split]) 1);
by(blast_tac (claset() addIs [conf_widen]) 1);
qed_spec_mp "approx_val_imp_approx_val_sup";


Goal 
"\\<lbrakk> wf_prog wt G; approx_loc G hp loc LT; idx < length LT ; val = loc ! idx ; G \\<turnstile> LT ! idx <=o at\\<rbrakk> \
\\\<Longrightarrow> approx_val G hp val at";
by (fast_tac (claset() addIs [approx_val_imp_approx_val_sup] addss (simpset() addsimps 
	[split_def,approx_loc_def,all_set_conv_all_nth])) 1);
qed "approx_loc_imp_approx_val_sup";


(** approx_loc **)

Goal 
"approx_loc G hp (s#xs) (l#ls) = \
\   ((length xs = length ls) \\<and> (approx_val G hp s l) \\<and> (approx_loc G hp xs ls))";
by (fast_tac (claset() addss (simpset() addsimps [approx_loc_def])) 1);
qed "approx_loc_Cons";


Goalw [approx_stk_def,approx_loc_def]
"\\<lbrakk> wf_prog wt G \\<rbrakk> \
\\\<Longrightarrow> (\\<forall>tt'\\<in>set (zip tys_n ts). tt' \\<in> widen G) \\<longrightarrow> \
\     length tys_n = length ts \\<longrightarrow> approx_stk G hp s tys_n \\<longrightarrow> approx_loc G hp s (map Some ts)";
by (force_tac (claset() addIs [approx_val_imp_approx_val_assConvertible], simpset() 
	addsimps [all_set_conv_all_nth,split_def]) 1);
qed_spec_mp "assConv_approx_stk_imp_approx_loc";


Goalw [approx_loc_def]
"\\<forall> lvars. approx_loc G hp lvars lt \\<longrightarrow>  hp \\<le>| hp' \\<longrightarrow> approx_loc G hp' lvars lt";
by (exhaust_tac "lt" 1);
 by (Asm_simp_tac 1);
by (force_tac (claset() addIs [approx_val_imp_approx_val_sup_heap],
	       simpset() addsimps [neq_Nil_conv]) 1);
qed_spec_mp "approx_loc_imp_approx_loc_sup_heap";


Goalw [sup_loc_def,approx_loc_def]
"wf_prog wt G \\<Longrightarrow> approx_loc G hp lvars lt \\<longrightarrow> G \\<turnstile> lt <=l lt' \\<longrightarrow> approx_loc G hp lvars lt'";
by (auto_tac (claset() , simpset() addsimps [all_set_conv_all_nth,split_def]));
by (auto_tac (claset() addEs [approx_val_imp_approx_val_sup] , simpset()));
qed_spec_mp "approx_loc_imp_approx_loc_sup";


Goalw  [approx_loc_def]
"\\<forall>loc idx x X. (approx_loc G hp loc LT) \\<longrightarrow> (approx_val G hp x X) \
\ \\<longrightarrow> (approx_loc G hp (loc[idx:=x]) (LT[idx:=X]))";
by (fast_tac (claset() addDs [set_update_subset RS subsetD]
              addss (simpset() addsimps [zip_update])) 1);
qed_spec_mp "approx_loc_imp_approx_loc_subst";


Goal 
"\\<forall>L1 l2 L2. length l1=length L1 \
\ \\<longrightarrow> approx_loc G hp (l1@l2) (L1@L2) = (approx_loc G hp l1 L1 \\<and> approx_loc G hp l2 L2)";
by (induct_tac "l1" 1);
 by (fast_tac (claset() addDs [] addss (simpset() addsimps [approx_loc_def])) 1);
br allI 1;
by (exhaust_tac "L1" 1);
 by (asm_full_simp_tac (simpset() addsimps []) 1);
by (asm_full_simp_tac (simpset() addsimps []) 1);
by (Clarify_tac 1);
by (asm_full_simp_tac (simpset() addsimps [approx_loc_Cons]) 1);
by (case_tac "length l2 = length L2" 1);
 by (asm_full_simp_tac (simpset() addsimps []) 1);
by (asm_full_simp_tac (simpset() addsimps [approx_loc_def]) 1);
qed_spec_mp "approx_loc_append";


(** approx_stk **)

Goalw [approx_stk_def,approx_loc_def]
"approx_stk G hp (rev s) (rev t) = approx_stk G hp s t";
by (fast_tac (claset() addss (simpset() addsimps [zip_rev,rev_map RS sym])) 1);
qed_spec_mp "approx_stk_rev_lem";

Goal 
"approx_stk G hp (rev s) t = approx_stk G hp s (rev t)";
by (fast_tac (claset() addIs [approx_stk_rev_lem RS subst] addss (simpset()))  1);
qed_spec_mp "approx_stk_rev";

Goalw [approx_stk_def]
"\\<forall> lvars. approx_stk G hp lvars lt \\<longrightarrow> hp \\<le>| hp' \\<longrightarrow> approx_stk G hp' lvars lt";
by (fast_tac (claset() addIs [approx_loc_imp_approx_loc_sup_heap])  1);
qed_spec_mp "approx_stk_imp_approx_stk_sup_heap";


Goalw [approx_stk_def]
"wf_prog wt G \\<Longrightarrow> approx_stk G hp lvars st \\<longrightarrow> G \\<turnstile> (map Some st) <=l (map Some st') \\<longrightarrow> approx_stk G hp lvars st'";
by (fast_tac (claset() addIs [approx_loc_imp_approx_loc_sup])  1);
qed_spec_mp "approx_stk_imp_approx_stk_sup";

Goalw [approx_stk_def,approx_loc_def]
"approx_stk G hp [] []";
by (asm_full_simp_tac (simpset() addsimps []) 1);
qed "approx_stk_Nil";


Goalw [approx_stk_def,approx_loc_def]
"approx_stk G hp (x # stk) (S#ST) = (approx_stk G hp stk ST \\<and> approx_val G hp x (Some S))";
by (fast_tac (claset() addss (simpset())) 1);
qed "approx_stk_Cons";

Goal 
"\\<lbrakk> approx_stk G hp stk (S#ST') \\<rbrakk> \
\ \\<Longrightarrow> \\<exists>s stk'. stk = s#stk' \\<and> approx_stk G hp stk' ST' \\<and> approx_val G hp s (Some S)";
by (exhaust_tac "stk" 1);
 by (fast_tac (claset() addss (simpset() addsimps [approx_stk_def,approx_loc_def])) 1);
by (fast_tac (claset() addss (simpset() addsimps [approx_stk_Cons])) 1);
qed "approx_stk_Cons_lemma";

Goal 
"\\<forall>ST' stk. approx_stk G hp stk (S@ST')   \
\ \\<longrightarrow> (\\<exists>s stk'. stk = s@stk' \\<and> length s = length S \\<and> length stk' = length ST' \\<and> \
\             approx_stk G hp s S \\<and> approx_stk G hp stk' ST')";
by (induct_tac "S" 1);
 by (fast_tac (claset() addDs [] addss (simpset() addsimps [approx_stk_def,approx_loc_def])) 1);
by (Clarify_tac 1);
by (asm_full_simp_tac (simpset() addsimps []) 1);
bd approx_stk_Cons_lemma 1;
by (Clarify_tac 1);
by (eres_inst_tac [("x","ST'")] allE 1);
by (eres_inst_tac [("x","stk'")] allE 1);
by (Clarify_tac 1);
by (res_inst_tac [("x","s#sa")] exI 1);
by (res_inst_tac [("x","stk'a")] exI 1);
by (asm_full_simp_tac (simpset() addsimps [approx_stk_Cons]) 1);
qed_spec_mp "approx_stk_append_lemma";


(** oconf **)

Goalw [oconf_def,lconf_def]
"\\<lbrakk> is_class G C; wf_prog wt G \\<rbrakk> \\<Longrightarrow> \
\G,h\\<turnstile> (C, map_of (map (\\<lambda>(f,fT).(f,default_val fT)) (fields(G,C))))\\<surd>";
by (asm_full_simp_tac (simpset() addsimps [map_of_map]) 1);
by (force_tac (claset() addIs [defval_conf]
                        addDs [map_of_SomeD,is_type_fields],simpset()) 1);
qed "correct_init_obj";


Goalw [oconf_def,lconf_def]
"\\<lbrakk> map_of (fields (G, oT)) FD = Some T ; G,hp\\<turnstile>v\\<Colon>\\<preceq>T ; \
\   G,hp\\<turnstile>(oT,fs)\\<surd> \\<rbrakk>  \
\\\<Longrightarrow> G,hp\\<turnstile>(oT, fs(FD\\<mapsto>v))\\<surd>";
by (asm_full_simp_tac (simpset() addsplits [ty.split]) 1);
qed_spec_mp "oconf_imp_oconf_field_update";


Goalw [oconf_def,lconf_def]
"hp x = None \\<longrightarrow> G,hp\\<turnstile>obj\\<surd>  \\<longrightarrow>  G,hp\\<turnstile>obj'\\<surd> \
\  \\<longrightarrow> G,(hp(newref hp\\<mapsto>obj'))\\<turnstile>obj\\<surd>";
by (Asm_full_simp_tac 1);
by (fast_tac (claset() addIs [conf_hext,sup_heap_newref]) 1);
qed_spec_mp "oconf_imp_oconf_heap_newref";

Goalw [oconf_def,lconf_def]
"hp a = Some obj'  \\<longrightarrow> obj_ty obj' = obj_ty obj'' \\<longrightarrow> G,hp\\<turnstile>obj\\<surd> \
\  \\<longrightarrow> G,hp(a\\<mapsto>obj'')\\<turnstile>obj\\<surd>";
by (Asm_full_simp_tac 1);
by (fast_tac (claset() addIs [approx_val_imp_approx_val_heap_update] addss (simpset())) 1);
qed_spec_mp "oconf_imp_oconf_heap_update";


(** hconf **)


Goal "hp x = None \\<longrightarrow> G\\<turnstile>h hp\\<surd> \\<longrightarrow> G,hp\\<turnstile>obj\\<surd> \\<longrightarrow> G\\<turnstile>h hp(newref hp\\<mapsto>obj)\\<surd>";
by (asm_full_simp_tac (simpset() addsplits [split_split] 
				 addsimps [hconf_def]) 1);
 by (fast_tac (claset()addIs[oconf_imp_oconf_heap_newref] addss (simpset())) 1);
qed_spec_mp "hconf_imp_hconf_newref";


Goal "map_of (fields (G, oT)) (F, D) = Some T \\<and> hp oloc = Some(oT,fs) \\<and> \
\ G,hp\\<turnstile>v\\<Colon>\\<preceq>T \\<and> G\\<turnstile>h hp\\<surd> \\<longrightarrow> G\\<turnstile>h hp(oloc \\<mapsto> (oT, fs((F,D)\\<mapsto>v)))\\<surd>";
by (asm_full_simp_tac (simpset() addsimps [hconf_def]) 1);
by (fast_tac (claset() addIs 
        [oconf_imp_oconf_heap_update, oconf_imp_oconf_field_update]
        addss (simpset() addsimps [obj_ty_def])) 1);
qed_spec_mp "hconf_imp_hconf_field_update";


(** correct_frames **)

Delsimps [fun_upd_apply]; 
Goal
"\\<forall>rT C sig. correct_frames G hp phi rT sig frs \\<longrightarrow> \
\    hp a = Some (cn,od) \\<longrightarrow> map_of (fields (G, cn)) fl = Some fd \\<longrightarrow> \
\    G,hp\\<turnstile>v\\<Colon>\\<preceq>fd \
\ \\<longrightarrow> correct_frames G (hp(a \\<mapsto> (cn, od(fl\\<mapsto>v)))) phi rT sig frs";
by (induct_tac "frs" 1);
 by (Asm_full_simp_tac 1);
by (asm_full_simp_tac (simpset() addsimps [split_def,correct_frame_def]) 1);
by (fast_tac (claset() addIs [approx_stk_imp_approx_stk_sup_heap,
				approx_loc_imp_approx_loc_sup_heap,
				sup_heap_update_value] addss (simpset())) 1);
qed_spec_mp "correct_frames_imp_correct_frames_field_update";


Goal
"\\<forall>rT C sig. hp x = None \\<longrightarrow> correct_frames G hp phi rT sig frs \\<and> \
\    oconf G hp obj \
\ \\<longrightarrow> correct_frames G (hp(newref hp \\<mapsto> obj)) phi rT sig frs";
by (induct_tac "frs" 1);
by  (asm_full_simp_tac (simpset() addsimps []) 1);
by (asm_full_simp_tac (simpset() addsimps [split_def,correct_frame_def]) 1);
by (fast_tac (claset() addIs [approx_stk_imp_approx_stk_sup_heap,
				approx_loc_imp_approx_loc_sup_heap,
				hconf_imp_hconf_newref,
				sup_heap_newref] addss (simpset())) 1);
qed_spec_mp "correct_frames_imp_correct_frames_newref";