src/HOL/Imperative_HOL/Relational.thy
changeset 37725 6d28a2aea936
parent 37719 271ecd4fb9f9
child 37755 7086b7feaaa5
equal deleted inserted replaced
37724:6607ccf77946 37725:6d28a2aea936
   309 extends h' h x \<Longrightarrow> ref_present y h \<Longrightarrow> ref_present y h'
   309 extends h' h x \<Longrightarrow> ref_present y h \<Longrightarrow> ref_present y h'
   310 extends h' h x \<Longrightarrow> ref_present y h \<Longrightarrow> get_ref y h = get_ref y h'
   310 extends h' h x \<Longrightarrow> ref_present y h \<Longrightarrow> get_ref y h = get_ref y h'
   311 extends h' h x \<Longrightarrow> lim h' = Suc (lim h)
   311 extends h' h x \<Longrightarrow> lim h' = Suc (lim h)
   312 *)
   312 *)
   313 
   313 
   314 lemma crel_Ref_new:
   314 lemma crel_ref:
   315   assumes "crel (Ref.new v) h h' x"
   315   assumes "crel (ref v) h h' x"
   316   obtains "get_ref x h' = v"
   316   obtains "Ref.get h' x = v"
   317   and "\<not> ref_present x h"
   317   and "\<not> Ref.present h x"
   318   and "ref_present x h'"
   318   and "Ref.present h' x"
   319   and "\<forall>y. ref_present y h \<longrightarrow> get_ref y h = get_ref y h'"
   319   and "\<forall>y. Ref.present h y \<longrightarrow> Ref.get h y = Ref.get h' y"
   320  (* and "lim h' = Suc (lim h)" *)
   320  (* and "lim h' = Suc (lim h)" *)
   321   and "\<forall>y. ref_present y h \<longrightarrow> ref_present y h'"
   321   and "\<forall>y. Ref.present h y \<longrightarrow> Ref.present h' y"
   322   using assms
   322   using assms
   323   unfolding Ref.new_def
   323   unfolding Ref.ref_def
   324   apply (elim crel_heap)
   324   apply (elim crel_heap)
   325   unfolding Ref.ref_def
   325   unfolding Ref.alloc_def
   326   apply (simp add: Let_def)
   326   apply (simp add: Let_def)
   327   unfolding ref_present_def
   327   unfolding Ref.present_def
   328   apply auto
   328   apply auto
   329   unfolding get_ref_def set_ref_def
   329   unfolding Ref.get_def Ref.set_def
   330   apply auto
   330   apply auto
   331   done
   331   done
   332 
   332 
   333 lemma crel_lookup:
   333 lemma crel_lookup:
   334   assumes "crel (!r') h h' r"
   334   assumes "crel (!r') h h' r"
   335   obtains "h = h'" "r = get_ref r' h"
   335   obtains "h = h'" "r = Ref.get h r'"
   336 using assms
   336 using assms
   337 unfolding Ref.lookup_def
   337 unfolding Ref.lookup_def
   338 by (auto elim: crel_heap)
   338 by (auto elim: crel_heap)
   339 
   339 
   340 lemma crel_update:
   340 lemma crel_update:
   341   assumes "crel (r' := v) h h' r"
   341   assumes "crel (r' := v) h h' r"
   342   obtains "h' = set_ref r' v h" "r = ()"
   342   obtains "h' = Ref.set r' v h" "r = ()"
   343 using assms
   343 using assms
   344 unfolding Ref.update_def
   344 unfolding Ref.update_def
   345 by (auto elim: crel_heap)
   345 by (auto elim: crel_heap)
   346 
   346 
   347 lemma crel_change:
   347 lemma crel_change:
   348   assumes "crel (Ref.change f r') h h' r"
   348   assumes "crel (Ref.change f r') h h' r"
   349   obtains "h' = set_ref r' (f (get_ref r' h)) h" "r = f (get_ref r' h)"
   349   obtains "h' = Ref.set r' (f (Ref.get h r')) h" "r = f (Ref.get h r')"
   350 using assms
   350 using assms
   351 unfolding Ref.change_def Let_def
   351 unfolding Ref.change_def Let_def
   352 by (auto elim!: crelE crel_lookup crel_update crel_return)
   352 by (auto elim!: crelE crel_lookup crel_update crel_return)
   353 
   353 
   354 subsection {* Elimination rules for the assert command *}
   354 subsection {* Elimination rules for the assert command *}
   465 (* thm crel_mapI is missing *)
   465 (* thm crel_mapI is missing *)
   466 
   466 
   467 subsubsection {* Introduction rules for reference commands *}
   467 subsubsection {* Introduction rules for reference commands *}
   468 
   468 
   469 lemma crel_lookupI:
   469 lemma crel_lookupI:
   470   shows "crel (!r) h h (get_ref r h)"
   470   shows "crel (!r) h h (Ref.get h r)"
   471   unfolding lookup_def by (auto intro!: crel_heapI')
   471   unfolding lookup_def by (auto intro!: crel_heapI')
   472 
   472 
   473 lemma crel_updateI:
   473 lemma crel_updateI:
   474   shows "crel (r := v) h (set_ref r v h) ()"
   474   shows "crel (r := v) h (Ref.set r v h) ()"
   475   unfolding update_def by (auto intro!: crel_heapI')
   475   unfolding update_def by (auto intro!: crel_heapI')
   476 
   476 
   477 lemma crel_changeI: 
   477 lemma crel_changeI: 
   478   shows "crel (Ref.change f r) h (set_ref r (f (get_ref r h)) h) (f (get_ref r h))"
   478   shows "crel (Ref.change f r) h (Ref.set r (f (Ref.get h r)) h) (f (Ref.get h r))"
   479 unfolding change_def Let_def by (auto intro!: crelI crel_returnI crel_lookupI crel_updateI)
   479 unfolding change_def Let_def by (auto intro!: crelI crel_returnI crel_lookupI crel_updateI)
   480 
   480 
   481 subsubsection {* Introduction rules for the assert command *}
   481 subsubsection {* Introduction rules for the assert command *}
   482 
   482 
   483 lemma crel_assertI:
   483 lemma crel_assertI:
   665 by (auto intro: noErrorI noError_length noError_return elim!: crel_length)
   665 by (auto intro: noErrorI noError_length noError_return elim!: crel_length)
   666 
   666 
   667 subsection {* Introduction rules for the reference commands *}
   667 subsection {* Introduction rules for the reference commands *}
   668 
   668 
   669 lemma noError_Ref_new:
   669 lemma noError_Ref_new:
   670   shows "noError (Ref.new v) h"
   670   shows "noError (ref v) h"
   671 unfolding Ref.new_def by (intro noError_heap)
   671   unfolding Ref.ref_def by (intro noError_heap)
   672 
   672 
   673 lemma noError_lookup:
   673 lemma noError_lookup:
   674   shows "noError (!r) h"
   674   shows "noError (!r) h"
   675   unfolding lookup_def by (intro noError_heap)
   675   unfolding lookup_def by (intro noError_heap)
   676 
   676 
   694 section {* Cumulative lemmas *}
   694 section {* Cumulative lemmas *}
   695 
   695 
   696 lemmas crel_elim_all =
   696 lemmas crel_elim_all =
   697   crelE crelE' crel_return crel_raise crel_if crel_option_case
   697   crelE crelE' crel_return crel_raise crel_if crel_option_case
   698   crel_length crel_new_weak crel_nth crel_upd crel_of_list_weak crel_map_entry crel_swap crel_make_weak crel_freeze crel_map_weak
   698   crel_length crel_new_weak crel_nth crel_upd crel_of_list_weak crel_map_entry crel_swap crel_make_weak crel_freeze crel_map_weak
   699   crel_Ref_new crel_lookup crel_update crel_change
   699   crel_ref crel_lookup crel_update crel_change
   700   crel_assert
   700   crel_assert
   701 
   701 
   702 lemmas crel_intro_all =
   702 lemmas crel_intro_all =
   703   crelI crelI' crel_returnI crel_raiseI crel_ifI crel_option_caseI
   703   crelI crelI' crel_returnI crel_raiseI crel_ifI crel_option_caseI
   704   crel_lengthI (* crel_newI *) crel_nthI crel_updI (* crel_of_listI crel_map_entryI crel_swapI crel_makeI crel_freezeI crel_mapI *)
   704   crel_lengthI (* crel_newI *) crel_nthI crel_updI (* crel_of_listI crel_map_entryI crel_swapI crel_makeI crel_freezeI crel_mapI *)