Datasets:
AI4M
/

text
stringlengths
0
3.34M
[STATEMENT] lemma tan_of_real: "of_real (tan x) = (tan (of_real x) :: 'a::{real_normed_field,banach})" [PROOF STATE] proof (prove) goal (1 subgoal): 1. of_real (tan x) = tan (of_real x) [PROOF STEP] by (simp add: tan_def sin_of_real cos_of_real)
(* Title: statecharts/Examples/CarAudioSystem.thy Author: Steffen Helke and Florian Kammüller, Software Engineering Group Copyright 2010 Technische Universitaet Berlin *) header {* Example Specification for a Car Audio System *} theory CarAudioSystem imports "HAKripke" "HAOps" begin subsection {* Definitions *} subsubsection {* Data space for two Integer-Variables *} datatype d = V0 int | V1 int primrec Sel0 :: "d => int" where "Sel0 (V0 i) = i" primrec Sel1 :: "d => int" where "Sel1 (V1 i) = i" (* Selectors for the two Integer-Variables *) definition Select0 :: "[d data] => int" where "Select0 d = Sel0 (DataPart d 0)" definition Select1 :: "[d data] => int" where "Select1 d = Sel1 (DataPart d 1)" (* Data Space for tthe two Integer-Variables *) definition DSpace :: "d dataspace" where "DSpace = Abs_dataspace ([range V0, range V1])" (* Lift in InitData *) definition LiftInitData :: "(d list) => d data" where "LiftInitData L = Abs_data (L,DSpace)" (* Lift in PUpdate-Function *) definition LiftPUpdate :: "(d data => ((d option) list)) => d pupdate" where "LiftPUpdate L = Abs_pupdate (\<lambda> d. if ((DataSpace d) = DSpace) then Abs_pdata (L d, DSpace) else (Data2PData d))" subsubsection {* Sequential Automaton @{text "Root_CTRL"} *} definition Root_CTRL_States :: "string set" where "Root_CTRL_States = {''CarAudioSystem''}" definition Root_CTRL_Init :: "string" where "Root_CTRL_Init = ''CarAudioSystem''" definition Root_CTRL_Labels :: "(string,string,d)label set" where "Root_CTRL_Labels = {}" definition Root_CTRL_Delta :: "(string,string,d)trans set" where "Root_CTRL_Delta = {}" definition Root_CTRL :: "(string,string,d)seqauto" where "Root_CTRL = Abs_seqauto (Root_CTRL_States, Root_CTRL_Init, Root_CTRL_Labels, Root_CTRL_Delta)" subsubsection {* Sequential Automaton @{text "CDPlayer_CTRL"} *} definition CDPlayer_CTRL_States :: "string set" where "CDPlayer_CTRL_States = {''ReadTracks'',''CDFull'',''CDEmpty''}" definition CDPlayer_CTRL_Init :: "string" where "CDPlayer_CTRL_Init = ''CDEmpty''" definition CDPlayer_CTRL_Update1 :: "d pupdate" where "CDPlayer_CTRL_Update1 = LiftPUpdate (% d. [None, Some (V1 ((Select0 d) + 1))])" definition CDPlayer_CTRL_Action1 :: "(string,d)action" where "CDPlayer_CTRL_Action1 = ({},CDPlayer_CTRL_Update1)" definition CDPlayer_CTRL_Update2 :: "d pupdate" where "CDPlayer_CTRL_Update2 = LiftPUpdate (% d. [Some (V0 ((Select0 d) + 1)), None])" definition CDPlayer_CTRL_Action2 :: "(string,d)action" where "CDPlayer_CTRL_Action2 = ({},CDPlayer_CTRL_Update2)" definition CDPlayer_CTRL_Update3 :: "d pupdate" where "CDPlayer_CTRL_Update3 = LiftPUpdate (% d. [Some (V0 0), None])" definition CDPlayer_CTRL_Action3 :: "(string,d)action" where "CDPlayer_CTRL_Action3 = ({},CDPlayer_CTRL_Update3)" definition CDPlayer_CTRL_Labels :: "(string,string,d)label set" where "CDPlayer_CTRL_Labels = {(En ''LastTrack'', defaultguard, CDPlayer_CTRL_Action1), (En ''NewTrack'', defaultguard, CDPlayer_CTRL_Action2), (And (En ''CDEject'') (In ''On''), defaultguard, CDPlayer_CTRL_Action3), (En ''CDIn'', defaultguard, defaultaction)}" definition CDPlayer_CTRL_Delta :: "(string,string,d)trans set" where "CDPlayer_CTRL_Delta = {(''ReadTracks'',(En ''LastTrack'', defaultguard, CDPlayer_CTRL_Action1), ''CDFull''), (''CDFull'',(And (En ''CDEject'') (In ''On''), defaultguard, CDPlayer_CTRL_Action3), ''CDEmpty''), (''ReadTracks'',(En ''NewTrack'', defaultguard, CDPlayer_CTRL_Action2), ''ReadTracks''), (''CDEmpty'',(En ''CDIn'', defaultguard, defaultaction), ''ReadTracks'')}" definition CDPlayer_CTRL :: "(string,string,d)seqauto" where "CDPlayer_CTRL = Abs_seqauto (CDPlayer_CTRL_States, CDPlayer_CTRL_Init, CDPlayer_CTRL_Labels, CDPlayer_CTRL_Delta)" subsubsection {* Sequential Automaton @{text "AudioPlayer_CTRL"} *} definition AudioPlayer_CTRL_States :: "string set" where "AudioPlayer_CTRL_States = {''Off'',''On''}" definition AudioPlayer_CTRL_Init :: "string" where "AudioPlayer_CTRL_Init = ''Off''" definition AudioPlayer_CTRL_Labels :: "(string,string,d)label set" where "AudioPlayer_CTRL_Labels = {(En ''O'', defaultguard, defaultaction)}" definition AudioPlayer_CTRL_Delta :: "(string,string,d)trans set" where "AudioPlayer_CTRL_Delta = {(''Off'', (En ''O'', defaultguard, defaultaction), ''On''), (''On'', (En ''O'', defaultguard, defaultaction), ''Off'')}" definition AudioPlayer_CTRL :: "(string,string,d)seqauto" where "AudioPlayer_CTRL = Abs_seqauto (AudioPlayer_CTRL_States, AudioPlayer_CTRL_Init, AudioPlayer_CTRL_Labels, AudioPlayer_CTRL_Delta)" subsubsection {* Sequential Automaton @{text "On_CTRL"} *} definition On_CTRL_States :: "string set" where "On_CTRL_States = {''TunerMode'',''CDMode''}" definition On_CTRL_Init :: "string" where "On_CTRL_Init = ''TunerMode''" definition On_CTRL_Labels :: "(string,string,d)label set" where "On_CTRL_Labels = {(And (En ''Src'') (In ''CDFull''), defaultguard, defaultaction), (En ''Src'', defaultguard, defaultaction), (En ''CDEject'', defaultguard, defaultaction), (En ''EndOfTitle'', (\<lambda> d. (DataPart d 0) = (DataPart d 1)), defaultaction)}" definition On_CTRL_Delta :: "(string,string,d)trans set" where "On_CTRL_Delta = {(''TunerMode'',(And (En ''Src'') (In ''CDFull''), defaultguard, defaultaction),''CDMode''), (''CDMode'', (En ''Src'', defaultguard, defaultaction), ''TunerMode''), (''CDMode'', (En ''CDEject'', defaultguard, defaultaction), ''TunerMode''), (''CDMode'', (En ''EndOfTitle'', (\<lambda> d. (DataPart d 0) = (DataPart d 1)), defaultaction), ''TunerMode'')}" definition On_CTRL :: "(string,string,d)seqauto" where "On_CTRL = Abs_seqauto (On_CTRL_States, On_CTRL_Init, On_CTRL_Labels, On_CTRL_Delta)" subsubsection {* Sequential Automaton @{text "TunerMode_CTRL"} *} definition TunerMode_CTRL_States :: "string set" where "TunerMode_CTRL_States = {''1'',''2'',''3'',''4''}" definition TunerMode_CTRL_Init :: "string" where "TunerMode_CTRL_Init = ''1''" definition TunerMode_CTRL_Labels :: "(string,string,d)label set" where "TunerMode_CTRL_Labels = {(En ''Next'', defaultguard, defaultaction), (En ''Back'', defaultguard, defaultaction)}" definition TunerMode_CTRL_Delta :: "(string,string,d)trans set" where "TunerMode_CTRL_Delta = {(''1'', (En ''Next'', defaultguard, defaultaction), ''2''), (''2'', (En ''Next'', defaultguard, defaultaction), ''3''), (''3'', (En ''Next'', defaultguard, defaultaction), ''4''), (''4'', (En ''Next'', defaultguard, defaultaction), ''1''), (''1'', (En ''Back'', defaultguard, defaultaction), ''4''), (''4'', (En ''Back'', defaultguard, defaultaction), ''3''), (''3'', (En ''Back'', defaultguard, defaultaction), ''2''), (''2'', (En ''Back'', defaultguard, defaultaction), ''1'')}" definition TunerMode_CTRL :: "(string,string,d)seqauto" where "TunerMode_CTRL = Abs_seqauto (TunerMode_CTRL_States, TunerMode_CTRL_Init, TunerMode_CTRL_Labels, TunerMode_CTRL_Delta)" subsubsection {* Sequential Automaton @{text "CDMode_CTRL"} *} definition CDMode_CTRL_States :: "string set" where "CDMode_CTRL_States = {''Playing'',''SelectingNextTrack'', ''SelectingPreviousTrack''}" definition CDMode_CTRL_Init :: "string" where "CDMode_CTRL_Init = ''Playing''" definition CDMode_CTRL_Update1 :: "d pupdate" where "CDMode_CTRL_Update1 = LiftPUpdate (% d. [ Some (V0 ((Select0 d) + 1)), None ])" definition CDMode_CTRL_Action1 :: "(string,d)action" where "CDMode_CTRL_Action1 = ({},CDMode_CTRL_Update1)" definition CDMode_CTRL_Update2 :: "d pupdate" where "CDMode_CTRL_Update2 = LiftPUpdate (% d. [ Some (V0 ((Select0 d) - 1)), None ])" definition CDMode_CTRL_Action2 :: "(string,d)action" where "CDMode_CTRL_Action2 = ({},CDMode_CTRL_Update2)" definition CDMode_CTRL_Labels :: "(string,string,d)label set" where "CDMode_CTRL_Labels = {(En ''Next'', defaultguard, defaultaction), (En ''Back'', defaultguard, defaultaction), (En ''Ready'', defaultguard, CDMode_CTRL_Action1), (En ''Ready'', defaultguard, CDMode_CTRL_Action2), (En ''EndOfTitle'',(\<lambda> (d:: d data). (Select0 d) < (Select1 d)), defaultaction)}" definition CDMode_CTRL_Delta :: "(string,string,d)trans set" where "CDMode_CTRL_Delta = {(''Playing'', (En ''Next'', defaultguard, defaultaction) , ''SelectingNextTrack''), (''SelectingNextTrack'', (En ''Ready'', defaultguard, CDMode_CTRL_Action1) ,''Playing''), (''Playing'', (En ''Back'', defaultguard, defaultaction) ,''SelectingPreviousTrack''), (''SelectingPreviousTrack'', (En ''Ready'', defaultguard, CDMode_CTRL_Action2), ''Playing''), (''Playing'', (En ''EndOfTitle'', (\<lambda> (d:: d data). (Select0 d) < (Select1 d)), defaultaction), ''SelectingNextTrack'')}" definition CDMode_CTRL :: "(string,string,d)seqauto" where "CDMode_CTRL = Abs_seqauto (CDMode_CTRL_States, CDMode_CTRL_Init, CDMode_CTRL_Labels, CDMode_CTRL_Delta)" subsubsection {* Hierarchical Automaton @{text "CarAudioSystem"} *} definition CarAudioSystem :: "(string,string,d)hierauto" where "CarAudioSystem = ((PseudoHA Root_CTRL (LiftInitData [V0 0, V1 0])) [++] (''CarAudioSystem'',CDPlayer_CTRL) [++] (''CarAudioSystem'',AudioPlayer_CTRL) [++] (''On'', TunerMode_CTRL) [++] (''On'', CDMode_CTRL))" subsection {* Lemmas *} subsubsection {* Sequential Automaton @{text "CDMode_CTRL"} *} lemma check_Root_CTRL: "(Root_CTRL_States,Root_CTRL_Init,Root_CTRL_Labels,Root_CTRL_Delta) : seqauto" apply (unfold seqauto_def SeqAuto_def Root_CTRL_States_def Root_CTRL_Init_def Root_CTRL_Labels_def Root_CTRL_Delta_def) apply simp done lemma States_Root_CTRL: "States Root_CTRL = Root_CTRL_States"; apply (simp add: Root_CTRL_def) apply (unfold States_def) apply (simp add: Abs_seqauto_inverse check_Root_CTRL) done lemma Init_State_Root_CTRL: "InitState Root_CTRL = Root_CTRL_Init"; apply (simp add: Root_CTRL_def) apply (unfold InitState_def) apply (simp add: Abs_seqauto_inverse check_Root_CTRL) done lemma Labels_Root_CTRL: "Labels Root_CTRL = Root_CTRL_Labels"; apply (simp add: Root_CTRL_def) apply (unfold Labels_def) apply (simp add: Abs_seqauto_inverse check_Root_CTRL) done lemma Delta_Root_CTRL: "Delta Root_CTRL = Root_CTRL_Delta"; apply (simp add: Root_CTRL_def) apply (unfold Delta_def) apply (simp add: Abs_seqauto_inverse check_Root_CTRL) done schematic_lemma Events_Root_CTRL: "SAEvents Root_CTRL = ?X" apply (unfold SAEvents_def expr_def) apply (rule trans) apply (simp add: expr_def Delta_Root_CTRL Root_CTRL_Delta_def) apply (rule refl) done subsubsection {* Sequential Automaton @{text "CDPlayer_CTRL"} *} lemma check_CDPlayer_CTRL: "(CDPlayer_CTRL_States,CDPlayer_CTRL_Init,CDPlayer_CTRL_Labels,CDPlayer_CTRL_Delta) : seqauto" apply (unfold seqauto_def SeqAuto_def CDPlayer_CTRL_States_def CDPlayer_CTRL_Init_def CDPlayer_CTRL_Labels_def CDPlayer_CTRL_Delta_def) apply simp done lemma States_CDPlayer_CTRL: "States CDPlayer_CTRL = CDPlayer_CTRL_States"; apply (simp add: CDPlayer_CTRL_def) apply (unfold States_def) apply (simp add: Abs_seqauto_inverse check_CDPlayer_CTRL) done lemma Init_State_CDPlayer_CTRL: "InitState CDPlayer_CTRL = CDPlayer_CTRL_Init"; apply (simp add: CDPlayer_CTRL_def) apply (unfold InitState_def) apply (simp add: Abs_seqauto_inverse check_CDPlayer_CTRL) done lemma Labels_CDPlayer_CTRL: "Labels CDPlayer_CTRL = CDPlayer_CTRL_Labels"; apply (simp add: CDPlayer_CTRL_def) apply (unfold Labels_def) apply (simp add: Abs_seqauto_inverse check_CDPlayer_CTRL) done lemma Delta_CDPlayer_CTRL: "Delta CDPlayer_CTRL = CDPlayer_CTRL_Delta"; apply (simp add: CDPlayer_CTRL_def) apply (unfold Delta_def) apply (simp add: Abs_seqauto_inverse check_CDPlayer_CTRL) done schematic_lemma Events_CDPlayer_CTRL: "SAEvents CDPlayer_CTRL = ?X" apply (unfold SAEvents_def) apply (rule trans) apply (simp add: expr_def Delta_CDPlayer_CTRL CDPlayer_CTRL_Delta_def CDPlayer_CTRL_Action1_def CDPlayer_CTRL_Action2_def CDPlayer_CTRL_Action3_def Label_def) apply (rule refl) done subsubsection {* Sequential Automaton @{text "AudioPlayer_CTRL"} *} lemma check_AudioPlayer_CTRL: "(AudioPlayer_CTRL_States,AudioPlayer_CTRL_Init,AudioPlayer_CTRL_Labels,AudioPlayer_CTRL_Delta) : seqauto" apply (unfold seqauto_def SeqAuto_def AudioPlayer_CTRL_States_def AudioPlayer_CTRL_Init_def AudioPlayer_CTRL_Labels_def AudioPlayer_CTRL_Delta_def) apply simp done lemma States_AudioPlayer_CTRL: "States AudioPlayer_CTRL = AudioPlayer_CTRL_States"; apply (simp add: AudioPlayer_CTRL_def) apply (unfold States_def) apply (simp add: Abs_seqauto_inverse check_AudioPlayer_CTRL) done lemma Init_State_AudioPlayer_CTRL: "InitState AudioPlayer_CTRL = AudioPlayer_CTRL_Init"; apply (simp add: AudioPlayer_CTRL_def) apply (unfold InitState_def) apply (simp add: Abs_seqauto_inverse check_AudioPlayer_CTRL) done lemma Labels_AudioPlayer_CTRL: "Labels AudioPlayer_CTRL = AudioPlayer_CTRL_Labels"; apply (simp add: AudioPlayer_CTRL_def) apply (unfold Labels_def) apply (simp add: Abs_seqauto_inverse check_AudioPlayer_CTRL) done lemma Delta_AudioPlayer_CTRL: "Delta AudioPlayer_CTRL = AudioPlayer_CTRL_Delta"; apply (simp add: AudioPlayer_CTRL_def) apply (unfold Delta_def) apply (simp add: Abs_seqauto_inverse check_AudioPlayer_CTRL) done schematic_lemma Events_AudioPlayer_CTRL: "SAEvents AudioPlayer_CTRL = ?X" apply (unfold SAEvents_def) apply (rule trans) apply (simp add: expr_def Delta_AudioPlayer_CTRL AudioPlayer_CTRL_Delta_def Label_def) apply (rule refl) done subsubsection {* Sequential Automaton @{text "On_CTRL"} *} lemma check_On_CTRL: "(On_CTRL_States,On_CTRL_Init,On_CTRL_Labels,On_CTRL_Delta) : seqauto" apply (unfold seqauto_def SeqAuto_def On_CTRL_States_def On_CTRL_Init_def On_CTRL_Labels_def On_CTRL_Delta_def) apply simp done lemma States_On_CTRL: "States On_CTRL = On_CTRL_States"; apply (simp add: On_CTRL_def) apply (unfold States_def) apply (simp add: Abs_seqauto_inverse check_On_CTRL) done lemma Init_State_On_CTRL: "InitState On_CTRL = On_CTRL_Init"; apply (simp add: On_CTRL_def) apply (unfold InitState_def) apply (simp add: Abs_seqauto_inverse check_On_CTRL) done lemma Labels_On_CTRL: "Labels On_CTRL = On_CTRL_Labels"; apply (simp add: On_CTRL_def) apply (unfold Labels_def) apply (simp add: Abs_seqauto_inverse check_On_CTRL) done lemma Delta_On_CTRL: "Delta On_CTRL = On_CTRL_Delta"; apply (simp add: On_CTRL_def) apply (unfold Delta_def) apply (simp add: Abs_seqauto_inverse check_On_CTRL) done schematic_lemma Events_On_CTRL: "SAEvents On_CTRL = ?X" apply (unfold SAEvents_def) apply (rule trans) apply (simp add: expr_def Delta_On_CTRL On_CTRL_Delta_def Label_def) apply (rule refl) done subsubsection {* Sequential Automaton @{text "TunerMode_CTRL"} *} lemma check_TunerMode_CTRL: "(TunerMode_CTRL_States,TunerMode_CTRL_Init,TunerMode_CTRL_Labels,TunerMode_CTRL_Delta) : seqauto" apply (unfold seqauto_def SeqAuto_def TunerMode_CTRL_States_def TunerMode_CTRL_Init_def TunerMode_CTRL_Labels_def TunerMode_CTRL_Delta_def) apply simp done lemma States_TunerMode_CTRL: "States TunerMode_CTRL = TunerMode_CTRL_States"; apply (simp add: TunerMode_CTRL_def) apply (unfold States_def) apply (simp add: Abs_seqauto_inverse check_TunerMode_CTRL) done lemma Init_State_TunerMode_CTRL: "InitState TunerMode_CTRL = TunerMode_CTRL_Init"; apply (simp add: TunerMode_CTRL_def) apply (unfold InitState_def) apply (simp add: Abs_seqauto_inverse check_TunerMode_CTRL) done lemma Delta_TunerMode_CTRL: "Delta TunerMode_CTRL = TunerMode_CTRL_Delta"; apply (simp add: TunerMode_CTRL_def) apply (unfold Delta_def) apply (simp add: Abs_seqauto_inverse check_TunerMode_CTRL) done schematic_lemma Events_TunerMode_CTRL: "SAEvents TunerMode_CTRL = ?X" apply (unfold SAEvents_def) apply (rule trans) apply (simp add: expr_def Delta_TunerMode_CTRL TunerMode_CTRL_Delta_def Label_def) apply (rule refl) done subsubsection {* Sequential Automaton @{text "CDMode_CTRL"} *} lemma check_CDMode_CTRL: "(CDMode_CTRL_States,CDMode_CTRL_Init,CDMode_CTRL_Labels,CDMode_CTRL_Delta) : seqauto" apply (unfold seqauto_def SeqAuto_def CDMode_CTRL_States_def CDMode_CTRL_Init_def CDMode_CTRL_Labels_def CDMode_CTRL_Delta_def) apply simp done lemma States_CDMode_CTRL: "States CDMode_CTRL = CDMode_CTRL_States"; apply (simp add: CDMode_CTRL_def) apply (unfold States_def) apply (simp add: Abs_seqauto_inverse check_CDMode_CTRL) done lemma Init_State_CDMode_CTRL: "InitState CDMode_CTRL = CDMode_CTRL_Init"; apply (simp add: CDMode_CTRL_def) apply (unfold InitState_def) apply (simp add: Abs_seqauto_inverse check_CDMode_CTRL) done lemma Labels_CDMode_CTRL: "Labels CDMode_CTRL = CDMode_CTRL_Labels"; apply (simp add: CDMode_CTRL_def) apply (unfold Labels_def) apply (simp add: Abs_seqauto_inverse check_CDMode_CTRL) done lemma Delta_CDMode_CTRL: "Delta CDMode_CTRL = CDMode_CTRL_Delta"; apply (simp add: CDMode_CTRL_def) apply (unfold Delta_def) apply (simp add: Abs_seqauto_inverse check_CDMode_CTRL) done schematic_lemma Events_CDMode_CTRL: "SAEvents CDMode_CTRL = ?X" apply (unfold SAEvents_def) apply (rule trans) apply (simp add: expr_def Label_def Delta_CDMode_CTRL CDMode_CTRL_Delta_def CDMode_CTRL_Action1_def CDMode_CTRL_Action2_def) apply (rule refl) done subsubsection {* Hierarchical Automaton @{text "CarAudioSystem"} *} lemmas CarAudioSystemStates = States_Root_CTRL States_CDPlayer_CTRL States_AudioPlayer_CTRL States_On_CTRL States_TunerMode_CTRL States_CDMode_CTRL Root_CTRL_States_def CDPlayer_CTRL_States_def AudioPlayer_CTRL_States_def On_CTRL_States_def TunerMode_CTRL_States_def CDMode_CTRL_States_def lemmas CarAudioSystemInitState = Init_State_Root_CTRL Init_State_CDPlayer_CTRL Init_State_AudioPlayer_CTRL Init_State_On_CTRL Init_State_TunerMode_CTRL Init_State_CDMode_CTRL Root_CTRL_Init_def CDPlayer_CTRL_Init_def AudioPlayer_CTRL_Init_def On_CTRL_Init_def TunerMode_CTRL_Init_def CDMode_CTRL_Init_def lemmas CarAudioSystemEvents = Events_Root_CTRL Events_CDPlayer_CTRL Events_AudioPlayer_CTRL Events_On_CTRL Events_TunerMode_CTRL Events_CDMode_CTRL lemmas CarAudioSystemthms = CarAudioSystemStates CarAudioSystemEvents CarAudioSystemInitState (* -------------------------------------------------------------- *) (* States of \<guillemotright> CarAudioSystem \<guillemotleft> *) (* -------------------------------------------------------------- *) schematic_lemma CarAudioSystem_StatesRoot: "HAStates (PseudoHA Root_CTRL (LiftInitData [V0 0, V1 0])) = ?X" apply (wellformed CarAudioSystemthms)+ done lemmas CarAudioSystemthms_1 = CarAudioSystemthms CarAudioSystem_StatesRoot schematic_lemma CarAudioSystem_StatesCDPlayer: "HAStates (PseudoHA Root_CTRL (LiftInitData [V0 0, V1 0]) [++] (''CarAudioSystem'',CDPlayer_CTRL)) = ?X" apply (wellformed CarAudioSystemthms_1)+ done lemmas CarAudioSystemthms_2 = CarAudioSystemthms_1 CarAudioSystem_StatesCDPlayer schematic_lemma CarAudioSystem_StatesAudioPlayer: "HAStates (PseudoHA Root_CTRL (LiftInitData [V0 0, V1 0]) [++] (''CarAudioSystem'',CDPlayer_CTRL) [++] (''CarAudioSystem'',AudioPlayer_CTRL)) = ?X" apply (wellformed CarAudioSystemthms_2)+ done lemmas CarAudioSystemthms_3 = CarAudioSystemthms_2 CarAudioSystem_StatesAudioPlayer schematic_lemma CarAudioSystem_StatesTunerMode: "HAStates (PseudoHA Root_CTRL (LiftInitData [V0 0, V1 0]) [++] (''CarAudioSystem'',CDPlayer_CTRL) [++] (''CarAudioSystem'',AudioPlayer_CTRL) [++] (''On'', TunerMode_CTRL )) = ?X" apply (wellformed CarAudioSystemthms_3)+ done lemmas CarAudioSystemthms_4 = CarAudioSystemthms_3 CarAudioSystem_StatesTunerMode schematic_lemma CarAudioSystem_StatesCDMode: "HAStates (PseudoHA Root_CTRL (LiftInitData [V0 0, V1 0]) [++] (''CarAudioSystem'',CDPlayer_CTRL) [++] (''CarAudioSystem'',AudioPlayer_CTRL) [++] (''On'', TunerMode_CTRL ) [++] (''On'', CDMode_CTRL)) = ?X" apply (wellformed CarAudioSystemthms_4)+ done lemmas CarAudioSystemthms_5 = CarAudioSystemthms_4 CarAudioSystem_StatesCDMode schematic_lemma SAsCarAudioSystem: "SAs CarAudioSystem = ?X" apply (unfold CarAudioSystem_def) apply (wellformed CarAudioSystemthms_5)+ done schematic_lemma EventsCarAudioSystem: "HAEvents CarAudioSystem = ?X"; apply (unfold CarAudioSystem_def) apply (wellformed CarAudioSystemthms_5)+ done schematic_lemma CompFunCarAudioSystem: "CompFun CarAudioSystem = ?X" apply (unfold CarAudioSystem_def) apply (wellformed CarAudioSystemthms_5)+ done schematic_lemma StatesCarAudioSystem: "HAStates CarAudioSystem = ?X" apply (unfold CarAudioSystem_def) apply (wellformed CarAudioSystemthms_5)+ done schematic_lemma ValueCarAudioSystem: "HAInitValue CarAudioSystem = ?X" apply (unfold CarAudioSystem_def) apply (wellformed CarAudioSystemthms_5)+ done schematic_lemma HAInitStatesCarAudioSystem: "HAInitStates CarAudioSystem = ?X" by (simp add: HAInitStates_def SAsCarAudioSystem CarAudioSystemInitState) schematic_lemma HARootCarAudioSystem: "HARoot CarAudioSystem = ?X" apply (unfold CarAudioSystem_def) apply (wellformed CarAudioSystemthms_5)+ done schematic_lemma HAInitStateCarAudioSystem: "HAInitState CarAudioSystem = ?X" by (simp add: HARootCarAudioSystem HAInitState_def CarAudioSystemInitState) (* -------------------------------------------------------------- *) (* Components of the initial data space assignement *) (* -------------------------------------------------------------- *) lemma check_DataSpace [simp]: "[range V0, range V1] \<in> dataspace" apply (unfold dataspace_def DataSpace.DataSpace_def) apply auto apply (rename_tac D) apply (case_tac "D") apply auto done lemma PartNum_DataSpace [simp]: "PartNum (DSpace) = 2" apply (unfold PartNum_def DSpace_def) apply (simp add: Abs_dataspace_inverse) done lemma PartDom_DataSpace_V0 [simp]: "(PartDom DSpace 0) = range V0" apply (unfold PartDom_def DSpace_def) apply (simp add: Abs_dataspace_inverse) done lemma PartDom_DataSpace_V1 [simp]: "(PartDom DSpace (Suc 0)) = range V1" apply (unfold PartDom_def DSpace_def) apply (simp add: Abs_dataspace_inverse) done lemma check_InitialData [simp]: "([V0 0, V1 0],DSpace) \<in> data" apply (unfold data_def Data.Data_def) apply auto apply (rename_tac d) apply (case_tac "d=0 \<or> d = 1") apply auto done lemma Select0_InitData [simp]: "Select0 (LiftInitData [V0 0, V1 0]) = 0" apply (unfold LiftInitData_def Select0_def DataPart_def DataValue_def) apply (simp add: Abs_data_inverse) done lemma Select1_InitData [simp]: "Select1 (LiftInitData [V0 0, V1 0]) = 0" apply (unfold LiftInitData_def Select1_def DataPart_def DataValue_def) apply (simp add: Abs_data_inverse) done lemma HAInitValue1_CarAudioSystem: "CarAudioSystem |=H= Atom (VAL (\<lambda> d. (Select0 d) = 0))" apply (simp add: ValueCarAudioSystem) done lemma HAInitValue2_CarAudioSystem: "CarAudioSystem |=H= Atom (VAL (\<lambda> d. (Select1 d) = 0))" apply (simp add: ValueCarAudioSystem) done lemma HAInitValue_DSpace_CarAudioSystem [simp]: "Data.DataSpace (LiftInitData [V0 0, V1 0]) = DSpace" apply (unfold LiftInitData_def Data.DataSpace_def) apply (simp add: Abs_data_inverse) done lemma check_InitStatus [simp]: "(CarAudioSystem, InitConf CarAudioSystem, {},LiftInitData [V0 0, V1 0]) \<in> status" apply (unfold status_def Status_def) apply (simp add: ValueCarAudioSystem) done lemma InitData_InitStatus [simp]: "Value (InitStatus CarAudioSystem) = LiftInitData [V0 0, V1 0]" apply (simp add: ValueCarAudioSystem) done lemma Events_InitStatus [simp]: "Events (InitStatus CarAudioSystem) = {}" apply (unfold InitStatus_def Events_def) apply (simp add: Abs_status_inverse) done lemma Conf_InitStatus [simp]: "Conf (InitStatus CarAudioSystem) = InitConf CarAudioSystem" apply (unfold InitStatus_def Conf_def) apply (simp add: Abs_status_inverse) done lemma CompFunCarAudioSystem_the: "the (CompFun CarAudioSystem ''On'') = {CDMode_CTRL,TunerMode_CTRL}" apply (unfold CarAudioSystem_def) apply (subst AddSA_CompFun_the) prefer 3 apply (subst AddSA_CompFun_the) prefer 3 apply (subst AddSA_CompFun_the2) apply (wellformed CarAudioSystemthms_5)+ done lemma CompFunCarAudioSystem_the2: "the (CompFun CarAudioSystem ''CarAudioSystem'') = {AudioPlayer_CTRL, CDPlayer_CTRL}" apply (unfold CarAudioSystem_def) apply (subst AddSA_CompFun_the3) prefer 5 apply (subst AddSA_CompFun_the3) prefer 5 apply (subst AddSA_CompFun_the) prefer 3 apply (subst AddSA_CompFun_the) prefer 3 apply (subst PseudoHA_CompFun_the) apply (wellformed CarAudioSystemthms_5)+ done lemma CompFunCarAudioSystem_the3: "the (CompFun CarAudioSystem ''Off'') = {}" apply (unfold CarAudioSystem_def) apply (subst AddSA_CompFun_the3) prefer 5 apply (subst AddSA_CompFun_the3) prefer 5 apply (subst AddSA_CompFun_the2) apply (wellformed CarAudioSystemthms_5)+ done schematic_lemma CompFunCarAudioSystem_ran: "ran (CompFun CarAudioSystem) = ?X" apply (unfold CarAudioSystem_def) apply (rule AddSA_CompFun_ran3_IFF) prefer 6 apply (subst AddSA_CompFun_PseudoHA_ran2) prefer 4 apply (simp add: insert_commute) apply (wellformed CarAudioSystemthms_5)+ done lemma Root_CTRL_CDPlayer_CTRL_noteq [simp]: "Root_CTRL \<noteq> CDPlayer_CTRL" apply (rule SA_States_disjunct) apply (wellformed CarAudioSystemthms_5)+ done lemma Root_CTRL_TunerMode_CTRL_noteq [simp]: "Root_CTRL \<noteq> TunerMode_CTRL" apply (rule SA_States_disjunct) apply (wellformed CarAudioSystemthms_5)+ done lemma Root_CTRL_CDMode_CTRL_noteq [simp]: "Root_CTRL \<noteq> CDMode_CTRL" apply (rule SA_States_disjunct) apply (wellformed CarAudioSystemthms_5)+ done lemma CDPlayer_CTRL_AudioPlayer_CTRL_noteq [simp]: "CDPlayer_CTRL \<noteq> AudioPlayer_CTRL" apply (rule SA_States_disjunct) apply (wellformed CarAudioSystemthms_5)+ done lemma CDPlayer_CTRL_TunerMode_CTRL_noteq [simp]: "CDPlayer_CTRL \<noteq> TunerMode_CTRL" apply (rule SA_States_disjunct) apply (wellformed CarAudioSystemthms_5)+ done lemma CDPlayer_CTRL_CDMode_CTRL_noteq [simp]: "CDPlayer_CTRL \<noteq> CDMode_CTRL" apply (rule SA_States_disjunct) apply (wellformed CarAudioSystemthms_5)+ done lemma AudioPlayer_CTRL_TunerMode_CTRL_noteq [simp]: "AudioPlayer_CTRL \<noteq> TunerMode_CTRL" apply (rule SA_States_disjunct) apply (wellformed CarAudioSystemthms_5)+ done lemma AudioPlayer_CTRL_CDMode_CTRL_noteq [simp]: "AudioPlayer_CTRL \<noteq> CDMode_CTRL" apply (rule SA_States_disjunct) apply (wellformed CarAudioSystemthms_5)+ done lemma TunerMode_CTRL_CDMode_CTRL_noteq [simp]: "TunerMode_CTRL \<noteq> CDMode_CTRL" apply (rule SA_States_disjunct) apply (wellformed CarAudioSystemthms_5)+ done schematic_lemma Chi_CarAudioSystem: "Chi CarAudioSystem ''CarAudioSystem'' = ?X" apply (unfold Chi_def) apply (rule trans) apply (simp add: SAsCarAudioSystem StatesCarAudioSystem restrict_def CompFunCarAudioSystem_the2) apply (rule trans) apply (simp add: not_sym) apply (simp add: CarAudioSystemStates insert_or) done schematic_lemma Chi_CarAudioSystem_On: "Chi CarAudioSystem ''On'' = ?X" apply (unfold Chi_def) apply (rule trans) apply (simp add: SAsCarAudioSystem StatesCarAudioSystem restrict_def CompFunCarAudioSystem_the) apply (rule trans) apply (simp add: not_sym) apply (simp add: CarAudioSystemStates insert_or) done schematic_lemma Chi_CarAudioSystem_Off: "Chi CarAudioSystem ''Off'' = ?X" apply (unfold Chi_def) apply (simp add: SAsCarAudioSystem StatesCarAudioSystem restrict_def CompFunCarAudioSystem_the3) done schematic_lemma InitConf_CarAudioSystem: "InitConf CarAudioSystem = ?X" apply (unfold CarAudioSystem_def) apply (rule AddSA_InitConf_IFF)+ apply simp apply (wellformed CarAudioSystemthms_5) apply fast apply (wellformed CarAudioSystemthms_5) apply simp apply (simp add: CarAudioSystemthms_5) apply (wellformed CarAudioSystemthms_5) apply fast apply (wellformed CarAudioSystemthms_5) apply fast apply simp apply (wellformed CarAudioSystemthms_5) apply fast apply (wellformed CarAudioSystemthms_5) apply fast apply simp apply (wellformed CarAudioSystemthms_5) apply force apply (wellformed CarAudioSystemthms_5) apply fast apply (simp add: CarAudioSystemthms_5) done lemma Initial_State_CarAudioSystem: "CarAudioSystem |=H= Atom (IN ''Off'')" apply (simp add: InitConf_CarAudioSystem ) done end
module Data.Trifunctor %default total %access public export ||| Zifunctor is abstraction over description of computation t that: ||| takes r as input (reader, input) ||| produce result a (a result) ||| or produce error of type e ||| Progression of abstractions: Functor => Bifunctor, Profunctor => Zifunctor ||| Zifunctor combine capabilities of Functor, Bifunctor, Profunctor and add more interface Zifunctor (t : Type -> Type -> Type -> Type) where zimap : (rr -> r) -> (e -> ee) -> (a -> aa) -> t r e a -> t rr ee aa bimap : (e -> ee) -> (a -> aa) -> t r e a -> t r ee aa bimap = zimap id dimap : (rr -> r) -> (a -> aa) -> t r e a -> t rr e aa dimap r = zimap r id dimapLeft : (rr -> r) -> (e -> ee) -> t r e a -> t rr ee a dimapLeft r e = zimap r e id map : (a -> aa) -> t r e a -> t r e aa map = zimap id id mapLeft : (e -> ee) -> t r e a -> t r ee a mapLeft e = zimap id e id contramap : (rr -> r) -> t r e a -> t rr e a contramap r = zimap r id id -- TODO Zifunctor implementation for r -> Either e a -- TODO Zifunctor implementation for r -> (e,a) -- TODO Zifunctor implementation for Bifunctor b => r -> b e a
Formal statement is: lemma bigger_prime: "\<exists>p. prime p \<and> p > (n::nat)" Informal statement is: There exists a prime number greater than $n$.
lemma has_contour_integral_newpath: "\<lbrakk>(f has_contour_integral y) h; f contour_integrable_on g; contour_integral g f = contour_integral h f\<rbrakk> \<Longrightarrow> (f has_contour_integral y) g"
Of giltwood with faux bronze painted decoration and applied with gilded lead mounts. Each inverted domed top set with finely cast gilt-lead stylized foliated mounts on a faux bronze ground. The reeded faux bronze shaft issuing from a finely carved foliate ‘cup’ resting on an inverted cone finial. The flared top of the shaft set with foliate gilt-lead mounts. The whole raised on four exquisitely carved giltwood winged female figures resting on a faux bronze platform base. Gilding and faux bronze refreshed in places. Danhauser had a predilection for delicately gilded carved wood rather than gilt-bronze, an 18th-century tradition he drew from Italy, which is illustrated by the present torcheres. This choice of material lends a softer, sculpted appearance, as opposed to the more rigid and formal designs of the French Empire style executed in bronze, which were rejected by the Viennese out of disdain for the Emperor Napoleon. Also of note is the use of gilt-lead mounts, instead of gilt-bronze, that are applied to the top of the torcheres. A suite of furniture probably by Danhauser in Schloss Wetzdorf, the former home of Josef Gottfried Pargfrieder, has been applied with gilt-lead decoration of anthemian and acanthine motifs. Furthermore, both the present torcheres and the Wetzdorf suite possess painted decoration to complement the giltwood ornaments. 1. Windischgrätz, F. ‘Furniture.’ Vienna in the Age of Schubert. The Biedermeier Interior 1815-48. London: Elron Press Ltd., 1979. 38. 3. Dr. Christian Witt-Dörring, Vienna, March 1997. Pair of Armchairs by Joseph Danhauser for Archduke Karl’s Palace, for Carlton Hobbs LLC.
lemma continuous_on_mult_left: fixes c::"'a::real_normed_algebra" shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. c * f x)"
program hello_world3 implicit none character*32 text c text = 'Hello World' c call printtext(text) end subroutine printtext(tekst) implicit none character*32 tekst c write (*,*) tekst c end
theory BlockchainNew imports Main "HOL.List" begin (* -- TYPES / Hash / Block Datatype / BlockTree Datatype --*) type_synonym Transactions = nat type_synonym Party = nat type_synonym Slot = nat datatype Hash = H nat nat definition "Slotzero = 0" type_synonym Parties = "Party list" fun Winner :: "Party \<Rightarrow> Slot \<Rightarrow> bool" where "Winner P S = (if P = S then True else False)" record Block = sl :: Slot txs :: Transactions pred :: Hash bid :: Party type_synonym Chain = "Block list" type_synonym Chains = "Chain list" type_synonym BlockPool = "Block list" definition "GenBlock = \<lparr>sl = 0, txs = 0, pred = H 0 0 ,bid = 0\<rparr>" definition "Block1 = \<lparr>sl = 1, txs =1, pred = H 0 0, bid = 1\<rparr>" definition "Block2 = \<lparr> sl = 2, txs = 0, pred = H 1 1, bid = 1\<rparr>" definition "Block3 = \<lparr> sl = 3, txs = 0, pred = H 2 1, bid = 1\<rparr>" datatype T = Leaf Block | Node Block T | Node2 Block T T definition "tree0 = Leaf GenBlock" (*-- Functions for valid_chain --*) fun HashCompare' :: "Hash \<Rightarrow> Block \<Rightarrow> bool" where "HashCompare' (H a b) bl1 = ((a = sl bl1) \<and> (b = bid bl1))" fun HashCompare :: "Block \<Rightarrow> Block \<Rightarrow> bool" where "HashCompare bl1 bl2 = HashCompare' (pred bl2) bl1" fun valid_blocks ::"Block \<Rightarrow> Block \<Rightarrow> bool" where "valid_blocks b1 b2 = ( HashCompare b2 b1 \<and>(sl b2 < sl b1))" fun valid_chain :: "Chain \<Rightarrow> bool" where "valid_chain [] = False"| "valid_chain [b1] = (if b1 = GenBlock then True else False)"| "valid_chain (b1#b2#c) = (if valid_blocks b1 b2 \<and> (b1 \<noteq> GenBlock) then valid_chain (b2#c) else False)" fun block_get :: "T \<Rightarrow> Block" where "block_get (Node2 m l r) = m"| "block_get (Node m l) = m"| "block_get (Leaf m) = m" fun valid_t_weak where "valid_t_weak (Node2 m l r) = (valid_blocks (block_get l) m \<and> valid_blocks (block_get r) m \<and> valid_t_weak r \<and> valid_t_weak l)"| "valid_t_weak (Node m l) = (valid_blocks (block_get l) m \<and> valid_t_weak l)"| "valid_t_weak (Leaf m) = True" fun hash_t where "hash_t(Node2 m l r) = (HashCompare m (block_get l) \<and> HashCompare m (block_get r) \<and> hash_t r \<and> hash_t l)"| "hash_t (Node m l) = (HashCompare m (block_get l) \<and> hash_t l)"| "hash_t (Leaf m) = True" fun sl_t where "sl_t(Node2 m l r) = (sl m < sl (block_get l) \<and> sl m < sl (block_get r) \<and> sl_t r \<and> sl_t l)"| "sl_t (Node m l) = (sl m < sl (block_get l) \<and> sl_t l)"| "sl_t (Leaf m) = True" (*-- Functions for allBlocks/allBlocks' and extendTree --*) fun allBlocks :: "T \<Rightarrow> BlockPool" where "allBlocks (Node2 m l r) = allBlocks l @ allBlocks r @ [m]"| "allBlocks (Node m l ) = allBlocks l @ [m]"| "allBlocks (Leaf m) = [m]" fun allBlocksAppend :: "Block \<Rightarrow>BlockPool list\<Rightarrow> BlockPool list" where "allBlocksAppend Bl BlP = (map (\<lambda> bl. bl @ [Bl]) BlP)" fun allBlocks' :: "T \<Rightarrow> BlockPool list" where "allBlocks' (Node2 m l r) =( allBlocksAppend m (allBlocks' l) @allBlocksAppend m (allBlocks' r))"| "allBlocks' (Node m l) =( allBlocksAppend m (allBlocks' l) @[[m]])"| "allBlocks' (Leaf m)= [[m]]" fun extendTree :: "T \<Rightarrow> Block \<Rightarrow> T" where "extendTree (Leaf Bl1) Bl2 = (if valid_blocks Bl2 Bl1 then (Node Bl1 (Leaf Bl2)) else (Leaf Bl1))"| "extendTree (Node Bl1 l) Bl2 = (if valid_blocks Bl2 Bl1 then (Node2 Bl1 l (Leaf Bl2)) else (Node Bl1 (extendTree l Bl2)))"| "extendTree (Node2 m l r) Bl2 = (Node2 m (extendTree l Bl2) (extendTree r Bl2))" fun valid_t where "valid_t t = (\<forall>c\<in>set(allBlocks' t).valid_chain c)" (*-- Functions for finding best_chain --*) fun best_c :: "Slot \<Rightarrow> BlockPool list \<Rightarrow> (Block list \<times> nat \<times> bool) option"where "best_c slot list = (let list' = map (\<lambda> l. (l,sl (hd l), valid_chain l)) list in find (\<lambda> (c,s,v).v\<and>(s\<le>slot)) list')" fun get_first :: "(Block list \<times> nat \<times> bool) option \<Rightarrow>Block list" where "get_first a = (case a of None \<Rightarrow> [] | Some a \<Rightarrow> fst a)" fun best_chain :: "Slot \<Rightarrow> T \<Rightarrow> Chain" where "best_chain s (Node x l) = (if s > 0 then get_first ( best_c s (allBlocks' (Node x l)))else [GenBlock])"| "best_chain s (Node2 x l r) = (if s > 0 then get_first ( best_c s (allBlocks' (Node2 x l r)))else [GenBlock])"| "best_chain s (Leaf m) = (if s > 0 then get_first ( best_c s (allBlocks' (Leaf m)))else [GenBlock])" (*-- Second Attempt at finding the best chain without using find--*) fun allChains' :: "T\<Rightarrow>Slot \<Rightarrow>BlockPool list" where "allChains' (Node2 m l r) s = (if sl m \<le> s then (allBlocksAppend m (allChains' l s) @allBlocksAppend m (allChains' r s))else[[]])"| "allChains' (Node m l) s = (if sl m \<le> s then (allBlocksAppend m (allChains' l s) @[[m]])else [[]])"| "allChains' (Leaf m) s = (if sl m \<le> s then [[m]] else [[]])" fun return_first :: "Chain list \<Rightarrow> Chain" where "return_first (x#xs) = x"| "return_first [] = undefined" fun best_chain_new :: "T \<Rightarrow> Slot \<Rightarrow> Chain" where "best_chain_new t s = return_first (allChains' t s)" (*-- Functions for equality --*) fun block_eq :: "Block \<Rightarrow> Block \<Rightarrow> bool" where "block_eq bl1 b2 = ((sl bl1 = sl b2)\<and>(txs bl1 = txs b2)\<and>(pred bl1 = pred b2)\<and>(bid bl1 = bid b2))" fun blockpool_eq_set :: "BlockPool \<Rightarrow> BlockPool \<Rightarrow> bool" where "blockpool_eq_set bpl1 bpl2 = (set(bpl1) = set(bpl2)) " fun blockpool_eq :: "BlockPool \<Rightarrow> BlockPool \<Rightarrow> bool" where "blockpool_eq Nil Nil= True"| "blockpool_eq a b = (((set a \<inter> set b) =set a)\<and>((set a \<inter> set b) =set b))" fun blocktree_eq :: "T \<Rightarrow> T \<Rightarrow> bool" where "blocktree_eq (Node2 t1 t2 t3) (Node2 t_1 t_2 t_3) =((Node2 t1 t2 t3) = (Node2 t_1 t_2 t_3))"| "blocktree_eq (Node t1 t2) (Node t_1 t_2) =((Node t1 t2) = (Node t_1 t_2))"| "blocktree_eq (Leaf m) (Leaf n) = (Leaf m = Leaf n)"| "blocktree_eq (T.Leaf v) (T.Node va vb) = False"| "blocktree_eq (T.Leaf v) (Node2 va vb vc) = False"| "blocktree_eq (T.Node v va) (T.Leaf vb) = False"| "blocktree_eq (T.Node v va) (Node2 vb vc vd) = False"| "blocktree_eq (Node2 va vb vc) (T.Leaf v) = False"| "blocktree_eq (Node2 vb vc vd) (T.Node v va) = False" (*-- LEMMAS + PROOFS -- *) export_code HashCompare' HashCompare GenBlock blockpool_eq_set block_eq valid_blocks valid_chain allBlocks allBlocksAppend allBlocks' tree0 extendTree valid_t valid_t_weak best_c get_first best_chain blocktree_eq in Haskell lemma initialTree : "allBlocks tree0 = [GenBlock]" by (simp add: GenBlock_def tree0_def) lemma initialExtend : "(extendTree tree0 b \<noteq> tree0) \<Longrightarrow> set (allBlocks (extendTree tree0 b)) = set ([b]@ allBlocks tree0)" apply(simp add : GenBlock_def tree0_def) by auto lemma base_best_valid :"valid_chain(best_chain s tree0)" apply(simp add : tree0_def GenBlock_def) done lemma initialExtendValid : "valid_t tree0 \<Longrightarrow>valid_t (extendTree tree0 b)" apply(simp add: GenBlock_def tree0_def) done lemma initialExtendweakValid : "valid_t_weak tree0 \<Longrightarrow>valid_t_weak (extendTree tree0 b)" by (simp add: tree0_def) lemma initialBestChain : "valid_t (extendTree tree0 b) \<Longrightarrow> valid_chain( best_chain s (extendTree tree0 b)) " apply(simp add: GenBlock_def tree0_def) done lemma ExtendInitial : "(extendTree tree0 Block1) = (Node GenBlock (Leaf Block1))" by (simp add: GenBlock_def tree0_def Block1_def) lemma ExtendLeaf : assumes "valid_blocks B m" shows "extendTree (Leaf m) B = (Node m (Leaf B))" using assms by auto lemma SameBlock : assumes "block_eq bl1 bl2" shows "bl1 = bl2" using assms apply(auto) done lemma SamePool : assumes "blockpool_eq (x) (y)" shows "set x = set y" using assms by (smt (verit, best) blockpool_eq.elims(2)) lemma SameTreeBase : assumes "blocktree_eq T1 T2" shows "T1 = T2" using assms SameBlock using blocktree_eq.elims(2) by blast lemma SameTree : assumes "blocktree_eq T1 T2" shows "blockpool_eq (allBlocks T1) (allBlocks T2)" using assms SamePool by (metis (no_types, opaque_lifting) SameTreeBase blockpool_eq.simps(1) blockpool_eq.simps(3) inf.idem valid_chain.cases) lemma find_in : \<open>find p ls = Some l\<Longrightarrow> l\<in> set(ls)\<close> proof(induction ls) case Nil then show ?case by simp next case (Cons a ls) then show ?case by (metis find_Some_iff nth_mem) qed lemma best_c_in : "best_c n bl \<noteq> None \<Longrightarrow> get_first(best_c n bl) \<in> set(bl)" apply(simp add: find_in) proof(induction bl) case Nil then show ?case by simp next case (Cons a bl) then show ?case by auto qed lemma slThan : assumes "valid_t_weak t \<and> t = (Node2 m l r)" shows "( sl m < sl (block_get r) \<and> sl m < sl(block_get l))" using assms by auto lemma predThan : assumes "valid_t_weak t \<and> t = (Node2 m l r)" shows "( HashCompare m (block_get r) \<and> HashCompare m (block_get l))" using assms by auto lemma slThan2 : assumes "sl_t t \<and> t = (Node2 m l r)" shows "( sl m < sl (block_get r) \<and> sl m < sl(block_get l))" using assms by auto lemma predThan2 : assumes "hash_t t \<and> t = (Node2 m l r)" shows "( HashCompare m (block_get r) \<and> HashCompare m (block_get l))" using assms by auto lemma BaseExtend : "(extendTree t b \<noteq> t) \<Longrightarrow> set (allBlocks (extendTree t b)) = set ([b]@ allBlocks t)" proof(induction t) case (Leaf x) then show ?case by auto next case (Node x1a t) then show ?case by auto next case (Node2 x1a t1 t2) then show ?case by fastforce qed lemma best_valid_new:assumes "s\<ge>0\<and>block_get t = GenBlock\<and>valid_t_weak t " shows" valid_chain (best_chain_new t s)" proof(cases "t") case (Leaf x1) then show ?thesis using assms apply(simp add: GenBlock_def) done next case (Node x21 x22) then show ?thesis using assms apply(simp add: GenBlock_def) apply(auto) apply(simp add: append_def) oops next case (Node2 x31 x32 x33) then show ?thesis oops qed lemma hashAll : assumes "valid_t_weak t" shows "hash_t t" using assms oops lemma validSame : assumes "valid_t_weak t" shows "sl_t t \<and> hash_t t" using assms oops lemma slExtend : "sl_t t \<and> block_get t = GenBlock \<Longrightarrow> sl_t(extendTree t b)" proof(induction "t") case (Leaf x) then show ?case by simp next case (Node x1a t) then show ?case apply(simp add: GenBlock_def) oops next case (Node2 x1a t1 t2) then show ?case oops qed lemma validExtend : assumes "valid_t_weak t \<and> block_get t = GenBlock" shows "valid_t_weak (extendTree t b)" using assms oops lemma best_valid: assumes "s>0\<and>block_get t = GenBlock\<and>valid_t_weak t" shows "valid_chain (best_chain s t)" proof(cases "t") case (Leaf x1) then show ?thesis apply(simp add: GenBlock_def) using GenBlock_def assms by auto next case (Node x21 x22) then show ?thesis apply(simp add: GenBlock_def) using GenBlock_def assms oops next case (Node2 x31 x32 x33) then show ?thesis sorry qed
lemma (in perfect_space) UNIV_not_singleton: "UNIV \<noteq> {x}" for x::'a
(* Title: HOL/Auth/n_mutualExOnI_lemma_on_inv__2.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_mutualExOnI Protocol Case Study*} theory n_mutualExOnI_lemma_on_inv__2 imports n_mutualExOnI_base begin section{*All lemmas on causal relation between inv__2 and some rule r*} lemma n_TryVsinv__2: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_Try i)" and a2: "(\<exists> p__Inv0 p__Inv1. p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv0~=p__Inv1\<and>f=inv__2 p__Inv0 p__Inv1)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_Try i" apply fastforce done from a2 obtain p__Inv0 p__Inv1 where a2:"p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv0~=p__Inv1\<and>f=inv__2 p__Inv0 p__Inv1" apply fastforce done have "(i=p__Inv0)\<or>(i=p__Inv1)\<or>(i~=p__Inv0\<and>i~=p__Inv1)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv0)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''n'') p__Inv1)) (Const C)) (eqn (IVar (Para (Ident ''n'') p__Inv0)) (Const I))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv1)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv1)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_CritVsinv__2: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_Crit i)" and a2: "(\<exists> p__Inv0 p__Inv1. p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv0~=p__Inv1\<and>f=inv__2 p__Inv0 p__Inv1)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_Crit i" apply fastforce done from a2 obtain p__Inv0 p__Inv1 where a2:"p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv0~=p__Inv1\<and>f=inv__2 p__Inv0 p__Inv1" apply fastforce done have "(i=p__Inv0)\<or>(i=p__Inv1)\<or>(i~=p__Inv0\<and>i~=p__Inv1)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv0)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv1)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv1)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_ExitVsinv__2: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_Exit i)" and a2: "(\<exists> p__Inv0 p__Inv1. p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv0~=p__Inv1\<and>f=inv__2 p__Inv0 p__Inv1)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_Exit i" apply fastforce done from a2 obtain p__Inv0 p__Inv1 where a2:"p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv0~=p__Inv1\<and>f=inv__2 p__Inv0 p__Inv1" apply fastforce done have "(i=p__Inv0)\<or>(i=p__Inv1)\<or>(i~=p__Inv0\<and>i~=p__Inv1)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv0)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv1)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv1)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_IdleVsinv__2: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_Idle i)" and a2: "(\<exists> p__Inv0 p__Inv1. p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv0~=p__Inv1\<and>f=inv__2 p__Inv0 p__Inv1)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_Idle i" apply fastforce done from a2 obtain p__Inv0 p__Inv1 where a2:"p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv0~=p__Inv1\<and>f=inv__2 p__Inv0 p__Inv1" apply fastforce done have "(i=p__Inv0)\<or>(i=p__Inv1)\<or>(i~=p__Inv0\<and>i~=p__Inv1)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv0)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv1)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv1)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
import numpy as np from games.abstract_game import Game def check_connect3(array): filled = 0 not in array uniquely = np.unique(array).size == 1 winner = None if not (filled and uniquely) else np.unique(array)[0] return filled and uniquely, winner class TicTacToe(Game): def __init__(self): super().__init__() self.board = np.zeros((3, 3)) self.players = [-1, 1] self.current_player = 1 # np.random.choice(self.players) def get_previous_player(self) -> int: return self.current_player * -1 def get_current_player(self): return self.current_player def evolve(self, move: tuple) -> tuple: assert move in self.get_valid_moves(), f"Move {move} is not valid." self.board[move] = self.current_player self.current_player = 1 if self.current_player == -1 else -1 for row in self.board: filled_uniquely, winner = check_connect3(row) if filled_uniquely: return True, winner for col in self.board.T: filled_uniquely, winner = check_connect3(col) if filled_uniquely: return True, winner diag = np.diagonal(self.board) filled_uniquely, winner = check_connect3(diag) if filled_uniquely: return True, winner oppo_diag = np.diagonal(np.fliplr(self.board)) filled_uniquely, winner = check_connect3(oppo_diag) if filled_uniquely: return True, winner if 0 not in np.unique(self.board): return True, 0 # 0 means nobody is winner return False, None def get_valid_moves(self) -> list: advanced_indices = np.where(self.board == 0) moves = list(zip(advanced_indices[0], advanced_indices[1])) return moves def __repr__(self): return np.array2string(self.board)
#!/usr/bin/env python3 import csv import argparse import pathlib import scipy from scipy.stats import wilcoxon, normaltest, ttest_1samp, ttest_ind import numpy as np if __name__ == '__main__': parser = argparse.ArgumentParser( description="Wilcoxon test for Clickstream" ) parser.add_argument("input", metavar="INPUT", help="input file", type=pathlib.Path ) args = parser.parse_args() with args.input.open('r') as csvfile: reader = csv.reader(csvfile, delimiter='\t') res_algo = [] res_cyclerank = [] for row in reader: # print(row) try: tau_algo = float(row[0]) tau_cyclerank = float(row[1]) res_algo.append(tau_algo) res_cyclerank.append(tau_cyclerank) except: # print('.', end='') pass # load the data with NumPy function loadtxt data_algo = np.array(res_algo) data_cyclerank = np.array(res_cyclerank) # normality test nt, p_nt = normaltest(data_algo-data_cyclerank) print('normality test: {} (p-value: {})'.format(nt, p_nt)) # normality test tt, p_tt = ttest_ind(data_algo, data_cyclerank) print('t-tests test: {} (p-value: {})' .format(tt, p_tt)) # wilcoxon test w, p_w = wilcoxon(data_algo, data_cyclerank) n = len(data_algo) sigma_w = np.sqrt(n*(n+1)*(2*n+1)) zscore_w = w/sigma_w print('wilcoxon test (z-score): {} (p-value: {})' .format(zscore_w, p_w)) exit(0)
[STATEMENT] lemma suppI_contra: "x \<notin> supp f \<Longrightarrow> f x = 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. x \<notin> supp f \<Longrightarrow> f x = (0::'b) [PROOF STEP] using suppI [PROOF STATE] proof (prove) using this: ?f ?x \<noteq> (0::?'a) \<Longrightarrow> ?x \<in> supp ?f goal (1 subgoal): 1. x \<notin> supp f \<Longrightarrow> f x = (0::'b) [PROOF STEP] by fast
.ds TL Introduction .NH "Introduction" .PP Congratulations on your purchase of \*(CO release 4.2! \*(CO gives your 80386- or 80486-based system a fully multi-tasking, multi-user operating system \(em at a fraction of the cost of other systems. We think you will appreciate the fact that \*(CO is powerful yet inexpensive, efficient, and easy to install. .PP This pamphlet shows you how to install \*(CO on your system. It also includes information you should find helpful in using \*(CO. This includes information on how to contact Mark Williams Technical Support, and how to access the Mark Williams Bulletin Board. \fIRead these notes carefully before you attempt to install or update \*(CO on your computer.\fR .SH "Frequently Asked Questions" .PP Before we begin, please note the following: .IP \fB1.\fR 0.3i If you need to telephone Mark Williams Technical Support, dial 1-708-291-6700. Please do not telephone on the Mark Williams sales number. .IP \fB2.\fR If you are updating your \*(CO system, you will .I not have received a card with a serial number on it. This is because you must use the serial number of your current \*(CO system. If you do not know your system's serial number, read the file .BR /etc/serialno and write down its contents on a piece of paper. Be sure to write the number correctly, or \*(CO will complain when you attempt to update it. .SH "Recent Enhancements" .PP \*(CO includes many new features: .IP \(bu 0.3i Improved support for third-party packages. The UNIX System-V editions of Lotus and WordPerfect now work out of the box. .IP \(bu Support for X Windows. An X Windows package is now available for \*(CO from Mark Williams Company. .IP \(bu A rewritten version of the \*(CO kernel. The kernel now includes \*(ST, the \*(UN system for portable device drivers; .IP \(bu Many new system calls, including support for the .B sigset() and .B sigaction() families of signal-handling system calls; and \*(UN System-V interprocess comunications, including shared memory, semaphores, and messages queues. .IP \(bu Tools for configuring and rebuilding the kernel. With release 4.2, you can change kernel variables, add or delete drivers, and modify driver variables, then build a new bootable kernel. .IP \(bu Support for peripheral devices has been expanded. Devices support now include SCSI tape and a variety of SCSI devices. The console has been rewritten to be more robust and to conform more closely to accepted \*(UN standards. The keyboard driver has been expanded and now supports more languages, including Greek. .IP \(bu An improved compiler, linker, and assembler. These include a completely restructured set of header files, which bring \*(CO closer to the \*(PX standard; support for mathematics co-processors; and a greatly improved version of the \*(CO debugger .BR db . .IP \(bu The visual shell .BR vsh . This shell uses drop-down menus, function keys, and single-key commands to give you a simple, clear interface to the \*(CO system; yet it works on a character-based terminal. .IP \(bu The Taylor \*(UU package. This is a more robust and flexible version of \*(UU. .IP \(bu The MLP print spooler. This spooler is modelled after the \*(UN command .BR lp . You now can have multiple printers of any type plugged into your \*(CO systems, and access them via parallel ports, serial ports, or the auxiliary port on a terminal. .IP \(bu A more robust version of the .B curses library, including support for eight-bit characters and color. .IP \(bu .B troff now supports eight-bit character sets. .B troff now comes with tools to ``cook'' loadable PostScript fonts, and to access fonts built into the Hewlett-Packard LaserJet III. .IP \(bu Improved versions of the Bourne shell .B sh and the Korn shell .BR ksh . Many bugs have been fixed, and the Bourne shell now supports shell functions. .PP The following new commands have been added to \*(CO: .nf .sp \n(pDu .tc . 0.1i .ta 1.25i \fBalmanac\fR Print a listing of the events on today's date in history \fBapropos\fR Find the Lexicon entries that relate to a given topic \fBasymkdev\fR Create a node for asynchronous devices \fBcancel\fR Cancel a print job \fBchreq\fR Change a job's priority, life expectancy, or output device \fBcohtune\fR Change the value of a flag or variable in a \*(CO device driver \fBcu\fR \*(UN-style communications program \fBfmt\fR Adjust the length of lines in a file of text \fBfwtable\fR Build a \fBtroff\fR font-width table from a PCL or PostScript ``soft font'' \fBgnucpio\fR GNU version of the \fBcpio\fR archiver \fBgtar\fR GNU version of the \fBtar\fR tape archiver \fBgzip\fR Industry-standard compression tool from the Free Software Foundation \fBidenable\fR Add a device driver to the \*(CO kernel, or delete a driver from it \fBidmkcoh\fR Build a new bootable kernel \fBlcasep\fR Convert text to lower case \fBidtune\fR Set the value of a ``tunable'' variable in the \*(CO kernel \fBipcrm\fR Remove an interprocess-communication item from memory \fBipcs\fR Display a snapshot of interprocess communications \fBlp\fR Spool a job for printing via the MLP spooler \fBlpadmin\fR Administer the MLP spooler \fBlpsched\fR Turn on the \fBlp\fR print spooler \fBlpshut\fR Turn off the \fBlp\fR print spooler \fBlpstat\fR Give the status of a printer or job spooled through the MLP spooler \fBpclfont\fR Prepare a PCL for downloading via MLP \fBPSfont\fR Cook an Adobe font into downloadable PostScript \fBreprint\fR Reprint a spooled job \fBroute\fR Show or reset a user's default printer \fBtape\fR Manipulate the tape device \fBttytype\fR Set the default types of remote terminals \fBvsh\fR Invoke the \*(CO visual shell .PP For more information on any command, see its entry in the Lexicon. .SH "How to Use These Notes" .PP This pamphlet consists of the following sections: .IP \fB1.\fR 0.3i The introduction \(em that is, the section you are reading right now. .IP \fB2.\fR List of hardware. This section lists hardware that we know works with \*(CO, and equipment that we know does \fInot\fR work with \*(CO. Check your equipment against this list .I before you begin installation. .IP \fB3.\fR Installation guide. This section walks you through the process of installing \*(CO on your computer. \fIThis section is for users who do not yet have \*(CO on their computers.\fR In the off chance that something goes wrong during installation, this section also describes problems that have occurred to some users, and how to work around them. .IP \fB4.\fR Update guide. \fIThis section is for users who already have \*(CO, and are upgrading to \*(CO release 4.2.\fR .IP \fB5.\fR Third-party software. This section details software available for \*(CO, including those available from Mark Williams Company and from third-party vendors. Because \*(CO can run many packages designed for \*(UN, the list of software that runs on \*(CO is growing daily. Check the Mark Williams BBS for the latest list of available software. .IP \fB6.\fR Running third-party software. This gives directions on to make any necessary minor configuration changes so you can install and run the most popular third-party packages. .IP \fB7.\fR Bulletin board and user groups. This section describes how to dial into the Mark Williams Bulletin Board. This BBS gives you access to public-domain software that has been ported to \*(CO. It gives new versions of device drivers, technical-support bulletins, product announcements, and bug fixes. You can also exchange mail with the Mark Williams technical support staff and other \*(CO users. .IP This section also introduces \*(CO user groups. This section describes \*(CO user groups throughout the world, and how you can contact them. It also describes how you can form a \*(CO user group and register it with Mark Williams Company. .IP \fB8.\fR Notes and errata. This section describes helpful hints that were discovered after the manual went to press. This section also lists bugs that have been found in this version of \*(CO, but have not yet been fixed. Please note that as soon as a bug is fixed, you can download the corrected version of the program in question from the Mark Williams BBS. It also summarizes corrections and changes in the Lexicon that have been made since the manual was last printed, and that are available in the on-line Lexicon. .PP Read these notes through before you do anything else. Then check your hardware against the machines listed in the following section. If you do not find a discrepancy between your machine and what is given in this section, then continue on to the installation or upgrade section, and load \*(CO onto your system. .SH "Contacting Mark Williams Technical Support" .PP Mark Williams Company has a team of technical support specialists who are skilled at helping you solve the problems you encounter with \*(CO. .PP The technical support staff try to respond promptly to all inquiries, whether by telephone, FAX, e-mail, or ordinary mail. Sometimes, however, we receive e-mail from a customer only to find that our reply message is undeliverable. Therefore, if you send us e-mail, please also include a FAX number or telephone number, or mailing address. This will help ensure that we can contact you with our reply; after all, if we can't reach you, we can't help you solve your problem. .PP To get the most out of your discussion with Technical Support, please follow these guidelines: .IP \fB1.\fR 0.3i Have your \*(CO serial number at hand. .IP \fB2.\fR Know the hardware configuration you are using. This includes make and model for your motherboard, BIOS, hard drive, and any add-in cards. .IP \fB3.\fR Have an exact description of the problem. If you are getting an error message or \*(QLpanic\*(QR message, write down \fIexactly\fR what appears on the screen. If a certain file, such as a C program or \fBnroff\fR document, causes a problem, try to whittle the file down to the smallest size that duplicates the problem, then mail the file on a floppy disk to Mark Williams Company. .IP \fB4.\fR If you are having problems with \*(UU, please log in as .B root (the super-user) and enter the command .BR uulog . If you continue to have problems, have available (and if possible, FAX to us) the contents of the following files: .BR /etc/ttys , .BR /usr/lib/uucp/sys , .BR /usr/lib/uucp/port , and .BR /usr/lib/uucp/dial . Also, execute the following command to log file permissions on key \*(UN files: .DM ls -lR /dev/com* /usr/lib/uucp /usr/spool/uucp >/tmp/MWC.info .DE Fax a hardcopy of file .B /tmp/MWC.info or copy the file onto a floppy and mail it to the Mark Williams Company Technical Support department. .IP \fB6.\fR If possible, call us when you are at your computer, with the computer turned on, so we can ``walk you through' any diagnostic or repair measures needed. .IP \fB7.\fR For information on how to contact Mark Williams Company, see the copyright page of this pamphlet.
Description: Stumps from dead trees that were drowned when the lake level was raised in the 1920s to generate electricity. This picture was taken by Monowai Hut. Lake Monowai is a large lake (31 km²) in the southern part of Fiordland National Park.
(* Title: HOL/Auth/n_germanSimp_lemma_inv__56_on_rules.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_germanSimp Protocol Case Study*} theory n_germanSimp_lemma_inv__56_on_rules imports n_germanSimp_lemma_on_inv__56 begin section{*All lemmas on causal relation between inv__56*} lemma lemma_inv__56_on_rules: assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__56 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" proof - have c1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__0 N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__1 N i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" apply (cut_tac b1, auto) done moreover { assume d1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_StoreVsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqSVsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__0 N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqE__part__0Vsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__1 N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqE__part__1Vsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInvAckVsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntSVsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntEVsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntSVsinv__56) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntEVsinv__56) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
If $f$ is continuous on the closed interval $[a,b]$, then $f$ attains its supremum on $[a,b]$.
[GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f g : X ⟶ Y inst✝ : HasEqualizer f g ⊢ (equalizerSubobjectIso f g).hom ≫ equalizer.ι f g = arrow (equalizerSubobject f g) [PROOFSTEP] simp [equalizerSubobjectIso] [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f g : X ⟶ Y inst✝ : HasEqualizer f g ⊢ (equalizerSubobjectIso f g).inv ≫ arrow (equalizerSubobject f g) = equalizer.ι f g [PROOFSTEP] simp [equalizerSubobjectIso] [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f g : X ⟶ Y inst✝ : HasEqualizer f g ⊢ arrow (equalizerSubobject f g) ≫ f = arrow (equalizerSubobject f g) ≫ g [PROOFSTEP] rw [← equalizerSubobject_arrow, Category.assoc, Category.assoc, equalizer.condition] [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f g : X ⟶ Y inst✝ : HasEqualizer f g W : C h : W ⟶ X w : h ≫ f = h ≫ g ⊢ equalizer.lift h w ≫ MonoOver.arrow (MonoOver.mk' (equalizer.ι f g)) = h [PROOFSTEP] simp [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f g : X ⟶ Y inst✝ : HasEqualizer f g W : C h : W ⟶ X w : Factors (equalizerSubobject f g) h ⊢ h ≫ f = h ≫ g [PROOFSTEP] rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, equalizerSubobject_arrow_comp, Category.assoc] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f ⊢ (kernelSubobjectIso f).hom ≫ kernel.ι f = arrow (kernelSubobject f) [PROOFSTEP] simp [kernelSubobjectIso] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f ⊢ (kernelSubobjectIso f).inv ≫ arrow (kernelSubobject f) = kernel.ι f [PROOFSTEP] simp [kernelSubobjectIso] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f ⊢ arrow (kernelSubobject f) ≫ f = 0 [PROOFSTEP] rw [← kernelSubobject_arrow] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f ⊢ ((kernelSubobjectIso f).hom ≫ kernel.ι f) ≫ f = 0 [PROOFSTEP] simp only [Category.assoc, kernel.condition, comp_zero] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f W : C h : W ⟶ X w : h ≫ f = 0 ⊢ kernel.lift f h w ≫ MonoOver.arrow (MonoOver.mk' (kernel.ι f)) = h [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f W : C h : W ⟶ X w : Factors (kernelSubobject f) h ⊢ h ≫ f = 0 [PROOFSTEP] rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, kernelSubobject_arrow_comp, comp_zero] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f W : C h : W ⟶ X w : h ≫ f = 0 ⊢ factorThruKernelSubobject f h w ≫ arrow (kernelSubobject f) = h [PROOFSTEP] dsimp [factorThruKernelSubobject] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f W : C h : W ⟶ X w : h ≫ f = 0 ⊢ factorThru (kernelSubobject f) h (_ : Factors (kernelSubobject f) h) ≫ arrow (kernelSubobject f) = h [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f W : C h : W ⟶ X w : h ≫ f = 0 ⊢ (factorThruKernelSubobject f h w ≫ (kernelSubobjectIso f).hom) ≫ kernel.ι f = kernel.lift f h w ≫ kernel.ι f [PROOFSTEP] simp [GOAL] C : Type u inst✝³ : Category.{v, u} C X Y Z : C inst✝² : HasZeroMorphisms C f : X ⟶ Y inst✝¹ : HasKernel f X' Y' : C f' : X' ⟶ Y' inst✝ : HasKernel f' sq : Arrow.mk f ⟶ Arrow.mk f' ⊢ (arrow (kernelSubobject f) ≫ sq.left) ≫ f' = 0 [PROOFSTEP] simp [sq.w] [GOAL] C : Type u inst✝³ : Category.{v, u} C X Y Z : C inst✝² : HasZeroMorphisms C f : X ⟶ Y inst✝¹ : HasKernel f X' Y' : C f' : X' ⟶ Y' inst✝ : HasKernel f' sq : Arrow.mk f ⟶ Arrow.mk f' ⊢ kernelSubobjectMap sq ≫ arrow (kernelSubobject f') = arrow (kernelSubobject f) ≫ sq.left [PROOFSTEP] simp [kernelSubobjectMap] [GOAL] C : Type u inst✝³ : Category.{v, u} C X Y Z : C inst✝² : HasZeroMorphisms C f : X ⟶ Y inst✝¹ : HasKernel f X' Y' : C f' : X' ⟶ Y' inst✝ : HasKernel f' ⊢ kernelSubobjectMap (𝟙 (Arrow.mk f)) = 𝟙 (underlying.obj (kernelSubobject f)) [PROOFSTEP] aesop_cat [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z : C inst✝³ : HasZeroMorphisms C f : X ⟶ Y inst✝² : HasKernel f X' Y' : C f' : X' ⟶ Y' inst✝¹ : HasKernel f' X'' Y'' : C f'' : X'' ⟶ Y'' inst✝ : HasKernel f'' sq : Arrow.mk f ⟶ Arrow.mk f' sq' : Arrow.mk f' ⟶ Arrow.mk f'' ⊢ kernelSubobjectMap (sq ≫ sq') = kernelSubobjectMap sq ≫ kernelSubobjectMap sq' [PROOFSTEP] aesop_cat [GOAL] C : Type u inst✝³ : Category.{v, u} C X Y Z : C inst✝² : HasZeroMorphisms C f : X ⟶ Y inst✝¹ : HasKernel f X' Y' : C f' : X' ⟶ Y' inst✝ : HasKernel f' sq : Arrow.mk f ⟶ Arrow.mk f' ⊢ kernel.map f f' sq.left sq.right (_ : (Arrow.mk f).hom ≫ (𝟭 C).map sq.right = (𝟭 C).map sq.left ≫ (Arrow.mk f').hom) ≫ (kernelSubobjectIso f').inv = (kernelSubobjectIso f).inv ≫ kernelSubobjectMap sq [PROOFSTEP] aesop_cat [GOAL] C : Type u inst✝³ : Category.{v, u} C X Y Z : C inst✝² : HasZeroMorphisms C f : X ⟶ Y inst✝¹ : HasKernel f X' Y' : C f' : X' ⟶ Y' inst✝ : HasKernel f' sq : Arrow.mk f ⟶ Arrow.mk f' ⊢ (kernelSubobjectIso f).hom ≫ kernel.map f f' sq.left sq.right (_ : (Arrow.mk f).hom ≫ (𝟭 C).map sq.right = (𝟭 C).map sq.left ≫ (Arrow.mk f').hom) = kernelSubobjectMap sq ≫ (kernelSubobjectIso f').hom [PROOFSTEP] simp [← Iso.comp_inv_eq, kernel_map_comp_kernelSubobjectIso_inv] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f A B : C ⊢ IsIso (kernel.ι 0) [PROOFSTEP] infer_instance [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C inst✝¹ : HasZeroMorphisms C f : X ⟶ Y inst✝ : HasKernel f A : Subobject X h : arrow A ≫ f = 0 ⊢ kernel.lift f (arrow A) h ≫ kernel.ι f = arrow A [PROOFSTEP] simp [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z : C inst✝³ : HasZeroMorphisms C f✝ : X ⟶ Y inst✝² : HasKernel f✝ X' : C f : X' ⟶ X inst✝¹ : IsIso f g : X ⟶ Y inst✝ : HasKernel g ⊢ (kernelSubobjectIsoComp f g).hom ≫ arrow (kernelSubobject g) = arrow (kernelSubobject (f ≫ g)) ≫ f [PROOFSTEP] simp [kernelSubobjectIsoComp] [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z : C inst✝³ : HasZeroMorphisms C f✝ : X ⟶ Y inst✝² : HasKernel f✝ X' : C f : X' ⟶ X inst✝¹ : IsIso f g : X ⟶ Y inst✝ : HasKernel g ⊢ (kernelSubobjectIsoComp f g).inv ≫ arrow (kernelSubobject (f ≫ g)) = arrow (kernelSubobject g) ≫ inv f [PROOFSTEP] simp [kernelSubobjectIsoComp] [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z✝ : C inst✝³ : HasZeroMorphisms C f✝ : X ⟶ Y inst✝² : HasKernel f✝ f : X ⟶ Y inst✝¹ : HasKernel f Z : C h : Y ⟶ Z inst✝ : HasKernel (f ≫ h) ⊢ arrow (kernelSubobject f) ≫ f ≫ h = 0 [PROOFSTEP] simp [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z✝ : C inst✝³ : HasZeroMorphisms C f✝ : X ⟶ Y inst✝² : HasKernel f✝ f : X ⟶ Y inst✝¹ : HasKernel f Z : C h : Y ⟶ Z inst✝ : Mono h ⊢ (arrow (kernelSubobject (f ≫ h)) ≫ f) ≫ h = 0 ≫ h [PROOFSTEP] simp [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z✝ : C inst✝³ : HasZeroMorphisms C f✝ : X ⟶ Y inst✝² : HasKernel f✝ f : X ⟶ Y inst✝¹ : HasKernel f Z : C h : Y ⟶ Z inst✝ : Mono h ⊢ IsIso (ofLE (kernelSubobject f) (kernelSubobject (f ≫ h)) (_ : kernelSubobject f ≤ kernelSubobject (f ≫ h))) [PROOFSTEP] rw [ofLE_mk_le_mk_of_comm (kernelCompMono f h).inv] [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z✝ : C inst✝³ : HasZeroMorphisms C f✝ : X ⟶ Y inst✝² : HasKernel f✝ f : X ⟶ Y inst✝¹ : HasKernel f Z : C h : Y ⟶ Z inst✝ : Mono h ⊢ IsIso ((underlyingIso (kernel.ι f)).hom ≫ (kernelCompMono f h).inv ≫ (underlyingIso (kernel.ι (f ≫ h))).inv) [PROOFSTEP] infer_instance [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z✝ : C inst✝³ : HasZeroMorphisms C f✝ : X ⟶ Y inst✝² : HasKernel f✝ f : X ⟶ Y inst✝¹ : HasKernel f Z : C h : Y ⟶ Z inst✝ : Mono h ⊢ (kernelCompMono f h).inv ≫ kernel.ι (f ≫ h) = kernel.ι f [PROOFSTEP] simp [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasCokernels C X : C ⊢ ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [inst : Mono f] [inst_1 : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (cokernel.π f).op) A f inst = (fun A f x => Subobject.mk (cokernel.π f).op) B g inst_1 [PROOFSTEP] rintro A B f g hf hg i rfl [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasCokernels C X A B : C g : B ⟶ X hg : Mono g i : A ≅ B hf : Mono (i.hom ≫ g) ⊢ (fun A f x => Subobject.mk (cokernel.π f).op) A (i.hom ≫ g) hf = (fun A f x => Subobject.mk (cokernel.π f).op) B g hg [PROOFSTEP] refine' Subobject.mk_eq_mk_of_comm _ _ (Iso.op _) (Quiver.Hom.unop_inj _) [GOAL] case refine'_1 C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasCokernels C X A B : C g : B ⟶ X hg : Mono g i : A ≅ B hf : Mono (i.hom ≫ g) ⊢ cokernel g ≅ cokernel (i.hom ≫ g) [PROOFSTEP] exact (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isCokernelEpiComp (colimit.isColimit _) i.hom rfl)).symm [GOAL] case refine'_2 C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasCokernels C X A B : C g : B ⟶ X hg : Mono g i : A ≅ B hf : Mono (i.hom ≫ g) ⊢ ((Iso.op (IsColimit.coconePointUniqueUpToIso (colimit.isColimit (parallelPair (i.hom ≫ g) 0)) (isCokernelEpiComp (colimit.isColimit (parallelPair g 0)) i.hom (_ : i.hom ≫ g = i.hom ≫ g))).symm).hom ≫ (cokernel.π g).op).unop = (cokernel.π (i.hom ≫ g)).op.unop [PROOFSTEP] simp only [Iso.comp_inv_eq, Iso.op_hom, Iso.symm_hom, unop_comp, Quiver.Hom.unop_op, colimit.comp_coconePointUniqueUpToIso_hom, Cofork.ofπ_ι_app, coequalizer.cofork_π] [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasCokernels C X : C ⊢ ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [inst : Mono f] [inst_1 : Mono g], Subobject.mk f ≤ Subobject.mk g → Subobject.lift (fun A f x => Subobject.mk (cokernel.π f).op) (_ : ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [hf : Mono f] [hg : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (cokernel.π f).op) A f hf = (fun A f x => Subobject.mk (cokernel.π f).op) B g hg) (Subobject.mk f) ≤ Subobject.lift (fun A f x => Subobject.mk (cokernel.π f).op) (_ : ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [hf : Mono f] [hg : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (cokernel.π f).op) A f hf = (fun A f x => Subobject.mk (cokernel.π f).op) B g hg) (Subobject.mk g) [PROOFSTEP] intro A B f g hf hg h [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f✝ : X✝ ⟶ Y inst✝¹ : HasKernel f✝ inst✝ : HasCokernels C X A B : C f : A ⟶ X g : B ⟶ X hf : Mono f hg : Mono g h : Subobject.mk f ≤ Subobject.mk g ⊢ Subobject.lift (fun A f x => Subobject.mk (cokernel.π f).op) (_ : ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [hf : Mono f] [hg : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (cokernel.π f).op) A f hf = (fun A f x => Subobject.mk (cokernel.π f).op) B g hg) (Subobject.mk f) ≤ Subobject.lift (fun A f x => Subobject.mk (cokernel.π f).op) (_ : ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [hf : Mono f] [hg : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (cokernel.π f).op) A f hf = (fun A f x => Subobject.mk (cokernel.π f).op) B g hg) (Subobject.mk g) [PROOFSTEP] dsimp only [Subobject.lift_mk] [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f✝ : X✝ ⟶ Y inst✝¹ : HasKernel f✝ inst✝ : HasCokernels C X A B : C f : A ⟶ X g : B ⟶ X hf : Mono f hg : Mono g h : Subobject.mk f ≤ Subobject.mk g ⊢ Subobject.mk (cokernel.π f).op ≤ Subobject.mk (cokernel.π g).op [PROOFSTEP] refine' Subobject.mk_le_mk_of_comm (cokernel.desc f (cokernel.π g) _).op _ [GOAL] case refine'_1 C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f✝ : X✝ ⟶ Y inst✝¹ : HasKernel f✝ inst✝ : HasCokernels C X A B : C f : A ⟶ X g : B ⟶ X hf : Mono f hg : Mono g h : Subobject.mk f ≤ Subobject.mk g ⊢ f ≫ cokernel.π g = 0 [PROOFSTEP] rw [← Subobject.ofMkLEMk_comp h, Category.assoc, cokernel.condition, comp_zero] [GOAL] case refine'_2 C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f✝ : X✝ ⟶ Y inst✝¹ : HasKernel f✝ inst✝ : HasCokernels C X A B : C f : A ⟶ X g : B ⟶ X hf : Mono f hg : Mono g h : Subobject.mk f ≤ Subobject.mk g ⊢ (cokernel.desc f (cokernel.π g) (_ : f ≫ cokernel.π g = 0)).op ≫ (cokernel.π f).op = (cokernel.π g).op [PROOFSTEP] exact Quiver.Hom.unop_inj (cokernel.π_desc _ _ _) [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasKernels C X : C ⊢ ∀ ⦃A B : Cᵒᵖ⦄ (f : A ⟶ op X) (g : B ⟶ op X) [inst : Mono f] [inst_1 : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (kernel.ι f.unop)) A f inst = (fun A f x => Subobject.mk (kernel.ι f.unop)) B g inst_1 [PROOFSTEP] rintro A B f g hf hg i rfl [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasKernels C X : C A B : Cᵒᵖ g : B ⟶ op X hg : Mono g i : A ≅ B hf : Mono (i.hom ≫ g) ⊢ (fun A f x => Subobject.mk (kernel.ι f.unop)) A (i.hom ≫ g) hf = (fun A f x => Subobject.mk (kernel.ι f.unop)) B g hg [PROOFSTEP] refine' Subobject.mk_eq_mk_of_comm _ _ _ _ [GOAL] case refine'_1 C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasKernels C X : C A B : Cᵒᵖ g : B ⟶ op X hg : Mono g i : A ≅ B hf : Mono (i.hom ≫ g) ⊢ kernel (i.hom ≫ g).unop ≅ kernel g.unop [PROOFSTEP] exact IsLimit.conePointUniqueUpToIso (limit.isLimit _) (isKernelCompMono (limit.isLimit (parallelPair g.unop 0)) i.unop.hom rfl) [GOAL] case refine'_2 C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasKernels C X : C A B : Cᵒᵖ g : B ⟶ op X hg : Mono g i : A ≅ B hf : Mono (i.hom ≫ g) ⊢ (IsLimit.conePointUniqueUpToIso (limit.isLimit (parallelPair (g.unop ≫ (Iso.unop i).hom) 0)) (isKernelCompMono (limit.isLimit (parallelPair g.unop 0)) (Iso.unop i).hom (_ : g.unop ≫ (Iso.unop i).hom = g.unop ≫ (Iso.unop i).hom))).hom ≫ kernel.ι g.unop = kernel.ι (i.hom ≫ g).unop [PROOFSTEP] dsimp [GOAL] case refine'_2 C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasKernels C X : C A B : Cᵒᵖ g : B ⟶ op X hg : Mono g i : A ≅ B hf : Mono (i.hom ≫ g) ⊢ (IsLimit.conePointUniqueUpToIso (limit.isLimit (parallelPair (g.unop ≫ i.hom.unop) 0)) (isKernelCompMono (limit.isLimit (parallelPair g.unop 0)) i.hom.unop (_ : g.unop ≫ i.hom.unop = g.unop ≫ i.hom.unop))).hom ≫ kernel.ι g.unop = kernel.ι (g.unop ≫ i.hom.unop) [PROOFSTEP] simp only [← Iso.eq_inv_comp, limit.conePointUniqueUpToIso_inv_comp, Fork.ofι_π_app] [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f : X✝ ⟶ Y inst✝¹ : HasKernel f inst✝ : HasKernels C X : C ⊢ ∀ ⦃A B : Cᵒᵖ⦄ (f : A ⟶ op X) (g : B ⟶ op X) [inst : Mono f] [inst_1 : Mono g], Subobject.mk f ≤ Subobject.mk g → Subobject.lift (fun A f x => Subobject.mk (kernel.ι f.unop)) (_ : ∀ ⦃A B : Cᵒᵖ⦄ (f : A ⟶ op X) (g : B ⟶ op X) [hf : Mono f] [hg : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (kernel.ι f.unop)) A f hf = (fun A f x => Subobject.mk (kernel.ι f.unop)) B g hg) (Subobject.mk f) ≤ Subobject.lift (fun A f x => Subobject.mk (kernel.ι f.unop)) (_ : ∀ ⦃A B : Cᵒᵖ⦄ (f : A ⟶ op X) (g : B ⟶ op X) [hf : Mono f] [hg : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (kernel.ι f.unop)) A f hf = (fun A f x => Subobject.mk (kernel.ι f.unop)) B g hg) (Subobject.mk g) [PROOFSTEP] intro A B f g hf hg h [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f✝ : X✝ ⟶ Y inst✝¹ : HasKernel f✝ inst✝ : HasKernels C X : C A B : Cᵒᵖ f : A ⟶ op X g : B ⟶ op X hf : Mono f hg : Mono g h : Subobject.mk f ≤ Subobject.mk g ⊢ Subobject.lift (fun A f x => Subobject.mk (kernel.ι f.unop)) (_ : ∀ ⦃A B : Cᵒᵖ⦄ (f : A ⟶ op X) (g : B ⟶ op X) [hf : Mono f] [hg : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (kernel.ι f.unop)) A f hf = (fun A f x => Subobject.mk (kernel.ι f.unop)) B g hg) (Subobject.mk f) ≤ Subobject.lift (fun A f x => Subobject.mk (kernel.ι f.unop)) (_ : ∀ ⦃A B : Cᵒᵖ⦄ (f : A ⟶ op X) (g : B ⟶ op X) [hf : Mono f] [hg : Mono g] (i : A ≅ B), i.hom ≫ g = f → (fun A f x => Subobject.mk (kernel.ι f.unop)) A f hf = (fun A f x => Subobject.mk (kernel.ι f.unop)) B g hg) (Subobject.mk g) [PROOFSTEP] dsimp only [Subobject.lift_mk] [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f✝ : X✝ ⟶ Y inst✝¹ : HasKernel f✝ inst✝ : HasKernels C X : C A B : Cᵒᵖ f : A ⟶ op X g : B ⟶ op X hf : Mono f hg : Mono g h : Subobject.mk f ≤ Subobject.mk g ⊢ Subobject.mk (kernel.ι f.unop) ≤ Subobject.mk (kernel.ι g.unop) [PROOFSTEP] refine' Subobject.mk_le_mk_of_comm (kernel.lift g.unop (kernel.ι f.unop) _) _ [GOAL] case refine'_1 C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f✝ : X✝ ⟶ Y inst✝¹ : HasKernel f✝ inst✝ : HasKernels C X : C A B : Cᵒᵖ f : A ⟶ op X g : B ⟶ op X hf : Mono f hg : Mono g h : Subobject.mk f ≤ Subobject.mk g ⊢ kernel.ι f.unop ≫ g.unop = 0 [PROOFSTEP] rw [← Subobject.ofMkLEMk_comp h, unop_comp, kernel.condition_assoc, zero_comp] [GOAL] case refine'_2 C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f✝ : X✝ ⟶ Y inst✝¹ : HasKernel f✝ inst✝ : HasKernels C X : C A B : Cᵒᵖ f : A ⟶ op X g : B ⟶ op X hf : Mono f hg : Mono g h : Subobject.mk f ≤ Subobject.mk g ⊢ kernel.lift g.unop (kernel.ι f.unop) (_ : kernel.ι f.unop ≫ g.unop = 0) ≫ kernel.ι g.unop = kernel.ι f.unop [PROOFSTEP] exact Quiver.Hom.op_inj (by simp) [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C inst✝² : HasZeroMorphisms C f✝ : X✝ ⟶ Y inst✝¹ : HasKernel f✝ inst✝ : HasKernels C X : C A B : Cᵒᵖ f : A ⟶ op X g : B ⟶ op X hf : Mono f hg : Mono g h : Subobject.mk f ≤ Subobject.mk g ⊢ (kernel.lift g.unop (kernel.ι f.unop) (_ : kernel.ι f.unop ≫ g.unop = 0) ≫ kernel.ι g.unop).op = (kernel.ι f.unop).op [PROOFSTEP] simp [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝ : HasImage f ⊢ (imageSubobjectIso f).hom ≫ image.ι f = arrow (imageSubobject f) [PROOFSTEP] simp [imageSubobjectIso] [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝ : HasImage f ⊢ (imageSubobjectIso f).inv ≫ arrow (imageSubobject f) = image.ι f [PROOFSTEP] simp [imageSubobjectIso] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝¹ : HasImage f inst✝ : HasEqualizers C ⊢ Epi (factorThruImageSubobject f) [PROOFSTEP] dsimp [factorThruImageSubobject] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝¹ : HasImage f inst✝ : HasEqualizers C ⊢ Epi (factorThruImage f ≫ (imageSubobjectIso f).inv) [PROOFSTEP] apply epi_comp [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝ : HasImage f ⊢ factorThruImageSubobject f ≫ arrow (imageSubobject f) = f [PROOFSTEP] simp [factorThruImageSubobject, imageSubobject_arrow] [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X✝ Y✝ Z✝ : C f✝ : X✝ ⟶ Y✝ inst✝³ : HasImage f✝ inst✝² : HasZeroMorphisms C X Y Z : C f : X ⟶ Y g : Y ⟶ Z inst✝¹ : HasImage f inst✝ : Epi (factorThruImageSubobject f) h : f ≫ g = 0 ⊢ factorThruImageSubobject f ≫ arrow (imageSubobject f) ≫ g = 0 [PROOFSTEP] simp [h] [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝ : HasImage f W : C k : W ⟶ X ⊢ (k ≫ factorThruImage f) ≫ MonoOver.arrow (MonoOver.mk' (image.ι f)) = k ≫ f [PROOFSTEP] simp [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝ : HasImage f W : C k : W ⟶ X h : Factors (imageSubobject f) (k ≫ f) ⊢ factorThru (imageSubobject f) (k ≫ f) h = k ≫ factorThruImageSubobject f [PROOFSTEP] ext [GOAL] case h C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝ : HasImage f W : C k : W ⟶ X h : Factors (imageSubobject f) (k ≫ f) ⊢ factorThru (imageSubobject f) (k ≫ f) h ≫ arrow (imageSubobject f) = (k ≫ factorThruImageSubobject f) ≫ arrow (imageSubobject f) [PROOFSTEP] simp [GOAL] C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝ : HasImage f W W' : C k : W ⟶ W' k' : W' ⟶ X h : Factors (imageSubobject f) (k ≫ k' ≫ f) ⊢ factorThru (imageSubobject f) (k ≫ k' ≫ f) h = k ≫ k' ≫ factorThruImageSubobject f [PROOFSTEP] ext [GOAL] case h C : Type u inst✝¹ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝ : HasImage f W W' : C k : W ⟶ W' k' : W' ⟶ X h : Factors (imageSubobject f) (k ≫ k' ≫ f) ⊢ factorThru (imageSubobject f) (k ≫ k' ≫ f) h ≫ arrow (imageSubobject f) = (k ≫ k' ≫ factorThruImageSubobject f) ≫ arrow (imageSubobject f) [PROOFSTEP] simp [GOAL] C : Type u inst✝³ : Category.{v, u} C X Y Z : C f✝ : X ⟶ Y inst✝² : HasImage f✝ X' : C h : X' ⟶ X f : X ⟶ Y inst✝¹ : HasImage f inst✝ : HasImage (h ≫ f) ⊢ image.preComp h f ≫ image.ι f = image.ι (h ≫ f) [PROOFSTEP] simp [GOAL] C : Type u inst✝³ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝² : HasImage f inst✝¹ : HasZeroMorphisms C inst✝ : HasZeroObject C ⊢ arrow (imageSubobject 0) = 0 [PROOFSTEP] rw [← imageSubobject_arrow] [GOAL] C : Type u inst✝³ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝² : HasImage f inst✝¹ : HasZeroMorphisms C inst✝ : HasZeroObject C ⊢ (imageSubobjectIso 0).hom ≫ image.ι 0 = 0 [PROOFSTEP] simp [GOAL] C : Type u inst✝³ : Category.{v, u} C X Y Z : C f : X ⟶ Y inst✝² : HasImage f inst✝¹ : HasZeroMorphisms C inst✝ : HasZeroObject C A B : C ⊢ (imageSubobjectIso 0 ≪≫ imageZero ≪≫ botCoeIsoZero.symm).hom ≫ arrow ⊥ = arrow (imageSubobject 0) [PROOFSTEP] simp [GOAL] C : Type u inst✝⁵ : Category.{v, u} C X Y Z : C f✝ : X ⟶ Y inst✝⁴ : HasImage f✝ inst✝³ : HasEqualizers C X' : C h : X' ⟶ X inst✝² : Epi h f : X ⟶ Y inst✝¹ : HasImage f inst✝ : HasImage (h ≫ f) ⊢ Epi (ofLE (imageSubobject (h ≫ f)) (imageSubobject f) (_ : imageSubobject (h ≫ f) ≤ imageSubobject f)) [PROOFSTEP] rw [ofLE_mk_le_mk_of_comm (image.preComp h f)] [GOAL] C : Type u inst✝⁵ : Category.{v, u} C X Y Z : C f✝ : X ⟶ Y inst✝⁴ : HasImage f✝ inst✝³ : HasEqualizers C X' : C h : X' ⟶ X inst✝² : Epi h f : X ⟶ Y inst✝¹ : HasImage f inst✝ : HasImage (h ≫ f) ⊢ Epi ((underlyingIso (image.ι (h ≫ f))).hom ≫ image.preComp h f ≫ (underlyingIso (image.ι f)).inv) [PROOFSTEP] infer_instance [GOAL] C : Type u inst✝⁵ : Category.{v, u} C X Y Z : C f✝ : X ⟶ Y inst✝⁴ : HasImage f✝ inst✝³ : HasEqualizers C X' : C h : X' ⟶ X inst✝² : Epi h f : X ⟶ Y inst✝¹ : HasImage f inst✝ : HasImage (h ≫ f) ⊢ image.preComp h f ≫ image.ι f = image.ι (h ≫ f) [PROOFSTEP] simp [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z : C f✝ : X ⟶ Y inst✝³ : HasImage f✝ inst✝² : HasEqualizers C f : X ⟶ Y inst✝¹ : HasImage f Y' : C h : Y ⟶ Y' inst✝ : IsIso h ⊢ (imageSubobjectCompIso f h).hom ≫ arrow (imageSubobject f) = arrow (imageSubobject (f ≫ h)) ≫ inv h [PROOFSTEP] simp [imageSubobjectCompIso] [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z : C f✝ : X ⟶ Y inst✝³ : HasImage f✝ inst✝² : HasEqualizers C f : X ⟶ Y inst✝¹ : HasImage f Y' : C h : Y ⟶ Y' inst✝ : IsIso h ⊢ (imageSubobjectCompIso f h).inv ≫ arrow (imageSubobject (f ≫ h)) = arrow (imageSubobject f) ≫ h [PROOFSTEP] simp [imageSubobjectCompIso] [GOAL] C : Type u inst✝² : Category.{v, u} C X Y Z : C f✝ : X ⟶ Y inst✝¹ : HasImage f✝ f : X ⟶ Y inst✝ : Mono f ⊢ (imageSubobjectIso f ≪≫ imageMonoIsoSource f ≪≫ (underlyingIso f).symm).hom ≫ arrow (Subobject.mk f) = arrow (imageSubobject f) [PROOFSTEP] simp [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X Y Z : C f✝ : X ⟶ Y inst✝³ : HasImage f✝ inst✝² : HasEqualizers C X' : C h : X' ⟶ X inst✝¹ : IsIso h f : X ⟶ Y inst✝ : HasImage f ⊢ inv (image.preComp h f) ≫ image.ι (h ≫ f) = image.ι f [PROOFSTEP] simp [GOAL] C : Type u inst✝² : Category.{v, u} C X✝ Y Z : C f✝ : X✝ ⟶ Y inst✝¹ : HasImage f✝ A B : C X : Subobject B f : A ⟶ B inst✝ : HasImage f h : A ⟶ underlying.obj X w : h ≫ arrow X = f ⊢ ((imageSubobjectIso f).hom ≫ image.lift (MonoFactorisation.mk (underlying.obj X) (arrow X) h)) ≫ arrow X = arrow (imageSubobject f) [PROOFSTEP] rw [assoc, image.lift_fac, imageSubobject_arrow] [GOAL] C : Type u inst✝³ : Category.{v, u} C X✝ Y Z : C f✝ : X✝ ⟶ Y inst✝² : HasImage f✝ A B X : C g : X ⟶ B inst✝¹ : Mono g f : A ⟶ B inst✝ : HasImage f h : A ⟶ X w : h ≫ g = f ⊢ (h ≫ (underlyingIso g).inv) ≫ arrow (Subobject.mk g) = f [PROOFSTEP] simp [w] [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X✝ Y✝ Z✝ : C f✝ : X✝ ⟶ Y✝ inst✝³ : HasImage f✝ W X Y Z : C f : W ⟶ X inst✝² : HasImage f g : Y ⟶ Z inst✝¹ : HasImage g sq : Arrow.mk f ⟶ Arrow.mk g inst✝ : HasImageMap sq ⊢ imageSubobjectMap sq ≫ arrow (imageSubobject g) = arrow (imageSubobject f) ≫ sq.right [PROOFSTEP] simp only [imageSubobjectMap, Category.assoc, imageSubobject_arrow'] [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X✝ Y✝ Z✝ : C f✝ : X✝ ⟶ Y✝ inst✝³ : HasImage f✝ W X Y Z : C f : W ⟶ X inst✝² : HasImage f g : Y ⟶ Z inst✝¹ : HasImage g sq : Arrow.mk f ⟶ Arrow.mk g inst✝ : HasImageMap sq ⊢ (imageSubobjectIso f).hom ≫ image.map sq ≫ image.ι g = arrow (imageSubobject f) ≫ sq.right [PROOFSTEP] erw [image.map_ι, ← Category.assoc, imageSubobject_arrow] [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X✝ Y✝ Z✝ : C f✝ : X✝ ⟶ Y✝ inst✝³ : HasImage f✝ W X Y Z : C f : W ⟶ X inst✝² : HasImage f g : Y ⟶ Z inst✝¹ : HasImage g sq : Arrow.mk f ⟶ Arrow.mk g inst✝ : HasImageMap sq ⊢ image.map sq ≫ (imageSubobjectIso (Arrow.mk g).hom).inv = (imageSubobjectIso f).inv ≫ imageSubobjectMap sq [PROOFSTEP] ext [GOAL] case h C : Type u inst✝⁴ : Category.{v, u} C X✝ Y✝ Z✝ : C f✝ : X✝ ⟶ Y✝ inst✝³ : HasImage f✝ W X Y Z : C f : W ⟶ X inst✝² : HasImage f g : Y ⟶ Z inst✝¹ : HasImage g sq : Arrow.mk f ⟶ Arrow.mk g inst✝ : HasImageMap sq ⊢ (image.map sq ≫ (imageSubobjectIso (Arrow.mk g).hom).inv) ≫ arrow (imageSubobject (Arrow.mk g).hom) = ((imageSubobjectIso f).inv ≫ imageSubobjectMap sq) ≫ arrow (imageSubobject (Arrow.mk g).hom) [PROOFSTEP] simpa using image.map_ι sq [GOAL] C : Type u inst✝⁴ : Category.{v, u} C X✝ Y✝ Z✝ : C f✝ : X✝ ⟶ Y✝ inst✝³ : HasImage f✝ W X Y Z : C f : W ⟶ X inst✝² : HasImage f g : Y ⟶ Z inst✝¹ : HasImage g sq : Arrow.mk f ⟶ Arrow.mk g inst✝ : HasImageMap sq ⊢ (imageSubobjectIso (Arrow.mk f).hom).hom ≫ image.map sq = imageSubobjectMap sq ≫ (imageSubobjectIso g).hom [PROOFSTEP] erw [← Iso.comp_inv_eq, Category.assoc, ← (imageSubobjectIso f).eq_inv_comp, image_map_comp_imageSubobjectIso_inv sq]
Galveston is home to two post @-@ secondary institutions offering traditional degrees in higher education . Galveston College , a junior college that opened in 1967 , and Texas A & M University at Galveston , an ocean @-@ oriented branch campus of Texas A & M University .
{-# OPTIONS --without-K #-} module sets.nat.ordering.properties where open import function.isomorphism open import sets.nat.core open import sets.nat.ordering.lt open import sets.nat.ordering.leq open import hott.level.core <-≤-iso : ∀ {n m} → (n < m) ≅ (suc n ≤ m) <-≤-iso = record { to = f ; from = g ; iso₁ = λ _ → h1⇒prop <-level _ _ ; iso₂ = λ _ → h1⇒prop ≤-level _ _ } where f : ∀ {n m} → n < m → suc n ≤ m f suc< = refl-≤ f (n<s p) = s≤s (trans-≤ suc≤ (f p)) g : ∀ {n m} → suc n ≤ m → n < m g {zero} (s≤s p) = z<n g {suc n} (s≤s p) = ap<-suc (g p)
$ifndef _TCON_REFINE_ $define _TCON_REFINE_ $include "Condition.mpl" $include "Utils.mpl" # 简化变换方程的约束条件 tconRefine:=proc(s::TeqSol) s:-tcons:=[map[2](singleRefine,s:-rsol,s:-tcons[1]), map[2](singleRefine,s:-rsol,s:-tcons[2])]; # s:-tcons:=map(x->epDeal~(x),s:-tcons); return s; end proc: # 对于 v[k] 删去 a[k]>0 和 a[k]<0 约束 singleRefine:=proc(rsol,con) local ind,n,rep,vs; n:=numelems(rsol); rep:=add(rsol[i]*v[i],i=1..n); vs:=indets(rep,name); if numelems(vs)<>1 then return con; else vs:=op([1,1],vs); return con minus {a[vs]>0,a[vs]<0}; end if; end proc: # 处理每个可能情况的约束条件 epDeal:=proc(s::set) local ca,ce,r; ce,ca:=selectremove(has,s,epsilon); ce:=ceDeal~(ce); r:=ce union ca; r:=classifySolve(r); return r; end proc: # 单个关于epsilon的条件处理 ceDeal:=proc(e) local rs; # 有的时候solve会抽,对于这种情况不做处理 try rs:=conSolve(e); catch : return e; end try; if numelems(rs)=0 then # 无解则原样返回 return e; elif numelems(rs)=1 then # 只有一个解,则不论有多少条件都可以 return rs[][]; else return e; end if; end proc: # 求解不等式, # 在解中删除自由变量 # 删除和epsilon有关的约束 conSolve:=proc(c) local r; r:=[RealDomain:-solve(c)]; r:=map(x->remove(t->evalb(lhs(t)=rhs(t)),x),r); r:=map(x->remove(has,x,epsilon),r); r:=[{r[]}[]];# 去重 return r; end proc: $endif
lemma has_contour_integral_rmul: "(f has_contour_integral i) g \<Longrightarrow> ((\<lambda>x. (f x) * c) has_contour_integral (i*c)) g"
The large amount of people likes to online shopping across the world. It is one of the best process and along to through shared page should be more Advertising to know about possible for more use and increase your sales with offline or online. It is also provides with more own schedules with the best process and more traditional digital coupons to paper more exciting with choose to try one of its products. On other hand, there are already to decent Promotions tool. It is also offer to all customers due to buy the percentage discounts social media discount direct promotional links. The Amazon coupon is also makes to more possible to more listed and more professional find out the all team of expert deal analysts with more clearly and maintains to choose the best process. You can understand the more shoppers with more product detail pages and have to own be brand registered to use them. It is also qualified with lots of their coupons and more makes to find and use with simply clip from automatically applied to their purchase. On other hand, the best coupons are also visible to shopper’s right destination with until no longer valid. Many online stores offer take into account the computed total and value plus the fees. It also choose the best coupons to take with possible form customer’s purchase. There are available from more used to targeted for similar and eligibility of make the deals more appealing offering discounts deals to only customers viewed or purchased certain different products linked to a single coupon at the same time. Currently, it is also leading with more pioneers in online shopping expertise and success. It is one of the destinations and belongs to more world class experience in online shopping with lots of product. However, it is also provide with the more reliable with more convenient and trusted modes of payment. On other hand, it is also helps to professional customers with hassle free manner and more protected with24x7 customer Support. There are available from daily basis with searching different daily basis with apply the more searches for applying at their website and applying are confirm that valid and check all the best selling process. When you are looking more Coupon Codes with listed between the more process as well as list to get possible for mobiles, home electronics and many more. Saree- Elegant & Classy Indian Wear!!
Formal statement is: lemma convex_imp_contractible: fixes S :: "'a::real_normed_vector set" shows "convex S \<Longrightarrow> contractible S" Informal statement is: Any convex set is contractible.
// Copyright Louis Dionne 2013-2017 // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) #include <boost/hana/ext/boost/mpl/integral_c.hpp> #include <boost/hana/core/tag_of.hpp> #include <boost/mpl/bool.hpp> #include <boost/mpl/char.hpp> #include <boost/mpl/int.hpp> #include <boost/mpl/integral_c.hpp> #include <boost/mpl/long.hpp> #include <boost/mpl/size_t.hpp> #include <cstddef> #include <type_traits> namespace hana = boost::hana; namespace mpl = boost::mpl; static_assert(std::is_same< hana::tag_of_t<mpl::bool_<true>>, hana::ext::boost::mpl::integral_c_tag<bool> >::value, ""); static_assert(std::is_same< hana::tag_of_t<mpl::int_<0>>, hana::ext::boost::mpl::integral_c_tag<int> >::value, ""); static_assert(std::is_same< hana::tag_of_t<mpl::long_<0>>, hana::ext::boost::mpl::integral_c_tag<long> >::value, ""); static_assert(std::is_same< hana::tag_of_t<mpl::size_t<0>>, hana::ext::boost::mpl::integral_c_tag<std::size_t> >::value, ""); static_assert(std::is_same< hana::tag_of_t<mpl::integral_c<int, 0>>, hana::ext::boost::mpl::integral_c_tag<int> >::value, ""); static_assert(std::is_same< hana::tag_of_t<mpl::char_<0>>, hana::ext::boost::mpl::integral_c_tag<char> >::value, ""); int main() { }
/****************************************************************************** (c) 2017 - 2019 Scientific Computation Research Center, Rensselaer Polytechnic Institute. All rights reserved. This work is open source software, licensed under the terms of the BSD license as described in the LICENSE file in the top-level directory. *******************************************************************************/ #ifndef MSI_PETSC_H #define MSI_PETSC_H #include "msi.h" #include "msi_solver.h" #include <pumi.h> #include <petsc.h> #include <map> #include <vector> // Added for the synchronization function // TODO : make it so these are not necessary #include "apfFieldData.h" #include "apfNew.h" #include "apfNumbering.h" #include "apfNumberingClass.h" #include "apfShape.h" int copyField2PetscVec(pField f, Vec& petscVec); int copyPetscVec2Field(Vec& petscVec, pField f, bool); void printMemStat( ); // NOTE: all field related interaction is done through msi api rather than apf class msi_matrix { public: msi_matrix(pField f); virtual ~msi_matrix( ); virtual int initialize( ) = 0; // create a matrix and solver object int destroy( ); // delete a matrix and solver object int set_value(msi_int row, msi_int col, int operation, double real_val, double imag_val); // insertion/addition with global numbering // values use column-wise, size * size block int add_values(msi_int rsize, msi_int* rows, msi_int csize, msi_int* columns, double* values); int get_values(std::vector<msi_int>& rows, std::vector<msi_int>& n_columns, std::vector<msi_int>& columns, std::vector<double>& values); void set_status(int s) { mat_status = s; } int get_status( ) { return mat_status; } int get_scalar_type( ) { #ifdef MSI_COMPLEX return 1; #else return 0; #endif } pField get_field( ) { return field; } int write(const char* file_name); virtual int get_type( ) const = 0; virtual int assemble( ) = 0; virtual int setupMat( ) = 0; virtual int preAllocate( ) = 0; virtual int flushAssembly( ); int printInfo( ); // PETSc data structures Mat* A; protected: int setupSeqMat( ); int setupParaMat( ); int preAllocateSeqMat( ); int preAllocateParaMat( ); int mat_status; pField field; // the field that provide numbering }; class matrix_mult : public msi_matrix { public: matrix_mult(pField f) : msi_matrix(f), localMat(1) { initialize( ); } virtual int initialize( ); void set_mat_local(bool flag) { localMat = flag; } int is_mat_local( ) { return localMat; } int multiply(pField in_f, pField out_f, bool sync = true); virtual int get_type( ) const { return 0; } // MSI_MULTIPLY; } virtual int assemble( ); virtual int setupMat( ); virtual int preAllocate( ); private: bool localMat; }; class matrix_solve : public msi_matrix { public: matrix_solve(pField f); virtual int initialize( ); virtual ~matrix_solve( ); int solve(pField rhs, pField sol, bool sync = true); int set_bc(msi_int row); int set_row(msi_int row, msi_int numVals, msi_int* colums, double* vals); int add_blockvalues(msi_int rbsize, msi_int* rows, msi_int cbsize, msi_int* columns, double* values); virtual int get_type( ) const { return 1; } virtual int assemble( ); virtual int setupMat( ); virtual int preAllocate( ); int iterNum; private: int setUpRemoteAStruct( ); int setUpRemoteAStructParaMat( ); int setKspType( ); int kspSet; KSP* ksp; Mat remoteA; std::set<int> remotePidOwned; std::map<int, std::map<int, int> > remoteNodeRow; // <pid, <locnode>, numAdj > std::map<int, int> remoteNodeRowSize; }; #endif
\chapter{\label{cpt:introduction}Introduction} This document describes the activities concerning my internship at \Rvk{} University. The introduction, which you are reading right now, describes the structure of this document. Chapter~\ref{cpt:assignment} describes the initial assignment as given by Kristinn R. Thorisson of \Rvk{} University. Since the final product differs from this first idea, the changes and their reasoning are given. In Chapter~\ref{cpt:planning} a planning is proposed. It is taken from the planning as written in the logbook which I held online at \url{http://nemendur.ru.is/christian06/logbook.html}. The design of the system to be built is given in Chapters~\ref{cpt:scenarios}, \ref{cpt:requirements}, and \ref{cpt:architecture}. These chapters are included from the design document. The full document can be downloaded from \url{http://nemendur.ru.is/christian06/amber/design.pdf} or the most recent version can be requested directly from the author, preferably by E-mail. The complete internship is evaluated in Chapter~\ref{cpt:evaluation}. This will contain learning points, which aspects went according to expectations and what can be improved. The document itself is concluded in Chapter~\ref{cpt:conclusion}.
(* * Copyright (C) 2014 NICTA * All rights reserved. *) (* Author: David Cock - [email protected] *) header "The Algebra of pGCL" theory Algebra imports WellDefined begin text_raw {* \label{s:Algebra} *} text {* Programs in pGCL have a rich algebraic structure, largely mirroring that for GCL. We show that programs form a lattice under refinement, with @{term "a \<Sqinter> b"} and @{term "a \<Squnion> b"} as the meet and join operators, respectively. We also take advantage of the algebraic structure to establish a framwork for the modular decomposition of proofs. *} subsection {* Program Refinement *} text_raw {* \label{s:progref} *} text {* Refinement in pGCL relates to refinement in GCL exactly as probabilistic entailment relates to implication. It turns out to have a very similar algebra, the rules of which we establish shortly. *} definition refines :: "'s prog \<Rightarrow> 's prog \<Rightarrow> bool" (infix "\<sqsubseteq>" 70) where "prog \<sqsubseteq> prog' \<equiv> \<forall>P. sound P \<longrightarrow> wp prog P \<tturnstile> wp prog' P" lemma refinesI[intro]: "\<lbrakk> \<And>P. sound P \<Longrightarrow> wp prog P \<tturnstile> wp prog' P \<rbrakk> \<Longrightarrow> prog \<sqsubseteq> prog'" unfolding refines_def by(simp) lemma refinesD[dest]: "\<lbrakk> prog \<sqsubseteq> prog'; sound P \<rbrakk> \<Longrightarrow> wp prog P \<tturnstile> wp prog' P" unfolding refines_def by(simp) text {* The equivalence relation below will turn out to be that induced by refinement. It is also the application of @{term equiv_trans} to the weakest precondition. *} definition pequiv :: "'s prog \<Rightarrow> 's prog \<Rightarrow> bool" (infix "\<simeq>" 70) where "prog \<simeq> prog' \<equiv> \<forall>P. sound P \<longrightarrow> wp prog P = wp prog' P" lemma pequivI[intro]: "\<lbrakk> \<And>P. sound P \<Longrightarrow> wp prog P = wp prog' P \<rbrakk> \<Longrightarrow> prog \<simeq> prog'" unfolding pequiv_def by(simp) lemma pequivD[dest,simp]: "\<lbrakk> prog \<simeq> prog'; sound P \<rbrakk> \<Longrightarrow> wp prog P = wp prog' P" unfolding pequiv_def by(simp) lemma pequiv_equiv_trans: "a \<simeq> b \<longleftrightarrow> equiv_trans (wp a) (wp b)" by(auto) subsection {* Simple Identities *} text {* The following identities involve only the primitive operations as defined in \autoref{s:syntax}, and refinement as defined above. *} subsubsection {* Laws following from the basic arithmetic of the operators seperately *} lemma DC_comm[ac_simps]: "a \<Sqinter> b = b \<Sqinter> a" unfolding DC_def by(simp add:ac_simps) lemma DC_assoc[ac_simps]: "a \<Sqinter> (b \<Sqinter> c) = (a \<Sqinter> b) \<Sqinter> c" unfolding DC_def by(simp add:ac_simps) lemma DC_idem: "a \<Sqinter> a = a" unfolding DC_def by(simp) lemma AC_comm[ac_simps]: "a \<Squnion> b = b \<Squnion> a" unfolding AC_def by(simp add:ac_simps) lemma AC_assoc[ac_simps]: "a \<Squnion> (b \<Squnion> c) = (a \<Squnion> b) \<Squnion> c" unfolding AC_def by(simp add:ac_simps) lemma AC_idem: "a \<Squnion> a = a" unfolding AC_def by(simp) lemma PC_quasi_comm: "a \<^bsub>p\<^esub>\<oplus> b = b \<^bsub>(\<lambda>s. 1 - p s)\<^esub>\<oplus> a" unfolding PC_def by(simp add:algebra_simps) lemma PC_idem: "a \<^bsub>p\<^esub>\<oplus> a = a" unfolding PC_def by(simp add:algebra_simps) lemma Seq_assoc[ac_simps]: "A ;; (B ;; C) = A ;; B ;; C" by(simp add:Seq_def o_def) lemma Abort_refines[intro]: "well_def a \<Longrightarrow> Abort \<sqsubseteq> a" by(rule refinesI, unfold wp_eval, auto dest!:well_def_wp_healthy) subsubsection {* Laws relating demonic choice and refinement *} lemma left_refines_DC: "(a \<Sqinter> b) \<sqsubseteq> a" by(auto intro!:refinesI simp:wp_eval) lemma right_refines_DC: "(a \<Sqinter> b) \<sqsubseteq> b" by(auto intro!:refinesI simp:wp_eval) lemma DC_refines: fixes a::"'s prog" and b and c assumes rab: "a \<sqsubseteq> b" and rac: "a \<sqsubseteq> c" shows "a \<sqsubseteq> (b \<Sqinter> c)" proof fix P::"'s \<Rightarrow> real" assume sP: "sound P" with assms have "wp a P \<tturnstile> wp b P" and "wp a P \<tturnstile> wp c P" by(auto dest:refinesD) thus "wp a P \<tturnstile> wp (b \<Sqinter> c) P" by(auto simp:wp_eval intro:min.boundedI) qed lemma DC_mono: fixes a::"'s prog" assumes rab: "a \<sqsubseteq> b" and rcd: "c \<sqsubseteq> d" shows "(a \<Sqinter> c) \<sqsubseteq> (b \<Sqinter> d)" proof(rule refinesI, unfold wp_eval, rule le_funI) fix P::"'s \<Rightarrow> real" and s::'s assume sP: "sound P" with assms have "wp a P s \<le> wp b P s" and "wp c P s \<le> wp d P s" by(auto) thus "min (wp a P s) (wp c P s) \<le> min (wp b P s) (wp d P s)" by(auto) qed subsubsection {* Laws relating angelic choice and refinement *} lemma left_refines_AC: "a \<sqsubseteq> (a \<Squnion> b)" by(auto intro!:refinesI simp:wp_eval) lemma right_refines_AC: "b \<sqsubseteq> (a \<Squnion> b)" by(auto intro!:refinesI simp:wp_eval) lemma AC_refines: fixes a::"'s prog" and b and c assumes rac: "a \<sqsubseteq> c" and rbc: "b \<sqsubseteq> c" shows "(a \<Squnion> b) \<sqsubseteq> c" proof fix P::"'s \<Rightarrow> real" assume sP: "sound P" with assms have "\<And>s. wp a P s \<le> wp c P s" and "\<And>s. wp b P s \<le> wp c P s" by(auto dest:refinesD) thus "wp (a \<Squnion> b) P \<tturnstile> wp c P" unfolding wp_eval by(auto) qed lemma AC_mono: fixes a::"'s prog" assumes rab: "a \<sqsubseteq> b" and rcd: "c \<sqsubseteq> d" shows "(a \<Squnion> c) \<sqsubseteq> (b \<Squnion> d)" proof(rule refinesI, unfold wp_eval, rule le_funI) fix P::"'s \<Rightarrow> real" and s::'s assume sP: "sound P" with assms have "wp a P s \<le> wp b P s" and "wp c P s \<le> wp d P s" by(auto) thus "max (wp a P s) (wp c P s) \<le> max (wp b P s) (wp d P s)" by(auto) qed subsubsection {* Laws depending on the arithmetic of @{term "a \<^bsub>p\<^esub>\<oplus> b"} and @{term "a \<Sqinter> b"} together *} lemma DC_refines_PC: assumes unit: "unitary p" shows "(a \<Sqinter> b) \<sqsubseteq> (a \<^bsub>p\<^esub>\<oplus> b)" proof(rule refinesI, unfold wp_eval, rule le_funI) fix s and P::"'a \<Rightarrow> real" assume sound: "sound P" from unit have nn_p: "0 \<le> p s" by(blast) from unit have "p s \<le> 1" by(blast) hence nn_np: "0 \<le> 1 - p s" by(simp) show "min (wp a P s) (wp b P s) \<le> p s * wp a P s + (1 - p s) * wp b P s" proof(cases "wp a P s \<le> wp b P s", simp_all add:min.absorb1 min.absorb2) case True note le = this have "wp a P s = (p s + (1 - p s)) * wp a P s" by(simp) also have "... = p s * wp a P s + (1 - p s) * wp a P s" by(simp only: distrib_right) also { from le and nn_np have "(1 - p s) * wp a P s \<le> (1 - p s) * wp b P s" by(rule mult_left_mono) hence "p s * wp a P s + (1 - p s) * wp a P s \<le> p s * wp a P s + (1 - p s) * wp b P s" by(rule add_left_mono) } finally show "wp a P s \<le> p s * wp a P s + (1 - p s) * wp b P s" . next case False then have le: "wp b P s \<le> wp a P s" by(simp) have "wp b P s = (p s + (1 - p s)) * wp b P s" by(simp) also have "... = p s * wp b P s + (1 - p s) * wp b P s" by(simp only:distrib_right) also { from le and nn_p have "p s * wp b P s \<le> p s * wp a P s" by(rule mult_left_mono) hence "p s * wp b P s + (1 - p s) * wp b P s \<le> p s * wp a P s + (1 - p s) * wp b P s" by(rule add_right_mono) } finally show "wp b P s \<le> p s * wp a P s + (1 - p s) * wp b P s" . qed qed subsubsection {* Laws depending on the arithmetic of @{term "a \<^bsub>p\<^esub>\<oplus> b"} and @{term "a \<Squnion> b"} together *} lemma PC_refines_AC: assumes unit: "unitary p" shows "(a \<^bsub>p\<^esub>\<oplus> b) \<sqsubseteq> (a \<Squnion> b)" proof(rule refinesI, unfold wp_eval, rule le_funI) fix s and P::"'a \<Rightarrow> real" assume sound: "sound P" from unit have "p s \<le> 1" by(blast) hence nn_np: "0 \<le> 1 - p s" by(simp) show "p s * wp a P s + (1 - p s) * wp b P s \<le> max (wp a P s) (wp b P s)" proof(cases "wp a P s \<le> wp b P s") case True note leab = this with unit nn_np have "p s * wp a P s + (1 - p s) * wp b P s \<le> p s * wp b P s + (1 - p s) * wp b P s" by(auto intro:add_mono mult_left_mono) also have "... = wp b P s" by(auto simp:field_simps) also from leab have "... = max (wp a P s) (wp b P s)" by(auto) finally show ?thesis . next case False note leba = this with unit nn_np have "p s * wp a P s + (1 - p s) * wp b P s \<le> p s * wp a P s + (1 - p s) * wp a P s" by(auto intro:add_mono mult_left_mono) also have "... = wp a P s" by(auto simp:field_simps) also from leba have "... = max (wp a P s) (wp b P s)" by(auto) finally show ?thesis . qed qed subsubsection {* Laws depending on the arithmetic of @{term "a \<Squnion> b"} and @{term "a \<Sqinter> b"} together *} lemma DC_refines_AC: "(a \<Sqinter> b) \<sqsubseteq> (a \<Squnion> b)" by(auto intro!:refinesI simp:wp_eval) subsubsection {* Laws Involving Refinement and Equivalence *} lemma pr_trans[trans]: fixes A::"'a prog" assumes prAB: "A \<sqsubseteq> B" and prBC: "B \<sqsubseteq> C" shows "A \<sqsubseteq> C" proof fix P::"'a \<Rightarrow> real" assume sP: "sound P" with prAB have "wp A P \<tturnstile> wp B P" by(blast) also from sP and prBC have "... \<tturnstile> wp C P" by(blast) finally show "wp A P \<tturnstile> ..." . qed lemma pequiv_refl[intro!,simp]: "a \<simeq> a" by(auto) lemma pequiv_comm[ac_simps]: "a \<simeq> b \<longleftrightarrow> b \<simeq> a" unfolding pequiv_def by(rule iffI, safe, simp_all) lemma pequiv_pr[dest]: "a \<simeq> b \<Longrightarrow> a \<sqsubseteq> b" by(auto) lemma pequiv_trans[intro,trans]: "\<lbrakk> a \<simeq> b; b \<simeq> c \<rbrakk> \<Longrightarrow> a \<simeq> c" unfolding pequiv_def by(auto intro!:order_trans) lemma pequiv_pr_trans[intro,trans]: "\<lbrakk> a \<simeq> b; b \<sqsubseteq> c \<rbrakk> \<Longrightarrow> a \<sqsubseteq> c" unfolding pequiv_def refines_def by(simp) lemma pr_pequiv_trans[intro,trans]: "\<lbrakk> a \<sqsubseteq> b; b \<simeq> c \<rbrakk> \<Longrightarrow> a \<sqsubseteq> c" unfolding pequiv_def refines_def by(simp) text {* Refinement induces equivalence by antisymmetry: *} lemma pequiv_antisym: "\<lbrakk> a \<sqsubseteq> b; b \<sqsubseteq> a \<rbrakk> \<Longrightarrow> a \<simeq> b" by(auto intro:antisym) lemma pequiv_DC: "\<lbrakk> a \<simeq> c; b \<simeq> d \<rbrakk> \<Longrightarrow> (a \<Sqinter> b) \<simeq> (c \<Sqinter> d)" by(auto intro!:DC_mono pequiv_antisym simp:ac_simps) lemma pequiv_AC: "\<lbrakk> a \<simeq> c; b \<simeq> d \<rbrakk> \<Longrightarrow> (a \<Squnion> b) \<simeq> (c \<Squnion> d)" by(auto intro!:AC_mono pequiv_antisym simp:ac_simps) subsection {* Deterministic Programs are Maximal *} text {* Any sub-additive refinement of a deterministic program is in fact an equivalence. Deterministic programs are thus maximal (under the refinement order) among sub-additive programs. *} lemma refines_determ: fixes a::"'s prog" assumes da: "determ (wp a)" and wa: "well_def a" and wb: "well_def b" and dr: "a \<sqsubseteq> b" shows "a \<simeq> b" txt {* Proof by contradiction. *} proof(rule pequivI, rule contrapos_pp) from wb have "feasible (wp b)" by(auto) with wb have sab: "sub_add (wp b)" by(auto dest: sublinear_subadd[OF well_def_wp_sublinear]) fix P::"'s \<Rightarrow> real" assume sP: "sound P" txt {* Assume that @{term a} and @{term b} are not equivalent: *} assume ne: "wp a P \<noteq> wp b P" txt {* Find a point at which they differ. As @{term "a \<sqsubseteq> b"}, @{term "wp b P s"} must by strictly greater than @{term "wp a P s"} here: *} hence "\<exists>s. wp a P s < wp b P s" proof(rule contrapos_np) assume "\<not>(\<exists>s. wp a P s < wp b P s)" hence "\<forall>s. wp b P s \<le> wp a P s" by(auto simp:not_less) hence "wp b P \<tturnstile> wp a P" by(auto) moreover from sP dr have "wp a P \<tturnstile> wp b P" by(auto) ultimately show "wp a P = wp b P" by(auto) qed then obtain s where less: "wp a P s < wp b P s" by(blast) txt {* Take a carefully constructed expectation: *} let ?Pc = "\<lambda>s. bound_of P - P s" have sPc: "sound ?Pc" proof(rule soundI) from sP have "\<And>s. 0 \<le> P s" by(auto) hence "\<And>s. ?Pc s \<le> bound_of P" by(auto) thus "bounded ?Pc" by(blast) from sP have "\<And>s. P s \<le> bound_of P" by(auto) hence "\<And>s. 0 \<le> ?Pc s" by(auto simp:sign_simps) thus "nneg ?Pc" by(auto) qed txt {* We then show that @{term "wp b"} violates feasibility, and thus healthiness. *} from sP have "0 \<le> bound_of P" by(auto) with da have "bound_of P = wp a (\<lambda>s. bound_of P) s" by(simp add:maximalD determ_maximalD) also have "... = wp a (\<lambda>s. ?Pc s + P s) s" by(simp) also from da sP sPc have "... = wp a ?Pc s + wp a P s" by(subst additiveD[OF determ_additiveD], simp_all add:sP sPc) also from sPc dr have "... \<le> wp b ?Pc s + wp a P s" by(auto) also from less have "... < wp b ?Pc s + wp b P s" by(auto) also from sab sP sPc have "... \<le> wp b (\<lambda>s. ?Pc s + P s) s" by(blast) finally have "\<not>wp b (\<lambda>s. bound_of P) s \<le> bound_of P" by(simp) thus "\<not>bounded_by (bound_of P) (wp b (\<lambda>s. bound_of P))" by(auto) next txt {* However, *} fix P::"'s \<Rightarrow> real" assume sP: "sound P" hence "nneg (\<lambda>s. bound_of P)" by(auto) moreover have "bounded_by (bound_of P) (\<lambda>s. bound_of P)" by(auto) ultimately show "bounded_by (bound_of P) (wp b (\<lambda>s. bound_of P))" using wb by(auto dest!:well_def_wp_healthy) qed subsection {* The Algebraic Structure of Refinement *} text {* Well-defined programs form a half-bounded semilattice under refinement, where @{term Abort} is bottom, and @{term "a \<Sqinter> b"} is @{term inf}. There is no unique top element, but all fully-deterministic programs are maximal. The type that we construct here is not especially useful, but serves as a convenient way to express this result. *} quotient_type 's program = "'s prog" / partial : "\<lambda>a b. a \<simeq> b \<and> well_def a \<and> well_def b" proof(rule part_equivpI) have "Skip \<simeq> Skip" and "well_def Skip" by(auto intro:wd_intros) thus "\<exists>x. x \<simeq> x \<and> well_def x \<and> well_def x" by(blast) show "symp (\<lambda>a b. a \<simeq> b \<and> well_def a \<and> well_def b)" proof(rule sympI, safe) fix a::"'a prog" and b assume "a \<simeq> b" hence "equiv_trans (wp a) (wp b)" by(simp add:pequiv_equiv_trans) thus "b \<simeq> a" by(simp add:ac_simps pequiv_equiv_trans) qed show "transp (\<lambda>a b. a \<simeq> b \<and> well_def a \<and> well_def b)" by(rule transpI, safe, rule pequiv_trans) qed instantiation program :: (type) semilattice_inf begin lift_definition less_eq_program :: "'a program \<Rightarrow> 'a program \<Rightarrow> bool" is refines proof(safe) fix a::"'a prog" and b c d assume "a \<simeq> b" hence "b \<simeq> a" by(simp add:ac_simps) also assume "a \<sqsubseteq> c" also assume "c \<simeq> d" finally show "b \<sqsubseteq> d" . next fix a::"'a prog" and b c d assume "a \<simeq> b" also assume "b \<sqsubseteq> d" also assume "c \<simeq> d" hence "d \<simeq> c" by(simp add:ac_simps) finally show "a \<sqsubseteq> c" . qed (* XXX - what's up here? *) lift_definition less_program :: "'a program \<Rightarrow> 'a program \<Rightarrow> bool" is "\<lambda>a b. a \<sqsubseteq> b \<and> \<not> b \<sqsubseteq> a" proof(safe) fix a::"'a prog" and b c d assume "a \<simeq> b" hence "b \<simeq> a" by(simp add:ac_simps) also assume "a \<sqsubseteq> c" also assume "c \<simeq> d" finally show "b \<sqsubseteq> d" . next fix a::"'a prog" and b c d assume "a \<simeq> b" also assume "b \<sqsubseteq> d" also assume "c \<simeq> d" hence "d \<simeq> c" by(simp add:ac_simps) finally show "a \<sqsubseteq> c" . next fix a b and c::"'a prog" and d assume "c \<simeq> d" also assume "d \<sqsubseteq> b" also assume "a \<simeq> b" hence "b \<simeq> a" by(simp add:ac_simps) finally have "c \<sqsubseteq> a" . moreover assume "\<not> c \<sqsubseteq> a" ultimately show False by(auto) next fix a b and c::"'a prog" and d assume "c \<simeq> d" hence "d \<simeq> c" by(simp add:ac_simps) also assume "c \<sqsubseteq> a" also assume "a \<simeq> b" finally have "d \<sqsubseteq> b" . moreover assume "\<not> d \<sqsubseteq> b" ultimately show False by(auto) qed lift_definition inf_program :: "'a program \<Rightarrow> 'a program \<Rightarrow> 'a program" is DC proof(safe) fix a b c d::"'s prog" assume "a \<simeq> b" and "c \<simeq> d" thus "(a \<Sqinter> c) \<simeq> (b \<Sqinter> d)" by(rule pequiv_DC) next fix a c::"'s prog" assume "well_def a" "well_def c" thus "well_def (a \<Sqinter> c)" by(rule wd_intros) next fix a c::"'s prog" assume "well_def a" "well_def c" thus "well_def (a \<Sqinter> c)" by(rule wd_intros) qed instance proof fix x y::"'a program" show "(x < y) = (x \<le> y \<and> \<not> y \<le> x)" by(transfer, simp) show "x \<le> x" by(transfer, auto) show "inf x y \<le> x" by(transfer, rule left_refines_DC) show "inf x y \<le> y" by(transfer, rule right_refines_DC) assume "x \<le> y" and "y \<le> x" thus "x = y" by(transfer, iprover intro:pequiv_antisym) next fix x y z::"'a program" assume "x \<le> y" and "y \<le> z" thus "x \<le> z" by(transfer, iprover intro:pr_trans) next fix x y z::"'a program" assume "x \<le> y" and "x \<le> z" thus "x \<le> inf y z" by(transfer, iprover intro:DC_refines) qed end instantiation program :: (type) bot begin lift_definition bot_program :: "'a program" is Abort by(auto intro:wd_intros) instance .. end lemma eq_det: "\<And>a b::'s prog. \<lbrakk> a \<simeq> b; determ (wp a) \<rbrakk> \<Longrightarrow> determ (wp b)" proof(intro determI additiveI maximalI) fix a b::"'s prog" and P::"'s \<Rightarrow> real" and Q::"'s \<Rightarrow> real" and s::"'s" assume da: "determ (wp a)" assume sP: "sound P" and sQ: "sound Q" and eq: "a \<simeq> b" hence "wp b (\<lambda>s. P s + Q s) s = wp a (\<lambda>s. P s + Q s) s" by(simp add:sound_intros) also from da sP sQ have "... = wp a P s + wp a Q s" by(simp add:additiveD determ_additiveD) also from eq sP sQ have "... = wp b P s + wp b Q s" by(simp add:pequivD) finally show "wp b (\<lambda>s. P s + Q s) s = wp b P s + wp b Q s" . next fix a b::"'s prog" and c::real assume da: "determ (wp a)" assume "a \<simeq> b" hence "b \<simeq> a" by(simp add:ac_simps) moreover assume nn: "0 \<le> c" ultimately have "wp b (\<lambda>_. c) = wp a (\<lambda>_. c)" by(simp add:pequivD const_sound) also from da nn have "... = (\<lambda>_. c)" by(simp add:determ_maximalD maximalD) finally show "wp b (\<lambda>_. c) = (\<lambda>_. c)" . qed lift_definition pdeterm :: "'s program \<Rightarrow> bool" is "\<lambda>a. determ (wp a)" proof(safe) fix a b::"'s prog" assume "a \<simeq> b" and "determ (wp a)" thus "determ (wp b)" by(rule eq_det) next fix a b::"'s prog" assume "a \<simeq> b" hence "b \<simeq> a" by(simp add:ac_simps) moreover assume "determ (wp b)" ultimately show "determ (wp a)" by(rule eq_det) qed lemma determ_maximal: "\<lbrakk> pdeterm a; a \<le> x \<rbrakk> \<Longrightarrow> a = x" by(transfer, auto intro:refines_determ) subsection {* Data Refinement *} text {* A projective data refinement construction for pGCL. By projective, we mean that the abstract state is always a function (@{term \<phi>}) of the concrete state. Refinement may be predicated (@{term G}) on the state. *} definition drefines :: "('b \<Rightarrow> 'a) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a prog \<Rightarrow> 'b prog \<Rightarrow> bool" where "drefines \<phi> G A B \<equiv> \<forall>P Q. (unitary P \<and> unitary Q \<and> (P \<tturnstile> wp A Q)) \<longrightarrow> (\<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> wp B (Q o \<phi>))" lemma drefinesD[dest]: "\<lbrakk> drefines \<phi> G A B; unitary P; unitary Q; P \<tturnstile> wp A Q \<rbrakk> \<Longrightarrow> \<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> wp B (Q o \<phi>)" unfolding drefines_def by(blast) text {* We can alternatively use G as an assumption: *} lemma drefinesD2: assumes dr: "drefines \<phi> G A B" and uP: "unitary P" and uQ: "unitary Q" and wpA: "P \<tturnstile> wp A Q" and G: "G s" shows "(P o \<phi>) s \<le> wp B (Q o \<phi>) s" proof - from uP have "0 \<le> (P o \<phi>) s" unfolding o_def by(blast) with G have "(P o \<phi>) s = (\<guillemotleft>G\<guillemotright> && (P o \<phi>)) s" by(simp add:exp_conj_def) also from assms have "... \<le> wp B (Q o \<phi>) s" by(blast) finally show "(P o \<phi>) s \<le> ..." . qed text {* This additional form is sometimes useful: *} lemma drefinesD3: assumes dr: "drefines \<phi> G a b" and G: "G s" and uQ: "unitary Q" and wa: "well_def a" shows "wp a Q (\<phi> s) \<le> wp b (Q o \<phi>) s" proof - let "?L s'" = "wp a Q s'" from uQ wa have sL: "sound ?L" by(blast) from uQ wa have bL: "bounded_by 1 ?L" by(blast) have "?L \<tturnstile> ?L" by(simp) with sL and bL and assms show ?thesis by(blast intro:drefinesD2[OF dr, where P="?L", simplified]) qed lemma drefinesI[intro]: "\<lbrakk> \<And>P Q. \<lbrakk> unitary P; unitary Q; P \<tturnstile> wp A Q \<rbrakk> \<Longrightarrow> \<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> wp B (Q o \<phi>) \<rbrakk> \<Longrightarrow> drefines \<phi> G A B" unfolding drefines_def by(blast) text {* Use G as an assumption, when showing refinement: *} lemma drefinesI2: fixes A::"'a prog" and B::"'b prog" and \<phi>::"'b \<Rightarrow> 'a" and G::"'b \<Rightarrow> bool" assumes wB: "well_def B" and withAs: "\<And>P Q s. \<lbrakk> unitary P; unitary Q; G s; P \<tturnstile> wp A Q \<rbrakk> \<Longrightarrow> (P o \<phi>) s \<le> wp B (Q o \<phi>) s" shows "drefines \<phi> G A B" proof fix P and Q assume uP: "unitary P" and uQ: "unitary Q" and wpA: "P \<tturnstile> wp A Q" hence "\<And>s. G s \<Longrightarrow> (P o \<phi>) s \<le> wp B (Q o \<phi>) s" using withAs by(blast) moreover from uQ have "unitary (Q o \<phi>)" unfolding o_def by(blast) moreover from uP have "unitary (P o \<phi>)" unfolding o_def by(blast) ultimately show "\<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> wp B (Q o \<phi>)" using wB by(blast intro:entails_pconj_assumption) qed lemma dr_strengthen_guard: fixes a::"'s prog" and b::"'t prog" assumes fg: "\<And>s. F s \<Longrightarrow> G s" and drab: "drefines \<phi> G a b" shows "drefines \<phi> F a b" proof(intro drefinesI) fix P Q::"'s expect" assume uP: "unitary P" and uQ: "unitary Q" and wp: "P \<tturnstile> wp a Q" from fg have "\<And>s. \<guillemotleft>F\<guillemotright> s \<le> \<guillemotleft>G\<guillemotright> s" by(simp add:embed_bool_def) hence "(\<guillemotleft>F\<guillemotright> && (P o \<phi>)) \<tturnstile> (\<guillemotleft>G\<guillemotright> && (P o \<phi>))" by(auto intro:pconj_mono le_funI simp:exp_conj_def) also from drab uP uQ wp have "... \<tturnstile> wp b (Q o \<phi>)" by(auto) finally show "\<guillemotleft>F\<guillemotright> && (P o \<phi>) \<tturnstile> wp b (Q o \<phi>)" . qed text {* Probabilistic correspondence, @{term pcorres}, is equality on distribution transformers, modulo a guard. It is the analogue, for data refinement, of program equivalence for program refinement. *} definition pcorres :: "('b \<Rightarrow> 'a) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a prog \<Rightarrow> 'b prog \<Rightarrow> bool" where "pcorres \<phi> G A B \<longleftrightarrow> (\<forall>Q. unitary Q \<longrightarrow> \<guillemotleft>G\<guillemotright> && (wp A Q o \<phi>) = \<guillemotleft>G\<guillemotright> && wp B (Q o \<phi>))" lemma pcorresI: "\<lbrakk> \<And>Q. unitary Q \<Longrightarrow> \<guillemotleft>G\<guillemotright> && (wp A Q o \<phi>) = \<guillemotleft>G\<guillemotright> && wp B (Q o \<phi>) \<rbrakk> \<Longrightarrow> pcorres \<phi> G A B" by(simp add:pcorres_def) text {* Often easier to use, as it allows one to assume the precondition. *} lemma pcorresI2[intro]: fixes A::"'a prog" and B::"'b prog" assumes withG: "\<And>Q s. \<lbrakk> unitary Q; G s \<rbrakk> \<Longrightarrow> wp A Q (\<phi> s)= wp B (Q o \<phi>) s" and wA: "well_def A" and wB: "well_def B" shows "pcorres \<phi> G A B" proof(rule pcorresI, rule ext) fix Q::"'a \<Rightarrow> real" and s::'b assume uQ: "unitary Q" hence uQ\<phi>: "unitary (Q o \<phi>)" by(auto) show "(\<guillemotleft>G\<guillemotright> && (wp A Q \<circ> \<phi>)) s = (\<guillemotleft>G\<guillemotright> && wp B (Q \<circ> \<phi>)) s" proof(cases "G s") case True note this moreover from well_def_wp_healthy[OF wA] uQ have "0 \<le> wp A Q (\<phi> s)" by(blast) moreover from well_def_wp_healthy[OF wB] uQ\<phi> have "0 \<le> wp B (Q o \<phi>) s" by(blast) ultimately show ?thesis using uQ by(simp add:exp_conj_def withG) next case False note this moreover from well_def_wp_healthy[OF wA] uQ have "wp A Q (\<phi> s) \<le> 1" by(blast) moreover from well_def_wp_healthy[OF wB] uQ\<phi> have "wp B (Q o \<phi>) s \<le> 1" by(blast dest!:healthy_bounded_byD intro:sound_nneg) ultimately show ?thesis by(simp add:exp_conj_def) qed qed lemma pcorresD: "\<lbrakk> pcorres \<phi> G A B; unitary Q \<rbrakk> \<Longrightarrow> \<guillemotleft>G\<guillemotright> && (wp A Q o \<phi>) = \<guillemotleft>G\<guillemotright> && wp B (Q o \<phi>)" unfolding pcorres_def by(simp) text {* Again, easier to use if the precondition is known to hold. *} lemma pcorresD2: assumes pc: "pcorres \<phi> G A B" and uQ: "unitary Q" and wA: "well_def A" and wB: "well_def B" and G: "G s" shows "wp A Q (\<phi> s) = wp B (Q o \<phi>) s" proof - from uQ well_def_wp_healthy[OF wA] have "0 \<le> wp A Q (\<phi> s)" by(auto) with G have "wp A Q (\<phi> s) = \<guillemotleft>G\<guillemotright> s .& wp A Q (\<phi> s)" by(simp) also { from pc uQ have "\<guillemotleft>G\<guillemotright> && (wp A Q o \<phi>) = \<guillemotleft>G\<guillemotright> && wp B (Q o \<phi>)" by(rule pcorresD) hence "\<guillemotleft>G\<guillemotright> s .& wp A Q (\<phi> s) = \<guillemotleft>G\<guillemotright> s .& wp B (Q o \<phi>) s" unfolding exp_conj_def o_def by(rule fun_cong) } also { from uQ have "sound Q" by(auto) hence "sound (Q o \<phi>)" by(auto intro:sound_intros) with well_def_wp_healthy[OF wB] have "0 \<le> wp B (Q o \<phi>) s" by(auto) with G have "\<guillemotleft>G\<guillemotright> s .& wp B (Q o \<phi>) s = wp B (Q o \<phi>) s" by(simp) } finally show ?thesis . qed subsection {* The Algebra of Data Refinement *} text {* Program refinement implies a trivial data refinement: *} lemma refines_drefines: fixes a::"'s prog" assumes rab: "a \<sqsubseteq> b" and wb: "well_def b" shows "drefines (\<lambda>s. s) G a b" proof(intro drefinesI2 wb, simp add:o_def) fix P::"'s \<Rightarrow> real" and Q::"'s \<Rightarrow> real" and s::'s assume sQ: "unitary Q" assume "P \<tturnstile> wp a Q" hence "P s \<le> wp a Q s" by(auto) also from rab sQ have "... \<le> wp b Q s" by(auto) finally show "P s \<le> wp b Q s" . qed text {* Data refinement is transitive: *} lemma dr_trans[trans]: fixes A::"'a prog" and B::"'b prog" and C::"'c prog" assumes drAB: "drefines \<phi> G A B" and drBC: "drefines \<phi>' G' B C" and Gimp: "\<And>s. G' s \<Longrightarrow> G (\<phi>' s)" shows "drefines (\<phi> o \<phi>') G' A C" proof(rule drefinesI) fix P::"'a \<Rightarrow> real" and Q::"'a \<Rightarrow> real" and s::'a assume uP: "unitary P" and uQ: "unitary Q" and wpA: "P \<tturnstile> wp A Q" have "\<guillemotleft>G'\<guillemotright> && \<guillemotleft>G o \<phi>'\<guillemotright> = \<guillemotleft>G'\<guillemotright>" proof(rule ext, unfold exp_conj_def) fix x show "\<guillemotleft>G'\<guillemotright> x .& \<guillemotleft>G o \<phi>'\<guillemotright> x = \<guillemotleft>G'\<guillemotright> x" (is ?X) proof(cases "G' x") case False then show ?X by(simp) next case True moreover with Gimp have "(G o \<phi>') x" by(simp add:o_def) ultimately show ?X by(simp) qed qed with uP have "\<guillemotleft>G'\<guillemotright> && (P o (\<phi> o \<phi>')) = \<guillemotleft>G'\<guillemotright> && ((\<guillemotleft>G\<guillemotright> && (P o \<phi>)) o \<phi>')" by(simp add:exp_conj_assoc o_assoc) also { from uP uQ wpA and drAB have "\<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> wp B (Q o \<phi>)" by(blast intro:drefinesD) with drBC and uP uQ have "\<guillemotleft>G'\<guillemotright> && ((\<guillemotleft>G\<guillemotright> && (P o \<phi>)) o \<phi>') \<tturnstile> wp C ((Q o \<phi>) o \<phi>')" by(blast intro:unitary_intros drefinesD) } finally show "\<guillemotleft>G'\<guillemotright> && (P o (\<phi> o \<phi>')) \<tturnstile> wp C (Q o (\<phi> o \<phi>'))" by(simp add:o_assoc) qed text {* Data refinement composes with program refinement: *} lemma pr_dr_trans[trans]: assumes prAB: "A \<sqsubseteq> B" and drBC: "drefines \<phi> G B C" shows "drefines \<phi> G A C" proof(rule drefinesI) fix P and Q assume uP: "unitary P" and uQ: "unitary Q" and wpA: "P \<tturnstile> wp A Q" note wpA also from uQ and prAB have "wp A Q \<tturnstile> wp B Q" by(blast) finally have "P \<tturnstile> wp B Q" . with uP uQ drBC show "\<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> wp C (Q o \<phi>)" by(blast intro:drefinesD) qed lemma dr_pr_trans[trans]: assumes drAB: "drefines \<phi> G A B" assumes prBC: "B \<sqsubseteq> C" shows "drefines \<phi> G A C" proof(rule drefinesI) fix P and Q assume uP: "unitary P" and uQ: "unitary Q" and wpA: "P \<tturnstile> wp A Q" with drAB have "\<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> wp B (Q o \<phi>)" by(blast intro:drefinesD) also from uQ prBC have "... \<tturnstile> wp C (Q o \<phi>)" by(blast) finally show "\<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> ..." . qed text {* If the projection @{term \<phi>} commutes with the transformer, then data refinement is reflexive: *} lemma dr_refl: assumes wa: "well_def a" and comm: "\<And>Q. unitary Q \<Longrightarrow> wp a Q o \<phi> \<tturnstile> wp a (Q o \<phi>)" shows "drefines \<phi> G a a" proof(intro drefinesI2 wa) fix P and Q and s assume wp: "P \<tturnstile> wp a Q" assume uQ: "unitary Q" have "(P o \<phi>) s = P (\<phi> s)" by(simp) also from wp have "... \<le> wp a Q (\<phi> s)" by(blast) also { from comm uQ have "wp a Q o \<phi> \<tturnstile> wp a (Q o \<phi>)" by(blast) hence "(wp a Q o \<phi>) s \<le> wp a (Q o \<phi>) s" by(blast) hence "wp a Q (\<phi> s) \<le> ..." by(simp) } finally show "(P o \<phi>) s \<le> wp a (Q o \<phi>) s" . qed text {* Correspondence implies data refinement *} lemma pcorres_drefine: assumes corres: "pcorres \<phi> G A C" and wC: "well_def C" shows "drefines \<phi> G A C" proof fix P and Q assume uP: "unitary P" and uQ: "unitary Q" and wpA: "P \<tturnstile> wp A Q" from wpA have "P o \<phi> \<tturnstile> wp A Q o \<phi>" by(simp add:o_def le_fun_def) hence "\<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> \<guillemotleft>G\<guillemotright> && (wp A Q o \<phi>)" by(rule exp_conj_mono_right) also from corres uQ have "... = \<guillemotleft>G\<guillemotright> && (wp C (Q o \<phi>))" by(rule pcorresD) also have "... \<tturnstile> wp C (Q o \<phi>)" proof(rule le_funI) fix s from uQ have "unitary (Q o \<phi>)" by(rule unitary_intros) with well_def_wp_healthy[OF wC] have nn_wpC: "0 \<le> wp C (Q o \<phi>) s" by(blast) show "(\<guillemotleft>G\<guillemotright> && wp C (Q o \<phi>)) s \<le> wp C (Q o \<phi>) s" proof(cases "G s") case True with nn_wpC show ?thesis by(simp add:exp_conj_def) next case False note this moreover { from uQ have "unitary (Q o \<phi>)" by(simp) with well_def_wp_healthy[OF wC] have "wp C (Q o \<phi>) s \<le> 1" by(auto) } moreover note nn_wpC ultimately show ?thesis by(simp add:exp_conj_def) qed qed finally show "\<guillemotleft>G\<guillemotright> && (P o \<phi>) \<tturnstile> wp C (Q o \<phi>)" . qed text {* Any \emph{data} refinement of a deterministic program is correspondence. This is the analogous result to that relating program refinement and equivalence. *} lemma drefines_determ: fixes a::"'a prog" and b::"'b prog" assumes da: "determ (wp a)" and wa: "well_def a" and wb: "well_def b" and dr: "drefines \<phi> G a b" shows "pcorres \<phi> G a b" txt {* The proof follows exactly the same form as that for program refinement: Assuming that correspondence \emph{doesn't} hold, we show that @{term "wp b"} is not feasible, and thus not healthy, contradicting the assumption. *} proof(rule pcorresI, rule contrapos_pp) from wb show "feasible (wp b)" by(auto) note ha = well_def_wp_healthy[OF wa] note hb = well_def_wp_healthy[OF wb] from wb have "sublinear (wp b)" by(auto) moreover from hb have "feasible (wp b)" by(auto) ultimately have sab: "sub_add (wp b)" by(rule sublinear_subadd) fix Q::"'a \<Rightarrow> real" assume uQ: "unitary Q" hence uQ\<phi>: "unitary (Q o \<phi>)" by(auto) assume ne: "\<guillemotleft>G\<guillemotright> && (wp a Q o \<phi>) \<noteq> \<guillemotleft>G\<guillemotright> && wp b (Q o \<phi>)" hence ne': "wp a Q o \<phi> \<noteq> wp b (Q o \<phi>)" by(auto) txt {* From refinement, @{term "\<guillemotleft>G\<guillemotright> && (wp a Q o \<phi>)"} lies below @{term "\<guillemotleft>G\<guillemotright> && wp b (Q o \<phi>)"}. *} from ha uQ have gle: "\<guillemotleft>G\<guillemotright> && (wp a Q o \<phi>) \<tturnstile> wp b (Q o \<phi>)" by(blast intro!:drefinesD[OF dr]) have le: "\<guillemotleft>G\<guillemotright> && (wp a Q o \<phi>) \<tturnstile> \<guillemotleft>G\<guillemotright> && wp b (Q o \<phi>)" unfolding exp_conj_def proof(rule le_funI) fix s from gle have "\<guillemotleft>G\<guillemotright> s .& (wp a Q o \<phi>) s \<le> wp b (Q o \<phi>) s" unfolding exp_conj_def by(auto) hence "\<guillemotleft>G\<guillemotright> s .& (\<guillemotleft>G\<guillemotright> s .& (wp a Q o \<phi>) s) \<le> \<guillemotleft>G\<guillemotright> s .& wp b (Q o \<phi>) s" by(auto intro:pconj_mono) moreover from uQ ha have "wp a Q (\<phi> s) \<le> 1" by(auto dest:healthy_bounded_byD) moreover from uQ ha have "0 \<le> wp a Q (\<phi> s)" by(auto) ultimately show "\<guillemotleft> G \<guillemotright> s .& (wp a Q \<circ> \<phi>) s \<le> \<guillemotleft> G \<guillemotright> s .& wp b (Q \<circ> \<phi>) s" by(simp add:pconj_assoc) qed txt {* If the programs do not correspond, the terms must differ somewhere, and given the previous result, the second must be somewhere strictly larger than the first: *} have nle: "\<exists>s. (\<guillemotleft>G\<guillemotright> && (wp a Q o \<phi>)) s < (\<guillemotleft>G\<guillemotright> && wp b (Q o \<phi>)) s" proof(rule contrapos_np[OF ne], rule ext, rule antisym) fix s from le show "(\<guillemotleft>G\<guillemotright> && (wp a Q o \<phi>)) s \<le> (\<guillemotleft>G\<guillemotright> && wp b (Q o \<phi>)) s" by(blast) next fix s assume "\<not> (\<exists>s. (\<guillemotleft>G\<guillemotright> && (wp a Q \<circ> \<phi>)) s < (\<guillemotleft>G\<guillemotright> && wp b (Q \<circ> \<phi>)) s)" thus " (\<guillemotleft>G\<guillemotright> && (wp b (Q \<circ> \<phi>))) s \<le> (\<guillemotleft>G\<guillemotright> && (wp a Q \<circ> \<phi>)) s" by(simp add:not_less) qed from this obtain s where less_s: "(\<guillemotleft>G\<guillemotright> && (wp a Q \<circ> \<phi>)) s < (\<guillemotleft>G\<guillemotright> && wp b (Q \<circ> \<phi>)) s" by(blast) txt {* The transformers themselves must differ at this point: *} hence larger: "wp a Q (\<phi> s) < wp b (Q \<circ> \<phi>) s" proof(cases "G s") case True moreover from ha uQ have "0 \<le> wp a Q (\<phi> s)" by(blast) moreover from hb uQ\<phi> have "0 \<le> wp b (Q o \<phi>) s" by(blast) moreover note less_s ultimately show ?thesis by(simp add:exp_conj_def) next case False moreover from ha uQ have "wp a Q (\<phi> s) \<le> 1" by(blast) moreover { from uQ have "bounded_by 1 (Q o \<phi>)" by(blast) moreover from unitary_sound[OF uQ] have "sound (Q o \<phi>)" by(auto) ultimately have "wp b (Q o \<phi>) s \<le> 1" using hb by(auto) } moreover note less_s ultimately show ?thesis by(simp add:exp_conj_def) qed from less_s have "(\<guillemotleft>G\<guillemotright> && (wp a Q \<circ> \<phi>)) s \<noteq> (\<guillemotleft>G\<guillemotright> && wp b (Q \<circ> \<phi>)) s" by(force) txt {* @{term G} must also hold, as otherwise both would be zero. *} hence G_s: "G s" proof(rule contrapos_np) assume nG: "\<not> G s" moreover from ha uQ have "wp a Q (\<phi> s) \<le> 1" by(blast) moreover { from uQ have "bounded_by 1 (Q o \<phi>)" by(blast) moreover from unitary_sound[OF uQ] have "sound (Q o \<phi>)" by(auto) ultimately have "wp b (Q o \<phi>) s \<le> 1" using hb by(auto) } ultimately show "(\<guillemotleft>G\<guillemotright> && (wp a Q \<circ> \<phi>)) s = (\<guillemotleft>G\<guillemotright> && wp b (Q \<circ> \<phi>)) s" by(simp add:exp_conj_def) qed txt {* Take a carefully constructed expectation: *} let ?Qc = "\<lambda>s. bound_of Q - Q s" have bQc: "bounded_by 1 ?Qc" proof(rule bounded_byI) fix s from uQ have "bound_of Q \<le> 1" and "0 \<le> Q s" by(auto) thus "bound_of Q - Q s \<le> 1" by(auto) qed have sQc: "sound ?Qc" proof(rule soundI) from bQc show "bounded ?Qc" by(auto) show "nneg ?Qc" proof(rule nnegI) fix s from uQ have "Q s \<le> bound_of Q" by(auto) thus "0 \<le> bound_of Q - Q s" by(auto) qed qed txt {* By the maximality of @{term "wp a"}, @{term "wp b"} must violate feasibility, by mapping @{term s} to something strictly greater than @{term "bound_of Q"}. *} from uQ have "0 \<le> bound_of Q" by(auto) with da have "bound_of Q = wp a (\<lambda>s. bound_of Q) (\<phi> s)" by(simp add:maximalD determ_maximalD) also have "wp a (\<lambda>s. bound_of Q) (\<phi> s) = wp a (\<lambda>s. Q s + ?Qc s) (\<phi> s)" by(simp) also { from da have "additive (wp a)" by(blast) with uQ sQc have "wp a (\<lambda>s. Q s + ?Qc s) (\<phi> s) = wp a Q (\<phi> s) + wp a ?Qc (\<phi> s)" by(subst additiveD, blast+) } also { from ha and sQc and bQc have "\<guillemotleft>G\<guillemotright> && (wp a ?Qc o \<phi>) \<tturnstile> wp b (?Qc o \<phi>)" by(blast intro!:drefinesD[OF dr]) hence "(\<guillemotleft>G\<guillemotright> && (wp a ?Qc o \<phi>)) s \<le> wp b (?Qc o \<phi>) s" by(blast) moreover from sQc and ha have "0 \<le> wp a (\<lambda>s. bound_of Q - Q s) (\<phi> s)" by(blast) ultimately have "wp a ?Qc (\<phi> s) \<le> wp b (?Qc o \<phi>) s" using G_s by(simp add:exp_conj_def) hence "wp a Q (\<phi> s) + wp a ?Qc (\<phi> s) \<le> wp a Q (\<phi> s) + wp b (?Qc o \<phi>) s" by(rule add_left_mono) also with larger have "wp a Q (\<phi> s) + wp b (?Qc o \<phi>) s < wp b (Q o \<phi>) s + wp b (?Qc o \<phi>) s" by(auto) finally have "wp a Q (\<phi> s) + wp a ?Qc (\<phi> s) < wp b (Q o \<phi>) s + wp b (?Qc o \<phi>) s" . } also from sab and unitary_sound[OF uQ] and sQc have "wp b (Q o \<phi>) s + wp b (?Qc o \<phi>) s \<le> wp b (\<lambda>s. (Q o \<phi>) s + (?Qc o \<phi>) s) s" by(blast) also have "... = wp b (\<lambda>s. bound_of Q) s" by(simp) finally show "\<not> feasible (wp b)" proof(rule contrapos_pn) assume fb: "feasible (wp b)" have "bounded_by (bound_of Q) (\<lambda>s. bound_of Q)" by(blast) hence "bounded_by (bound_of Q) (wp b (\<lambda>s. bound_of Q))" using uQ by(blast intro:feasible_boundedD[OF fb]) hence "wp b (\<lambda>s. bound_of Q) s \<le> bound_of Q" by(blast) thus "\<not> bound_of Q < wp b (\<lambda>s. bound_of Q) s" by(simp) qed qed subsection {* Structural Rules for Correspondence *} lemma pcorres_Skip: "pcorres \<phi> G Skip Skip" by(simp add:pcorres_def wp_eval) text {* Correspondence composes over sequential composition. *} lemma pcorres_Seq: fixes A::"'b prog" and B::"'c prog" and C::"'b prog" and D::"'c prog" and \<phi>::"'c \<Rightarrow> 'b" assumes pcAB: "pcorres \<phi> G A B" and pcCD: "pcorres \<phi> H C D" and wA: "well_def A" and wB: "well_def B" and wC: "well_def C" and wD: "well_def D" and p3p2: "\<And>Q. unitary Q \<Longrightarrow> \<guillemotleft>I\<guillemotright> && wp B Q = wp B (\<guillemotleft>H\<guillemotright> && Q)" and p1p3: "\<And>s. G s \<Longrightarrow> I s" shows "pcorres \<phi> G (A;;C) (B;;D)" proof(rule pcorresI) fix Q::"'b \<Rightarrow> real" assume uQ: "unitary Q" with well_def_wp_healthy[OF wC] have uCQ: "unitary (wp C Q)" by(auto) from uQ well_def_wp_healthy[OF wD] have uDQ: "unitary (wp D (Q o \<phi>))" by(auto dest:unitary_comp) have p3p1: "\<And>R S. \<lbrakk> unitary R; unitary S; \<guillemotleft>I\<guillemotright> && R = \<guillemotleft>I\<guillemotright> && S \<rbrakk> \<Longrightarrow> \<guillemotleft>G\<guillemotright> && R = \<guillemotleft>G\<guillemotright> && S" proof(rule ext) fix R::"'c \<Rightarrow> real" and S::"'c \<Rightarrow> real" and s::'c assume a3: "\<guillemotleft>I\<guillemotright> && R = \<guillemotleft>I\<guillemotright> && S" and uR: "unitary R" and uS: "unitary S" show "(\<guillemotleft>G\<guillemotright> && R) s = (\<guillemotleft>G\<guillemotright> && S) s" proof(simp add:exp_conj_def, cases "G s") case False note this moreover from uR have "R s \<le> 1" by(blast) moreover from uS have "S s \<le> 1" by(blast) ultimately show "\<guillemotleft>G\<guillemotright> s .& R s = \<guillemotleft>G\<guillemotright> s .& S s" by(simp) next case True note p1 = this with p1p3 have "I s" by(blast) with fun_cong[OF a3, where x=s] have "1 .& R s = 1 .& S s" by(simp add:exp_conj_def) with p1 show "\<guillemotleft>G\<guillemotright> s .& R s = \<guillemotleft>G\<guillemotright> s .& S s" by(simp) qed qed show "\<guillemotleft>G\<guillemotright> && (wp (A;;C) Q o \<phi>) = \<guillemotleft>G\<guillemotright> && wp (B;;D) (Q o \<phi>)" proof(simp add:wp_eval) from uCQ pcAB have "\<guillemotleft>G\<guillemotright> && (wp A (wp C Q) \<circ> \<phi>) = \<guillemotleft>G\<guillemotright> && wp B ((wp C Q) \<circ> \<phi>)" by(auto dest:pcorresD) also have "\<guillemotleft>G\<guillemotright> && wp B ((wp C Q) \<circ> \<phi>) = \<guillemotleft>G\<guillemotright> && wp B (wp D (Q \<circ> \<phi>))" proof(rule p3p1) from uCQ well_def_wp_healthy[OF wB] show "unitary (wp B (wp C Q \<circ> \<phi>))" by(auto intro:unitary_comp) from uDQ well_def_wp_healthy[OF wB] show "unitary (wp B (wp D (Q \<circ> \<phi>)))" by(auto) from uQ have "\<guillemotleft> H \<guillemotright> && (wp C Q \<circ> \<phi>) = \<guillemotleft> H \<guillemotright> && wp D (Q \<circ> \<phi>)" by(blast intro:pcorresD[OF pcCD]) thus "\<guillemotleft> I \<guillemotright> && wp B (wp C Q \<circ> \<phi>) = \<guillemotleft> I \<guillemotright> && wp B (wp D (Q \<circ> \<phi>))" by(simp add:p3p2 uCQ uDQ) qed finally show "\<guillemotleft>G\<guillemotright> && (wp A (wp C Q) \<circ> \<phi>) = \<guillemotleft>G\<guillemotright> && wp B (wp D (Q \<circ> \<phi>))" . qed qed subsection {* Structural Rules for Data Refinement *} lemma dr_Skip: fixes \<phi>::"'c \<Rightarrow> 'b" shows "drefines \<phi> G Skip Skip" proof(intro drefinesI2 wd_intros) fix P::"'b \<Rightarrow> real" and Q::"'b \<Rightarrow> real" and s::'c assume "P \<tturnstile> wp Skip Q" hence "(P o \<phi>) s \<le> wp Skip Q (\<phi> s)" by(simp, blast) thus "(P o \<phi>) s \<le> wp Skip (Q o \<phi>) s" by(simp add:wp_eval) qed lemma dr_Abort: fixes \<phi>::"'c \<Rightarrow> 'b" shows "drefines \<phi> G Abort Abort" proof(intro drefinesI2 wd_intros) fix P::"'b \<Rightarrow> real" and Q::"'b \<Rightarrow> real" and s::'c assume "P \<tturnstile> wp Abort Q" hence "(P o \<phi>) s \<le> wp Abort Q (\<phi> s)" by(auto) thus "(P o \<phi>) s \<le> wp Abort (Q o \<phi>) s" by(simp add:wp_eval) qed lemma dr_Apply: fixes \<phi>::"'c \<Rightarrow> 'b" assumes commutes: "f o \<phi> = \<phi> o g" shows "drefines \<phi> G (Apply f) (Apply g)" proof(intro drefinesI2 wd_intros) fix P::"'b \<Rightarrow> real" and Q::"'b \<Rightarrow> real" and s::'c assume wp: "P \<tturnstile> wp (Apply f) Q" hence "P \<tturnstile> (Q o f)" by(simp add:wp_eval) hence "P (\<phi> s) \<le> (Q o f) (\<phi> s)" by(blast) also have "... = Q ((f o \<phi>) s)" by(simp) also with commutes have "... = ((Q o \<phi>) o g) s" by(simp) also have "... = wp (Apply g) (Q o \<phi>) s" by(simp add:wp_eval) finally show "(P o \<phi>) s \<le> wp (Apply g) (Q o \<phi>) s" by(simp) qed lemma dr_Seq: assumes drAB: "drefines \<phi> P A B" and drBC: "drefines \<phi> Q C D" and wpB: "\<guillemotleft>P\<guillemotright> \<tturnstile> wp B \<guillemotleft>Q\<guillemotright>" and wB: "well_def B" and wC: "well_def C" and wD: "well_def D" shows "drefines \<phi> P (A;;C) (B;;D)" proof fix R and S assume uR: "unitary R" and uS: "unitary S" and wpAC: "R \<tturnstile> wp (A;;C) S" from uR have "\<guillemotleft>P\<guillemotright> && (R o \<phi>) = \<guillemotleft>P\<guillemotright> && (\<guillemotleft>P\<guillemotright> && (R o \<phi>))" by(simp add:exp_conj_assoc) also { from well_def_wp_healthy[OF wC] uR uS and wpAC[unfolded eval_wp_Seq o_def] have "\<guillemotleft>P\<guillemotright> && (R o \<phi>) \<tturnstile> wp B (wp C S o \<phi>)" by(auto intro:drefinesD[OF drAB]) with wpB well_def_wp_healthy[OF wC] uS sublinear_sub_conj[OF well_def_wp_sublinear, OF wB] have "\<guillemotleft>P\<guillemotright> && (\<guillemotleft>P\<guillemotright> && (R o \<phi>)) \<tturnstile> wp B (\<guillemotleft>Q\<guillemotright> && (wp C S o \<phi>))" by(auto intro!:entails_combine dest!:unitary_sound) } also { from uS well_def_wp_healthy[OF wC] have "\<guillemotleft>Q\<guillemotright> && (wp C S o \<phi>) \<tturnstile> wp D (S o \<phi>)" by(auto intro!:drefinesD[OF drBC]) with well_def_wp_healthy[OF wB] well_def_wp_healthy[OF wC] well_def_wp_healthy[OF wD] and unitary_sound[OF uS] have "wp B (\<guillemotleft>Q\<guillemotright> && (wp C S o \<phi>)) \<tturnstile> wp B (wp D (S o \<phi>))" by(blast intro!:mono_transD) } finally show "\<guillemotleft>P\<guillemotright> && (R o \<phi>) \<tturnstile> wp (B;;D) (S o \<phi>)" unfolding wp_eval o_def . qed lemma dr_repeat: fixes \<phi> :: "'a \<Rightarrow> 'b" assumes dr_ab: "drefines \<phi> G a b" and Gpr: "\<guillemotleft>G\<guillemotright> \<tturnstile> wp b \<guillemotleft>G\<guillemotright>" and wa: "well_def a" and wb: "well_def b" shows "drefines \<phi> G (repeat n a) (repeat n b)" (is "?X n") proof(induct n) show "?X 0" by(simp add:dr_Skip) fix n assume IH: "?X n" thus "?X (Suc n)" by(auto intro!:dr_Seq Gpr assms wd_intros) qed end
Formal statement is: lemma open_negations: fixes S :: "'a::real_normed_vector set" shows "open S \<Longrightarrow> open ((\<lambda>x. - x) ` S)" Informal statement is: If $S$ is an open set, then so is the set of all negations of elements of $S$.
Formal statement is: lemma has_contour_integral_integrable: "(f has_contour_integral i) g \<Longrightarrow> f contour_integrable_on g" Informal statement is: If a function $f$ has a contour integral along a contour $g$, then $f$ is contour integrable along $g$.
module Main import BoundAst %default total
If $S$ is an open subset of $\mathbb{C}$, then $S$ is contractible if and only if $S$ is simply connected.
theory SINVAR_NonInterference imports "../TopoS_Helper" begin subsection {* SecurityInvariant NonInterference *} datatype node_config = Interfering | Unrelated definition default_node_properties :: "node_config" where "default_node_properties = Interfering" definition undirected_reachable :: "'v graph \<Rightarrow> 'v => 'v set" where "undirected_reachable G v = (succ_tran (undirected G) v) - {v}" lemma undirected_reachable_mono: "E' \<subseteq> E \<Longrightarrow> undirected_reachable \<lparr>nodes = N, edges = E'\<rparr> n \<subseteq> undirected_reachable \<lparr>nodes = N, edges = E\<rparr> n" unfolding undirected_reachable_def undirected_def succ_tran_def by (fastforce intro: trancl_mono) fun sinvar :: "'v graph \<Rightarrow> ('v \<Rightarrow> node_config) \<Rightarrow> bool" where "sinvar G nP = (\<forall> n \<in> (nodes G). (nP n) = Interfering \<longrightarrow> (nP ` (undirected_reachable G n)) \<subseteq> {Unrelated})" fun verify_globals :: "'v graph \<Rightarrow> ('v \<Rightarrow> node_config) \<Rightarrow> 'b \<Rightarrow> bool" where "verify_globals _ _ _ = True" definition receiver_violation :: "bool" where "receiver_violation = True" text{*simplifications for sets we need in the uniqueness proof*} lemma tmp1: "{(b, a). a = vertex_1 \<and> b = vertex_2} = {(vertex_2, vertex_1)}" by auto lemma tmp6: "{(vertex_1, vertex_2), (vertex_2, vertex_1)}\<^sup>+ = {(vertex_1, vertex_1), (vertex_2, vertex_2), (vertex_1, vertex_2), (vertex_2, vertex_1)}" apply(rule) apply(rule) apply(case_tac x, simp) apply(erule_tac r="{(vertex_1, vertex_2), (vertex_2, vertex_1)}" in trancl_induct) apply(auto) apply (metis (mono_tags) insertCI r_r_into_trancl)+ done lemma tmp2: "(insert (vertex_1, vertex_2) {(b, a). a = vertex_1 \<and> b = vertex_2})\<^sup>+ = {(vertex_1, vertex_1), (vertex_2, vertex_2), (vertex_1, vertex_2), (vertex_2, vertex_1)}" apply(subst tmp1) apply(fact tmp6) done lemma tmp3: "{(b, a). False} = {}" by simp lemma tmp4: "{(e1, e2). e1 = vertex_1 \<and> e2 = vertex_2 \<and> (e1 = vertex_1 \<longrightarrow> e2 \<noteq> vertex_2)} = {}" by blast lemma tmp5: "{(b, a). a = vertex_1 \<and> b = vertex_2 \<or> a = vertex_1 \<and> b = vertex_2 \<and> (a = vertex_1 \<longrightarrow> b \<noteq> vertex_2)} = {(vertex_2, vertex_1)}" by fastforce lemma unique_default_example: "undirected_reachable \<lparr>nodes = {vertex_1, vertex_2}, edges = {(vertex_1, vertex_2)}\<rparr> vertex_1 = {vertex_2}" by(auto simp add: undirected_def undirected_reachable_def succ_tran_def tmp2) lemma unique_default_example_hlp1: "delete_edges \<lparr>nodes = {vertex_1, vertex_2}, edges = {(vertex_1, vertex_2)}\<rparr> {(vertex_1, vertex_2)} = \<lparr>nodes = {vertex_1, vertex_2}, edges = {}\<rparr>" by(simp add: delete_edges_def) lemma unique_default_example_2: "undirected_reachable (delete_edges \<lparr>nodes = {vertex_1, vertex_2}, edges = {(vertex_1, vertex_2)}\<rparr> {(vertex_1,vertex_2 )}) vertex_1 = {}" apply(simp add: undirected_def undirected_reachable_def succ_tran_def unique_default_example_hlp1) apply(subst tmp3) by auto lemma unique_default_example_3: "undirected_reachable (delete_edges \<lparr>nodes = {vertex_1, vertex_2}, edges = {(vertex_1, vertex_2)}\<rparr> {(vertex_1,vertex_2 )}) vertex_2 = {}" apply(simp add: undirected_def undirected_reachable_def succ_tran_def unique_default_example_hlp1) apply(subst tmp3) by auto lemma unique_default_example_4: "(undirected_reachable (add_edge vertex_1 vertex_2 (delete_edges \<lparr>nodes = {vertex_1, vertex_2}, edges = {(vertex_1, vertex_2)}\<rparr> {(vertex_1, vertex_2)})) vertex_1) = {vertex_2}" apply(simp add: delete_edges_def add_edge_def undirected_def undirected_reachable_def succ_tran_def) apply(subst tmp4) apply(subst tmp5) apply(simp) apply(subst tmp6) by force lemma unique_default_example_5: "(undirected_reachable (add_edge vertex_1 vertex_2 (delete_edges \<lparr>nodes = {vertex_1, vertex_2}, edges = {(vertex_1, vertex_2)}\<rparr> {(vertex_1, vertex_2)})) vertex_2) = {vertex_1}" apply(simp add: delete_edges_def add_edge_def undirected_def undirected_reachable_def succ_tran_def) apply(subst tmp4) apply(subst tmp5) apply(simp) apply(subst tmp6) by force (*lemma empty_undirected_reachable_false: "xb \<in> undirected_reachable \<lparr>nodes = nodes G, edges = {(e1, e2). False}\<rparr> na \<longleftrightarrow> False" apply(simp add: undirected_reachable_def succ_tran_def undirected_def) apply(subst tmp3) by fastforce*) lemma empty_undirected_reachable_false: "xb \<in> undirected_reachable (delete_edges G (edges G)) na \<longleftrightarrow> False" apply(simp add: undirected_reachable_def succ_tran_def undirected_def delete_edges_edges_empty) apply(subst tmp3) by fastforce subsubsection{*monotonic and preliminaries*} interpretation NonInterference: SecurityInvariant_IFS where default_node_properties = SINVAR_NonInterference.default_node_properties and sinvar = SINVAR_NonInterference.sinvar and verify_globals = verify_globals unfolding SINVAR_NonInterference.default_node_properties_def apply unfold_locales apply(rule ballI) apply(drule SINVAR_NonInterference.offending_notevalD) apply(simp) apply clarify apply(rename_tac xa) apply(case_tac "nP xa") (*case Interfering*) apply simp apply(erule_tac x=n and A="nodes G" in ballE) prefer 2 apply fast apply(simp) apply(thin_tac "valid_graph G") apply(thin_tac "(a,b) \<in> f") apply(thin_tac "n \<in> nodes G") apply(thin_tac "nP n = Interfering") apply(erule disjE) apply (metis fun_upd_other fun_upd_same imageI node_config.distinct(1) set_rev_mp singleton_iff) apply (metis fun_upd_other fun_upd_same imageI node_config.distinct(1) set_rev_mp singleton_iff) (*case Unrelated*) apply simp (*unique: *) apply(erule default_uniqueness_by_counterexample_IFS) apply (simp add: SecurityInvariant_withOffendingFlows.set_offending_flows_def SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def SecurityInvariant_withOffendingFlows.is_offending_flows_def) apply (simp add:delete_edges_set_nodes) apply (simp split: split_split_asm split_split) apply(rule_tac x="\<lparr> nodes={vertex_1,vertex_2}, edges = {(vertex_1,vertex_2)} \<rparr>" in exI, simp) apply(rule conjI) apply(simp add: valid_graph_def) apply(rule_tac x="(\<lambda> x. default_node_properties)(vertex_1 := Interfering, vertex_2 := Interfering)" in exI, simp) apply(rule conjI) apply(simp add: unique_default_example) apply(rule_tac x="vertex_2" in exI, simp) apply(rule_tac x="{(vertex_1,vertex_2)}" in exI, simp) apply(simp add: unique_default_example) apply(simp add: unique_default_example_2) apply(simp add: unique_default_example_3) apply(simp add: unique_default_example_4) apply(simp add: unique_default_example_5) apply(case_tac otherbot) apply simp apply(simp add:graph_ops) done lemma TopoS_NonInterference: "SecurityInvariant sinvar default_node_properties receiver_violation" unfolding receiver_violation_def by unfold_locales hide_const (open) sinvar verify_globals receiver_violation default_node_properties --{*Hide all the helper lemmas.*} hide_fact tmp1 tmp2 tmp3 tmp4 tmp5 tmp6 unique_default_example unique_default_example_2 unique_default_example_3 unique_default_example_4 unique_default_example_5 empty_undirected_reachable_false end
module Cats.Category.Constructions.Iso where open import Relation.Binary using (IsEquivalence ; Setoid) open import Level open import Cats.Category.Base open import Cats.Util.Conv import Relation.Binary.EqReasoning as EqReasoning import Cats.Category.Constructions.Epi as Epi import Cats.Category.Constructions.Mono as Mono module Build {lo la l≈} (Cat : Category lo la l≈) where private open module Cat = Category Cat open Cat.≈-Reasoning open Epi.Build Cat open Mono.Build Cat record _≅_ (A B : Obj) : Set (lo ⊔ la ⊔ l≈) where field forth : A ⇒ B back : B ⇒ A back-forth : back ∘ forth ≈ id forth-back : forth ∘ back ≈ id open _≅_ instance HasArrow-≅ : ∀ {A B} → HasArrow (A ≅ B) lo la l≈ HasArrow-≅ = record { Cat = Cat ; _⃗ = forth } ≅-equiv : IsEquivalence _≅_ ≅-equiv = record { refl = refl ; sym = sym ; trans = trans } where refl : ∀ {A} → A ≅ A refl {A} = record { forth = id ; back = id ; back-forth = id-l ; forth-back = id-l } sym : ∀ {A B} → A ≅ B → B ≅ A sym iso = record { forth = back iso ; back = forth iso ; back-forth = forth-back iso ; forth-back = back-forth iso } trans : ∀ {A B C : Obj} → A ≅ B → B ≅ C → A ≅ C trans {A} {B} {C} A≅B B≅C = record { forth = forth B≅C ∘ forth A≅B ; back = back A≅B ∘ back B≅C ; back-forth = begin (back A≅B ∘ back B≅C) ∘ forth B≅C ∘ forth A≅B ≈⟨ assoc ⟩ back A≅B ∘ back B≅C ∘ forth B≅C ∘ forth A≅B ≈⟨ ∘-resp-r (≈.trans unassoc (∘-resp-l (back-forth B≅C))) ⟩ back A≅B ∘ id ∘ forth A≅B ≈⟨ ∘-resp-r id-l ⟩ back A≅B ∘ forth A≅B ≈⟨ back-forth A≅B ⟩ id ∎ ; forth-back = begin (forth B≅C ∘ forth A≅B) ∘ back A≅B ∘ back B≅C ≈⟨ assoc ⟩ forth B≅C ∘ forth A≅B ∘ back A≅B ∘ back B≅C ≈⟨ ∘-resp-r (≈.trans unassoc (∘-resp-l (forth-back A≅B))) ⟩ forth B≅C ∘ id ∘ back B≅C ≈⟨ ∘-resp-r id-l ⟩ forth B≅C ∘ back B≅C ≈⟨ forth-back B≅C ⟩ id ∎ } ≅-Setoid : Setoid lo (lo ⊔ la ⊔ l≈) ≅-Setoid = record { Carrier = Obj ; _≈_ = _≅_ ; isEquivalence = ≅-equiv } module ≅ = IsEquivalence ≅-equiv module ≅-Reasoning = EqReasoning ≅-Setoid iso-mono : ∀ {A B} (iso : A ≅ B) → IsMono (forth iso) iso-mono iso {g = g} {h} iso∘g≈iso∘h = begin g ≈⟨ ≈.sym id-l ⟩ id ∘ g ≈⟨ ∘-resp-l (≈.sym (back-forth iso)) ⟩ (back iso ∘ forth iso) ∘ g ≈⟨ assoc ⟩ back iso ∘ forth iso ∘ g ≈⟨ ∘-resp-r iso∘g≈iso∘h ⟩ back iso ∘ forth iso ∘ h ≈⟨ unassoc ⟩ (back iso ∘ forth iso) ∘ h ≈⟨ ∘-resp-l (back-forth iso) ⟩ id ∘ h ≈⟨ id-l ⟩ h ∎ iso-epi : ∀ {A B} (iso : A ≅ B) → IsEpi (forth iso) iso-epi iso {g = g} {h} g∘iso≈h∘iso = begin g ≈⟨ ≈.sym id-r ⟩ g ∘ id ≈⟨ ∘-resp-r (≈.sym (forth-back iso)) ⟩ g ∘ forth iso ∘ back iso ≈⟨ unassoc ⟩ (g ∘ forth iso) ∘ back iso ≈⟨ ∘-resp-l g∘iso≈h∘iso ⟩ (h ∘ forth iso) ∘ back iso ≈⟨ assoc ⟩ h ∘ forth iso ∘ back iso ≈⟨ ∘-resp-r (forth-back iso) ⟩ h ∘ id ≈⟨ id-r ⟩ h ∎
// // Copyright (c) 2019-2021 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include <boost/nowide/args.hpp> #include <boost/nowide/convert.hpp> int main(int argc, char** argv, char** env) { boost::nowide::args _(argc, argv, env); if(argc < 1) return 1; if(boost::nowide::narrow(boost::nowide::widen(argv[0])) != argv[0]) return 1; return 0; }
The law firm of Rhonda Peoples-Waters, P.A. is pleased to offer aggressive, trusted and professional legal representation. This firm specializes in the areas of personal injury, auto accidents, and criminal defense. The trial experience associated with the law firm of Rhonda Peoples-Waters P.A. is distinguishable and noteworthy. This law firm prides itself with “treating our clients as we desire to be treated.” We invite you to join us in our quest for JUSTICE for ALL. Rhonda Peoples-Waters is an auto accident lawyer in Jacksonville, FL. She has been an auto accident lawyer in Jacksonville, FL since 1999. Rhonda Peoples-Waters, P.A. also provides counsel on a variety of civil law cases including: personal injury, contract law, family law, traffic law, and wills & probate. Selling alcohol to a minor.
Megan Emerick is a FUNimation veteran of almost 9 years, with some of the best shows the company's anime catalog has to offer under her belt! (Yuri Gamagori), and she's appeared in countless other classics, like Soul Eater and Fairy Tail! To learn more about Megan, follow her on Twitter (@MeganEmerick)!
using LHEF using Test const SAMPLES_DIR = joinpath(@__DIR__, "") @testset "laziness" begin lazyevents = parse_lhe(joinpath(SAMPLES_DIR, "ft.lhe")) @test lazyevents isa Base.Generator events = collect(lazyevents) @test events isa Vector @test length(events) == 45 end @testset "parsing" begin events = parse_lhe(joinpath(SAMPLES_DIR, "ft.lhe")) |> collect event = events[1] particles = event.particles header = event.header @test values(header) == (6, 0, 0.1182900E-04, 0.2556536E+03, 0.7546771E-02, 0.1112889E+00) @test length(particles) == 6 @test values(particles[1]) == (0, 21, -1, 0, 0, 502, 503, 0.00000000000E+00 , 0.00000000000E+00 , 0.10709531583E+04 , 0.10709531583E+04, 0.00000000000E+00, 0., -1.) @test values(particles[2]) == (1, 21, -1, 0, 0, 501, 504, 0.00000000000E+00 , 0.00000000000E+00 , -0.77476002582E+03, 0.77476002582E+03, 0.00000000000E+00, 0., 1.) @test values(particles[3]) == (2, 6 , 1 , 1, 2, 501, 0 , 0.11337785248E+03 , 0.11416185862E+03 , -0.41887649846E+02, 0.23993966451E+03, 0.17300000000E+03, 0., 1.) @test values(particles[4]) == (3, 6 , 1 , 1, 2, 502, 0 , 0.34597641987E+02 , -0.27246642769E+03,-0.24576811815E+03 , 0.40714360973E+03, 0.17300000000E+03, 0., 1.) @test values(particles[5]) == (4, -6, 1 , 1, 2, 0 , 503, 0.15534573574E+02 , 0.18289123966E+03 , 0.82271340950E+03 , 0.86050966450E+03, 0.17300000000E+03, 0., -1.) @test values(particles[6]) == (5, -6, 1 , 1, 2, 0 , 504, -0.16351006804E+03,-0.24586670591E+02 ,-0.23886450899E+03 , 0.33812024543E+03, 0.17300000000E+03, 0., -1.) end @testset "gzip" begin e1 = parse_lhe(joinpath(SAMPLES_DIR, "ft.lhe")) |> collect e2 = parse_lhe(joinpath(SAMPLES_DIR, "ft.lhe.gz")) |> collect @test all([e1[i].particles == e2[i].particles for i in 1:length(e1)]) end @testset "flattened particles" begin particles = flatparticles(joinpath(SAMPLES_DIR, "ft.lhe.gz")) @test length(particles) == 270 @test maximum(p.eventnum for p in particles) == 45 end
In the uk, adjudication is on the market without any consideration for events to a building agreement, following the enactment of the Housing offers development and Regeneration Act 1996. usually, inside a relatively brief time period, events in dispute could have a call from an adjudicator, which, other than in constrained situations, the courts will implement. Adjudication has develop into the number 1 approach to dispute solution within the building industry. The brief timescale signifies that a celebration must comprehend what to do, whilst to do it and be capable of payment that the opposite social gathering and the adjudicator are following the fitting steps. A Practical Guide to building Adjudication provides events the mandatory info to accomplish this. It presents an easy assessment of the method and process of adjudication by way of connection with laws and case legislation, augmented with sensible advice together with feedback on what to do or to not do, drafting advice and checklists. Separate chapters for Scotland and northern eire determine and clarify the diversities in method and judicial interpretation among these jurisdictions and England and Wales, and extra designated factors of the adjudication regimes in Australia, eire, Malaysia, New Zealand and Singapore are integrated. all the chapters on jurisdictions outdoors England and Wales has been written by means of senior specialists in these jurisdictions to make sure the content material is actual and insightful. There are various useful appendices together with a financial institution of version shape adjudication files and tabulated targeted comparisons of the Scheme for development Contracts, the opposite significant adjudication ideas, the key adjudicator nominating our bodies and the united kingdom and foreign regimes. Readers will rather take pleasure in the main finished index of adjudication situations to be had, taken care of into 260 topic headings offering speedy entry to all of the pronounced situations on any adjudication topic. The publication goals at offering a cutting-edge evaluate and evaluation of the established order and way forward for the ODR box through the top ODR students on the earth. foreign, comparative, and interdisciplinary techniques were applied, and the booklet is split into major components. partly one, in-depth evaluate of ODR, its purposes, and destiny is equipped in a comparative and analytical context, and half presents a neighborhood orientated procedure, the place the clients, demanding situations, and good fortune of ODR and its purposes within the North the USA, Latin the US, Africa, Australia, Europe, and Asia is mapped and entirely addressed. As a linguistically-grounded, serious exam of consent, this quantity perspectives consent no longer as a person psychological country or act yet as a strategy that's interactionally-and discursively-situated. It highlights the ways that felony consent is frequently fictional (at top) end result of the impoverished view of that means and the linguistic ideologies that usually tell interpretations and representations within the criminal approach. Englische anti-suit injunctions zur Durchsetzung von Schiedsvereinbarungen untersagen dem Kläger in einem aus englischer Sicht ausländischen staatlichen Verfahren, dieses unter Verletzung einer Schiedsvereinbarung zu betreiben. Ingrid Naumann untersucht, inwiefern die großzügige Haltung englischer Gerichte beim Erlass solcher anti-suit injunctions im Widerspruch zu der Beschränkung steht, anti-suit injunctions nur im Einklang mit der internationalen Comitas zu erlassen. Neste texto s? o analisados os aspetos essenciais do regime do documento eletronico, em conformidade com os seguintes diplomas: Regulamento (EU) n? 910/2014, Regime Juridico do Documento Eletronico e da Assinatura electronic, Codigo Civil, Codigo de Processo Civil e Codigo do Notariado. Presidiu a investigac?
{ InformerScen.mpl } TITLE InformerScen; STOCHASTIC TREE TwoStage; SCENARIOS scen := 1..10; RANDOM DATA Demand[scen] := (210, 290, 335, 370, 415, 450, 460, 495, 540, 585); PROBABILITIES prob[scen] := (0.03, 0.134, 0.086, 0.188, 0.226, 0.08, 0.056, 0.132, 0.06, 0.008); DATA Budget := 1500; ProdCost := 0.81; SellPrice := 0.90; Margin := SellPrice - ProdCost; DECISION VARIABLES Production; STAGE2 VARIABLES Shortfall; Excess; MODEL MAX Profit = Margin * Production - Margin * Shortfall - SellPrice * Excess; SUBJECT TO BudgetLimit: Production * ProdCost <= Budget; Balance: Production + Shortfall - Excess = Demand; END -------------------------------------------------------------------------------------- VarCount = 3 ConCount = 2 StageCount = 2 VarStages[vars] := (1,2,2) ConStages[cons] := (1,2) ScenCount = 10 RandomCount = 10 TreeType = TWOSTAGE TreeStage[scen] := (1,2,2,2,2,2,2,2,2,2) ProbData[scen] := (0.03, 0.134, 0.086, 0.188, 0.226, 0.08, 0.056, 0.132, 0.06, 0.008) RandomScen[random] := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) RandomVar[random] := (RHS, RHS, RHS, RHS, RHS, RHS, RHS, RHS, RHS, RHS) RandomCon[random] := (2, 2, 2, 2, 2, 2, 2, 2, 2, 2) RandomData[random] := (210, 290, 335, 370, 415, 450, 460, 495, 540, 585) --------------------------------------------------------------------------------------
module Main import HTML import VNode import Render import Attributes Model : Type Model = Integer %foreign "browser:lambda: (node, func) => node.onclick = func" prim__onClick : AnyPtr -> (IO ()) -> PrimIO AnyPtr initModel : Model initModel = 0 view : Model -> DOM V view count = div [] [ h1 [] [text "Count"] , span [] [text count] , button [Id "inc", Class ["test", "foobar"]] [text "+"] ] update : Model -> IO () update model = do root <- getRoot "idris-root" let model = model + 1 let html = view model live <- render root html button <- getRoot "inc" _ <- primIO $ prim__onClick button (update model) pure () main : IO () main = do update (-1)
[GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A U✝ : C S✝ : Sieve U✝ hS : S✝ ∈ GrothendieckTopology.sieves J U✝ ⊢ Sieve.functorPushforward (𝟭 C) S✝ ∈ GrothendieckTopology.sieves J ((𝟭 C).obj U✝) [PROOFSTEP] simpa using hS [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A F : C ⥤ D hF : CoverPreserving J K F G : D ⥤ A hG : CoverPreserving K L G U✝ : C S✝ : Sieve U✝ hS : S✝ ∈ GrothendieckTopology.sieves J U✝ ⊢ Sieve.functorPushforward (F ⋙ G) S✝ ∈ GrothendieckTopology.sieves L ((F ⋙ G).obj U✝) [PROOFSTEP] rw [Sieve.functorPushforward_comp] [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A F : C ⥤ D hF : CoverPreserving J K F G : D ⥤ A hG : CoverPreserving K L G U✝ : C S✝ : Sieve U✝ hS : S✝ ∈ GrothendieckTopology.sieves J U✝ ⊢ Sieve.functorPushforward G (Sieve.functorPushforward F S✝) ∈ GrothendieckTopology.sieves L ((F ⋙ G).obj U✝) [PROOFSTEP] exact hG.cover_preserve (hF.cover_preserve hS) [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x ⊢ Compatible (FamilyOfElements.functorPushforward G x) [PROOFSTEP] rintro Z₁ Z₂ W g₁ g₂ f₁' f₂' H₁ H₂ eq [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x Z₁ Z₂ W : D g₁ : W ⟶ Z₁ g₂ : W ⟶ Z₂ f₁' : Z₁ ⟶ G.obj Z f₂' : Z₂ ⟶ G.obj Z H₁ : Presieve.functorPushforward G T f₁' H₂ : Presieve.functorPushforward G T f₂' eq : g₁ ≫ f₁' = g₂ ≫ f₂' ⊢ ℱ.val.map g₁.op (FamilyOfElements.functorPushforward G x f₁' H₁) = ℱ.val.map g₂.op (FamilyOfElements.functorPushforward G x f₂' H₂) [PROOFSTEP] unfold FamilyOfElements.functorPushforward [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x Z₁ Z₂ W : D g₁ : W ⟶ Z₁ g₂ : W ⟶ Z₂ f₁' : Z₁ ⟶ G.obj Z f₂' : Z₂ ⟶ G.obj Z H₁ : Presieve.functorPushforward G T f₁' H₂ : Presieve.functorPushforward G T f₂' eq : g₁ ≫ f₁' = g₂ ≫ f₂' ⊢ ℱ.val.map g₁.op (FunctorPushforwardStructure.casesOn (getFunctorPushforwardStructure H₁) fun Z_1 g h h₁ fac => ℱ.val.map h.op (x g h₁)) = ℱ.val.map g₂.op (FunctorPushforwardStructure.casesOn (getFunctorPushforwardStructure H₂) fun Z_1 g h h₁ fac => ℱ.val.map h.op (x g h₁)) [PROOFSTEP] rcases getFunctorPushforwardStructure H₁ with ⟨X₁, f₁, h₁, hf₁, rfl⟩ [GOAL] case mk C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x Z₁ Z₂ W : D g₁ : W ⟶ Z₁ g₂ : W ⟶ Z₂ f₂' : Z₂ ⟶ G.obj Z H₂ : Presieve.functorPushforward G T f₂' X₁ : C f₁ : X₁ ⟶ Z h₁ : Z₁ ⟶ G.obj X₁ hf₁ : T f₁ H₁ : Presieve.functorPushforward G T (h₁ ≫ G.map f₁) eq : g₁ ≫ h₁ ≫ G.map f₁ = g₂ ≫ f₂' ⊢ ℱ.val.map g₁.op (FunctorPushforwardStructure.casesOn { preobj := X₁, premap := f₁, lift := h₁, cover := hf₁, fac := (_ : h₁ ≫ G.map f₁ = h₁ ≫ G.map f₁) } fun Z_1 g h h₁_1 fac => ℱ.val.map h.op (x g h₁_1)) = ℱ.val.map g₂.op (FunctorPushforwardStructure.casesOn (getFunctorPushforwardStructure H₂) fun Z_1 g h h₁ fac => ℱ.val.map h.op (x g h₁)) [PROOFSTEP] rcases getFunctorPushforwardStructure H₂ with ⟨X₂, f₂, h₂, hf₂, rfl⟩ [GOAL] case mk.mk C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x Z₁ Z₂ W : D g₁ : W ⟶ Z₁ g₂ : W ⟶ Z₂ X₁ : C f₁ : X₁ ⟶ Z h₁ : Z₁ ⟶ G.obj X₁ hf₁ : T f₁ H₁ : Presieve.functorPushforward G T (h₁ ≫ G.map f₁) X₂ : C f₂ : X₂ ⟶ Z h₂ : Z₂ ⟶ G.obj X₂ hf₂ : T f₂ H₂ : Presieve.functorPushforward G T (h₂ ≫ G.map f₂) eq : g₁ ≫ h₁ ≫ G.map f₁ = g₂ ≫ h₂ ≫ G.map f₂ ⊢ ℱ.val.map g₁.op (FunctorPushforwardStructure.casesOn { preobj := X₁, premap := f₁, lift := h₁, cover := hf₁, fac := (_ : h₁ ≫ G.map f₁ = h₁ ≫ G.map f₁) } fun Z_1 g h h₁_1 fac => ℱ.val.map h.op (x g h₁_1)) = ℱ.val.map g₂.op (FunctorPushforwardStructure.casesOn { preobj := X₂, premap := f₂, lift := h₂, cover := hf₂, fac := (_ : h₂ ≫ G.map f₂ = h₂ ≫ G.map f₂) } fun Z_1 g h h₁ fac => ℱ.val.map h.op (x g h₁)) [PROOFSTEP] suffices ℱ.val.map (g₁ ≫ h₁).op (x f₁ hf₁) = ℱ.val.map (g₂ ≫ h₂).op (x f₂ hf₂) by simpa using this [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x Z₁ Z₂ W : D g₁ : W ⟶ Z₁ g₂ : W ⟶ Z₂ X₁ : C f₁ : X₁ ⟶ Z h₁ : Z₁ ⟶ G.obj X₁ hf₁ : T f₁ H₁ : Presieve.functorPushforward G T (h₁ ≫ G.map f₁) X₂ : C f₂ : X₂ ⟶ Z h₂ : Z₂ ⟶ G.obj X₂ hf₂ : T f₂ H₂ : Presieve.functorPushforward G T (h₂ ≫ G.map f₂) eq : g₁ ≫ h₁ ≫ G.map f₁ = g₂ ≫ h₂ ≫ G.map f₂ this : ℱ.val.map (g₁ ≫ h₁).op (x f₁ hf₁) = ℱ.val.map (g₂ ≫ h₂).op (x f₂ hf₂) ⊢ ℱ.val.map g₁.op (FunctorPushforwardStructure.casesOn { preobj := X₁, premap := f₁, lift := h₁, cover := hf₁, fac := (_ : h₁ ≫ G.map f₁ = h₁ ≫ G.map f₁) } fun Z_1 g h h₁_1 fac => ℱ.val.map h.op (x g h₁_1)) = ℱ.val.map g₂.op (FunctorPushforwardStructure.casesOn { preobj := X₂, premap := f₂, lift := h₂, cover := hf₂, fac := (_ : h₂ ≫ G.map f₂ = h₂ ≫ G.map f₂) } fun Z_1 g h h₁ fac => ℱ.val.map h.op (x g h₁)) [PROOFSTEP] simpa using this [GOAL] case mk.mk C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x Z₁ Z₂ W : D g₁ : W ⟶ Z₁ g₂ : W ⟶ Z₂ X₁ : C f₁ : X₁ ⟶ Z h₁ : Z₁ ⟶ G.obj X₁ hf₁ : T f₁ H₁ : Presieve.functorPushforward G T (h₁ ≫ G.map f₁) X₂ : C f₂ : X₂ ⟶ Z h₂ : Z₂ ⟶ G.obj X₂ hf₂ : T f₂ H₂ : Presieve.functorPushforward G T (h₂ ≫ G.map f₂) eq : g₁ ≫ h₁ ≫ G.map f₁ = g₂ ≫ h₂ ≫ G.map f₂ ⊢ ℱ.val.map (g₁ ≫ h₁).op (x f₁ hf₁) = ℱ.val.map (g₂ ≫ h₂).op (x f₂ hf₂) [PROOFSTEP] apply hG.Compatible ℱ h _ _ hf₁ hf₂ [GOAL] case mk.mk C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x Z₁ Z₂ W : D g₁ : W ⟶ Z₁ g₂ : W ⟶ Z₂ X₁ : C f₁ : X₁ ⟶ Z h₁ : Z₁ ⟶ G.obj X₁ hf₁ : T f₁ H₁ : Presieve.functorPushforward G T (h₁ ≫ G.map f₁) X₂ : C f₂ : X₂ ⟶ Z h₂ : Z₂ ⟶ G.obj X₂ hf₂ : T f₂ H₂ : Presieve.functorPushforward G T (h₂ ≫ G.map f₂) eq : g₁ ≫ h₁ ≫ G.map f₁ = g₂ ≫ h₂ ≫ G.map f₂ ⊢ (g₁ ≫ h₁) ≫ G.map f₁ = (g₂ ≫ h₂) ≫ G.map f₂ [PROOFSTEP] simpa using eq [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : FamilyOfElements.Compatible x Y : C f : Y ⟶ Z hf : T f ⊢ FamilyOfElements.functorPushforward G x (G.map f) (_ : Presieve.functorPushforward G T (G.map f)) = x f hf [PROOFSTEP] unfold FamilyOfElements.functorPushforward [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : FamilyOfElements.Compatible x Y : C f : Y ⟶ Z hf : T f ⊢ (FunctorPushforwardStructure.casesOn (getFunctorPushforwardStructure (_ : Presieve.functorPushforward G T (G.map f))) fun Z_1 g h h₁ fac => ℱ.val.map h.op (x g h₁)) = x f hf [PROOFSTEP] rcases e₁ : getFunctorPushforwardStructure (image_mem_functorPushforward G T hf) with ⟨X, g, f', hg, eq⟩ [GOAL] case mk C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : FamilyOfElements.Compatible x Y : C f : Y ⟶ Z hf : T f X : C g : X ⟶ Z f' : G.obj Y ⟶ G.obj X hg : T g eq : G.map f = f' ≫ G.map g e₁ : getFunctorPushforwardStructure (_ : Presieve.functorPushforward G T (G.map f)) = { preobj := X, premap := g, lift := f', cover := hg, fac := eq } ⊢ (FunctorPushforwardStructure.casesOn { preobj := X, premap := g, lift := f', cover := hg, fac := eq } fun Z_1 g h h₁ fac => ℱ.val.map h.op (x g h₁)) = x f hf [PROOFSTEP] simpa using hG.Compatible ℱ h f' (𝟙 _) hg hf (by simp [eq]) [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : FamilyOfElements.Compatible x Y : C f : Y ⟶ Z hf : T f X : C g : X ⟶ Z f' : G.obj Y ⟶ G.obj X hg : T g eq : G.map f = f' ≫ G.map g e₁ : getFunctorPushforwardStructure (_ : Presieve.functorPushforward G T (G.map f)) = { preobj := X, premap := g, lift := f', cover := hg, fac := eq } ⊢ f' ≫ G.map g = 𝟙 (G.obj Y) ≫ G.map f [PROOFSTEP] simp [eq] [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ : SheafOfTypes K✝ Z : C✝ T : Presieve Z x : FamilyOfElements (G✝.op ⋙ ℱ.val) T h : Compatible x C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ⊢ CompatiblePreserving K G [PROOFSTEP] constructor [GOAL] case Compatible C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ : SheafOfTypes K✝ Z : C✝ T : Presieve Z x : FamilyOfElements (G✝.op ⋙ ℱ.val) T h : Compatible x C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ⊢ ∀ (ℱ : SheafOfTypes K) {Z : C} {T : Presieve Z} {x : FamilyOfElements (G.op ⋙ ℱ.val) T}, Compatible x → ∀ {Y₁ Y₂ : C} {X : D} (f₁ : X ⟶ G.obj Y₁) (f₂ : X ⟶ G.obj Y₂) {g₁ : Y₁ ⟶ Z} {g₂ : Y₂ ⟶ Z} (hg₁ : T g₁) (hg₂ : T g₂), f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ → ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] intro ℱ Z T x hx Y₁ Y₂ X f₁ f₂ g₁ g₂ hg₁ hg₂ e [GOAL] case Compatible C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ ⊢ ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] let c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) /- This can then be viewed as a cospan of structured arrows, and we may obtain an arbitrary cone over it since `StructuredArrow W u` is cofiltered. Then, it suffices to prove that it is compatible when restricted onto `u(c'.X.right)`. -/ [GOAL] case Compatible C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) ⊢ ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] let c' := IsCofiltered.cone (c.toStructuredArrow ⋙ StructuredArrow.pre _ _ _) [GOAL] case Compatible C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) ⊢ ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] have eq₁ : f₁ = (c'.pt.hom ≫ G.map (c'.π.app left).right) ≫ eqToHom (by simp) := by erw [← (c'.π.app left).w] dsimp simp [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) ⊢ G.obj ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).obj left).right = G.obj Y₁ [PROOFSTEP] simp [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) ⊢ f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) [PROOFSTEP] erw [← (c'.π.app left).w] [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) ⊢ f₁ = ((Functor.fromPUnit c.pt).map (NatTrans.app c'.π left).left ≫ ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).obj left).hom) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) [PROOFSTEP] dsimp [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) ⊢ f₁ = (𝟙 X ≫ f₁ ≫ 𝟙 (G.obj Y₁)) ≫ 𝟙 (G.obj Y₁) [PROOFSTEP] simp [GOAL] case Compatible C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) ⊢ ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] have eq₂ : f₂ = (c'.pt.hom ≫ G.map (c'.π.app right).right) ≫ eqToHom (by simp) := by erw [← (c'.π.app right).w] dsimp simp [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) ⊢ G.obj ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).obj right).right = G.obj Y₂ [PROOFSTEP] simp [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) ⊢ f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) [PROOFSTEP] erw [← (c'.π.app right).w] [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) ⊢ f₂ = ((Functor.fromPUnit c.pt).map (NatTrans.app c'.π right).left ≫ ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).obj right).hom) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) [PROOFSTEP] dsimp [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) ⊢ f₂ = (𝟙 X ≫ f₂ ≫ 𝟙 (G.obj Y₂)) ≫ 𝟙 (G.obj Y₂) [PROOFSTEP] simp [GOAL] case Compatible C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) ⊢ ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] conv_lhs => rw [eq₁] [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) | ℱ.val.map f₁.op (x g₁ hg₁) [PROOFSTEP] rw [eq₁] [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) | ℱ.val.map f₁.op (x g₁ hg₁) [PROOFSTEP] rw [eq₁] [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) | ℱ.val.map f₁.op (x g₁ hg₁) [PROOFSTEP] rw [eq₁] [GOAL] case Compatible C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) ⊢ ℱ.val.map ((c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁)).op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] conv_rhs => rw [eq₂] [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) | ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] rw [eq₂] [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) | ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] rw [eq₂] [GOAL] C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) | ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] rw [eq₂] [GOAL] case Compatible C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) ⊢ ℱ.val.map ((c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁)).op (x g₁ hg₁) = ℱ.val.map ((c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂)).op (x g₂ hg₂) [PROOFSTEP] simp only [op_comp, Functor.map_comp, types_comp_apply, eqToHom_op, eqToHom_map] [GOAL] case Compatible C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) ⊢ ℱ.val.map (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).pt.hom.op (ℱ.val.map (G.map (NatTrans.app (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).π left).right).op (eqToHom (_ : ℱ.val.obj (op (G.obj Y₁)) = ℱ.val.obj (op (G.obj ((Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G).obj left).right))) (x g₁ hg₁))) = ℱ.val.map (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).pt.hom.op (ℱ.val.map (G.map (NatTrans.app (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).π right).right).op (eqToHom (_ : ℱ.val.obj (op (G.obj Y₂)) = ℱ.val.obj (op (G.obj ((Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G).obj right).right))) (x g₂ hg₂))) [PROOFSTEP] apply congr_arg [GOAL] case Compatible.h C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) ⊢ ℱ.val.map (G.map (NatTrans.app (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).π left).right).op (eqToHom (_ : ℱ.val.obj (op (G.obj Y₁)) = ℱ.val.obj (op (G.obj ((Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G).obj left).right))) (x g₁ hg₁)) = ℱ.val.map (G.map (NatTrans.app (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).π right).right).op (eqToHom (_ : ℱ.val.obj (op (G.obj Y₂)) = ℱ.val.obj (op (G.obj ((Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G).obj right).right))) (x g₂ hg₂)) [PROOFSTEP] injection c'.π.naturality WalkingCospan.Hom.inl with _ e₁ [GOAL] case Compatible.h C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) left_eq✝ : (((Functor.const WalkingCospan).obj c'.pt).map Hom.inl).left ≫ (NatTrans.app c'.π one).left = (NatTrans.app c'.π left).left ≫ ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).map Hom.inl).left e₁ : (((Functor.const WalkingCospan).obj c'.pt).map Hom.inl).right ≫ (NatTrans.app c'.π one).right = (NatTrans.app c'.π left).right ≫ ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).map Hom.inl).right ⊢ ℱ.val.map (G.map (NatTrans.app (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).π left).right).op (eqToHom (_ : ℱ.val.obj (op (G.obj Y₁)) = ℱ.val.obj (op (G.obj ((Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G).obj left).right))) (x g₁ hg₁)) = ℱ.val.map (G.map (NatTrans.app (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).π right).right).op (eqToHom (_ : ℱ.val.obj (op (G.obj Y₂)) = ℱ.val.obj (op (G.obj ((Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G).obj right).right))) (x g₂ hg₂)) [PROOFSTEP] injection c'.π.naturality WalkingCospan.Hom.inr with _ e₂ [GOAL] case Compatible.h C✝ : Type u₁ inst✝⁵ : Category.{v₁, u₁} C✝ D✝ : Type u₂ inst✝⁴ : Category.{v₂, u₂} D✝ A : Type u₃ inst✝³ : Category.{v₃, u₃} A J : GrothendieckTopology C✝ K✝ : GrothendieckTopology D✝ L : GrothendieckTopology A G✝ : C✝ ⥤ D✝ hG : CompatiblePreserving K✝ G✝ ℱ✝ : SheafOfTypes K✝ Z✝ : C✝ T✝ : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₁ inst✝¹ : Category.{v₁, u₁} D K : GrothendieckTopology D G : C ⥤ D inst✝ : RepresentablyFlat G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ G.obj Y₁ f₂ : X ⟶ G.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ e : f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂ c : Cone (cospan g₁ g₂ ⋙ G) := (Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e) c' : Cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) := IsCofiltered.cone (Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G) eq₁ : f₁ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π left).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₁ ≫ 𝟙 (G.obj Y₁)))).right = G.obj Y₁) eq₂ : f₂ = (c'.pt.hom ≫ G.map (NatTrans.app c'.π right).right) ≫ eqToHom (_ : G.obj ((StructuredArrow.pre X (cospan g₁ g₂) G).obj (StructuredArrow.mk (f₂ ≫ 𝟙 (G.obj Y₂)))).right = G.obj Y₂) left_eq✝¹ : (((Functor.const WalkingCospan).obj c'.pt).map Hom.inl).left ≫ (NatTrans.app c'.π one).left = (NatTrans.app c'.π left).left ≫ ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).map Hom.inl).left e₁ : (((Functor.const WalkingCospan).obj c'.pt).map Hom.inl).right ≫ (NatTrans.app c'.π one).right = (NatTrans.app c'.π left).right ≫ ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).map Hom.inl).right left_eq✝ : (((Functor.const WalkingCospan).obj c'.pt).map Hom.inr).left ≫ (NatTrans.app c'.π one).left = (NatTrans.app c'.π right).left ≫ ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).map Hom.inr).left e₂ : (((Functor.const WalkingCospan).obj c'.pt).map Hom.inr).right ≫ (NatTrans.app c'.π one).right = (NatTrans.app c'.π right).right ≫ ((Cone.toStructuredArrow c ⋙ StructuredArrow.pre c.pt (cospan g₁ g₂) G).map Hom.inr).right ⊢ ℱ.val.map (G.map (NatTrans.app (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).π left).right).op (eqToHom (_ : ℱ.val.obj (op (G.obj Y₁)) = ℱ.val.obj (op (G.obj ((Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G).obj left).right))) (x g₁ hg₁)) = ℱ.val.map (G.map (NatTrans.app (IsCofiltered.cone (Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G)).π right).right).op (eqToHom (_ : ℱ.val.obj (op (G.obj Y₂)) = ℱ.val.obj (op (G.obj ((Cone.toStructuredArrow ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)) ⋙ StructuredArrow.pre ((Cones.postcompose (diagramIsoCospan (cospan g₁ g₂ ⋙ G)).inv).obj (PullbackCone.mk f₁ f₂ e)).pt (cospan g₁ g₂) G).obj right).right))) (x g₂ hg₂)) [PROOFSTEP] exact hx (c'.π.app left).right (c'.π.app right).right hg₁ hg₂ (e₁.symm.trans e₂) [GOAL] C : Type u₁ inst✝⁴ : Category.{v₁, u₁} C D : Type u₂ inst✝³ : Category.{v₂, u₂} D A : Type u₃ inst✝² : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x F : C ⥤ D inst✝¹ : Full F inst✝ : Faithful F hF : {c : C} → {d : D} → (d ⟶ F.obj c) → (c' : C) × (F.obj c' ≅ d) ⊢ CompatiblePreserving K F [PROOFSTEP] constructor [GOAL] case Compatible C : Type u₁ inst✝⁴ : Category.{v₁, u₁} C D : Type u₂ inst✝³ : Category.{v₂, u₂} D A : Type u₃ inst✝² : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G.op ⋙ ℱ.val) T h : Compatible x F : C ⥤ D inst✝¹ : Full F inst✝ : Faithful F hF : {c : C} → {d : D} → (d ⟶ F.obj c) → (c' : C) × (F.obj c' ≅ d) ⊢ ∀ (ℱ : SheafOfTypes K) {Z : C} {T : Presieve Z} {x : FamilyOfElements (F.op ⋙ ℱ.val) T}, Compatible x → ∀ {Y₁ Y₂ : C} {X : D} (f₁ : X ⟶ F.obj Y₁) (f₂ : X ⟶ F.obj Y₂) {g₁ : Y₁ ⟶ Z} {g₂ : Y₂ ⟶ Z} (hg₁ : T g₁) (hg₂ : T g₂), f₁ ≫ F.map g₁ = f₂ ≫ F.map g₂ → ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] introv hx he [GOAL] case Compatible C : Type u₁ inst✝⁴ : Category.{v₁, u₁} C D : Type u₂ inst✝³ : Category.{v₂, u₂} D A : Type u₃ inst✝² : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ✝ : SheafOfTypes K Z✝ : C T✝ : Presieve Z✝ x✝ : FamilyOfElements (G.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ F : C ⥤ D inst✝¹ : Full F inst✝ : Faithful F hF : {c : C} → {d : D} → (d ⟶ F.obj c) → (c' : C) × (F.obj c' ≅ d) ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (F.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ F.obj Y₁ f₂ : X ⟶ F.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ he : f₁ ≫ F.map g₁ = f₂ ≫ F.map g₂ ⊢ ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] obtain ⟨X', e⟩ := hF f₁ [GOAL] case Compatible.mk C : Type u₁ inst✝⁴ : Category.{v₁, u₁} C D : Type u₂ inst✝³ : Category.{v₂, u₂} D A : Type u₃ inst✝² : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ✝ : SheafOfTypes K Z✝ : C T✝ : Presieve Z✝ x✝ : FamilyOfElements (G.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ F : C ⥤ D inst✝¹ : Full F inst✝ : Faithful F hF : {c : C} → {d : D} → (d ⟶ F.obj c) → (c' : C) × (F.obj c' ≅ d) ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (F.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ F.obj Y₁ f₂ : X ⟶ F.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ he : f₁ ≫ F.map g₁ = f₂ ≫ F.map g₂ X' : C e : F.obj X' ≅ X ⊢ ℱ.val.map f₁.op (x g₁ hg₁) = ℱ.val.map f₂.op (x g₂ hg₂) [PROOFSTEP] apply (ℱ.1.mapIso e.op).toEquiv.injective [GOAL] case Compatible.mk.a C : Type u₁ inst✝⁴ : Category.{v₁, u₁} C D : Type u₂ inst✝³ : Category.{v₂, u₂} D A : Type u₃ inst✝² : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ✝ : SheafOfTypes K Z✝ : C T✝ : Presieve Z✝ x✝ : FamilyOfElements (G.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ F : C ⥤ D inst✝¹ : Full F inst✝ : Faithful F hF : {c : C} → {d : D} → (d ⟶ F.obj c) → (c' : C) × (F.obj c' ≅ d) ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (F.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ F.obj Y₁ f₂ : X ⟶ F.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ he : f₁ ≫ F.map g₁ = f₂ ≫ F.map g₂ X' : C e : F.obj X' ≅ X ⊢ ↑(ℱ.val.mapIso (Iso.op e)).toEquiv (ℱ.val.map f₁.op (x g₁ hg₁)) = ↑(ℱ.val.mapIso (Iso.op e)).toEquiv (ℱ.val.map f₂.op (x g₂ hg₂)) [PROOFSTEP] simp only [Iso.op_hom, Iso.toEquiv_fun, ℱ.1.mapIso_hom, ← FunctorToTypes.map_comp_apply] [GOAL] case Compatible.mk.a C : Type u₁ inst✝⁴ : Category.{v₁, u₁} C D : Type u₂ inst✝³ : Category.{v₂, u₂} D A : Type u₃ inst✝² : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ✝ : SheafOfTypes K Z✝ : C T✝ : Presieve Z✝ x✝ : FamilyOfElements (G.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ F : C ⥤ D inst✝¹ : Full F inst✝ : Faithful F hF : {c : C} → {d : D} → (d ⟶ F.obj c) → (c' : C) × (F.obj c' ≅ d) ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (F.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ F.obj Y₁ f₂ : X ⟶ F.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ he : f₁ ≫ F.map g₁ = f₂ ≫ F.map g₂ X' : C e : F.obj X' ≅ X ⊢ ℱ.val.map (f₁.op ≫ e.hom.op) (x g₁ hg₁) = ℱ.val.map (f₂.op ≫ e.hom.op) (x g₂ hg₂) [PROOFSTEP] simpa using hx (F.preimage <| e.hom ≫ f₁) (F.preimage <| e.hom ≫ f₂) hg₁ hg₂ (F.map_injective <| by simpa using he) [GOAL] C : Type u₁ inst✝⁴ : Category.{v₁, u₁} C D : Type u₂ inst✝³ : Category.{v₂, u₂} D A : Type u₃ inst✝² : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G : C ⥤ D hG : CompatiblePreserving K G ℱ✝ : SheafOfTypes K Z✝ : C T✝ : Presieve Z✝ x✝ : FamilyOfElements (G.op ⋙ ℱ✝.val) T✝ h : Compatible x✝ F : C ⥤ D inst✝¹ : Full F inst✝ : Faithful F hF : {c : C} → {d : D} → (d ⟶ F.obj c) → (c' : C) × (F.obj c' ≅ d) ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (F.op ⋙ ℱ.val) T hx : Compatible x Y₁ Y₂ : C X : D f₁ : X ⟶ F.obj Y₁ f₂ : X ⟶ F.obj Y₂ g₁ : Y₁ ⟶ Z g₂ : Y₂ ⟶ Z hg₁ : T g₁ hg₂ : T g₂ he : f₁ ≫ F.map g₁ = f₂ ≫ F.map g₂ X' : C e : F.obj X' ≅ X ⊢ F.map (F.preimage (e.hom ≫ f₁) ≫ g₁) = F.map (F.preimage (e.hom ≫ f₂) ≫ g₂) [PROOFSTEP] simpa using he [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A ⊢ Presheaf.IsSheaf J (G.op ⋙ ℱ.val) [PROOFSTEP] intro X U S hS x hx [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x ⊢ ∃! t, IsAmalgamation x t [PROOFSTEP] change FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) _ at x [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x ⊢ ∃! t, IsAmalgamation x t [PROOFSTEP] let H := ℱ.2 X _ (hG₂.cover_preserve hS) [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) ⊢ ∃! t, IsAmalgamation x t [PROOFSTEP] let hx' := hx.functorPushforward hG₁ (sheafOver ℱ X) [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx ⊢ ∃! t, IsAmalgamation x t [PROOFSTEP] constructor [GOAL] case h C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx ⊢ (fun t => IsAmalgamation x t) ?w ∧ ∀ (y : ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U)), (fun t => IsAmalgamation x t) y → y = ?w case w C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx ⊢ ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U) [PROOFSTEP] swap [GOAL] case w C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx ⊢ ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U) [PROOFSTEP] apply H.amalgamate (x.functorPushforward G) [GOAL] case w C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx ⊢ Compatible (FamilyOfElements.functorPushforward G x) [PROOFSTEP] exact hx' [GOAL] case h C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx ⊢ (fun t => IsAmalgamation x t) (IsSheafFor.amalgamate H (FamilyOfElements.functorPushforward G x) hx') ∧ ∀ (y : ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U)), (fun t => IsAmalgamation x t) y → y = IsSheafFor.amalgamate H (FamilyOfElements.functorPushforward G x) hx' [PROOFSTEP] constructor [GOAL] case h.left C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx ⊢ (fun t => IsAmalgamation x t) (IsSheafFor.amalgamate H (FamilyOfElements.functorPushforward G x) hx') [PROOFSTEP] intro V f hf [GOAL] case h.left C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx V : C f : V ⟶ U hf : S.arrows f ⊢ ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).map f.op (IsSheafFor.amalgamate H (FamilyOfElements.functorPushforward G x) hx') = x f hf [PROOFSTEP] convert H.isAmalgamation hx' (G.map f) (image_mem_functorPushforward G S hf) [GOAL] case h.e'_3.h C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx V : C f : V ⟶ U hf : S.arrows f e_1✝ : ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op V) = (ℱ.val ⋙ coyoneda.obj (op X)).obj (op (G.obj V)) ⊢ x f hf = FamilyOfElements.functorPushforward G x (G.map f) (_ : Presieve.functorPushforward G S.arrows (G.map f)) [PROOFSTEP] rw [hG₁.apply_map (sheafOver ℱ X) hx] [GOAL] case h.right C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx ⊢ ∀ (y : ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U)), (fun t => IsAmalgamation x t) y → y = IsSheafFor.amalgamate H (FamilyOfElements.functorPushforward G x) hx' [PROOFSTEP] intro y hy [GOAL] case h.right C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx y : ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U) hy : IsAmalgamation x y ⊢ y = IsSheafFor.amalgamate H (FamilyOfElements.functorPushforward G x) hx' [PROOFSTEP] refine' H.isSeparatedFor _ y _ _ (H.isAmalgamation (hx.functorPushforward hG₁ (sheafOver ℱ X))) [GOAL] case h.right C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx y : ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U) hy : IsAmalgamation x y ⊢ IsAmalgamation (FamilyOfElements.functorPushforward G x) y [PROOFSTEP] rintro V f ⟨Z, f', g', h, rfl⟩ -- porting note: didn't need coercion (S : Presieve U) in Lean 3 [GOAL] case h.right.intro.intro.intro.intro C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z✝ : C T : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h✝ : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx y : ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U) hy : IsAmalgamation x y V : D Z : C f' : Z ⟶ U g' : V ⟶ G.obj Z h : S.arrows f' ⊢ (ℱ.val ⋙ coyoneda.obj (op X)).map (g' ≫ G.map f').op y = FamilyOfElements.functorPushforward G x (g' ≫ G.map f') (_ : ∃ Z_1 g h, S.arrows g ∧ g' ≫ G.map f' = h ≫ G.map g) [PROOFSTEP] erw [FamilyOfElements.comp_of_compatible (S.functorPushforward G) hx' (image_mem_functorPushforward G (S : Presieve U) h) g'] [GOAL] case h.right.intro.intro.intro.intro C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z✝ : C T : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h✝ : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx y : ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U) hy : IsAmalgamation x y V : D Z : C f' : Z ⟶ U g' : V ⟶ G.obj Z h : S.arrows f' ⊢ (ℱ.val ⋙ coyoneda.obj (op X)).map (g' ≫ G.map f').op y = (sheafOver ℱ X).val.map g'.op (FamilyOfElements.functorPushforward G x (G.map f') (_ : Presieve.functorPushforward G S.arrows (G.map f'))) [PROOFSTEP] dsimp [GOAL] case h.right.intro.intro.intro.intro C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z✝ : C T : Presieve Z✝ x✝ : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h✝ : Compatible x✝ G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A X : A U : C S : Sieve U hS : S ∈ GrothendieckTopology.sieves J U x : FamilyOfElements (G.op ⋙ ℱ.val ⋙ coyoneda.obj (op X)) S.arrows hx : Compatible x H : IsSheafFor (ℱ.val ⋙ coyoneda.obj (op X)) (Sieve.functorPushforward G S).arrows := Sheaf.cond ℱ X (Sieve.functorPushforward G S) (CoverPreserving.cover_preserve hG₂ hS) hx' : Compatible (FamilyOfElements.functorPushforward G x) := Compatible.functorPushforward hG₁ (sheafOver ℱ X) hx y : ((G.op ⋙ ℱ.val) ⋙ coyoneda.obj (op X)).obj (op U) hy : IsAmalgamation x y V : D Z : C f' : Z ⟶ U g' : V ⟶ G.obj Z h : S.arrows f' ⊢ y ≫ ℱ.val.map ((G.map f').op ≫ g'.op) = FamilyOfElements.functorPushforward G x (G.map f') (_ : Presieve.functorPushforward G S.arrows (G.map f')) ≫ ℱ.val.map g'.op [PROOFSTEP] simp [hG₁.apply_map (sheafOver ℱ X) hx h, ← hy f' h] [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A ⊢ { obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.map (𝟙 ℱ) = 𝟙 ({ obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.obj ℱ) [PROOFSTEP] ext1 [GOAL] case h C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ✝ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G✝.op ⋙ ℱ✝.val) T h : Compatible x G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G ℱ : Sheaf K A ⊢ ({ obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.map (𝟙 ℱ)).val = (𝟙 ({ obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.obj ℱ)).val [PROOFSTEP] apply ((whiskeringLeft _ _ _).obj G.op).map_id [GOAL] C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G✝.op ⋙ ℱ.val) T h : Compatible x G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G X✝ Y✝ Z✝ : Sheaf K A f : X✝ ⟶ Y✝ g : Y✝ ⟶ Z✝ ⊢ { obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.map (f ≫ g) = { obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.map f ≫ { obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.map g [PROOFSTEP] ext1 [GOAL] case h C : Type u₁ inst✝² : Category.{v₁, u₁} C D : Type u₂ inst✝¹ : Category.{v₂, u₂} D A : Type u₃ inst✝ : Category.{v₃, u₃} A J : GrothendieckTopology C K : GrothendieckTopology D L : GrothendieckTopology A G✝ : C ⥤ D hG : CompatiblePreserving K G✝ ℱ : SheafOfTypes K Z : C T : Presieve Z x : FamilyOfElements (G✝.op ⋙ ℱ.val) T h : Compatible x G : C ⥤ D hG₁ : CompatiblePreserving K G hG₂ : CoverPreserving J K G X✝ Y✝ Z✝ : Sheaf K A f : X✝ ⟶ Y✝ g : Y✝ ⟶ Z✝ ⊢ ({ obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.map (f ≫ g)).val = ({ obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.map f ≫ { obj := fun ℱ => pullbackSheaf hG₁ hG₂ ℱ, map := fun {X Y} f => { val := ((whiskeringLeft Cᵒᵖ Dᵒᵖ A).obj G.op).map f.val } }.map g).val [PROOFSTEP] apply ((whiskeringLeft _ _ _).obj G.op).map_comp
Although never gaining wide fame , Ali had a dedicated following on the vaudeville circuit in the United States . He performed for heads of state including Tsar Nicholas II of Russia . Judy Garland named him her favorite vaudevillian and David Blaine identified Ali as his favorite magician . Portions of his act were captured in the short film Strange as It Seems ( 1930 ) and in Politiquerias ( 1931 ) , the Spanish @-@ language version of Laurel and Hardy 's Chickens Come Home . Two documentaries contain footage of Ali taken from Politiquerias : 1977 's Gizmo ! , and 1999 's Vaudeville . Ali 's unusual gastric abilities led to rumors that the Rockefeller Institute had offered a large sum of money to obtain his stomach post @-@ mortem . After he died in England , his body was offered to Johns Hopkins University for study , though the offer was declined .
Set Warnings "-notation-overridden". Require Import Category.Lib. Require Export Category.Theory.Category. Generalizable All Variables. Set Primitive Projections. Set Universe Polymorphism. Unset Transparent Obligations. Reserved Notation "C ^op" (at level 7). Definition Opposite `(C : Category) : Category := {| obj := @obj C; hom := fun x y => @hom C y x; homset := fun x y => @homset C y x; id := @id C; compose := fun _ _ _ f g => g ∘ f; compose_respects := fun x y z f g fg h i hi => @compose_respects C z y x h i hi f g fg; id_left := fun x y f => @id_right C y x f; id_right := fun x y f => @id_left C y x f; comp_assoc := fun x y z w f g h => @comp_assoc_sym C w z y x h g f; comp_assoc_sym := fun x y z w f g h => @comp_assoc C w z y x h g f |}. Notation "C ^op" := (@Opposite C) (at level 7, format "C ^op") : category_scope. Lemma op_invol {C : Category} : (C^op)^op = C. Proof. unfold Opposite; simpl. destruct C; simpl. f_equal. Qed. Definition op {C : Category} {x y} (f : y ~{C}~> x) : x ~{C^op}~> y := f. Definition unop {C : Category} {x y} (f : x ~{C^op}~> y) : y ~{C}~> x := f. (* If two objects are isomorphic in C, then they are also isomorphic in C^op, just the conversion arrows are flipped. *) Require Export Category.Theory.Isomorphism. Program Instance Isomorphism_Opposite {C : Category} {x y : C} (iso : @Isomorphism C x y) : @Isomorphism (C^op) x y := { to := from iso; from := to iso; iso_to_from := iso_to_from iso; iso_from_to := iso_from_to iso }.
(* Property from Productive Use of Failure in Inductive Proof, Andrew Ireland and Alan Bundy, JAR 1996. This Isabelle theory is produced using the TIP tool offered at the following website: https://github.com/tip-org/tools This file was originally provided as part of TIP benchmark at the following website: https://github.com/tip-org/benchmarks Yutaka Nagashima at CIIRC, CTU changed the TIP output theory file slightly to make it compatible with Isabelle2017.*) theory TIP_prop_48 imports "../../Test_Base" begin datatype 'a list = nil2 | cons2 "'a" "'a list" datatype Nat = Z | S "Nat" fun length :: "'a list => Nat" where "length (nil2) = Z" | "length (cons2 y xs) = S (length xs)" fun t2 :: "Nat => Nat => bool" where "t2 (Z) y = True" | "t2 (S z) (Z) = False" | "t2 (S z) (S x2) = t2 z x2" fun insert :: "Nat => Nat list => Nat list" where "insert x (nil2) = cons2 x (nil2)" | "insert x (cons2 z xs) = (if t2 x z then cons2 x (cons2 z xs) else cons2 z (insert x xs))" fun isort :: "Nat list => Nat list" where "isort (nil2) = nil2" | "isort (cons2 y xs) = insert y (isort xs)" theorem property0 : "((length (isort x)) = (length x))" oops end
# Copyright (c) 2018-2021, Carnegie Mellon University # See LICENSE for details IsASPAlgebra := x -> IsRec(x) and IsBound(x.isASPAlgebra) and x.isASPAlgebra; Class(AlgebraOps, PrintOps, rec( \= := (b1, b2) -> Cond( not IsASPAlgebra(b1) or not IsASPAlgebra(b2), false, ObjId(b1)=ObjId(b2) and b1.rChildren() = b2.rChildren()) )); Class(ASPAlgebra, rec( isASPAlgebra:=true, codeletShape := self >> Concatenation([ObjId(self)], List(self.rChildren(), CodeletShape)), from_rChildren := (self, rch) >> ApplyFunc(ObjId(self), rch), unparse := "RewritableObjectExp", )); Declare(XN_skew, XN_plus_1, XN_min_1, XN_min_w); #F XN_min_1(n) -- represents x^n - 1 polynomial #F Spectral decomposition: 1d and 2d components #F <n> even or odd #F Class(XN_min_1, ASPAlgebra, rec( __call__ := (self, n, rot) >> let(nn:=_unwrap(n), Checked(IsPosIntSym(nn), IsIntSym(rot), WithBases(self, rec(n := nn, rot := rot, operations := PrintOps)))), hashAs := self >> ObjId(self)(self.n, 1), rChildren := self >> [self.n, self.rot], rSetChild := rSetChildFields("n", "rot"), print := self >> Print(self.__name__, "(", self.n, ", ", self.rot,")"), conj := self >> CopyFields(self, rec(rot := -self.rot)), prettyPrint := self >> PrintEval("x$1 - 1", When(self.n=1, "", Concat("^", StringInt(self.n)))), rspectrum := self >> let(rot := EvalScalar(self.rot), n := EvalScalar(self.n), Cond( n <= 1, [self], # if n<=1 then then can't decompose further Concatenation( [ XN_min_1(1, rot) ], Cond(IsOddInt(n), [], [XN_plus_1(1, rot)]), List([1..Int((n-1)/2)], i -> XN_skew(2, i/n, rot))) )), cspectrum := self >> let(rot := EvalScalar(self.rot), n := EvalScalar(self.n), Cond( n = 1, [self], n = 2, [XN_min_1(1,self.rot), XN_plus_1(1, self.rot)], n > 2, ConcatList(self.rspectrum(), x -> x.cspectrum()) )), # rfactor(1) == rspectrum() # rfactor(n) == self rfactor := (self, m) >> Checked((self.n mod m) = 0, List(XN_min_1(self.n/m, self.rot).rspectrum(), x -> CopyFields(x, rec(n := x.n * m)))), shift := self >> Z(self.n, -1) )); #F XN_min_1U(n) -- represents x^n - 1 polynomial #F Spectral decomposition: 2d components only #F <n> must be even #F Class(XN_min_1U, XN_min_1, rec( __call__ := (self, n, rot) >> let(nn:=_unwrap(n), Checked(IsPosIntSym(nn), IsSymbolic(nn) or IsEvenInt(nn), IsIntSym(rot), WithBases(self, rec(n := nn, rot := rot, operations := PrintOps)))), rspectrum := self >> let(rot := EvalScalar(self.rot), n := EvalScalar(self.n), Cond( self.n <= 1, [self], # if n==1 then then can't decompose further Concatenation( Cond(IsOddInt(n), [XN_min_1(1, rot)], [XN_min_1(2, rot)]), List([1..Int((n-1)/2)], i -> XN_skew(2, i/n, rot))) )) )); Class(XN_skew_base, ASPAlgebra, rec( prettyPrint := self >> Cond(IsOddInt(self.n) or self.a=1/4, PrintEval("x$1 + 1", When(self.n=1, "", Concat("^", StringInt(self.n)))), PrintEval("x^$1 - 2 x$2 cos($3*pi) + 1", self.n, When(self.n=2, "", Concat("^", StringInt(self.n/2))), 2*self.a) ), conj := self >> CopyFields(self, rec(rot := -self.rot)), shift := self >> let(n:=self.n, cos:=CosPi(self.rot*2*self.a), i := Ind(n), HStack(VStack(O(1,n-1),I(n-1)), Mat([List([0..n-1], i -> Cond(i=0, -1, i=n/2, 2*cos, 0))]).transpose())), cspectrum := self >> let(rot := EvalScalar(self.rot), n := EvalScalar(self.n), Cond( n = 1, [self], n = 2, [XN_min_w(1,self.a, rot), XN_min_w(1,1-self.a, rot)], n > 2, ConcatList(self.rspectrum(), x -> x.cspectrum()) )) )); #F XN_skew(n, a, rot) -- represents x^n - 2x^{n/2} cospi(2*a) + 1 polynomial #F Spectral decomposition: 2d components only #F <n> must be even #F Class(XN_skew, XN_skew_base, rec( __call__ := (self, n, a, rot) >> let(nn := _unwrap(n), Checked(IsPosIntSym(nn), IsSymbolic(nn) or IsEvenInt(nn), IsIntSym(rot), IsRatSym(a), IsSymbolic(a) or (0 < a and a < 1), WithBases(self, rec(n := nn, a := a, rot := rot, operations := PrintOps)))), hashAs := self >> XN_skew(self.n, 1/16, 1), rChildren := self >> [self.n, self.a, self.rot], rSetChild := rSetChildFieldsF(_unwrap, "n", "a", "rot"), print := self >> Print(self.__name__, "(", self.n, ", ", self.a, ", ", self.rot, ")"), rspectrum := self >> let(rot := EvalScalar(self.rot), n := EvalScalar(self.n), Cond( n <= 2, [self], # if n<=2 then then can't decompose further List([0..Int(n/2)-1], i -> XN_skew(2, (i + self.a)/(n/2), rot)))), # rfactor(1) == rspectrum(), rfactor(n) == self rfactor := (self, m) >> Checked(IsEvenInt(m), m > 1, (self.n mod m) = 0, List(XN_skew(2*self.n/m, self.a, self.rot).rspectrum(), x -> CopyFields(x, rec(n := x.n * m/2)))), )); #F XN_plus_1(n, rot) -- represents x^n + 1 polynomial #F Spectral decomposition: 1d and 2d components #F <n> even or odd #F Class(XN_plus_1, XN_skew_base, rec( __call__ := (self, n, rot) >> let(nn:=_unwrap(n), Checked(IsPosIntSym(nn), IsIntSym(rot), WithBases(self, rec(n := nn, a := 1/4, rot := rot, operations := PrintOps)))), rspectrum := self >> let(rot := EvalScalar(self.rot), n := EvalScalar(self.n), Cond( n <= 2, [self], # if n<=2 then then can't decompose further Concatenation( List([0..Int(n/2)-1], i -> XN_skew(2, (i + 1/2)/(n), rot)), Cond(IsEvenInt(n), [], [XN_plus_1(1, rot)])) )), rfactor := (self, mm) >> Checked(mm >= 1, (self.n mod mm) = 0, Cond( IsOddInt(mm) and not IsOddInt(self.n), Error("<mm> can only be odd if polynomial degree (self.n) is odd"), let(m := When(IsOddInt(self.n), mm, mm/2), List(XN_plus_1(self.n/m, self.rot).rspectrum(), x -> CopyFields(x, rec(n := x.n * m)))))), hashAs := self >> XN_plus_1(self.n, 1), rChildren := self >> [self.n, self.rot], rSetChild := rSetChildFields("n", "rot"), print := self >> Print(self.__name__, "(", self.n, ", ", self.rot, ")"), )); #F XN_min_w(n, a, rot) -- represents x^n - w_a polynomial #F Spectral decomposition: 1d components only over complex numbers #F Class(XN_min_w, XN_skew_base, rec( __call__ := (self, n, a, rot) >> let(nn:=_unwrap(n), Checked( IsPosIntSym(nn), IsRatSym(a), IsSymbolic(a) or (0 < a and a < 1), IsIntSym(rot), WithBases(self, rec(n := nn, a := a, rot := rot, operations := PrintOps)))), hashAs := self >> XN_min_w(self.n, 1/16, 1), rChildren := self >> [self.n, self.a, self.rot], rSetChild := rSetChildFields("n", "a", "rot"), print := self >> Print(self.__name__, "(", self.n, ", ", self.a, ", ", self.rot, ")"), rspectrum := self >> Error("Polynomial algebra is complex, no real spectrum"), cspectrum := self >> let(rot := EvalScalar(self.rot), n := EvalScalar(self.n), Cond( n = 1, [self], # if n<=2 then then can't decompose further List([0..n-1], i -> XN_min_1(1, (i + self.a)/n, rot)))), prettyPrint := self >> PrintEval("x^$1 - w_$2", self.n, self.a), shift := self >> let(n:=self.n, cos:=CosPi(self.rot*2*self.a), i := Ind(n), DirectSum(_omega(EvalScalar(self.a))*I(1), When(n=1, [], I(n-1)))* Prm(Z(n,-1))) ));
""" Taylor-Green vortex in 2D and 3D. """ import numpy as np from lettuce.unit import UnitConversion class TaylorGreenVortex2D: def __init__(self, resolution, reynolds_number, mach_number, lattice): self.resolution = resolution self.units = UnitConversion( lattice, reynolds_number=reynolds_number, mach_number=mach_number, characteristic_length_lu=resolution, characteristic_length_pu=2*np.pi, characteristic_velocity_pu=1 ) def analytic_solution(self, x, t=0): nu = self.units.viscosity_pu u = np.array([np.cos(x[0]) * np.sin(x[1]) * np.exp(-2*nu*t), -np.sin(x[0]) * np.cos(x[1]) * np.exp(-2*nu*t)]) p = -np.array([0.25 * (np.cos(2*x[0]) + np.cos(2*x[1])) * np.exp(-4 * nu * t)]) return p, u def initial_solution(self, x): return self.analytic_solution(x, t=0) @property def grid(self): x = np.linspace(0, 2 * np.pi, num=self.resolution, endpoint=False) y = np.linspace(0, 2 * np.pi, num=self.resolution, endpoint=False) return np.meshgrid(x, y, indexing='ij') @property def boundaries(self): return [] class TaylorGreenVortex3D: def __init__(self, resolution, reynolds_number, mach_number, lattice): self.resolution = resolution self.units = UnitConversion( lattice, reynolds_number=reynolds_number, mach_number=mach_number, characteristic_length_lu=resolution/(2*np.pi), characteristic_length_pu=1, characteristic_velocity_pu=1 ) def initial_solution(self, x): u = np.array([ np.sin(x[0]) * np.cos(x[1]) * np.cos(x[2]), -np.cos(x[0]) * np.sin(x[1]) * np.cos(x[2]), np.zeros_like(np.sin(x[0])) ]) p = np.array([1 / 16. * (np.cos(2 * x[0]) + np.cos(2 * x[1])) * (np.cos(2 * x[2]) + 2)]) return p, u @property def grid(self): x = np.linspace(0, 2 * np.pi, num=self.resolution, endpoint=False) y = np.linspace(0, 2 * np.pi, num=self.resolution, endpoint=False) z = np.linspace(0, 2 * np.pi, num=self.resolution, endpoint=False) return np.meshgrid(x, y, z, indexing='ij') @property def boundaries(self): return []
[STATEMENT] lemma primepow_gt_Suc_0: "primepow n \<Longrightarrow> n > Suc 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. primepow n \<Longrightarrow> Suc 0 < n [PROOF STEP] using one_less_power[of "p::nat" for p] [PROOF STATE] proof (prove) using this: \<lbrakk>1 < ?p3; 0 < ?n\<rbrakk> \<Longrightarrow> 1 < ?p3 ^ ?n goal (1 subgoal): 1. primepow n \<Longrightarrow> Suc 0 < n [PROOF STEP] by (auto simp: primepow_def prime_nat_iff)
theory Chapter3 imports Main begin type_synonym data_object = string type_synonym method_name = string type_synonym thread = nat datatype history_element = Invocation data_object method_name thread | Response data_object method_name thread fun get_task :: "history_element \<Rightarrow> nat" where "get_task (Invocation d m t) = t" | "get_task (Response d m t) = t" fun get_object :: "history_element \<Rightarrow> data_object" where "get_object (Invocation d m t) = d" | "get_object (Response d m t) = d" type_synonym history = "history_element list" fun is_in :: "history \<Rightarrow> history_element \<Rightarrow> bool" where "is_in [] e = False" | "is_in (head#tail) e = (if (head = e) then True else (is_in tail e))" fun history_before :: "history \<Rightarrow> history_element \<Rightarrow> history" where "history_before [] e = []" | "history_before (head#tail) e = (if (head = e) then [] else [head]@(history_before tail e))" fun history_after :: "history \<Rightarrow> history_element \<Rightarrow> history" where "history_after [] e = []" | "history_after (head#tail) e = (if (head = e) then tail else (history_after tail e))" fun precedes :: "history \<Rightarrow> history_element \<Rightarrow> history_element \<Rightarrow> bool" where "precedes [] _ _ = False" | "precedes (head#tail) e1 e2 = (if (head = e1) then True else (if (head = e2) then False else (precedes tail e1 e2)))" value "[(Invocation ''a'' ''m'' 1)]" fun matches :: "history_element \<Rightarrow> history_element \<Rightarrow> bool" where "matches (Invocation d1 m1 t1) (Response d2 m2 t2) = ((d1 = d2) \<and> (m1 = m2) \<and> (t1 = t2))" | "matches _ _ = False" fun is_invocation :: "history_element \<Rightarrow> bool" where "is_invocation (Invocation _ _ _) = True" | "is_invocation _ = False" fun has_response :: "history_element \<Rightarrow> history \<Rightarrow> bool" where "has_response _ [] = False" | "has_response e (head#tail) = (if (matches e head) then True else (has_response e tail))" fun get_response :: "history_element \<Rightarrow> history \<Rightarrow> history_element option" where "get_response _ [] = None" | "get_response e (head#tail) = (if (matches e head) then (Some e) else (get_response e tail))" fun is_sequential :: "history \<Rightarrow> bool" where "is_sequential [] = True" | "is_sequential [(Invocation _ _ _)] = True" | "is_sequential [(Response _ _ _)] = False" | "is_sequential (h1#tail1) = (case tail1 of h2#[] \<Rightarrow> (matches h1 h2) | (h2#tail2) \<Rightarrow> if (matches h1 h2) then (is_sequential tail2) else False)" value "(is_sequential [ (history_element.Invocation ''a'' ''m1'' 2), (history_element.Response ''a'' ''m1'' 2) ])" value "(is_sequential [ (history_element.Invocation ''a'' ''m1'' 2), (history_element.Response ''a'' ''m1'' 2), (history_element.Invocation ''a'' ''m1'' 2), (history_element.Response ''b'' ''m1'' 2) ])" value "(is_sequential [ (history_element.Invocation ''a'' ''m1'' 1), (history_element.Response ''a'' ''m1'' 1), (history_element.Invocation ''a'' ''m2'' 3), (history_element.Response ''a'' ''m2'' 3) ])" fun thread_subhistory :: "history \<Rightarrow> thread \<Rightarrow> history" where "thread_subhistory (h1#tail) t = (if ((get_task h1) = t) then h1#(thread_subhistory tail t) else (thread_subhistory tail t))" | "thread_subhistory [] t = []" value "(thread_subhistory [ (history_element.Invocation ''a'' ''m1'' 1), (history_element.Response ''a'' ''m1'' 1), (history_element.Invocation ''a'' ''m2'' 3), (history_element.Response ''a'' ''m2'' 3) ] 3 )" definition at_most_once_found :: "history \<Rightarrow> history_element \<Rightarrow> bool" where "at_most_once_found h e = ((is_in h e) \<longrightarrow> \<not>(is_in (history_after h e) e))" definition is_well_formed :: "history \<Rightarrow> bool" where "is_well_formed h = ((\<forall>i.(is_sequential (thread_subhistory h i))) \<and> (\<forall>e.(at_most_once_found h e)))" definition are_equivalent :: "history \<Rightarrow> history \<Rightarrow> bool" where "are_equivalent h1 h2 = (\<forall>i.(thread_subhistory h1 i) = (thread_subhistory h2 i))" (* Lemmas for sanity check *) lemma "(is_well_formed [])" apply(simp add:is_well_formed_def add:at_most_once_found_def) done lemma "h1 = h2 \<longrightarrow> (are_equivalent h1 h2)" apply(simp add:are_equivalent_def add:at_most_once_found_def) done fun only_responses :: "history \<Rightarrow> bool" where "only_responses [] = True" | "only_responses ((Response _ _ _)#tail) = (only_responses tail)" | "only_responses _ = False" (* common prefix, then only responses, and a legal history: *) definition is_extension :: "history \<Rightarrow> history \<Rightarrow> bool" where "is_extension h1 h2 = ((is_well_formed h1) \<and> (is_well_formed h2) \<and> (\<exists>suffix.((h2 = h1@suffix) \<and> only_responses(suffix))))" lemma "is_extension [(Invocation d m t)] [(Invocation d m t), (Response d m t)]" apply(simp add:is_extension_def) apply(simp add:is_well_formed_def) apply(auto) apply(simp add:at_most_once_found_def) apply(simp add:at_most_once_found_def) apply(auto) done fun complete :: "history \<Rightarrow> history" where "complete [] = []" | "complete ((Response d m t)#tail) = (Response d m t)#(complete tail)" | "complete ((Invocation d m t)#tail) = (if (has_response (Invocation d m t) tail) then (Invocation d m t)#(complete tail) else (complete tail))" value "(complete [(Invocation ''a'' ''b'' 1), (Invocation ''a'' ''b'' 2), (Response ''a'' ''b'' 1)])" fun method_call_precedes :: "history \<Rightarrow> history_element \<Rightarrow> history_element \<Rightarrow> bool" where "method_call_precedes h (Invocation d1 m1 t1) (Invocation d2 m2 t2) = (if (\<not>((is_in h (Invocation d1 m1 t1) \<and> (is_in h (Response d1 m1 t1)) \<and> (is_in h (Invocation d2 m2 t2))))) then False else (precedes h (Response d1 m1 t1) (Invocation d2 m2 t2)))" | "method_call_precedes h _ _ = False" lemma "(\<not>(is_in h (Invocation d1 m1 t1)) \<and> (is_well_formed h)) \<longrightarrow> \<not>(method_call_precedes h (Invocation d1 m1 t1) (Invocation d2 m2 t2))" apply(auto) done lemma "(\<not>(is_in h (Invocation d1 m1 t1)) \<and> (is_well_formed h)) \<longrightarrow> \<not>(method_call_precedes h (Invocation d1 m1 t1) (Invocation d2 m2 t2))" apply(auto) done definition is_linearizable :: "history \<Rightarrow> bool" where "is_linearizable H = (\<exists>extension.((is_extension extension H) \<and> (is_well_formed extension) \<and> (\<exists>S.((is_sequential S) \<and> (is_well_formed S) \<and> (are_equivalent (complete extension) S)) (* L1 *) \<and> (\<forall>m0.(\<forall>m1.(method_call_precedes H m0 m1) \<longrightarrow> (method_call_precedes S m0 m1))) (*L2*) )))" fun object_subhistory :: "history \<Rightarrow> data_object \<Rightarrow> history" where "object_subhistory (h1#tail) object = (if ((get_object h1) = object) then h1#(object_subhistory tail object) else (object_subhistory tail object))" | "object_subhistory [] t = []" lemma "linearizability_is_compositional" : "(is_well_formed H) \<longrightarrow> ((\<forall>object.(is_linearizable (object_subhistory H object))) \<longrightarrow> (is_linearizable H))" apply(auto) apply(simp add:is_linearizable_def add:is_well_formed_def add:is_extension_def add:is_sequential_def add:at_most_once_found_def) apply(auto) apply(rule exI) apply(auto) apply(rule exI) apply(rule mp) apply(auto) apply(rule allE) apply(auto) (* tbc *)
Formal statement is: lemma (in Dynkin_system) diff: assumes sets: "D \<in> M" "E \<in> M" and "D \<subseteq> E" shows "E - D \<in> M" Informal statement is: If $D$ and $E$ are measurable sets and $D \subseteq E$, then $E - D$ is measurable.
State Before: α : Type u_2 β : Type u_1 γ : Type ?u.73172 q : Pmf (α → β) p : Pmf α b : β ⊢ b ∈ support (seq q p) ↔ ∃ f, f ∈ support q ∧ b ∈ f '' support p State After: no goals Tactic: simp
# <ins>Lab #1: Python Basics</ins> These exercises are meant to give you some practice with the concepts from Tutorials 1.1 & 1.2. There's a prompt or two for each section, as well as a final question that brings it all together. Show your work! GLHF! *** ## Basic Arithmetic 1. Use the Pythagorean theorem, $a^2 + b^2 = c^2$, to find the hypotenuse length of a right triangle with side lengths $a = 6.1$ and $b = 5.6$. ```python # Your answer below: a, b = 6.1, 5.6 c = (a**2 + b**2)**(1/2.0) print(c) ``` 8.280700453464066 2. Use the distance modulus, $m_v - M_v = 5log(d/10 \text{ pc})$, to find the distance to a star with apparent magnitude $m_v = 0.5$ and absolute magnitude $M_v = -5.85$. ```python # Your answer below: m, M = 0.5, -5.85 d = 10**((m-M)/5)*10 print(d, 'pc') ``` 186.20871366628677 pc *** ## Comments 1. Write a single-line comment containing your Swings order. ```python # Your answer below: # Whatever the best-looking special is ``` 2. Write a multi-line comment describing your favorite astronomy fact. ```python # Your answer below: ''' Tycho Brahe died of a ruptured bladder because he was too polite to get up to use the bathroom at a dinner party. He also got into swordfights all the time, one of which cost him part of his nose. ''' ``` *** ## Printing 1. Print your favorite letter, number and symbol on the same line. ```python # Your answer here: print('W', 5318008, '~') ``` W 5318008 ~ *** ## Data types 1. Use both string multiplication and concatenation to print 3 different animal noises. ```python # Your answer here: print('m' + 'o'*5) print('b' + 'a'*5 + 'h') print('n' + 'e'*5 + 'igh') ``` mooooo baaaaah neeeeeigh 2. Print a true statement using four different comparison operators. ```python # Your answer here: print(((1 > 4) or (1 < 4)) and ((1 == 2) or (1 != 2))) ``` True *** ## Variables 1. Use the quadratic equation, $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$, to find the roots of $5x^2 + 3x - 1$ by calculating the numerator and denominator separately. (**Tip:** When parintheses in a big equation get a little hard to read, breaking it up like this is a good way to make code easier to read.) ```python # Your answer here: import math a,b,c = 5,3,-1 num_plus = -b + math.sqrt(b**2 - 4 * a * c) num_minus = -b - math.sqrt(b**2 - 4 * a * c) denom = 2*a root_plus = num_plus/denom root_minus = num_minus/denom print(root_plus, root_minus) ``` 0.23851648071345039 -0.8385164807134504 *** ## User input 1. Prompt the user for their age and calculate the percent of their life they've completed assuming they live to 80 years old. ```python # Your answer here: age = input('How old are you in years? ') print((int(age)/80.0)*100.0, '%') ``` How old are you in years? 21 26.25 % *** ## Debugging 1. Rewrite the code below, fixing the errors and formatting with best practices. ```python X1 = 1 Y1 = 2 X2 = 2 Y2 = 6 Dist = sqrt((X2-X1)^2-(Y2+Y1)^2)) print(Dist) ``` ```python # Your answer below: import math x1, y1, x2, y2 = 1, 2, 2, 6 dist = math.sqrt((x2-x1)**2 + (y2-y1)**2) print(dist) ``` 4.123105625617661 *** ## Indexing 1. Print the 4th, 9th, and 15th letter and the letter at the 20th, 3rd, and 12th indices of the word "pneumonoultramicroscopicsilicovolcanoconiosis" by indexing. ```python # Your answer below: string = "pneumonoultramicroscopicsilicovolcanoconiosis" fourth,ninth,fifteenth = string[3], string[9], string[15] index_20, index_3, index_12 = string[20], string[3], string[12] print("Fourth letter:", fourth) print("Ninth letter:", ninth) print("Fifteenth letter:", fifteenth) print("Third index:", index_3) print("Twelfth index:", index_12) print("Twentieth index:", index_20) ``` Fourth letter: u Ninth letter: l Fifteenth letter: c Third index: u Twelfth index: a Twentieth index: o 2. Print the strings "pneumono," "ultra," "volcano," and "coniosis" by slicing the word from part one. ```python # Your answer below: string = "pneumonoultramicroscopicsilicovolcanoconiosis" pneumono = string[:8] ultra = string[8:13] microscopic = string[13:24] volcanoconiosis = string[-15:] print(pneumono, ultra, microscopic, volcanoconiosis) ``` pneumono ultra microscopic volcanoconiosis 3. Add together every third number in the list [155,2,54,34,5,16,7,38,26,10] and print the result. ```python # Your answer below lst = [155,2,54,34,5,6,7,38,9,10] print(lst[2]+lst[5]+lst[8]) ``` 69 *** ## Manipulating strings and lists 1. Fix the string "peea7nut. bt-tt9r" with string (or list) functions. ```python # Your code below: string = "peea7nut. bt-tt9r" string = string.replace('ea','a') string = string.replace('7','') string = string.replace('.','') string = string.replace('t-','u') string = string.replace('9','e') print(string) # Alternatively... string = "peea7nut. bt-tt9r" string = list(string) string.remove('e') string.remove('7') string.remove('.') string.remove('-') string[8] = 'u' string[-2] = 'e' string = ''.join(string) print(string) ``` peanut butter peanut butter *** ## `numpy` arrays 1. Use the Wien displacement law to calculate the temperatures of blackbodies with 20 peak wavelengths between 300nm and 700nm using arrays. \begin{equation} \lambda_{peak}T = 0.29 \text{ cm K} \end{equation} ```python # Your code below: import numpy as np lambdas = np.linspace(300,700,20) lambdas_cm = lambdas*1E-7 temps = 0.29 / lambdas_cm print(temps) ``` [9666.66666667 9032.78688525 8476.92307692 7985.50724638 7547.94520548 7155.84415584 6802.4691358 6482.35294118 6191.01123596 5924.7311828 5680.41237113 5455.44554455 5247.61904762 5055.04587156 4876.10619469 4709.4017094 4553.71900826 4408. 4271.31782946 4142.85714286] ## Challenge I: DMS/HMS Converter While DMS (degrees, minutes, seconds) and HMS (hours, minutes, seconds) formats for celestial coordinates have their place (e.g. in every database ever), having them in decimal degrees is often more convenient for calculations. Write two scripts: one that allows the user to enter in a DMS coordinate and prints it in decimal degrees, and another for HMS coordinates. ```python # Your code below: # DMS dms = input("Enter D:M:S coordinates, separated by colons: ") dms = dms.split(":") degs, mins, secs = dms decdeg = float(degs) + float(mins)/60.0 + float(secs)/3600.0 print("Decimal degrees:", decdeg) ``` Enter D:M:S coordinates, separated by colons: 54:54:54 Decimal degrees: 54.915 ```python # HMS hms = input("Enter H:M:S coordinates, separated by colons: ") hms = hms.split(":") hrs, mins, secs = hms decdeg = (float(hrs) + float(mins)/60.0 + float(secs)/3600.0) * 15 print("Decimal degrees:", decdeg) ``` Enter H:M:S coordinates, separated by colons: 12:00:00 Decimal degrees: 180.0
# Solvers ```python from sympy import * from sympy.solvers.solveset import solveset init_printing() ``` For each exercise, fill in the function according to its docstring. ```python a, b, c, d, x, y, z, t = symbols('a b c d x y z t') f, g, h = symbols('f g h', cls=Function) ``` ## Algebraic Equations Write a function that computes the [quadratic equation](http://en.wikipedia.org/wiki/Quadratic_equation). ```python def quadratic(): return solveset(a*x**2 + b*x + c, x) quadratic() ``` Write a function that computes the general solution to the cubic $x^3 + ax^2 + bx + c$. ```python def cubic(): return solveset(x**3 + a*x**2 + b*x + c, x) cubic() ``` ## Differential Equations A population that grows without bound is modeled by the differential equation $$f'(t)=af(t)$$ Solve this differential equation using SymPy. ```python dsolve(f(t).diff(t) - a*f(t), f(t)) ``` If the population growth is bounded, it is modeled by $$f'(t) = f(t)(1 - f(t))$$ Solve this differential equation using SymPy. ```python dsolve(f(t).diff(t) - f(t)*(1 - f(t)), f(t)) ```
%!TEX root = ../main.tex \chapter{Acknowledgements} \lipsum[22]
Formal statement is: lemma tendsto_of_real_iff: "((\<lambda>x. of_real (f x) :: 'a::real_normed_div_algebra) \<longlongrightarrow> of_real c) F \<longleftrightarrow> (f \<longlongrightarrow> c) F" Informal statement is: The sequence of real numbers $f_n$ converges to $c$ if and only if the sequence of complex numbers $f_n$ converges to $c$.
section \<open>Records \label{sec:records}\<close> (*<*) theory Records imports Main begin (*>*) text \<open> \index{records|(}% Records are familiar from programming languages. A record of $n$ fields is essentially an $n$-tuple, but the record's components have names, which can make expressions easier to read and reduces the risk of confusing one field for another. A record of Isabelle/HOL covers a collection of fields, with select and update operations. Each field has a specified type, which may be polymorphic. The field names are part of the record type, and the order of the fields is significant --- as it is in Pascal but not in Standard ML. If two different record types have field names in common, then the ambiguity is resolved in the usual way, by qualified names. Record types can also be defined by extending other record types. Extensible records make use of the reserved pseudo-field \cdx{more}, which is present in every record type. Generic record operations work on all possible extensions of a given type scheme; polymorphism takes care of structural sub-typing behind the scenes. There are also explicit coercion functions between fixed record types. \<close> subsection \<open>Record Basics\<close> text \<open> Record types are not primitive in Isabelle and have a delicate internal representation \<^cite>\<open>"NaraschewskiW-TPHOLs98"\<close>, based on nested copies of the primitive product type. A \commdx{record} declaration introduces a new record type scheme by specifying its fields, which are packaged internally to hold up the perception of the record as a distinguished entity. Here is a simple example: \<close> record point = Xcoord :: int Ycoord :: int text \<open>\noindent Records of type \<^typ>\<open>point\<close> have two fields named \<^const>\<open>Xcoord\<close> and \<^const>\<open>Ycoord\<close>, both of type~\<^typ>\<open>int\<close>. We now define a constant of type \<^typ>\<open>point\<close>: \<close> definition pt1 :: point where "pt1 \<equiv> (| Xcoord = 999, Ycoord = 23 |)" text \<open>\noindent We see above the ASCII notation for record brackets. You can also use the symbolic brackets \<open>\<lparr>\<close> and \<open>\<rparr>\<close>. Record type expressions can be also written directly with individual fields. The type name above is merely an abbreviation. \<close> definition pt2 :: "\<lparr>Xcoord :: int, Ycoord :: int\<rparr>" where "pt2 \<equiv> \<lparr>Xcoord = -45, Ycoord = 97\<rparr>" text \<open> For each field, there is a \emph{selector}\index{selector!record} function of the same name. For example, if \<open>p\<close> has type \<^typ>\<open>point\<close> then \<open>Xcoord p\<close> denotes the value of the \<open>Xcoord\<close> field of~\<open>p\<close>. Expressions involving field selection of explicit records are simplified automatically: \<close> lemma "Xcoord \<lparr>Xcoord = a, Ycoord = b\<rparr> = a" by simp text \<open> The \emph{update}\index{update!record} operation is functional. For example, \<^term>\<open>p\<lparr>Xcoord := 0\<rparr>\<close> is a record whose \<^const>\<open>Xcoord\<close> value is zero and whose \<^const>\<open>Ycoord\<close> value is copied from~\<open>p\<close>. Updates of explicit records are also simplified automatically: \<close> lemma "\<lparr>Xcoord = a, Ycoord = b\<rparr>\<lparr>Xcoord := 0\<rparr> = \<lparr>Xcoord = 0, Ycoord = b\<rparr>" by simp text \<open> \begin{warn} Field names are declared as constants and can no longer be used as variables. It would be unwise, for example, to call the fields of type \<^typ>\<open>point\<close> simply \<open>x\<close> and~\<open>y\<close>. \end{warn} \<close> subsection \<open>Extensible Records and Generic Operations\<close> text \<open> \index{records!extensible|(}% Now, let us define coloured points (type \<open>cpoint\<close>) to be points extended with a field \<open>col\<close> of type \<open>colour\<close>: \<close> datatype colour = Red | Green | Blue record cpoint = point + col :: colour text \<open>\noindent The fields of this new type are \<^const>\<open>Xcoord\<close>, \<open>Ycoord\<close> and \<open>col\<close>, in that order. \<close> definition cpt1 :: cpoint where "cpt1 \<equiv> \<lparr>Xcoord = 999, Ycoord = 23, col = Green\<rparr>" text \<open> We can define generic operations that work on arbitrary instances of a record scheme, e.g.\ covering \<^typ>\<open>point\<close>, \<^typ>\<open>cpoint\<close>, and any further extensions. Every record structure has an implicit pseudo-field, \cdx{more}, that keeps the extension as an explicit value. Its type is declared as completely polymorphic:~\<^typ>\<open>'a\<close>. When a fixed record value is expressed using just its standard fields, the value of \<open>more\<close> is implicitly set to \<open>()\<close>, the empty tuple, which has type \<^typ>\<open>unit\<close>. Within the record brackets, you can refer to the \<open>more\<close> field by writing ``\<open>\<dots>\<close>'' (three dots): \<close> lemma "Xcoord \<lparr>Xcoord = a, Ycoord = b, \<dots> = p\<rparr> = a" by simp text \<open> This lemma applies to any record whose first two fields are \<open>Xcoord\<close> and~\<^const>\<open>Ycoord\<close>. Note that \<open>\<lparr>Xcoord = a, Ycoord = b, \<dots> = ()\<rparr>\<close> is exactly the same as \<open>\<lparr>Xcoord = a, Ycoord = b\<rparr>\<close>. Selectors and updates are always polymorphic wrt.\ the \<open>more\<close> part of a record scheme, its value is just ignored (for select) or copied (for update). The \<open>more\<close> pseudo-field may be manipulated directly as well, but the identifier needs to be qualified: \<close> lemma "point.more cpt1 = \<lparr>col = Green\<rparr>" by (simp add: cpt1_def) text \<open>\noindent We see that the colour part attached to this \<^typ>\<open>point\<close> is a rudimentary record in its own right, namely \<open>\<lparr>col = Green\<rparr>\<close>. In order to select or update \<open>col\<close>, this fragment needs to be put back into the context of the parent type scheme, say as \<open>more\<close> part of another \<^typ>\<open>point\<close>. To define generic operations, we need to know a bit more about records. Our definition of \<^typ>\<open>point\<close> above has generated two type abbreviations: \medskip \begin{tabular}{l} \<^typ>\<open>point\<close>~\<open>=\<close>~\<open>\<lparr>Xcoord :: int, Ycoord :: int\<rparr>\<close> \\ \<^typ>\<open>'a point_scheme\<close>~\<open>=\<close>~\<open>\<lparr>Xcoord :: int, Ycoord :: int, \<dots> :: 'a\<rparr>\<close> \\ \end{tabular} \medskip \noindent Type \<^typ>\<open>point\<close> is for fixed records having exactly the two fields \<^const>\<open>Xcoord\<close> and~\<open>Ycoord\<close>, while the polymorphic type \<^typ>\<open>'a point_scheme\<close> comprises all possible extensions to those two fields. Note that \<^typ>\<open>unit point_scheme\<close> coincides with \<^typ>\<open>point\<close>, and \<^typ>\<open>\<lparr>col :: colour\<rparr> point_scheme\<close> with \<^typ>\<open>cpoint\<close>. In the following example we define two operations --- methods, if we regard records as objects --- to get and set any point's \<open>Xcoord\<close> field. \<close> definition getX :: "'a point_scheme \<Rightarrow> int" where "getX r \<equiv> Xcoord r" definition setX :: "'a point_scheme \<Rightarrow> int \<Rightarrow> 'a point_scheme" where "setX r a \<equiv> r\<lparr>Xcoord := a\<rparr>" text \<open> Here is a generic method that modifies a point, incrementing its \<^const>\<open>Xcoord\<close> field. The \<open>Ycoord\<close> and \<open>more\<close> fields are copied across. It works for any record type scheme derived from \<^typ>\<open>point\<close> (including \<^typ>\<open>cpoint\<close> etc.): \<close> definition incX :: "'a point_scheme \<Rightarrow> 'a point_scheme" where "incX r \<equiv> \<lparr>Xcoord = Xcoord r + 1, Ycoord = Ycoord r, \<dots> = point.more r\<rparr>" text \<open> Generic theorems can be proved about generic methods. This trivial lemma relates \<^const>\<open>incX\<close> to \<open>getX\<close> and \<open>setX\<close>: \<close> lemma "incX r = setX r (getX r + 1)" by (simp add: getX_def setX_def incX_def) text \<open> \begin{warn} If you use the symbolic record brackets \<open>\<lparr>\<close> and \<open>\<rparr>\<close>, then you must also use the symbolic ellipsis, ``\<open>\<dots>\<close>'', rather than three consecutive periods, ``\<open>...\<close>''. Mixing the ASCII and symbolic versions causes a syntax error. (The two versions are more distinct on screen than they are on paper.) \end{warn}% \index{records!extensible|)} \<close> subsection \<open>Record Equality\<close> text \<open> Two records are equal\index{equality!of records} if all pairs of corresponding fields are equal. Concrete record equalities are simplified automatically: \<close> lemma "(\<lparr>Xcoord = a, Ycoord = b\<rparr> = \<lparr>Xcoord = a', Ycoord = b'\<rparr>) = (a = a' \<and> b = b')" by simp text \<open> The following equality is similar, but generic, in that \<open>r\<close> can be any instance of \<^typ>\<open>'a point_scheme\<close>: \<close> lemma "r\<lparr>Xcoord := a, Ycoord := b\<rparr> = r\<lparr>Ycoord := b, Xcoord := a\<rparr>" by simp text \<open>\noindent We see above the syntax for iterated updates. We could equivalently have written the left-hand side as \<open>r\<lparr>Xcoord := a\<rparr>\<lparr>Ycoord := b\<rparr>\<close>. Record equality is \emph{extensional}: \index{extensionality!for records} a record is determined entirely by the values of its fields. \<close> lemma "r = \<lparr>Xcoord = Xcoord r, Ycoord = Ycoord r\<rparr>" by simp text \<open>\noindent The generic version of this equality includes the pseudo-field \<open>more\<close>: \<close> lemma "r = \<lparr>Xcoord = Xcoord r, Ycoord = Ycoord r, \<dots> = point.more r\<rparr>" by simp text \<open> The simplifier can prove many record equalities automatically, but general equality reasoning can be tricky. Consider proving this obvious fact: \<close> lemma "r\<lparr>Xcoord := a\<rparr> = r\<lparr>Xcoord := a'\<rparr> \<Longrightarrow> a = a'" apply simp? oops text \<open>\noindent Here the simplifier can do nothing, since general record equality is not eliminated automatically. One way to proceed is by an explicit forward step that applies the selector \<^const>\<open>Xcoord\<close> to both sides of the assumed record equality: \<close> lemma "r\<lparr>Xcoord := a\<rparr> = r\<lparr>Xcoord := a'\<rparr> \<Longrightarrow> a = a'" apply (drule_tac f = Xcoord in arg_cong) txt \<open>@{subgoals [display, indent = 0, margin = 65]} Now, \<open>simp\<close> will reduce the assumption to the desired conclusion.\<close> apply simp done text \<open> The \<open>cases\<close> method is preferable to such a forward proof. We state the desired lemma again: \<close> lemma "r\<lparr>Xcoord := a\<rparr> = r\<lparr>Xcoord := a'\<rparr> \<Longrightarrow> a = a'" txt \<open>The \methdx{cases} method adds an equality to replace the named record term by an explicit record expression, listing all fields. It even includes the pseudo-field \<open>more\<close>, since the record equality stated here is generic for all extensions.\<close> apply (cases r) txt \<open>@{subgoals [display, indent = 0, margin = 65]} Again, \<open>simp\<close> finishes the proof. Because \<open>r\<close> is now represented as an explicit record construction, the updates can be applied and the record equality can be replaced by equality of the corresponding fields (due to injectivity).\<close> apply simp done text \<open> The generic cases method does not admit references to locally bound parameters of a goal. In longer proof scripts one might have to fall back on the primitive \<open>rule_tac\<close> used together with the internal field representation rules of records. The above use of \<open>(cases r)\<close> would become \<open>(rule_tac r = r in point.cases_scheme)\<close>. \<close> subsection \<open>Extending and Truncating Records\<close> text \<open> Each record declaration introduces a number of derived operations to refer collectively to a record's fields and to convert between fixed record types. They can, for instance, convert between types \<^typ>\<open>point\<close> and \<^typ>\<open>cpoint\<close>. We can add a colour to a point or convert a \<^typ>\<open>cpoint\<close> to a \<^typ>\<open>point\<close> by forgetting its colour. \begin{itemize} \item Function \cdx{make} takes as arguments all of the record's fields (including those inherited from ancestors). It returns the corresponding record. \item Function \cdx{fields} takes the record's very own fields and returns a record fragment consisting of just those fields. This may be filled into the \<open>more\<close> part of the parent record scheme. \item Function \cdx{extend} takes two arguments: a record to be extended and a record containing the new fields. \item Function \cdx{truncate} takes a record (possibly an extension of the original record type) and returns a fixed record, removing any additional fields. \end{itemize} These functions provide useful abbreviations for standard record expressions involving constructors and selectors. The definitions, which are \emph{not} unfolded by default, are made available by the collective name of \<open>defs\<close> (\<open>point.defs\<close>, \<open>cpoint.defs\<close>, etc.). For example, here are the versions of those functions generated for record \<^typ>\<open>point\<close>. We omit \<open>point.fields\<close>, which happens to be the same as \<open>point.make\<close>. @{thm [display, indent = 0, margin = 65] point.make_def [no_vars] point.extend_def [no_vars] point.truncate_def [no_vars]} Contrast those with the corresponding functions for record \<^typ>\<open>cpoint\<close>. Observe \<open>cpoint.fields\<close> in particular. @{thm [display, indent = 0, margin = 65] cpoint.make_def [no_vars] cpoint.fields_def [no_vars] cpoint.extend_def [no_vars] cpoint.truncate_def [no_vars]} To demonstrate these functions, we declare a new coloured point by extending an ordinary point. Function \<open>point.extend\<close> augments \<open>pt1\<close> with a colour value, which is converted into an appropriate record fragment by \<open>cpoint.fields\<close>. \<close> definition cpt2 :: cpoint where "cpt2 \<equiv> point.extend pt1 (cpoint.fields Green)" text \<open> The coloured points \<^const>\<open>cpt1\<close> and \<open>cpt2\<close> are equal. The proof is trivial, by unfolding all the definitions. We deliberately omit the definition of~\<open>pt1\<close> in order to reveal the underlying comparison on type \<^typ>\<open>point\<close>. \<close> lemma "cpt1 = cpt2" apply (simp add: cpt1_def cpt2_def point.defs cpoint.defs) txt \<open>@{subgoals [display, indent = 0, margin = 65]}\<close> apply (simp add: pt1_def) done text \<open> In the example below, a coloured point is truncated to leave a point. We use the \<open>truncate\<close> function of the target record. \<close> lemma "point.truncate cpt2 = pt1" by (simp add: pt1_def cpt2_def point.defs) text \<open> \begin{exercise} Extend record \<^typ>\<open>cpoint\<close> to have a further field, \<open>intensity\<close>, of type~\<^typ>\<open>nat\<close>. Experiment with generic operations (using polymorphic selectors and updates) and explicit coercions (using \<open>extend\<close>, \<open>truncate\<close> etc.) among the three record types. \end{exercise} \begin{exercise} (For Java programmers.) Model a small class hierarchy using records. \end{exercise} \index{records|)} \<close> (*<*) end (*>*)
Paid search campaigns can be highly effective - and highly time-consuming, and highly complex. We have the expertise and the experience to monitor your campaign and make the ongoing strategic adjustments it needs to remain competitive and lucrative. Every PPC campaign starts with a carefully developed keyword list. These keywords are the building blocks of your strategy, helping determine the use of your budget and the value of your leads. We conduct thorough research into your business, your industry and your competition, analyzing the keywords that users choose most. By creating and choosing a cost-effective cross-section of keywords, we're able to place your ads in front of the highest number of relevant leads for your budget. After studying your competitors and your target audience, our paid search experts develop and implement a strategy for reaching out to the users most likely to engage with your ads. Using this strategy, we develop strategic ad copy and launch your PPC campaign on the web's top search engines, giving you immediate placement that can start generating clicks and ROI right away. We start tracking and refining your paid search strategy on day one, carefully monitoring your clicks, budget and overall user engagement. By regularly tracking and optimizing your campaign, we're able to better focus on relevant, qualified users. Our ongoing management and testing ensures that your campaign continues to function efficiently and generate the best ROI for your budget. We prepare regular reports on the success of your campaign, demonstrating the value of your budget in measureable data. Our PPC team's reports include the analytics that inform your campaign's ongoing strategy and reflect your ROI. This data illustrates the value of your paid search advertising and shows which strategies generate the best returns. better search engine performance. 100% natural. Search engine optimization isn't about tricks and shortcuts. We do SEO right, so you can get better rankings and be seen by more people the natural way. By analyzing your industry, your competitors and the ever-changing algorithms of the web's top search engines, our SEO experts develop a list of keywords that consumers use when searching for businesses like yours. We track your keyword performance over time, so you can watch your website attract more valuable traffic. External links leading back to your website help you earn new traffic and increase your value with search engines, but you have to focus on quality, not quantity. Bulk link acquisition strategies don't work - in fact, they can get you penalized by search engines. We build high quality links that reflect your site's authority and outlast search engine algorithm changes, giving you the type of exposure that makes a real difference. Directly engaging your audience on social media turns brand awareness into brand preference, sending valuable signals to search engines and defining your image on some of the web's most visited sites. Your keywords form the foundation of your entire SEO strategy, so we choose the ones that will yield the biggest returns. By selecting keywords analytically, we're able to start building a better campaign from day one.
% ********************************************************************** % Author: Ajahn Chah % Translator: % Title: Learning to Listen % First published: % Comment: Given in September 2521 (1978) at Wat Nong Pah Pong % Copyright: Permission granted by Wat Pah Nanachat to reprint for free distribution % ********************************************************************** \chapter{Learning to Listen} \index[general]{Dhamma!listening to} \vspace*{0.5\baselineskip} \dropcaps{D}{uring an informal gathering} at his residence one evening, the Ajahn said, `When you listen to the Dhamma, you must open up your heart and compose yourself in its centre. Don't try and accumulate what you hear, or make painstaking efforts to retain it through your memory. Just let the Dhamma flow into your heart as it reveals itself, and keep yourself continuously open to the flow in the present moment. What is ready to be retained will remain. It will happen of its own accord, not through forced effort on your part. \index[general]{Dhamma talks!giving} Similarly, when you expound the Dhamma, there must be no force involved. The Dhamma must flow spontaneously from the present moment according to circumstances. You know, it's strange, but sometimes people come to me and really show no apparent desire to hear the Dhamma, but there it is -- it just happens. The Dhamma comes flowing out with no effort whatsoever. Then at other times, people seem to be quite keen to listen. They even formally ask for a discourse, and then, nothing! It just won't happen. What can you do? I don't know why it is, but I know that things happen in this way. It's as though people have different levels of receptivity, and when you are there at the same level, things just happen. If you must expound the Dhamma, the best way is not to think about it at all. Simply forget it. The more you think and try to plan, the worse it will be. This is hard to do, though, isn't it? Sometimes, when you're flowing along quite smoothly, there will be a pause, and someone may ask a question. Then, suddenly, there's a whole new direction. There seems to be an unlimited source that you can never exhaust. \index[general]{teaching!skilful ways of} I believe without a doubt in the Buddha's ability to know the temperaments and receptivity of other beings. He used this very same method of spontaneous teaching. It's not that he needed to use any superhuman power, but rather that he was sensitive to the needs of the people around him and so taught to them accordingly. An instance demonstrating his own spontaneity occurred when once, after he had expounded the Dhamma to a group of his disciples, he asked them if they had ever heard this teaching before. They replied that they had not. He then went on to say that he himself had also never heard it before. Just continue your practice no matter what you are doing. Practice is not dependent on any one posture, such as sitting or walking. Rather, it is a continuous awareness of the flow of your own consciousness and feelings. No matter what is happening, just compose yourself and always be mindfully aware of that flow. \index[general]{moving forward, backward, standing still} \index[similes]{moving forward, backward, standing still!right practice} Later, the Ajahn went on to say, `Practice is not moving forward, but there is forward movement. At the same time, it is not moving back, but there is backward movement. And, finally, practice is not stopping and being still, but there is stopping and being still. So there is moving forward and backward as well as being still, but you can't say that it is any one of the three. Then practice eventually comes to a point where there is neither forward nor backward movement, nor any being still. Where is that?' On another informal occasion, he said, `To define Buddhism without a lot of words and phrases, we can simply say, ``Don't cling or hold on to anything. Harmonize with actuality, with things just as they are.''\thinspace'
Formal statement is: lemma closure_mono: "S \<subseteq> T \<Longrightarrow> closure S \<subseteq> closure T" Informal statement is: If $S \subseteq T$, then $\overline{S} \subseteq \overline{T}$.
proposition homotopic_loops_trans: "\<lbrakk>homotopic_loops s p q; homotopic_loops s q r\<rbrakk> \<Longrightarrow> homotopic_loops s p r"
[STATEMENT] lemma smc_Set_Comp_app[smc_Set_cs_simps]: assumes "S : b \<mapsto>\<^bsub>smc_Set \<alpha>\<^esub> c" and "T : a \<mapsto>\<^bsub>smc_Set \<alpha>\<^esub> b" shows "S \<circ>\<^sub>A\<^bsub>smc_Set \<alpha>\<^esub> T = S \<circ>\<^sub>S\<^sub>e\<^sub>t T" [PROOF STATE] proof (prove) goal (1 subgoal): 1. S \<circ>\<^sub>A\<^bsub>smc_Set \<alpha>\<^esub> T = S \<circ>\<^sub>R\<^sub>e\<^sub>l T [PROOF STEP] proof- [PROOF STATE] proof (state) goal (1 subgoal): 1. S \<circ>\<^sub>A\<^bsub>smc_Set \<alpha>\<^esub> T = S \<circ>\<^sub>R\<^sub>e\<^sub>l T [PROOF STEP] from assms [PROOF STATE] proof (chain) picking this: S : b \<mapsto>\<^bsub>smc_Set \<alpha>\<^esub> c T : a \<mapsto>\<^bsub>smc_Set \<alpha>\<^esub> b [PROOF STEP] have "[S, T]\<^sub>\<circ> \<in>\<^sub>\<circ> composable_arrs (smc_Set \<alpha>)" [PROOF STATE] proof (prove) using this: S : b \<mapsto>\<^bsub>smc_Set \<alpha>\<^esub> c T : a \<mapsto>\<^bsub>smc_Set \<alpha>\<^esub> b goal (1 subgoal): 1. [S, T]\<^sub>\<circ> \<in>\<^sub>\<circ> composable_arrs (smc_Set \<alpha>) [PROOF STEP] by (auto simp: smc_cs_intros) [PROOF STATE] proof (state) this: [S, T]\<^sub>\<circ> \<in>\<^sub>\<circ> composable_arrs (smc_Set \<alpha>) goal (1 subgoal): 1. S \<circ>\<^sub>A\<^bsub>smc_Set \<alpha>\<^esub> T = S \<circ>\<^sub>R\<^sub>e\<^sub>l T [PROOF STEP] then [PROOF STATE] proof (chain) picking this: [S, T]\<^sub>\<circ> \<in>\<^sub>\<circ> composable_arrs (smc_Set \<alpha>) [PROOF STEP] show "S \<circ>\<^sub>A\<^bsub>smc_Set \<alpha>\<^esub> T = S \<circ>\<^sub>S\<^sub>e\<^sub>t T" [PROOF STATE] proof (prove) using this: [S, T]\<^sub>\<circ> \<in>\<^sub>\<circ> composable_arrs (smc_Set \<alpha>) goal (1 subgoal): 1. S \<circ>\<^sub>A\<^bsub>smc_Set \<alpha>\<^esub> T = S \<circ>\<^sub>R\<^sub>e\<^sub>l T [PROOF STEP] unfolding smc_Set_Comp [PROOF STATE] proof (prove) using this: [S, T]\<^sub>\<circ> \<in>\<^sub>\<circ> composable_arrs (smc_Set \<alpha>) goal (1 subgoal): 1. (\<lambda>ST\<in>\<^sub>\<circ>composable_arrs (smc_Set \<alpha>). ST\<lparr>[]\<^sub>\<circ>\<rparr> \<circ>\<^sub>R\<^sub>e\<^sub>l ST\<lparr>1\<^sub>\<nat>\<rparr>) \<lparr>S, T\<rparr>\<^sub>\<bullet> = S \<circ>\<^sub>R\<^sub>e\<^sub>l T [PROOF STEP] by (simp add: nat_omega_simps) [PROOF STATE] proof (state) this: S \<circ>\<^sub>A\<^bsub>smc_Set \<alpha>\<^esub> T = S \<circ>\<^sub>R\<^sub>e\<^sub>l T goal: No subgoals! [PROOF STEP] qed
#ifndef BOOST_CORE_NO_EXCEPTIONS_SUPPORT_HPP #define BOOST_CORE_NO_EXCEPTIONS_SUPPORT_HPP #if defined(_MSC_VER) #pragma once #endif //---------------------------------------------------------------------- // (C) Copyright 2004 Pavel Vozenilek. // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // // // This file contains helper macros used when exception support may be // disabled (as indicated by macro BOOST_NO_EXCEPTIONS). // // Before picking up these macros you may consider using RAII techniques // to deal with exceptions - their syntax can be always the same with // or without exception support enabled. //---------------------------------------------------------------------- #include <boost/config.hpp> #include <boost/config/workaround.hpp> #if !(defined BOOST_NO_EXCEPTIONS) #define BOOST_TRY \ { \ try #define BOOST_CATCH(x) catch (x) #define BOOST_RETHROW throw; #define BOOST_CATCH_END } #else #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) #define BOOST_TRY \ { \ if ("") #define BOOST_CATCH(x) else if (!"") #elif !defined(BOOST_MSVC) || BOOST_MSVC >= 1900 #define BOOST_TRY \ { \ if (true) #define BOOST_CATCH(x) else if (false) #else // warning C4127: conditional expression is constant #define BOOST_TRY \ { \ __pragma(warning(push)) __pragma(warning(disable : 4127)) if (true) \ __pragma(warning(pop)) #define BOOST_CATCH(x) \ else __pragma(warning(push)) __pragma(warning(disable : 4127)) if (false) \ __pragma(warning(pop)) #endif #define BOOST_RETHROW #define BOOST_CATCH_END } #endif #endif
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import data.set.pointwise.smul import group_theory.submonoid.membership import order.well_founded_set /-! # Pointwise instances on `submonoid`s and `add_submonoid`s > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file provides: * `submonoid.has_inv` * `add_submonoid.has_neg` and the actions * `submonoid.pointwise_mul_action` * `add_submonoid.pointwise_mul_action` which matches the action of `mul_action_set`. These are all available in the `pointwise` locale. Additionally, it provides various degrees of monoid structure: * `add_submonoid.has_one` * `add_submonoid.has_mul` * `add_submonoid.mul_one_class` * `add_submonoid.semigroup` * `add_submonoid.monoid` which is available globally to match the monoid structure implied by `submodule.idem_semiring`. ## Implementation notes Most of the lemmas in this file are direct copies of lemmas from `algebra/pointwise.lean`. While the statements of these lemmas are defeq, we repeat them here due to them not being syntactically equal. Before adding new lemmas here, consider if they would also apply to the action on `set`s. -/ open set variables {α : Type*} {G : Type*} {M : Type*} {R : Type*} {A : Type*} variables [monoid M] [add_monoid A] /-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in `group_theory.submonoid.basic`, but currently we cannot because that file is imported by this. -/ namespace submonoid open_locale pointwise variables {s t u : set M} @[to_additive] lemma mul_subset {S : submonoid M} (hs : s ⊆ S) (ht : t ⊆ S) : s * t ⊆ S := by { rintro _ ⟨p, q, hp, hq, rfl⟩, exact submonoid.mul_mem _ (hs hp) (ht hq) } @[to_additive] lemma mul_subset_closure (hs : s ⊆ u) (ht : t ⊆ u) : s * t ⊆ submonoid.closure u := mul_subset (subset.trans hs submonoid.subset_closure) (subset.trans ht submonoid.subset_closure) @[to_additive] lemma coe_mul_self_eq (s : submonoid M) : (s : set M) * s = s := begin ext x, refine ⟨_, λ h, ⟨x, 1, h, s.one_mem, mul_one x⟩⟩, rintro ⟨a, b, ha, hb, rfl⟩, exact s.mul_mem ha hb end @[to_additive] lemma closure_mul_le (S T : set M) : closure (S * T) ≤ closure S ⊔ closure T := Inf_le $ λ x ⟨s, t, hs, ht, hx⟩, hx ▸ (closure S ⊔ closure T).mul_mem (set_like.le_def.mp le_sup_left $ subset_closure hs) (set_like.le_def.mp le_sup_right $ subset_closure ht) @[to_additive] lemma sup_eq_closure (H K : submonoid M) : H ⊔ K = closure (H * K) := le_antisymm (sup_le (λ h hh, subset_closure ⟨h, 1, hh, K.one_mem, mul_one h⟩) (λ k hk, subset_closure ⟨1, k, H.one_mem, hk, one_mul k⟩)) (by conv_rhs { rw [← closure_eq H, ← closure_eq K] }; apply closure_mul_le) @[to_additive] lemma pow_smul_mem_closure_smul {N : Type*} [comm_monoid N] [mul_action M N] [is_scalar_tower M N N] (r : M) (s : set N) {x : N} (hx : x ∈ closure s) : ∃ n : ℕ, r ^ n • x ∈ closure (r • s) := begin apply @closure_induction N _ s (λ (x : N), ∃ n : ℕ, r ^ n • x ∈ closure (r • s)) _ hx, { intros x hx, exact ⟨1, subset_closure ⟨_, hx, by rw pow_one⟩⟩ }, { exact ⟨0, by simpa using one_mem _⟩ }, { rintro x y ⟨nx, hx⟩ ⟨ny, hy⟩, use nx + ny, convert mul_mem hx hy, rw [pow_add, smul_mul_assoc, mul_smul, mul_comm, ← smul_mul_assoc, mul_comm] } end variables [group G] open_locale pointwise /-- The submonoid with every element inverted. -/ @[to_additive /-" The additive submonoid with every element negated. "-/] protected def has_inv : has_inv (submonoid G) := { inv := λ S, { carrier := (S : set G)⁻¹, one_mem' := show (1 : G)⁻¹ ∈ S, by { rw inv_one, exact S.one_mem }, mul_mem' := λ a b (ha : a⁻¹ ∈ S) (hb : b⁻¹ ∈ S), show (a * b)⁻¹ ∈ S, by { rw mul_inv_rev, exact S.mul_mem hb ha } } } localized "attribute [instance] submonoid.has_inv" in pointwise open_locale pointwise @[simp, to_additive] lemma coe_inv (S : submonoid G) : ↑(S⁻¹) = (S : set G)⁻¹ := rfl @[simp, to_additive] lemma mem_inv {g : G} {S : submonoid G} : g ∈ S⁻¹ ↔ g⁻¹ ∈ S := iff.rfl @[to_additive] instance : has_involutive_inv (submonoid G) := set_like.coe_injective.has_involutive_inv _ $ λ _, rfl @[simp, to_additive] lemma inv_le_inv (S T : submonoid G) : S⁻¹ ≤ T⁻¹ ↔ S ≤ T := set_like.coe_subset_coe.symm.trans set.inv_subset_inv @[to_additive] lemma inv_le (S T : submonoid G) : S⁻¹ ≤ T ↔ S ≤ T⁻¹ := set_like.coe_subset_coe.symm.trans set.inv_subset /-- `submonoid.has_inv` as an order isomorphism. -/ @[to_additive /-" `add_submonoid.has_neg` as an order isomorphism "-/, simps] def inv_order_iso : submonoid G ≃o submonoid G := { to_equiv := equiv.inv _, map_rel_iff' := inv_le_inv } @[to_additive] lemma closure_inv (s : set G) : closure s⁻¹ = (closure s)⁻¹ := begin apply le_antisymm, { rw [closure_le, coe_inv, ←set.inv_subset, inv_inv], exact subset_closure }, { rw [inv_le, closure_le, coe_inv, ←set.inv_subset], exact subset_closure } end @[simp, to_additive] lemma inv_inf (S T : submonoid G) : (S ⊓ T)⁻¹ = S⁻¹ ⊓ T⁻¹ := set_like.coe_injective set.inter_inv @[simp, to_additive] lemma inv_sup (S T : submonoid G) : (S ⊔ T)⁻¹ = S⁻¹ ⊔ T⁻¹ := (inv_order_iso : submonoid G ≃o submonoid G).map_sup S T @[simp, to_additive] lemma inv_bot : (⊥ : submonoid G)⁻¹ = ⊥ := set_like.coe_injective $ (set.inv_singleton 1).trans $ congr_arg _ inv_one @[simp, to_additive] lemma inv_top : (⊤ : submonoid G)⁻¹ = ⊤ := set_like.coe_injective $ set.inv_univ @[simp, to_additive] lemma inv_infi {ι : Sort*} (S : ι → submonoid G) : (⨅ i, S i)⁻¹ = ⨅ i, (S i)⁻¹ := (inv_order_iso : submonoid G ≃o submonoid G).map_infi _ @[simp, to_additive] lemma inv_supr {ι : Sort*} (S : ι → submonoid G) : (⨆ i, S i)⁻¹ = ⨆ i, (S i)⁻¹ := (inv_order_iso : submonoid G ≃o submonoid G).map_supr _ end submonoid namespace submonoid section monoid variables [monoid α] [mul_distrib_mul_action α M] /-- The action on a submonoid corresponding to applying the action to every element. This is available as an instance in the `pointwise` locale. -/ protected def pointwise_mul_action : mul_action α (submonoid M) := { smul := λ a S, S.map (mul_distrib_mul_action.to_monoid_End _ M a), one_smul := λ S, by { ext, simp, }, mul_smul := λ a₁ a₂ S, (congr_arg (λ f : monoid.End M, S.map f) (monoid_hom.map_mul _ _ _)).trans (S.map_map _ _).symm,} localized "attribute [instance] submonoid.pointwise_mul_action" in pointwise open_locale pointwise @[simp] lemma coe_pointwise_smul (a : α) (S : submonoid M) : ↑(a • S) = a • (S : set M) := rfl lemma smul_mem_pointwise_smul (m : M) (a : α) (S : submonoid M) : m ∈ S → a • m ∈ a • S := (set.smul_mem_smul_set : _ → _ ∈ a • (S : set M)) lemma mem_smul_pointwise_iff_exists (m : M) (a : α) (S : submonoid M) : m ∈ a • S ↔ ∃ (s : M), s ∈ S ∧ a • s = m := (set.mem_smul_set : m ∈ a • (S : set M) ↔ _) @[simp] lemma smul_bot (a : α) : a • (⊥ : submonoid M) = ⊥ := map_bot _ lemma smul_sup (a : α) (S T : submonoid M) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ lemma smul_closure (a : α) (s : set M) : a • closure s = closure (a • s) := monoid_hom.map_mclosure _ _ instance pointwise_central_scalar [mul_distrib_mul_action αᵐᵒᵖ M] [is_central_scalar α M] : is_central_scalar α (submonoid M) := ⟨λ a S, congr_arg (λ f : monoid.End M, S.map f) $ monoid_hom.ext $ by exact op_smul_eq_smul _⟩ end monoid section group variables [group α] [mul_distrib_mul_action α M] open_locale pointwise @[simp] lemma smul_mem_pointwise_smul_iff {a : α} {S : submonoid M} {x : M} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff lemma mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : submonoid M} {x : M} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem lemma mem_inv_pointwise_smul_iff {a : α} {S : submonoid M} {x : M} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] lemma pointwise_smul_le_pointwise_smul_iff {a : α} {S T : submonoid M} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff lemma pointwise_smul_subset_iff {a : α} {S T : submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff lemma subset_pointwise_smul_iff {a : α} {S T : submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff end group section group_with_zero variables [group_with_zero α] [mul_distrib_mul_action α M] open_locale pointwise @[simp] lemma smul_mem_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : submonoid M) (x : M) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : set M) x lemma mem_inv_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : submonoid M) (x : M) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : set M) x @[simp] lemma pointwise_smul_le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : submonoid M} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha lemma pointwise_smul_le_iff₀ {a : α} (ha : a ≠ 0) {S T : submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha lemma le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha end group_with_zero open_locale pointwise @[to_additive] lemma mem_closure_inv {G : Type*} [group G] (S : set G) (x : G) : x ∈ submonoid.closure S⁻¹ ↔ x⁻¹ ∈ submonoid.closure S := by rw [closure_inv, mem_inv] end submonoid namespace add_submonoid section monoid variables [monoid α] [distrib_mul_action α A] /-- The action on an additive submonoid corresponding to applying the action to every element. This is available as an instance in the `pointwise` locale. -/ protected def pointwise_mul_action : mul_action α (add_submonoid A) := { smul := λ a S, S.map (distrib_mul_action.to_add_monoid_End _ A a), one_smul := λ S, (congr_arg (λ f : add_monoid.End A, S.map f) (monoid_hom.map_one _)).trans S.map_id, mul_smul := λ a₁ a₂ S, (congr_arg (λ f : add_monoid.End A, S.map f) (monoid_hom.map_mul _ _ _)).trans (S.map_map _ _).symm,} localized "attribute [instance] add_submonoid.pointwise_mul_action" in pointwise open_locale pointwise @[simp] lemma coe_pointwise_smul (a : α) (S : add_submonoid A) : ↑(a • S) = a • (S : set A) := rfl lemma smul_mem_pointwise_smul (m : A) (a : α) (S : add_submonoid A) : m ∈ S → a • m ∈ a • S := (set.smul_mem_smul_set : _ → _ ∈ a • (S : set A)) lemma mem_smul_pointwise_iff_exists (m : A) (a : α) (S : add_submonoid A) : m ∈ a • S ↔ ∃ (s : A), s ∈ S ∧ a • s = m := (set.mem_smul_set : m ∈ a • (S : set A) ↔ _) @[simp] lemma smul_bot (a : α) : a • (⊥ : add_submonoid A) = ⊥ := map_bot _ lemma smul_sup (a : α) (S T : add_submonoid A) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ @[simp] lemma smul_closure (a : α) (s : set A) : a • closure s = closure (a • s) := add_monoid_hom.map_mclosure _ _ instance pointwise_central_scalar [distrib_mul_action αᵐᵒᵖ A] [is_central_scalar α A] : is_central_scalar α (add_submonoid A) := ⟨λ a S, congr_arg (λ f : add_monoid.End A, S.map f) $ add_monoid_hom.ext $ by exact op_smul_eq_smul _⟩ end monoid section group variables [group α] [distrib_mul_action α A] open_locale pointwise @[simp] lemma smul_mem_pointwise_smul_iff {a : α} {S : add_submonoid A} {x : A} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff lemma mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : add_submonoid A} {x : A} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem lemma mem_inv_pointwise_smul_iff {a : α} {S : add_submonoid A} {x : A} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] lemma pointwise_smul_le_pointwise_smul_iff {a : α} {S T : add_submonoid A} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff lemma pointwise_smul_le_iff {a : α} {S T : add_submonoid A} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff lemma le_pointwise_smul_iff {a : α} {S T : add_submonoid A} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff end group section group_with_zero variables [group_with_zero α] [distrib_mul_action α A] open_locale pointwise @[simp] lemma smul_mem_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : add_submonoid A) (x : A) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : set A) x lemma mem_pointwise_smul_iff_inv_smul_mem₀ {a : α} (ha : a ≠ 0) (S : add_submonoid A) (x : A) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : set A) x lemma mem_inv_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : add_submonoid A) (x : A) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : set A) x @[simp] lemma pointwise_smul_le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : add_submonoid A} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha lemma pointwise_smul_le_iff₀ {a : α} (ha : a ≠ 0) {S T : add_submonoid A} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha lemma le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : add_submonoid A} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha end group_with_zero end add_submonoid /-! ### Elementwise monoid structure of additive submonoids These definitions are a cut-down versions of the ones around `submodule.has_mul`, as that API is usually more useful. -/ namespace add_submonoid open_locale pointwise section add_monoid_with_one variables [add_monoid_with_one R] instance : has_one (add_submonoid R) := ⟨(nat.cast_add_monoid_hom R).mrange⟩ theorem one_eq_mrange : (1 : add_submonoid R) = (nat.cast_add_monoid_hom R).mrange := rfl lemma nat_cast_mem_one (n : ℕ) : (n : R) ∈ (1 : add_submonoid R) := ⟨_, rfl⟩ @[simp] lemma mem_one {x : R} : x ∈ (1 : add_submonoid R) ↔ ∃ n : ℕ, ↑n = x := iff.rfl theorem one_eq_closure : (1 : add_submonoid R) = closure {1} := begin simp only [closure_singleton_eq, mul_one, one_eq_mrange], congr' 1 with n, simp, end theorem one_eq_closure_one_set : (1 : add_submonoid R) = closure 1 := one_eq_closure end add_monoid_with_one section non_unital_non_assoc_semiring variables [non_unital_non_assoc_semiring R] /-- Multiplication of additive submonoids of a semiring R. The additive submonoid `S * T` is the smallest R-submodule of `R` containing the elements `s * t` for `s ∈ S` and `t ∈ T`. -/ instance : has_mul (add_submonoid R) := ⟨λ M N, ⨆ s : M, N.map $ add_monoid_hom.mul s.1⟩ theorem mul_mem_mul {M N : add_submonoid R} {m n : R} (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := (le_supr _ ⟨m, hm⟩ : _ ≤ M * N) ⟨n, hn, rfl⟩ theorem mul_le {M N P : add_submonoid R} : M * N ≤ P ↔ ∀ (m ∈ M) (n ∈ N), m * n ∈ P := ⟨λ H m hm n hn, H $ mul_mem_mul hm hn, λ H, supr_le $ λ ⟨m, hm⟩, map_le_iff_le_comap.2 $ λ n hn, H m hm n hn⟩ @[elab_as_eliminator] protected theorem mul_induction_on {M N : add_submonoid R} {C : R → Prop} {r : R} (hr : r ∈ M * N) (hm : ∀ (m ∈ M) (n ∈ N), C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := (@mul_le _ _ _ _ ⟨C, ha, by simpa only [zero_mul] using hm _ (zero_mem _) _ (zero_mem _)⟩).2 hm hr open_locale pointwise -- this proof is copied directly from `submodule.span_mul_span` theorem closure_mul_closure (S T : set R) : closure S * closure T = closure (S * T) := begin apply le_antisymm, { rw mul_le, intros a ha b hb, apply closure_induction ha, work_on_goal 1 { intros, apply closure_induction hb, work_on_goal 1 { intros, exact subset_closure ⟨_, _, ‹_›, ‹_›, rfl⟩ } }, all_goals { intros, simp only [mul_zero, zero_mul, zero_mem, left_distrib, right_distrib, mul_smul_comm, smul_mul_assoc]; solve_by_elim [add_mem _ _, zero_mem _] { max_depth := 4, discharger := tactic.interactive.apply_instance } } }, { rw closure_le, rintros _ ⟨a, b, ha, hb, rfl⟩, exact mul_mem_mul (subset_closure ha) (subset_closure hb) } end lemma mul_eq_closure_mul_set (M N : add_submonoid R) : M * N = closure (M * N) := by rw [←closure_mul_closure, closure_eq, closure_eq] @[simp] theorem mul_bot (S : add_submonoid R) : S * ⊥ = ⊥ := eq_bot_iff.2 $ mul_le.2 $ λ m hm n hn, by rw [add_submonoid.mem_bot] at hn ⊢; rw [hn, mul_zero] @[simp] theorem bot_mul (S : add_submonoid R) : ⊥ * S = ⊥ := eq_bot_iff.2 $ mul_le.2 $ λ m hm n hn, by rw [add_submonoid.mem_bot] at hm ⊢; rw [hm, zero_mul] @[mono] theorem mul_le_mul {M N P Q : add_submonoid R} (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q := mul_le.2 $ λ m hm n hn, mul_mem_mul (hmp hm) (hnq hn) theorem mul_le_mul_left {M N P : add_submonoid R} (h : M ≤ N) : M * P ≤ N * P := mul_le_mul h (le_refl P) theorem mul_le_mul_right {M N P : add_submonoid R} (h : N ≤ P) : M * N ≤ M * P := mul_le_mul (le_refl M) h lemma mul_subset_mul {M N : add_submonoid R} : (↑M : set R) * (↑N : set R) ⊆ (↑(M * N) : set R) := by { rintros _ ⟨i, j, hi, hj, rfl⟩, exact mul_mem_mul hi hj } end non_unital_non_assoc_semiring section non_unital_non_assoc_ring variables [non_unital_non_assoc_ring R] /-- `add_submonoid.has_pointwise_neg` distributes over multiplication. This is available as an instance in the `pointwise` locale. -/ protected def has_distrib_neg : has_distrib_neg (add_submonoid R) := { neg := has_neg.neg, neg_mul := λ x y, begin refine le_antisymm (mul_le.2 $ λ m hm n hn, _) ((add_submonoid.neg_le _ _).2 $ mul_le.2 $ λ m hm n hn, _); simp only [add_submonoid.mem_neg, ←neg_mul] at *, { exact mul_mem_mul hm hn }, { exact mul_mem_mul (neg_mem_neg.2 hm) hn }, end, mul_neg := λ x y, begin refine le_antisymm (mul_le.2 $ λ m hm n hn, _) ((add_submonoid.neg_le _ _).2 $ mul_le.2 $ λ m hm n hn, _); simp only [add_submonoid.mem_neg, ←mul_neg] at *, { exact mul_mem_mul hm hn,}, { exact mul_mem_mul hm (neg_mem_neg.2 hn) }, end, ..add_submonoid.has_involutive_neg } localized "attribute [instance] add_submonoid.has_distrib_neg" in pointwise end non_unital_non_assoc_ring section non_assoc_semiring variables [non_assoc_semiring R] instance : mul_one_class (add_submonoid R) := { one := 1, mul := (*), one_mul := λ M, by rw [one_eq_closure_one_set, ←closure_eq M, closure_mul_closure, one_mul], mul_one := λ M, by rw [one_eq_closure_one_set, ←closure_eq M, closure_mul_closure, mul_one] } end non_assoc_semiring section non_unital_semiring variables [non_unital_semiring R] instance : semigroup (add_submonoid R) := { mul := (*), mul_assoc := λ M N P, le_antisymm (mul_le.2 $ λ mn hmn p hp, suffices M * N ≤ (M * (N * P)).comap (add_monoid_hom.mul_right p), from this hmn, mul_le.2 $ λ m hm n hn, show m * n * p ∈ M * (N * P), from (mul_assoc m n p).symm ▸ mul_mem_mul hm (mul_mem_mul hn hp)) (mul_le.2 $ λ m hm np hnp, suffices N * P ≤ (M * N * P).comap (add_monoid_hom.mul_left m), from this hnp, mul_le.2 $ λ n hn p hp, show m * (n * p) ∈ M * N * P, from mul_assoc m n p ▸ mul_mem_mul (mul_mem_mul hm hn) hp) } end non_unital_semiring section semiring variables [semiring R] instance : monoid (add_submonoid R) := { one := 1, mul := (*), ..add_submonoid.semigroup, ..add_submonoid.mul_one_class } lemma closure_pow (s : set R) : ∀ n : ℕ, closure s ^ n = closure (s ^ n) | 0 := by rw [pow_zero, pow_zero, one_eq_closure_one_set] | (n + 1) := by rw [pow_succ, pow_succ, closure_pow, closure_mul_closure] lemma pow_eq_closure_pow_set (s : add_submonoid R) (n : ℕ) : s ^ n = closure ((s : set R) ^ n) := by rw [←closure_pow, closure_eq] lemma pow_subset_pow {s : add_submonoid R} {n : ℕ} : (↑s : set R)^n ⊆ ↑(s^n) := (pow_eq_closure_pow_set s n).symm ▸ subset_closure end semiring end add_submonoid namespace set.is_pwo variables [ordered_cancel_comm_monoid α] {s : set α} @[to_additive] lemma submonoid_closure (hpos : ∀ x : α, x ∈ s → 1 ≤ x) (h : s.is_pwo) : is_pwo ((submonoid.closure s) : set α) := begin rw submonoid.closure_eq_image_prod, refine (h.partially_well_ordered_on_sublist_forall₂ (≤)).image_of_monotone_on _, exact λ l1 hl1 l2 hl2 h12, h12.prod_le_prod' (λ x hx, hpos x $ hl2 x hx) end end set.is_pwo
-- Copyright 2017, the blau.io contributors -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. module API.WebGL.Shader import IdrisScript %access public export %default total record WebGLShader where constructor New self : JSRef FRAGMENT_SHADER : Int FRAGMENT_SHADER = 0x8B30 VERTEX_SHADER : Int VERTEX_SHADER = 0x8B31
# Chempy example notebook ##### Credit goes to CHEMPY authors MOST OF THIS NOTEBOOK IS ADAPTED FROM THEIR EXAMPLES First we are going to import the chempy package, see the install instructions on the chempy github, and use the "chempy._ _version_" as a sanity check for installing the correct version. Make sure to install the optional dependencies for the chempy package because other useful packages such as thermo,sympy, etc are useful for ode solving, thermodynamic constants, etc. __This is to remind myself that I am in the virtual env kittens where I installed chempy__ #### MOST OF THE RATE CONSTANTS VALUES ARE ARBITRARY. will need to ask elizabeth for more clarification, but this notebook is a good start to figuring out the kinetic modelling ```python import chempy import numpy as np import sympy as sp sp.init_printing() import matplotlib.pyplot as plt %matplotlib inline sp.__version__, chempy.__version__ ``` ('1.4', '0.7.8') We will first go through an example of balancing stoichiometry and mass fraction calculations that comes with the chempy package ```python # import classes from chempy import balance_stoichiometry from pprint import pprint from chempy import mass_fractions ``` ```python reactants, products = balance_stoichiometry({'HCOOH'},{'H2','CO2'})#,'CO','H2O'}) ``` ```python # Creates an ordered dictionary object with the reactants reactants ``` OrderedDict([('HCOOH', 1)]) ```python products ``` OrderedDict([('CO2', 1), ('H2', 1)]) ```python # Creates a dictionary object with the stoichiometric constants as the items and the reactants as the keys pprint(dict(reactants)) ``` {'HCOOH': 1} ```python pprint(dict(products)) ``` {'CO2': 1, 'H2': 1} ```python mass_fractions ``` <function chempy.chemistry.mass_fractions(stoichiometries, substances=None, substance_factory=<bound method Substance.from_formula of <class 'chempy.chemistry.Substance'>>)> ```python # Calculates the weight percents based on the mass for fractions in map(mass_fractions, [reactants, products]): pprint({k: '{0:.3g} wt%'.format(v*100) for k, v in fractions.items()}) # .3g is for the number of sig figs ``` {'HCOOH': '100 wt%'} {'CO2': '95.6 wt%', 'H2': '4.38 wt%'} ```python reaction, product = balance_stoichiometry({'HCOOH'},{'CO','H2O'}) for fractions in map(mass_fractions, [reaction, product]): pprint({k: '{0:.3g} wt%'.format(v*100) for k, v in fractions.items()}) # .4g is for the number of sig figs ``` {'HCOOH': '100 wt%'} {'CO': '60.9 wt%', 'H2O': '39.1 wt%'} ## Reaction Chemical Kinetics ```python # Import packages from chempy import ReactionSystem from chempy.kinetics.ode import get_odesys from collections import defaultdict import numpy as np import matplotlib.pyplot as plt ``` ```python # Reaction System from string # The rate constants below are arbitrary rsys = ReactionSystem.from_string(""" HCOOH -> H2 + CO2; 42 HCOOH -> H2O + CO; 17 """) # "[H2O]" = 1.0 (actually 55.4 at RT) # Ordinary Differential Systems of Equations odesys, extra = get_odesys(rsys) # Time axis tout = sorted(np.concatenate((np.linspace(0, 23), np.logspace(-8, 1)))) # Initial Concentrations c0 = defaultdict(float, {'HCOOH': 1.00, 'H2': 0.00, 'CO2': 0.000, 'H2O': 0.00, 'CO': 0.00}) # Integrated ode system result = odesys.integrate(tout, c0, atol=1e-12, rtol=1e-14) # Plotting the results fig, axes = plt.subplots(1, 2, figsize=(12, 5)) for ax in axes: result.plot(names=[k for k in rsys.substances if k != 'H2O'], ax=ax) ax.legend(loc='best', prop={'size': 9}) ax.set_xlabel('Time') ax.set_ylabel('Concentration') axes[1].set_ylim([1e-13, 1e-1]) axes[1].set_xscale('log') axes[1].set_yscale('log') fig.tight_layout() #fig.savefig('examples/kinetics.png', dpi=72) ``` ```python rsys ``` <table class="chempy_ReactionSystem chempy_2333850077504"><tr><th style="text-align:center;" colspan="5"></th></tr><tr class="chempy_2333850077504_0"><td style="text-align:right;"><span class="chempy_HCOOH" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">HCOOH</span></td><td style="text-align:center;">&rarr;</td><td style="text-align:left;"><span class="chempy_CO2" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">CO<sub>2</sub></span> + <span class="chempy_H2" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">H<sub>2</sub></span></td><td style="text-align:left;">&nbsp;42</td></tr> <tr class="chempy_2333850077504_1"><td style="text-align:right;"><span class="chempy_HCOOH" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">HCOOH</span></td><td style="text-align:center;">&rarr;</td><td style="text-align:left;"><span class="chempy_CO" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">CO</span> + <span class="chempy_H2O" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">H<sub>2</sub>O</span></td><td style="text-align:left;">&nbsp;17</td></tr></table> ```python odesys ``` <pyodesys.symbolic.SymbolicSys at 0x21f64e9ad30> ```python extra ``` {'param_keys': [], 'unique': OrderedDict(), 'p_units': None, 'max_euler_step_cb': <function chempy.kinetics.ode.get_odesys.<locals>.max_euler_step_cb(x, y, p=())>, 'linear_dependencies': <function chempy.kinetics.ode.get_odesys.<locals>.linear_dependencies(preferred=None)>, 'rate_exprs_cb': <pyodesys.util._Callback at 0x21f64e8bc88>, 'cstr_fr_fc': False, 'unit_registry': None} # Example kinetic model with 2 sets of products ```python # EXAMPLE KINETIC MODEL from __future__ import absolute_import, division, print_function from collections import defaultdict from ipywidgets import interact import matplotlib.pyplot as plt from chempy import Reaction, Substance, ReactionSystem from chempy.kinetics.ode import get_odesys from chempy.kinetics.analysis import plot_reaction_contributions from chempy.printing.tables import UnimolecularTable, BimolecularTable from chempy.util.graph import rsys2graph import sympy sympy.init_printing() %matplotlib inline ``` ```python # Substance ?? A, B, C, D, E, F= map(Substance, 'ABCDEF') # Sympy ?? One = sympy.S.One # Reactions object reactions = r0, r1 = [ Reaction({'A'}, {'B', 'C'}, 4*One/100, name='R1: A cons.'), Reaction({'A'}, {'D', 'E'}, 3*One/100, name='R2: A cons.'), ] # Reaction system rsys = ReactionSystem(reactions, (A, B, C, D, E)) # UnimolecularTable and BimolecularTable from Reaction system uni, not_uni = UnimolecularTable.from_ReactionSystem(rsys) bi, not_bi = BimolecularTable.from_ReactionSystem(rsys) assert not (not_uni & not_bi), "There are only uni- & bi-molecular reactions in this set" # Ordinary Differential Systems of Equations odesys, extra = get_odesys(rsys, include_params=True) odesys.exprs ``` ```python # Jacobian matrix of Ordinary Differential Systems of Equations odesys.get_jac() ``` $\displaystyle \left[\begin{matrix}- \frac{7}{100} & 0 & 0 & 0 & 0\\\frac{1}{25} & 0 & 0 & 0 & 0\\\frac{1}{25} & 0 & 0 & 0 & 0\\\frac{3}{100} & 0 & 0 & 0 & 0\\\frac{3}{100} & 0 & 0 & 0 & 0\end{matrix}\right]$ ```python reactions ``` [<chempy.chemistry.Reaction at 0x21f6892f7b8>, <chempy.chemistry.Reaction at 0x21f6892f8d0>] ```python rsys ``` <table class="chempy_ReactionSystem chempy_2333921702072"><tr><th style="text-align:center;" colspan="5"></th></tr><tr class="chempy_2333921702072_0"><td style="text-align:right;"><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td style="text-align:center;">&rarr;</td><td style="text-align:left;"><span class="chempy_B" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">B</span> + <span class="chempy_C" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">C</span></td><td style="text-align:left;">&nbsp;0.04</td><td style="text-align:left;">&nbsp;R1: A cons.</td></tr> <tr class="chempy_2333921702072_1"><td style="text-align:right;"><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td style="text-align:center;">&rarr;</td><td style="text-align:left;"><span class="chempy_D" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">D</span> + <span class="chempy_E" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">E</span></td><td style="text-align:left;">&nbsp;0.03</td><td style="text-align:left;">&nbsp;R2: A cons.</td></tr></table> ```python uni ``` <table><tr><td><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td ><a title="0: A → B + C; 0.04">R1: A cons.</a>, <a title="1: A → D + E; 0.03">R2: A cons.</a></td></tr> <tr><td><span class="chempy_B" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">B</span></td><td ></td></tr> <tr><td><span class="chempy_C" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">C</span></td><td ></td></tr> <tr><td><span class="chempy_D" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">D</span></td><td ></td></tr> <tr><td><span class="chempy_E" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">E</span></td><td ></td></tr></table> ```python bi ``` <table><th></th><th><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></th><th><span class="chempy_B" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">B</span></th><th><span class="chempy_C" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">C</span></th><th><span class="chempy_D" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">D</span></th><th><span class="chempy_E" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">E</span></th> <tr><td><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td ></td><td ></td><td ></td><td ></td><td ></td></tr> <tr><td><span class="chempy_B" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">B</span></td><td >-</td><td ></td><td ></td><td ></td><td ></td></tr> <tr><td><span class="chempy_C" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">C</span></td><td >-</td><td >-</td><td ></td><td ></td><td ></td></tr> <tr><td><span class="chempy_D" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">D</span></td><td >-</td><td >-</td><td >-</td><td ></td><td ></td></tr> <tr><td><span class="chempy_E" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">E</span></td><td >-</td><td >-</td><td >-</td><td >-</td><td ></td></tr></table> ```python not_uni ``` ```python not_bi ``` ```python # Initial Concentration c0 = defaultdict(float, {'A': 1}) # Integrated ode system ?? result = odesys.integrate(1e10, c0, integrator='cvode', nsteps=2000) # Dictionary object ?? {k: v for k, v in result.info.items() if not k.startswith('internal')} ``` c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of '#include <math.h>': warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed to include math.h: warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of '#include <sundials/sundials_config.h>': warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: sundials not in include path, set e.g. $CPLUS_INCLUDE_PATH (): warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of ' #include <sundials/sundials_config.h> #if SUNDIALS_VERSION_MAJOR >= 3 #include <stdio.h> #include <sunmatrix/sunmatrix_dense.h> #else #error "Sundials 2?" #endif ': warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of ' #include <sundials/sundials_config.h> #if defined(SUNDIALS_PACKAGE_VERSION) /* == 2.7.0 */ #include <cvodes/cvodes_spgmr.h> #else #error "Unkown sundials version" #endif ': warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Unknown sundials version: warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of ' #include <sundials/sundials_config.h> #if !defined(SUNDIALS_KLU) #error "INFO: KLU was not enabled for this sundials build" #endif ': warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of '#include <sundials/sundials_config.h> #ifndef SUNDIALS_SINGLE_PRECISION #error "INFO: SUNDIALS_SINGLE not defined in sundials/sundials_config.h" #endif ': warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of '#include <sundials/sundials_config.h> #ifndef SUNDIALS_DOUBLE_PRECISION #error "INFO: SUNDIALS_DOUBLE not defined in sundials/sundials_config.h" #endif ': warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of '#include <sundials/sundials_config.h> #ifndef SUNDIALS_EXTENDED_PRECISION #error "INFO: SUNDIALS_EXTENDED not defined in sundials/sundials_config.h" #endif ': warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Couldn't determine sundials precision from sundials/sundials_config.h warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of '#include <sundials/sundials_types.h> #ifndef SUNDIALS_INT32_T #error INFO: SUNDIALS_INT32_T is not defined #endif ': warnings.warn(msg) c:\users\user1\anaconda3\envs\kittens\lib\site-packages\pycvodes\_config.py:44: UserWarning: Failed test compilation of '#include <sundials/sundials_types.h> #ifndef SUNDIALS_INT64_T #error INFO: SUNDIALS_INT64_T is not defined #endif ': warnings.warn(msg) {'n_nonlin_solv_iters': 233, 'n_steps': 186, 'n_dls_jac_evals': 4, 'n_nonlin_solv_conv_fails': 0, 'n_root_evals': 0, 'n_rhs_evals': 234, 'n_lin_solv_setups': 48, 'n_err_test_fails': 8, 'n_dls_rhs_evals': 0, 'njvev': 0, 'nfev': 234, 'njev': 4, 'time_cpu': 0.011, 'time_jtimes': 0.0, 'time_jac': 0.000191574, 'time_wall': 0.010793836, 'time_rhs': 0.010093234000000013, 'time_prec': 0.0, 'time_quads': 0.0, 'time_roots': 0.0, 'steps': array([], dtype=float64), 'orders': array([], dtype=int32), 'fpes': array([], dtype=int32), 'success': True, 'atol': [1e-08], 'rtol': 1e-08, 'mode': 'adaptive'} ```python odesys ``` <pyodesys.symbolic.SymbolicSys at 0x21f688d5198> ```python extra ``` {'param_keys': [], 'unique': OrderedDict(), 'p_units': None, 'max_euler_step_cb': None, 'linear_dependencies': None, 'rate_exprs_cb': <pyodesys.util._Callback at 0x21f6892fa90>, 'cstr_fr_fc': False, 'unit_registry': None} ```python # Experimental rates ?? extra['rate_exprs_cb'](result.xout, result.yout) ``` array([[ 4.00000000e-02, 3.00000000e-02], [ 3.99999791e-02, 2.99999844e-02], [ 3.99967271e-02, 2.99975453e-02], [ 3.99865668e-02, 2.99899251e-02], [ 3.99764087e-02, 2.99823065e-02], [ 3.99662532e-02, 2.99746899e-02], [ 3.99561001e-02, 2.99670751e-02], [ 3.99346578e-02, 2.99509933e-02], [ 3.98952558e-02, 2.99214418e-02], [ 3.98203854e-02, 2.98652891e-02], [ 3.96304666e-02, 2.97228500e-02], [ 3.95263476e-02, 2.96447607e-02], [ 3.94225021e-02, 2.95668765e-02], [ 3.93189294e-02, 2.94891970e-02], [ 3.91159337e-02, 2.93369503e-02], [ 3.89139863e-02, 2.91854897e-02], [ 3.87130818e-02, 2.90348113e-02], [ 3.85132147e-02, 2.88849110e-02], [ 3.83143795e-02, 2.87357846e-02], [ 3.79337531e-02, 2.84503148e-02], [ 3.73264129e-02, 2.79948096e-02], [ 3.67287969e-02, 2.75465977e-02], [ 3.61407485e-02, 2.71055614e-02], [ 3.55621145e-02, 2.66715859e-02], [ 3.49927444e-02, 2.62445583e-02], [ 3.44324903e-02, 2.58243678e-02], [ 3.38812063e-02, 2.54109048e-02], [ 3.33387487e-02, 2.50040616e-02], [ 3.24162116e-02, 2.43121587e-02], [ 3.15192025e-02, 2.36394019e-02], [ 3.06470150e-02, 2.29852613e-02], [ 2.97989624e-02, 2.23492218e-02], [ 2.89743767e-02, 2.17307825e-02], [ 2.76893824e-02, 2.07670368e-02], [ 2.64613765e-02, 1.98460324e-02], [ 2.52878319e-02, 1.89658739e-02], [ 2.41663336e-02, 1.81247502e-02], [ 2.30945733e-02, 1.73209300e-02], [ 2.20703449e-02, 1.65527586e-02], [ 2.10915401e-02, 1.58186551e-02], [ 2.01561447e-02, 1.51171085e-02], [ 1.92622334e-02, 1.44466751e-02], [ 1.74302608e-02, 1.30726956e-02], [ 1.63209099e-02, 1.22406825e-02], [ 1.52821632e-02, 1.14616224e-02], [ 1.43095274e-02, 1.07321455e-02], [ 1.33987953e-02, 1.00490965e-02], [ 1.19767624e-02, 8.98257176e-03], [ 1.11752112e-02, 8.38140841e-03], [ 1.04273033e-02, 7.82047751e-03], [ 9.72944951e-03, 7.29708713e-03], [ 9.07830037e-03, 6.80872528e-03], [ 8.34266157e-03, 6.25699618e-03], [ 7.66663380e-03, 5.74997535e-03], [ 7.04538610e-03, 5.28403958e-03], [ 6.47447948e-03, 4.85585961e-03], [ 5.94983492e-03, 4.46237619e-03], [ 5.46770384e-03, 4.10077788e-03], [ 5.02464118e-03, 3.76848089e-03], [ 4.61748104e-03, 3.46311078e-03], [ 4.24331413e-03, 3.18248559e-03], [ 3.89946697e-03, 2.92460023e-03], [ 3.58348269e-03, 2.68761202e-03], [ 3.29310348e-03, 2.46982761e-03], [ 3.02625447e-03, 2.26969085e-03], [ 2.78102894e-03, 2.08577170e-03], [ 2.55567469e-03, 1.91675602e-03], [ 2.34858151e-03, 1.76143613e-03], [ 2.15826965e-03, 1.61870224e-03], [ 1.98337926e-03, 1.48753445e-03], [ 1.82266072e-03, 1.36699554e-03], [ 1.67496562e-03, 1.25622422e-03], [ 1.53923866e-03, 1.15442900e-03], [ 1.41451002e-03, 1.06088252e-03], [ 1.29988848e-03, 9.74916357e-04], [ 1.19455502e-03, 8.95916267e-04], [ 1.09775702e-03, 8.23317766e-04], [ 1.00880282e-03, 7.56602117e-04], [ 9.27056822e-04, 6.95292616e-04], [ 8.51934918e-04, 6.38951189e-04], [ 7.82900344e-04, 5.87175258e-04], [ 7.19459827e-04, 5.39594871e-04], [ 6.61160066e-04, 4.95870049e-04], [ 6.07584491e-04, 4.55688368e-04], [ 5.58350288e-04, 4.18762716e-04], [ 5.13105665e-04, 3.84829249e-04], [ 4.71527335e-04, 3.53645501e-04], [ 4.33318209e-04, 3.24988657e-04], [ 3.98205271e-04, 2.98653954e-04], [ 3.65937629e-04, 2.74453222e-04], [ 3.36284720e-04, 2.52213540e-04], [ 3.09034667e-04, 2.31776000e-04], [ 2.72061796e-04, 2.04046347e-04], [ 2.39512522e-04, 1.79634391e-04], [ 2.10857507e-04, 1.58143130e-04], [ 1.85630703e-04, 1.39223028e-04], [ 1.63421939e-04, 1.22566454e-04], [ 1.43870204e-04, 1.07902653e-04], [ 1.26657658e-04, 9.49932435e-05], [ 1.11504427e-04, 8.36283205e-05], [ 9.81641102e-05, 7.36230827e-05], [ 8.64198077e-05, 6.48148558e-05], [ 7.60805864e-05, 5.70604398e-05], [ 6.69783502e-05, 5.02337627e-05], [ 5.89651031e-05, 4.42238273e-05], [ 5.19105539e-05, 3.89329154e-05], [ 4.57000044e-05, 3.42750033e-05], [ 4.02324815e-05, 3.01743612e-05], [ 3.54190913e-05, 2.65643185e-05], [ 3.11815727e-05, 2.33861795e-05], [ 2.74510278e-05, 2.05882708e-05], [ 2.41668026e-05, 1.81251020e-05], [ 2.12755003e-05, 1.59566253e-05], [ 1.75056313e-05, 1.31292235e-05], [ 1.44039148e-05, 1.08029361e-05], [ 1.18518599e-05, 8.88889491e-06], [ 9.75193522e-06, 7.31395142e-06], [ 8.02401013e-06, 6.01800760e-06], [ 6.60223839e-06, 4.95167880e-06], [ 5.43241565e-06, 4.07431174e-06], [ 4.46988461e-06, 3.35241346e-06], [ 3.67788945e-06, 2.75841709e-06], [ 3.02621177e-06, 2.26965883e-06], [ 2.49000293e-06, 1.86750220e-06], [ 2.04881003e-06, 1.53660752e-06], [ 1.68579297e-06, 1.26434473e-06], [ 1.38709477e-06, 1.04032108e-06], [ 1.14131926e-06, 8.55989445e-07], [ 8.38052171e-07, 6.28539129e-07], [ 6.15511979e-07, 4.61633984e-07], [ 4.52156444e-07, 3.39117333e-07], [ 3.32130784e-07, 2.49098088e-07], [ 2.43907039e-07, 1.82930280e-07], [ 1.79104383e-07, 1.34328288e-07], [ 1.31542625e-07, 9.86569685e-08], [ 9.66260770e-08, 7.24695577e-08], [ 7.09698669e-08, 5.32274002e-08], [ 5.21143367e-08, 3.90857525e-08], [ 3.14617924e-08, 2.35963443e-08], [ 1.91091814e-08, 1.43318861e-08], [ 1.16984682e-08, 8.77385118e-09], [ 7.15785297e-09, 5.36838972e-09], [ 4.33438087e-09, 3.25078565e-09], [ 2.61121267e-09, 1.95840950e-09], [ 1.21334427e-09, 9.10008201e-10], [ 1.61967179e-09, 1.21475385e-09], [ 1.06285474e-09, 7.97141055e-10], [ 2.07729306e-10, 1.55796979e-10], [-9.59293320e-11, -7.19469990e-11], [ 8.96962950e-11, 6.72722212e-11], [ 1.04470567e-09, 7.83529255e-10], [ 7.78316673e-10, 5.83737505e-10], [ 6.93022615e-11, 5.19766962e-11], [-1.88991908e-10, -1.41743931e-10], [ 2.67524332e-11, 2.00643249e-11], [ 1.72278821e-10, 1.29209116e-10], [ 5.26186486e-11, 3.94639864e-11], [-8.17638928e-11, -6.13229196e-11], [-2.90894793e-10, -2.18171095e-10], [-3.18967988e-10, -2.39225991e-10], [-1.63582207e-10, -1.22686655e-10], [-1.81596404e-11, -1.36197303e-11], [ 1.83549750e-11, 1.37662312e-11], [ 1.32137566e-11, 9.91031742e-12], [-2.76716376e-12, -2.07537282e-12], [-3.04536327e-11, -2.28402245e-11], [-1.62952245e-11, -1.22214184e-11], [-4.61533631e-11, -3.46150223e-11], [-5.60159158e-11, -4.20119368e-11], [-1.28556083e-11, -9.64170621e-12], [ 3.98511958e-12, 2.98883968e-12], [-5.82143618e-13, -4.36607714e-13], [-3.26420773e-12, -2.44815580e-12], [-4.22232971e-12, -3.16674728e-12], [-7.46289015e-13, -5.59716761e-13], [ 8.12130098e-14, 6.09097574e-14], [ 1.82886619e-13, 1.37164964e-13], [ 7.96723760e-14, 5.97542820e-14], [ 2.13431203e-14, 1.60073402e-14], [ 1.34327057e-17, 1.00745293e-17], [ 3.12507252e-21, 2.34380439e-21], [ 7.27189653e-26, 5.45392240e-26], [ 1.69212205e-31, 1.26909154e-31], [ 3.93790608e-38, 2.95342956e-38], [ 8.96831017e-46, 6.72623263e-46], [ 5.34552942e-53, 4.00914707e-53], [ 2.98704733e-61, 2.24028550e-61]]) ```python result.plot(xscale='log', yscale='log') ``` ```python # PLOTTING THE REACTION CONTRIBUTIONS DIRECTLY FROM CHEMPY ROBERTSON fig, axes = plt.subplots(2, 2, figsize=(14, 6)) # normal y scale plot_reaction_contributions(result, rsys, extra['rate_exprs_cb'], 'AB', axes=axes[0, :]) plot_reaction_contributions(result, rsys, extra['rate_exprs_cb'], 'AD', axes=axes[1, :]) plt.tight_layout() ``` ```python fig, axes = plt.subplots(2, 2, figsize=(14, 6)) # Linear y scale plot_reaction_contributions(result, rsys, extra['rate_exprs_cb'], 'AC', axes=axes[0, :], relative=True, yscale='linear') plot_reaction_contributions(result, rsys, extra['rate_exprs_cb'], 'AE', axes=axes[1, :], relative=True, yscale='linear') plt.tight_layout() ``` ### Now we will incorporate mass action into the kinetic model ```python str_massaction = """ A -> B + C; 'k1' A -> D + E; 'k2' """ ``` ```python rsys3 = ReactionSystem.from_string(str_massaction, substance_factory=lambda formula: Substance(formula)) ``` ```python str_massaction ``` "\nA -> B + C; 'k1'\nA -> D + E; 'k2'\n" ```python rsys3 ``` <table class="chempy_ReactionSystem chempy_2333921359912"><tr><th style="text-align:center;" colspan="5"></th></tr><tr class="chempy_2333921359912_0"><td style="text-align:right;"><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td style="text-align:center;">&rarr;</td><td style="text-align:left;"><span class="chempy_B" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">B</span> + <span class="chempy_C" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">C</span></td><td style="text-align:left;">&nbsp;MassAction((), ('k1',))</td></tr> <tr class="chempy_2333921359912_1"><td style="text-align:right;"><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td style="text-align:center;">&rarr;</td><td style="text-align:left;"><span class="chempy_D" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">D</span> + <span class="chempy_E" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">E</span></td><td style="text-align:left;">&nbsp;MassAction((), ('k2',))</td></tr></table> ```python odesys3, extra3 = get_odesys(rsys3, include_params=False, lower_bounds=[0, 0, 0,0,0]) extra3['param_keys'], extra3['unique'] ``` ([], OrderedDict([('k1', None), ('k2', None)])) ```python odesys3.exprs, odesys3.params, odesys3.names, odesys3.param_names ``` ((-p_0*y_0 - p_1*y_0, p_0*y_0, p_0*y_0, p_1*y_0, p_1*y_0), (p_0, p_1), ('A', 'B', 'C', 'D', 'E'), ('k1', 'k2')) ```python def integrate_and_plot(A0=1.0, B0=0.0, C0=0.0, D0=0.0, E0=0.0, lg_k1=-2, lg_k2=4, lg_tend=9): plt.figure(figsize=(14, 4)) tout, yout, info = odesys3.integrate( 10**lg_tend, {'A': A0, 'B': B0, 'C': C0,'D': D0, 'E': E0}, {'k1': 10**lg_k1, 'k2': 10**lg_k2}, integrator='cvode', nsteps=3000) plt.subplot(1, 2, 1) odesys3.plot_result(xscale='log', yscale='log') plt.legend(loc='best') plt.subplot(1, 2, 2) plt.plot(tout[tout<.05], yout[tout<.05, odesys3.names.index('B')]) _ = plt.legend('best') interact(integrate_and_plot) #, **kw) # kw for additional optional arguments ``` interactive(children=(FloatSlider(value=1.0, description='A0', max=3.0, min=-1.0), FloatSlider(value=0.0, desc… <function __main__.integrate_and_plot(A0=1.0, B0=0.0, C0=0.0, D0=0.0, E0=0.0, lg_k1=-2, lg_k2=4, lg_tend=9)> ```python # We could also have used SymPy to construct symbolic rates: import sympy rsys_sym = ReactionSystem.from_string(""" A -> B + C; sp.Symbol('k1') A -> D + E; sp.Symbol('k2') """, rxn_parse_kwargs=dict(globals_={'sp': sympy}), substance_factory=lambda formula: Substance(formula)) odesys_sym, _ = get_odesys(rsys_sym, params=True) for attr in 'exprs params names param_names'.split(): print(getattr(odesys_sym, attr)) ``` (-k1*y_0 - k2*y_0, k1*y_0, k1*y_0, k2*y_0, k2*y_0) (k1, k2) ('A', 'B', 'C', 'D', 'E') () For larger systems it is easy to loose track of what substances are actually playing a part, here the html tables can help (note the yellow background color): ```python rsys.substances['F'] = F uni, not_uni = UnimolecularTable.from_ReactionSystem(rsys) uni ``` <table><tr><td><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td ><a title="0: A → B + C; 0.04">R1: A cons.</a>, <a title="1: A → D + E; 0.03">R2: A cons.</a></td></tr> <tr><td><span class="chempy_B" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">B</span></td><td ></td></tr> <tr><td><span class="chempy_C" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">C</span></td><td ></td></tr> <tr><td><span class="chempy_D" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">D</span></td><td ></td></tr> <tr><td><span class="chempy_E" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">E</span></td><td ></td></tr> <tr><td><span class="chempy_F" style="border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">F</span></td><td style="background-color: #eee8aa;"></td></tr></table> ```python bi, not_bi = BimolecularTable.from_ReactionSystem(rsys) bi ``` <table><th></th><th><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></th><th><span class="chempy_B" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">B</span></th><th><span class="chempy_C" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">C</span></th><th><span class="chempy_D" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">D</span></th><th><span class="chempy_E" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">E</span></th><th><span class="chempy_F" style="border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">F</span></th> <tr><td><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td ></td><td ></td><td ></td><td ></td><td ></td><td style="background-color: #eee8aa;"></td></tr> <tr><td><span class="chempy_B" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">B</span></td><td >-</td><td ></td><td ></td><td ></td><td ></td><td style="background-color: #eee8aa;"></td></tr> <tr><td><span class="chempy_C" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">C</span></td><td >-</td><td >-</td><td ></td><td ></td><td ></td><td style="background-color: #eee8aa;"></td></tr> <tr><td><span class="chempy_D" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">D</span></td><td >-</td><td >-</td><td >-</td><td ></td><td ></td><td style="background-color: #eee8aa;"></td></tr> <tr><td><span class="chempy_E" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">E</span></td><td >-</td><td >-</td><td >-</td><td >-</td><td ></td><td style="background-color: #eee8aa;"></td></tr> <tr><td><span class="chempy_F" style="border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">F</span></td><td >-</td><td >-</td><td >-</td><td >-</td><td >-</td><td style="background-color: #eee8aa;"></td></tr></table> ```python # # Saving a Picture # rsys2graph(rsys, 'pciture.png', save='.') # from IPython.display import Image; Image('picture.png') ``` # Arrhenius Kinetic model with 2 sets of products ```python from collections import defaultdict from itertools import chain import numpy as np import sympy as sp import matplotlib.pyplot as plt from ipywidgets import interact from chempy import Substance, Reaction, ReactionSystem from chempy.kinetics.rates import Arrhenius, MassAction from chempy.kinetics.ode import get_odesys from chempy.printing.numbers import number_to_scientific_latex from chempy.units import SI_base_registry, default_units as u sp.init_printing() %matplotlib inline ``` ```python A, B, C, D, E, F= map(Substance, 'ABCDEF') r1 = Reaction({'A'}, {'B','C'}, MassAction(Arrhenius(unique_keys=('A1', 'Ea_R_1')))) r2 = Reaction({'A'}, {'D','E'}, MassAction(Arrhenius(unique_keys=('A2', 'Ea_R_2')))) rsys = ReactionSystem([r1, r2]) rsys ``` <table class="chempy_ReactionSystem chempy_2333923987920"><tr><th style="text-align:center;" colspan="5"></th></tr><tr class="chempy_2333923987920_0"><td style="text-align:right;"><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td style="text-align:center;">&rarr;</td><td style="text-align:left;"><span class="chempy_B" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">B</span> + <span class="chempy_C" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">C</span></td><td style="text-align:left;">&nbsp;MassAction((Arrhenius((), ('A1', 'Ea_R_1')),))</td></tr> <tr class="chempy_2333923987920_1"><td style="text-align:right;"><span class="chempy_A" style="background-color:#ffb6c1; border: 1px solid #c71585; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">A</span></td><td style="text-align:center;">&rarr;</td><td style="text-align:left;"><span class="chempy_D" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">D</span> + <span class="chempy_E" style="background-color:#90ee90; border: 1px solid #008000; border-radius: 5pt; padding: 0pt 3pt 0pt 3pt;">E</span></td><td style="text-align:left;">&nbsp;MassAction((Arrhenius((), ('A2', 'Ea_R_2')),))</td></tr></table> ```python # Temperature is at 15 C just like the calibration # Activation energies and rates are arbitrary params = {'A1': 1e11/u.s, 'A2': 2e11/u.s, 'Ea_R_1': 8e3*u.K, 'Ea_R_2': 8.5e3*u.K, 'temperature': 288*u.K} c0 = defaultdict(lambda: 0*u.molar, {'A': 1*u.molar}) variables = c0.copy() variables.update(params) rsys.rates(variables) ``` {'C': array(0.08635041) * M/s, 'A': array(-0.11678104) * M/s, 'B': array(0.08635041) * M/s, 'E': array(0.03043063) * M/s, 'D': array(0.03043063) * M/s} ```python odesys, extra = get_odesys(rsys, include_params=False, lower_bounds=0) print(dict(zip(odesys.dep, odesys.names))) print(dict(zip(odesys.params, odesys.param_names))) odesys.exprs ``` ```python params2 = params.copy() pk = 'Ea_R_2' params2[pk] = [(320+273), (340+273), (360+273)]*u.K ``` ```python params2 ``` {'A1': array(1.e+11) * 1/s, 'A2': array(2.e+11) * 1/s, 'Ea_R_1': array(8000.) * K, 'Ea_R_2': array([593., 613., 633.]) * K, 'temperature': array(288.) * K} ```python params2[pk] ``` array([593., 613., 633.]) * K # Run time errors happen for 1 second or over for arrhenius model # Will need to fix ```python res2 = odesys.integrate(.001*u.s, c0, params2, integrator='cvode') # plotting at the 3 temperatures fig, axes = plt.subplots(1, len(res2), figsize=(14, 4)) for r, ax in zip(res2, axes): r.plot(ax=ax) ax.set_title('$%s = %s$' % (pk.replace('_', '\\_'), number_to_scientific_latex(r.named_param('Ea_R_2')))) ``` Using ipywidgets to get interactive controls: ```python def integrate_and_plot(T_C=25): res = odesys.integrate(7*u.s, c0, dict(params, temperature=(T_C+273.15)*u.K), integrator='cvode') res.plot() interact(integrate_and_plot) ``` interactive(children=(IntSlider(value=25, description='T_C', max=75, min=-25), Output()), _dom_classes=('widge… <function __main__.integrate_and_plot(T_C=25)> ```python ```
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Algebra.Signature module Fragment.Equational.Theory.Laws (Σ : Signature) where open import Fragment.Equational.Theory.Base using (Eq) open import Function using (_∘_) open import Data.Empty using (⊥) open import Data.Fin using (#_) open import Data.Sum using (inj₁; inj₂) open import Data.Product using (_,_) import Relation.Binary.PropositionalEquality as PE open import Fragment.Algebra.Free Σ open import Fragment.Algebra.Free.Syntax Σ (PE.setoid ⊥) module _ where private a = # 0 dne : ops Σ 1 → Eq Σ 1 dne ~ = ⟨ ~ ⟩₁ ⟨ ~ ⟩₁ ⟨ a ⟩ , ⟨ a ⟩ module _ (e : ops Σ 0) where private a = # 0 idₗ : ops Σ 2 → Eq Σ 1 idₗ • = ⟨ e ⟩₀ ⟨ • ⟩₂ ⟨ a ⟩ , ⟨ a ⟩ idᵣ : ops Σ 2 → Eq Σ 1 idᵣ • = ⟨ a ⟩ ⟨ • ⟩₂ ⟨ e ⟩₀ , ⟨ a ⟩ anₗ : ops Σ 2 → Eq Σ 1 anₗ • = ⟨ e ⟩₀ ⟨ • ⟩₂ ⟨ a ⟩ , ⟨ e ⟩₀ anᵣ : ops Σ 2 → Eq Σ 1 anᵣ • = ⟨ a ⟩ ⟨ • ⟩₂ ⟨ e ⟩₀ , ⟨ e ⟩₀ invₗ : ops Σ 1 → ops Σ 2 → Eq Σ 1 invₗ ~ • = (⟨ ~ ⟩₁ ⟨ a ⟩) ⟨ • ⟩₂ ⟨ a ⟩ , ⟨ e ⟩₀ invᵣ : ops Σ 1 → ops Σ 2 → Eq Σ 1 invᵣ ~ • = ⟨ a ⟩ ⟨ • ⟩₂ (⟨ ~ ⟩₁ ⟨ a ⟩) , ⟨ e ⟩₀ module _ where private a = # 0 b = # 1 c = # 2 hom : ops Σ 1 → ∀ {n} → ops Σ n → Eq Σ n hom h {n} f = ⟨ h ⟩₁ term f (map ⟨_⟩ (allFin n)) , term f (map (⟨ h ⟩₁_ ∘ ⟨_⟩) (allFin n)) where open import Data.Vec using (map; allFin) comm : ops Σ 2 → Eq Σ 2 comm • = ⟨ a ⟩ ⟨ • ⟩₂ ⟨ b ⟩ , ⟨ b ⟩ ⟨ • ⟩₂ ⟨ a ⟩ assoc : ops Σ 2 → Eq Σ 3 assoc • = (⟨ a ⟩ ⟨ • ⟩₂ ⟨ b ⟩) ⟨ • ⟩₂ ⟨ c ⟩ , ⟨ a ⟩ ⟨ • ⟩₂ (⟨ b ⟩ ⟨ • ⟩₂ ⟨ c ⟩)
\documentclass[10pt]{article} \pdfoutput=1 \usepackage[ruled,vlined]{algorithm2e} \usepackage{multirow} \usepackage{hyperref} \usepackage{graphicx} \title{Structural representations of DNA regulatory substrates can enhance sequence-based algorithms by associating functional sequence variants} \author{ Jan Zrimec \\ Chalmers University of Technology\\ Gothenburg, Sweden \\ \texttt{[email protected]} \\ } \date{13 June 2020} \begin{document} \maketitle \begin{abstract} The nucleotide sequence representation of DNA can be inadequate for resolving protein-DNA binding sites and regulatory substrates, such as those involved in gene expression and horizontal gene transfer. Considering that sequence-like representations are algorithmically very useful, here we fused over 60 currently available DNA physicochemical and conformational variables into compact structural representations that can encode single DNA binding sites to whole regulatory regions. We find that the main structural components reflect key properties of protein-DNA interactions and can be condensed to the amount of information found in a single nucleotide position. The most accurate structural representations compress functional DNA sequence variants by 30\% to 50\%, as each instance encodes from tens to thousands of sequences. We show that a structural distance function discriminates among groups of DNA substrates more accurately than nucleotide sequence-based metrics. As this opens up a variety of implementation possibilities, we develop and test a distance-based alignment algorithm, demonstrating the potential of using the structural representations to enhance sequence-based algorithms. Due to the bias of most current bioinformatic methods to nucleotide sequence representations, it is possible that considerable performance increases might still be achievable with such solutions. \end{abstract} % % Keywords. % \keywords{Bioinformatic algorithms, DNA structural properties, Transcriptional regulation, Horizontal gene transfer} \section{Introduction} Besides the popular yet simplistic representation of DNA as a polymer chain of 4 different nucleotide bases A, C, G and T, the molecule in its double stranded dsDNA form possesses certain conformational and physicochemical properties. These are especially important in relation to interactions of the DNA with proteins, which drive many essential cellular processes \cite{Rohs2009-hm,Zrimec2015-xf,Zrimec2018-lx}. These include but are not limited to transcription \cite{Rohs2009-hm}, replication \cite{Chen2012-gd} as well as horizontal gene transfer (HGT) \cite{Zrimec2018-lx,Zrimec2020-wx}. The processes are commonly initiated and regulated at specific DNA regulatory regions, which are the substrates for protein binding and enzymatic activity, and include promoters \cite{Watson2008-dt}, origins of replication \cite{Chen2012-gd} and origins of transfer (transfer regions, plasmid conjugation in HGT) \cite{De_La_Cruz2010-xj}. The DNA substrates contain either one or multiple protein binding sites, such as for instance transcription factor binding sites (TFBS) in promoters, as well as additional sequence and structure context that is related to protein-DNA recognition and binding preceding the main enzymatic processing \cite{Levo2015-iu,Marcovitz2013-kg,Zrimec2018-lx}. As such, the nucleotide sequence representation is often not sufficiently detailed for discriminating DNA regulatory substrates, as it encodes specific conserved structural properties that are not directly obvious from the mere sequence context (Table 1) \cite{Zrimec2018-lx,Tosato2017-nq,Slattery2014-ne}. To uncover the encoded structural properties, many DNA structure models and prediction tools have been developed, including (i) DNA thermodynamic stability and its potential for destabilization and melting bubble formation, modelled with the nearest neighbor (NN) framework \cite{SantaLucia1998-hc} and thermally induced duplex destabilization \cite{Zrimec2015-xf}, (ii) DNA major and minor groove properties that describe their size and thus accessibility by proteins, which are the focus of the DNAshape and ORChID2 models \cite{Bishop2011-jm,Chiu2016-kb} among others, (iii) DNA intrinsic curvature and flexibility, modeled by measuring DNAzeI digestion profiles \cite{Brukner1995-pt} and DNA persistence lengths \cite{Geggier2010-mw}, (vi) DNA twisting and supercoiling, captured by multiple DNA conformational models and variables \cite{Karas1996-qz,Olson1998-rw,Perez2004-sx}, (v) differences in DNA spacing and orientation between binding and enzymatic sites, described for instance by DNA helical repeats \cite{Geggier2010-mw}, and (vi) the propensity for transitions between DNA forms, such as from B-DNA to A-DNA or to Z-DNA given with respective variables \cite{Aida1988-iq,Hartmann1989-ji,Kulkarni2013-xm,Ho1986-hg}. However, due to the large variety and differences among the DNA structural models and variables, it is not simple to choose among them or integrate them within existing DNA bioinformatic frameworks. Current studies thus focus on specific groups of DNA structural properties and do not span the whole possible structural repertoire \cite{Chiu2016-kb,Zrimec2018-lx,Zrimec2013-ds,Samee2019-xj,Bansal2014-ko,Chen2012-gd}. A common DNA structural representation could thus help circumvent these problems and facilitate the development of novel, improved DNA algorithms. \begin{table*} \footnotesize \caption{Overview of DNA structural properties and representative variables in protein-DNA interaction.} \begin{tabular}{p{3cm}|p{3cm}|p{3cm}|p{1cm}} \hline DNA structural properties & Facilitated protein-DNA interactions & Representative structural variables & References\\ %\hline DNA stability, destabilizations and melting bubble formation & Enzymatic processing of substrates, e.g. nicking of transfer regions, leads to secondary structure formation & Duplex stability, Thermally induced duplex destabilization (TIDD) & \cite{SantaLucia1998-hc,Lucas2010-gi,Zrimec2015-xf,Sut2009-kg}\\ \hline Major and minor groove properties & Readout of chemical information, e.g. TFs in promoters & DNAShape, ORChID2 & \cite{Rohs2009-hm,Chiu2016-kb,Bishop2011-jm,Watson2008-dt}\\ \hline Intrinsically curved or flexible regions & Binding and topological changes, e.g. IHF binding in promoters & DNAzeI cleavage frequency, Persistence length & \cite{Brukner1995-pt,Geggier2010-mw,Moncalian1999-qj}\\ \hline DNA twist and supercoiling & Topological changes recognized by proteins, e.g. histones, and affect other properties & Twist and other conformational variables & \cite{Karas1996-qz,Olson1998-rw,Perez2004-sx,Watson2008-dt}\\ \hline Differences in DNA spacing and orientation in binding and enzymatic sites & Affect binding with multiple contact points and protein complex formation & Helical repeats & \cite{Williams2007-be,Geggier2010-mw,Watson2008-dt}\\ \hline Propensity for transitions between DNA forms B-DNA, A-DNA, Z-DNA & Affect overall features recognized by proteins and their accessibility & B-A and B-Z transition propensities & \cite{Aida1988-iq,Ho1986-hg,Hartmann1989-ji,Kulkarni2013-xm}\\ \hline \end{tabular} \end{table*} Hence, the aim of the present study was to analyse and engineer novel DNA structural representations for use with bioinformatic frameworks, such as sequence alignment and motif finding algorithms, and to compare them with the standard nucleotide sequence-based methods. First, based on DNA physicochemical and conformational properties that are involved in DNA-protein interactions and using dimensionality reduction techniques we constructed different structural DNA representations. To explore the smallest amount of structural information that could sufficiently describe functional DNA regions we compressed the DNA representations using clustering algorithms to encompass from an estimated 2 to 8 bits of information. Next, we explored the capability of each representation to encode multiple DNA sequence variants using TFBS motif datasets. To facilitate the usefulness of the representations with existing DNA algorithms via comparison of the (dis)similarity of encoded sequences, we developed a structural distance function and tested it on datasets of transfer and promoter regions. Finally, we explored the applicability of the structural representations within a sequence alignment framework and discussed ideas for hybrid sequence and structure-based approaches specifically for analysing regulatory DNA substrates. \section{Methods} \subsection{Datasets} We obtained 64 published DNA structure models that were shown to be informative for analysis of DNA-protein interactions \cite{Zrimec2020-wx} (Table 1). These models were based on nearest neighbor dinucleotide (56), trinucleotide (4) and pentanucleotide (4) models and included physicochemical and conformational properties and properties attributed to DNA-protein interactions. Of these, 44 models were derived experimentally and the rest computationally based on experimental data. The set included the widely used models DNA shape \cite{Rohs2009-hm,Chiu2016-kb}, Orchid \cite{Bishop2011-jm}, DNA stability and thermally induced duplex destabilization \cite{SantaLucia1998-hc,Zrimec2015-xf}. A dataset of transcription factor binding site (TFBS) motifs was obtained from the Jaspar database \cite{Khan2018-wj} (sites file) and filtered to contain only sequences with \{A,C,G,T\} characters, of equal length as the median length in each motif group but at least 9 bp long and containing at least 10 motif sequence variants. A published dataset of transfer regions from 4 mobility (Mob) groups \cite{Zrimec2018-lx} was used as positive examples and expanded with 64 negative examples. Negative example sequences were selected randomly from a region 200 to 800 bp around the enzymatic nicking sites \cite{Zrimec2018-lx}, thus containing different non-regulatory coding and non-coding regions, and low sequence similarity was verified among the sequences (p-distance \textgreater{} 0.6). The part of the transfer regions with relevant protein binding features from -140 bp to +80 bp according to the nicking site was used \cite{Zrimec2018-lx}. For testing the alignment algorithm, a second published dataset of 112 transfer regions (queries) of equal length as the ones above and 52 plasmids (targets) \cite{Zrimec2020-wx} from 4 Mob groups was used. A dataset of Escherichia coli promoter regions was obtained \cite{Gusmao2014-hp} with 100 bp positive and negative examples (positive, mixed1 and control). We randomly sampled 200 sequences from each dataset to create a 600 element dataset. The second dataset of Escherichia coli promoter regions was obtained from Regulon DB v9 \cite{Gama-Castro2016-so} and contained only 81 bp positive examples grouped according to 6 sigma factors \cite{Watson2008-dt}. A random sampling of 94 sequences (size of smallest group) from each group yielded a dataset with 564 elements. \subsection{Construction and analysis of DNA structural representations} To develop DNA structural representations we computed the structural properties of all permutations of k-mers 3, 5, 7 and 9 bp in length (1 to 4 neighboring regions around a specific nucleotide) and performed dimensionality reduction followed by clustering (Fig. 1A). The structurally defined groups of k-mers were termed s-mers. Structural properties were calculated in windows of 5 bp or at default values as described \cite{Zrimec2015-xf,Zrimec2018-lx}. Dimensionality reduction and analysis of the main components of variance was performed using Principal Component Analysis (PCA). The k-means clustering algorithm was used (Matlab), where clusters with a lowest total sum of distances were chosen from 10 runs of up to 1000 iterations at default settings. The optimal amount of clusters was analysed with the Elbow, average Silhouette \cite{Rousseeuw1987-mx} and GAP \cite{Tibshirani2001-wq} methods with Matlab function evalclusters at default settings with triplicate runs. The tested numbers of clusters included 4, 8, 16, 32, 64, 128 and 256 clusters, chosen considering that (i) positions with $2^x$ possible states (clusters) can carry a maximum of x bits of information \cite{Schneider1986-iv}, (ii) 1 bp of DNA carries up to 2 bits of information (iii) up to 4 bp neighboring regions defined the structural effect in the s-mers, and (iv) s-mers are overlapping, meaning information is distributed among all of them. Thus, up to 8 bits of information (256 clusters) was expected per s-mer (and less with decreasing s-mer size). \begin{figure}[ht] \centering \includegraphics[width=7.5cm,keepaspectratio]{smir_fig_smers.png} \caption{Schematic depiction of the (A) construction and (B) usage of structural representations. In a structural representation of a given DNA sequence, each central nucleotide position and its neighboring regions define a k-mer from 3 to 9 bp in length, and are encoded as an s-mer with n structural dimensions (S. dim.) that can be defined as a sequence of s-mer cluster centroids.} \end{figure} For a DNA substrate, the length of the structural representation was equal to the length of the nucleotide sequence minus the leftover nucleotides at the borders equal to $(s-1)/2$, due to the neighboring nucleotides in s-mers (Fig. 1B). The s-distance between two DNA substrates was the sum of squared Euclidean distances between the cluster centroids of all equally positioned s-mers in their structural representations of length \textit{n}, \begin{equation} s-distance=\sum_{i=1}^{n}d(C_{1i}, C_{2i})^2, \end{equation} where \(C_{1i} = (c_{11}, c_{12},..., c_{1k})\) is the cluster centroid of the s-mer at position \textit{i} of the first sequence and \(C_{2i} = (c_{21}, c_{22},..., c_{2k})\) is the cluster centroid of s-mer at position \textit{i} of the second sequence. \subsection{Statistical analysis and performance metrics} For statistical hypothesis testing, the Python package Scipy v1.1.0 was used with default settings. To evaluate the explained variation, the coefficient of determination was defined as \begin{equation} R^2=1-\frac{SS_{Residual}}{SS_{Total}}, \end{equation} where \(SS_{Residual}\) is the within group residual sum of squares and \(SS_{Total}\) is the total sum of squares. The compression ratio was calculated as \begin{equation} Compression\: ratio = \frac{\textrm{Num. unique k-mers}}{\textrm{Num. unique s-mers}}. \end{equation} Precision and recall were defined as \begin{equation} Precision = \frac{TP}{TP+FP}, \end{equation} \begin{equation} Recall = \frac{TP}{TP+FN}, \end{equation} where \textit{TP}, \textit{FP} and \textit{FN} denote the number of true positive, false positive and false negative elements, respectively. The $F_1$-score was defined as \begin{equation} F_1-score = \frac{2\cdot precision\cdot recall}{precision+recall}. \end{equation} The \textit{F}-test was performed using permutational multivariate analysis of variance with sequence bootstraps \cite{Anderson2001-zz,Zrimec2018-lx}. The distribution of the \textit{F} function under the null hypothesis of no differences among group means was evaluated by performing 1e4 bootstrap repetitions, with \textit{p}-values calculated as \begin{equation} p = \frac{\textrm{Num. }F_{Bootstrap}\geq F}{\textrm{Total num. }F_{Bootstrap}}. \end{equation} \subsection{Alignment algorithm} We developed and tested a simple ungapped DNA sequence alignment framework (Algorithm 1) that finds the most similar segments to query sequences in target sequences using a given distance function. The assessment of algorithm performance included (i) locating the transfer regions to within +/- 1 bp of their known locations in the target plasmids and (ii) correct typing of Mob groups in the target plasmids. For this, true and false positive and negative counts were obtained from the alignment tests by considering only the lowest scoring hit per alignment. A true or false positive value was assigned if the result was below a specified significance cutoff and corresponded or did not correspond, respectively, to the known value (region location or Mob group), and alternatively, a false or true negative value was assigned to results above the significance cutoff that corresponded or did not correspond, respectively, to the known value. The statistical significance of distance scores (at \textit{p}-value cutoffs from 1e-6 to 1e-1) was evaluated using bootstrap permutations (\textit{n} = 1e6 per sequence) of 10 randomly selected query sequences (Eq. 7) and a mapping function between the distance scores and \textit{p}-values was then obtained by least squares curve fitting (Matlab) to a second order polynomial function (distance score of 0 corresponded to the theoretical limit of ~1e-132) \cite{Zrimec2020-wx}. \begin{algorithm} \footnotesize \SetAlgoLined \textbf{input} query\_set, target\_set\; \For{i = 1 : size(query\_set)}{ \For{j = 1 : size(target\_set)}{ \For{k = 1 : length(target\_set(j))}{ dist(i,j,k) = distance(query\_set(i),target\_set(j)(k))\; } } } \textbf{return} min(dist(:,:)). \caption{Sequence alignment algorithm.} \end{algorithm} \subsection{Software} Matlab v2017 (www.mathworks.com), Python v3.6 (www.python.org) and R v3.5 (www.r-project.org) were used. The code is available at \url{https://www.github.com/JanZrimec/smer\_acm\_bcb\_20}. \section{Results} \subsection{Fusion of DNA structural properties into a compact representation encapsulates main protein-DNA binding features} Considering that the first 4 neighboring nucleotides have the largest effect on the structural state of a given nucleotide base pair \cite{Zrimec2015-xf,Peyrard2009-as}, we designed nucleotide-position specific DNA structural representations that included the effects of 1 to 4 neighboring nucleotides, termed s-mers (Table 2: sizes 3, 5, 7 and 9 bp, Fig. 1). The s-mers were based on calculating up to 64 of the most widely used DNA structural properties for all permutations of the corresponding equally sized k-mers (Table 2, Methods M1), followed by dimensionality reduction and clustering (Fig. 1A, Methods M2). The calculated DNA structural properties included physicochemical, conformational and protein-DNA binding variables of experimental origin \cite{Zrimec2020-wx} (Table 1). Dimensionality reduction with Principal Component Analysis (PCA) yielded a specific number of principal components (PC) with each s-mer size \textit{s} that explained over 99\% of the data variance (Fig. 2). The amount of PCs increased with the s-mer size and with the number of initial structural variables from 14 to 18 PCs, which was an over 3.5-fold decrease in the amount of variables required to describe almost all of the original information (Table 2). On average, 3, 6, 9 and 17 components were required to explain over 60, 80, 90, and 99\% of the variance, respectively. The coefficient of variation (\(\sigma/\mu\)) of the first 6 most informative PCs across the s-mer sizes was below 0.637 and lowest with the first and sixth components with 0.160 and 0.466, respectively, showing that these PCs carried similar structural information with each \textit{s}. Analysis of PCA loadings showed that each PC mainly comprised a number of distinct structural variables, which enabled us to determine the key protein-DNA binding features defined by the 6 most informative components (in the order of decreasing importance): thermodynamic stability \cite{SantaLucia1998-hc,Protozanova2004-xc}, horizontal flexibility \cite{Olson1998-rw,Brukner1995-pt,Bolshoy1991-ux,Gorin1995-es,Karas1996-qz,Chiu2016-kb}, torsional flexibility \cite{Perez2004-sx,Kabsch1982-tv,Olson1998-rw,Karas1996-qz}, conformational stability \cite{SantaLucia1998-hc,Aida1988-iq,Perez2004-sx,Packer2000-ri,Geggier2010-mw}, major and minor groove accessibility \cite{Protozanova2004-xc,Kabsch1982-tv,Gorin1995-es,Olson1998-rw} and A-DNA to B-DNA transition potential \cite{Aida1988-iq,Perez2004-sx,Gorin1995-es,Karas1996-qz}. Moreover, the top 20 sorted structural variables contained 3 of the well known DNAshape functions \cite{Chiu2016-kb,Rohs2009-hm} and ORChID2 \cite{Bishop2011-jm}, with nucleosome positioning (phase) \cite{Satchwell1986-me} being the most important. \begin{table*} \footnotesize \caption{Summary of s-mer construction. The groups of s-mers comprised all permutations of nucleotide k-mers of 3 to 9 bps in length. Due to sequence length constraints, not all DNA structural models could be computed with all s-mers. The amount of structural models used is given under 'Structures'. The given amount of principal components (PC) describing over 99\% of the variance of the data was chosen to define each structural representation.} \begin{tabular}{p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{2cm}} \hline S-mer size \textit{s} & Neighbors & Permut. & Structures & PC \textgreater{} 0.99 & Number of clusters \textit{k}\\ \hline 3 & 1 & 64 & 57 & 14 & 2\string^2 to 2\string^6\\ 5 & 2 & 1024 & 62 & 17 & 2\string^2 to 2\string^8\\ 7 & 3 & 16384 & 64 & 18 & 2\string^2 to 2\string^8\\ 9 & 4 & 262144 & 64 & 18 & 2\string^2 to 2\string^8\\ \hline \end{tabular} \end{table*} \begin{figure}[ht] \centering \includegraphics[width=7.5cm,keepaspectratio]{smer_fig_scatter.png} \caption{The first two dimensions (principal components, PC) of the structural representation with s-mer size \textit{s} = 5 and number of clusters \textit{k} = 16, where each point represents a different 5-mer nucleotide permutation \{AAAAA, AAAAC, …,TTTTT\}, colors depict the clusters and black points denote the cluster centroids.} \end{figure} Although the dimensionality reduced structural data was not expected to form strong clusters, we considered that a limit must exist to the resolution of the structural representations, above which there is no measurable influence on the achievable computational accuracy. Additionally, we wanted to achieve an additional level of compactness of the DNA codes as well as test the clustering of the structural data points. Clustering was performed with the number of clusters \textit{k} varied between 4 and 256 clusters (2 to 8 bits), with the exception of using up to 32 clusters with 3-mers (Table 2, Methods M2). Standard cluster evaluation methods, including Elbow and Silhouette \cite{Rousseeuw1987-mx}, showed that with a decreasing \textit{k}, the overall accuracy of the clustered data representations decreased compared to using a higher number of clusters. At the highest \textit{k} (256), the explained variance ($R^2$) was over 80\% with both s-mer sizes 5 and 7 (\textit{s} = 9 not fully tested due to memory restrictions). With a decreasing number of clusters, progressively larger clusters were obtained (Fig. 3) with a decrease in the percentage of explained variance down to ~40\% with \textit{k} = 4 clusters, and similarly a decrease in the average Silhouette ratio. The cluster sizes were approximately normally distributed (Fig. 3), with the variation of cluster sizes increasing with an increasing \textit{k}, although the coefficient of variation did not surpass 0.52. \begin{figure}[ht] \centering \includegraphics[width=7.5cm,keepaspectratio]{smer_fig_cluster_distribution.png} \caption{The distributions of cluster sizes across the structural representations with different s-mer sizes \textit{s} and number of clusters \textit{k}.} \end{figure} \subsection{Structural representations encode groups of functional sequence variants with conserved properties} We next explored whether the s-mers could encode groups of conserved functional DNA motifs \cite{Levo2015-iu}, and if our structural DNA representations could more compactly but also more accurately encapsulate DNA motifs than bare k-mers. We used a dataset of 595 Jaspar \cite{Khan2018-wj} transcription factor binding site (TFBS) motifs comprising 1,296,654 unique DNA sequences from multiple model organisms (Methods M1), which contained at least 10 motifs in each group and were at least 9 bp long. To test the capacity of the structural representations to encode TFBS motifs we first measured the \textit{compression ratio} (Eq. 3), which was the ratio of the amount of unique s-mers versus the amount of unique k-mers observed with a given TFBS motif. As a note, due to computational complexity and memory limitations, only certain parameter combinations could be tested. We observed an increase in the average \textit{compression ratio} across motifs with an increasing s-mer size (Fig. 4), as it increased from 1.132 with \textit{s} = 5 (\textit{k} = 256) to 1.296 with \textit{s} = 9 (\textit{k} = 256). Similarly and as expected, the average compression ratio increased with decreasing amount of clusters (Fig. 4), from 1.132 with \textit{k} = 256 (\textit{s} = 5) to 3.152 with \textit{k} = 4 (\textit{s} = 3). The variation of the compression ratio across the different motifs was approximately constant (SD between 0.056 with \textit{s} = 3, \textit{k} = 4 and 0.092 with \textit{s} = 7, \textit{k} = 128). Moreover, we measured a significant negative correlation (Pearson's \textit{r}, \textit{p}-value \textless{} 4.7e-5) between the \textit{compression ratio} and the TFBS sequence length increasing from -0.166 to -0.667 with an increasing s-mer size \textit{s} = 3 (\textit{k} = 32) to \textit{s} = 9 (\textit{k} = 128), respectively, and up to -0.724 with a decreasing cluster size \textit{k} (s = 3, k = 4). Weak correlation (Pearson's \textit{r}, \textit{p}-value \textless{} 0.026) was also observed between the \textit{compression ratio} and the number of unique sequences in a TFBS motif, similarly as above increasing from -0.091 to -0.311 with an increasing \textit{s} = 3 (\textit{k} = 32) to \textit{s} = 9 (\textit{k} = 128), respectively, and up to -0.382 with a decreasing \textit{k} (\textit{s} = 3, \textit{k} = 4). This suggested that the capacity for compression decreases with more abundant DNA sequence space, such as with longer motifs or ones with a more diverse set of sequence variants. \begin{figure}[ht] \centering \includegraphics[width=7.5cm,keepaspectratio]{smer_fig_compression.png} \caption{Compression ratios of Jaspar TFBS motifs obtained with different structural representations. Due to computation and memory limitations only certain parameter combinations of s-mer size \textit{s} and number of clusters \textit{k} were analysed. The black line denotes no compression.} \end{figure} Since the structural representations indeed compressed the TFBS motifs up to 3-fold, we next explored how accurate the encodings were at describing different functional motif variants. We selected the most sequence-abundant motif, the 18 bp Human MAFF motif (Jaspar: MA0495.1, class of Basic leucine zipper factors) that contained 49,462 unique sequence variants. Using a randomly selected 1\% (\textit{n} = 495) subset of these sequence variants to define their s-mers, we measured how many of the remaining 99\% of the motifs were described by (or rather, could be predicted from) these structural encodings. This meant reconstructing all the possible motif sequence variants from each structural representation instance, and gave an estimate of the encoding accuracy. The initial \textit{precision} and \textit{recall} (Methods M3) obtained without any encoding were 1 and 0.01, respectively. Unsurprisingly, an inverse relation was observed between \textit{precision} and \textit{recall} (Fig. 5). \textit{Precision} was highest (0.838) with a low s-mer size (\textit{s} = 3, \textit{k} = 32) and decreased 6.5-fold with an increasing \textit{s} (0.129, \textit{s} = 9, \textit{k} = 256), whereas \textit{recall} increased by 9\% from 0.0102 to 0.0111 at the equal parameter values, respectively. A reason for the decrease in \textit{precision} was likely that the average amount of distinct sequence variants encapsulated by the different structural representations increased with an increasing s-mer size as well as with a decreasing \textit{k} (Fig. 6). This related to an increasing coverage of the correct TFBS motifs (true positives) as well as an increasing number of variants not in the given TFBS sequence set (false positives). However, it is also possible that the TFBS sequence set is incomplete and does not contain all the possible functional sequence variants of that motif, meaning that the true positive and negative space is unknown. With an 18 bp DNA sequence, such as is the length of the MAFF motif, we estimated that up to 6.9e10 sequence variants could exist, whereas the set of sequence variants in the TFBS represented merely 7.2e-7 of this diversity and was likely undersampled. This suggested that for further analysis, datasets with a more complete coverage of the functional sequence space should be used. \begin{figure}[ht] \centering \includegraphics[width=7.5cm,keepaspectratio]{smer_fig_prc.png} \caption{Precision versus recall when comparing an encoding of 1\% of sequence variants of the Human MAFF motif (Jaspar: MA0495.1) with the remaining 99\% of sequence variants, at different structural representation parameters s-mer size \textit{s} and number of clusters \textit{k}. The precision and recall obtained with nucleotide k-mers were 1 and 0.01, respectively.} \end{figure} \begin{figure}[ht] \centering \includegraphics[width=7.5cm,keepaspectratio]{smer_fig_variants.png} \caption{Amount of unique DNA sequence variants encoded by structural representations of the 18 bp long Human MAFF motif (Jaspar: MA0495.1), results with 1\% (\textit{n} = 100) of motif variants shown.} \end{figure} \subsection{A structure-based distance function resolves regulatory DNA more accurately than sequence-based ones} To facilitate the comparison of two different structural representations (Fig. 1: s-mer vectors), such as is done with nucleotide sequences using for instance the p-distance (equal to the Hamming distance corrected for sequence length), we defined a structural distance, termed s-distance, as the sum of squared Euclidean distances between s-mer cluster centroids of two representations (Eq. 1). To test the s-distance and compare it to the p-distance, we used a dataset of whole DNA regulatory regions that control the initiation of DNA transfer in plasmid conjugation (origin-of-transfer regions) \cite{De_La_Cruz2010-xj} (Methods 1). These transfer regions are 220 bp long and comprise binding sites for the relaxase as well as those for accessory proteins that regulate transfer. The dataset contained 64 unique transfer sequences \cite{Zrimec2018-lx} from 4 distinct mobility groups (Mob, defined by amino acid homology of the main transfer enzyme relaxase) \cite{Garcillan-Barcia2009-yk}, with approximately equal group sizes of 16 elements. We previously determined that the Mob groups of these regions could be clearly discriminated based on 6 DNA physicochemical and conformational properties \cite{Zrimec2018-lx}. In order to additionally test the possibility of discriminating between functional and non-functional transfer sequences, here we expanded the dataset to include, besides the positive sequences (Pos) also an equal amount negative counterparts (Neg, Methods M1). Using the specific distance functions as the measure of variation across the data within a permutational MANOVA framework (bootstrap \textit{n} = 1e4, Methods M3) \cite{Anderson2005-pu}, we observed significant (\textit{p}-value \(\leq\) 1e-4) discrimination of both the positive/negative examples as well as MOB groups with the s-distance, which was not the case with the p-distance (Table 3). On average, when discriminating positive/negative examples and MOB groups with the s-distance, the amount of explained variance (R2, Eq. 2) increased 3-fold and 2.2-fold, respectively, compared to using the p-distance (Table 3). Additionally, using two datasets of Escherichia coli promoter regions, one with positive and negative examples \cite{Gusmao2014-hp} and the other grouped according to 6 most prevalent sigma factors \cite{Gama-Castro2016-so} (Methods M1), we verified the above results, as significant (\textit{p}-value \textless{} 0.05) group discrimination could be achieved with structural representations and not with the p-distance. \begin{table*} \footnotesize \caption{Comparison of distance functions based on nucleotide sequence (p-distance) and structural representations (s-distance). $F_1$-scores were obtained with the alignment algorithm (Algorithm 1).} \begin{tabular}{p{1.5cm}|p{1.1cm}|p{1.1cm}|p{1cm}|p{1.1cm}|p{1cm}|p{1.1cm}|p{1cm}} \hline \multirow{2}{*}{Func.} & \multirow{2}{*}{Params.} & \multicolumn{2}{c}{\textit{$R^2$}} & \multicolumn{2}{c}{ANOVA \textit{p}-value} & \multicolumn{2}{c}{$F_1$-score} \\ \cline{3-8} & & Pos/Neg & Mob & Pos/Neg & Mob& Pos/Neg & Mob \\ \hline p-distance & / & 0.017 & 0.113 & 0.472 & 0.473 & 0.892 & 0.834\\ s-distance & \textit{s} = 3, \textit{k} = 32 & 0.046 & 0.237 & \textless{} 1e-4 & \textless{} 1e-4 & 0.955 & 0.853\\ & \textit{s} = 5, \textit{k} = 128 & 0.049 & 0.248 & \textless{} 1e-4 & \textless{} 1e-4 & 0.942 & 0.923\\ & \textit{s} = 7, \textit{k} = 128 & 0.054 & 0.253 & 1e-4 & \textless{} 1e-4 & 0.970 & 0.923\\ & \textit{s} = 9, \textit{k} = 128 & 0.057 & 0.264 & 1e-4 & \textless{} 1e-4 & 0.954 & 0.879\\ \hline \end{tabular} \end{table*} Furthermore, to determine how the amount of encoded sequence variants scales with the length of the sequence, we computed the amount of sequence variants encoded by structural representations of the 220 bp transfer regions, by randomly selecting 10 transfer regions (Fig. 7). Compared to the 18 bp TFBS motifs, structural representations of the 220 bp transfer regions encoded, on average, an over 32-fold higher number of sequence variants (Fig. 7). \begin{figure}[ht] \centering \includegraphics[width=7.5cm,keepaspectratio]{smer_fig_variants_orit.png} \caption{Amount of unique DNA sequence variants encoded by structural representations of 220 bp long plasmid transfer regions, results with 10 region variants shown.} \end{figure} \subsection{DNA sequence-based algorithms can be enhanced with structural representations} We tested whether the structural representations and s-distance could be applied to existing algorithm frameworks, such as DNA sequence alignment. The DNA alignment framework that we developed (Algorithm 1) enabled the use of different metrics such as the s-distance and could align a query and a target sequence based on finding the minimal distance between them. Since equal sized groups were no longer required, we used an expanded dataset of 112 distinct transfer regions as the query dataset and a target dataset of 52 plasmids with known locations of the transfer regions as well as their Mob groups \cite{Zrimec2020-wx} (Methods M1). By counting the amount of lowest-distance alignments in the target dataset that were below a specified distance threshold, we could define similar metrics as for a binary classification problem, namely amounts of true and false positive and negative results (Methods M4) as well as the harmonic mean of precision and recall, the $F_1$-score (Eq. 6). Although both distance functions proved accurate, we observed, on average, an over 7\% improvement of the $F_1$-score with the s-distance compared to the p-distance, both when discriminating functional regions (Pos/Neg) as well as the Mob groups (\textit{p}-value \textless{} 1e-13, Table 3). The s-distance based algorithm (at \textit{s} = 7, \textit{k} = 128) thus correctly uncovered 32 (62\%) transfer regions in the target set with 30 of them (58\%) correctly Mob typed, compared to 29 (56\%) and 26 (50\%) with the sequence based p-distance, respectively. This suggested that existing DNA sequence-based algorithms could indeed be enhanced with structural representations \cite{Marcovitz2013-kg,Levo2015-iu,Slattery2014-ne,Rohs2009-hm} (Fig. 8). \begin{figure}[ht] \centering \includegraphics[width=6cm,keepaspectratio]{smir_fig_algorithms.png} \caption{Possibilities for combined sequence structure algorithms based on how proteins recognize and bind their active sites in the regulatory DNA. Interactions of lower specificity with the surrounding DNA (corresponding to DNA with less conserved nucleotide sequence but defined structural properties) guide the proteins towards their specific binding sites (highly conserved or exact sequence).} \end{figure} \section{Discussion} Here we used a number of functionally-relevant DNA physicochemical and conformational properties (Table 2: 57 to 64 structural variables) and fused them into compact DNA structural representations containing the most important structural information (e.g. 6 components carried over 80\% of the initial data variance). Recovery of the key distinguishing properties of the first 6 structural components showed that they indeed reflected the main properties involved in protein-DNA interactions (Table 1). The amount of structural information could be further refined with clustering down to 2 bits (Fig. 3), where the compression ratio of functional DNA sequence motifs could be as high as 3:1 (Fig. 4). Nevertheless, the most promising results were obtained with a number of clusters corresponding to 6 to 8 bits of information (64 to 256 clusters, Fig. 5). These structural representations could compress functional sequence variants by around 30\% to 50\%, where each instance of the structural representation encapsulated up to ~20 sequence variants of a TFBS motif (Fig. 6) and up to ~2000 variants of a whole DNA regulatory region (Fig. 7). Further testing is required, however, using datasets with a more complete coverage of the functional sequence space or experimentally, to properly investigate the capacity to encode groups of functional DNA sequence variants and their conserved functional properties. Devising the s-distance function opens up a plethora of possibilities for testing the structural codes and implementing them into DNA algorithms, as it was found to resolve regulatory DNA more accurately than sequence-based metrics \cite{Zrimec2020-wx,Zrimec2018-lx} (Table 3). One can also think of additional metrics that can prove useful, such as for instance a Jaccard distance using s-mers instead of k-mers \cite{Zrimec2020-wx}, that can distinguish coding and non-coding sequences across genomes or help bin species in metagenomic data. Furthermore, by developing and testing a distance-based alignment algorithm (Algorithm 1), we demonstrated the potential of the structural representations to enhance existing sequence-based algorithms. Here, the usefulness of sequence-like codes (similar to the nucleotide code ACGT) stood out, as the structural representations could be realized as mere sequences of cluster indices with precomputed pairwise distances, abstracting from, and altogether disposing of, the structural component space. This can simplify their implementation in existing sequence-based algorithms and also improves the accuracy of pinpointing enzymatic sites, such as nicking sites in transfer regions, down to a resolution of 1 bp \cite{Zrimec2020-wx}. Accordingly, the solution can uncover many new variants of transfer regions in natural plasmids, helping researchers investigate the potential for plasmid mobility and its global effects \cite{Zrimec2020-wx}. The use of whole sets of structural variables is more frequently found in the domain of machine learning (ML), where ML models trained on specific sets of target variables then learn to use only specific subsets of the structural features \cite{Zrimec2015-xf,Zrimec2018-lx,Zrimec2013-ds}. For instance, when training ML models for discriminating Pos/Neg examples or MOB groups (Table 3), different variables at different locations were found to be most informative \cite{Zrimec2018-lx}. Although this leads to efficient discriminative or predictive models for specific tasks, DNA sequence analysis frequently requires generalizing across multiple tasks and using all of the features (e.g. alignment). Indeed, we have found that sequence based models of structural properties outperform ML models \cite{Zrimec2020-wx,Zrimec2018-lx}. Deep learning algorithms, however, might prove to be much more capable as they can interpret new data representations themselves \cite{Bengio2013-xg} and, in our experience, outperform any structural feature-based model using mere nucleotide sequence \cite{Zrimec2019-ql}. Besides sequence alignment \cite{Zrimec2020-wx}, the potential uses of the structural representations include: (i) phylogenetic analysis of regulatory DNA regions \cite{Garcillan-Barcia2009-yk}, (ii) analysis of single nucleotide variations \cite{Watson2008-dt}, as the structural representations contain variants with position-specific nucleotide substitutions, (iii) motif identification \cite{Samee2019-xj}, where, for instance, the initialization stage of graph-based algorithms could be performed using structural representations \cite{Stepancic2014-yu}, and (iv) design of DNA substrates with a modified DNA sequence but conserved functionality. Other, combined approaches could potentially mimic the protein-DNA search and binding dynamics in DNA regulatory regions \cite{Marcovitz2013-kg,Levo2015-iu,Slattery2014-ne,Rohs2009-hm} and adopt a combination of both structural and sequence features (Fig. 8). Another possibility is to use different representations for the non-coding (structural) and coding (sequence) regions, e.g. for whole-gene identification. Indeed, due to the bias of the current bioinformatic methods to nucleotide sequence based approaches, it is possible that considerable performance increases might still be achievable in certain fields with such novel solutions \cite{Zrimec2020-wx, Samee2019-xj}. \section*{Acknowledgements} This work was supported by the Slovenian Research Agency under grant agreement no. [Z2-7257]. I kindly thank Filip Buric (Chalmers Univ. of Tech., Sweden), Tomaz Pisanski and Nino Basic (UP-FAMNIT, Slovenia), Chrats Melkonian (VU, Netherlands), Maria Pilar Garcillan-Barcia and Fernando de la Cruz (UNICAN, Spain), Joshua Ramsey (Curtin Univ., Australia) and Ziva Stepancic and Ales Lapanje (IJS, Slovenia) for their discussions and support of this research. \bibliographystyle{unsrt} \bibliography{2020_Zrimec-representations} \end{document} \endinput
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import algebra.order.group.defs import algebra.hom.equiv.units.basic /-! # Inverse and multiplication as order isomorphisms in ordered groups > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. -/ set_option old_structure_cmd true open function universe u variable {α : Type u} section group variables [group α] section typeclasses_left_right_le variables [has_le α] [covariant_class α α (*) (≤)] [covariant_class α α (swap (*)) (≤)] {a b c d : α} section variable (α) /-- `x ↦ x⁻¹` as an order-reversing equivalence. -/ @[to_additive "`x ↦ -x` as an order-reversing equivalence.", simps] def order_iso.inv : α ≃o αᵒᵈ := { to_equiv := (equiv.inv α).trans order_dual.to_dual, map_rel_iff' := λ a b, @inv_le_inv_iff α _ _ _ _ _ _ } end @[to_additive neg_le] lemma inv_le' : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := (order_iso.inv α).symm_apply_le alias inv_le' ↔ inv_le_of_inv_le' _ attribute [to_additive neg_le_of_neg_le] inv_le_of_inv_le' @[to_additive le_neg] lemma le_inv' : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := (order_iso.inv α).le_symm_apply end typeclasses_left_right_le end group alias le_inv' ↔ le_inv_of_le_inv _ attribute [to_additive] le_inv_of_le_inv section group variables [group α] [has_le α] section right variables [covariant_class α α (swap (*)) (≤)] {a b c d : α} /-- `equiv.mul_right` as an `order_iso`. See also `order_embedding.mul_right`. -/ @[to_additive "`equiv.add_right` as an `order_iso`. See also `order_embedding.add_right`.", simps to_equiv apply {simp_rhs := tt}] def order_iso.mul_right (a : α) : α ≃o α := { map_rel_iff' := λ _ _, mul_le_mul_iff_right a, to_equiv := equiv.mul_right a } @[simp, to_additive] lemma order_iso.mul_right_symm (a : α) : (order_iso.mul_right a).symm = order_iso.mul_right a⁻¹ := by { ext x, refl } end right section left variables [covariant_class α α (*) (≤)] /-- `equiv.mul_left` as an `order_iso`. See also `order_embedding.mul_left`. -/ @[to_additive "`equiv.add_left` as an `order_iso`. See also `order_embedding.add_left`.", simps to_equiv apply {simp_rhs := tt}] def order_iso.mul_left (a : α) : α ≃o α := { map_rel_iff' := λ _ _, mul_le_mul_iff_left a, to_equiv := equiv.mul_left a } @[simp, to_additive] lemma order_iso.mul_left_symm (a : α) : (order_iso.mul_left a).symm = order_iso.mul_left a⁻¹ := by { ext x, refl } end left end group
!!# FUNCTION MODULE: <FUN_CMPLX> MODULE FUN_CMPLX !!## PURPOSE !! Overload the complex conversion intrinsic, <CMPLX>, !! to accept string arguments. !!## USAGE ! ! C = CMPLX(S,KIND) ! !! where <KIND> is the desired <KIND> of complex <C>. !!## EXTERNAL KINDS USE KND_IntrinsicTypes,ONLY: KIND_C,KIND_Csp,KIND_Cdp,KIND_S !!((01-A-KND_IntrinsicTypes.f90)) !!## GLOBAL USER MODULES USE USR_Cstar0 !!((05-A-USR_Cstar0.f90)) !!## EXTERNAL PROCEDURES USE FUN_Error !!((04-A-FUN_Error.f90)) !!## DEFAULT IMPLICIT IMPLICIT NONE !!## DEFAULT ACCESS PRIVATE !!## INTRINSIC OVERLOADING INTERFACE CMPLX MODULE PROCEDURE CMPLX_S ENDINTERFACE !!## ACCESS PUBLIC :: CMPLX !!## CONTAINED PROCEDURES CONTAINS PURE ELEMENTAL FUNCTION CMPLX_S(S,KIND) RESULT(Cstar0) !!#### REQUIRED INPUT CHARACTER(LEN=*,KIND=KIND_S),INTENT(IN) :: S INTEGER ,INTENT(IN) :: KIND !!#### REQUIRED OUTPUT TYPE(TYPE_Cstar0) :: Cstar0 !!#### LOCAL VARIABLES INTEGER :: jerr !!--begin-- Cstar0% KIND = KIND SELECT CASE( Cstar0% KIND ) CASE( KIND_Csp ) ; READ(S,*,IOSTAT=jerr) Cstar0%Csp CASE( KIND_Cdp ) ; READ(S,*,IOSTAT=jerr) Cstar0%Cdp CASE DEFAULT ; jerr = 1 END SELECT IF( jerr/=0 )THEN Cstar0% KIND = 0 END IF !!--end-- END FUNCTION ENDMODULE
lemma subset_box: fixes a :: "'a::euclidean_space" shows "cbox c d \<subseteq> cbox a b \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i \<le> d\<bullet>i) \<longrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th1) and "cbox c d \<subseteq> box a b \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i \<le> d\<bullet>i) \<longrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < c\<bullet>i \<and> d\<bullet>i < b\<bullet>i)" (is ?th2) and "box c d \<subseteq> cbox a b \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i) \<longrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th3) and "box c d \<subseteq> box a b \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i) \<longrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th4)
#include <svgpp/parser/grammar/urange.hpp> #include <gtest/gtest.h> #include <boost/tuple/tuple_io.hpp> namespace qi = boost::spirit::qi; namespace { template<class StringT> void valid_testT(StringT const & testStr, int r1, int r2) { typename StringT::const_iterator first = testStr.begin(); svgpp::urange_grammar<typename StringT::const_iterator> grammar; std::pair<unsigned, unsigned> urange; EXPECT_TRUE(qi::parse(first, testStr.end(), grammar, urange)); EXPECT_TRUE(first == testStr.end()); EXPECT_EQ(r1, urange.first); EXPECT_EQ(r2, urange.second); } template<class StringT> void invalid_testT(StringT const & testStr) { typename StringT::const_iterator first = testStr.begin(); svgpp::urange_grammar<typename StringT::const_iterator> grammar; EXPECT_TRUE(!qi::parse(first, testStr.end(), grammar) || first != testStr.end()); } typedef boost::tuple<const char *, int, int> urange_test_t; urange_test_t ValidTests[] = { urange_test_t("U+0-7FFFFFFF", 0, 0x7FFFFFFF), urange_test_t("U+05D1", 0x05D1, 0x05D1), urange_test_t("U+20A7", 0x20A7, 0x20A7), urange_test_t("U+215?", 0x2150, 0x215F), urange_test_t("U+00??", 0x0, 0xFF), urange_test_t("U+E??", 0xE00, 0xEFF), urange_test_t("U+AC00-D7FF", 0xAC00, 0xD7FF), urange_test_t("U+370-3FF", 0x370, 0x3FF), urange_test_t("U+3000-33FF", 0x3000, 0x33FF) }; std::ostream & operator<< (std::ostream & os, urange_test_t const & val) { return boost::tuples::operator<<(os, val); } class ValidURange : public ::testing::TestWithParam<urange_test_t> { }; char const * const InvalidStrings[] = { "U+-7FF", " U+05D1", "U+05D1 ", "U+ 05D1", "U+00??A", "U+0- 7FFFFFFF" }; } TEST_P(ValidURange, Valid) { std::string testStr = GetParam().get<0>(); valid_testT(testStr, GetParam().get<1>(), GetParam().get<2>()); valid_testT(std::wstring(testStr.begin(), testStr.end()), GetParam().get<1>(), GetParam().get<2>()); } INSTANTIATE_TEST_CASE_P(urange_grammar, ValidURange, ::testing::ValuesIn(ValidTests)); class InvalidURange : public ::testing::TestWithParam<const char*> { }; TEST_P(InvalidURange, Invalid) { std::string testStr = GetParam(); invalid_testT(testStr); invalid_testT(std::wstring(testStr.begin(), testStr.end()) ); } INSTANTIATE_TEST_CASE_P(urange_grammar, InvalidURange, ::testing::ValuesIn(InvalidStrings));
# Here we use generators : the given formula doesn't need one, but the alternate # non-squares function is better done with a generator. # The formula is implemented with exact floor(sqrt(n)), so we use # a trick: multiply by 100 to get the first decimal digit of the # square root of n, then add 5 (that's 1/2 multiplied by 10). # Then just divide by 10 to get floor(1/2 + sqrt(n)) exactly. # It looks weird, but unlike floating point, it will do the job # for any n. NonSquaresGen := function() local ns, n; n := 0; ns := function() n := n + 1; return n + QuoInt(5 + RootInt(100*n), 10); end; return ns; end; NonSquaresAlt := function() local ns, n, q, k; n := 1; q := 4; k := 3; ns := function() n := n + 1; if n = q then n := n + 1; k := k + 2; q := q + k; fi; return n; end; return ns; end; gen := NonSquaresGen(); List([1 .. 22] i -> gen()); # [ 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27 ] a := NonSquaresGen(); b := NonSquaresAlt(); ForAll([1 .. 1000000], i -> a() = b()); # true
State Before: F : Type ?u.99156 α : Type u_1 β : Type ?u.99162 𝕜 : Type ?u.99165 E : Type ?u.99168 inst✝¹ : CancelCommMonoidWithZero α inst✝ : NoZeroDivisors α s : Set α a : α hs : MulSalemSpencer s ha : a ≠ 0 ⊢ MulSalemSpencer ((fun x => x * a) '' s) State After: case intro.intro.intro.intro.intro.intro F : Type ?u.99156 α : Type u_1 β : Type ?u.99162 𝕜 : Type ?u.99165 E : Type ?u.99168 inst✝¹ : CancelCommMonoidWithZero α inst✝ : NoZeroDivisors α s : Set α a : α hs : MulSalemSpencer s ha : a ≠ 0 b : α hb : b ∈ s c : α hc : c ∈ s d : α hd : d ∈ s h : (fun x => x * a) b * (fun x => x * a) c = (fun x => x * a) d * (fun x => x * a) d ⊢ (fun x => x * a) b = (fun x => x * a) c Tactic: rintro _ _ _ ⟨b, hb, rfl⟩ ⟨c, hc, rfl⟩ ⟨d, hd, rfl⟩ h State Before: case intro.intro.intro.intro.intro.intro F : Type ?u.99156 α : Type u_1 β : Type ?u.99162 𝕜 : Type ?u.99165 E : Type ?u.99168 inst✝¹ : CancelCommMonoidWithZero α inst✝ : NoZeroDivisors α s : Set α a : α hs : MulSalemSpencer s ha : a ≠ 0 b : α hb : b ∈ s c : α hc : c ∈ s d : α hd : d ∈ s h : (fun x => x * a) b * (fun x => x * a) c = (fun x => x * a) d * (fun x => x * a) d ⊢ (fun x => x * a) b = (fun x => x * a) c State After: case intro.intro.intro.intro.intro.intro F : Type ?u.99156 α : Type u_1 β : Type ?u.99162 𝕜 : Type ?u.99165 E : Type ?u.99168 inst✝¹ : CancelCommMonoidWithZero α inst✝ : NoZeroDivisors α s : Set α a : α hs : MulSalemSpencer s ha : a ≠ 0 b : α hb : b ∈ s c : α hc : c ∈ s d : α hd : d ∈ s h : b * c * (a * a) = d * d * (a * a) ⊢ (fun x => x * a) b = (fun x => x * a) c Tactic: rw [mul_mul_mul_comm, mul_mul_mul_comm d] at h State Before: case intro.intro.intro.intro.intro.intro F : Type ?u.99156 α : Type u_1 β : Type ?u.99162 𝕜 : Type ?u.99165 E : Type ?u.99168 inst✝¹ : CancelCommMonoidWithZero α inst✝ : NoZeroDivisors α s : Set α a : α hs : MulSalemSpencer s ha : a ≠ 0 b : α hb : b ∈ s c : α hc : c ∈ s d : α hd : d ∈ s h : b * c * (a * a) = d * d * (a * a) ⊢ (fun x => x * a) b = (fun x => x * a) c State After: no goals Tactic: rw [hs hb hc hd (mul_right_cancel₀ (mul_ne_zero ha ha) h)]
If $S$ is locally path-connected, then the path-component of $x$ is the same as the connected component of $x$.
#!/usr/bin/Rscript ## Author: David Eccles (gringer), 2007-2016 <[email protected]> ## structure2pdf.r -- generates box/dot plot for results from structure usage <- function(){ cat("usage: ./structure2pdf.r", "<file>( p<name> <range from> <range to>)* [options]\n"); cat("\nOther Options:\n"); cat("-help : Only display this help message\n"); cat("-gdionly [K=2] : Only calculate Genome Diagnostic Index\n"); cat("-line <value> : Draw a horizontal line at <value>\n"); cat("-sort : Sort individuals by Q values\n"); cat("-basicsort : Sort individuals strictly by Q values\n"); cat("-barplot [K=2] : Always do a barplot (rather than scatterplot)\n"); cat("-error [k=2] : Show error bars from \"_f\" file\n"); cat("-mean [K=2] : Draw mean and SE lines for each popualtion\n"); cat("-noshade [K=2] : Don't draw background coloured stripes\n"); cat("-nostack [K>2] : Don't put highest Q on the bottom\n"); cat("-stacksort [K>2] : Sort each individual's bar vertically\n"); cat("-halfheight : Output a PDF file half the usual height\n"); cat("-svg : Output to an SVG file (instead of PDF)\n"); cat("-pointsize <value> : Scaling factor for point size\n"); cat("-flip [K=2] : swap Q values for first and second clusters\n"); cat("-rotatelabels : Make population labels display vertically\n"); cat("-labelaxis : Place population labels on the axis\n"); cat("c<name> : Set the colour for the next population to <name>\n"); cat("\n"); } ## bgShade -- makes a shaded fill on a plot (fills a band in the x direction) bgShade <- function(fromX, toX, levels = 40, color.palette = cm.colors, cl = color.palette(levels), density = NA){ rect(fromX,-0.01,toX,1/levels,col = cl[1], density=density, border = NA, lwd = 2); if(levels>2){ for(x in 3:levels-2){ if(x < (levels / 2)){ ag = 45; } else{ ag = 135; } rect(fromX,(x) * 1/levels,toX,(x+1) * 1/levels, col = cl[x+1], density=density, angle = ag, border = NA, lwd = 2); } } rect(fromX,1-1/levels,toX, 1.01, col = cl[levels], density=density, angle = 135, border = NA, lwd = 2); } seq1 <- function(length.out = 10){ return(seq(0,1,length.out = length.out)); } invertOrder <- function(x){ order(x, decreasing = TRUE)[order(x, decreasing = TRUE)]; } orderHighest <- function(x){ highOrder <- order(x, decreasing = TRUE); highestNum <- highOrder[1]; swapOrder <- 1:length(x); swapOrder[highestNum] <- 1; swapOrder[1] <- highestNum; return(swapOrder); } sortHighest <- function(x){ return(x[orderHighest(x)]); } popNames <- character(0); popLimits <- NULL; breakstyle <- integer(0); infile.name <- FALSE; prob.df <- FALSE; flip <- FALSE; doSVG <- FALSE; sortByQ <- FALSE; basicSort <- FALSE; labelAxis <- FALSE; rotateLabels <- FALSE; halfHeight <- FALSE; pointSize <- 1; popColours <- FALSE; shadedBG <- TRUE; onlyBarPlot <- FALSE; showError <- FALSE; drawMeans <- FALSE; sortStacks <- TRUE; stackFlip <- TRUE; gdiOnly <- FALSE; horizLines <- NULL; qlow.df <- NULL; qhigh.df <- NULL; argLoc <- 1; while(!is.na(commandArgs(TRUE)[argLoc])){ if(file.exists(commandArgs(TRUE)[argLoc])){ # file existence check if(infile.name == FALSE){ infile.name <- commandArgs(TRUE)[argLoc]; } else{ cat("Error: More than one input file specified\n"); usage(); quit(save = "no", status=1); } } else { if(commandArgs(TRUE)[argLoc] == "-help"){ usage(); quit(save = "no", status=0); } if(substr(commandArgs(TRUE)[argLoc],1,1) == "p"){ inName <- substring(commandArgs(TRUE)[argLoc],2); if(substr(inName,1,1) == '_'){ breakstyle <- c(breakstyle,1); inName <- substr(inName, 2, nchar(inName)); } else{ breakstyle <- c(breakstyle,2); } popNames <- append(popNames, sub("_"," ",inName)); popLimits <- cbind(popLimits,c(as.numeric(commandArgs(TRUE)[argLoc+1]), as.numeric(commandArgs(TRUE)[argLoc+2]))); argLoc <- argLoc + 2; } if(commandArgs(TRUE)[argLoc] == "-gdionly"){ gdiOnly <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-line"){ horizLines = c(horizLines, as.numeric(commandArgs(TRUE)[argLoc+1])); argLoc <- argLoc + 1; } if(commandArgs(TRUE)[argLoc] == "-barplot"){ onlyBarPlot <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-error"){ showError <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-sort"){ sortByQ <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-basicsort"){ sortByQ <- TRUE; basicSort <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-mean"){ drawMeans <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-noshade"){ shadedBG <- FALSE; } if(commandArgs(TRUE)[argLoc] == "-nostack"){ sortStacks <- FALSE; } if(commandArgs(TRUE)[argLoc] == "-stacksort"){ sortStacks <- TRUE; stackFlip <- FALSE; } if(commandArgs(TRUE)[argLoc] == "-halfheight"){ halfHeight <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-svg"){ library(cairoDevice); doSVG <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-pointsize"){ pointSize <- as.numeric(commandArgs(TRUE)[argLoc+1]); cat("Setting point size to ",pointSize,"\n",sep=""); argLoc <- argLoc + 1; } if(commandArgs(TRUE)[argLoc] == "-flip"){ flip <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-rotatelabels"){ labelAxis <- TRUE; rotateLabels <- TRUE; } if(commandArgs(TRUE)[argLoc] == "-labelaxis"){ labelAxis <- TRUE; } if(substr(commandArgs(TRUE)[argLoc],1,1) == "c"){ inName <- substring(commandArgs(TRUE)[argLoc],2); if(popColours[1] == FALSE){ popColours <- inName; } else{ popColours <- c(popColours,inName); } } } argLoc <- argLoc + 1; } if(infile.name == FALSE){ cat("Error: No valid file given\n\n"); usage(); quit(save = "no", status=1); } else { tmpWarn <- getOption("warn"); infile.con <- file(infile.name); open(infile.con); options(warn = -1); tmpLines <- readLines(infile.con); options(warn = tmpWarn); rm(tmpWarn); idx <- grep("([0-9] individuals|Inferred clusters)",tmpLines); if(length(idx) == 2){ ## Assume "_f"-style file [standard Structure output] numIndivs <- as.numeric(gsub("[^0-9]","",tmpLines[idx[1]])); seek(infile.con, 0); tmp.df <- read.table(infile.con, nrows = numIndivs, skip = idx[2], row.names = 2, stringsAsFactors = FALSE); colnames(tmp.df)[c(1,2,3)] <- c("Line","Missing%","Separator"); tmp.df$"Missing%" = as.numeric(gsub("[^0-9]","",tmp.df$"Missing%")) tmp.df$"Missing%" = NULL; ## simplifies conversion later tmp.df$Line = NULL tmp.df$Separator = NULL; idx <- grep("\\(",tmp.df[1,]); if(length(idx) > 0){ ## probability intervals exist, so we put them in prob.df infile.df <- tmp.df[1:(idx[1]-1)]; # copy over data table tmp.df <- tmp.df[-(1:(idx[1]-1))]; # remove Q values from temp table tmp.names <- rownames(tmp.df); tmp.df <- data.frame(lapply(tmp.df,gsub,pattern="[^0-9,\\.]", replacement=""), stringsAsFactors = FALSE); # extract low/high limits, assumes #.###,#.### (i.e. 3 d.p) qlow.df <- data.frame(lapply(tmp.df,substring,1,5), stringsAsFactors = FALSE); # convert character to numeric value qlow.df <- data.frame(lapply(qlow.df,as.numeric)); rownames(qlow.df) <- tmp.names; colnames(qlow.df) <- paste("Q",1:(dim(qlow.df)[2]), sep = "") qhigh.df <- data.frame(lapply(tmp.df,substring,7,11), stringsAsFactors = FALSE); # convert character to numeric value qhigh.df <- data.frame(lapply(qhigh.df,as.numeric)); rownames(qhigh.df) <- tmp.names; colnames(qhigh.df) <- paste("Q",1:(dim(qhigh.df)[2]), sep = "") } else { infile.df <- tmp.df; # no probability intervals, so we're done } rm(tmp.df); # clean up rm(numIndivs); } else{ ## Assume "_q"-style file ## NOTE: "_q" files seem to have 1 d.p. more precision in results seek(infile.con, 0); infile.df <- read.table(infile.con)[,-1]; ## remove first column (IDs) } rm(tmpLines); close(infile.con); } cat("Input file has data for ",dim(infile.df)[1]," individuals\n",sep=""); if(length(popNames) == 0){ cat("Warning: no populations defined.\n", " All individuals will be treated as the same population\n" , sep=""); popNames <- "All"; popLimits <- rbind(1,dim(infile.df)[1]); breakstyle <- c(breakstyle,1); } else { totLength <- 0; for(x in 1:dim(popLimits)[2]){ totLength <- totLength + (popLimits[2,x] - popLimits[1,x] + 1); if((popLimits[2,x] > dim(infile.df)[1]) || (popLimits[1,x] < 1)){ cat("Error: range of population", popNames[x] , " outside range of individuals", "in the file\n"); usage(); quit(save = "no", status = 2); } } if(totLength < dim(infile.df)[1]){ cat("Warning: fewer individuals specified than present in the file\n"); } if(totLength > dim(infile.df)[1]){ cat("Warning: more individuals specified than present in the file\n"); } } nextPos <- 1; tmpfile.df <- NULL; tmpLimits <- NULL; tmplow.df <- NULL; tmphigh.df <- NULL; for(x in 1:dim(popLimits)[2]){ tmpLimits <- cbind(tmpLimits,c(nextPos, nextPos + (popLimits[2,x] - popLimits[1,x]))); cat("extracting population '",popNames[x], "' (",popLimits[2,x] - popLimits[1,x] + 1," individuals)\n",sep=""); tmpfile.df <- rbind(tmpfile.df, infile.df[popLimits[1,x]:popLimits[2,x],]); tmplow.df <- rbind(tmplow.df, qlow.df[popLimits[1,x]:popLimits[2,x],]); tmphigh.df <- rbind(tmphigh.df, qhigh.df[popLimits[1,x]:popLimits[2,x],]); nextPos <- tmpLimits[2,x] + 1; } infile.df <- data.frame(tmpfile.df); qlow.df <- data.frame(tmplow.df); qhigh.df <- data.frame(tmphigh.df); popLimits <- tmpLimits; colnames(infile.df) <- paste("Q",1:(dim(infile.df)[2]), sep = "") if(flip){ # flip order of the first and second population tmp <- infile.df$Q1; infile.df$Q1 <- infile.df$Q2; infile.df$Q2 <- tmp; qlow.df <- 1 - qlow.df; qhigh.df <- 1 - qhigh.df; } if(sortByQ){ # sort based on max Q within each population cat("sorting..."); maxPopFormat <- paste("%0",nchar(dim(infile.df)[2]),"d",sep=""); for(x in 1:dim(popLimits)[2]){ tmp.df <- infile.df[popLimits[1,x]:popLimits[2,x],]; # work out position of maximum Q per individual ## Sort 0 -- sort by dominant Q for the population popMaxQ <- unlist(tmp.df[which(colSums(tmp.df) == max(colSums(tmp.df)))]); ## Sort 1 -- Q > 0.5 indLargeQpos <- apply((tmp.df > 0.5) * rep(seq(1,dim(tmp.df)[2]), each = dim(tmp.df)[1]),1,max); ## Sort 2 -- greater than mean Q indMeanQpos <- apply((tmp.df > apply(tmp.df,1,mean))* rep(seq(1,dim(tmp.df)[2]), each = dim(tmp.df)[1]),1,max); ## Sort 3 -- max Q indMaxQpos <- apply((tmp.df == apply(tmp.df,1,max))* rep(seq(1,dim(tmp.df)[2]), each = dim(tmp.df)[1]),1,max); maxCounts <- # how many times a population is max for each individual colSums((tmp.df) == apply(tmp.df,1,max)); ## Make sure populations with the same counts don't end up alternating maxCounts[duplicated(maxCounts)] <- seq(0.1,0.4, length.out = length(which(duplicated(maxCounts)))); ## Ordering based on Q ranking of populations for each individual (not currently used) indQOrder <- order(apply(apply(apply(tmp.df,1,order),1,sprintf,fmt=maxPopFormat),1,paste,collapse="")); # work out value of maximum Q per individual indMaxQ <- apply(tmp.df * (tmp.df == apply(tmp.df,1,max)),1,max); indMeanQ <- apply(tmp.df * (tmp.df == apply(tmp.df,1,mean)),1,max); indMinQ <- apply(tmp.df * (tmp.df == apply(tmp.df,1,min)),1,max); ## older sort -- by maximum Q for all individuals #sumRank <- apply(infile.df[popLimits[1,x]:popLimits[2,x],],2,sum); #sortRank <- infile.df[popLimits[1,x]:popLimits[2,x], # sumRank == max(sumRank)]; #infile.df[popLimits[1,x]:popLimits[2,x],] <- # infile.df[order(sortRank)+popLimits[1,x]-1,]; # Sort by max Q position, then by max Q if(basicSort){ infile.df[popLimits[1,x]:popLimits[2,x],] <- infile.df[order(popMaxQ,decreasing = TRUE)+popLimits[1,x]-1,]; } else { infile.df[popLimits[1,x]:popLimits[2,x],] <- infile.df[order(maxCounts[indMaxQpos],indMaxQ,decreasing = TRUE)+popLimits[1,x]-1,]; } if(!is.null(qlow.df)){ if(basicSort){ qlow.df[popLimits[1,x]:popLimits[2,x],] <- qlow.df[order(popMaxQ,decreasing = TRUE)+popLimits[1,x]-1,]; qhigh.df[popLimits[1,x]:popLimits[2,x],] <- qhigh.df[order(popMaxQ,decreasing = TRUE)+popLimits[1,x]-1,]; } else { qlow.df[popLimits[1,x]:popLimits[2,x],] <- qlow.df[order(maxCounts[indMaxQpos],indMaxQ,decreasing = TRUE)+popLimits[1,x]-1,]; qhigh.df[popLimits[1,x]:popLimits[2,x],] <- qhigh.df[order(maxCounts[indMaxQpos],indMaxQ,decreasing = TRUE)+popLimits[1,x]-1,]; } } } cat("done\n"); } if(doSVG){ if(halfHeight){ Cairo_svg("output_Q.svg", width = 11, height = 4); } else { Cairo_svg("output_Q.svg", width = 11, height = 8); } } else { if(halfHeight){ pdf("output_Q.pdf", width = 11, height = 4); } else { pdf("output_Q.pdf", width = 11, height = 8, paper = 'a4r'); } } par(mar=c(5,6,1,1)); if((onlyBarPlot) || (length(colnames(infile.df)) > 2)){ if(popColours[1] == FALSE){ popColours <- rainbow(length(colnames(infile.df))); } if(sortStacks){ if(stackFlip){ popColours <- popColours[apply(infile.df,1,orderHighest)]; barMat <- apply(infile.df,1,sortHighest); } else{ popColours <- popColours[apply(infile.df,1,order, decreasing = TRUE)]; barMat <- apply(infile.df,1,sort, decreasing = TRUE); } } else{ barMat <- t(as.matrix(infile.df[,1:length(colnames(infile.df))])); } barMat <- (barMat*1.001) / colSums(barMat); ## set up plot, but don't draw bars/blocks barCentres <- barplot(barMat, col = NA, border = NA, space = 0, ylab = "Q", xlab = "Individual", cex.lab = 2, cex.axis = 1.5, las = 2, xaxt = "n", ylim = c(0,1), mgp = c(4,1,0)); rect(xleft = rep(barCentres - 0.5, each = dim(barMat)[1]), xright = rep(barCentres + 0.5, each = dim(barMat)[1]), ybottom = rbind(0,apply(t(barMat),1,cumsum)[1:(dim(barMat)[1]-1),]), ytop = rbind( apply(t(barMat),1,cumsum)[2:(dim(barMat)[1]),],1), col = popColours, border = popColours, lwd = 0.5); if(length(horizLines)>0){ abline(h = horizLines, lwd = 3, col = "grey"); } for(x in 1:dim(popLimits)[2]){ if(x > 1){ lines(x=rep(barCentres[popLimits[1,x]]-0.5,2),y=c(0,1), lty = breakstyle[x], lwd = 1); } if(!labelAxis){ srtLabel = 0; if(rotateLabels){ srtLabel = 90; } text((barCentres[popLimits[1,x]] + barCentres[popLimits[2,x]])/2, 0.5, popNames[x], cex = 2, srt = srtLabel); } } if(labelAxis){ axLas <- 0; if(rotateLabels){ axLas <- 2; } axis(side = 1,labels = popNames, at = (barCentres[popLimits[1,]] + barCentres[popLimits[2,]])/2, col = NA, cex.axis = 1.5, las = axLas); } } else { if(!gdiOnly){ if(halfHeight){ plot(infile.df$Q1, ylab = "Q", pch = NA, xlab = "Individual", main = "", las = 2, cex.lab = 2, cex.axis = 1.5, mgp=c(4,1,0), ylim = c(0,1)); } else { plot(infile.df$Q1, ylab = "Estimated Ancestral Fraction (Q)", pch = NA, xlab = "Individual", main = "", las = 2, cex.lab = 2, cex.axis = 1.5, mgp=c(4,1,0), ylim = c(0,1)); } if(length(horizLines)>0){ abline(h = horizLines, lwd = 3, col = "grey"); } for(x in 1:dim(popLimits)[2]){ if(shadedBG){ bgShade(popLimits[1,x]-0.5,popLimits[2,x]+0.5,50, density = 25, cl = c(rgb(0.5+seq1(25)*0.5,0.5+seq1(25)*0.5,1), rgb(1-seq1(25)*0.5,1,1-seq1(25)*0.5))); ## redraw cutoff lines over shading if(length(horizLines)>0){ abline(h = horizLines, lwd = 3, col = "grey"); } } if(x > 1){ lines(x=rep(popLimits[1,x]-0.5,2),y=c(0,1), lty = breakstyle[x], lwd = 1); } text((popLimits[1,x] + popLimits[2,x])/2,0.5,popNames[x],cex = 2); } par(new=TRUE) if(showError && (!is.null(qlow.df))){ arrows(x0 = 1:(dim(infile.df)[1]), x1 = 1:(dim(infile.df)[1]), y0 = qlow.df$Q1, y1 = qhigh.df$Q1, angle = 90, code = 3, length = 0.03, lwd = 2 * pointSize, col = "#EF6464"); } points(x=1:dim(infile.df)[1],y=infile.df$Q1, col="#000000", pch = 16, cex = 1 * pointSize); } for(x in 1:dim(popLimits)[2]){ if(drawMeans){ qdata <- infile.df[popLimits[1,x]:popLimits[2,x],1]; sDev <- sd(qdata); cat(sprintf("Mean Q for population %d: %f (SD = %f)\n",x, mean(qdata), sDev)); if(!gdiOnly){ lines(x=c(popLimits[1,x]-0.5,popLimits[2,x]+0.5),y=rep(mean(qdata) + sDev,2), lwd = 1, col = "red"); lines(x=c(popLimits[1,x]-0.5,popLimits[2,x]+0.5),y=rep(mean(qdata),2), lwd = 2, col = "grey"); lines(x=c(popLimits[1,x]-0.5,popLimits[2,x]+0.5),y=rep(mean(qdata) - sDev,2), lwd = 1, col = "red"); } } } if(dim(popLimits)[2] == 2){ cat(sprintf("Genome Diagnostic Index (GDI): %f\n", abs(mean(infile.df[popLimits[1,1]:popLimits[2,1],1]) - mean(infile.df[popLimits[1,2]:popLimits[2,2],1])))); cat(sprintf("Mean (SD) for populations: %f (%f), %f (%f)\n", mean(infile.df[popLimits[1,1]:popLimits[2,1],1]), sd(infile.df[popLimits[1,1]:popLimits[2,1],1]), mean(infile.df[popLimits[1,2]:popLimits[2,2],1]), sd(infile.df[popLimits[1,2]:popLimits[2,2],1]))); if(flip){ print(t.test(1 - infile.df[popLimits[1,1]:popLimits[2,1],1], 1 - infile.df[popLimits[1,2]:popLimits[2,2],1])); } else { print(t.test(infile.df[popLimits[1,1]:popLimits[2,1],1], infile.df[popLimits[1,2]:popLimits[2,2],1])); } } } dummy <- dev.off();
module Issue794a where open import Common.Prelude open import Common.MAlonzo postulate A : Set id : .A → A → A id x y = y
(* This Isabelle theory is produced using the TIP tool offered at the following website: https://github.com/tip-org/tools This file was originally provided as part of TIP benchmark at the following website: https://github.com/tip-org/benchmarks Yutaka Nagashima at CIIRC, CTU changed the TIP output theory file slightly to make it compatible with Isabelle2017. \:w Some proofs were added by Yutaka Nagashima.*) theory TIP_sort_nat_HSortSorts imports "../../Test_Base" begin datatype 'a list = nil2 | cons2 "'a" "'a list" datatype Nat = Z | S "Nat" datatype Heap = Node "Heap" "Nat" "Heap" | Nil fun toHeap :: "Nat list => Heap list" where "toHeap (nil2) = nil2" | "toHeap (cons2 y z) = cons2 (Node Nil y Nil) (toHeap z)" fun le :: "Nat => Nat => bool" where "le (Z) y = True" | "le (S z) (Z) = False" | "le (S z) (S x2) = le z x2" fun ordered :: "Nat list => bool" where "ordered (nil2) = True" | "ordered (cons2 y (nil2)) = True" | "ordered (cons2 y (cons2 y2 xs)) = ((le y y2) & (ordered (cons2 y2 xs)))" fun hmerge :: "Heap => Heap => Heap" where "hmerge (Node z x2 x3) (Node x4 x5 x6) = (if le x2 x5 then Node (hmerge x3 (Node x4 x5 x6)) x2 z else Node (hmerge (Node z x2 x3) x6) x5 x4)" | "hmerge (Node z x2 x3) (Nil) = Node z x2 x3" | "hmerge (Nil) y = y" fun hpairwise :: "Heap list => Heap list" where "hpairwise (nil2) = nil2" | "hpairwise (cons2 q (nil2)) = cons2 q (nil2)" | "hpairwise (cons2 q (cons2 r qs)) = cons2 (hmerge q r) (hpairwise qs)" (*fun did not finish the proof*) function hmerging :: "Heap list => Heap" where "hmerging (nil2) = Nil" | "hmerging (cons2 q (nil2)) = q" | "hmerging (cons2 q (cons2 z x2)) = hmerging (hpairwise (cons2 q (cons2 z x2)))" by pat_completeness auto fun toHeap2 :: "Nat list => Heap" where "toHeap2 x = hmerging (toHeap x)" (*fun did not finish the proof*) function toList :: "Heap => Nat list" where "toList (Node q y r) = cons2 y (toList (hmerge q r))" | "toList (Nil) = nil2" by pat_completeness auto fun hsort :: "Nat list => Nat list" where "hsort x = toList (toHeap2 x)" theorem property0 : "ordered (hsort xs)" oops end
The second variation of ancient and Conceptual matters in Psychology bargains a full of life and interesting advent to the most concerns underlying the emergence and carrying on with evolution of psychology. The booklet starts with the matter of the connection among systematic philosophy and the heritage of philosophy. Why does philosophy connect quite a bit significance to heritage? attention of this query is a necessary a part of metaphysics, and it has very important effects for the technique of either historical past and philosophy. A bunch of difficulties that looks conspicuously within the current quantity, and in to this point contributes to the health of its identify, has bought a substantial curiosity at the a part of the general public at huge. Such curiosity turns out susceptible to take its clue from the job of these who usher in startling revelations at the foundation of bizarre psychic studies, and who supply promise of revealing different worlds than the only with which logic and customary sensation acquaint us, instead of from the wary and constant result of critical scholars in learn or in laboratory. How do we, analysts, review no matter if research is producing modifications in our sufferers? Time for switch: monitoring modifications in Psychoanalyses. The Three-Level version specializes in the query of ways to watch alterations in psychoanalysis. The IPA undertaking Committee on scientific remark and checking out bargains a device, a heuristic, or a advisor for refining, conceptualizing, and systematizing scientific observations approximately sufferer ameliorations: The Three-Level version for gazing sufferer changes (3-LM). Written records form an external memory, which allows an accumulation of knowledge. ■ For a long time the number of readers was limited. In addition, they were not encouraged to think critically about what they were reading (scholastic method). 3 What do you think? Is the current emphasis on ‘critical thinking’ exaggerated? Is it possible to think critically without first knowing the facts? The discovery of numbers Another development that has been crucial for the growth of science is the discovery of numbers. As these were the elements in Aristotle’s philosophy that attracted the scholars, other disagreements were soon to follow. By 1277 the Catholic bishop of Paris, Etienne Tempier, already had a list of 219 propositions related to Aristotelian philosophy that he forbad to be taught at the University of Paris. A cultural movement based on imitation of the Greek and Roman civilisations Renaissance cultural movement from the fourteenth to the seventeenth century based on a rediscovery and imitation of the classical Greek and Roman civilisations The availability of the ancient texts not only influenced scientists but also society as a whole. There people started to work with nine different symbols to represent the numbers one to nine. In addition, they used the place of the symbols in the digit string to represent powers of 10. The first digit represented the units, the second digit the tens, the third digit the hundreds, and so on. So, ‘thirty-two’ no longer consisted of two vertical lines to represent the two units and three symbols of ten to represent the 30, but became a symbol of 2 in the units position and a symbol of 3 in the tens position.
* * ------------------------------------------------------------------ * N O N H 1 * ------------------------------------------------------------------ * SUBROUTINE nonh1(IK) IMPLICIT DOUBLE PRECISION(A-H,O-Z) PARAMETER (LSDIM=30000, NWD=128) * POINTER (qcn,cn(lsdim)), (qpackn,ipackn(lsdim)), : (qjan,jan(lsdim)),(qjbn,jbn(lsdim)) COMMON /buffer/qcn, qpackn, qjan, qjbn POINTER (qintgrl1,intgrl1(1)),(qintptr1,intptr1(1)), : (qcnn1,cnn1(1)),(qjann1,jann1(1)),(qjbnn1,jbnn1(1)), : (qintgrl2,intgrl2(1)),(qintptr2,intptr2(1)), : (qcnn2,cnn2(1)),(qjann2,jann2(1)),(qjbnn2,jbnn2(1)) COMMON /CSF/qintgrl1,nint1,qintptr1,qcnn1,ncoef1,qjann1,qjbnn1, : qintgrl2,nint2,qintptr2,qcnn2,ncoef2,qjann2,qjbnn2 COMMON/DEBUG/IBUG1,IBUG2,IBUG3,NBUG6,NBUG7,IFULL COMMON/DIMEN/KFL1,KFL2,KFL3,KFL4,KFL5,KFL6,KFL7,MXIHSH COMMON/INFORM/IREAD,IWRITE,IOUT,ISC0,ISC1,ISC2,ISC3, : IALL,JSC(3),ISCW COMMON /DIAGNL/IDIAG,JA,JB COMMON /fout/lcount,nrec,iflag,lij,nij POINTER(QNOC,NOCCSH(1)),(QNELCSH,NELCSH(8,1)), : (QNOCORB,NOCORB(8,1)),(QJ1,J1QNRD(15,1)) POINTER(QIAJCMP,IAJCMP(1)),(QLJCOMP,LJCOMP(1)), : (QNJCOMP,NJCOMP(1)),(QIAJCLD,IAJCLD(1)), : (QLJCLSD,LJCLSD(1)) COMMON /NDIMS/ QNOC,QNELCSH,QNOCORB,QJ1,NCFG COMMON /NON30/ QIAJCMP,QNJCOMP,QLJCOMP,QIAJCLD,QLJCLSD,MAXORB COMMON /DBG /IBUGM character*1 ff common/nlorb/nq1(nwd),lq1(nwd),nq2(nwd),lq2(nwd) * 1 FORMAT(//' IOUT = FGR.LST (OUTPUT FILE)'/ : ' IBUG1 =',I3,' (DEBUG IN WEIGHTS OF 1-EL PART)'/ : ' IBUG2 =',I3,' (DEBUG IN WEIGHTS OF 2-EL PART)'/ : ' IBUG3 =',I3,' (DEBUG IN RECOUPLING PACKAGE)'//) * * ... THE FOLLOWING SECTION CONCERNS INPUT/OUTPUT AND MAY BE * SYSTEM DEPENDENT. CHECK ALLOWED UNIT NUMBERS AND * FILE NAME CONVENTIONS - MODIFY, IF NECESSARY. * IREAD = IK IOUT = 14+IK ISC3=17 * OPEN(UNIT=ISC3,STATUS='SCRATCH',FORM='UNFORMATTED') * * ... END OF MACHINE DEPENDENT SECTION * IBUG1 = 0 IBUG2 = 0 IBUG3 = 0 * WRITE(ISCW, '(A)') ' IBUG1,IBUG2,IBUG3 ? FORMAT(3(I1,1X)) ' * READ(5,'(I1,1X,I1,1X,I1)') IBUG1,IBUG2,IBUG3 * WRITE(IWRITE,1) IBUG1,IBUG2,IBUG3 * WRITE(ISCW, '(A)') ' FULL PRINT-OUT ? (Y/N) ' IFULL = 0 * READ(5,'(A2)') ANS * IF ( ANS .EQ. 'Y' .OR. ANS .EQ. 'y') IFULL = 1 * NEW = 0 NZER0 = 0 NONE = 0 * * --- Determine input data; non-orthogonal case * CALL CFGN1(NCLOSD) CALL SETSUPRAS(IK,NCLOSD) * IF ( NEW .EQ. 0 ) NEW = NCFG IF (NZERO .EQ. 0) THEN NZERO = NCFG IFIRST = 0 ELSE IFIRST = 1 END IF * IALL = 1 * * Initialize parameters for output * NIJ = 0 lcount = 0 nrec = 0 * .. allocate memory for buffered i/o call alloc(qcn,lsdim,8) call alloc(qpackn,lsdim,4) call alloc(qjan,lsdim,4) call alloc(qjbn,lsdim,4) * CALL ANGMOM(NEW,NZERO,IFIRST) * * .. clear arrays which have not been written to disk iou = 9+ik n = lcount if (n .ne. 0) then write(isc3) (cn(j),j=1,n), (ipackn(j),j=1,n), : (jan(j),j=1,n),(jbn(j),j=1,n) end if rewind(isc3) * * deallocate the arrays that will not be used any longer call dalloc(qcn,lsdim) call dalloc(qpackn,lsdim) call dalloc(qjan,lsdim) call dalloc(qjbn,lsdim) nl = nrec*lsdim + lcount * .. we are not taking advantage of the fact that the number * of integrals could be up to an order of magnitude less than * the number of coefficients. This could be done with a * "realloc" after the call to outls if deemed important. if (ik.eq. 1) then call alloc(qintgrl1,nl,4) call alloc(qintptr1,nl,4) call alloc(qcnn1,nl,8) call alloc(qjann1,nl,4) call alloc(qjbnn1,nl,4) call outls(intgrl1,nint1,intptr1,cnn1,ncoef1,jann1,jbnn1) nint = nint1 ncoef = ncoef1 else call alloc(qintgrl2,nl,4) call alloc(qintptr2,nl,4) call alloc(qcnn2,nl,8) call alloc(qjann2,nl,4) call alloc(qjbnn2,nl,4) call outls(intgrl2,nint2,intptr2,cnn2,ncoef2,jann2,jbnn2) nint = nint2 ncoef = ncoef2 end if write(iscw,'(I10, A)') nij, ' non-zero matrix elements' write(iscw,'(I10, A)') ncoef, ' number of L(i,j) coefficients' write(iscw,'(I10, A)') nint, ' number of L(i,j) integrals' CLOSE (ISC3) * Obtain n and l values of the orbital for the initial (or the final state) * and check if the order found by nonh satisfies the built-in RAS order. * (We might be in trouble with the (j.leq.i) selection of savels otherwise.) print*,' ik = ',ik,' maxorb = ',maxorb print*,' njcomp = ',njcomp print*,' ljcomp = ',ljcomp if (ik.eq.1) then lmx1 = 0 do i = 1,maxorb nq1(i) = njcomp(i) lq1(i) = ljcomp(i) if (lq1(i).gt.lmx1) lmx1 = lq1(i) write(*,*) ' Initial Orbital n l',nq1(i),lq1(i) end do call rscheck(nq1,lq1,lmx1,maxorb) else lmx2 = 0 do i = 1,maxorb nq2(i) = njcomp(i) lq2(i) = ljcomp(i) if (lq2(i).gt.lmx2) lmx2 = lq1(i) write(*,*) ' Final Orbital n l',nq2(i),lq2(i) end do call rscheck(nq2,lq2,lmx2,maxorb) endif * Here, one can now deallocate print*,' dalloc, qnjcomp: maxorb = ',maxorb call dalloc(qnjcomp,maxorb) print*,' dalloc, qljcomp: maxorb = ',maxorb call dalloc(qljcomp,maxorb) * Lets do some debugging on files 'debug1/2' * (but only if needed!) !if(ibugm.eq.0) go to 6 if (ik .eq. 1) then !open(unit=21,file='debug1',status='unknown') !write (21,*) ' Data for l.h.s.' !write (21,*) nint1, ' Integrals' do i = 1,nint1 lv = intgrl1(i) iv = mod(lv,64) lv = lv/64 jv = mod(lv,64) lv = lv/64 !write(21,'(4I6)') lv,jv,iv, intptr1(I) end do !write(22,*) ncoef2, ' Coefficients' !write(22,'(F12.8,2I6)') ! : (cnn1(j),jann1(j),jbnn1(j),j=1,ncoef1) !close(21) ! open(unit=50,file='st1.lst',form='unformatted'); ! write(50) ncoef ! write(50) nint1 ! write(50) (intptr1(I),intgrl1(i),i=1,nint1); ! write(50) (cnn1(j),jann1(j),jbnn1(j),j=1,ncoef) ! close(50) else !open(unit=22,file='debug2',status='unknown') !write(22,*) !write (22,*) ' Data for r.h.s.' !write (22,*) nint2, ' Integrals' do i = 1,nint2 lv = intgrl2(i) iv = mod(lv,64) lv = lv/64 jv = mod(lv,64) lv = lv/64 ! write(22,'(4I6)') lv,jv,iv, intptr2(I) end do ! write(22,*) ncoef2, ' Coefficients' ! write(22,'(F12.8,2I6)') ! : (cnn2(j),jann2(j),jbnn2(j),j=1,ncoef2) ! close(22) ! open(unit=50,file='st2.lst',form='unformatted'); ! write(50) ncoef ! write(50) nint2 ! write(50) (intptr2(I),intgrl2(i),i=1,nint2); ! write(50) (cnn2(j),jann2(j),jbnn2(j),j=1,ncoef2) ! close(50) end if !write(ff,'(A1)') ik 6 write(iscw,'(//A/A//)') ' END OF NON',' ==========' END
(* Author: Tobias Nipkow *) section "Swapping Adjacent Elements in a List" theory Swaps imports Inversion begin text\<open>Swap elements at index \<open>n\<close> and @{term "Suc n"}:\<close> definition "swap n xs = (if Suc n < size xs then xs[n := xs!Suc n, Suc n := xs!n] else xs)" lemma length_swap[simp]: "length(swap i xs) = length xs" by(simp add: swap_def) lemma swap_id[simp]: "Suc n \<ge> size xs \<Longrightarrow> swap n xs = xs" by(simp add: swap_def) lemma distinct_swap[simp]: "distinct(swap i xs) = distinct xs" by(simp add: swap_def) lemma swap_Suc[simp]: "swap (Suc n) (a # xs) = a # swap n xs" by(induction xs) (auto simp: swap_def) lemma index_swap_distinct: "distinct xs \<Longrightarrow> Suc n < length xs \<Longrightarrow> index (swap n xs) x = (if x = xs!n then Suc n else if x = xs!Suc n then n else index xs x)" by(auto simp add: swap_def index_swap_if_distinct) lemma set_swap[simp]: "set(swap n xs) = set xs" by(auto simp add: swap_def set_conv_nth nth_list_update) metis lemma nth_swap_id[simp]: "Suc i < length xs \<Longrightarrow> swap i xs ! i = xs!(i+1)" by(simp add: swap_def) lemma before_in_swap: "dist_perm xs ys \<Longrightarrow> Suc n < size xs \<Longrightarrow> x < y in (swap n xs) \<longleftrightarrow> x < y in xs \<and> \<not> (x = xs!n \<and> y = xs!Suc n) \<or> x = xs!Suc n \<and> y = xs!n" by(simp add:before_in_def index_swap_distinct) (metis Suc_lessD Suc_lessI index_less_size_conv index_nth_id less_Suc_eq n_not_Suc_n nth_index) lemma Inv_swap: assumes "dist_perm xs ys" shows "Inv xs (swap n ys) = (if Suc n < size xs then if ys!n < ys!Suc n in xs then Inv xs ys \<union> {(ys!n, ys!Suc n)} else Inv xs ys - {(ys!Suc n, ys!n)} else Inv xs ys)" proof- have "length xs = length ys" using assms by (metis distinct_card) with assms show ?thesis by(simp add: Inv_def set_eq_iff) (metis before_in_def not_before_in before_in_swap) qed text\<open>Perform a list of swaps, from right to left:\<close> abbreviation swaps where "swaps == foldr swap" lemma swaps_inv[simp]: "set (swaps sws xs) = set xs \<and> size(swaps sws xs) = size xs \<and> distinct(swaps sws xs) = distinct xs" by (induct sws arbitrary: xs) (simp_all add: swap_def) lemma swaps_eq_Nil_iff[simp]: "swaps acts xs = [] \<longleftrightarrow> xs = []" by(induction acts)(auto simp: swap_def) lemma swaps_map_Suc[simp]: "swaps (map Suc sws) (a # xs) = a # swaps sws xs" by(induction sws arbitrary: xs) auto lemma card_Inv_swaps_le: "distinct xs \<Longrightarrow> card (Inv xs (swaps sws xs)) \<le> length sws" by(induction sws) (auto simp: Inv_swap card_insert_if card_Diff_singleton_if) lemma nth_swaps: "\<forall>i\<in>set is. j < i \<Longrightarrow> swaps is xs ! j = xs ! j" by(induction "is")(simp_all add: swap_def) lemma not_before0[simp]: "~ x < xs ! 0 in xs" apply(cases "xs = []") by(auto simp: before_in_def neq_Nil_conv) lemma before_id[simp]: "\<lbrakk> distinct xs; i < size xs; j < size xs \<rbrakk> \<Longrightarrow> xs ! i < xs ! j in xs \<longleftrightarrow> i < j" by(simp add: before_in_def index_nth_id) lemma before_swaps: "\<lbrakk> distinct is; \<forall>i\<in>set is. Suc i < size xs; distinct xs; i \<notin> set is; i < j; j < size xs \<rbrakk> \<Longrightarrow> swaps is xs ! i < swaps is xs ! j in xs" apply(induction "is" arbitrary: i j) apply simp apply(auto simp: swap_def nth_list_update) done lemma card_Inv_swaps: "\<lbrakk> distinct is; \<forall>i\<in>set is. Suc i < size xs; distinct xs \<rbrakk> \<Longrightarrow> card(Inv xs (swaps is xs)) = length is" apply(induction "is") apply simp apply(simp add: Inv_swap before_swaps card_insert_if) apply(simp add: Inv_def) done lemma swaps_eq_nth_take_drop: "i < length xs \<Longrightarrow> swaps [0..<i] xs = xs!i # take i xs @ drop (Suc i) xs" apply(induction i arbitrary: xs) apply (auto simp add: neq_Nil_conv swap_def drop_update_swap take_Suc_conv_app_nth Cons_nth_drop_Suc[symmetric]) done lemma index_swaps_size: "distinct s \<Longrightarrow> index s q \<le> index (swaps sws s) q + length sws" apply(induction sws arbitrary: s) apply simp apply (fastforce simp: swap_def index_swap_if_distinct index_nth_id) done lemma index_swaps_last_size: "distinct s \<Longrightarrow> size s \<le> index (swaps sws s) (last s) + length sws + 1" apply(cases "s = []") apply simp using index_swaps_size[of s "last s" sws] by simp end
subroutine upwhu(j ,nmmaxj ,nmmax ,kmax ,icx , & & zmodel ,kcs ,kcu ,kspu ,dps , & & s0 ,dpu ,umean ,hu ,gdp ) !----- GPL --------------------------------------------------------------------- ! ! Copyright (C) Stichting Deltares, 2011-2016. ! ! This program is free software: you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation version 3. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! ! contact: [email protected] ! Stichting Deltares ! P.O. Box 177 ! 2600 MH Delft, The Netherlands ! ! All indications and logos of, and references to, "Delft3D" and "Deltares" ! are registered trademarks of Stichting Deltares, and remain the property of ! Stichting Deltares. All rights reserved. ! !------------------------------------------------------------------------------- ! $Id: upwhu.f90 5717 2016-01-12 11:35:24Z mourits $ ! $HeadURL: https://svn.oss.deltares.nl/repos/delft3d/tags/6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute/upwhu.f90 $ !!--description----------------------------------------------------------------- ! ! Function: Switch which makes it possible to use ! upwind-approach for wet cross section in shallow ! areas or if the model area contains structures. ! Method used: ! !!--pseudo code and references-------------------------------------------------- ! NONE !!--declarations---------------------------------------------------------------- use precision use globaldata use dfparall ! implicit none ! type(globdat),target :: gdp ! ! The following list of pointer parameters is used to point inside the gdp structure ! real(fp) , pointer :: dco real(fp) , pointer :: dgcuni logical , pointer :: nonhyd character(8) , pointer :: dpuopt character(6) , pointer :: momsol integer , pointer :: nh_level ! ! Global variables ! integer , intent(in) :: icx !! Increment in the X-dir., if ICX= NMAX then computation proceeds in the X-dir. If icx=1 then computation proceeds in the Y-dir. integer :: j !! Begin pointer for arrays which have been transformed into 1D arrays. Due to the shift in the 2nd (M-) index, J = -2*NMAX + 1 integer , intent(in) :: kmax ! Description and declaration in esm_alloc_int.f90 integer , intent(in) :: nmmax ! Description and declaration in dimens.igs integer :: nmmaxj ! Description and declaration in dimens.igs integer , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: kcs ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: kcu ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub, 0:kmax) , intent(in) :: kspu ! Description and declaration in esm_alloc_int.f90 logical , intent(in) :: zmodel ! Description and declaration in procs.igs real(prec) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: dps ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: dpu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: hu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: s0 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: umean ! Description and declaration in esm_alloc_real.f90 ! ! Local variables ! integer :: nm ! Counter for loop 1,NMMAX integer :: nmd integer :: nmu integer :: nmuu real(fp) :: ds1 real(fp) :: ds2 real(fp) :: h1 real(fp) :: h2 real(fp) :: level real(fp) , external :: slim integer :: nm_pos ! indicating the array to be exchanged has nm index at the 2nd place, e.g., dbodsd(lsedtot,nm) ! !! executable statements ------------------------------------------------------- ! dco => gdp%gdnumeco%dco dgcuni => gdp%gdnumeco%dgcuni nonhyd => gdp%gdprocs%nonhyd dpuopt => gdp%gdnumeco%dpuopt momsol => gdp%gdnumeco%momsol nh_level => gdp%gdnonhyd%nh_level nm_pos = 1 ! ! In case DPUOPT = 'UPW' apply upwind approach for for the total ! water depth. This implies that upwind also applies for DPU (both ! in SIGMA and Z-model) ! Reference: "A staggered conservative scheme for every Froude ! number in rapidly varied shallow water flows"; by ! GS Stelling and SPA Duijnmeijer ! if (dpuopt=='UPW' .and. momsol /= 'finvol') then do nm = 1, nmmax nmu = nm + icx if (kcu(nm)==1) then if (umean(nm)>=0.001) then dpu(nm) = real(dps(nm),fp) elseif (umean(nm)<= - 0.001) then dpu(nm) = real(dps(nmu),fp) else dpu(nm) = min(real(dps(nmu),fp), real(dps(nm),fp)) endif endif enddo ! ! exchange depth with neighbours for parallel runs ! call dfexchg ( dpu, 1, 1, dfloat, nm_pos, gdp ) endif ! ! Apply Upwind of water level if: ! - HU(initial) < DCO (in Z-model not yet tested) OR ! - KSPU > 0 (in Z-model not yet tested) OR ! - DPUOPT = 'UPW' ! ! Start by computing HU(initial) and see whether it is < DCO value ! and upwind should be applied (one of the criteria above). ! ! In SIGMA case HU(initial) is computed with the mean water level ! In Z-model HU(initial) is always computed with the upwind ! formulation for the water level ! HU must always be computed, even if KCU is not 1 ! condition ! do nm = 1, nmmax nmu = nm + icx if (zmodel) then if (nonhyd .and. nh_level==nh_full) then hu(nm) = 0.5_fp*(s0(nm) + s0(nmu)) + dpu(nm) else hu(nm) = max(s0(nmu), s0(nm)) + dpu(nm) endif else hu(nm) = 0.5_fp*(s0(nm) + s0(nmu)) + dpu(nm) endif if (kcu(nm) == 1) then if ( hu(nm) < dco .or. & & kspu(nm, 0) > 0 .or. & & dpuopt == 'UPW' .or. & & zmodel ) then if (umean(nm) > 0.001_fp) then hu(nm) = s0(nm) + dpu(nm) elseif (umean(nm) < -0.001_fp) then hu(nm) = s0(nmu) + dpu(nm) else hu(nm) = max(s0(nmu), s0(nm)) + dpu(nm) endif endif ! ! HU determination for flooding option ! Special approach for steep bottom slopes ! if (momsol=='flood ') then if (umean(nm) >= 0.001_fp) then nmd = nm - icx ds1 = (s0(nm )-s0(nmd)) * kcu(nmd) ds2 = (s0(nmu)-s0(nm )) * kcu(nm ) if (kspu(nm,0)>0 .or. kspu(nmd,0)>0) then ds2 = 0.0_fp endif level= s0(nm) + slim(ds1,ds2) hu(nm) = level + dpu(nm) if (real(dps(nm),fp) > real(dps(nmu),fp)+dgcuni) then h1 = 2.0_fp * hu(nm) / 3.0_fp h2 = s0(nmu) + dpu(nm) hu(nm) = MIN(hu(nm) , MAX(h1,h2)) endif elseif (umean(nm) <= - 0.001_fp) then nmuu = nmu + icx ds1 = (s0(nmuu)-s0(nmu)) * kcu(nmu) ds2 = (s0(nmu )-s0(nm )) * kcu(nm ) if (kspu(nm,0)>0 .or. kspu(nmu,0)>0) then ds2 = 0.0_fp endif level = s0(nmu) - slim(ds1,ds2) hu(nm) = level + dpu(nm) if (real(dps(nm),fp)+dgcuni < real(dps(nmu),fp)) then h1 = 2.0_fp * hu(nm) / 3.0_fp h2 = s0(nm) + dpu(nm) hu(nm) = MIN(hu(nm) , MAX(h1,h2)) endif else hu(nm) = dpu(nm) + MAX(s0(nmu),s0(nm)) endif endif endif enddo ! ! exchange height with neighbours for parallel runs ! call dfexchg ( hu, 1, 1, dfloat, nm_pos, gdp ) call upwhu_dd(j ,nmmaxj ,nmmax ,kmax ,icx , & & zmodel ,kcs ,kcu ,kspu ,dps , & & s0 ,dpu ,umean ,hu ,gdp ) end subroutine upwhu
Boating can be a bit challenging within Davis because there are so few large bodies of water within city limits most of the water in town is suitable only for paddle boating handlaunched vessels. Typically, rowing sculls and power boating must be done outside of Davis. Despite the dearth of suitable locations for the various types of boating, it remains a popular activity within our populace, so here we attempt to provide a listing of nearby waterways in which to boat. In Davis Flat Water Paddling Arboretum Putah Creek Stonegate Lake (Stonegate Country Club members only.) Local Not so far away... less than twenty miles Flat Water Paddling Lake Solano County Park wiki:westsac:Port of Sacramento Sacramento River Rowing Sculls wiki:westsac:Port of Sacramento Washington basin Sailing Davis Sailing Team http://lwsailing.org / Lake Washington Sailing Club Power Boating Sacramento River Regional Somewhat farther afield Flat Water Paddling http://www.parks.ca.gov/default.asp?page_id500 Lake Natoma / http://www.sacstateaquaticcenter.com Sac State Aquatic Center (Kayak rentals for cheap!) Cache Creek Folsom Lake Lake Berryessa Lake Hennessey http://www.parks.ca.gov/default.asp?page_id500 Lake Natoma (http://www.paddling.net/places/showReport.html?747 trip report) The Delta Sacramento/San Joaquin Delta Tower Park Float Tubes Tubing Float tubes (innertubes) provide the ultimate economy & simplicity in personal watercraft. White Water see Rafting American River Cache Creek Putah Creek Rowing Sculls http://www.parks.ca.gov/default.asp?page_id500 Lake Natoma Sailing http://www.sacstateaquaticcenter.com Sac State Aquatic Center Take a class, or private lesson to rent a Laser, Pico, Holder 14 or Holder 20 Keelboats. Sailing club membership allows unlimited access. Power Boating American River Folsom Lake Lake Berryessa Ocean San Francisco Bay Tomales Bay Sonoma Coast Bodega Bay Beaches provides driving directions and a brief description of some access points for ocean beaches and some river beaches Resources http://brtinsights.blogspot.com/ BRT Kayaking California river guides, trip reports, photos, techniques, book reviews. http://www.cacreeks.com/ California Creeks is a guide to many California rivers http://groups.google.com/group/daviskayakers DavisKayakers Group This is an attempt to gather local kayakers together so that we can meet each others, plan trips, learn/teach each others, share stories and have a good time. Davis Racing Dragons is a campus group that paddles big racing boats Houseboats offers information on the UC Davis houseboating tradition http://www.kevsmom.com/ Kevs Mom has great information on river running & the site owner has strong connections to Davis Outdoor Adventures staff can provide lots of firsthand information on local waters and their site has additional information http://www.raftwet.com/Americanriver.html Raft Wet http://www.rivercityrowing.org/ River City Rowing Club is a private Sacramento rowing club UC Davis Crew is UC Davis rowing club http://www.aorafting.com/river/southforkamerican/welcome.htm SF American river trips AllOutdoors Rafting http://www.caliriver.com/tuolumne/ Tuolumne river rafting information 20051116 10:27:08 nbsp I wonder how paddling and boating should work together. Right now theyre very similar but I guess that they can stay seperate if they both get more information. In the future we might have a motor boating page, a paddling page, a waterskiing page, .... Users/JackHaskel Seems like paddling, motorboating, sailing, etc. ought to be subsets of boating. 20060605 19:24:51 nbsp I recommend Tower Park in the Sacramento Delta, it can be reached on HWY 12 from either end of the Delta. A campground, secluded inlet with docks, and a launch ramp not too far away. Users/KarlMogel 20070419 07:11:29 nbsp im a new transplant to cali and davis...but does anyone know of opportunities for sailing and friendly regattas that are within an hours drive time? i mean 420s, FJs, Mumm 30s, J22s, Melges 24, hobie cats etc. cheers! Users/AshleyMarie 20090720 14:13:32 nbsp Hi AshleyMarie. Im from the Davis Sailing Team. Are you a student? If so wed love to have you on the team. We race CFJs and Lasers on the collegiate circuit. If you are not a student we can set you up with our host club, Lake Washington Sailing Club, which is only 20 min away in West Sac. They have beercans every Thursday in the summer and regattas through out the year. Users/jadeeyes1113
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Int.Base where open import Cubical.Core.Everything open import Cubical.Data.Nat data ℤ : Type₀ where pos : (n : ℕ) → ℤ negsuc : (n : ℕ) → ℤ neg : (n : ℕ) → ℤ neg zero = pos zero neg (suc n) = negsuc n infix 100 -_ -_ : ℕ → ℤ -_ = neg {-# DISPLAY pos n = n #-} {-# DISPLAY negsuc n = - (suc n) #-} sucInt : ℤ → ℤ sucInt (pos n) = pos (suc n) sucInt (negsuc zero) = pos zero sucInt (negsuc (suc n)) = negsuc n predInt : ℤ → ℤ predInt (pos zero) = negsuc zero predInt (pos (suc n)) = pos n predInt (negsuc n) = negsuc (suc n) -- Natural number and negative integer literals for ℤ open import Cubical.Data.Nat.Literals public instance fromNatℤ : FromNat ℤ fromNatℤ = record { Constraint = λ _ → ⊤ ; fromNat = λ n → pos n } instance negativeℤ : Negative ℤ negativeℤ = record { Constraint = λ _ → ⊤ ; fromNeg = λ n → neg n }
/* main.h: contains all forward declarations and necessary includes */ #ifndef MAIN_H #define MAIN_H #define DEBUG false #include <cstdlib> #include <iostream> #include <string> #include <cmath> #include <list> #include <ctime> #include <unistd.h> #include <gsl/gsl_rng.h> using namespace std; extern gsl_rng *r; // global random number generator: class Agent; // a thinking human agent class Link; // a link between two agents bool validLink(Agent* agent1, Agent* agent2, list<Link> &relation); // returns false if the Agents are the same or already linked void removeLink(Agent* agent1, Agent* agent2, list<Link> &relation); // searches for and removes the link between two agents void printXML(int nr_of_agents, list<Link> &relation); // prints XML output void printDOT(list<Link> &relation); // prints GraphViz DOT output double connectivity(); // TODO: returns some statistic indicating the fat-tailness of the connectivity distribution double assortativity(list<Link> &relation); // returns the assortativity coefficient of the network double clustering(int nr_of_agents, Agent population[], list<Link> &relation); // returns the global clustering coefficient bool exists(Agent* target, list<Agent*> &agents); // returns true if the target is in the list of agents double avgpath(int nr_of_agents, Agent population[]); // returns the average path length #endif // MAIN_H
= = = U21 squad = = =
(* Copyright (C) 2007--2010 Norbert Schirmer * All rights reserved, DFKI GmbH *) theory ReduceStoreBufferSimulation imports ReduceStoreBuffer begin (* FIXME: a lot of theorems that now have sharing_consistent as precondition, may as well work with weak_sharing_consistent *) locale initial\<^sub>s\<^sub>b = simple_ownership_distinct + read_only_unowned + unowned_shared + constrains ts::"('p,'p store_buffer,bool,owns,rels) thread_config list" assumes empty_sb: "\<lbrakk>i < length ts; ts!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<rbrakk> \<Longrightarrow> sb=[]" assumes empty_is: "\<lbrakk>i < length ts; ts!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<rbrakk> \<Longrightarrow> is=[]" assumes empty_rels: "\<lbrakk>i < length ts; ts!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<rbrakk> \<Longrightarrow> \<R>=Map.empty" sublocale initial\<^sub>s\<^sub>b \<subseteq> outstanding_non_volatile_refs_owned_or_read_only proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "non_volatile_owned_or_read_only False \<S> \<O> sb" using empty_sb [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> outstanding_volatile_writes_unowned_by_others proof fix i j p\<^sub>i is\<^sub>i \<O>\<^sub>i \<R>\<^sub>i \<D>\<^sub>i \<theta>\<^sub>i sb\<^sub>i p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume i_bound: "i < length ts" and j_bound: "j < length ts" and neq_i_j: "i \<noteq> j" and ts_i: "ts ! i = (p\<^sub>i, is\<^sub>i, \<theta>\<^sub>i, sb\<^sub>i, \<D>\<^sub>i, \<O>\<^sub>i, \<R>\<^sub>i)" and ts_j: "ts ! j = (p\<^sub>j, is\<^sub>j, \<theta>\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j, \<R>\<^sub>j)" show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>i = {}" using empty_sb [OF i_bound ts_i] empty_sb [OF j_bound ts_j] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> read_only_reads_unowned proof fix i j p\<^sub>i is\<^sub>i \<O>\<^sub>i \<R>\<^sub>i \<D>\<^sub>i \<theta>\<^sub>i sb\<^sub>i p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume i_bound: "i < length ts" and j_bound: "j < length ts" and neq_i_j: "i \<noteq> j" and ts_i: "ts ! i = (p\<^sub>i, is\<^sub>i, \<theta>\<^sub>i, sb\<^sub>i, \<D>\<^sub>i, \<O>\<^sub>i, \<R>\<^sub>i)" and ts_j: "ts ! j = (p\<^sub>j, is\<^sub>j, \<theta>\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j, \<R>\<^sub>j)" show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>i) \<O>\<^sub>i) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>i) = {}" using empty_sb [OF i_bound ts_i] empty_sb [OF j_bound ts_j] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> ownership_distinct proof fix i j p\<^sub>i is\<^sub>i \<O>\<^sub>i \<R>\<^sub>i \<D>\<^sub>i \<theta>\<^sub>i sb\<^sub>i p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume i_bound: "i < length ts" and j_bound: "j < length ts" and neq_i_j: "i \<noteq> j" and ts_i: "ts ! i = (p\<^sub>i, is\<^sub>i, \<theta>\<^sub>i, sb\<^sub>i, \<D>\<^sub>i, \<O>\<^sub>i, \<R>\<^sub>i)" and ts_j: "ts ! j = (p\<^sub>j, is\<^sub>j, \<theta>\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j, \<R>\<^sub>j)" show "(\<O>\<^sub>i \<union> all_acquired sb\<^sub>i) \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {}" using simple_ownership_distinct [OF i_bound j_bound neq_i_j ts_i ts_j] empty_sb [OF i_bound ts_i] empty_sb [OF j_bound ts_j] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_ownership .. sublocale initial\<^sub>s\<^sub>b \<subseteq> outstanding_non_volatile_writes_unshared proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "non_volatile_writes_unshared \<S> sb" using empty_sb [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> sharing_consis proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "sharing_consistent \<S> \<O> sb" using empty_sb [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> no_outstanding_write_to_read_only_memory proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "no_write_to_read_only_memory \<S> sb" using empty_sb [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_sharing .. sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_ownership_and_sharing .. sublocale initial\<^sub>s\<^sub>b \<subseteq> load_tmps_distinct proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "distinct_load_tmps is" using empty_is [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> read_tmps_distinct proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "distinct_read_tmps sb" using empty_sb [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> load_tmps_read_tmps_distinct proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "load_tmps is \<inter> read_tmps sb = {}" using empty_sb [OF i_bound ts_i] empty_is [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> load_tmps_read_tmps_distinct .. sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_write_sops proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "\<forall>sop \<in> write_sops sb. valid_sop sop" using empty_sb [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_store_sops proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "\<forall>sop \<in> store_sops is. valid_sop sop" using empty_is [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_sops .. sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_reads proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "reads_consistent False \<O> m sb" using empty_sb [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_history proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "program.history_consistent program_step \<theta> (hd_prog p sb) sb" using empty_sb [OF i_bound ts_i] by (auto simp add: program.history_consistent.simps) qed sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_data_dependency proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "data_dependency_consistent_instrs (dom \<theta>) is" using empty_is [OF i_bound ts_i] by auto next fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "load_tmps is \<inter> \<Union>(fst ` write_sops sb) = {}" using empty_is [OF i_bound ts_i] empty_sb [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> load_tmps_fresh proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "load_tmps is \<inter> dom \<theta> = {}" using empty_is [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> enough_flushs proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}" using empty_sb [OF i_bound ts_i] by auto qed sublocale initial\<^sub>s\<^sub>b \<subseteq> valid_program_history proof fix i "is" \<O> \<R> \<D> \<theta> sb p sb\<^sub>1 sb\<^sub>2 assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" assume sb: "sb=sb\<^sub>1@sb\<^sub>2" show "\<exists>isa. instrs sb\<^sub>2 @ is = isa @ prog_instrs sb\<^sub>2" using empty_sb [OF i_bound ts_i] empty_is [OF i_bound ts_i] sb by auto next fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "last_prog p sb = p" using empty_sb [OF i_bound ts_i] by auto qed inductive sim_config:: "('p,'p store_buffer,bool,owns,rels) thread_config list \<times> memory \<times> shared \<Rightarrow> ('p, unit,bool,owns,rels) thread_config list \<times> memory \<times> shared \<Rightarrow> bool" ("_ \<sim> _" [60,60] 100) where "\<lbrakk>m = flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b; \<S> = share_all_until_volatile_write ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b; length ts\<^sub>s\<^sub>b = length ts; \<forall>i < length ts\<^sub>s\<^sub>b. let (p, is\<^sub>s\<^sub>b, \<theta>, sb, \<D>\<^sub>s\<^sub>b, \<O>, \<R>) = ts\<^sub>s\<^sub>b!i; suspends = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb in \<exists>is \<D>. instrs suspends @ is\<^sub>s\<^sub>b = is @ prog_instrs suspends \<and> \<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb \<noteq> {}) \<and> ts!i = (hd_prog p suspends, is, \<theta> |` (dom \<theta> - read_tmps suspends),(), \<D>, acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>, release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) (dom \<S>\<^sub>s\<^sub>b) \<R> ) \<rbrakk> \<Longrightarrow> (ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" text \<open>The machine without history only stores writes in the store-buffer.\<close> inductive sim_history_config:: "('p,'p store_buffer,'dirty,'owns,'rels) thread_config list \<Rightarrow> ('p,'p store_buffer,bool,owns,rels) thread_config list \<Rightarrow> bool" ("_ \<sim>\<^sub>h _ " [60,60] 100) where "\<lbrakk>length ts = length ts\<^sub>h; \<forall>i < length ts. (\<exists>\<O>' \<D>' \<R>'. let (p,is, \<theta>, sb,\<D>, \<O>,\<R>) = ts\<^sub>h!i in ts!i=(p,is, \<theta>, filter is_Write\<^sub>s\<^sub>b sb,\<D>',\<O>',\<R>') \<and> (filter is_Write\<^sub>s\<^sub>b sb = [] \<longrightarrow> sb=[])) \<rbrakk> \<Longrightarrow> ts \<sim>\<^sub>h ts\<^sub>h" lemma (in initial\<^sub>s\<^sub>b) history_refl:"ts \<sim>\<^sub>h ts" apply - apply (rule sim_history_config.intros) apply simp apply clarsimp subgoal for i apply (case_tac "ts!i") apply (drule_tac i=i in empty_sb) apply assumption apply auto done done lemma share_all_empty: "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts \<longrightarrow> ts!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[] \<Longrightarrow> share_all_until_volatile_write ts \<S> = \<S>" apply (induct ts) apply clarsimp apply clarsimp apply (frule_tac x=0 in spec) apply clarsimp apply force done lemma flush_all_empty: "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts \<longrightarrow> ts!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[] \<Longrightarrow> flush_all_until_volatile_write ts m = m" apply (induct ts) apply clarsimp apply clarsimp apply (frule_tac x=0 in spec) apply clarsimp apply force done lemma sim_config_emptyE: assumes empty: "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[]" assumes sim: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" shows "\<S> = \<S>\<^sub>s\<^sub>b \<and> m = m\<^sub>s\<^sub>b \<and> length ts = length ts\<^sub>s\<^sub>b \<and> (\<forall>i < length ts\<^sub>s\<^sub>b. let (p, is, \<theta>, sb, \<D>, \<O>, \<R>) = ts\<^sub>s\<^sub>b!i in ts!i = (p, is, \<theta>, (), \<D>, \<O>, \<R>))" proof - from sim show ?thesis apply cases apply (clarsimp simp add: flush_all_empty [OF empty] share_all_empty [OF empty]) subgoal for i apply (drule_tac x=i in spec) apply (cut_tac i=i in empty [rule_format]) apply clarsimp apply assumption apply (auto simp add: Let_def) done done qed lemma sim_config_emptyI: assumes empty: "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[]" assumes leq: "length ts = length ts\<^sub>s\<^sub>b" assumes ts: "(\<forall>i < length ts\<^sub>s\<^sub>b. let (p, is, \<theta>, sb, \<D>, \<O>, \<R>) = ts\<^sub>s\<^sub>b!i in ts!i = (p, is, \<theta>, (), \<D>, \<O>, \<R>))" shows "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b)" apply (rule sim_config.intros) apply (simp add: flush_all_empty [OF empty]) apply (simp add: share_all_empty [OF empty]) apply (simp add: leq) apply (clarsimp) apply (frule (1) empty [rule_format]) using ts apply (auto simp add: Let_def) done lemma mem_eq_un_eq: "\<lbrakk>length ts'=length ts; \<forall>i< length ts'. P (ts'!i) = Q (ts!i) \<rbrakk> \<Longrightarrow> (\<Union>x\<in>set ts'. P x) = (\<Union>x\<in>set ts. Q x)" apply (auto simp add: in_set_conv_nth ) apply (force dest!: nth_mem) apply (frule nth_mem) subgoal for x i apply (drule_tac x=i in spec) apply auto done done (* FIXME: move up *) lemma (in program) trace_to_steps: assumes trace: "trace c 0 k" shows steps: "c 0 \<Rightarrow>\<^sub>d\<^sup>* c k" using trace proof (induct k) case 0 show "c 0 \<Rightarrow>\<^sub>d\<^sup>* c 0" by auto next case (Suc k) have prem: "trace c 0 (Suc k)" by fact hence "trace c 0 k" by (auto simp add: program_trace_def) from Suc.hyps [OF this] have "c 0 \<Rightarrow>\<^sub>d\<^sup>* c k" . also term program_trace from prem interpret program_trace program_step c 0 "Suc k" . from step [of k] have "c (k) \<Rightarrow>\<^sub>d c (Suc k)" by auto finally show ?case . qed lemma (in program) safe_reach_to_safe_reach_upto: assumes safe_reach: "safe_reach_direct safe c\<^sub>0" shows "safe_reach_upto n safe c\<^sub>0" proof fix k c l assume k_n: "k \<le> n" assume trace: "trace c 0 k" assume c_0: "c 0 = c\<^sub>0" assume l_k: "l \<le> k" show "safe (c l)" proof - from trace k_n l_k have trace': "trace c 0 l" by (auto simp add: program_trace_def) from trace_to_steps [OF trace'] have "c 0 \<Rightarrow>\<^sub>d\<^sup>* c l". with safe_reach c_0 show "safe (c l)" by (cases "c l") (auto simp add: safe_reach_def) qed qed lemma (in program_progress) safe_free_flowing_implies_safe_delayed': assumes init: "initial\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b" assumes sim: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" assumes safe_reach_ff: "safe_reach_direct safe_free_flowing (ts,m,\<S>)" shows "safe_reach_direct safe_delayed (ts,m,\<S>)" proof - from init interpret ini: initial\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b . from sim obtain m: "m = flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b" and \<S>: "\<S> = share_all_until_volatile_write ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b" and leq: "length ts\<^sub>s\<^sub>b = length ts" and t_sim: "\<forall>i < length ts\<^sub>s\<^sub>b. let (p, is\<^sub>s\<^sub>b, \<theta>, sb, \<D>\<^sub>s\<^sub>b, \<O>, \<R>) = ts\<^sub>s\<^sub>b!i; suspends = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb in \<exists>is \<D>. instrs suspends @ is\<^sub>s\<^sub>b = is @ prog_instrs suspends \<and> \<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb \<noteq> {}) \<and> ts!i = (hd_prog p suspends, is, \<theta> |` (dom \<theta> - read_tmps suspends),(), \<D>, acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>, release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) (dom \<S>\<^sub>s\<^sub>b) \<R> )" by cases auto from ini.empty_sb have shared_eq: "\<S> = \<S>\<^sub>s\<^sub>b" apply (simp only: \<S>) apply (rule share_all_empty) apply force done have sd: "simple_ownership_distinct ts" proof fix i j p\<^sub>i is\<^sub>i \<O>\<^sub>i \<R>\<^sub>i \<D>\<^sub>i \<theta>\<^sub>i sb\<^sub>i p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume i_bound: "i < length ts" and j_bound: "j < length ts" and neq_i_j: "i \<noteq> j" and ts_i: "ts ! i = (p\<^sub>i, is\<^sub>i, \<theta>\<^sub>i, sb\<^sub>i, \<D>\<^sub>i, \<O>\<^sub>i, \<R>\<^sub>i)" and ts_j: "ts ! j = (p\<^sub>j, is\<^sub>j, \<theta>\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j, \<R>\<^sub>j)" show "(\<O>\<^sub>i) \<inter> (\<O>\<^sub>j ) = {}" proof - from t_sim [simplified leq, rule_format, OF i_bound] ini.empty_sb [simplified leq, OF i_bound] have ts_i: "ts\<^sub>s\<^sub>b!i = (p\<^sub>i,is\<^sub>i,\<theta>\<^sub>i,[],\<D>\<^sub>i,\<O>\<^sub>i,\<R>\<^sub>i)" using ts_i by (force simp add: Let_def) from t_sim [simplified leq, rule_format, OF j_bound] ini.empty_sb [simplified leq, OF j_bound] have ts_j: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,[],\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" using ts_j by (force simp add: Let_def) from ini.simple_ownership_distinct [simplified leq, OF i_bound j_bound neq_i_j ts_i ts_j] show ?thesis . qed qed have ro: "read_only_unowned \<S> ts" proof fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" show "\<O> \<inter> read_only \<S> = {}" proof - from t_sim [simplified leq, rule_format, OF i_bound] ini.empty_sb [simplified leq, OF i_bound] have ts_i: "ts\<^sub>s\<^sub>b!i = (p,is,\<theta>,[],\<D>,\<O>,\<R>)" using ts_i by (force simp add: Let_def) from ini.read_only_unowned [simplified leq, OF i_bound ts_i] shared_eq show ?thesis by simp qed qed have us: "unowned_shared \<S> ts" proof show "- (\<Union>((\<lambda>(_, _, _, _, _, \<O>, _). \<O>) ` set ts)) \<subseteq> dom \<S>" proof - have "(\<Union>((\<lambda>(_, _, _, _, _, \<O>, _). \<O>) ` set ts\<^sub>s\<^sub>b)) = (\<Union>((\<lambda>(_, _, _, _, _, \<O>, _). \<O>) ` set ts))" apply clarsimp apply (rule mem_eq_un_eq) apply (simp add: leq) apply clarsimp apply (frule t_sim [rule_format]) apply (clarsimp simp add: Let_def) apply (drule (1) ini.empty_sb) apply auto done with ini.unowned_shared show ?thesis by (simp only: shared_eq) qed qed { fix i "is" \<O> \<R> \<D> \<theta> sb p assume i_bound: "i < length ts" assume ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" have "\<R> = Map.empty" proof - from t_sim [simplified leq, rule_format, OF i_bound] ini.empty_sb [simplified leq, OF i_bound] have ts_i: "ts\<^sub>s\<^sub>b!i = (p,is,\<theta>,[],\<D>,\<O>,\<R>)" using ts_i by (force simp add: Let_def) from ini.empty_rels [simplified leq, OF i_bound ts_i] show ?thesis . qed } with us have initial: "initial (ts, m, \<S>)" by (fastforce simp add: initial_def) { fix ts' \<S>' m' assume steps: "(ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>')" have "safe_delayed (ts',m',\<S>')" proof - from steps_to_trace [OF steps] obtain c k where trace: "trace c 0 k" and c_0: "c 0 = (ts,m,\<S>)" and c_k: "c k = (ts',m',\<S>')" by auto from safe_reach_to_safe_reach_upto [OF safe_reach_ff] have safe_upto_k: "safe_reach_upto k safe_free_flowing (ts, m, \<S>)". from safe_free_flowing_implies_safe_delayed [OF _ _ _ _ safe_upto_k, simplified, OF initial sd ro us] have "safe_reach_upto k safe_delayed (ts, m, \<S>)". then interpret program_safe_reach_upto program_step k safe_delayed "(ts,m,\<S>)" . from safe_config [where c=c and k=k and l=k, OF _ trace c_0] c_k show ?thesis by simp qed } then show ?thesis by (clarsimp simp add: safe_reach_def) qed (* FIXME: move up *) lemma map_onws_sb_owned:"\<And>j. j < length ts \<Longrightarrow> map \<O>_sb ts ! j = (\<O>\<^sub>j,sb\<^sub>j) \<Longrightarrow> map owned ts ! j = \<O>\<^sub>j" apply (induct ts) apply simp subgoal for t ts j apply (case_tac j) apply (case_tac t) apply auto done done lemma map_onws_sb_owned':"\<And>j. j < length ts \<Longrightarrow> \<O>_sb (ts ! j) = (\<O>\<^sub>j,sb\<^sub>j) \<Longrightarrow> owned (ts ! j) = \<O>\<^sub>j" apply (induct ts) apply simp subgoal for t ts j apply (case_tac j) apply (case_tac t) apply auto done done (* FIXME: substitutes in application below: read_only_read_acquired_unforwarded_witness*) lemma read_only_read_acquired_unforwarded_acquire_witness: "\<And>\<S> \<O> X.\<lbrakk>non_volatile_owned_or_read_only True \<S> \<O> sb; sharing_consistent \<S> \<O> sb; a \<notin> read_only \<S>; a \<notin> \<O>; a \<in> unforwarded_non_volatile_reads sb X\<rbrakk> \<Longrightarrow>(\<exists>sop a' v ys zs A L R W. sb = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W # zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a' \<noteq> a) \<or> (\<exists>A L R W ys zs. sb = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys)" proof (induct sb) case Nil thus ?case by simp next case (Cons x sb) show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile a' sop v A L R W) show ?thesis proof (cases volatile) case True note volatile=this from Cons.prems obtain nvo': "non_volatile_owned_or_read_only True (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) (\<O> \<union> A - R) sb" and a_nro: "a \<notin> read_only \<S>" and a_unowned: "a \<notin> \<O>" and A_shared_owns: "A \<subseteq> dom \<S> \<union> \<O>" and L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "sharing_consistent (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) (\<O> \<union> A - R) sb" and a_unforw: "a \<in> unforwarded_non_volatile_reads sb (insert a' X)" by (clarsimp simp add: Write\<^sub>s\<^sub>b True) from unforwarded_not_written [OF a_unforw] have a_notin: "a \<notin> insert a' X". hence a'_a: "a' \<noteq> a" by simp from R_owns a_unowned have a_R: "a \<notin> R" by auto show ?thesis proof (cases "a \<in> A") case True then show ?thesis apply - apply (rule disjI1) apply (rule_tac x=sop in exI) apply (rule_tac x=a' in exI) apply (rule_tac x=v in exI) apply (rule_tac x="[]" in exI) apply (rule_tac x=sb in exI) apply (simp add: Write\<^sub>s\<^sub>b volatile True a'_a) done next case False with a_unowned R_owns a_nro L_A A_R obtain a_nro': "a \<notin> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" and a_unowned': "a \<notin> \<O> \<union> A - R" by (force simp add: in_read_only_convs) from Cons.hyps [OF nvo' consis' a_nro' a_unowned' a_unforw] have "(\<exists>sop a' v ys zs A L R W. sb = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W # zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a' \<noteq> a) \<or> (\<exists>A L R W ys zs. sb = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys)" (is "?write \<or> ?ghst") by simp then show ?thesis proof assume ?write then obtain sop' a'' v' ys zs A' L' R' W' where sb: "sb = ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a'' \<noteq> a" by auto show ?thesis using props False a_notin sb apply - apply (rule disjI1) apply (rule_tac x=sop' in exI) apply (rule_tac x=a'' in exI) apply (rule_tac x=v' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Write\<^sub>s\<^sub>b volatile False a'_a) done next assume ?ghst then obtain ys zs A' L' R' W' where sb: "sb = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys" by auto show ?thesis using props False a_notin sb apply - apply (rule disjI2) apply (rule_tac x=A' in exI) apply (rule_tac x=L' in exI) apply (rule_tac x=R' in exI) apply (rule_tac x=W' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Write\<^sub>s\<^sub>b volatile False a'_a) done qed qed next case False from Cons.prems obtain consis': "sharing_consistent \<S> \<O> sb" and a_nro': "a \<notin> read_only \<S>" and a_unowned: "a \<notin> \<O>" and a_ro': "a' \<in> \<O>" and nvo': "non_volatile_owned_or_read_only True \<S> \<O> sb" and a_unforw': "a \<in> unforwarded_non_volatile_reads sb (insert a' X)" by (auto simp add: Write\<^sub>s\<^sub>b False split: if_split_asm) from unforwarded_not_written [OF a_unforw'] have a_notin: "a \<notin> insert a' X". from Cons.hyps [OF nvo' consis' a_nro' a_unowned a_unforw'] have "(\<exists>sop a' v ys zs A L R W. sb = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W # zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a' \<noteq> a) \<or> (\<exists>A L R W ys zs. sb = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys)" (is "?write \<or> ?ghst") by simp then show ?thesis proof assume ?write then obtain sop' a'' v' ys zs A' L' R' W' where sb: "sb = ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a'' \<noteq> a" by auto show ?thesis using props False a_notin sb apply - apply (rule disjI1) apply (rule_tac x=sop' in exI) apply (rule_tac x=a'' in exI) apply (rule_tac x=v' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Write\<^sub>s\<^sub>b False ) done next assume ?ghst then obtain ys zs A' L' R' W' where sb: "sb = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W' # zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys" by auto show ?thesis using props False a_notin sb apply - apply (rule disjI2) apply (rule_tac x=A' in exI) apply (rule_tac x=L' in exI) apply (rule_tac x=R' in exI) apply (rule_tac x=W' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Write\<^sub>s\<^sub>b False ) done qed qed next case (Read\<^sub>s\<^sub>b volatile a' t v) from Cons.prems obtain consis': "sharing_consistent \<S> \<O> sb" and a_nro': "a \<notin> read_only \<S>" and a_unowned: "a \<notin> \<O>" and nvo': "non_volatile_owned_or_read_only True \<S> \<O> sb" and a_unforw: "a \<in> unforwarded_non_volatile_reads sb X" by (auto simp add: Read\<^sub>s\<^sub>b split: if_split_asm) from Cons.hyps [OF nvo' consis' a_nro' a_unowned a_unforw] have "(\<exists>sop a' v ys zs A L R W. sb = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W # zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a' \<noteq> a) \<or> (\<exists>A L R W ys zs. sb = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys)" (is "?write \<or> ?ghst") by simp then show ?thesis proof assume ?write then obtain sop' a'' v' ys zs A' L' R' W' where sb: "sb = ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a'' \<noteq> a" by auto show ?thesis using props sb apply - apply (rule disjI1) apply (rule_tac x=sop' in exI) apply (rule_tac x=a'' in exI) apply (rule_tac x=v' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Read\<^sub>s\<^sub>b) done next assume ?ghst then obtain ys zs A' L' R' W' where sb: "sb = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys" by auto show ?thesis using props sb apply - apply (rule disjI2) apply (rule_tac x=A' in exI) apply (rule_tac x=L' in exI) apply (rule_tac x=R' in exI) apply (rule_tac x=W' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Read\<^sub>s\<^sub>b ) done qed next case Prog\<^sub>s\<^sub>b from Cons.prems obtain consis': "sharing_consistent \<S> \<O> sb" and a_nro': "a \<notin> read_only \<S>" and a_unowned: "a \<notin> \<O>" and nvo': "non_volatile_owned_or_read_only True \<S> \<O> sb" and a_unforw: "a \<in> unforwarded_non_volatile_reads sb X" by (auto simp add: Prog\<^sub>s\<^sub>b) from Cons.hyps [OF nvo' consis' a_nro' a_unowned a_unforw] have "(\<exists>sop a' v ys zs A L R W. sb = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W # zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a' \<noteq> a) \<or> (\<exists>A L R W ys zs. sb = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys)" (is "?write \<or> ?ghst") by simp then show ?thesis proof assume ?write then obtain sop' a'' v' ys zs A' L' R' W' where sb: "sb = ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a'' \<noteq> a" by auto show ?thesis using props sb apply - apply (rule disjI1) apply (rule_tac x=sop' in exI) apply (rule_tac x=a'' in exI) apply (rule_tac x=v' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Prog\<^sub>s\<^sub>b) done next assume ?ghst then obtain ys zs A' L' R' W' where sb: "sb = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys" by auto show ?thesis using props sb apply - apply (rule disjI2) apply (rule_tac x=A' in exI) apply (rule_tac x=L' in exI) apply (rule_tac x=R' in exI) apply (rule_tac x=W' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Prog\<^sub>s\<^sub>b ) done qed next case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain nvo': "non_volatile_owned_or_read_only True (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) (\<O> \<union> A - R) sb" and a_nro: "a \<notin> read_only \<S>" and a_unowned: "a \<notin> \<O>" and A_shared_owns: "A \<subseteq> dom \<S> \<union> \<O>" and L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "sharing_consistent (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) (\<O> \<union> A - R) sb" and a_unforw: "a \<in> unforwarded_non_volatile_reads sb X" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) show ?thesis proof (cases "a \<in> A") case True then show ?thesis apply - apply (rule disjI2) apply (rule_tac x=A in exI) apply (rule_tac x=L in exI) apply (rule_tac x=R in exI) apply (rule_tac x=W in exI) apply (rule_tac x="[]" in exI) apply (rule_tac x=sb in exI) apply (simp add: Ghost\<^sub>s\<^sub>b True) done next case False with a_unowned a_nro L_A R_owns a_nro L_A A_R obtain a_nro': "a \<notin> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" and a_unowned': "a \<notin> \<O> \<union> A - R" by (force simp add: in_read_only_convs) from Cons.hyps [OF nvo' consis' a_nro' a_unowned' a_unforw] have "(\<exists>sop a' v ys zs A L R W. sb = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W # zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a' \<noteq> a) \<or> (\<exists>A L R W ys zs. sb = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys)" (is "?write \<or> ?ghst") by simp then show ?thesis proof assume ?write then obtain sop' a'' v' ys zs A' L' R' W' where sb: "sb = ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a'' \<noteq> a" by auto show ?thesis using props sb apply - apply (rule disjI1) apply (rule_tac x=sop' in exI) apply (rule_tac x=a'' in exI) apply (rule_tac x=v' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Ghost\<^sub>s\<^sub>b False ) done next assume ?ghst then obtain ys zs A' L' R' W' where sb: "sb = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" and props: "a \<in> A'" "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys" by auto show ?thesis using props sb apply - apply (rule disjI2) apply (rule_tac x=A' in exI) apply (rule_tac x=L' in exI) apply (rule_tac x=R' in exI) apply (rule_tac x=W' in exI) apply (rule_tac x="(x#ys)" in exI) apply (rule_tac x=zs in exI) apply (simp add: Ghost\<^sub>s\<^sub>b False ) done qed qed qed qed (* FIXME: indentation*) (* lemma release_take_drop: "\<And>\<R> S. release (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) S (release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) S \<R>) = release sb S \<R>" apply (induct sb) apply clarsimp apply (auto split:memref.splits) apply fastforce*) lemma release_shared_exchange_weak: assumes shared_eq: "\<forall>a \<in> \<O> \<union> all_acquired sb. (\<S>'::shared) a = \<S> a" assumes consis: "weak_sharing_consistent \<O> sb" shows "release sb (dom \<S>') \<R> = release sb (dom \<S>) \<R>" using shared_eq consis proof (induct sb arbitrary: \<S> \<S>' \<O> \<R>) case Nil thus ?case by auto next case (Cons x sb) show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile a sop v A L R W) show ?thesis proof (cases volatile) case True from Cons.prems obtain L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" and shared_eq: "\<forall>a \<in> \<O> \<union> A \<union> all_acquired sb. \<S>' a = \<S> a" by (clarsimp simp add: Write\<^sub>s\<^sub>b True ) from shared_eq have shared_eq': "\<forall>a\<in>\<O> \<union> A - R \<union> all_acquired sb. (\<S>' \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) a = (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) a" by (auto simp add: augment_shared_def restrict_shared_def) from Cons.hyps [OF shared_eq' consis'] have "release sb (dom (\<S>' \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)) Map.empty = release sb (dom (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)) Map.empty" . then show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b True domIff) next case False with Cons show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b) qed next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto next case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" and shared_eq: "\<forall>a \<in> \<O> \<union> A \<union> all_acquired sb. \<S>' a = \<S> a" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b ) from shared_eq have shared_eq': "\<forall>a\<in>\<O> \<union> A - R \<union> all_acquired sb. (\<S>' \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) a = (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) a" by (auto simp add: augment_shared_def restrict_shared_def) from shared_eq R_owns have "\<forall>a\<in>R. (a \<in> dom \<S>) = (a \<in> dom \<S>')" by (auto simp add: domIff) from augment_rels_shared_exchange [OF this] have "(augment_rels (dom \<S>') R \<R>) = (augment_rels (dom \<S>) R \<R>)". with Cons.hyps [OF shared_eq' consis'] have "release sb (dom (\<S>' \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)) (augment_rels (dom \<S>') R \<R>) = release sb (dom (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)) (augment_rels (dom \<S>) R \<R>)" by simp then show ?thesis by (clarsimp simp add: Ghost\<^sub>s\<^sub>b domIff) qed qed lemma read_only_share_all_shared: "\<And>\<S>. \<lbrakk> a \<in> read_only (share sb \<S>)\<rbrakk> \<Longrightarrow> a \<in> read_only \<S> \<union> all_shared sb" proof (induct sb) case Nil thus ?case by simp next case (Cons x sb) show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile a sop v A L R W) show ?thesis proof (cases volatile) case True with Write\<^sub>s\<^sub>b Cons.hyps [of "(\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)"] Cons.prems show ?thesis by (auto simp add: read_only_def augment_shared_def restrict_shared_def split: if_split_asm option.splits) next case False with Write\<^sub>s\<^sub>b Cons show ?thesis by auto qed next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto next case (Ghost\<^sub>s\<^sub>b A L R W) with Cons.hyps [of "(\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)"] Cons.prems show ?thesis by (auto simp add: read_only_def augment_shared_def restrict_shared_def split: if_split_asm option.splits) qed qed lemma read_only_shared_all_until_volatile_write_subset': "\<And>\<S>. read_only (share_all_until_volatile_write ts \<S>) \<subseteq> read_only \<S> \<union> (\<Union>((\<lambda>(_, _, _, sb, _, _ ,_). all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)) ` set ts))" proof (induct ts) case Nil thus ?case by simp next case (Cons t ts) obtain p "is" \<O> \<R> \<D> \<theta> sb where t: "t = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" by (cases t) have aargh: "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) = (\<lambda>a. \<not> is_volatile_Write\<^sub>s\<^sub>b a)" by (rule ext) auto let ?take_sb = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" let ?drop_sb = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" { fix a assume a_in: "a \<in> read_only (share_all_until_volatile_write ts (share ?take_sb \<S>))" and a_notin_shared: "a \<notin> read_only \<S>" and a_notin_rest: "a \<notin> (\<Union>((\<lambda>(_, _, _, sb, _, _ ,_). all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)) ` set ts))" have "a \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" proof - from Cons.hyps [of "(share ?take_sb \<S>)"] a_in a_notin_rest have "a \<in> read_only (share ?take_sb \<S>)" by (auto simp add: aargh) from read_only_share_all_shared [OF this] a_notin_shared show ?thesis by auto qed } then show ?case by (auto simp add: t aargh) qed lemma read_only_share_acquired_all_shared: "\<And>\<O> \<S>. weak_sharing_consistent \<O> sb \<Longrightarrow> \<O> \<inter> read_only \<S> = {} \<Longrightarrow> a \<in> read_only (share sb \<S>) \<Longrightarrow> a \<in> \<O> \<union> all_acquired sb \<Longrightarrow> a \<in> all_shared sb" proof (induct sb) case Nil thus ?case by auto next case (Cons x sb) show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile a' sop v A L R W) show ?thesis proof (cases volatile) case True note volatile=this from Cons.prems obtain owns_ro: "\<O> \<inter> read_only \<S> = {}" and L_A: " L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" and a_share: "a \<in> read_only (share sb (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" and a_A_all: "a \<in> \<O> \<union> A \<union> all_acquired sb" by (clarsimp simp add: Write\<^sub>s\<^sub>b True) from owns_ro A_R R_owns have owns_ro': "(\<O> \<union> A - R) \<inter> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs) from Cons.hyps [OF consis' owns_ro' a_share] show ?thesis using L_A A_R R_owns owns_ro a_A_all by (auto simp add: Write\<^sub>s\<^sub>b volatile augment_shared_def restrict_shared_def read_only_def domIff split: if_split_asm) next case False with Cons Write\<^sub>s\<^sub>b show ?thesis by (auto) qed next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto next case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain owns_ro: "\<O> \<inter> read_only \<S> = {}" and L_A: " L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" and a_share: "a \<in> read_only (share sb (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" and a_A_all: "a \<in> \<O> \<union> A \<union> all_acquired sb" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) from owns_ro A_R R_owns have owns_ro': "(\<O> \<union> A - R) \<inter> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs) from Cons.hyps [OF consis' owns_ro' a_share] show ?thesis using L_A A_R R_owns owns_ro a_A_all by (auto simp add: Ghost\<^sub>s\<^sub>b augment_shared_def restrict_shared_def read_only_def domIff split: if_split_asm) qed qed lemma read_only_share_unowned': "\<And>\<O> \<S>. \<lbrakk>weak_sharing_consistent \<O> sb; \<O> \<inter> read_only \<S> = {}; a \<notin> \<O> \<union> all_acquired sb; a \<in> read_only \<S>\<rbrakk> \<Longrightarrow> a \<in> read_only (share sb \<S>)" proof (induct sb) case Nil thus ?case by simp next case (Cons x sb) show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile a' sop v A L R W) show ?thesis proof (cases volatile) case False with Cons Write\<^sub>s\<^sub>b show ?thesis by auto next case True from Cons.prems obtain owns_ro: "\<O> \<inter> read_only \<S> = {}" and L_A: " L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" and a_share: "a \<in> read_only \<S>" and a_notin: "a \<notin> \<O>" "a \<notin> A" "a \<notin> all_acquired sb" by (clarsimp simp add: Write\<^sub>s\<^sub>b True) from owns_ro A_R R_owns have owns_ro': "(\<O> \<union> A - R) \<inter> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs) from a_notin have a_notin': "a \<notin> \<O> \<union> A - R \<union> all_acquired sb" by auto from a_share a_notin L_A A_R R_owns have a_ro': "a \<in> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: read_only_def restrict_shared_def augment_shared_def) from Cons.hyps [OF consis' owns_ro' a_notin' a_ro'] have "a \<in> read_only (share sb (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" by auto then show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b True) qed next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto next case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain owns_ro: "\<O> \<inter> read_only \<S> = {}" and L_A: " L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" and a_share: "a \<in> read_only \<S>" and a_notin: "a \<notin> \<O>" "a \<notin> A" "a \<notin> all_acquired sb" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) from owns_ro A_R R_owns have owns_ro': "(\<O> \<union> A - R) \<inter> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs) from a_notin have a_notin': "a \<notin> \<O> \<union> A - R \<union> all_acquired sb" by auto from a_share a_notin L_A A_R R_owns have a_ro': "a \<in> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: read_only_def restrict_shared_def augment_shared_def) from Cons.hyps [OF consis' owns_ro' a_notin' a_ro'] have "a \<in> read_only (share sb (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" by auto then show ?thesis by (auto simp add: Ghost\<^sub>s\<^sub>b) qed qed (* lemma release_False_mono: "\<And>S \<R>. \<R> a = Some False \<Longrightarrow> release sb S \<R> a = Some False " proof (induct sb) case Nil thus ?case by simp next case (Cons x sb) show ?case proof (cases x) case (Ghost\<^sub>s\<^sub>b A L R W) have rels_a: "\<R> a = Some False" by fact then have "(augment_rels S R \<R>) a = Some False" by (auto simp add: augment_rels_def) from Cons.hyps [where \<R> = "(augment_rels S R \<R>)", OF this] show ?thesis by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) next case Write\<^sub>s\<^sub>b with Cons show ?thesis apply auto next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto qed qed *) lemma release_False_mono: "\<And>S \<R>. \<R> a = Some False \<Longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {} \<Longrightarrow> release sb S \<R> a = Some False " proof (induct sb) case Nil thus ?case by simp next case (Cons x sb) show ?case proof (cases x) case (Ghost\<^sub>s\<^sub>b A L R W) have rels_a: "\<R> a = Some False" by fact then have "(augment_rels S R \<R>) a = Some False" by (auto simp add: augment_rels_def) from Cons.hyps [where \<R> = "(augment_rels S R \<R>)", OF this] Cons.prems show ?thesis by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) next case Write\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto qed qed lemma release_False_mono_take: "\<And>S \<R>. \<R> a = Some False \<Longrightarrow> release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) S \<R> a = Some False " proof (induct sb) case Nil thus ?case by simp next case (Cons x sb) show ?case proof (cases x) case (Ghost\<^sub>s\<^sub>b A L R W) have rels_a: "\<R> a = Some False" by fact then have "(augment_rels S R \<R>) a = Some False" by (auto simp add: augment_rels_def) from Cons.hyps [where \<R> = "(augment_rels S R \<R>)", OF this] show ?thesis by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) next case Write\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto qed qed lemma shared_switch: "\<And>\<S> \<O>. \<lbrakk>weak_sharing_consistent \<O> sb; read_only \<S> \<inter> \<O> = {}; \<S> a \<noteq> Some False; share sb \<S> a = Some False\<rbrakk> \<Longrightarrow> a \<in> \<O> \<union> all_acquired sb " proof (induct sb) case Nil thus ?case by (auto simp add: read_only_def) next case (Cons x sb) have aargh: "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) = (\<lambda>a. \<not> is_volatile_Write\<^sub>s\<^sub>b a)" by (rule ext) auto show ?case proof (cases x) case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain dist: "read_only \<S> \<inter> \<O> = {}" and share: "\<S> a \<noteq> Some False" and share': "share sb (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) a = Some False" and L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b aargh) from dist L_A A_R R_owns have dist': "read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<inter> (\<O> \<union> A - R)= {}" by (auto simp add: in_read_only_convs) show ?thesis proof (cases "(\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) a = Some False") case False from Cons.hyps [OF consis' dist' this share'] show ?thesis by (auto simp add: Ghost\<^sub>s\<^sub>b) next case True with share L_A A_R R_owns dist have "a \<in> \<O> \<union> A" by (cases "\<S> a") (auto simp add: augment_shared_def restrict_shared_def read_only_def split: if_split_asm ) thus ?thesis by (auto simp add: Ghost\<^sub>s\<^sub>b) qed next case (Write\<^sub>s\<^sub>b volatile a' sop v A L R W) show ?thesis proof (cases volatile) case True note volatile=this from Cons.prems obtain dist: "read_only \<S> \<inter> \<O> = {}" and share: "\<S> a \<noteq> Some False" and share': "share sb (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) a = Some False" and L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" by (clarsimp simp add: Write\<^sub>s\<^sub>b True aargh) from dist L_A A_R R_owns have dist': "read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<inter> (\<O> \<union> A - R)= {}" by (auto simp add: in_read_only_convs) show ?thesis proof (cases "(\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) a = Some False") case False from Cons.hyps [OF consis' dist' this share'] show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b True) next case True with share L_A A_R R_owns dist have "a \<in> \<O> \<union> A" by (cases "\<S> a") (auto simp add: augment_shared_def restrict_shared_def read_only_def split: if_split_asm ) thus ?thesis by (auto simp add: Write\<^sub>s\<^sub>b volatile) qed next case False with Cons show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b) qed next case Read\<^sub>s\<^sub>b with Cons show ?thesis by (auto) next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by (auto) qed qed lemma shared_switch_release_False: "\<And>\<S> \<R>. \<lbrakk> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}; a \<notin> dom \<S>; a \<in> dom (share sb \<S>)\<rbrakk> \<Longrightarrow> release sb (dom \<S>) \<R> a = Some False" proof (induct sb) case Nil thus ?case by (auto simp add: read_only_def) next case (Cons x sb) have aargh: "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) = (\<lambda>a. \<not> is_volatile_Write\<^sub>s\<^sub>b a)" by (rule ext) auto show ?case proof (cases x) case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain a_notin: "a \<notin> dom \<S>" and share: "a \<in> dom (share sb (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" and out': "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b aargh) show ?thesis proof (cases "a \<in> R") case False with a_notin have "a \<notin> dom (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by auto from Cons.hyps [OF out' this share] show ?thesis by (auto simp add: Ghost\<^sub>s\<^sub>b) next case True with a_notin have "augment_rels (dom \<S>) R \<R> a = Some False" by (auto simp add: augment_rels_def split: option.splits) from release_False_mono [of "augment_rels (dom \<S>) R \<R>", OF this out'] show ?thesis by (auto simp add: Ghost\<^sub>s\<^sub>b) qed next case Write\<^sub>s\<^sub>b with Cons show ?thesis by (clarsimp split: if_split_asm) next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto qed qed lemma release_not_unshared_no_write: "\<And>\<S> \<R>. \<lbrakk> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}; non_volatile_writes_unshared \<S> sb; release sb (dom \<S>) \<R> a \<noteq> Some False; a \<in> dom (share sb \<S>)\<rbrakk> \<Longrightarrow> a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb" proof (induct sb) case Nil thus ?case by (auto simp add: read_only_def) next case (Cons x sb) have aargh: "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) = (\<lambda>a. \<not> is_volatile_Write\<^sub>s\<^sub>b a)" by (rule ext) auto show ?case proof (cases x) case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain share: "a \<in> dom (share sb (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" and rel: "release sb (dom (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)) (augment_rels (dom \<S>) R \<R>) a \<noteq> Some False" and out': "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}" and nvu: "non_volatile_writes_unshared (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) sb" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b ) from Cons.hyps [OF out' nvu rel share] show ?thesis by (auto simp add: Ghost\<^sub>s\<^sub>b) next case (Write\<^sub>s\<^sub>b volatile a' sop v A L R W) show ?thesis proof (cases volatile) case True with Write\<^sub>s\<^sub>b Cons.prems have False by auto thus ?thesis .. next case False note not_vol = this from Cons.prems obtain rel: "release sb (dom \<S>) \<R> a \<noteq> Some False" and out': "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}" and nvo: "non_volatile_writes_unshared \<S> sb" and a'_not_dom: "a' \<notin> dom \<S>" and a_dom: "a \<in> dom (share sb \<S>)" by (auto simp add: Write\<^sub>s\<^sub>b False) from Cons.hyps [OF out' nvo rel a_dom] have a_notin_rest: "a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb". show ?thesis proof (cases "a'=a") case False with a_notin_rest show ?thesis by (clarsimp simp add: Write\<^sub>s\<^sub>b not_vol ) next case True from shared_switch_release_False [OF out' a'_not_dom [simplified True] a_dom] have "release sb (dom \<S>) \<R> a = Some False". with rel have False by simp thus ?thesis .. qed qed next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto qed qed corollary release_not_unshared_no_write_take: assumes nvw: "non_volatile_writes_unshared \<S> (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" assumes rel: "release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) (dom \<S>) \<R> a \<noteq> Some False" assumes a_in: "a \<in> dom (share (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<S>)" shows "a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" using release_not_unshared_no_write[OF takeWhile_not_vol_write_outstanding_refs [of sb] nvw rel a_in] by simp (* FIXME: may replace the un-primed variants, similar for the following lemmas *) lemma read_only_unacquired_share': "\<And>S \<O>. \<lbrakk>\<O> \<inter> read_only S = {}; weak_sharing_consistent \<O> sb; a \<in> read_only S; a \<notin> all_shared sb; a \<notin> acquired True sb \<O> \<rbrakk> \<Longrightarrow> a \<in> read_only (share sb S)" proof (induct sb) case Nil thus ?case by simp next case (Cons x sb) show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile a' sop v A L R W) show ?thesis proof (cases volatile) case True note volatile=this from Cons.prems obtain a_ro: "a \<in> read_only S" and a_R: "a \<notin> R" and a_unsh: "a \<notin> all_shared sb" and owns_ro: "\<O> \<inter> read_only S = {}" and L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" and a_notin: "a \<notin> acquired True sb (\<O> \<union> A - R)" by (clarsimp simp add: Write\<^sub>s\<^sub>b True) show ?thesis proof (cases "a \<in> A") case True with a_R have "a \<in> \<O> \<union> A - R" by auto from all_shared_acquired_in [OF this a_unsh] have "a \<in> acquired True sb (\<O> \<union> A - R)" by auto with a_notin have False by auto thus ?thesis .. next case False from owns_ro A_R R_owns have owns_ro': "(\<O> \<union> A - R) \<inter> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs) from a_ro False owns_ro R_owns L_A have a_ro': "a \<in> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) from Cons.hyps [OF owns_ro' consis' a_ro' a_unsh a_notin] show ?thesis by (clarsimp simp add: Write\<^sub>s\<^sub>b True) qed next case False with Cons show ?thesis by (clarsimp simp add: Write\<^sub>s\<^sub>b False) qed next case Read\<^sub>s\<^sub>b with Cons show ?thesis by (clarsimp) next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by (clarsimp) next case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain a_ro: "a \<in> read_only S" and a_R: "a \<notin> R" and a_unsh: "a \<notin> all_shared sb" and owns_ro: "\<O> \<inter> read_only S = {}" and L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" and a_notin: "a \<notin> acquired True sb (\<O> \<union> A - R)" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) show ?thesis proof (cases "a \<in> A") case True with a_R have "a \<in> \<O> \<union> A - R" by auto from all_shared_acquired_in [OF this a_unsh] have "a \<in> acquired True sb (\<O> \<union> A - R)" by auto with a_notin have False by auto thus ?thesis .. next case False from owns_ro A_R R_owns have owns_ro': "(\<O> \<union> A - R) \<inter> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs) from a_ro False owns_ro R_owns L_A have a_ro': "a \<in> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) from Cons.hyps [OF owns_ro' consis' a_ro' a_unsh a_notin] show ?thesis by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) qed qed qed lemma read_only_share_all_until_volatile_write_unacquired': "\<And>\<S>. \<lbrakk>ownership_distinct ts; read_only_unowned \<S> ts; weak_sharing_consis ts; \<forall>i < length ts. (let (_,_,_,sb,_,\<O>,\<R>) = ts!i in a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O> \<and> a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb )); a \<in> read_only \<S>\<rbrakk> \<Longrightarrow> a \<in> read_only (share_all_until_volatile_write ts \<S>)" proof (induct ts) case Nil thus ?case by simp next case (Cons t ts) obtain p "is" \<O> \<R> \<D> \<theta> sb where t: "t = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" by (cases t) have dist: "ownership_distinct (t#ts)" by fact then interpret ownership_distinct "t#ts" . from ownership_distinct_tl [OF dist] have dist': "ownership_distinct ts". have aargh: "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) = (\<lambda>a. \<not> is_volatile_Write\<^sub>s\<^sub>b a)" by (rule ext) auto have a_ro: "a \<in> read_only \<S>" by fact have ro_unowned: "read_only_unowned \<S> (t#ts)" by fact then interpret read_only_unowned \<S> "t#ts" . have consis: "weak_sharing_consis (t#ts)" by fact then interpret weak_sharing_consis "t#ts" . note consis' = weak_sharing_consis_tl [OF consis] let ?take_sb = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" let ?drop_sb = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" from weak_sharing_consis [of 0] t have consis_sb: "weak_sharing_consistent \<O> sb" by force with weak_sharing_consistent_append [of \<O> ?take_sb ?drop_sb] have consis_take: "weak_sharing_consistent \<O> ?take_sb" by auto have ro_unowned': "read_only_unowned (share ?take_sb \<S>) ts" proof fix j fix p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts" assume jth: "ts!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "\<O>\<^sub>j \<inter> read_only (share ?take_sb \<S>) = {}" proof - { fix a assume a_owns: "a \<in> \<O>\<^sub>j" assume a_ro: "a \<in> read_only (share ?take_sb \<S>)" have False proof - from ownership_distinct [of 0 "Suc j"] j_bound jth t have dist: "(\<O> \<union> all_acquired sb) \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {}" by fastforce from read_only_unowned [of "Suc j"] j_bound jth have dist_ro: "\<O>\<^sub>j \<inter> read_only \<S> = {}" by force show ?thesis proof (cases "a \<in> (\<O> \<union> all_acquired sb)") case True with dist a_owns show False by auto next case False hence "a \<notin> (\<O> \<union> all_acquired ?take_sb)" using all_acquired_append [of ?take_sb ?drop_sb] by auto from read_only_share_unowned [OF consis_take this a_ro] have "a \<in> read_only \<S>". with dist_ro a_owns show False by auto qed qed } thus ?thesis by auto qed qed from Cons.prems obtain unacq_ts: "\<forall>i < length ts. (let (_,_,_,sb,_,\<O>,_) = ts!i in a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O> \<and> a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)) " and unacq_sb: "a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>" and unsh_sb: "a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) " apply clarsimp apply (rule that) apply (auto simp add: t aargh) done from read_only_unowned [of 0] t have owns_ro: "\<O> \<inter> read_only \<S> = {}" by force from read_only_unacquired_share' [OF owns_ro consis_take a_ro unsh_sb unacq_sb] have "a \<in> read_only (share (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<S>)". from Cons.hyps [OF dist' ro_unowned' consis' unacq_ts this] show ?case by (simp add: t) qed lemma not_shared_not_acquired_switch: "\<And>X Y. \<lbrakk>a \<notin> all_shared sb; a \<notin> X; a \<notin> acquired True sb X; a \<notin> Y\<rbrakk> \<Longrightarrow> a \<notin> acquired True sb Y" proof (induct sb) case Nil thus ?case by simp next case (Cons x sb) show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile a' sop v A L R W) show ?thesis proof (cases volatile) case True from Cons.prems obtain a_X: "a \<notin> X" and a_acq: "a \<notin> acquired True sb (X \<union> A - R)" and a_Y: "a \<notin> Y" and a_R: "a \<notin> R" and a_shared: "a \<notin> all_shared sb" by (clarsimp simp add: Write\<^sub>s\<^sub>b True) show ?thesis proof (cases "a \<in> A") case True with a_X a_R have "a \<in> X \<union> A - R" by auto from all_shared_acquired_in [OF this a_shared] have "a \<in> acquired True sb (X \<union> A - R)". with a_acq have False by simp thus ?thesis .. next case False with a_X a_Y obtain a_X': "a \<notin> X \<union> A - R" and a_Y': "a \<notin> Y \<union> A - R" by auto from Cons.hyps [OF a_shared a_X' a_acq a_Y'] show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b True) qed next case False with Cons.hyps [of X Y] Cons.prems show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b) qed next case Read\<^sub>s\<^sub>b with Cons.hyps [of X Y] Cons.prems show ?thesis by (auto) next case Prog\<^sub>s\<^sub>b with Cons.hyps [of X Y] Cons.prems show ?thesis by (auto) next case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain a_X: "a \<notin> X" and a_acq: "a \<notin> acquired True sb (X \<union> A - R)" and a_Y: "a \<notin> Y" and a_R: "a \<notin> R" and a_shared: "a \<notin> all_shared sb" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) show ?thesis proof (cases "a \<in> A") case True with a_X a_R have "a \<in> X \<union> A - R" by auto from all_shared_acquired_in [OF this a_shared] have "a \<in> acquired True sb (X \<union> A - R)". with a_acq have False by simp thus ?thesis .. next case False with a_X a_Y obtain a_X': "a \<notin> X \<union> A - R" and a_Y': "a \<notin> Y \<union> A - R" by auto from Cons.hyps [OF a_shared a_X' a_acq a_Y'] show ?thesis by (auto simp add: Ghost\<^sub>s\<^sub>b) qed qed qed (* FIXME: could be strengthened to acquired True sb empty I suppose *) lemma read_only_share_all_acquired_in': "\<And>S \<O>. \<lbrakk>\<O> \<inter> read_only S = {}; weak_sharing_consistent \<O> sb; a \<in> read_only (share sb S)\<rbrakk> \<Longrightarrow> a \<in> read_only (share sb Map.empty) \<or> (a \<in> read_only S \<and> a \<notin> acquired True sb \<O> \<and> a \<notin> all_shared sb )" proof (induct sb) case Nil thus ?case by auto next case (Cons x sb) show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile a' sop v A L R W) show ?thesis proof (cases volatile) case True note volatile=this from Cons.prems obtain a_in: "a \<in> read_only (share sb (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" and owns_ro: "\<O> \<inter> read_only S = {}" and L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" by (clarsimp simp add: Write\<^sub>s\<^sub>b True) from owns_ro A_R R_owns have owns_ro': "(\<O> \<union> A - R) \<inter> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs) from Cons.hyps [OF owns_ro' consis' a_in] have hyp: "a \<in> read_only (share sb Map.empty) \<or> (a \<in> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<and> a \<notin> acquired True sb (\<O> \<union> A - R) \<and> a \<notin> all_shared sb)". have "a \<in> read_only (share sb (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)) \<or> (a \<in> read_only S \<and> a \<notin> R \<and> a \<notin> acquired True sb (\<O> \<union> A - R) \<and> a \<notin> all_shared sb)" proof - { assume a_emp: "a \<in> read_only (share sb Map.empty)" have "read_only Map.empty \<subseteq> read_only (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) from share_read_only_mono_in [OF a_emp this] have "a \<in> read_only (share sb (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))". } moreover { assume a_ro: "a \<in> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" and a_not_acq: "a \<notin> acquired True sb (\<O> \<union> A - R)" and a_unsh: "a \<notin> all_shared sb" have ?thesis proof (cases "a \<in> read_only S") case True with a_ro obtain a_A: "a \<notin> A" by (auto simp add: in_read_only_convs) with True a_not_acq a_unsh R_owns owns_ro show ?thesis by auto next case False with a_ro have a_ro_empty: "a \<in> read_only (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs split: if_split_asm) have "read_only (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<subseteq> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) with owns_ro' have owns_ro_empty: "(\<O> \<union> A - R) \<inter> read_only (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by blast from read_only_unacquired_share' [OF owns_ro_empty consis' a_ro_empty a_unsh a_not_acq] have "a \<in> read_only (share sb (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))". thus ?thesis by simp qed } moreover note hyp ultimately show ?thesis by blast qed then show ?thesis by (clarsimp simp add: Write\<^sub>s\<^sub>b True) next case False with Cons show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b) qed next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto next case (Ghost\<^sub>s\<^sub>b A L R W) from Cons.prems obtain a_in: "a \<in> read_only (share sb (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" and owns_ro: "\<O> \<inter> read_only S = {}" and L_A: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owns: "R \<subseteq> \<O>" and consis': "weak_sharing_consistent (\<O> \<union> A - R) sb" by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) from owns_ro A_R R_owns have owns_ro': "(\<O> \<union> A - R) \<inter> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs) from Cons.hyps [OF owns_ro' consis' a_in] have hyp: "a \<in> read_only (share sb Map.empty) \<or> (a \<in> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<and> a \<notin> acquired True sb (\<O> \<union> A - R) \<and> a \<notin> all_shared sb)". have "a \<in> read_only (share sb (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)) \<or> (a \<in> read_only S \<and> a \<notin> R \<and> a \<notin> acquired True sb (\<O> \<union> A - R) \<and> a \<notin> all_shared sb)" proof - { assume a_emp: "a \<in> read_only (share sb Map.empty)" have "read_only Map.empty \<subseteq> read_only (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) from share_read_only_mono_in [OF a_emp this] have "a \<in> read_only (share sb (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))". } moreover { assume a_ro: "a \<in> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" and a_not_acq: "a \<notin> acquired True sb (\<O> \<union> A - R)" and a_unsh: "a \<notin> all_shared sb" have ?thesis proof (cases "a \<in> read_only S") case True with a_ro obtain a_A: "a \<notin> A" by (auto simp add: in_read_only_convs) with True a_not_acq a_unsh R_owns owns_ro show ?thesis by auto next case False with a_ro have a_ro_empty: "a \<in> read_only (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs split: if_split_asm) have "read_only (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<subseteq> read_only (S \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) with owns_ro' have owns_ro_empty: "(\<O> \<union> A - R) \<inter> read_only (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by blast from read_only_unacquired_share' [OF owns_ro_empty consis' a_ro_empty a_unsh a_not_acq] have "a \<in> read_only (share sb (Map.empty \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))". thus ?thesis by simp qed } moreover note hyp ultimately show ?thesis by blast qed then show ?thesis by (clarsimp simp add: Ghost\<^sub>s\<^sub>b) qed qed lemma in_read_only_share_all_until_volatile_write': assumes dist: "ownership_distinct ts" assumes consis: "sharing_consis \<S> ts" assumes ro_unowned: "read_only_unowned \<S> ts" assumes i_bound: "i < length ts" assumes ts_i: "ts!i = (p,is,\<theta>,sb,\<D>,\<O>,\<R>)" assumes a_unacquired_others: "\<forall>j < length ts. i\<noteq>j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,\<O>,_) = ts!j in a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O> \<and> a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j ))" assumes a_ro_share: "a \<in> read_only (share sb \<S>)" shows "a \<in> read_only (share (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) (share_all_until_volatile_write ts \<S>))" proof - from consis interpret sharing_consis \<S> ts . interpret read_only_unowned \<S> ts by fact from sharing_consis [OF i_bound ts_i] have consis_sb: "sharing_consistent \<S> \<O> sb". from sharing_consistent_weak_sharing_consistent [OF this] have weak_consis: "weak_sharing_consistent \<O> sb". from read_only_unowned [OF i_bound ts_i] have owns_ro: "\<O> \<inter> read_only \<S> = {}". from read_only_share_all_acquired_in' [OF owns_ro weak_consis a_ro_share] (* make similar version with acquired and all_shared instead of all_acquired *) have "a \<in> read_only (share sb Map.empty) \<or> a \<in> read_only \<S> \<and> a \<notin> acquired True sb \<O> \<and> a \<notin> all_shared sb". moreover let ?take_sb = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" let ?drop_sb = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" from weak_consis weak_sharing_consistent_append [of \<O> ?take_sb ?drop_sb] obtain weak_consis': "weak_sharing_consistent (acquired True ?take_sb \<O>) ?drop_sb" and weak_consis_take: "weak_sharing_consistent \<O> ?take_sb" by auto { assume "a \<in> read_only (share sb Map.empty)" with share_append [of ?take_sb ?drop_sb] have a_in': "a \<in> read_only (share ?drop_sb (share ?take_sb Map.empty))" by auto have owns_empty: "\<O> \<inter> read_only Map.empty = {}" by auto from weak_sharing_consistent_preserves_distinct [OF weak_consis_take owns_empty] have "acquired True ?take_sb \<O> \<inter> read_only (share ?take_sb Map.empty) = {}". from read_only_share_all_acquired_in [OF this weak_consis' a_in'] have "a \<in> read_only (share ?drop_sb Map.empty) \<or> a \<in> read_only (share ?take_sb Map.empty) \<and> a \<notin> all_acquired ?drop_sb". moreover { assume a_ro_drop: "a \<in> read_only (share ?drop_sb Map.empty)" have "read_only Map.empty \<subseteq> read_only (share_all_until_volatile_write ts \<S>)" by auto from share_read_only_mono_in [OF a_ro_drop this] have ?thesis . } moreover { assume a_ro_take: "a \<in> read_only (share ?take_sb Map.empty)" assume a_unacq_drop: "a \<notin> all_acquired ?drop_sb" from read_only_share_unowned_in [OF weak_consis_take a_ro_take] have "a \<in> \<O> \<union> all_acquired ?take_sb" by auto hence "a \<in> \<O> \<union> all_acquired sb" using all_acquired_append [of ?take_sb ?drop_sb] by auto from share_all_until_volatile_write_thread_local' [OF dist consis i_bound ts_i this] a_ro_share have ?thesis by (auto simp add: read_only_def) } ultimately have ?thesis by blast } moreover { assume a_ro: "a \<in> read_only \<S>" assume a_unacq: "a \<notin> acquired True sb \<O>" assume a_unsh: "a \<notin> all_shared sb" with all_shared_append [of ?take_sb ?drop_sb] obtain a_notin_take: "a \<notin> all_shared ?take_sb" and a_notin_drop: "a \<notin> all_shared ?drop_sb" by auto have ?thesis proof (cases "a \<in> acquired True ?take_sb \<O>") case True from all_shared_acquired_in [OF this a_notin_drop] acquired_append [of True ?take_sb ?drop_sb \<O>] a_unacq have False by auto thus ?thesis .. next case False with a_unacquired_others i_bound ts_i a_notin_take have a_unacq': "\<forall>j < length ts. (let (_,_,_,sb\<^sub>j,_,\<O>,_) = ts!j in a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O> \<and> a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j ))" by (auto simp add: Let_def) from local.weak_sharing_consis_axioms have "weak_sharing_consis ts" . from read_only_share_all_until_volatile_write_unacquired' [OF dist ro_unowned \<open>weak_sharing_consis ts\<close> a_unacq' a_ro] have a_ro_all: "a \<in> read_only (share_all_until_volatile_write ts \<S>)" . from weak_consis weak_sharing_consistent_append [of \<O> ?take_sb ?drop_sb] have weak_consis_drop: "weak_sharing_consistent (acquired True ?take_sb \<O>) ?drop_sb" by auto from weak_sharing_consistent_preserves_distinct_share_all_until_volatile_write [OF dist ro_unowned \<open>weak_sharing_consis ts\<close> i_bound ts_i] have "acquired True ?take_sb \<O> \<inter> read_only (share_all_until_volatile_write ts \<S>) = {}". from read_only_unacquired_share' [OF this weak_consis_drop a_ro_all a_notin_drop] acquired_append [of True ?take_sb ?drop_sb \<O>] a_unacq show ?thesis by auto qed } ultimately show ?thesis by blast qed lemma all_acquired_unshared_acquired: "\<And>\<O>. a \<in> all_acquired sb ==> a \<notin> all_shared sb ==> a \<in> acquired True sb \<O>" apply (induct sb) apply (auto split: memref.split intro: all_shared_acquired_in) done lemma safe_RMW_common: assumes safe: "\<O>s,\<R>s,i\<turnstile> (RMW a t (D,f) cond ret A L R W# is, \<theta>, m, \<D>, \<O>, \<S>)\<surd>" shows "(a \<in> \<O> \<or> a \<in> dom \<S>) \<and> (\<forall>j < length \<O>s. i\<noteq>j \<longrightarrow> (\<R>s!j) a \<noteq> Some False)" using safe apply (cases) apply (auto simp add: domIff) done lemma acquired_reads_all_acquired': "\<And>\<O>. acquired_reads True sb \<O> \<subseteq> acquired True sb \<O> \<union> all_shared sb" apply (induct sb) apply clarsimp apply (auto split: memref.splits dest: all_shared_acquired_in) done lemma release_all_shared_exchange: "\<And>\<R> S' S. \<forall>a \<in> all_shared sb. (a \<in> S') = (a \<in> S) \<Longrightarrow> release sb S' \<R> = release sb S \<R>" proof (induct sb) case Nil thus ?case by auto next case (Cons x sb) show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile a' sop v A L R W) show ?thesis proof (cases volatile) case True note volatile=this from Cons.hyps [of "(S' \<union> R - L)" "(S \<union> R - L)" Map.empty] Cons.prems show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b volatile) next case False with Cons Write\<^sub>s\<^sub>b show ?thesis by auto qed next case Read\<^sub>s\<^sub>b with Cons show ?thesis by auto next case Prog\<^sub>s\<^sub>b with Cons show ?thesis by auto next case (Ghost\<^sub>s\<^sub>b A L R W) from augment_rels_shared_exchange [of R S S' \<R>] Cons.prems have "augment_rels S' R \<R> = augment_rels S R \<R>" by (auto simp add: Ghost\<^sub>s\<^sub>b) with Cons.hyps [of "(S' \<union> R - L)" "(S \<union> R - L)" "augment_rels S R \<R>"] Cons.prems show ?thesis by (auto simp add: Ghost\<^sub>s\<^sub>b) qed qed lemma release_append_Prog\<^sub>s\<^sub>b: "\<And>S \<R>. (release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis])) S \<R>) = (release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) S \<R>) " by (induct sb) (auto split: memref.splits) subsection \<open>Simulation of Store Buffer Machine with History by Virtual Machine with Delayed Releases\<close> theorem (in xvalid_program) concurrent_direct_steps_simulates_store_buffer_history_step: assumes step_sb: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b')" assumes valid_own: "valid_ownership \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" assumes valid_sb_reads: "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" assumes valid_hist: "valid_history program_step ts\<^sub>s\<^sub>b" assumes valid_sharing: "valid_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" assumes tmps_distinct: "tmps_distinct ts\<^sub>s\<^sub>b" assumes valid_sops: "valid_sops ts\<^sub>s\<^sub>b" assumes valid_dd: "valid_data_dependency ts\<^sub>s\<^sub>b" assumes load_tmps_fresh: "load_tmps_fresh ts\<^sub>s\<^sub>b" assumes enough_flushs: "enough_flushs ts\<^sub>s\<^sub>b" assumes valid_program_history: "valid_program_history ts\<^sub>s\<^sub>b" assumes valid: "valid ts\<^sub>s\<^sub>b" assumes sim: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" assumes safe_reach: "safe_reach_direct safe_delayed (ts,m,\<S>)" shows "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<and> valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<and> valid_history program_step ts\<^sub>s\<^sub>b' \<and> valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<and> tmps_distinct ts\<^sub>s\<^sub>b' \<and> valid_data_dependency ts\<^sub>s\<^sub>b' \<and> valid_sops ts\<^sub>s\<^sub>b' \<and> load_tmps_fresh ts\<^sub>s\<^sub>b' \<and> enough_flushs ts\<^sub>s\<^sub>b' \<and> valid_program_history ts\<^sub>s\<^sub>b' \<and> valid ts\<^sub>s\<^sub>b' \<and> (\<exists>ts' \<S>' m'. (ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>') \<and> (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b') \<sim> (ts',m',\<S>'))" proof - interpret direct_computation: computation direct_memop_step empty_storebuffer_step program_step "\<lambda>p p' is sb. sb" . interpret sbh_computation: computation sbh_memop_step flush_step program_step "\<lambda>p p' is sb. sb @ [Prog\<^sub>s\<^sub>b p p' is]" . interpret valid_ownership \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b by fact interpret valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b by fact interpret valid_history program_step ts\<^sub>s\<^sub>b by fact interpret valid_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b by fact interpret tmps_distinct ts\<^sub>s\<^sub>b by fact interpret valid_sops ts\<^sub>s\<^sub>b by fact interpret valid_data_dependency ts\<^sub>s\<^sub>b by fact interpret load_tmps_fresh ts\<^sub>s\<^sub>b by fact interpret enough_flushs ts\<^sub>s\<^sub>b by fact interpret valid_program_history ts\<^sub>s\<^sub>b by fact from valid_own valid_sharing have valid_own_sharing: "valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" by (simp add: valid_sharing_def valid_ownership_and_sharing_def) then interpret valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b . from safe_reach_safe_refl [OF safe_reach] have safe: "safe_delayed (ts,m,\<S>)". from step_sb show ?thesis proof (cases) case (Memop i p\<^sub>s\<^sub>b "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b sb \<D>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b \<R>\<^sub>s\<^sub>b "is\<^sub>s\<^sub>b'" \<theta>\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b') then obtain ts\<^sub>s\<^sub>b': "ts\<^sub>s\<^sub>b' = ts\<^sub>s\<^sub>b[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b',\<theta>\<^sub>s\<^sub>b', sb', \<D>\<^sub>s\<^sub>b', \<O>\<^sub>s\<^sub>b',\<R>\<^sub>s\<^sub>b')]" and i_bound: "i < length ts\<^sub>s\<^sub>b" and ts\<^sub>s\<^sub>b_i: "ts\<^sub>s\<^sub>b ! i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b,\<theta>\<^sub>s\<^sub>b,sb, \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)" and sbh_step: "(is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, sb, m\<^sub>s\<^sub>b, \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b, \<R>\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<rightarrow>\<^sub>s\<^sub>b\<^sub>h (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b', sb', m\<^sub>s\<^sub>b', \<D>\<^sub>s\<^sub>b', \<O>\<^sub>s\<^sub>b', \<R>\<^sub>s\<^sub>b', \<S>\<^sub>s\<^sub>b')" by auto from sim obtain m: "m = flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b" and \<S>: "\<S> = share_all_until_volatile_write ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b" and leq: "length ts\<^sub>s\<^sub>b = length ts" and ts_sim: "\<forall>i<length ts\<^sub>s\<^sub>b. let (p, is\<^sub>s\<^sub>b, \<theta>, sb, \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>) = ts\<^sub>s\<^sub>b ! i; suspends = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb in \<exists>is \<D>. instrs suspends @ is\<^sub>s\<^sub>b = is @ prog_instrs suspends \<and> \<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb \<noteq> {}) \<and> ts ! i = (hd_prog p suspends, is, \<theta> |` (dom \<theta> - read_tmps suspends), (), \<D>, acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b, release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) (dom \<S>\<^sub>s\<^sub>b) \<R>)" by cases blast from i_bound leq have i_bound': "i < length ts" by auto have split_sb: "sb = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb" (is "sb = ?take_sb@?drop_sb") by simp from ts_sim [rule_format, OF i_bound] ts\<^sub>s\<^sub>b_i obtain suspends "is" \<D> where suspends: "suspends = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb" and is_sim: "instrs suspends @ is\<^sub>s\<^sub>b = is @ prog_instrs suspends" and \<D>: "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb \<noteq> {})" and ts_i: "ts ! i = (hd_prog p\<^sub>s\<^sub>b suspends, is, \<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - read_tmps suspends), (), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by (auto simp add: Let_def) from sbh_step_preserves_valid [OF i_bound ts\<^sub>s\<^sub>b_i sbh_step valid] have valid': "valid ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') from \<D> have \<D>\<^sub>s\<^sub>b: "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ?drop_sb \<noteq> {})" apply - apply (case_tac "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}") apply (fastforce simp add: outstanding_refs_conv dest: set_dropWhileD) apply (clarsimp) apply (drule outstanding_refs_non_empty_dropWhile) apply blast done let ?ts' = "ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, (), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)]" have i_bound_ts': "i < length ?ts'" using i_bound' by auto hence ts'_i: "?ts'!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, (), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp from local.sharing_consis_axioms have sharing_consis_ts\<^sub>s\<^sub>b: "sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" . from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have sharing_consis_sb: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". from sharing_consistent_weak_sharing_consistent [OF this] have weak_consis_sb: "weak_sharing_consistent \<O>\<^sub>s\<^sub>b sb". from this weak_sharing_consistent_append [of \<O>\<^sub>s\<^sub>b ?take_sb ?drop_sb] have weak_consis_drop:"weak_sharing_consistent (acquired True ?take_sb \<O>\<^sub>s\<^sub>b) ?drop_sb" by auto from local.ownership_distinct_axioms have ownership_distinct_ts\<^sub>s\<^sub>b: "ownership_distinct ts\<^sub>s\<^sub>b" . have steps_flush_sb: "(ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (?ts', flush ?drop_sb m, share ?drop_sb \<S>)" proof - from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have reads_consis: "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b sb". from reads_consistent_drop_volatile_writes_no_volatile_reads [OF this] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b ?drop_sb = {}". from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb". then have cph: "causal_program_history is\<^sub>s\<^sub>b ?drop_sb" apply - apply (rule causal_program_history_suffix [where sb="?take_sb"] ) apply (simp) done from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have last_prog: "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". then have lp: "last_prog p\<^sub>s\<^sub>b ?drop_sb = p\<^sub>s\<^sub>b" apply - apply (rule last_prog_same_append [where sb="?take_sb"]) apply simp done from reads_consistent_flush_all_until_volatile_write [OF valid_own_sharing i_bound ts\<^sub>s\<^sub>b_i reads_consis] have reads_consis_m: "reads_consistent True (acquired True ?take_sb \<O>\<^sub>s\<^sub>b) m ?drop_sb" by (simp add: m) from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b (?take_sb@?drop_sb)) (?take_sb@?drop_sb)" by (simp) have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>s\<^sub>b sb) ?take_sb = (hd_prog p\<^sub>s\<^sub>b ?drop_sb)" proof - from last_prog_hd_prog_append' [OF h_consis] last_prog have "last_prog (hd_prog p\<^sub>s\<^sub>b ?drop_sb) ?take_sb = hd_prog p\<^sub>s\<^sub>b ?drop_sb" by (simp) moreover have "last_prog (hd_prog p\<^sub>s\<^sub>b (?take_sb @ ?drop_sb)) ?take_sb = last_prog (hd_prog p\<^sub>s\<^sub>b ?drop_sb) ?take_sb" by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp) qed from valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<forall>sop\<in>write_sops (?take_sb@?drop_sb). valid_sop sop" by (simp) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops ?drop_sb. valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps (?take_sb@?drop_sb)" by (simp) then obtain read_tmps_take_drop: "read_tmps ?take_sb \<inter> read_tmps ?drop_sb = {}" and distinct_read_tmps_drop: "distinct_read_tmps ?drop_sb" by (simp only: distinct_read_tmps_append) from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b ?drop_sb) ?drop_sb" by (simp add: last_prog_hd_prog) have rel_eq: "release ?drop_sb (dom \<S>) (release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b) = release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b" proof - from release_append [of ?take_sb ?drop_sb] have "release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b = release ?drop_sb (dom (share ?take_sb \<S>\<^sub>s\<^sub>b)) (release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp also have dist: "ownership_distinct ts\<^sub>s\<^sub>b" by fact have consis: "sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" by fact have "release ?drop_sb (dom (share ?take_sb \<S>\<^sub>s\<^sub>b)) (release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b) = release ?drop_sb (dom \<S>) (release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b) " apply (simp only: \<S>) apply (rule release_shared_exchange_weak [rule_format, OF _ weak_consis_drop]) apply (rule share_all_until_volatile_write_thread_local [OF dist consis i_bound ts\<^sub>s\<^sub>b_i, symmetric]) using acquired_all_acquired [of True ?take_sb \<O>\<^sub>s\<^sub>b] all_acquired_append [of ?take_sb ?drop_sb] by auto finally show ?thesis by simp qed from flush_store_buffer [OF i_bound' is_sim [simplified suspends] cph ts_i [simplified suspends] refl lp reads_consis_m hist_consis' valid_sops_drop distinct_read_tmps_drop no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], of \<S>] show ?thesis by (simp add: acquired_take_drop [where pending_write=True, simplified] \<D>\<^sub>s\<^sub>b rel_eq) qed from safe_reach_safe_rtrancl [OF safe_reach steps_flush_sb] have safe_ts': "safe_delayed (?ts', flush ?drop_sb m, share ?drop_sb \<S>)". from safe_delayedE [OF safe_ts' i_bound_ts' ts'_i] have safe_memop_flush_sb: "map owned ?ts',map released ?ts',i\<turnstile> (is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, flush ?drop_sb m, \<D>\<^sub>s\<^sub>b,acquired True sb \<O>\<^sub>s\<^sub>b, share ?drop_sb \<S>) \<surd>". from acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b have acquired_take_sb: "acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<subseteq> \<O>\<^sub>s\<^sub>b \<union> all_acquired ?take_sb ". (* FIXME delete from share_takeWhile_non_volatile_Write\<^sub>s\<^sub>b have share_take_sb: "share ?take_sb \<S>\<^sub>s\<^sub>b = \<S>\<^sub>s\<^sub>b \<ominus>\<^bsub>(all_acquired ?take_sb)\<^esub> all_unshared ?take_sb". from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". with sharing_consistent_append [where xs="?take_sb" and ys="?drop_sb", of \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b] have sharing_consis_drop_sb: "sharing_consistent (share ?take_sb \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb \<O>\<^sub>s\<^sub>b) ?drop_sb" by (simp add: acquired_take_sb share_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) from read_only_takeWhile_dropWhile_share_all_until_volatile_write [OF i_bound ts\<^sub>s\<^sub>b_i] have read_only_drop: "read_only (share ?drop_sb \<S>) \<subseteq> read_only (share sb \<S>\<^sub>s\<^sub>b)" by (simp add: \<S>) *) from sbh_step show ?thesis proof (cases) case (SBHReadBuffered a v volatile t) then obtain "is\<^sub>s\<^sub>b": "is\<^sub>s\<^sub>b = Read volatile a t # is\<^sub>s\<^sub>b'" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<D>\<^sub>s\<^sub>b': "\<D>\<^sub>s\<^sub>b'=\<D>\<^sub>s\<^sub>b" and \<theta>\<^sub>s\<^sub>b': "\<theta>\<^sub>s\<^sub>b' = \<theta>\<^sub>s\<^sub>b(t\<mapsto>v)" and sb': "sb'=sb@[Read\<^sub>s\<^sub>b volatile a t v]" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b' = m\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=\<R>\<^sub>s\<^sub>b" and buf_v: "buffered_val sb a = Some v" by auto from safe_memop_flush_sb [simplified is\<^sub>s\<^sub>b] obtain access_cond': "a \<in> acquired True sb \<O>\<^sub>s\<^sub>b \<or> a \<in> read_only (share ?drop_sb \<S>) \<or> (volatile \<and> a \<in> dom (share ?drop_sb \<S>))" and volatile_clean: "volatile \<longrightarrow> \<not> \<D>\<^sub>s\<^sub>b" and rels_cond: "\<forall>j < length ts. i\<noteq>j \<longrightarrow> released (ts!j) a \<noteq> Some False" and rels_nv_cond: "\<not>volatile \<longrightarrow> (\<forall>j < length ts. i\<noteq>j \<longrightarrow> a \<notin> dom (released (ts!j)))" by cases auto from clean_no_outstanding_volatile_Write\<^sub>s\<^sub>b [OF i_bound ts\<^sub>s\<^sub>b_i] volatile_clean have volatile_cond: "volatile \<longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb ={}" by auto from buffered_val_witness [OF buf_v] obtain volatile' sop' A' L' R' W' where witness: "Write\<^sub>s\<^sub>b volatile' a sop' v A' L' R' W' \<in> set sb" by auto (* FIXME: since this is the buffered-val case, there should be a simpler proof not involving simulation to an unsafe state. Then we would not have to repeat the proof.*) { fix j p\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<theta>\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j, \<D>\<^sub>s\<^sub>b\<^sub>j, \<O>\<^sub>j,\<R>\<^sub>j)" assume non_vol: "\<not> volatile" have "a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof assume a_j: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" from ts_sim [rule_format, OF j_bound] jth obtain suspends\<^sub>j "is\<^sub>j" \<D>\<^sub>j where suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (auto simp add: Let_def) from a_j ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] have a_notin_sb: "a \<notin> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by auto with acquired_all_acquired [of True sb \<O>\<^sub>s\<^sub>b] have a_not_acq: "a \<notin> acquired True sb \<O>\<^sub>s\<^sub>b" by blast with access_cond' non_vol have a_ro: "a \<in> read_only (share ?drop_sb \<S>)" by auto from read_only_share_unowned_in [OF weak_consis_drop a_ro] a_notin_sb acquired_all_acquired [of True ?take_sb \<O>\<^sub>s\<^sub>b] all_acquired_append [of ?take_sb ?drop_sb] have a_ro_shared: "a \<in> read_only \<S>" by auto from rels_nv_cond [rule_format, OF non_vol j_bound [simplified leq] neq_i_j] ts\<^sub>j have "a \<notin> dom (release ?take_sb\<^sub>j (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>j)" by auto with dom_release_takeWhile [of sb\<^sub>j "(dom (\<S>\<^sub>s\<^sub>b))" \<R>\<^sub>j] obtain a_rels\<^sub>j: "a \<notin> dom \<R>\<^sub>j" and a_shared\<^sub>j: "a \<notin> all_shared ?take_sb\<^sub>j" by auto have "a \<notin> \<Union>((\<lambda>(_, _, _, sb, _, _, _). all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)) ` set ts\<^sub>s\<^sub>b)" proof - { fix k p\<^sub>k "is\<^sub>k" \<theta>\<^sub>k sb\<^sub>k \<D>\<^sub>k \<O>\<^sub>k \<R>\<^sub>k assume k_bound: "k < length ts\<^sub>s\<^sub>b" assume ts_k: "ts\<^sub>s\<^sub>b ! k = (p\<^sub>k,is\<^sub>k,\<theta>\<^sub>k,sb\<^sub>k,\<D>\<^sub>k,\<O>\<^sub>k,\<R>\<^sub>k)" assume a_in: "a \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k)" have False proof (cases "k=j") case True with a_shared\<^sub>j jth ts_k a_in show False by auto next case False from ownership_distinct [OF j_bound k_bound False [symmetric] jth ts_k] a_j have "a \<notin> (\<O>\<^sub>k \<union> all_acquired sb\<^sub>k)" by auto with all_shared_acquired_or_owned [OF sharing_consis [OF k_bound ts_k]] a_in show False using all_acquired_append [of "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k" "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k"] all_shared_append [of "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k" "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k"] by auto qed } thus ?thesis by (fastforce simp add: in_set_conv_nth) qed with a_ro_shared read_only_shared_all_until_volatile_write_subset' [of ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b] have a_ro_shared\<^sub>s\<^sub>b: "a \<in> read_only \<S>\<^sub>s\<^sub>b" by (auto simp add: \<S>) with read_only_unowned [OF j_bound jth] have a_notin_owns_j: "a \<notin> \<O>\<^sub>j" by auto have own_dist: "ownership_distinct ts\<^sub>s\<^sub>b" by fact have share_consis: "sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" by fact from sharing_consistent_share_all_until_volatile_write [OF own_dist share_consis i_bound ts\<^sub>s\<^sub>b_i] have consis': "sharing_consistent \<S> (acquired True ?take_sb \<O>\<^sub>s\<^sub>b) ?drop_sb" by (simp add: \<S>) from share_all_until_volatile_write_thread_local [OF own_dist share_consis j_bound jth a_j] a_ro_shared have a_ro_take: "a \<in> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: domIff \<S> read_only_def) from sharing_consis [OF j_bound jth] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". from sharing_consistent_weak_sharing_consistent [OF this] weak_sharing_consistent_append [of \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have weak_consis_drop:"weak_sharing_consistent \<O>\<^sub>j ?take_sb\<^sub>j" by auto from read_only_share_acquired_all_shared [OF this read_only_unowned [OF j_bound jth] a_ro_take ] a_notin_owns_j a_shared\<^sub>j have "a \<notin> all_acquired ?take_sb\<^sub>j" by auto with a_j a_notin_owns_j have a_drop: "a \<in> all_acquired ?drop_sb\<^sub>j" using all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] by simp from i_bound j_bound leq have j_bound_ts': "j < length ?ts'" by auto note conflict_drop = a_drop [simplified suspends\<^sub>j [symmetric]] from split_all_acquired_in [OF conflict_drop] (* FIXME: exract common parts *) show False proof assume "\<exists>sop a' v ys zs A L R W. (suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W# zs) \<and> a \<in> A" then obtain a' sop' v' ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a_A': "a \<in> A'" by blast from sharing_consis [OF j_bound jth] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". then have A'_R': "A' \<inter> R' = {}" by (simp add: sharing_consistent_append [of _ _ ?take_sb\<^sub>j ?drop_sb\<^sub>j, simplified] suspends\<^sub>j [symmetric] split_suspends\<^sub>j sharing_consistent_append) from valid_program_history [OF j_bound jth] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts'_j: "?ts'!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j, release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_last_prog [OF j_bound jth] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound jth] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound jth reads_consis_j] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m_j] have reads_consis_flush_suspend: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound jth] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound jth] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound jth] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']" and sb'="zs", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts'_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="share ?drop_sb \<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d\<^sup>* (?ts'[j:=(last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs)) (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']), is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), True, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (flush ?drop_sb m), share (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (share ?drop_sb \<S>))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append outstanding_refs_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b,(), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = rtranclp_trans [OF steps_flush_sb steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this i_bound_ys ts_ys_i, simplified is\<^sub>s\<^sub>b] non_vol a_not_acq have "a \<in> read_only (share (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (share ?drop_sb \<S>))" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done with a_A' show False by (simp add: share_append in_read_only_convs) next assume "\<exists>A L R W ys zs. suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A L R W # zs \<and> a \<in> A" then obtain A' L' R' W' ys zs where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a_A': "a \<in> A'" by blast from valid_program_history [OF j_bound jth] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts'_j: "?ts'!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j, release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_last_prog [OF j_bound jth] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound jth] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound jth reads_consis_j] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m_j] have reads_consis_flush_suspend: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound jth] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound jth] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound jth] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']" and sb'="zs", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts'_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="share ?drop_sb \<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d\<^sup>* (?ts'[j:=(last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)) (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']), is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (flush ?drop_sb m), share (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (share ?drop_sb \<S>))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b,\<theta>\<^sub>s\<^sub>b,(), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = rtranclp_trans [OF steps_flush_sb steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this i_bound_ys ts_ys_i, simplified is\<^sub>s\<^sub>b] non_vol a_not_acq have "a \<in> read_only (share (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (share ?drop_sb \<S>))" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done with a_A' show False by (simp add: share_append in_read_only_convs) qed qed } note non_volatile_unowned_others = this { assume a_in: "a \<in> read_only (share (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<S>)" assume nv: "\<not> volatile" have "a \<in> read_only (share sb \<S>\<^sub>s\<^sub>b)" proof (cases "a \<in> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb") case True from share_all_until_volatile_write_thread_local' [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b i_bound ts\<^sub>s\<^sub>b_i True] True a_in show ?thesis by (simp add: \<S> read_only_def) next case False from read_only_share_unowned [OF weak_consis_drop _ a_in] False acquired_all_acquired [of True ?take_sb \<O>\<^sub>s\<^sub>b] all_acquired_append [of ?take_sb ?drop_sb] have a_ro_shared: "a \<in> read_only \<S>" by auto have "a \<notin> \<Union>((\<lambda>(_, _, _, sb, _, _, _). all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)) ` set ts\<^sub>s\<^sub>b)" proof - { fix k p\<^sub>k "is\<^sub>k" \<theta>\<^sub>k sb\<^sub>k \<D>\<^sub>k \<O>\<^sub>k \<R>\<^sub>k assume k_bound: "k < length ts\<^sub>s\<^sub>b" assume ts_k: "ts\<^sub>s\<^sub>b ! k = (p\<^sub>k,is\<^sub>k,\<theta>\<^sub>k,sb\<^sub>k,\<D>\<^sub>k,\<O>\<^sub>k,\<R>\<^sub>k)" assume a_in: "a \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k)" have False proof (cases "k=i") case True with False ts\<^sub>s\<^sub>b_i ts_k a_in all_shared_acquired_or_owned [OF sharing_consis [OF k_bound ts_k]] all_shared_append [of "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k" "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k"] show False by auto next case False from rels_nv_cond [rule_format, OF nv k_bound [simplified leq] False [symmetric] ] ts_sim [rule_format, OF k_bound] ts_k have "a \<notin> dom (release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k) (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>k)" by (auto simp add: Let_def) with dom_release_takeWhile [of sb\<^sub>k "(dom (\<S>\<^sub>s\<^sub>b))" \<R>\<^sub>k] obtain a_rels\<^sub>j: "a \<notin> dom \<R>\<^sub>k" and a_shared\<^sub>j: "a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k)" by auto with False a_in show ?thesis by auto qed } thus ?thesis by (fastforce simp add: in_set_conv_nth) qed with read_only_shared_all_until_volatile_write_subset' [of ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b] a_ro_shared have "a \<in> read_only \<S>\<^sub>s\<^sub>b" by (auto simp add: \<S>) from read_only_share_unowned' [OF weak_consis_sb read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] False this] show ?thesis . qed } note non_vol_ro_reduction = this have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (cases volatile) case False from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". then have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b False a t v])" using access_cond' False non_vol_ro_reduction by (auto simp add: non_volatile_owned_or_read_only_append) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (auto simp add: False ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next case True from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". then have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b True a t v])" using True by (simp add: non_volatile_owned_or_read_only_append) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (auto simp add: True ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof - have out: "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t v]) \<subseteq> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb" by (auto simp add: outstanding_refs_append) have "all_acquired (sb @ [Read\<^sub>s\<^sub>b volatile a t v]) \<subseteq> all_acquired sb" by (auto simp add: all_acquired_append) from outstanding_volatile_writes_unowned_by_others_store_buffer [OF i_bound ts\<^sub>s\<^sub>b_i out this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof (cases volatile) case True have r: "read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Read\<^sub>s\<^sub>b volatile a t v])) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Read\<^sub>s\<^sub>b volatile a t v])) \<subseteq> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" apply (case_tac "outstanding_refs (is_volatile_Write\<^sub>s\<^sub>b) sb = {}") apply (simp_all add: outstanding_vol_write_take_drop_appends acquired_append read_only_reads_append True) done have "\<O>\<^sub>s\<^sub>b \<union> all_acquired (sb @ [Read\<^sub>s\<^sub>b volatile a t v]) \<subseteq> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by (simp add: all_acquired_append) from read_only_reads_unowned_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i r this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb') next case False show ?thesis proof (unfold_locales) fix n m fix p\<^sub>n "is\<^sub>n" \<O>\<^sub>n \<R>\<^sub>n \<D>\<^sub>n \<theta>\<^sub>n sb\<^sub>n p\<^sub>m "is\<^sub>m" \<O>\<^sub>m \<R>\<^sub>m \<D>\<^sub>m \<theta>\<^sub>m sb\<^sub>m assume n_bound: "n < length ts\<^sub>s\<^sub>b'" and m_bound: "m < length ts\<^sub>s\<^sub>b'" and neq_n_m: "n\<noteq>m" and nth: "ts\<^sub>s\<^sub>b'!n = (p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n, \<R>\<^sub>n)" and mth: "ts\<^sub>s\<^sub>b'!m =(p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m, \<R>\<^sub>m)" from n_bound have n_bound': "n < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from m_bound have m_bound': "m < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') have acq_eq: "(\<O>\<^sub>s\<^sub>b' \<union> all_acquired sb') = (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb)" by (simp add: all_acquired_append sb' \<O>\<^sub>s\<^sub>b') show "(\<O>\<^sub>m \<union> all_acquired sb\<^sub>m) \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<O>\<^sub>n) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) = {}" proof (cases "m=i") case True with neq_n_m have neq_n_i: "n\<noteq>i" by auto with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n, \<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') note read_only_reads_unowned [OF n_bound' i_bound neq_n_i nth' ts\<^sub>s\<^sub>b_i] moreover note acq_eq ultimately show ?thesis using True ts\<^sub>s\<^sub>b_i nth mth n_bound' m_bound' by (simp add: ts\<^sub>s\<^sub>b') next case False note neq_m_i = this with m_bound mth i_bound have mth': "ts\<^sub>s\<^sub>b!m = (p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" by (auto simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "n=i") case True note read_only_reads_unowned [OF i_bound m_bound' neq_m_i [symmetric] ts\<^sub>s\<^sub>b_i mth'] moreover note acq_eq moreover note non_volatile_unowned_others [OF m_bound' neq_m_i [symmetric] mth'] ultimately show ?thesis using True ts\<^sub>s\<^sub>b_i nth mth n_bound' m_bound' neq_m_i apply (case_tac "outstanding_refs (is_volatile_Write\<^sub>s\<^sub>b) sb = {}") apply (clarsimp simp add: outstanding_vol_write_take_drop_appends acquired_append read_only_reads_append ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b')+ done next case False with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n, \<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_reads_unowned [OF n_bound' m_bound' neq_n_m nth' mth'] False neq_m_i show ?thesis by (clarsimp) qed qed qed qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof - have "all_acquired (sb @ [Read\<^sub>s\<^sub>b volatile a t v]) \<subseteq> all_acquired sb" by (auto simp add: all_acquired_append) from ownership_distinct_instructions_read_value_store_buffer_independent [OF i_bound ts\<^sub>s\<^sub>b_i this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') qed qed have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" proof - from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have hcons: "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b sb) sb". from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have t_notin_reads: "t \<notin> read_tmps sb" by (auto simp add: "is\<^sub>s\<^sub>b") from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have t_notin_writes: "t \<notin> \<Union>(fst ` write_sops sb)" by (auto simp add: "is\<^sub>s\<^sub>b") from valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have valid_sops: "\<forall>sop \<in> write_sops sb. valid_sop sop" by auto from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have t_fresh: "t \<notin> dom \<theta>\<^sub>s\<^sub>b" using "is\<^sub>s\<^sub>b" by simp have "history_consistent (\<theta>\<^sub>s\<^sub>b(t\<mapsto>v)) (hd_prog p\<^sub>s\<^sub>b (sb@ [Read\<^sub>s\<^sub>b volatile a t v])) (sb@ [Read\<^sub>s\<^sub>b volatile a t v])" using t_notin_writes valid_sops t_fresh hcons valid_implies_valid_prog_hd [OF i_bound ts\<^sub>s\<^sub>b_i valid] apply - apply (rule history_consistent_appendI) apply (auto simp add: hd_prog_append_Read\<^sub>s\<^sub>b) done from valid_history_nth_update [OF i_bound this] show ?thesis by (auto simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed from reads_consistent_buffered_snoc [OF buf_v valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] volatile_cond] have reads_consis': "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t v])" by (simp split: if_split_asm) from valid_reads_nth_update [OF i_bound this] have valid_reads': "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t v])" by (auto simp add: non_volatile_writes_unshared_append) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' \<S>\<^sub>s\<^sub>b') next from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". then have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t v])" by (simp add: sharing_consistent_append) from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' \<S>\<^sub>s\<^sub>b') next note read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] from read_only_unowned_nth_update [OF i_bound this] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b sb". hence "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b volatile a t v])" by (simp add: no_write_to_read_only_memory_append) from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound this] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' sb') qed have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b'" by (auto split: instr.splits simp add: is\<^sub>s\<^sub>b) from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') next from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps sb". moreover from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "t \<notin> read_tmps sb" by (auto simp add: is\<^sub>s\<^sub>b) ultimately have "distinct_read_tmps (sb @ [Read\<^sub>s\<^sub>b volatile a t v])" by (auto simp add: distinct_read_tmps_append) from read_tmps_distinct_nth_update [OF i_bound this] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> read_tmps (sb @ [Read\<^sub>s\<^sub>b volatile a t v]) = {}" by (clarsimp simp add: read_tmps_append "is\<^sub>s\<^sub>b") from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb') qed have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" proof - from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have valid_store_sops': "\<forall>sop\<in>store_sops is\<^sub>s\<^sub>b'. valid_sop sop" by (auto simp add: "is\<^sub>s\<^sub>b") from valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have valid_write_sops': "\<forall>sop\<in>write_sops (sb@ [Read\<^sub>s\<^sub>b volatile a t v]). valid_sop sop" by (auto simp add: write_sops_append) from valid_sops_nth_update [OF i_bound valid_write_sops' valid_store_sops'] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" proof - from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] have dd_is: "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b') is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b') from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> \<Union>(fst ` write_sops (sb@ [Read\<^sub>s\<^sub>b volatile a t v])) = {}" by (auto simp add: write_sops_append "is\<^sub>s\<^sub>b") from valid_data_dependency_nth_update [OF i_bound dd_is this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps (Read volatile a t # is\<^sub>s\<^sub>b') \<inter> dom \<theta>\<^sub>s\<^sub>b = {}" by (simp add: "is\<^sub>s\<^sub>b") moreover from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "t \<notin> load_tmps is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b") ultimately have "load_tmps is\<^sub>s\<^sub>b' \<inter> dom (\<theta>\<^sub>s\<^sub>b(t \<mapsto> v)) = {}" by auto from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<theta>\<^sub>s\<^sub>b') qed have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" proof - from clean_no_outstanding_volatile_Write\<^sub>s\<^sub>b [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<not> \<D>\<^sub>s\<^sub>b \<longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b volatile a t v]) = {}" by (auto simp add: outstanding_refs_append ) from enough_flushs_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b') qed have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . then have causal': "causal_program_history is\<^sub>s\<^sub>b' (sb@[Read\<^sub>s\<^sub>b volatile a t v])" by (auto simp: causal_program_history_Read "is\<^sub>s\<^sub>b") from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". hence "last_prog p\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t v]) = p\<^sub>s\<^sub>b" by (simp add: last_prog_append_Read\<^sub>s\<^sub>b) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed show ?thesis proof (cases "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}") case True from True have flush_all: "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = sb" by (auto simp add: outstanding_refs_conv ) from True have suspend_nothing: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = []" by (auto simp add: outstanding_refs_conv) hence suspends_empty: "suspends = []" by (simp add: suspends) from suspends_empty is_sim have "is": "is = Read volatile a t # is\<^sub>s\<^sub>b'" by (simp add: "is\<^sub>s\<^sub>b") with suspends_empty ts_i have ts_i: "ts!i = (p\<^sub>s\<^sub>b, Read volatile a t # is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp from direct_memop_step.Read have "(Read volatile a t # is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), m, \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> m a), (), m, \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, \<S>)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i this] have "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> m a), (), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)], m, \<S>)" . moreover from flush_all_until_volatile_write_Read_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified "is\<^sub>s\<^sub>b"] ] have flush_commute: "flush_all_until_volatile_write (ts\<^sub>s\<^sub>b[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t\<mapsto>v), sb @ [Read\<^sub>s\<^sub>b volatile a t v], \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b, \<R>\<^sub>s\<^sub>b)]) m\<^sub>s\<^sub>b = flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b". from True witness have not_volatile': "volatile' = False" by (auto simp add: outstanding_refs_conv) from witness not_volatile' have a_out_sb: "a \<in> outstanding_refs (Not \<circ> is_volatile) sb" apply (cases sop') apply (fastforce simp add: outstanding_refs_conv is_volatile_def split: memref.splits) done with non_volatile_owned_or_read_only_outstanding_refs [OF outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i]] have a_owned: "a \<in> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb \<union> read_only_reads \<O>\<^sub>s\<^sub>b sb" by auto have "flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b a = v" proof - (* FIXME: Same proof as in Unbuffered case *) have "\<forall>j < length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,_,_) = ts\<^sub>s\<^sub>b!j in a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" proof - { fix j p\<^sub>j "is\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j, xs\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j, \<R>\<^sub>j)" have "a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" proof let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume a_in: "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b ?take_sb\<^sub>j" with outstanding_refs_takeWhile [where P'= "Not \<circ> is_volatile_Write\<^sub>s\<^sub>b"] have a_in': "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" by auto with non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound jth]] have j_owns: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto with ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] have a_not_owns: "a \<notin> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by blast from non_volatile_owned_or_read_only_append [of False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] outstanding_non_volatile_refs_owned_or_read_only [OF j_bound jth] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j" by simp from non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF this] a_in have j_owns_drop: "a \<in> \<O>\<^sub>j \<union> all_acquired ?take_sb\<^sub>j" by auto from rels_cond [rule_format, OF j_bound [simplified leq] neq_i_j] ts_sim [rule_format, OF j_bound] jth have no_unsharing:"release ?take_sb\<^sub>j (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>j a \<noteq> Some False" by (auto simp add: Let_def) { assume "a \<in> acquired True sb \<O>\<^sub>s\<^sub>b" with acquired_all_acquired_in [OF this] ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] j_owns have False by auto } moreover { assume a_ro: "a \<in> read_only (share ?drop_sb \<S>)" from read_only_share_unowned_in [OF weak_consis_drop a_ro] a_not_owns acquired_all_acquired [of True ?take_sb \<O>\<^sub>s\<^sub>b] all_acquired_append [of ?take_sb ?drop_sb] have "a \<in> read_only \<S>" by auto with share_all_until_volatile_write_thread_local [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b j_bound jth j_owns] have "a \<in> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: read_only_def \<S>) hence a_dom: "a \<in> dom (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: read_only_def domIff) from outstanding_non_volatile_writes_unshared [OF j_bound jth] non_volatile_writes_unshared_append [of \<S>\<^sub>s\<^sub>b ?take_sb\<^sub>j ?drop_sb\<^sub>j] have nvw: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b ?take_sb\<^sub>j" by auto from release_not_unshared_no_write_take [OF this no_unsharing a_dom] a_in have False by auto } moreover { assume a_share: "volatile \<and> a \<in> dom (share ?drop_sb \<S>)" from outstanding_non_volatile_writes_unshared [OF j_bound jth] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb\<^sub>j". with non_volatile_writes_unshared_append [of \<S>\<^sub>s\<^sub>b "?take_sb\<^sub>j" "?drop_sb\<^sub>j"] have unshared_take: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" by clarsimp from valid_own have own_dist: "ownership_distinct ts\<^sub>s\<^sub>b" by (simp add: valid_ownership_def) from valid_sharing have "sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" by (simp add: valid_sharing_def) from sharing_consistent_share_all_until_volatile_write [OF own_dist this i_bound ts\<^sub>s\<^sub>b_i] have sc: "sharing_consistent \<S> (acquired True ?take_sb \<O>\<^sub>s\<^sub>b) ?drop_sb" by (simp add: \<S>) from sharing_consistent_share_all_shared have "dom (share ?drop_sb \<S>) \<subseteq> dom \<S> \<union> all_shared ?drop_sb" by auto also from sharing_consistent_all_shared [OF sc] have "\<dots> \<subseteq> dom \<S> \<union> acquired True ?take_sb \<O>\<^sub>s\<^sub>b" by auto also from acquired_all_acquired all_acquired_takeWhile have "\<dots> \<subseteq> dom \<S> \<union> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb)" by force finally have a_shared: "a \<in> dom \<S>" using a_share a_not_owns by auto with share_all_until_volatile_write_thread_local [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b j_bound jth j_owns] have a_dom: "a \<in> dom (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: \<S> domIff) from release_not_unshared_no_write_take [OF unshared_take no_unsharing a_dom] a_in have False by auto } ultimately show False using access_cond' by auto qed } thus ?thesis by (fastforce simp add: Let_def) qed from flush_all_until_volatile_write_buffered_val_conv [OF True i_bound ts\<^sub>s\<^sub>b_i this] show ?thesis by (simp add: buf_v) qed hence m_a_v: "m a = v" by (simp add: m) have tmps_commute: "\<theta>\<^sub>s\<^sub>b(t \<mapsto> v) = (\<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - {t}))(t \<mapsto> v)" apply (rule ext) apply (auto simp add: restrict_map_def domIff) done from suspend_nothing have suspend_nothing': "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = []" by (simp add: sb') from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b volatile a t v]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t\<mapsto>m a),(),\<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)],m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b') using share_all_until_volatile_write_Read_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b]] apply (simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b') using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i True \<D>' apply (clarsimp simp add: Let_def nth_list_update outstanding_refs_conv m_a_v ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' \<R>\<^sub>s\<^sub>b' suspend_nothing' \<D>\<^sub>s\<^sub>b' flush_all acquired_append release_append split: if_split_asm ) apply (rule tmps_commute) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_sops' valid_dd' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply ) next case False then obtain r where r_in: "r \<in> set sb" and volatile_r: "is_volatile_Write\<^sub>s\<^sub>b r" by (auto simp add: outstanding_refs_conv) from takeWhile_dropWhile_real_prefix [OF r_in, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)", simplified, OF volatile_r] obtain a' v' sb'' sop' A' L' R' W' where sb_split: "sb = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" and drop: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" apply (auto) subgoal for y ys apply (case_tac y) apply auto done done from drop suspends have suspends: "suspends = Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" by simp have "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts, m, \<S>)" by auto moreover from flush_all_until_volatile_write_Read_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified "is\<^sub>s\<^sub>b"] ] have flush_commute: "flush_all_until_volatile_write (ts\<^sub>s\<^sub>b[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> v), sb @ [Read\<^sub>s\<^sub>b volatile a t v], \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b, \<R>\<^sub>s\<^sub>b)]) m\<^sub>s\<^sub>b = flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b". have "Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'\<in> set sb" by (subst sb_split) auto from dropWhile_append1 [OF this, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)"] have drop_app_comm: "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Read\<^sub>s\<^sub>b volatile a t v])) = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ [Read\<^sub>s\<^sub>b volatile a t v]" by simp from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "t \<notin> dom \<theta>\<^sub>s\<^sub>b" by (auto simp add: "is\<^sub>s\<^sub>b") then have tmps_commute: "\<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - read_tmps sb'') = \<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - insert t (read_tmps sb''))" apply - apply (rule ext) apply auto done from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b volatile a t v]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b' ) using share_all_until_volatile_write_Read_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b]] apply (simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i is_sim \<D>' apply (clarsimp simp add: Let_def nth_list_update is_sim drop_app_comm read_tmps_append suspends prog_instrs_append_Read\<^sub>s\<^sub>b instrs_append_Read\<^sub>s\<^sub>b hd_prog_append_Read\<^sub>s\<^sub>b drop "is\<^sub>s\<^sub>b" ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' acquired_append takeWhile_append1 [OF r_in] volatile_r split: if_split_asm) apply (simp add: drop tmps_commute)+ done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply ) qed next case (SBHReadUnbuffered a volatile t) then obtain "is\<^sub>s\<^sub>b": "is\<^sub>s\<^sub>b = Read volatile a t # is\<^sub>s\<^sub>b'" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=\<R>\<^sub>s\<^sub>b" and \<theta>\<^sub>s\<^sub>b': "\<theta>\<^sub>s\<^sub>b' = \<theta>\<^sub>s\<^sub>b(t\<mapsto>(m\<^sub>s\<^sub>b a))" and sb': "sb'=sb@[Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b' = m\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" and \<D>\<^sub>s\<^sub>b': "\<D>\<^sub>s\<^sub>b'=\<D>\<^sub>s\<^sub>b" and buf_None: "buffered_val sb a = None" by auto from safe_memop_flush_sb [simplified is\<^sub>s\<^sub>b] obtain access_cond': "a \<in> acquired True sb \<O>\<^sub>s\<^sub>b \<or> a \<in> read_only (share ?drop_sb \<S>) \<or> (volatile \<and> a \<in> dom (share ?drop_sb \<S>))" and volatile_clean: "volatile \<longrightarrow> \<not> \<D>\<^sub>s\<^sub>b" and rels_cond: "\<forall>j < length ts. i\<noteq>j \<longrightarrow> released (ts!j) a \<noteq> Some False" and rels_nv_cond: "\<not>volatile \<longrightarrow> (\<forall>j < length ts. i\<noteq>j \<longrightarrow> a \<notin> dom (released (ts!j)))" by cases auto from clean_no_outstanding_volatile_Write\<^sub>s\<^sub>b [OF i_bound ts\<^sub>s\<^sub>b_i] volatile_clean have volatile_cond: "volatile \<longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb ={}" by auto { fix j p\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<theta>\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j, \<D>\<^sub>s\<^sub>b\<^sub>j, \<O>\<^sub>j,\<R>\<^sub>j)" assume non_vol: "\<not> volatile" have "a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof assume a_j: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" from ts_sim [rule_format, OF j_bound] jth obtain suspends\<^sub>j "is\<^sub>j" \<D>\<^sub>j where suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (auto simp add: Let_def) from a_j ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] have a_notin_sb: "a \<notin> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by auto with acquired_all_acquired [of True sb \<O>\<^sub>s\<^sub>b] have a_not_acq: "a \<notin> acquired True sb \<O>\<^sub>s\<^sub>b" by blast with access_cond' non_vol have a_ro: "a \<in> read_only (share ?drop_sb \<S>)" by auto from read_only_share_unowned_in [OF weak_consis_drop a_ro] a_notin_sb acquired_all_acquired [of True ?take_sb \<O>\<^sub>s\<^sub>b] all_acquired_append [of ?take_sb ?drop_sb] have a_ro_shared: "a \<in> read_only \<S>" by auto from rels_nv_cond [rule_format, OF non_vol j_bound [simplified leq] neq_i_j] ts\<^sub>j have "a \<notin> dom (release ?take_sb\<^sub>j (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>j)" by auto with dom_release_takeWhile [of sb\<^sub>j "(dom (\<S>\<^sub>s\<^sub>b))" \<R>\<^sub>j] obtain a_rels\<^sub>j: "a \<notin> dom \<R>\<^sub>j" and a_shared\<^sub>j: "a \<notin> all_shared ?take_sb\<^sub>j" by auto have "a \<notin> \<Union>((\<lambda>(_, _, _, sb, _, _, _). all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)) ` set ts\<^sub>s\<^sub>b)" proof - { fix k p\<^sub>k "is\<^sub>k" \<theta>\<^sub>k sb\<^sub>k \<D>\<^sub>k \<O>\<^sub>k \<R>\<^sub>k assume k_bound: "k < length ts\<^sub>s\<^sub>b" assume ts_k: "ts\<^sub>s\<^sub>b ! k = (p\<^sub>k,is\<^sub>k,\<theta>\<^sub>k,sb\<^sub>k,\<D>\<^sub>k,\<O>\<^sub>k,\<R>\<^sub>k)" assume a_in: "a \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k)" have False proof (cases "k=j") case True with a_shared\<^sub>j jth ts_k a_in show False by auto next case False from ownership_distinct [OF j_bound k_bound False [symmetric] jth ts_k] a_j have "a \<notin> (\<O>\<^sub>k \<union> all_acquired sb\<^sub>k)" by auto with all_shared_acquired_or_owned [OF sharing_consis [OF k_bound ts_k]] a_in show False using all_acquired_append [of "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k" "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k"] all_shared_append [of "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k" "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k"] by auto qed } thus ?thesis by (fastforce simp add: in_set_conv_nth) qed with a_ro_shared read_only_shared_all_until_volatile_write_subset' [of ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b] have a_ro_shared\<^sub>s\<^sub>b: "a \<in> read_only \<S>\<^sub>s\<^sub>b" by (auto simp add: \<S>) with read_only_unowned [OF j_bound jth] have a_notin_owns_j: "a \<notin> \<O>\<^sub>j" by auto have own_dist: "ownership_distinct ts\<^sub>s\<^sub>b" by fact have share_consis: "sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" by fact from sharing_consistent_share_all_until_volatile_write [OF own_dist share_consis i_bound ts\<^sub>s\<^sub>b_i] have consis': "sharing_consistent \<S> (acquired True ?take_sb \<O>\<^sub>s\<^sub>b) ?drop_sb" by (simp add: \<S>) from share_all_until_volatile_write_thread_local [OF own_dist share_consis j_bound jth a_j] a_ro_shared have a_ro_take: "a \<in> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: domIff \<S> read_only_def) from sharing_consis [OF j_bound jth] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". from sharing_consistent_weak_sharing_consistent [OF this] weak_sharing_consistent_append [of \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have weak_consis_drop:"weak_sharing_consistent \<O>\<^sub>j ?take_sb\<^sub>j" by auto from read_only_share_acquired_all_shared [OF this read_only_unowned [OF j_bound jth] a_ro_take ] a_notin_owns_j a_shared\<^sub>j have "a \<notin> all_acquired ?take_sb\<^sub>j" by auto with a_j a_notin_owns_j have a_drop: "a \<in> all_acquired ?drop_sb\<^sub>j" using all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] by simp from i_bound j_bound leq have j_bound_ts': "j < length ?ts'" by auto note conflict_drop = a_drop [simplified suspends\<^sub>j [symmetric]] from split_all_acquired_in [OF conflict_drop] (* FIXME: exract common parts *) show False proof assume "\<exists>sop a' v ys zs A L R W. (suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W# zs) \<and> a \<in> A" then obtain a' sop' v' ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a_A': "a \<in> A'" by blast from sharing_consis [OF j_bound jth] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". then have A'_R': "A' \<inter> R' = {}" by (simp add: sharing_consistent_append [of _ _ ?take_sb\<^sub>j ?drop_sb\<^sub>j, simplified] suspends\<^sub>j [symmetric] split_suspends\<^sub>j sharing_consistent_append) from valid_program_history [OF j_bound jth] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts'_j: "?ts'!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j, release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_last_prog [OF j_bound jth] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound jth] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound jth reads_consis_j] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m_j] have reads_consis_flush_suspend: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound jth] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound jth] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound jth] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']" and sb'="zs", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts'_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="share ?drop_sb \<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d\<^sup>* (?ts'[j:=(last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs)) (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']), is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), True, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (flush ?drop_sb m), share (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (share ?drop_sb \<S>))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append outstanding_refs_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b,(), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = rtranclp_trans [OF steps_flush_sb steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this i_bound_ys ts_ys_i, simplified is\<^sub>s\<^sub>b] non_vol a_not_acq have "a \<in> read_only (share (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (share ?drop_sb \<S>))" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done with a_A' show False by (simp add: share_append in_read_only_convs) next assume "\<exists>A L R W ys zs. suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A L R W # zs \<and> a \<in> A" then obtain A' L' R' W' ys zs where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a_A': "a \<in> A'" by blast from valid_program_history [OF j_bound jth] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts'_j: "?ts'!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j, release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_last_prog [OF j_bound jth] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound jth] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound jth reads_consis_j] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m_j] have reads_consis_flush_suspend: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound jth] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound jth] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound jth] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']" and sb'="zs", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts'_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="share ?drop_sb \<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d\<^sup>* (?ts'[j:=(last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)) (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']), is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (flush ?drop_sb m), share (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (share ?drop_sb \<S>))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b,\<theta>\<^sub>s\<^sub>b,(), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = rtranclp_trans [OF steps_flush_sb steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this i_bound_ys ts_ys_i, simplified is\<^sub>s\<^sub>b] non_vol a_not_acq have "a \<in> read_only (share (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (share ?drop_sb \<S>))" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done with a_A' show False by (simp add: share_append in_read_only_convs) qed qed } note non_volatile_unowned_others = this { assume a_in: "a \<in> read_only (share (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<S>)" assume nv: "\<not> volatile" have "a \<in> read_only (share sb \<S>\<^sub>s\<^sub>b)" proof (cases "a \<in> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb") case True from share_all_until_volatile_write_thread_local' [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b i_bound ts\<^sub>s\<^sub>b_i True] True a_in show ?thesis by (simp add: \<S> read_only_def) next case False from read_only_share_unowned [OF weak_consis_drop _ a_in] False acquired_all_acquired [of True ?take_sb \<O>\<^sub>s\<^sub>b] all_acquired_append [of ?take_sb ?drop_sb] have a_ro_shared: "a \<in> read_only \<S>" by auto have "a \<notin> \<Union>((\<lambda>(_, _, _, sb, _, _, _). all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)) ` set ts\<^sub>s\<^sub>b)" proof - { fix k p\<^sub>k "is\<^sub>k" \<theta>\<^sub>k sb\<^sub>k \<D>\<^sub>k \<O>\<^sub>k \<R>\<^sub>k assume k_bound: "k < length ts\<^sub>s\<^sub>b" assume ts_k: "ts\<^sub>s\<^sub>b ! k = (p\<^sub>k,is\<^sub>k,\<theta>\<^sub>k,sb\<^sub>k,\<D>\<^sub>k,\<O>\<^sub>k,\<R>\<^sub>k)" assume a_in: "a \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k)" have False proof (cases "k=i") case True with False ts\<^sub>s\<^sub>b_i ts_k a_in all_shared_acquired_or_owned [OF sharing_consis [OF k_bound ts_k]] all_shared_append [of "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k" "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k"] show False by auto next case False from rels_nv_cond [rule_format, OF nv k_bound [simplified leq] False [symmetric] ] ts_sim [rule_format, OF k_bound] ts_k have "a \<notin> dom (release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k) (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>k)" by (auto simp add: Let_def) with dom_release_takeWhile [of sb\<^sub>k "(dom (\<S>\<^sub>s\<^sub>b))" \<R>\<^sub>k] obtain a_rels\<^sub>j: "a \<notin> dom \<R>\<^sub>k" and a_shared\<^sub>j: "a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>k)" by auto with False a_in show ?thesis by auto qed } thus ?thesis by (auto simp add: in_set_conv_nth) qed with read_only_shared_all_until_volatile_write_subset' [of ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b] a_ro_shared have "a \<in> read_only \<S>\<^sub>s\<^sub>b" by (auto simp add: \<S>) from read_only_share_unowned' [OF weak_consis_sb read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] False this] show ?thesis . qed } note non_vol_ro_reduction = this have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (cases volatile) case False from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". then have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b False a t (m\<^sub>s\<^sub>b a)])" using access_cond' False non_vol_ro_reduction by (auto simp add: non_volatile_owned_or_read_only_append) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (auto simp add: False ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next case True from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". then have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b True a t (m\<^sub>s\<^sub>b a)])" using True by (simp add: non_volatile_owned_or_read_only_append) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (auto simp add: True ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof - have out: "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]) \<subseteq> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb" by (auto simp add: outstanding_refs_append) have "all_acquired (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]) \<subseteq> all_acquired sb" by (auto simp add: all_acquired_append) from outstanding_volatile_writes_unowned_by_others_store_buffer [OF i_bound ts\<^sub>s\<^sub>b_i out this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof (cases volatile) case True have r: "read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])) \<subseteq> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" apply (case_tac "outstanding_refs (is_volatile_Write\<^sub>s\<^sub>b) sb = {}") apply (simp_all add: outstanding_vol_write_take_drop_appends acquired_append read_only_reads_append True) done have "\<O>\<^sub>s\<^sub>b \<union> all_acquired (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]) \<subseteq> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by (simp add: all_acquired_append) from read_only_reads_unowned_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i r this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb') next case False show ?thesis proof (unfold_locales) fix n m fix p\<^sub>n "is\<^sub>n" \<O>\<^sub>n \<R>\<^sub>n \<D>\<^sub>n \<theta>\<^sub>n sb\<^sub>n p\<^sub>m "is\<^sub>m" \<O>\<^sub>m \<R>\<^sub>m \<D>\<^sub>m \<theta>\<^sub>m sb\<^sub>m assume n_bound: "n < length ts\<^sub>s\<^sub>b'" and m_bound: "m < length ts\<^sub>s\<^sub>b'" and neq_n_m: "n\<noteq>m" and nth: "ts\<^sub>s\<^sub>b'!n = (p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" and mth: "ts\<^sub>s\<^sub>b'!m =(p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" from n_bound have n_bound': "n < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from m_bound have m_bound': "m < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') have acq_eq: "(\<O>\<^sub>s\<^sub>b' \<union> all_acquired sb') = (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb)" by (simp add: all_acquired_append sb' \<O>\<^sub>s\<^sub>b') show "(\<O>\<^sub>m \<union> all_acquired sb\<^sub>m) \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<O>\<^sub>n) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) = {}" proof (cases "m=i") case True with neq_n_m have neq_n_i: "n\<noteq>i" by auto with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') note read_only_reads_unowned [OF n_bound' i_bound neq_n_i nth' ts\<^sub>s\<^sub>b_i] moreover note acq_eq ultimately show ?thesis using True ts\<^sub>s\<^sub>b_i nth mth n_bound' m_bound' by (simp add: ts\<^sub>s\<^sub>b') next case False note neq_m_i = this with m_bound mth i_bound have mth': "ts\<^sub>s\<^sub>b!m = (p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" by (auto simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "n=i") case True note read_only_reads_unowned [OF i_bound m_bound' neq_m_i [symmetric] ts\<^sub>s\<^sub>b_i mth'] moreover note acq_eq moreover note non_volatile_unowned_others [OF m_bound' neq_m_i [symmetric] mth'] ultimately show ?thesis using True ts\<^sub>s\<^sub>b_i nth mth n_bound' m_bound' neq_m_i apply (case_tac "outstanding_refs (is_volatile_Write\<^sub>s\<^sub>b) sb = {}") apply (clarsimp simp add: outstanding_vol_write_take_drop_appends acquired_append read_only_reads_append ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b')+ done next case False with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_reads_unowned [OF n_bound' m_bound' neq_n_m nth' mth'] False neq_m_i show ?thesis by (clarsimp) qed qed qed qed show "ownership_distinct ts\<^sub>s\<^sub>b'" proof - have "all_acquired (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]) \<subseteq> all_acquired sb" by (auto simp add: all_acquired_append) from ownership_distinct_instructions_read_value_store_buffer_independent [OF i_bound ts\<^sub>s\<^sub>b_i this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') qed qed have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" proof - from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have hcons: "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b sb) sb". from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have t_notin_reads: "t \<notin> read_tmps sb" by (auto simp add: "is\<^sub>s\<^sub>b") from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have t_notin_writes: "t \<notin> \<Union>(fst ` write_sops sb )" by (auto simp add: "is\<^sub>s\<^sub>b") from valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have valid_sops: "\<forall>sop \<in> write_sops sb. valid_sop sop" by auto from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have t_fresh: "t \<notin> dom \<theta>\<^sub>s\<^sub>b" using "is\<^sub>s\<^sub>b" by simp from valid_implies_valid_prog_hd [OF i_bound ts\<^sub>s\<^sub>b_i valid] have "history_consistent (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a)) (hd_prog p\<^sub>s\<^sub>b (sb@ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])) (sb@ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])" using t_notin_writes valid_sops t_fresh hcons apply - apply (rule history_consistent_appendI) apply (auto simp add: hd_prog_append_Read\<^sub>s\<^sub>b) done from valid_history_nth_update [OF i_bound this] show ?thesis by (auto simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed from reads_consistent_unbuffered_snoc [OF buf_None refl valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] volatile_cond ] have reads_consis': "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])" by (simp split: if_split_asm) from valid_reads_nth_update [OF i_bound this] have valid_reads': "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])" by (auto simp add: non_volatile_writes_unshared_append) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' \<S>\<^sub>s\<^sub>b') next from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". then have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])" by (simp add: sharing_consistent_append) from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' \<S>\<^sub>s\<^sub>b') next note read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] from read_only_unowned_nth_update [OF i_bound this] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b sb". hence "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])" by (simp add: no_write_to_read_only_memory_append) from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound this] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' sb') qed have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b'" by (auto split: instr.splits simp add: is\<^sub>s\<^sub>b) from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') next from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps sb". moreover from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "t \<notin> read_tmps sb" by (auto simp add: is\<^sub>s\<^sub>b) ultimately have "distinct_read_tmps (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])" by (auto simp add: distinct_read_tmps_append) from read_tmps_distinct_nth_update [OF i_bound this] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> read_tmps (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]) = {}" by (clarsimp simp add: read_tmps_append "is\<^sub>s\<^sub>b") from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb') qed have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" proof - from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have valid_store_sops': "\<forall>sop\<in>store_sops is\<^sub>s\<^sub>b'. valid_sop sop" by (auto simp add: "is\<^sub>s\<^sub>b") from valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have valid_write_sops': "\<forall>sop\<in>write_sops (sb@ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]). valid_sop sop" by (auto simp add: write_sops_append) from valid_sops_nth_update [OF i_bound valid_write_sops' valid_store_sops'] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" proof - from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] have dd_is: "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b') is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b') from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> \<Union>(fst ` write_sops (sb@ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])) = {}" by (auto simp add: write_sops_append "is\<^sub>s\<^sub>b") from valid_data_dependency_nth_update [OF i_bound dd_is this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps (Read volatile a t # is\<^sub>s\<^sub>b') \<inter> dom \<theta>\<^sub>s\<^sub>b = {}" by (simp add: "is\<^sub>s\<^sub>b") moreover from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "t \<notin> load_tmps is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b") ultimately have "load_tmps is\<^sub>s\<^sub>b' \<inter> dom (\<theta>\<^sub>s\<^sub>b(t \<mapsto> (m\<^sub>s\<^sub>b a))) = {}" by auto from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<theta>\<^sub>s\<^sub>b') qed have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" proof - from clean_no_outstanding_volatile_Write\<^sub>s\<^sub>b [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<not> \<D>\<^sub>s\<^sub>b \<longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]) = {}" by (auto simp add: outstanding_refs_append ) from enough_flushs_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b') qed have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . then have causal': "causal_program_history is\<^sub>s\<^sub>b' (sb@[Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])" by (auto simp: causal_program_history_Read "is\<^sub>s\<^sub>b") from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". hence "last_prog p\<^sub>s\<^sub>b (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]) = p\<^sub>s\<^sub>b" by (simp add: last_prog_append_Read\<^sub>s\<^sub>b) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed show ?thesis proof (cases "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}") case True from True have flush_all: "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = sb" by (auto simp add: outstanding_refs_conv ) from True have suspend_nothing: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = []" by (auto simp add: outstanding_refs_conv) hence suspends_empty: "suspends = []" by (simp add: suspends) from suspends_empty is_sim have "is": "is = Read volatile a t # is\<^sub>s\<^sub>b'" by (simp add: "is\<^sub>s\<^sub>b") with suspends_empty ts_i have ts_i: "ts!i = (p\<^sub>s\<^sub>b, Read volatile a t # is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp from direct_memop_step.Read have "(Read volatile a t # is\<^sub>s\<^sub>b',\<theta>\<^sub>s\<^sub>b, (), m, \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b,\<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> m a), (), m, \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, \<S>)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i this] have "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> m a), (), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)], m, \<S>)". moreover from flush_all_until_volatile_write_Read_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified "is\<^sub>s\<^sub>b"] ] have flush_commute: "flush_all_until_volatile_write (ts\<^sub>s\<^sub>b[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a), sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)], \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)]) m\<^sub>s\<^sub>b = flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b". have "flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b a = m\<^sub>s\<^sub>b a" proof - have "\<forall>j < length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,_,_) = ts\<^sub>s\<^sub>b!j in a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" proof - { fix j p\<^sub>j "is\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j, xs\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j, \<R>\<^sub>j)" have "a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" proof let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume a_in: "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b ?take_sb\<^sub>j" with outstanding_refs_takeWhile [where P'= "Not \<circ> is_volatile_Write\<^sub>s\<^sub>b"] have a_in': "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" by auto with non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound jth]] have j_owns: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto with ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] have a_not_owns: "a \<notin> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by blast from non_volatile_owned_or_read_only_append [of False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] outstanding_non_volatile_refs_owned_or_read_only [OF j_bound jth] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j" by simp from non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF this] a_in have j_owns_drop: "a \<in> \<O>\<^sub>j \<union> all_acquired ?take_sb\<^sub>j" by auto from rels_cond [rule_format, OF j_bound [simplified leq] neq_i_j] ts_sim [rule_format, OF j_bound] jth have no_unsharing:"release ?take_sb\<^sub>j (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>j a \<noteq> Some False" by (auto simp add: Let_def) { assume "a \<in> acquired True sb \<O>\<^sub>s\<^sub>b" with acquired_all_acquired_in [OF this] ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] j_owns have False by auto } moreover { assume a_ro: "a \<in> read_only (share ?drop_sb \<S>)" from read_only_share_unowned_in [OF weak_consis_drop a_ro] a_not_owns acquired_all_acquired [of True ?take_sb \<O>\<^sub>s\<^sub>b] all_acquired_append [of ?take_sb ?drop_sb] have "a \<in> read_only \<S>" by auto with share_all_until_volatile_write_thread_local [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b j_bound jth j_owns] have "a \<in> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: read_only_def \<S>) hence a_dom: "a \<in> dom (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: read_only_def domIff) from outstanding_non_volatile_writes_unshared [OF j_bound jth] non_volatile_writes_unshared_append [of \<S>\<^sub>s\<^sub>b ?take_sb\<^sub>j ?drop_sb\<^sub>j] have nvw: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b ?take_sb\<^sub>j" by auto from release_not_unshared_no_write_take [OF this no_unsharing a_dom] a_in have False by auto } moreover { assume a_share: "volatile \<and> a \<in> dom (share ?drop_sb \<S>)" from outstanding_non_volatile_writes_unshared [OF j_bound jth] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb\<^sub>j". with non_volatile_writes_unshared_append [of \<S>\<^sub>s\<^sub>b "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] have unshared_take: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" by clarsimp from valid_own have own_dist: "ownership_distinct ts\<^sub>s\<^sub>b" by (simp add: valid_ownership_def) from valid_sharing have "sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" by (simp add: valid_sharing_def) from sharing_consistent_share_all_until_volatile_write [OF own_dist this i_bound ts\<^sub>s\<^sub>b_i] have sc: "sharing_consistent \<S> (acquired True ?take_sb \<O>\<^sub>s\<^sub>b) ?drop_sb" by (simp add: \<S>) from sharing_consistent_share_all_shared have "dom (share ?drop_sb \<S>) \<subseteq> dom \<S> \<union> all_shared ?drop_sb" by auto also from sharing_consistent_all_shared [OF sc] have "\<dots> \<subseteq> dom \<S> \<union> acquired True ?take_sb \<O>\<^sub>s\<^sub>b" by auto also from acquired_all_acquired all_acquired_takeWhile have "\<dots> \<subseteq> dom \<S> \<union> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb)" by force finally have a_shared: "a \<in> dom \<S>" using a_share a_not_owns by auto with share_all_until_volatile_write_thread_local [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b j_bound jth j_owns] have a_dom: "a \<in> dom (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: \<S> domIff) from release_not_unshared_no_write_take [OF unshared_take no_unsharing a_dom] a_in have False by auto } ultimately show False using access_cond' by auto qed } thus ?thesis by (fastforce simp add: Let_def) qed from flush_all_until_volatile_write_buffered_val_conv [OF True i_bound ts\<^sub>s\<^sub>b_i this] show ?thesis by (simp add: buf_None) qed hence m_a: "m a = m\<^sub>s\<^sub>b a" by (simp add: m) have tmps_commute: "\<theta>\<^sub>s\<^sub>b(t \<mapsto> (m\<^sub>s\<^sub>b a)) = (\<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - {t}))(t \<mapsto> (m\<^sub>s\<^sub>b a))" apply (rule ext) apply (auto simp add: restrict_map_def domIff) done from suspend_nothing have suspend_nothing': "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = []" by (simp add: sb') from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t\<mapsto>m a),(), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)], m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b' ) using share_all_until_volatile_write_Read_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b]] apply (simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i True \<D>' apply (clarsimp simp add: Let_def nth_list_update outstanding_refs_conv m_a ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b' suspend_nothing' flush_all acquired_append release_append split: if_split_asm ) apply (rule tmps_commute) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_sops' valid_dd' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply ) next case False then obtain r where r_in: "r \<in> set sb" and volatile_r: "is_volatile_Write\<^sub>s\<^sub>b r" by (auto simp add: outstanding_refs_conv) from takeWhile_dropWhile_real_prefix [OF r_in, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)", simplified, OF volatile_r] obtain a' v' sb'' sop' A' L' R' W' where sb_split: "sb = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" and drop: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" apply (auto) subgoal for y ys apply (case_tac y) apply auto done done from drop suspends have suspends: "suspends = Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" by simp have "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts, m, \<S>)" by auto moreover note flush_commute = flush_all_until_volatile_write_Read_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified "is\<^sub>s\<^sub>b"] ] have "Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'\<in> set sb" by (subst sb_split) auto from dropWhile_append1 [OF this, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)"] have drop_app_comm: "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)])) = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ [Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]" by simp from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "t \<notin> dom \<theta>\<^sub>s\<^sub>b" by (auto simp add: "is\<^sub>s\<^sub>b") then have tmps_commute: "\<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - read_tmps sb'') = \<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - insert t (read_tmps sb''))" apply - apply (rule ext) apply auto done from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Read\<^sub>s\<^sub>b volatile a t (m\<^sub>s\<^sub>b a)]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb') using share_all_until_volatile_write_Read_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b]] apply (simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i is_sim \<D>' apply (clarsimp simp add: Let_def nth_list_update is_sim drop_app_comm read_tmps_append suspends prog_instrs_append_Read\<^sub>s\<^sub>b instrs_append_Read\<^sub>s\<^sub>b hd_prog_append_Read\<^sub>s\<^sub>b drop "is\<^sub>s\<^sub>b" ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' acquired_append takeWhile_append1 [OF r_in] volatile_r split: if_split_asm) apply (simp add: drop tmps_commute)+ done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply ) qed next case (SBHWriteNonVolatile a D f A L R W) then obtain "is\<^sub>s\<^sub>b": "is\<^sub>s\<^sub>b = Write False a (D, f) A L R W# is\<^sub>s\<^sub>b'" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=\<R>\<^sub>s\<^sub>b" and \<theta>\<^sub>s\<^sub>b': "\<theta>\<^sub>s\<^sub>b' = \<theta>\<^sub>s\<^sub>b" and \<D>\<^sub>s\<^sub>b': "\<D>\<^sub>s\<^sub>b'=\<D>\<^sub>s\<^sub>b" and sb': "sb'=sb@[Write\<^sub>s\<^sub>b False a (D, f) (f \<theta>\<^sub>s\<^sub>b) A L R W]" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b' = m\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" by auto from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] have D_tmps: "D \<subseteq> dom \<theta>\<^sub>s\<^sub>b" by (simp add: is\<^sub>s\<^sub>b) from safe_memop_flush_sb [simplified is\<^sub>s\<^sub>b] obtain a_owned': "a \<in> acquired True sb \<O>\<^sub>s\<^sub>b" and a_unshared': "a \<notin> dom (share ?drop_sb \<S>)" and rels_cond: "\<forall>j < length ts. i\<noteq>j \<longrightarrow> a \<notin> dom (released (ts!j))" (* FIXME: rels_cond unused; maybe remove from safe_delayed *) by cases auto from a_owned' acquired_all_acquired have a_owned'': "a \<in> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by auto { fix j fix p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume neq_i_j: "i \<noteq> j" have "a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof - from ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] a_owned'' show ?thesis by auto qed } note a_unowned_others = this have a_unshared: "a \<notin> dom (share sb \<S>\<^sub>s\<^sub>b)" proof assume a_share: "a \<in> dom (share sb \<S>\<^sub>s\<^sub>b)" from valid_sharing have "sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" by (simp add: valid_sharing_def) from in_shared_sb_share_all_until_volatile_write [OF this i_bound ts\<^sub>s\<^sub>b_i a_owned'' a_share] have "a \<in> dom (share ?drop_sb \<S>)" by (simp add: \<S>) with a_unshared' show False by auto qed (* from acquired_owns_shared [OF sharing_consis_drop_sb] have "acquired True ?drop_sb \<O> \<subseteq> \<O> \<union> \<S>". moreover from share_owns_shared [OF sharing_consis_drop_sb] have "share ?drop_sb \<S> \<subseteq> \<O> \<union> \<S>". *) (* obtain a_owned: "a \<in> \<O>" and a_unshared: "a \<notin> \<S>" by cases auto *) have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". with a_owned' have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (simp add: non_volatile_owned_or_read_only_append) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof - have "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) \<subseteq> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb" by (auto simp add: outstanding_refs_append) from outstanding_volatile_writes_unowned_by_others_store_buffer [OF i_bound ts\<^sub>s\<^sub>b_i this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' all_acquired_append) qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof - have r: "read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])) \<subseteq> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" apply (case_tac "outstanding_refs (is_volatile_Write\<^sub>s\<^sub>b) sb = {}") apply (simp_all add: outstanding_vol_write_take_drop_appends acquired_append read_only_reads_append ) done have "\<O>\<^sub>s\<^sub>b \<union> all_acquired (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) \<subseteq> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by (simp add: all_acquired_append) from read_only_reads_unowned_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i r this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb') qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof - from ownership_distinct_instructions_read_value_store_buffer_independent [OF i_bound ts\<^sub>s\<^sub>b_i] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' all_acquired_append) qed qed have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" proof - from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b sb) sb". with valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] D_tmps valid_implies_valid_prog_hd [OF i_bound ts\<^sub>s\<^sub>b_i valid] have "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b (sb@[Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])) (sb@ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" apply - apply (rule history_consistent_appendI) apply (auto simp add: hd_prog_append_Write\<^sub>s\<^sub>b) done from valid_history_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have valid_reads': "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b'" proof - from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b sb" . from reads_consistent_snoc_Write\<^sub>s\<^sub>b [OF this] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])". from valid_reads_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] a_unshared have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (auto simp add: non_volatile_writes_unshared_append) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". then have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (simp add: sharing_consistent_append) from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' \<S>\<^sub>s\<^sub>b') next from read_only_unowned_nth_update [OF i_bound read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] ] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from a_unshared have "a \<notin> read_only (share sb \<S>\<^sub>s\<^sub>b)" by (auto simp add: read_only_def dom_def) with no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (simp add: no_write_to_read_only_memory_append) from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound this] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb') qed have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b'" by (auto split: instr.splits simp add: "is\<^sub>s\<^sub>b") from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') next from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps sb". hence "distinct_read_tmps (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (simp add: distinct_read_tmps_append) from read_tmps_distinct_nth_update [OF i_bound this] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> read_tmps (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) = {}" by (clarsimp simp add: read_tmps_append "is\<^sub>s\<^sub>b") from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" proof - from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] obtain valid_Df: "valid_sop (D,f)" and valid_store_sops': "\<forall>sop\<in>store_sops is\<^sub>s\<^sub>b'. valid_sop sop" by (auto simp add: "is\<^sub>s\<^sub>b") from valid_Df valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have valid_write_sops': "\<forall>sop\<in>write_sops (sb@ [Write\<^sub>s\<^sub>b False a (D, f) (f \<theta>\<^sub>s\<^sub>b) A L R W]). valid_sop sop" by (auto simp add: write_sops_append) from valid_sops_nth_update [OF i_bound valid_write_sops' valid_store_sops'] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" proof - from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] obtain D_indep: "D \<inter> load_tmps is\<^sub>s\<^sub>b' = {}" and dd_is: "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b') is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b') from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] D_indep have "load_tmps is\<^sub>s\<^sub>b' \<inter> \<Union>(fst ` write_sops (sb@ [Write\<^sub>s\<^sub>b False a (D, f) (f \<theta>\<^sub>s\<^sub>b) A L R W])) = {}" by (auto simp add: write_sops_append "is\<^sub>s\<^sub>b") from valid_data_dependency_nth_update [OF i_bound dd_is this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> dom \<theta>\<^sub>s\<^sub>b = {}" by (auto simp add: "is\<^sub>s\<^sub>b") from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b" sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" proof - from clean_no_outstanding_volatile_Write\<^sub>s\<^sub>b [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<not> \<D>\<^sub>s\<^sub>b \<longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) = {}" by (auto simp add: outstanding_refs_append ) from enough_flushs_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b') qed have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . then have causal': "causal_program_history is\<^sub>s\<^sub>b' (sb@[Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (auto simp: causal_program_history_Write "is\<^sub>s\<^sub>b") from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". hence "last_prog p\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) = p\<^sub>s\<^sub>b" by (simp add: last_prog_append_Write\<^sub>s\<^sub>b) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i, rule_format] have "valid_sop (D,f)" by (auto simp add: "is\<^sub>s\<^sub>b") then interpret valid_sop "(D,f)" . show ?thesis proof (cases "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}") case True from True have flush_all: "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = sb" by (auto simp add: outstanding_refs_conv) from True have suspend_nothing: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = []" by (auto simp add: outstanding_refs_conv) hence suspends_empty: "suspends = []" by (simp add: suspends) from suspends_empty is_sim have "is": "is = Write False a (D,f) A L R W# is\<^sub>s\<^sub>b'" by (simp add: "is\<^sub>s\<^sub>b") with suspends_empty ts_i have ts_i: "ts!i = (p\<^sub>s\<^sub>b, Write False a (D,f) A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>s\<^sub>b)" by simp from direct_memop_step.WriteNonVolatile [OF ] have "(Write False a (D, f) A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),m,\<D>,acquired True ?take_sb \<O>\<^sub>s\<^sub>b ,release ?take_sb (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>s\<^sub>b, \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), m(a := f \<theta>\<^sub>s\<^sub>b), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>s\<^sub>b, \<S>)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i this] have "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),\<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>s\<^sub>b)], m(a := f \<theta>\<^sub>s\<^sub>b),\<S>)". moreover have "\<forall>j<length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_, _, sb\<^sub>j,_,_,_) = ts\<^sub>s\<^sub>b ! j in a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" proof - { fix j p\<^sub>j "is\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j, xs\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j,\<R>\<^sub>j)" have "a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" proof assume a_in: "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" hence "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" using outstanding_refs_append [of is_non_volatile_Write\<^sub>s\<^sub>b "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto with non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound jth]] have j_owns: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto from j_owns a_owned'' ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] show False by auto qed } thus ?thesis by (fastforce simp add: Let_def) qed note flush_commute = flush_all_until_volatile_write_append_non_volatile_write_commute [OF True i_bound ts\<^sub>s\<^sub>b_i this] from suspend_nothing have suspend_nothing': "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = []" by (simp add: sb') from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(),\<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>s\<^sub>b)], m(a:=f \<theta>\<^sub>s\<^sub>b),\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' sb' \<theta>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' ) using share_all_until_volatile_write_Write_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b]] apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i True \<D>' apply (clarsimp simp add: Let_def nth_list_update outstanding_refs_conv ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b' suspend_nothing' flush_all acquired_append release_append split: if_split_asm) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_sops' valid_dd' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply) next case False then obtain r where r_in: "r \<in> set sb" and volatile_r: "is_volatile_Write\<^sub>s\<^sub>b r" by (auto simp add: outstanding_refs_conv) from takeWhile_dropWhile_real_prefix [OF r_in, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)", simplified, OF volatile_r] obtain a' v' sb'' sop' A' L' R' W' where sb_split: "sb = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" and drop: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" apply (auto) subgoal for y ys apply (case_tac y) apply auto done done from drop suspends have suspends: "suspends = Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" by simp have "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts, m, \<S>)" by auto moreover note flush_commute = flush_all_until_volatile_write_append_unflushed [OF False i_bound ts\<^sub>s\<^sub>b_i] have "Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W' \<in> set sb" by (subst sb_split) auto note drop_app = dropWhile_append1 [OF this, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)", simplified] from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb') using share_all_until_volatile_write_Write_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b]] apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i is_sim \<D>' apply (clarsimp simp add: Let_def nth_list_update is_sim drop_app read_tmps_append suspends prog_instrs_append_Write\<^sub>s\<^sub>b instrs_append_Write\<^sub>s\<^sub>b hd_prog_append_Write\<^sub>s\<^sub>b drop "is\<^sub>s\<^sub>b" ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' acquired_append takeWhile_append1 [OF r_in] volatile_r split: if_split_asm) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply ) qed next case (SBHWriteVolatile a D f A L R W) then obtain "is\<^sub>s\<^sub>b": "is\<^sub>s\<^sub>b = Write True a (D, f) A L R W# is\<^sub>s\<^sub>b'" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=\<R>\<^sub>s\<^sub>b" and \<theta>\<^sub>s\<^sub>b': "\<theta>\<^sub>s\<^sub>b' = \<theta>\<^sub>s\<^sub>b" and \<D>\<^sub>s\<^sub>b': "\<D>\<^sub>s\<^sub>b'=True" and sb': "sb'=sb@[Write\<^sub>s\<^sub>b True a (D, f) (f \<theta>\<^sub>s\<^sub>b) A L R W]" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b' = m\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" by auto from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] have D_subset: "D \<subseteq> dom \<theta>\<^sub>s\<^sub>b" by (simp add: is\<^sub>s\<^sub>b) from safe_memop_flush_sb [simplified is\<^sub>s\<^sub>b] obtain a_unowned_others_ts: "\<forall>j<length (map owned ts). i \<noteq> j \<longrightarrow> (a \<notin> owned (ts!j) \<union> dom (released (ts!j)))" and L_subset: "L \<subseteq> A" and A_shared_owned: "A \<subseteq> dom (share ?drop_sb \<S>) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" and R_acq: "R \<subseteq> acquired True sb \<O>\<^sub>s\<^sub>b" and A_R: "A \<inter> R = {}" and A_unowned_by_others_ts: "\<forall>j<length (map owned ts). i\<noteq>j \<longrightarrow> (A \<inter> (owned (ts!j) \<union> dom (released (ts!j))) = {})" and a_not_ro': "a \<notin> read_only (share ?drop_sb \<S>)" by cases auto from a_unowned_others_ts ts_sim leq have a_unowned_others: "\<forall>j<length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,\<O>\<^sub>j,_) = ts\<^sub>s\<^sub>b!j in a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<and> a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" apply (clarsimp simp add: Let_def) subgoal for j apply (drule_tac x=j in spec) apply (auto simp add: dom_release_takeWhile) done done (* from a_unowned_others_ts ts_sim leq have a_unowned_others: "\<forall>j<length (map owns_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j,sb\<^sub>j) = (map owns_sb ts\<^sub>s\<^sub>b)!j in a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<and> a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" apply (clarsimp simp add: Let_def) apply (drule_tac x=j in spec) apply (auto simp add: dom_release_takeWhile) done *) (* from a_unowned_others have a_unacquired_others: "\<forall>j<length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,_) = ts\<^sub>s\<^sub>b!j in a \<notin> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" by (auto simp add: acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) *) have a_not_ro: "a \<notin> read_only (share sb \<S>\<^sub>s\<^sub>b)" proof assume a: "a \<in> read_only (share sb \<S>\<^sub>s\<^sub>b)" from local.read_only_unowned_axioms have "read_only_unowned \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b". from in_read_only_share_all_until_volatile_write' [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b \<open>read_only_unowned \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> i_bound ts\<^sub>s\<^sub>b_i a_unowned_others a] have "a \<in> read_only (share ?drop_sb \<S>)" by (simp add: \<S>) with a_not_ro' show False by simp qed from A_unowned_by_others_ts ts_sim leq have A_unowned_by_others: "\<forall>j<length ts\<^sub>s\<^sub>b. i\<noteq>j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,\<O>\<^sub>j,_) = ts\<^sub>s\<^sub>b!j in A \<inter> (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<union> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)) = {})" apply (clarsimp simp add: Let_def) subgoal for j apply (drule_tac x=j in spec) apply (force simp add: dom_release_takeWhile) done done have a_not_acquired_others: "\<forall>j<length (map \<O>_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j,sb\<^sub>j) = (map \<O>_sb ts\<^sub>s\<^sub>b)!j in a \<notin> all_acquired sb\<^sub>j)" proof - { fix j \<O>\<^sub>j sb\<^sub>j assume j_bound: "j < length (map owned ts\<^sub>s\<^sub>b)" assume neq_i_j: "i\<noteq>j" assume ts\<^sub>s\<^sub>b_j: "(map \<O>_sb ts\<^sub>s\<^sub>b)!j = (\<O>\<^sub>j,sb\<^sub>j)" assume conflict: "a \<in> all_acquired sb\<^sub>j" have False proof - from j_bound leq have j_bound': "j < length (map owned ts)" by auto from j_bound have j_bound'': "j < length ts\<^sub>s\<^sub>b" by auto from j_bound' have j_bound''': "j < length ts" by simp let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" from ts_sim [rule_format, OF j_bound''] ts\<^sub>s\<^sub>b_j j_bound'' obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<R>\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>j \<theta>\<^sub>s\<^sub>b\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j, \<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j, release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (force simp add: Let_def) done from a_unowned_others [rule_format,OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound obtain a_unacq: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" and a_not_shared: "a \<notin> all_shared ?take_sb\<^sub>j" by auto have conflict_drop: "a \<in> all_acquired suspends\<^sub>j" proof (rule ccontr) assume "a \<notin> all_acquired suspends\<^sub>j" with all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] conflict have "a \<in> all_acquired ?take_sb\<^sub>j" by (auto simp add: suspends\<^sub>j) from all_acquired_unshared_acquired [OF this a_not_shared] a_unacq show False by auto qed from j_bound''' i_bound' have j_bound_ts': "j < length ?ts'" by simp (* FIXME: extract common intermediate steps of both cases*) from split_all_acquired_in [OF conflict_drop] show ?thesis proof assume "\<exists>sop a' v ys zs A L R W. suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W# zs \<and> a \<in> A" then obtain a' sop' v' ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a_A': "a \<in> A'" by blast from sharing_consis [OF j_bound'' ts\<^sub>s\<^sub>b_j] have sharing_consis_j: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". then have A'_R': "A' \<inter> R' = {}" by (simp add: sharing_consistent_append [of _ _ ?take_sb\<^sub>j ?drop_sb\<^sub>j, simplified] suspends\<^sub>j [symmetric] split_suspends\<^sub>j sharing_consistent_append) from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts'_j: "?ts'!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m_j] have reads_consis_flush_suspend: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']" and sb'="zs", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts'_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="share ?drop_sb \<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d\<^sup>* (?ts'[j:=(last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs)) (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']), is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), True, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (flush ?drop_sb m), share (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (share ?drop_sb \<S>))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append outstanding_refs_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b,(), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = rtranclp_trans [OF steps_flush_sb steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this i_bound_ys ts_ys_i, simplified is\<^sub>s\<^sub>b] have a_unowned: "\<forall>j < length ?ts_ys. i\<noteq>j \<longrightarrow> (let (\<O>\<^sub>j) = map owned ?ts_ys!j in a \<notin> \<O>\<^sub>j)" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done from a_A' a_unowned [rule_format, of j] neq_i_j j_bound' A'_R' show False by (auto simp add: Let_def) next assume "\<exists>A L R W ys zs. suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a \<in> A" then obtain A' L' R' W' ys zs where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a_A': "a \<in> A'" by blast from sharing_consis [OF j_bound'' ts\<^sub>s\<^sub>b_j] have sharing_consis_j: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". then have A'_R': "A' \<inter> R' = {}" by (simp add: sharing_consistent_append [of _ _ ?take_sb\<^sub>j ?drop_sb\<^sub>j, simplified] suspends\<^sub>j [symmetric] split_suspends\<^sub>j sharing_consistent_append) from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts'_j: "?ts'!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j, release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m_j] have reads_consis_flush_suspend: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']" and sb'="zs", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts'_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="share ?drop_sb \<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d\<^sup>* (?ts'[j:=(last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)) (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']), is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (flush ?drop_sb m), share (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (share ?drop_sb \<S>))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b,\<theta>\<^sub>s\<^sub>b,(), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = rtranclp_trans [OF steps_flush_sb steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this i_bound_ys ts_ys_i, simplified is\<^sub>s\<^sub>b] have a_unowned: "\<forall>j < length ?ts_ys. i\<noteq>j \<longrightarrow> (let (\<O>\<^sub>j) = map owned ?ts_ys!j in a \<notin> \<O>\<^sub>j)" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done from a_A' a_unowned [rule_format, of j] neq_i_j j_bound' A'_R' show False by (auto simp add: Let_def) qed qed } thus ?thesis by (auto simp add: Let_def) qed have A_unused_by_others: "\<forall>j<length (map \<O>_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j, sb\<^sub>j) = map \<O>_sb ts\<^sub>s\<^sub>b! j in A \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j = {})" proof - { fix j \<O>\<^sub>j sb\<^sub>j assume j_bound: "j < length (map owned ts\<^sub>s\<^sub>b)" assume neq_i_j: "i\<noteq>j" assume ts\<^sub>s\<^sub>b_j: "(map \<O>_sb ts\<^sub>s\<^sub>b)!j = (\<O>\<^sub>j,sb\<^sub>j)" assume conflict: "A \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {}" have False proof - from j_bound leq have j_bound': "j < length (map owned ts)" by auto from j_bound have j_bound'': "j < length ts\<^sub>s\<^sub>b" by auto from j_bound' have j_bound''': "j < length ts" by simp from conflict obtain a' where a'_in: "a' \<in> A" and a'_in_j: "a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" by auto let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" from ts_sim [rule_format, OF j_bound''] ts\<^sub>s\<^sub>b_j j_bound'' obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<D>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>j \<R>\<^sub>j \<theta>\<^sub>s\<^sub>b\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j, release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (force simp add: Let_def) done have "a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b suspends\<^sub>j" proof - from a'_in_j have "a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (?take_sb\<^sub>j @ ?drop_sb\<^sub>j)" by simp thus ?thesis apply (simp only: outstanding_refs_append suspends\<^sub>j) apply (auto simp add: outstanding_refs_conv dest: set_takeWhileD) done qed from split_volatile_Write\<^sub>s\<^sub>b_in_outstanding_refs [OF this] obtain sop v ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") by blast from direct_memop_step.WriteVolatile [where \<theta>=\<theta>\<^sub>s\<^sub>b and m="flush ?drop_sb m"] have "(Write True a (D, f) A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m,\<D>\<^sub>s\<^sub>b,acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, share ?drop_sb \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), (flush ?drop_sb m)(a := f \<theta>\<^sub>s\<^sub>b), True, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R, Map.empty, share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound_ts' [simplified is\<^sub>s\<^sub>b] ts'_i [simplified is\<^sub>s\<^sub>b] this [simplified is\<^sub>s\<^sub>b]] have store_step: "(?ts', flush ?drop_sb m,share ?drop_sb \<S> ) \<Rightarrow>\<^sub>d (?ts'[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), True, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)], (flush ?drop_sb m)(a := f \<theta>\<^sub>s\<^sub>b), share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L )" (is " _ \<Rightarrow>\<^sub>d (?ts_A, ?m_A, ?share_A)") by (simp add: is\<^sub>s\<^sub>b) from i_bound' have i_bound'': "i < length ?ts_A" by simp from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts_A_j: "?ts_A!j = (hd_prog p\<^sub>j (ys @ Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs), is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (ys @ Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs)), (), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (simp add: split_suspends\<^sub>j) from j_bound''' i_bound' neq_i_j have j_bound'''': "j < length ?ts_A" by simp from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j reads_consis] have reads_consis_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m] have reads_consis_flush_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". from a_unowned_others [rule_format, OF _ neq_i_j] j_bound ts\<^sub>s\<^sub>b_j obtain a_notin_owns_j: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" and a_unshared: "a \<notin> all_shared ?take_sb\<^sub>j" by auto from a_not_acquired_others [rule_format, OF _ neq_i_j] j_bound ts\<^sub>s\<^sub>b_j have a_not_acquired_j: "a \<notin> all_acquired sb\<^sub>j" by auto from outstanding_non_volatile_refs_owned_or_read_only [OF j_bound'' ts\<^sub>s\<^sub>b_j] have nvo_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". (* FIXME: make this a lemma, duplicated some times below *) have a_no_non_vol_read: "a \<notin> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j" proof assume a_in_nvr:"a \<in> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j" from reads_consistent_drop [OF reads_consis] have rc: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?take_sb\<^sub>j m\<^sub>s\<^sub>b) ?drop_sb\<^sub>j". from non_volatile_owned_or_read_only_drop [OF nvo_j] have nvo_j_drop: "non_volatile_owned_or_read_only True (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by simp from outstanding_refs_non_volatile_Read\<^sub>s\<^sub>b_all_acquired [OF rc this a_in_nvr] have a_owns_acq_ror: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j \<union> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by (auto dest!: acquired_all_acquired_in all_acquired_takeWhile_dropWhile_in simp add: acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) have a_unowned_j: "a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof (cases "a \<in> \<O>\<^sub>j") case False with a_not_acquired_j show ?thesis by auto next case True from all_shared_acquired_in [OF True a_unshared] a_notin_owns_j have False by auto thus ?thesis .. qed with a_owns_acq_ror have a_ror: "a \<in> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto with read_only_reads_unowned [OF j_bound'' i_bound neq_i_j [symmetric] ts\<^sub>s\<^sub>b_j ts\<^sub>s\<^sub>b_i] have a_unowned_sb: "a \<notin> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by auto from sharing_consis [OF j_bound'' ts\<^sub>s\<^sub>b_j] sharing_consistent_append [of \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have consis_j_drop: "sharing_consistent (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto from read_only_reads_read_only [OF nvo_j_drop consis_j_drop] a_ror a_unowned_j all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b [of sb\<^sub>j \<O>\<^sub>j] have "a \<in> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: ) from read_only_share_all_shared [OF this] a_unshared have "a \<in> read_only \<S>\<^sub>s\<^sub>b" by fastforce from read_only_unacquired_share [OF read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] weak_sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] this] a_unowned_sb have "a \<in> read_only (share sb \<S>\<^sub>s\<^sub>b)" by auto with a_not_ro show False by simp qed with reads_consistent_mem_eq_on_non_volatile_reads [OF _ subset_refl reads_consis_flush_m] have "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) hence reads_consis_m_A_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A ys" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops ys. valid_sop sop" apply (simp only: write_sops_append ) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b ys = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from flush_store_buffer_append [ OF j_bound'''' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_A_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_m_A_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?share_A"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs) @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs)" and steps_ys: "(?ts_A, ?m_A, ?share_A) \<Rightarrow>\<^sub>d\<^sup>* (?ts_A[j:= (last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W' # zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j') ], flush ys ?m_A, share ys ?share_A)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto) note conflict_computation = rtranclp_trans [OF rtranclp_r_rtranclp [OF steps_flush_sb, OF store_step] steps_ys] from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Write\<^sub>s\<^sub>b True a' sop v A' L' R' W']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Write True a' sop A' L' R' W'#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from j_bound''' have j_bound_ys: "j < length ?ts_ys" by auto from j_bound_ys neq_i_j have ts_ys_j: "?ts_ys!j=(last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by auto from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j, simplified is\<^sub>j'] have a_unowned: "\<forall>i < length ?ts_ys. j\<noteq>i \<longrightarrow> (let (\<O>\<^sub>i) = map owned ?ts_ys!i in a' \<notin> \<O>\<^sub>i)" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done from a'_in a_unowned [rule_format, of i] neq_i_j i_bound' A_R show False by (auto simp add: Let_def) qed } thus ?thesis by (auto simp add: Let_def) qed have A_unaquired_by_others: "\<forall>j<length (map \<O>_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j, sb\<^sub>j) = map \<O>_sb ts\<^sub>s\<^sub>b! j in A \<inter> all_acquired sb\<^sub>j = {})" proof - { fix j \<O>\<^sub>j sb\<^sub>j assume j_bound: "j < length (map owned ts\<^sub>s\<^sub>b)" assume neq_i_j: "i\<noteq>j" assume ts\<^sub>s\<^sub>b_j: "(map \<O>_sb ts\<^sub>s\<^sub>b)!j = (\<O>\<^sub>j,sb\<^sub>j)" assume conflict: "A \<inter> all_acquired sb\<^sub>j \<noteq> {}" have False proof - from j_bound leq have j_bound': "j < length (map owned ts)" by auto from j_bound have j_bound'': "j < length ts\<^sub>s\<^sub>b" by auto from j_bound' have j_bound''': "j < length ts" by simp from conflict obtain a' where a'_in: "a' \<in> A" and a'_in_j: "a' \<in> all_acquired sb\<^sub>j" by auto let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" from ts_sim [rule_format, OF j_bound''] ts\<^sub>s\<^sub>b_j j_bound'' obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<D>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>j \<R>\<^sub>j \<theta>\<^sub>s\<^sub>b\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (force simp add: Let_def) done from a'_in_j all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "a' \<in> all_acquired ?take_sb\<^sub>j \<or> a' \<in> all_acquired suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) thus False proof assume "a' \<in> all_acquired ?take_sb\<^sub>j" with A_unowned_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound a'_in show False by (auto dest: all_acquired_unshared_acquired) next assume conflict_drop: "a' \<in> all_acquired suspends\<^sub>j" from split_all_acquired_in [OF conflict_drop] (* FIXME: exract common parts *) show False proof assume "\<exists>sop a'' v ys zs A L R W. suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a'' sop v A L R W# zs \<and> a' \<in> A" then obtain a'' sop' v' ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a'_A': "a' \<in> A'" by auto from direct_memop_step.WriteVolatile [where \<theta>=\<theta>\<^sub>s\<^sub>b and m="flush ?drop_sb m"] have "(Write True a (D, f) A L R W # is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m ,\<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, share ?drop_sb \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), (flush ?drop_sb m)(a := f \<theta>\<^sub>s\<^sub>b), True, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty, share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound_ts' [simplified is\<^sub>s\<^sub>b] ts'_i [simplified is\<^sub>s\<^sub>b] this [simplified is\<^sub>s\<^sub>b]] have store_step: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d (?ts'[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),True, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)], (flush ?drop_sb m)(a := f \<theta>\<^sub>s\<^sub>b),share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_A, ?m_A, ?share_A)") by (simp add: is\<^sub>s\<^sub>b) from i_bound' have i_bound'': "i < length ?ts_A" by simp from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts_A_j: "?ts_A!j = (hd_prog p\<^sub>j (ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs), is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs)), (), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (simp add: split_suspends\<^sub>j) from j_bound''' i_bound' neq_i_j have j_bound'''': "j < length ?ts_A" by simp from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j reads_consis] have reads_consis_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m] have reads_consis_flush_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". from a_unowned_others [rule_format, OF _ neq_i_j] j_bound ts\<^sub>s\<^sub>b_j obtain a_notin_owns_j: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" and a_unshared: "a \<notin> all_shared ?take_sb\<^sub>j" by auto from a_not_acquired_others [rule_format, OF _ neq_i_j] j_bound ts\<^sub>s\<^sub>b_j have a_not_acquired_j: "a \<notin> all_acquired sb\<^sub>j" by auto from outstanding_non_volatile_refs_owned_or_read_only [OF j_bound'' ts\<^sub>s\<^sub>b_j] have nvo_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". have a_no_non_vol_read: "a \<notin> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j" proof assume a_in_nvr:"a \<in> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j" from reads_consistent_drop [OF reads_consis] have rc: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?take_sb\<^sub>j m\<^sub>s\<^sub>b) ?drop_sb\<^sub>j". from non_volatile_owned_or_read_only_drop [OF nvo_j] have nvo_j_drop: "non_volatile_owned_or_read_only True (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by simp from outstanding_refs_non_volatile_Read\<^sub>s\<^sub>b_all_acquired [OF rc this a_in_nvr] have a_owns_acq_ror: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j \<union> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by (auto dest!: acquired_all_acquired_in all_acquired_takeWhile_dropWhile_in simp add: acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) have a_unowned_j: "a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof (cases "a \<in> \<O>\<^sub>j") case False with a_not_acquired_j show ?thesis by auto next case True from all_shared_acquired_in [OF True a_unshared] a_notin_owns_j have False by auto thus ?thesis .. qed with a_owns_acq_ror have a_ror: "a \<in> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto with read_only_reads_unowned [OF j_bound'' i_bound neq_i_j [symmetric] ts\<^sub>s\<^sub>b_j ts\<^sub>s\<^sub>b_i] have a_unowned_sb: "a \<notin> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by auto from sharing_consis [OF j_bound'' ts\<^sub>s\<^sub>b_j] sharing_consistent_append [of \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have consis_j_drop: "sharing_consistent (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto from read_only_reads_read_only [OF nvo_j_drop consis_j_drop] a_ror a_unowned_j all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b [of sb\<^sub>j \<O>\<^sub>j] have "a \<in> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto) from read_only_share_all_shared [OF this] a_unshared have "a \<in> read_only \<S>\<^sub>s\<^sub>b" by fastforce from read_only_unacquired_share [OF read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] weak_sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] this] a_unowned_sb have "a \<in> read_only (share sb \<S>\<^sub>s\<^sub>b)" by auto with a_not_ro show False by simp qed with reads_consistent_mem_eq_on_non_volatile_reads [OF _ subset_refl reads_consis_flush_m] have "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) hence reads_consis_m_A_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A ys" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops ys. valid_sop sop" apply (simp only: write_sops_append ) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b ys = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from flush_store_buffer_append [ OF j_bound'''' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_A_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_m_A_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?share_A"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs) @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs)" and steps_ys: "(?ts_A, ?m_A, ?share_A) \<Rightarrow>\<^sub>d\<^sup>* (?ts_A[j:= (last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j') ], flush ys ?m_A, share ys ?share_A)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto) note conflict_computation = rtranclp_trans [OF rtranclp_r_rtranclp [OF steps_flush_sb, OF store_step] steps_ys] from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Write True a'' sop' A' L' R' W'#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from j_bound''' have j_bound_ys: "j < length ?ts_ys" by auto from j_bound_ys neq_i_j have ts_ys_j: "?ts_ys!j=(last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs)),(),\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by auto from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j, simplified is\<^sub>j'] have A'_unowned: "\<forall>i < length ?ts_ys. j\<noteq>i \<longrightarrow> (let (\<O>\<^sub>i) = map owned ?ts_ys!i in A' \<inter> \<O>\<^sub>i = {})" apply cases apply (fastforce simp add: Let_def is\<^sub>s\<^sub>b)+ done from a'_in a'_A' A'_unowned [rule_format, of i] neq_i_j i_bound' A_R show False by (auto simp add: Let_def) next assume "\<exists>A L R W ys zs. suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A L R W # zs \<and> a' \<in> A" then obtain ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a'_A': "a' \<in> A'" by auto from direct_memop_step.WriteVolatile [where \<theta>=\<theta>\<^sub>s\<^sub>b and m="flush ?drop_sb m"] have "(Write True a (D, f) A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m,\<D>\<^sub>s\<^sub>b,acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, share ?drop_sb \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), (flush ?drop_sb m)(a := f \<theta>\<^sub>s\<^sub>b), True, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R, Map.empty, share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound_ts' [simplified is\<^sub>s\<^sub>b] ts'_i [simplified is\<^sub>s\<^sub>b] this [simplified is\<^sub>s\<^sub>b]] have store_step: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d (?ts'[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), True, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)], (flush ?drop_sb m)(a := f \<theta>\<^sub>s\<^sub>b),share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_A, ?m_A, ?share_A)") by (simp add: is\<^sub>s\<^sub>b) from i_bound' have i_bound'': "i < length ?ts_A" by simp from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts_A_j: "?ts_A!j = (hd_prog p\<^sub>j (ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs), is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)), (),\<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (simp add: split_suspends\<^sub>j) from j_bound''' i_bound' neq_i_j have j_bound'''': "j < length ?ts_A" by simp from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j reads_consis] have reads_consis_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m] have reads_consis_flush_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". from a_unowned_others [rule_format, OF _ neq_i_j] j_bound ts\<^sub>s\<^sub>b_j obtain a_notin_owns_j: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" and a_unshared: "a \<notin> all_shared ?take_sb\<^sub>j" by auto from a_not_acquired_others [rule_format, OF _ neq_i_j] j_bound ts\<^sub>s\<^sub>b_j have a_not_acquired_j: "a \<notin> all_acquired sb\<^sub>j" by auto from outstanding_non_volatile_refs_owned_or_read_only [OF j_bound'' ts\<^sub>s\<^sub>b_j] have nvo_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". have a_no_non_vol_read: "a \<notin> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j" proof assume a_in_nvr:"a \<in> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j" from reads_consistent_drop [OF reads_consis] have rc: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?take_sb\<^sub>j m\<^sub>s\<^sub>b) ?drop_sb\<^sub>j". from non_volatile_owned_or_read_only_drop [OF nvo_j] have nvo_j_drop: "non_volatile_owned_or_read_only True (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by simp from outstanding_refs_non_volatile_Read\<^sub>s\<^sub>b_all_acquired [OF rc this a_in_nvr] have a_owns_acq_ror: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j \<union> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by (auto dest!: acquired_all_acquired_in all_acquired_takeWhile_dropWhile_in simp add: acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) have a_unowned_j: "a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof (cases "a \<in> \<O>\<^sub>j") case False with a_not_acquired_j show ?thesis by auto next case True from all_shared_acquired_in [OF True a_unshared] a_notin_owns_j have False by auto thus ?thesis .. qed with a_owns_acq_ror have a_ror: "a \<in> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto with read_only_reads_unowned [OF j_bound'' i_bound neq_i_j [symmetric] ts\<^sub>s\<^sub>b_j ts\<^sub>s\<^sub>b_i] have a_unowned_sb: "a \<notin> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by auto from sharing_consis [OF j_bound'' ts\<^sub>s\<^sub>b_j] sharing_consistent_append [of \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have consis_j_drop: "sharing_consistent (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto from read_only_reads_read_only [OF nvo_j_drop consis_j_drop] a_ror a_unowned_j all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b [of sb\<^sub>j \<O>\<^sub>j] have "a \<in> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto) from read_only_share_all_shared [OF this] a_unshared have "a \<in> read_only \<S>\<^sub>s\<^sub>b" by fastforce from read_only_unacquired_share [OF read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] weak_sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] this] a_unowned_sb have "a \<in> read_only (share sb \<S>\<^sub>s\<^sub>b)" by auto with a_not_ro show False by simp qed with reads_consistent_mem_eq_on_non_volatile_reads [OF _ subset_refl reads_consis_flush_m] have "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) hence reads_consis_m_A_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A ys" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops ys. valid_sop sop" apply (simp only: write_sops_append ) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b ys = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from flush_store_buffer_append [ OF j_bound'''' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_A_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_m_A_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?share_A"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs (Ghost\<^sub>s\<^sub>b A' L' R' W' # zs) @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)" and steps_ys: "(?ts_A, ?m_A, ?share_A) \<Rightarrow>\<^sub>d\<^sup>* (?ts_A[j:= (last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j') ], flush ys ?m_A, share ys ?share_A)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto) note conflict_computation = rtranclp_trans [OF rtranclp_r_rtranclp [OF steps_flush_sb, OF store_step] steps_ys] from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Ghost A' L' R' W'#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from j_bound''' have j_bound_ys: "j < length ?ts_ys" by auto from j_bound_ys neq_i_j have ts_ys_j: "?ts_ys!j=(last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs)),(),\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by auto from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j, simplified is\<^sub>j'] have A'_unowned: "\<forall>i < length ?ts_ys. j\<noteq>i \<longrightarrow> (let (\<O>\<^sub>i) = map owned ?ts_ys!i in A' \<inter> \<O>\<^sub>i = {})" apply cases apply (fastforce simp add: Let_def is\<^sub>s\<^sub>b)+ done from a'_in a'_A' A'_unowned [rule_format, of i] neq_i_j i_bound' A_R show False by (auto simp add: Let_def) qed qed qed } thus ?thesis by (auto simp add: Let_def) qed have A_no_read_only_reads_by_others: "\<forall>j<length (map \<O>_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j, sb\<^sub>j) = map \<O>_sb ts\<^sub>s\<^sub>b! j in A \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) = {})" proof - { fix j \<O>\<^sub>j sb\<^sub>j assume j_bound: "j < length (map \<O>_sb ts\<^sub>s\<^sub>b)" assume neq_i_j: "i\<noteq>j" assume ts\<^sub>s\<^sub>b_j: "(map \<O>_sb ts\<^sub>s\<^sub>b)!j = (\<O>\<^sub>j,sb\<^sub>j)" let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume conflict: "A \<inter> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j \<noteq> {}" have False proof - from j_bound leq have j_bound': "j < length (map owned ts)" by auto from j_bound have j_bound'': "j < length ts\<^sub>s\<^sub>b" by auto from j_bound' have j_bound''': "j < length ts" by simp from conflict obtain a' where a'_in: "a' \<in> A" and a'_in_j: "a' \<in> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto from ts_sim [rule_format, OF j_bound''] ts\<^sub>s\<^sub>b_j j_bound'' obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<D>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>j \<R>\<^sub>j \<theta>\<^sub>s\<^sub>b\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (force simp add: Let_def) done from split_in_read_only_reads [OF a'_in_j [simplified suspends\<^sub>j [symmetric]]] obtain t v ys zs where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Read\<^sub>s\<^sub>b False a' t v# zs" (is "suspends\<^sub>j = ?suspends") and a'_unacq: "a' \<notin> acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j)" by blast from direct_memop_step.WriteVolatile [where \<theta>=\<theta>\<^sub>s\<^sub>b and m="flush ?drop_sb m"] have "(Write True a (D, f) A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m, \<D>\<^sub>s\<^sub>b,acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, share ?drop_sb \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), (flush ?drop_sb m)(a := f \<theta>\<^sub>s\<^sub>b), True, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty, share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound_ts' [simplified is\<^sub>s\<^sub>b] ts'_i [simplified is\<^sub>s\<^sub>b] this [simplified is\<^sub>s\<^sub>b]] have store_step: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d (?ts'[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), True, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)], (flush ?drop_sb m)(a := f \<theta>\<^sub>s\<^sub>b),share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_A, ?m_A, ?share_A)") by (simp add: is\<^sub>s\<^sub>b) from i_bound' have i_bound'': "i < length ?ts_A" by simp from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts_A_j: "?ts_A!j = (hd_prog p\<^sub>j (ys @ Read\<^sub>s\<^sub>b False a' t v# zs), is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (ys @ Read\<^sub>s\<^sub>b False a' t v# zs)), (), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (simp add: split_suspends\<^sub>j) from j_bound''' i_bound' neq_i_j have j_bound'''': "j < length ?ts_A" by simp from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j reads_consis] have reads_consis_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m] have reads_consis_flush_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". from a_unowned_others [rule_format, OF j_bound'' neq_i_j ] j_bound ts\<^sub>s\<^sub>b_j obtain a_notin_owns_j: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" and a_unshared: "a \<notin> all_shared ?take_sb\<^sub>j" by auto from a_not_acquired_others [rule_format, OF j_bound neq_i_j] j_bound ts\<^sub>s\<^sub>b_j have a_not_acquired_j: "a \<notin> all_acquired sb\<^sub>j" by auto from outstanding_non_volatile_refs_owned_or_read_only [OF j_bound'' ts\<^sub>s\<^sub>b_j] have nvo_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". have a_no_non_vol_read: "a \<notin> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j" proof assume a_in_nvr:"a \<in> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j" from reads_consistent_drop [OF reads_consis] have rc: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?take_sb\<^sub>j m\<^sub>s\<^sub>b) ?drop_sb\<^sub>j". from non_volatile_owned_or_read_only_drop [OF nvo_j] have nvo_j_drop: "non_volatile_owned_or_read_only True (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by simp from outstanding_refs_non_volatile_Read\<^sub>s\<^sub>b_all_acquired [OF rc this a_in_nvr] have a_owns_acq_ror: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j \<union> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by (auto dest!: acquired_all_acquired_in all_acquired_takeWhile_dropWhile_in simp add: acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) have a_unowned_j: "a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof (cases "a \<in> \<O>\<^sub>j") case False with a_not_acquired_j show ?thesis by auto next case True from all_shared_acquired_in [OF True a_unshared] a_notin_owns_j have False by auto thus ?thesis .. qed with a_owns_acq_ror have a_ror: "a \<in> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto with read_only_reads_unowned [OF j_bound'' i_bound neq_i_j [symmetric] ts\<^sub>s\<^sub>b_j ts\<^sub>s\<^sub>b_i] have a_unowned_sb: "a \<notin> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by auto from sharing_consis [OF j_bound'' ts\<^sub>s\<^sub>b_j] sharing_consistent_append [of \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have consis_j_drop: "sharing_consistent (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto from read_only_reads_read_only [OF nvo_j_drop consis_j_drop] a_ror a_unowned_j all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b [of sb\<^sub>j \<O>\<^sub>j] have "a \<in> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto) from read_only_share_all_shared [OF this] a_unshared have "a \<in> read_only \<S>\<^sub>s\<^sub>b" by fastforce from read_only_unacquired_share [OF read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] weak_sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] this] a_unowned_sb have "a \<in> read_only (share sb \<S>\<^sub>s\<^sub>b)" by auto with a_not_ro show False by simp qed with reads_consistent_mem_eq_on_non_volatile_reads [OF _ subset_refl reads_consis_flush_m] have "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) hence reads_consis_m_A_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A ys" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops ys. valid_sop sop" apply (simp only: write_sops_append ) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b ys = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from flush_store_buffer_append [ OF j_bound'''' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_A_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_m_A_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?share_A"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs (Read\<^sub>s\<^sub>b False a' t v# zs) @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs (Read\<^sub>s\<^sub>b False a' t v# zs)" and steps_ys: "(?ts_A, ?m_A, ?share_A) \<Rightarrow>\<^sub>d\<^sup>* (?ts_A[j:= (last_prog (hd_prog p\<^sub>j (Read\<^sub>s\<^sub>b False a' t v# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Read\<^sub>s\<^sub>b False a' t v# zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j') ], flush ys ?m_A, share ys ?share_A)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto) note conflict_computation = rtranclp_trans [OF rtranclp_r_rtranclp [OF steps_flush_sb, OF store_step] steps_ys] from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Read\<^sub>s\<^sub>b False a' t v]) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Read False a' t#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from j_bound''' have j_bound_ys: "j < length ?ts_ys" by auto from j_bound_ys neq_i_j have ts_ys_j: "?ts_ys!j=(last_prog (hd_prog p\<^sub>j (Read\<^sub>s\<^sub>b False a' t v# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Read\<^sub>s\<^sub>b False a' t v# zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by auto from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j, simplified is\<^sub>j'] have "a' \<in> acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<or> a' \<in> read_only (share ys (share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done with a'_unacq have a'_ro: "a' \<in> read_only (share ys (share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" by auto from a'_in have a'_not_ro: "a' \<notin> read_only (share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) have "a' \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof - { assume a_notin: "a' \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" from weak_sharing_consis [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "weak_sharing_consistent \<O>\<^sub>j sb\<^sub>j". with weak_sharing_consistent_append [of \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "weak_sharing_consistent (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) with split_suspends\<^sub>j have weak_consis: "weak_sharing_consistent (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ys" by (simp add: weak_sharing_consistent_append) from all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "all_acquired ys \<subseteq> all_acquired sb\<^sub>j" apply (clarsimp) apply (clarsimp simp add: suspends\<^sub>j [symmetric] split_suspends\<^sub>j all_acquired_append) done with a_notin acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b [of sb\<^sub>j \<O>\<^sub>j] all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "a' \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<union> all_acquired ys" by auto from read_only_share_unowned [OF weak_consis this a'_ro] have "a' \<in> read_only (share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" . with a'_not_ro have False by auto } thus ?thesis by blast qed moreover from A_unaquired_by_others [rule_format, OF j_bound neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have "A \<inter> all_acquired sb\<^sub>j = {}" by (auto simp add: Let_def) moreover from A_unowned_by_others [rule_format, OF j_bound'' neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have "A \<inter> \<O>\<^sub>j = {}" by (auto simp add: Let_def dest: all_shared_acquired_in) moreover note a'_in ultimately show False by auto qed } thus ?thesis by (auto simp add: Let_def) qed have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) " by (auto simp add: non_volatile_owned_or_read_only_append) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix i\<^sub>1 j p\<^sub>1 "is\<^sub>1" \<O>\<^sub>1 \<R>\<^sub>1 \<D>\<^sub>1 xs\<^sub>1 sb\<^sub>1 p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume i\<^sub>1_bound: "i\<^sub>1 < length ts\<^sub>s\<^sub>b'" assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume i\<^sub>1_j: "i\<^sub>1 \<noteq> j" assume ts_i\<^sub>1: "ts\<^sub>s\<^sub>b'!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" proof (cases "i\<^sub>1=i") case True with i\<^sub>1_j have i_j: "i\<noteq>j" by simp from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') hence j_bound'': "j < length (map owned ts\<^sub>s\<^sub>b)" by simp from ts_j i_j have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from a_unowned_others [rule_format, OF _ i_j] i_j ts_j j_bound obtain a_notin_j: "a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j" and a_unshared: "a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" by (auto simp add: Let_def ts\<^sub>s\<^sub>b') from a_not_acquired_others [rule_format, OF _ i_j] i_j ts_j j_bound have a_notin_acq: "a \<notin> all_acquired sb\<^sub>j" by (auto simp add: Let_def ts\<^sub>s\<^sub>b') from outstanding_volatile_writes_unowned_by_others [OF i_bound j_bound' i_j ts\<^sub>s\<^sub>b_i ts_j'] have "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}". with ts_i\<^sub>1 a_notin_j a_unshared a_notin_acq True i_bound show ?thesis by (auto simp add: ts\<^sub>s\<^sub>b' sb' outstanding_refs_append acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b dest: all_shared_acquired_in) next case False note i\<^sub>1_i = this from i\<^sub>1_bound have i\<^sub>1_bound': "i\<^sub>1 < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_i\<^sub>1 False have ts_i\<^sub>1': "ts\<^sub>s\<^sub>b!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" by (simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "j=i") case True from i\<^sub>1_bound' have i\<^sub>1_bound'': "i\<^sub>1 < length (map owned ts\<^sub>s\<^sub>b)" by simp from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' i_bound i\<^sub>1_i ts_i\<^sub>1' ts\<^sub>s\<^sub>b_i] have "(\<O>\<^sub>s\<^sub>b \<union> all_acquired sb) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}". moreover from A_unused_by_others [rule_format, OF _ False [symmetric]] False ts_i\<^sub>1 i\<^sub>1_bound have "A \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" by (auto simp add: Let_def ts\<^sub>s\<^sub>b') ultimately show ?thesis using ts_j True ts\<^sub>s\<^sub>b' by (auto simp add: i_bound ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' all_acquired_append) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j False have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' j_bound' i\<^sub>1_j ts_i\<^sub>1' ts_j'] show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" . qed qed qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof - have "\<forall>j<length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (p\<^sub>j, is\<^sub>j, \<theta>\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j,\<R>\<^sub>j) = ts\<^sub>s\<^sub>b ! j in (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb') \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {})" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume neq_i_j: "i \<noteq> j" assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j, is\<^sub>j, \<theta>\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j,\<R>\<^sub>j)" have "(\<O>\<^sub>s\<^sub>b \<union> all_acquired sb') \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {}" proof - { fix a' assume a'_in_i: "a' \<in> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb')" assume a'_in_j: "a' \<in> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j)" have False proof - from a'_in_i have "a' \<in> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb) \<or> a' \<in> A" by (simp add: sb' all_acquired_append) then show False proof assume "a' \<in> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb)" with ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] a'_in_j show ?thesis by auto next assume "a' \<in> A" moreover have j_bound': "j < length (map owned ts\<^sub>s\<^sub>b)" using j_bound by auto from A_unowned_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound obtain "A \<inter> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j = {}" and "A \<inter> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) = {}" by (auto simp add: Let_def) moreover from A_unaquired_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have "A \<inter> all_acquired sb\<^sub>j = {}" by auto ultimately show ?thesis using a'_in_j by (auto dest: all_shared_acquired_in) qed qed } then show ?thesis by auto qed } then show ?thesis by (fastforce simp add: Let_def) qed from ownership_distinct_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb') qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof fix n m fix p\<^sub>n "is\<^sub>n" \<O>\<^sub>n \<R>\<^sub>n \<D>\<^sub>n \<theta>\<^sub>n sb\<^sub>n p\<^sub>m "is\<^sub>m" \<O>\<^sub>m \<R>\<^sub>m \<D>\<^sub>m \<theta>\<^sub>m sb\<^sub>m assume n_bound: "n < length ts\<^sub>s\<^sub>b'" and m_bound: "m < length ts\<^sub>s\<^sub>b'" and neq_n_m: "n\<noteq>m" and nth: "ts\<^sub>s\<^sub>b'!n = (p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" and mth: "ts\<^sub>s\<^sub>b'!m =(p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" from n_bound have n_bound': "n < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from m_bound have m_bound': "m < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') show "(\<O>\<^sub>m \<union> all_acquired sb\<^sub>m) \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<O>\<^sub>n) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) = {}" proof (cases "m=i") case True with neq_n_m have neq_n_i: "n\<noteq>i" by auto with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') note read_only_reads_unowned [OF n_bound' i_bound neq_n_i nth' ts\<^sub>s\<^sub>b_i] moreover from A_no_read_only_reads_by_others [rule_format, OF _ neq_n_i [symmetric]] n_bound' nth' have "A \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<O>\<^sub>n) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) = {}" by auto ultimately show ?thesis using True ts\<^sub>s\<^sub>b_i nth' mth n_bound' m_bound' by (auto simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' all_acquired_append) next case False note neq_m_i = this with m_bound mth i_bound have mth': "ts\<^sub>s\<^sub>b!m = (p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" by (auto simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "n=i") case True note read_only_reads_unowned [OF i_bound m_bound' neq_m_i [symmetric] ts\<^sub>s\<^sub>b_i mth'] then show ?thesis using True neq_m_i ts\<^sub>s\<^sub>b_i nth mth n_bound' m_bound' apply (case_tac "outstanding_refs (is_volatile_Write\<^sub>s\<^sub>b) sb = {}") apply (clarsimp simp add: outstanding_vol_write_take_drop_appends acquired_append read_only_reads_append ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b')+ done next case False with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_reads_unowned [OF n_bound' m_bound' neq_n_m nth' mth'] False neq_m_i show ?thesis by (clarsimp) qed qed qed qed have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" proof - from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b sb) sb". with valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] D_subset valid_implies_valid_prog_hd [OF i_bound ts\<^sub>s\<^sub>b_i valid] have "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b (sb@[Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])) (sb@ [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" apply - apply (rule history_consistent_appendI) apply (auto simp add: hd_prog_append_Write\<^sub>s\<^sub>b) done from valid_history_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<theta>\<^sub>s\<^sub>b') qed have valid_reads': "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b'" proof - from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b sb" . from reads_consistent_snoc_Write\<^sub>s\<^sub>b [OF this] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])". from valid_reads_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') qed have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (auto simp add: non_volatile_writes_unshared_append) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' \<S>\<^sub>s\<^sub>b') next from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have consis': "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". from A_shared_owned have "A \<subseteq> dom (share ?drop_sb \<S>) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" by (simp add: sharing_consistent_append acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) moreover have "dom (share ?drop_sb \<S>) \<subseteq> dom \<S> \<union> dom (share sb \<S>\<^sub>s\<^sub>b)" proof fix a' assume a'_in: "a' \<in> dom (share ?drop_sb \<S>)" from share_unshared_in [OF a'_in] show "a' \<in> dom \<S> \<union> dom (share sb \<S>\<^sub>s\<^sub>b)" proof assume "a' \<in> dom (share ?drop_sb Map.empty)" from share_mono_in [OF this] share_append [of ?take_sb ?drop_sb] have "a' \<in> dom (share sb \<S>\<^sub>s\<^sub>b)" by auto thus ?thesis by simp next assume "a' \<in> dom \<S> \<and> a' \<notin> all_unshared ?drop_sb" thus ?thesis by auto qed qed ultimately have A_subset: "A \<subseteq> dom \<S> \<union> dom (share sb \<S>\<^sub>s\<^sub>b) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" by auto with A_unowned_by_others have "A \<subseteq> dom (share sb \<S>\<^sub>s\<^sub>b) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" proof - { fix x assume x_A: "x \<in> A" have "x \<in> dom (share sb \<S>\<^sub>s\<^sub>b) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" proof - { assume "x \<in> dom \<S>" from share_all_until_volatile_write_share_acquired [OF \<open>sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> i_bound ts\<^sub>s\<^sub>b_i this [simplified \<S>]] A_unowned_by_others x_A have ?thesis by (fastforce simp add: Let_def) } with A_subset show ?thesis using x_A by auto qed } thus ?thesis by blast qed with consis' L_subset A_R R_acq have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (simp add: sharing_consistent_append acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' \<S>\<^sub>s\<^sub>b') next from read_only_unowned_nth_update [OF i_bound read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] ] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from a_not_ro no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (simp add: no_write_to_read_only_memory_append) from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound this] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb') qed have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b'" by (simp add: "is\<^sub>s\<^sub>b") from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') next from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps (sb @ [Write\<^sub>s\<^sub>b True a (D, f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (auto simp add: distinct_read_tmps_append) from read_tmps_distinct_nth_update [OF i_bound this] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> read_tmps (sb @ [Write\<^sub>s\<^sub>b True a (D, f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) ={}" by (auto simp add: read_tmps_append "is\<^sub>s\<^sub>b") from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb') qed have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" proof - from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] obtain valid_Df: "valid_sop (D,f)" and valid_store_sops': "\<forall>sop\<in>store_sops is\<^sub>s\<^sub>b'. valid_sop sop" by (auto simp add: "is\<^sub>s\<^sub>b") from valid_Df valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have valid_write_sops': "\<forall>sop\<in>write_sops (sb@ [Write\<^sub>s\<^sub>b True a (D, f) (f \<theta>\<^sub>s\<^sub>b) A L R W]). valid_sop sop" by (auto simp add: write_sops_append) from valid_sops_nth_update [OF i_bound valid_write_sops' valid_store_sops'] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" proof - from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] obtain D_indep: "D \<inter> load_tmps is\<^sub>s\<^sub>b' = {}" and dd_is: "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b') is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b') from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] D_indep have "load_tmps is\<^sub>s\<^sub>b' \<inter> \<Union>(fst ` write_sops (sb@ [Write\<^sub>s\<^sub>b True a (D, f) (f \<theta>\<^sub>s\<^sub>b) A L R W])) ={}" by (auto simp add: write_sops_append "is\<^sub>s\<^sub>b") from valid_data_dependency_nth_update [OF i_bound dd_is this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> dom \<theta>\<^sub>s\<^sub>b = {}" by (auto simp add: "is\<^sub>s\<^sub>b") from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" proof - from clean_no_outstanding_volatile_Write\<^sub>s\<^sub>b [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<not> True \<longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) = {}" by (auto simp add: outstanding_refs_append ) from enough_flushs_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b') qed have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . then have causal': "causal_program_history is\<^sub>s\<^sub>b' (sb@[Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W])" by (auto simp: causal_program_history_Write "is\<^sub>s\<^sub>b") from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". hence "last_prog p\<^sub>s\<^sub>b (sb @ [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) = p\<^sub>s\<^sub>b" by (simp add: last_prog_append_Write\<^sub>s\<^sub>b) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed show ?thesis proof (cases "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}") case True from True have flush_all: "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = sb" by (auto simp add: outstanding_refs_conv) from True have suspend_nothing: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = []" by (auto simp add: outstanding_refs_conv) hence suspends_empty: "suspends = []" by (simp add: suspends) from suspends_empty is_sim have "is": "is = Write True a (D,f) A L R W# is\<^sub>s\<^sub>b'" by (simp add: "is\<^sub>s\<^sub>b") with suspends_empty ts_i have ts_i: "ts!i = (p\<^sub>s\<^sub>b, Write True a (D,f) A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(),\<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp have "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts, m, \<S>)" by auto moreover note flush_commute = flush_all_until_volatile_write_append_volatile_write_commute [OF True i_bound ts\<^sub>s\<^sub>b_i] from True have drop_app: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb@[Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]) = [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>\<^sub>s\<^sub>b) A L R W]" by (auto simp add: outstanding_refs_conv) have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute ts\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' sb') using share_all_until_volatile_write_Write_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b]] apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i apply (clarsimp simp add: Let_def nth_list_update drop_app (* drop*) ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' outstanding_refs_append takeWhile_tail flush_all split: if_split_asm ) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_sops' valid_dd' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by auto next case False then obtain r where r_in: "r \<in> set sb" and volatile_r: "is_volatile_Write\<^sub>s\<^sub>b r" by (auto simp add: outstanding_refs_conv) from takeWhile_dropWhile_real_prefix [OF r_in, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)", simplified, OF volatile_r] obtain a' v' sb'' A'' L'' R'' W'' sop' where sb_split: "sb = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ Write\<^sub>s\<^sub>b True a' sop' v' A'' L'' R'' W''# sb''" and drop: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = Write\<^sub>s\<^sub>b True a' sop' v' A'' L'' R'' W''# sb''" apply (auto) subgoal for y ys apply (case_tac y) apply auto done done from drop suspends have suspends: "suspends = Write\<^sub>s\<^sub>b True a' sop' v' A'' L'' R'' W''# sb''" by simp have "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts, m, \<S>)" by auto moreover note flush_commute = flush_all_until_volatile_write_append_unflushed [OF False i_bound ts\<^sub>s\<^sub>b_i] have "Write\<^sub>s\<^sub>b True a' sop' v' A'' L'' R'' W'' \<in> set sb" by (subst sb_split) auto note drop_app = dropWhile_append1 [OF this, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)", simplified] have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb') using share_all_until_volatile_write_Write_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b]] apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i is_sim apply (clarsimp simp add: Let_def nth_list_update is_sim drop_app read_tmps_append suspends prog_instrs_append_Write\<^sub>s\<^sub>b instrs_append_Write\<^sub>s\<^sub>b hd_prog_append_Write\<^sub>s\<^sub>b drop "is\<^sub>s\<^sub>b" ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' outstanding_refs_append takeWhile_tail release_append split: if_split_asm) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply ) qed next case SBHFence then obtain "is\<^sub>s\<^sub>b": "is\<^sub>s\<^sub>b = Fence # is\<^sub>s\<^sub>b'" and sb: "sb=[]" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=Map.empty" and \<theta>\<^sub>s\<^sub>b': "\<theta>\<^sub>s\<^sub>b' = \<theta>\<^sub>s\<^sub>b" and \<D>\<^sub>s\<^sub>b': "\<not> \<D>\<^sub>s\<^sub>b'" and sb': "sb'=sb" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b' = m\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" by auto have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b []" by simp from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next from outstanding_volatile_writes_unowned_by_others_store_buffer [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') next from read_only_reads_unowned_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i, of "[]" \<O>\<^sub>s\<^sub>b] show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') next from ownership_distinct_instructions_read_value_store_buffer_independent [OF i_bound ts\<^sub>s\<^sub>b_i] show "ownership_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" proof - from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b []) []" by simp from valid_history_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have valid_reads': "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b'" proof - have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b []" by simp from valid_reads_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b []" by (simp add: sb) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb sb' \<S>\<^sub>s\<^sub>b') next have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b []" by simp from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' sb \<S>\<^sub>s\<^sub>b') next from read_only_unowned_nth_update [OF i_bound read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] ] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound, of "[]"] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' sb) qed have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" split: instr.splits) from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b") next from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps []" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') from read_tmps_distinct_nth_update [OF i_bound this] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> read_tmps [] = {}" by (clarsimp) from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" proof - from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] obtain valid_store_sops': "\<forall>sop\<in>store_sops is\<^sub>s\<^sub>b'. valid_sop sop" by (auto simp add: "is\<^sub>s\<^sub>b" ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') from valid_sops_nth_update [OF i_bound _ valid_store_sops', where sb= "[]" ] show ?thesis by (auto simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" proof - from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] obtain dd_is: "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b') is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b') from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> \<Union>(fst ` write_sops []) = {}" by (auto simp add: write_sops_append) from valid_data_dependency_nth_update [OF i_bound dd_is this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> dom \<theta>\<^sub>s\<^sub>b = {}" by (auto simp add: "is\<^sub>s\<^sub>b") from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: "is\<^sub>s\<^sub>b" ts\<^sub>s\<^sub>b' sb' sb \<theta>\<^sub>s\<^sub>b') qed from enough_flushs_nth_update [OF i_bound, where sb="[]" ] have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" by (auto simp add: ts\<^sub>s\<^sub>b' sb' sb) have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - have causal': "causal_program_history is\<^sub>s\<^sub>b' sb'" by (simp add: "is\<^sub>s\<^sub>b" sb sb') have "last_prog p\<^sub>s\<^sub>b sb' = p\<^sub>s\<^sub>b" by (simp add: sb' sb) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed from is_sim have "is": "is = Fence # is\<^sub>s\<^sub>b'" by (simp add: suspends sb "is\<^sub>s\<^sub>b") with ts_i have ts_i: "ts!i = (p\<^sub>s\<^sub>b, Fence # is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by (simp add: suspends sb) from direct_memop_step.Fence have "(Fence # is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),m,\<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), m, False, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, Map.empty, \<S>)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i this] have "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), False, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,Map.empty)], m, \<S>)". moreover have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(), False,acquired True ?take_sb \<O>\<^sub>s\<^sub>b,Map.empty)],m,\<S>)" apply (rule sim_config.intros) apply (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' m flush_all_until_volatile_nth_update_unused [OF i_bound ts\<^sub>s\<^sub>b_i]) using share_all_until_volatile_write_Fence_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b sb]] apply (clarsimp simp add: \<S> ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' is\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' sb) using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim apply (clarsimp simp add: Let_def nth_list_update ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' ex_not \<theta>\<^sub>s\<^sub>b' split: if_split_asm ) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_sops' valid_dd' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply) next case (SBHRMWReadOnly cond t a D f ret A L R W) then obtain "is\<^sub>s\<^sub>b": "is\<^sub>s\<^sub>b = RMW a t (D,f) cond ret A L R W # is\<^sub>s\<^sub>b'" and cond: "\<not> (cond (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a)))" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=Map.empty" and \<theta>\<^sub>s\<^sub>b': "\<theta>\<^sub>s\<^sub>b' = \<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a)" and \<D>\<^sub>s\<^sub>b': "\<not> \<D>\<^sub>s\<^sub>b'" and sb: "sb=[]" and sb': "sb'=[]" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b' = m\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" by auto from safe_RMW_common [OF safe_memop_flush_sb [simplified is\<^sub>s\<^sub>b]] obtain access_cond: "a \<in> \<O>\<^sub>s\<^sub>b \<or> a \<in> dom \<S>" and rels_cond: " \<forall>j < length ts. i\<noteq>j \<longrightarrow> released (ts!j) a \<noteq> Some False" by (auto simp add: \<S> sb) have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b []" by simp from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next from outstanding_volatile_writes_unowned_by_others_store_buffer [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from read_only_reads_unowned_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i, of "[]" \<O>\<^sub>s\<^sub>b] show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') next from ownership_distinct_instructions_read_value_store_buffer_independent [OF i_bound ts\<^sub>s\<^sub>b_i] show "ownership_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" proof - from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "history_consistent (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a)) (hd_prog p\<^sub>s\<^sub>b []) []" by simp from valid_history_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have valid_reads': "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b'" proof - have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b []" by simp from valid_reads_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b []" by (simp add: sb) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb sb' \<S>\<^sub>s\<^sub>b') next have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b []" by simp from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' sb \<S>\<^sub>s\<^sub>b') next from read_only_unowned_nth_update [OF i_bound read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] ] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound, of "[]"] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' sb) qed have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" split: instr.splits) from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b") next from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps []" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') from read_tmps_distinct_nth_update [OF i_bound this] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> read_tmps [] = {}" by (clarsimp) from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" proof - from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] obtain valid_store_sops': "\<forall>sop\<in>store_sops is\<^sub>s\<^sub>b'. valid_sop sop" by (auto simp add: "is\<^sub>s\<^sub>b" ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') from valid_sops_nth_update [OF i_bound _ valid_store_sops', where sb= "[]" ] show ?thesis by (auto simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" proof - from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] obtain dd_is: "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b') is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b') from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> \<Union>(fst ` write_sops []) = {}" by (auto simp add: write_sops_append) from valid_data_dependency_nth_update [OF i_bound dd_is this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps (RMW a t (D,f) cond ret A L R W# is\<^sub>s\<^sub>b') \<inter> dom \<theta>\<^sub>s\<^sub>b = {}" by (simp add: "is\<^sub>s\<^sub>b") moreover from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "t \<notin> load_tmps is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b") ultimately have "load_tmps is\<^sub>s\<^sub>b' \<inter> dom (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m\<^sub>s\<^sub>b a)) = {}" by auto from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<theta>\<^sub>s\<^sub>b') qed from enough_flushs_nth_update [OF i_bound, where sb="[]" ] have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" by (auto simp add: ts\<^sub>s\<^sub>b' sb' sb) have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - have causal': "causal_program_history is\<^sub>s\<^sub>b' sb'" by (simp add: "is\<^sub>s\<^sub>b" sb sb') have "last_prog p\<^sub>s\<^sub>b sb' = p\<^sub>s\<^sub>b" by (simp add: sb' sb) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed from is_sim have "is": "is = RMW a t (D,f) cond ret A L R W# is\<^sub>s\<^sub>b'" by (simp add: suspends sb "is\<^sub>s\<^sub>b") with ts_i have ts_i: "ts!i = (p\<^sub>s\<^sub>b, RMW a t (D,f) cond ret A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by (simp add: suspends sb) have "flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b a = m\<^sub>s\<^sub>b a" proof - have "\<forall>j < length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,_,_) = ts\<^sub>s\<^sub>b!j in a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" proof - { fix j p\<^sub>j "is\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j, xs\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j,\<R>\<^sub>j)" have "a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" proof let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume a_in: "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b ?take_sb\<^sub>j" with outstanding_refs_takeWhile [where P'= "Not \<circ> is_volatile_Write\<^sub>s\<^sub>b"] have a_in': "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" by auto with non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound jth]] have j_owns: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto from rels_cond [rule_format, OF j_bound [simplified leq] neq_i_j] ts_sim [rule_format, OF j_bound] jth have no_unsharing:"release ?take_sb\<^sub>j (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>j a \<noteq> Some False" by (auto simp add: Let_def) from access_cond show False proof assume "a \<in> \<O>\<^sub>s\<^sub>b" with ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] j_owns show False by auto next assume a_shared: "a \<in> dom \<S>" with share_all_until_volatile_write_thread_local [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b j_bound jth j_owns] have a_dom: "a \<in> dom (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: \<S> domIff) from outstanding_non_volatile_writes_unshared [OF j_bound jth] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb\<^sub>j". with non_volatile_writes_unshared_append [of \<S>\<^sub>s\<^sub>b "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] have unshared_take: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" by clarsimp from release_not_unshared_no_write_take [OF unshared_take no_unsharing a_dom] a_in show False by auto qed qed } thus ?thesis by (fastforce simp add: Let_def) qed from flush_all_until_volatile_write_buffered_val_conv [OF _ i_bound ts\<^sub>s\<^sub>b_i this] show ?thesis by (simp add: sb) qed hence m_a: "m a = m\<^sub>s\<^sub>b a" by (simp add: m) from cond have cond': "\<not> cond (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a))" by (simp add: m_a) from direct_memop_step.RMWReadOnly [where cond=cond and \<theta>=\<theta>\<^sub>s\<^sub>b and m=m, OF cond'] have "(RMW a t (D, f) cond ret A L R W # is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),m, \<D>, \<O>\<^sub>s\<^sub>b, \<R>\<^sub>s\<^sub>b, \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> m a), (), m, False, \<O>\<^sub>s\<^sub>b, Map.empty, \<S>)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i [simplified sb, simplified] this] have "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> m a), (), False, \<O>\<^sub>s\<^sub>b,Map.empty)], m, \<S>)". moreover have tmps_commute: "\<theta>\<^sub>s\<^sub>b(t \<mapsto> (m\<^sub>s\<^sub>b a)) = (\<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - {t}))(t \<mapsto> (m\<^sub>s\<^sub>b a))" apply (rule ext) apply (auto simp add: restrict_map_def domIff) done have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> m a),(), False,\<O>\<^sub>s\<^sub>b,Map.empty)],m,\<S>)" apply (rule sim_config.intros) apply (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' m flush_all_until_volatile_nth_update_unused [OF i_bound ts\<^sub>s\<^sub>b_i, simplified sb]) using share_all_until_volatile_write_RMW_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b sb]] apply (clarsimp simp add: \<S> ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' is\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' sb) using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim apply (clarsimp simp add: Let_def nth_list_update ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' ex_not m_a split: if_split_asm) apply (rule tmps_commute) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_sops' valid_dd' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply) next case (SBHRMWWrite cond t a D f ret A L R W) then obtain "is\<^sub>s\<^sub>b": "is\<^sub>s\<^sub>b = RMW a t (D,f) cond ret A L R W # is\<^sub>s\<^sub>b'" and cond: "(cond (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a)))" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b \<union> A - R" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=Map.empty" and \<D>\<^sub>s\<^sub>b': "\<not> \<D>\<^sub>s\<^sub>b'" and \<theta>\<^sub>s\<^sub>b': "\<theta>\<^sub>s\<^sub>b' = \<theta>\<^sub>s\<^sub>b(t\<mapsto>ret (m\<^sub>s\<^sub>b a) (f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a))))" and sb: "sb=[]" and sb': "sb'=[]" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b' = m\<^sub>s\<^sub>b(a := f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a)))" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L" by auto from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] have D_subset: "D \<subseteq> dom \<theta>\<^sub>s\<^sub>b" by (simp add: is\<^sub>s\<^sub>b) from is_sim have "is": "is = RMW a t (D,f) cond ret A L R W # is\<^sub>s\<^sub>b'" by (simp add: suspends sb "is\<^sub>s\<^sub>b") with ts_i have ts_i: "ts!i = (p\<^sub>s\<^sub>b, RMW a t (D,f) cond ret A L R W # is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(), \<D>, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)" by (simp add: suspends sb) from safe_RMW_common [OF safe_memop_flush_sb [simplified is\<^sub>s\<^sub>b]] obtain access_cond: "a \<in> \<O>\<^sub>s\<^sub>b \<or> a \<in> dom \<S>" and rels_cond: " \<forall>j < length ts. i\<noteq>j \<longrightarrow> released (ts!j) a \<noteq> Some False" by (auto simp add: \<S> sb) have a_unflushed: "\<forall>j < length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,_,_) = ts\<^sub>s\<^sub>b!j in a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" proof - { fix j p\<^sub>j "is\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j, xs\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j, \<R>\<^sub>j)" have "a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" proof let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume a_in: "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b ?take_sb\<^sub>j" with outstanding_refs_takeWhile [where P'= "Not \<circ> is_volatile_Write\<^sub>s\<^sub>b"] have a_in': "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" by auto with non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound jth]] have j_owns: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto with ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] have a_not_owns: "a \<notin> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by blast assume a_in: "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" with outstanding_refs_takeWhile [where P'= "Not \<circ> is_volatile_Write\<^sub>s\<^sub>b"] have a_in': "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" by auto from rels_cond [rule_format, OF j_bound [simplified leq] neq_i_j] ts_sim [rule_format, OF j_bound] jth have no_unsharing:"release ?take_sb\<^sub>j (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>j a \<noteq> Some False" by (auto simp add: Let_def) from access_cond show False proof assume "a \<in> \<O>\<^sub>s\<^sub>b" with ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] j_owns show False by auto next assume a_shared: "a \<in> dom \<S>" with share_all_until_volatile_write_thread_local [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b j_bound jth j_owns] have a_dom: "a \<in> dom (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by (auto simp add: \<S> domIff) from outstanding_non_volatile_writes_unshared [OF j_bound jth] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb\<^sub>j". with non_volatile_writes_unshared_append [of \<S>\<^sub>s\<^sub>b "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] have unshared_take: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" by clarsimp from release_not_unshared_no_write_take [OF unshared_take no_unsharing a_dom] a_in show False by auto qed qed } thus ?thesis by (fastforce simp add: Let_def) qed have "flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b a = m\<^sub>s\<^sub>b a" proof - from flush_all_until_volatile_write_buffered_val_conv [OF _ i_bound ts\<^sub>s\<^sub>b_i a_unflushed] show ?thesis by (simp add: sb) qed hence m_a: "m a = m\<^sub>s\<^sub>b a" by (simp add: m) from cond have cond': "cond (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a))" by (simp add: m_a) from safe_memop_flush_sb [simplified is\<^sub>s\<^sub>b] cond' obtain L_subset: "L \<subseteq> A" and A_shared_owned: "A \<subseteq> dom \<S> \<union> \<O>\<^sub>s\<^sub>b" and R_owned: "R \<subseteq> \<O>\<^sub>s\<^sub>b" and A_R: "A \<inter> R = {}" and a_unowned_others_ts: "\<forall>j<length ts. i \<noteq> j \<longrightarrow> (a \<notin> owned (ts!j) \<union> dom (released (ts!j)))" and A_unowned_by_others_ts: "\<forall>j<length ts. i \<noteq> j \<longrightarrow> (A \<inter> (owned (ts!j) \<union> dom (released (ts!j))) = {})" and a_not_ro: "a \<notin> read_only \<S>" by cases (auto simp add: sb) from a_unowned_others_ts ts_sim leq have a_unowned_others: "\<forall>j<length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,\<O>\<^sub>j,_) = ts\<^sub>s\<^sub>b!j in a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<and> a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" apply (clarsimp simp add: Let_def) subgoal for j apply (drule_tac x=j in spec) apply (auto simp add: dom_release_takeWhile) done done from A_unowned_by_others_ts ts_sim leq have A_unowned_by_others: "\<forall>j<length ts\<^sub>s\<^sub>b. i\<noteq>j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,\<O>\<^sub>j,_) = ts\<^sub>s\<^sub>b!j in A \<inter> (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<union> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)) = {})" apply (clarsimp simp add: Let_def) subgoal for j apply (drule_tac x=j in spec) apply (force simp add: dom_release_takeWhile) done done have a_not_ro': "a \<notin> read_only \<S>\<^sub>s\<^sub>b" proof assume a: "a \<in> read_only (\<S>\<^sub>s\<^sub>b)" from local.read_only_unowned_axioms have "read_only_unowned \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b". from in_read_only_share_all_until_volatile_write' [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b \<open>read_only_unowned \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> i_bound ts\<^sub>s\<^sub>b_i a_unowned_others, simplified sb, simplified, OF a] have "a \<in> read_only (\<S>)" by (simp add: \<S>) with a_not_ro show False by simp qed { fix j fix p\<^sub>j is\<^sub>s\<^sub>b\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b!j=(p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume neq_i_j: "i\<noteq>j" have "a \<notin> unforwarded_non_volatile_reads (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) {}" proof let ?take_sb\<^sub>j = "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" let ?drop_sb\<^sub>j = "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" assume a_in: "a \<in> unforwarded_non_volatile_reads ?drop_sb\<^sub>j {}" from a_unowned_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound obtain a_unacq_take: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" and a_not_shared: "a \<notin> all_shared ?take_sb\<^sub>j" by auto (* then obtain a_unowned: "a \<notin> \<O>\<^sub>j" and a_unacq_take': "a \<notin> all_acquired ?take_sb\<^sub>j" by (auto simp add: acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) *) note nvo_j = outstanding_non_volatile_refs_owned_or_read_only [OF j_bound ts\<^sub>s\<^sub>b_j] from non_volatile_owned_or_read_only_drop [OF nvo_j] have nvo_drop_j: "non_volatile_owned_or_read_only True (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" . note consis_j = sharing_consis [OF j_bound ts\<^sub>s\<^sub>b_j] with sharing_consistent_append [of \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] obtain consis_take_j: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j" and consis_drop_j: "sharing_consistent (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto from in_unforwarded_non_volatile_reads_non_volatile_Read\<^sub>s\<^sub>b [OF a_in] have a_in': "a \<in> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j". note reads_consis_j = valid_reads [OF j_bound ts\<^sub>s\<^sub>b_j] from reads_consistent_drop [OF this] have reads_consis_drop_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?take_sb\<^sub>j m\<^sub>s\<^sub>b) ?drop_sb\<^sub>j". from read_only_share_all_shared [of a ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b] a_not_ro' a_not_shared have a_not_ro_j: "a \<notin> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by auto from ts_sim [rule_format, OF j_bound] ts\<^sub>s\<^sub>b_j j_bound obtain suspends\<^sub>j "is\<^sub>j" \<D>\<^sub>j where suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>j |` (dom \<theta>\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (auto simp: Let_def) from ts\<^sub>j neq_i_j j_bound have ts'_j: "?ts'!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>j |` (dom \<theta>\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_last_prog [OF j_bound ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". from j_bound i_bound' leq have j_bound_ts': "j < length ?ts'" by simp from read_only_read_acquired_unforwarded_acquire_witness [OF nvo_drop_j consis_drop_j a_not_ro_j a_unacq_take a_in] have False proof assume "\<exists>sop a' v ys zs A L R W. ?drop_sb\<^sub>j= ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W # zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a'\<noteq>a" with suspends\<^sub>j obtain a' sop' v' ys zs' A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs'" (is "suspends\<^sub>j=?suspends") and a_A': "a \<in> A'" and no_write: "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b (ys @ [Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'])" by(auto simp add: outstanding_refs_append ) from last_prog have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from sharing_consis [OF j_bound ts\<^sub>s\<^sub>b_j] have sharing_consis_j: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". then have A'_R': "A' \<inter> R' = {}" by (simp add: sharing_consistent_append [of _ _ ?take_sb\<^sub>j ?drop_sb\<^sub>j, simplified] suspends\<^sub>j [symmetric] split_suspends\<^sub>j sharing_consistent_append) from valid_program_history [OF j_bound ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from valid_reads [OF j_bound ts\<^sub>s\<^sub>b_j] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m_j] have reads_consis_flush_suspend: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']" and sb'="zs'", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts'_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="share ?drop_sb \<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs' @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs'" and steps_ys: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d\<^sup>* (?ts'[j:=(last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs')) (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']), is\<^sub>j', \<theta>\<^sub>j |` (dom \<theta>\<^sub>j - read_tmps zs'), (), True, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (flush ?drop_sb m), share (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (share ?drop_sb \<S>))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append outstanding_refs_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b,(), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = rtranclp_trans [OF steps_flush_sb steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have safe: "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from flush_unchanged_addresses [OF no_write] have "flush (ys @ [Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) m a = m a". with safe_delayedE [OF safe i_bound_ys ts_ys_i, simplified is\<^sub>s\<^sub>b] cond' have a_unowned: "\<forall>j < length ?ts_ys. i\<noteq>j \<longrightarrow> (let (\<O>\<^sub>j) = map owned ?ts_ys!j in a \<notin> \<O>\<^sub>j)" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b sb) done from a_A' a_unowned [rule_format, of j] neq_i_j j_bound leq A'_R' show False by (auto simp add: Let_def) next assume "\<exists>A L R W ys zs. ?drop_sb\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys" with suspends\<^sub>j obtain ys zs' A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs'" (is "suspends\<^sub>j=?suspends") and a_A': "a \<in> A'" and no_write: "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W'])" by (auto simp add: outstanding_refs_append) from last_prog have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from sharing_consis [OF j_bound ts\<^sub>s\<^sub>b_j] have sharing_consis_j: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". then have A'_R': "A' \<inter> R' = {}" by (simp add: sharing_consistent_append [of _ _ ?take_sb\<^sub>j ?drop_sb\<^sub>j, simplified] suspends\<^sub>j [symmetric] split_suspends\<^sub>j sharing_consistent_append) from valid_program_history [OF j_bound ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from valid_reads [OF j_bound ts\<^sub>s\<^sub>b_j] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m_j] have reads_consis_flush_suspend: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) suspends\<^sub>j". hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?drop_sb m) (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']" and sb'="zs'", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts'_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="share ?drop_sb \<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs' @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs'" and steps_ys: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d\<^sup>* (?ts'[j:=(last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs')) (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']), is\<^sub>j', \<theta>\<^sub>j |` (dom \<theta>\<^sub>j - read_tmps zs'), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (flush ?drop_sb m), share (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) (share ?drop_sb \<S>))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append outstanding_refs_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b,(), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = rtranclp_trans [OF steps_flush_sb steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have safe: "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from flush_unchanged_addresses [OF no_write] have "flush (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) m a = m a". with safe_delayedE [OF safe i_bound_ys ts_ys_i, simplified is\<^sub>s\<^sub>b] cond' have a_unowned: "\<forall>j < length ?ts_ys. i\<noteq>j \<longrightarrow> (let (\<O>\<^sub>j) = map owned ?ts_ys!j in a \<notin> \<O>\<^sub>j)" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b sb) done from a_A' a_unowned [rule_format, of j] neq_i_j j_bound leq A'_R' show False by (auto simp add: Let_def) qed then show False by simp qed } note a_notin_unforwarded_non_volatile_reads_drop = this (* FIXME: split in to theorems, one for A \<inter> \<O>\<^sub>j and one for A \<inter> outstanding_refs\<dots> *) have A_unused_by_others: "\<forall>j<length (map \<O>_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j, sb\<^sub>j) = map \<O>_sb ts\<^sub>s\<^sub>b! j in A \<inter> (\<O>\<^sub>j \<union> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j) = {})" proof - { fix j \<O>\<^sub>j sb\<^sub>j assume j_bound: "j < length (map owned ts\<^sub>s\<^sub>b)" assume neq_i_j: "i\<noteq>j" assume ts\<^sub>s\<^sub>b_j: "(map \<O>_sb ts\<^sub>s\<^sub>b)!j = (\<O>\<^sub>j,sb\<^sub>j)" assume conflict: "A \<inter> (\<O>\<^sub>j \<union> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j) \<noteq> {}" have False proof - from j_bound leq have j_bound': "j < length (map owned ts)" by auto from j_bound have j_bound'': "j < length ts\<^sub>s\<^sub>b" by auto from j_bound' have j_bound''': "j < length ts" by simp from conflict obtain a' where a_in: "a' \<in> A" and conflict: "a' \<in> \<O>\<^sub>j \<or> a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" by auto from A_unowned_by_others [rule_format, OF _ neq_i_j] j_bound ts\<^sub>s\<^sub>b_j have A_unshared_j: "A \<inter> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) = {}" by (auto simp add: Let_def) from conflict show ?thesis proof assume "a' \<in> \<O>\<^sub>j" from all_shared_acquired_in [OF this] A_unshared_j a_in have conflict: "a' \<in> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j" by (auto) with A_unowned_by_others [rule_format, OF _ neq_i_j] j_bound ts\<^sub>s\<^sub>b_j a_in show False by auto next assume a_in_j: "a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" from ts_sim [rule_format, OF j_bound''] ts\<^sub>s\<^sub>b_j j_bound'' obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<D>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>j \<R>\<^sub>j \<theta>\<^sub>s\<^sub>b\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (force simp add: Let_def) done have "a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b suspends\<^sub>j" proof - from a_in_j have "a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (?take_sb\<^sub>j @ ?drop_sb\<^sub>j)" by simp thus ?thesis apply (simp only: outstanding_refs_append suspends\<^sub>j) apply (auto simp add: outstanding_refs_conv dest: set_takeWhileD) done qed from split_volatile_Write\<^sub>s\<^sub>b_in_outstanding_refs [OF this] obtain sop' v' ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") by blast from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_volatile_refs_owned_or_read_only [OF j_bound'' ts\<^sub>s\<^sub>b_j] have nvo_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". with non_volatile_owned_or_read_only_append [of False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have nvo_take_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j" by auto from a_unowned_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have a_not_acq: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" by auto from a_notin_unforwarded_non_volatile_reads_drop[OF j_bound'' ts\<^sub>s\<^sub>b_j neq_i_j] have a_notin_unforwarded_reads: "a \<notin> unforwarded_non_volatile_reads suspends\<^sub>j {}" by (simp add: suspends\<^sub>j) let ?ma="(m(a := f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m a))))" from reads_consistent_mem_eq_on_unforwarded_non_volatile_reads [where W="{}" and m'="?ma",simplified, OF _ subset_refl reads_consis_m_j] a_notin_unforwarded_reads have reads_consis_ma_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?ma suspends\<^sub>j" by auto from reads_consis_ma_j have reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?ma (ys)" by (simp add: split_suspends\<^sub>j reads_consistent_append) from direct_memop_step.RMWWrite [where cond=cond and \<theta>=\<theta>\<^sub>s\<^sub>b and m=m, OF cond' ] have "(RMW a t (D, f) cond ret A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), m,\<D>, \<O>\<^sub>s\<^sub>b, \<R>\<^sub>s\<^sub>b, \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))), (), ?ma, False, \<O>\<^sub>s\<^sub>b \<union> A - R, Map.empty,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i this] have step_a: "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))), (), False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)], ?ma,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_a, _, ?shared_a)"). from ts\<^sub>j neq_i_j j_bound have ts_a_j: "?ts_a!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom (\<S>\<^sub>s\<^sub>b)) \<R>\<^sub>j)" by auto from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from j_bound' have j_bound_ts_a: "j < length ?ts_a" by auto from flush_store_buffer_append [where sb="ys" and sb'="Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'#zs", simplified, OF j_bound_ts_a is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_a_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?shared_a"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "Write True a' sop' A' L' R' W'# instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts_a, ?ma, ?shared_a) \<Rightarrow>\<^sub>d\<^sup>* (?ts_a[j:=(last_prog (hd_prog p\<^sub>j zs) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')], flush ys (?ma), share ys (?shared_a))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append) from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Write True a' sop' A' L' R' W'#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))),(), False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)" by simp from j_bound_ts_a have j_bound_ys: "j < length ?ts_ys" by auto then have ts_ys_j: "?ts_ys!j = (last_prog (hd_prog p\<^sub>j zs) ys, Write True a' sop' A' L' R' W'#is\<^sub>j'', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by (clarsimp simp add: is\<^sub>j') note conflict_computation = r_rtranclp_rtranclp [OF step_a steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j] have a_unowned: "\<forall>i < length ts. j\<noteq>i \<longrightarrow> (let (\<O>\<^sub>i) = map owned ?ts_ys!i in a' \<notin> \<O>\<^sub>i)" apply cases apply (auto simp add: Let_def) done from a_in a_unowned [rule_format, of i] neq_i_j i_bound' A_R show False by (auto simp add: Let_def) qed qed } thus ?thesis by (auto simp add: Let_def) qed have A_unacquired_by_others: "\<forall>j<length (map \<O>_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j, sb\<^sub>j) = map \<O>_sb ts\<^sub>s\<^sub>b! j in A \<inter> all_acquired sb\<^sub>j = {})" proof - { fix j \<O>\<^sub>j sb\<^sub>j assume j_bound: "j < length (map owned ts\<^sub>s\<^sub>b)" assume neq_i_j: "i\<noteq>j" assume ts\<^sub>s\<^sub>b_j: "(map \<O>_sb ts\<^sub>s\<^sub>b)!j = (\<O>\<^sub>j,sb\<^sub>j)" assume conflict: "A \<inter> all_acquired sb\<^sub>j \<noteq> {}" have False proof - from j_bound leq have j_bound': "j < length (map owned ts)" by auto from j_bound have j_bound'': "j < length ts\<^sub>s\<^sub>b" by auto from j_bound' have j_bound''': "j < length ts" by simp from conflict obtain a' where a'_in: "a' \<in> A" and a'_in_j: "a' \<in> all_acquired sb\<^sub>j" by auto let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" from ts_sim [rule_format, OF j_bound''] ts\<^sub>s\<^sub>b_j j_bound'' obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<theta>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<R>\<^sub>j \<D>\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j,\<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (force simp add: Let_def) done from a'_in_j all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "a' \<in> all_acquired ?take_sb\<^sub>j \<or> a' \<in> all_acquired suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) thus False proof assume "a' \<in> all_acquired ?take_sb\<^sub>j" with A_unowned_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound a'_in show False by (auto dest: all_acquired_unshared_acquired) next assume conflict_drop: "a' \<in> all_acquired suspends\<^sub>j" from split_all_acquired_in [OF conflict_drop] show ?thesis proof assume "\<exists>sop a'' v ys zs A L R W. suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a'' sop v A L R W# zs \<and> a' \<in> A" then obtain a'' sop' v' ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a'_A': "a' \<in> A'" by blast from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_volatile_refs_owned_or_read_only [OF j_bound'' ts\<^sub>s\<^sub>b_j] have nvo_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". with non_volatile_owned_or_read_only_append [of False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have nvo_take_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j" by auto from a_unowned_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have a_not_acq: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" by auto from a_notin_unforwarded_non_volatile_reads_drop[OF j_bound'' ts\<^sub>s\<^sub>b_j neq_i_j] have a_notin_unforwarded_reads: "a \<notin> unforwarded_non_volatile_reads suspends\<^sub>j {}" by (simp add: suspends\<^sub>j) let ?ma="(m(a := f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m a))))" from reads_consistent_mem_eq_on_unforwarded_non_volatile_reads [where W="{}" and m'="?ma",simplified, OF _ subset_refl reads_consis_m_j] a_notin_unforwarded_reads have reads_consis_ma_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?ma suspends\<^sub>j" by auto from reads_consis_ma_j have reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?ma (ys)" by (simp add: split_suspends\<^sub>j reads_consistent_append) from direct_memop_step.RMWWrite [where cond=cond and \<theta>=\<theta>\<^sub>s\<^sub>b and m=m, OF cond'] have "(RMW a t (D, f) cond ret A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), m, \<D>, \<O>\<^sub>s\<^sub>b, \<R>\<^sub>s\<^sub>b, \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))), (), ?ma, False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty, \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i [simplified sb, simplified] this] have step_a: "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))), (), False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)], ?ma,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_a, _, ?shared_a)"). from ts\<^sub>j neq_i_j j_bound have ts_a_j: "?ts_a!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from j_bound' have j_bound_ts_a: "j < length ?ts_a" by auto from flush_store_buffer_append [where sb="ys" and sb'="Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'#zs", simplified, OF j_bound_ts_a is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_a_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?shared_a"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "Write True a'' sop' A' L' R' W'# instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts_a, ?ma, ?shared_a) \<Rightarrow>\<^sub>d\<^sup>* (?ts_a[j:=(last_prog (hd_prog p\<^sub>j zs) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')], flush ys (?ma), share ys (?shared_a))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append) from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Write True a'' sop' A' L' R' W'#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))),(), False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)" by simp from j_bound_ts_a have j_bound_ys: "j < length ?ts_ys" by auto then have ts_ys_j: "?ts_ys!j = (last_prog (hd_prog p\<^sub>j zs) ys, Write True a'' sop' A' L' R' W'#is\<^sub>j'', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by (clarsimp simp add: is\<^sub>j') note conflict_computation = r_rtranclp_rtranclp [OF step_a steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j] have A'_unowned: "\<forall>i < length ?ts_ys. j\<noteq>i \<longrightarrow> (let (\<O>\<^sub>i) = map owned ?ts_ys!i in A' \<inter> \<O>\<^sub>i = {})" apply cases apply (fastforce simp add: Let_def is\<^sub>s\<^sub>b)+ done from a'_in a'_A' A'_unowned [rule_format, of i] neq_i_j i_bound' A_R show False by (auto simp add: Let_def) next assume "\<exists>A L R W ys zs. suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a' \<in> A" then obtain ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a'_A': "a' \<in> A'" by blast from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_volatile_refs_owned_or_read_only [OF j_bound'' ts\<^sub>s\<^sub>b_j] have nvo_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". with non_volatile_owned_or_read_only_append [of False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have nvo_take_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j" by auto from a_unowned_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have a_not_acq: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" by auto from a_notin_unforwarded_non_volatile_reads_drop[OF j_bound'' ts\<^sub>s\<^sub>b_j neq_i_j] have a_notin_unforwarded_reads: "a \<notin> unforwarded_non_volatile_reads suspends\<^sub>j {}" by (simp add: suspends\<^sub>j) let ?ma="(m(a := f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m a))))" from reads_consistent_mem_eq_on_unforwarded_non_volatile_reads [where W="{}" and m'="?ma",simplified, OF _ subset_refl reads_consis_m_j] a_notin_unforwarded_reads have reads_consis_ma_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?ma suspends\<^sub>j" by auto from reads_consis_ma_j have reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?ma (ys)" by (simp add: split_suspends\<^sub>j reads_consistent_append) from direct_memop_step.RMWWrite [where cond=cond and \<theta>=\<theta>\<^sub>s\<^sub>b and m=m, OF cond'] have "(RMW a t (D, f) cond ret A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), m, \<D>,\<O>\<^sub>s\<^sub>b, \<R>\<^sub>s\<^sub>b, \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))), (), ?ma, False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i [simplified sb, simplified] this] have step_a: "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))), (), False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)], ?ma,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_a, _, ?shared_a)"). from ts\<^sub>j neq_i_j j_bound have ts_a_j: "?ts_a!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from j_bound' have j_bound_ts_a: "j < length ?ts_a" by auto from flush_store_buffer_append [where sb="ys" and sb'="Ghost\<^sub>s\<^sub>b A' L' R' W'#zs", simplified, OF j_bound_ts_a is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_a_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?shared_a"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "Ghost A' L' R' W'# instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts_a, ?ma, ?shared_a) \<Rightarrow>\<^sub>d\<^sup>* (?ts_a[j:=(last_prog (hd_prog p\<^sub>j zs) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')], flush ys (?ma), share ys (?shared_a))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append) from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Ghost A' L' R' W'#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))),(), False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)" by simp from j_bound_ts_a have j_bound_ys: "j < length ?ts_ys" by auto then have ts_ys_j: "?ts_ys!j = (last_prog (hd_prog p\<^sub>j zs) ys, Ghost A' L' R' W'#is\<^sub>j'', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps zs), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by (clarsimp simp add: is\<^sub>j') note conflict_computation = r_rtranclp_rtranclp [OF step_a steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j] have A'_unowned: "\<forall>i < length ?ts_ys. j\<noteq>i \<longrightarrow> (let (\<O>\<^sub>i) = map owned ?ts_ys!i in A' \<inter> \<O>\<^sub>i = {})" apply cases apply (fastforce simp add: Let_def is\<^sub>s\<^sub>b)+ done from a'_in a'_A' A'_unowned [rule_format, of i] neq_i_j i_bound' A_R show False by (auto simp add: Let_def) qed qed qed } thus ?thesis by (auto simp add: Let_def) qed { fix j fix p\<^sub>j is\<^sub>s\<^sub>b\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b!j=(p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume neq_i_j: "i\<noteq>j" have "A \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) = {}" proof - { let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume conflict: "A \<inter> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j \<noteq> {}" have False proof - from conflict obtain a' where a'_in: "a' \<in> A" and a'_in_j: "a' \<in> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto from ts_sim [rule_format, OF j_bound] ts\<^sub>s\<^sub>b_j j_bound obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<D>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>j \<theta>\<^sub>s\<^sub>b\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (clarsimp simp add: Let_def) done from split_in_read_only_reads [OF a'_in_j [simplified suspends\<^sub>j [symmetric]]] obtain t' v' ys zs where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Read\<^sub>s\<^sub>b False a' t' v'# zs" (is "suspends\<^sub>j = ?suspends") and a'_unacq: "a' \<notin> acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j)" by blast from valid_program_history [OF j_bound ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from valid_last_prog [OF j_bound ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_volatile_refs_owned_or_read_only [OF j_bound ts\<^sub>s\<^sub>b_j] have nvo_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". with non_volatile_owned_or_read_only_append [of False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have nvo_take_j: "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j" by auto from a_unowned_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have a_not_acq: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" by auto from a_notin_unforwarded_non_volatile_reads_drop[OF j_bound ts\<^sub>s\<^sub>b_j neq_i_j] have a_notin_unforwarded_reads: "a \<notin> unforwarded_non_volatile_reads suspends\<^sub>j {}" by (simp add: suspends\<^sub>j) let ?ma="(m(a := f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m a))))" from reads_consistent_mem_eq_on_unforwarded_non_volatile_reads [where W="{}" and m'="?ma",simplified, OF _ subset_refl reads_consis_m_j] a_notin_unforwarded_reads have reads_consis_ma_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?ma suspends\<^sub>j" by auto from reads_consis_ma_j have reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?ma (ys)" by (simp add: split_suspends\<^sub>j reads_consistent_append) from direct_memop_step.RMWWrite [where cond=cond and \<theta>=\<theta>\<^sub>s\<^sub>b and m=m, OF cond' ] have "(RMW a t (D, f) cond ret A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), m, \<D>,\<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b,\<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))), (), ?ma, False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty, \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i this] have step_a: "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))), (), False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)], ?ma,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_a, _, ?shared_a)"). from ts\<^sub>j neq_i_j j_bound have ts_a_j: "?ts_a!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by auto from valid_write_sops [OF j_bound ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from j_bound leq have j_bound_ts_a: "j < length ?ts_a" by auto from flush_store_buffer_append [where sb="ys" and sb'="Read\<^sub>s\<^sub>b False a' t' v'#zs", simplified, OF j_bound_ts_a is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_a_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?shared_a"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "Read False a' t'# instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs" and steps_ys: "(?ts_a, ?ma, ?shared_a) \<Rightarrow>\<^sub>d\<^sup>* (?ts_a[j:=(last_prog (hd_prog p\<^sub>j zs) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - insert t' (read_tmps zs)), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')], flush ys (?ma), share ys (?shared_a))" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append) from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Read\<^sub>s\<^sub>b False a' t' v']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Read False a' t'#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j have ts_ys_i: "?ts_ys!i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a)))),(), False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)" by simp from j_bound_ts_a have j_bound_ys: "j < length ?ts_ys" by auto then have ts_ys_j: "?ts_ys!j = (last_prog (hd_prog p\<^sub>j zs) ys, Read False a' t'#is\<^sub>j'', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - insert t' (read_tmps zs)), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by (clarsimp simp add: is\<^sub>j') note conflict_computation = r_rtranclp_rtranclp [OF step_a steps_ys] from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j] have "a' \<in> acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<or> a' \<in> read_only (share ys (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done with a'_unacq have a'_ro: "a' \<in> read_only (share ys (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" by auto from a'_in have a'_not_ro: "a' \<notin> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) have "a' \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof - { assume a_notin: "a' \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" from weak_sharing_consis [OF j_bound ts\<^sub>s\<^sub>b_j] have "weak_sharing_consistent \<O>\<^sub>j sb\<^sub>j". with weak_sharing_consistent_append [of \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "weak_sharing_consistent (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) with split_suspends\<^sub>j have weak_consis: "weak_sharing_consistent (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ys" by (simp add: weak_sharing_consistent_append) from all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "all_acquired ys \<subseteq> all_acquired sb\<^sub>j" apply (clarsimp) apply (clarsimp simp add: suspends\<^sub>j [symmetric] split_suspends\<^sub>j all_acquired_append) done with a_notin acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b [of sb\<^sub>j \<O>\<^sub>j] all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "a' \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<union> all_acquired ys" by auto from read_only_share_unowned [OF weak_consis this a'_ro] have "a' \<in> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" . with a'_not_ro have False by auto with a_notin read_only_share_unowned [OF weak_consis _ a'_ro] all_acquired_takeWhile [of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)" sb\<^sub>j] have "a' \<in> read_only (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) with a'_not_ro have False by auto } thus ?thesis by blast qed moreover from A_unacquired_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have "A \<inter> all_acquired sb\<^sub>j = {}" by (auto simp add: Let_def) moreover from A_unowned_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have "A \<inter> \<O>\<^sub>j = {}" by (auto simp add: Let_def dest: all_shared_acquired_in) moreover note a'_in ultimately show False by auto qed } thus ?thesis by (auto simp add: Let_def) qed } note A_no_read_only_reads = this have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof fix j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j p\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume ts\<^sub>s\<^sub>b'_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b' \<O>\<^sub>j sb\<^sub>j" proof (cases "j=i") case True have "non_volatile_owned_or_read_only False (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) (\<O>\<^sub>s\<^sub>b \<union> A - R) []" by simp then show ?thesis using True i_bound ts\<^sub>s\<^sub>b'_j by (auto simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' sb sb') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') with ts\<^sub>s\<^sub>b'_j False i_bound have ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') note nvo = outstanding_non_volatile_refs_owned_or_read_only [OF j_bound' ts\<^sub>s\<^sub>b_j] from read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] R_owned have "R \<inter> read_only \<S>\<^sub>s\<^sub>b = {}" by auto with A_no_read_only_reads [OF j_bound' ts\<^sub>s\<^sub>b_j False [symmetric]] L_subset have "\<forall>a\<in>read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j). a \<in> read_only \<S>\<^sub>s\<^sub>b \<longrightarrow> a \<in> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) from non_volatile_owned_or_read_only_read_only_reads_eq' [OF nvo this] have "non_volatile_owned_or_read_only False (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<O>\<^sub>j sb\<^sub>j". thus ?thesis by (simp add: \<S>\<^sub>s\<^sub>b') qed qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix i\<^sub>1 j p\<^sub>1 "is\<^sub>1" \<O>\<^sub>1 \<R>\<^sub>1 \<D>\<^sub>1 xs\<^sub>1 sb\<^sub>1 p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume i\<^sub>1_bound: "i\<^sub>1 < length ts\<^sub>s\<^sub>b'" assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume i\<^sub>1_j: "i\<^sub>1 \<noteq> j" assume ts_i\<^sub>1: "ts\<^sub>s\<^sub>b'!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" proof (cases "i\<^sub>1=i") case True with ts_i\<^sub>1 i_bound show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb) next case False note i\<^sub>1_i = this from i\<^sub>1_bound have i\<^sub>1_bound': "i\<^sub>1 < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b' sb' sb) hence i\<^sub>1_bound'': "i\<^sub>1 < length (map owned ts\<^sub>s\<^sub>b)" by auto from ts_i\<^sub>1 False have ts_i\<^sub>1': "ts\<^sub>s\<^sub>b!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" by (simp add: ts\<^sub>s\<^sub>b' sb' sb) show ?thesis proof (cases "j=i") case True from i_bound ts_j ts\<^sub>s\<^sub>b' True have sb\<^sub>j: "sb\<^sub>j=[]" by (simp add: ts\<^sub>s\<^sub>b' sb') from A_unused_by_others [rule_format, OF _ False [symmetric]] ts_i\<^sub>1 i\<^sub>1_bound'' False i\<^sub>1_bound' have "A \<inter> (\<O>\<^sub>1 \<union> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1) = {}" by (auto simp add: Let_def ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' owned_def) moreover from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' i_bound i\<^sub>1_i ts_i\<^sub>1' ts\<^sub>s\<^sub>b_i] have "\<O>\<^sub>s\<^sub>b \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" by (simp add: sb) ultimately show ?thesis using ts_j True by (auto simp add: i_bound ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb\<^sub>j) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j False have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' j_bound' i\<^sub>1_j ts_i\<^sub>1' ts_j'] show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" . qed qed qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof fix n m fix p\<^sub>n "is\<^sub>n" \<O>\<^sub>n \<R>\<^sub>n \<D>\<^sub>n \<theta>\<^sub>n sb\<^sub>n p\<^sub>m "is\<^sub>m" \<O>\<^sub>m \<R>\<^sub>m \<D>\<^sub>m \<theta>\<^sub>m sb\<^sub>m assume n_bound: "n < length ts\<^sub>s\<^sub>b'" and m_bound: "m < length ts\<^sub>s\<^sub>b'" and neq_n_m: "n\<noteq>m" and nth: "ts\<^sub>s\<^sub>b'!n = (p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" and mth: "ts\<^sub>s\<^sub>b'!m =(p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" from n_bound have n_bound': "n < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from m_bound have m_bound': "m < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') show "(\<O>\<^sub>m \<union> all_acquired sb\<^sub>m) \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<O>\<^sub>n) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) = {}" proof (cases "m=i") case True with neq_n_m have neq_n_i: "n\<noteq>i" by auto with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') note read_only_reads_unowned [OF n_bound' i_bound neq_n_i nth' ts\<^sub>s\<^sub>b_i] moreover note A_no_read_only_reads [OF n_bound' nth'] ultimately show ?thesis using True ts\<^sub>s\<^sub>b_i neq_n_i nth mth n_bound' m_bound' by (auto simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb sb') next case False note neq_m_i = this with m_bound mth i_bound have mth': "ts\<^sub>s\<^sub>b!m = (p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" by (auto simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "n=i") case True with ts\<^sub>s\<^sub>b_i nth mth neq_m_i n_bound' show ?thesis by (auto simp add: ts\<^sub>s\<^sub>b' sb') next case False with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_reads_unowned [OF n_bound' m_bound' neq_n_m nth' mth'] False neq_m_i show ?thesis by (clarsimp) qed qed qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix i\<^sub>1 j p\<^sub>1 "is\<^sub>1" \<O>\<^sub>1 \<R>\<^sub>1 \<D>\<^sub>1 xs\<^sub>1 sb\<^sub>1 p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume i\<^sub>1_bound: "i\<^sub>1 < length ts\<^sub>s\<^sub>b'" assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume i\<^sub>1_j: "i\<^sub>1 \<noteq> j" assume ts_i\<^sub>1: "ts\<^sub>s\<^sub>b'!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "(\<O>\<^sub>1 \<union> all_acquired sb\<^sub>1) \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j)= {}" proof (cases "i\<^sub>1=i") case True with i\<^sub>1_j have i_j: "i\<noteq>j" by simp from i_bound ts_i\<^sub>1 ts\<^sub>s\<^sub>b' True have sb\<^sub>1: "sb\<^sub>1=[]" by (simp add: ts\<^sub>s\<^sub>b' sb') from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') hence j_bound'': "j < length (map owned ts\<^sub>s\<^sub>b)" by simp from ts_j i_j have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from A_unused_by_others [rule_format, OF _ i_j] ts_j i_j j_bound' have "A \<inter> (\<O>\<^sub>j \<union> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j) = {}" by (auto simp add: Let_def ts\<^sub>s\<^sub>b' owned_def) moreover from A_unacquired_by_others [rule_format, OF _ i_j] ts_j i_j j_bound' have "A \<inter> all_acquired sb\<^sub>j = {}" by (auto simp add: Let_def ts\<^sub>s\<^sub>b') (* from a_not_acquired_others [rule_format, OF j_bound'' i_j] ts_j i_j j_bound' have "a \<notin> all_acquired sb\<^sub>j" by (auto simp add: Let_def ts\<^sub>s\<^sub>b') *) moreover from ownership_distinct [OF i_bound j_bound' i_j ts\<^sub>s\<^sub>b_i ts_j'] have "\<O>\<^sub>s\<^sub>b \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j)= {}" by (simp add: sb) ultimately show ?thesis using ts_i\<^sub>1 True by (auto simp add: i_bound ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' sb\<^sub>1) next case False note i\<^sub>1_i = this from i\<^sub>1_bound have i\<^sub>1_bound': "i\<^sub>1 < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') hence i\<^sub>1_bound'': "i\<^sub>1 < length (map owned ts\<^sub>s\<^sub>b)" by simp from ts_i\<^sub>1 False have ts_i\<^sub>1': "ts\<^sub>s\<^sub>b!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" by (simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "j=i") case True from A_unused_by_others [rule_format, OF _ False [symmetric]] ts_i\<^sub>1 False i\<^sub>1_bound' have "A \<inter> (\<O>\<^sub>1 \<union> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1) = {}" by (auto simp add: Let_def ts\<^sub>s\<^sub>b' owned_def) moreover from A_unacquired_by_others [rule_format, OF _ False [symmetric]] ts_i\<^sub>1 False i\<^sub>1_bound' have "A \<inter> all_acquired sb\<^sub>1 = {}" by (auto simp add: Let_def ts\<^sub>s\<^sub>b' owned_def) moreover from ownership_distinct [OF i\<^sub>1_bound' i_bound i\<^sub>1_i ts_i\<^sub>1' ts\<^sub>s\<^sub>b_i] have "(\<O>\<^sub>1 \<union> all_acquired sb\<^sub>1) \<inter> \<O>\<^sub>s\<^sub>b = {}" by (simp add: sb) ultimately show ?thesis using ts_j True by (auto simp add: i_bound ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j False have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from ownership_distinct [OF i\<^sub>1_bound' j_bound' i\<^sub>1_j ts_i\<^sub>1' ts_j'] show "(\<O>\<^sub>1 \<union> all_acquired sb\<^sub>1) \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {}" . qed qed qed qed have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" proof - from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "history_consistent (\<theta>\<^sub>s\<^sub>b(t\<mapsto>ret (m\<^sub>s\<^sub>b a) (f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a))))) (hd_prog p\<^sub>s\<^sub>b []) []" by simp from valid_history_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' sb) qed from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have reads_consis: "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b sb" . have valid_reads': "valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix j p\<^sub>j "is\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b' sb\<^sub>j" proof (cases "i=j") case True from reads_consis ts_j j_bound sb show ?thesis by (clarsimp simp add: True m\<^sub>s\<^sub>b' Write\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b' sb') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') moreover from ts_j False have ts_j': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" using j_bound by (simp add: ts\<^sub>s\<^sub>b') ultimately have consis_m: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j" by (rule valid_reads) let ?m' = "(m\<^sub>s\<^sub>b(a := f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m\<^sub>s\<^sub>b a))))" from a_unowned_others [rule_format, OF _ False] j_bound' ts_j' obtain a_acq: "a \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j" and a_unsh: "a \<notin> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" by auto with a_notin_unforwarded_non_volatile_reads_drop [OF j_bound' ts_j' False] have "\<forall>a\<in>acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<union> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<union> unforwarded_non_volatile_reads (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) {}. ?m' a = m\<^sub>s\<^sub>b a" by auto from reads_consistent_mem_eq_on_unforwarded_non_volatile_reads_drop [where W="{}",simplified, OF this _ _ consis_m] acquired_reads_all_acquired' [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" \<O>\<^sub>j] have "reads_consistent False \<O>\<^sub>j (m\<^sub>s\<^sub>b(a := f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m\<^sub>s\<^sub>b a)))) sb\<^sub>j" by (auto simp del: fun_upd_apply) thus ?thesis by (simp add: m\<^sub>s\<^sub>b') qed qed have valid_sharing': "valid_sharing (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_writes_unshared (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "non_volatile_writes_unshared (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) sb\<^sub>j" proof (cases "i=j") case True with i_bound jth show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') from jth False have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from outstanding_non_volatile_writes_unshared [OF j_bound' jth'] have unshared: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb\<^sub>j". have "\<forall>a\<in>dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) - dom \<S>\<^sub>s\<^sub>b. a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" proof - { fix a assume a_in: "a \<in> dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) - dom \<S>\<^sub>s\<^sub>b" hence a_R: "a \<in> R" by clarsimp assume a_in_j: "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" have False proof - from non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound' jth']] a_in_j have "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto moreover with ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] a_R R_owned show False by blast qed } thus ?thesis by blast qed from non_volatile_writes_unshared_no_outstanding_non_volatile_Write\<^sub>s\<^sub>b [OF unshared this] show ?thesis . qed qed next show "sharing_consis (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "sharing_consistent (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<O>\<^sub>j sb\<^sub>j" proof (cases "i=j") case True with i_bound jth show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') from jth False have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from sharing_consis [OF j_bound' jth'] have consis: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". have acq_cond: "all_acquired sb\<^sub>j \<inter> dom \<S>\<^sub>s\<^sub>b - dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" proof - { fix a assume a_acq: "a \<in> all_acquired sb\<^sub>j" assume "a \<in> dom \<S>\<^sub>s\<^sub>b" assume a_L: "a \<in> L" have False proof - from A_unacquired_by_others [rule_format, of j,OF _ False] j_bound' jth' have "A \<inter> all_acquired sb\<^sub>j = {}" by auto with a_acq a_L L_subset show False by blast qed } thus ?thesis by auto qed have uns_cond: "all_unshared sb\<^sub>j \<inter> dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) - dom \<S>\<^sub>s\<^sub>b = {}" proof - { fix a assume a_uns: "a \<in> all_unshared sb\<^sub>j" assume "a \<notin> L" assume a_R: "a \<in> R" have False proof - from unshared_acquired_or_owned [OF consis] a_uns have "a \<in> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j" by auto with ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] R_owned a_R show False by blast qed } thus ?thesis by auto qed from sharing_consistent_preservation [OF consis acq_cond uns_cond] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed qed next show "unowned_shared (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (unfold_locales) show "- \<Union>((\<lambda>(_,_, _, _,_, \<O>,_). \<O>) ` set ts\<^sub>s\<^sub>b') \<subseteq> dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" proof - have s: "\<Union>((\<lambda>(_,_, _, _,_, \<O>,_). \<O>) ` set ts\<^sub>s\<^sub>b') = \<Union>((\<lambda>(_,_, _, _,_, \<O>,_). \<O>) ` set ts\<^sub>s\<^sub>b) \<union> A - R" apply (unfold ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') apply (rule acquire_release_ownership_nth_update [OF R_owned i_bound ts\<^sub>s\<^sub>b_i]) apply fact done note unowned_shared L_subset A_R then show ?thesis apply (simp only: s) apply auto done qed qed next show "read_only_unowned (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "\<O>\<^sub>j \<inter> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" proof (cases "i=j") case True from read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] R_owned A_R have "(\<O>\<^sub>s\<^sub>b \<union> A - R) \<inter> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs ) with jth ts\<^sub>s\<^sub>b_i i_bound True show ?thesis by (auto simp add: \<O>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') with False jth have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_unowned [OF j_bound' jth'] have "\<O>\<^sub>j \<inter> read_only \<S>\<^sub>s\<^sub>b = {}". moreover from A_unowned_by_others [rule_format, OF _ False] j_bound' jth' have "A \<inter> \<O>\<^sub>j = {}" by (auto dest: all_shared_acquired_in ) moreover from ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] have "\<O>\<^sub>s\<^sub>b \<inter> \<O>\<^sub>j = {}" by auto moreover note R_owned A_R ultimately show ?thesis by (fastforce simp add: in_read_only_convs split: if_split_asm) qed qed next show "no_outstanding_write_to_read_only_memory (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "no_write_to_read_only_memory (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) sb\<^sub>j" proof (cases "i=j") case True with jth ts\<^sub>s\<^sub>b_i i_bound show ?thesis by (auto simp add: sb sb' ts\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') with False jth have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from no_outstanding_write_to_read_only_memory [OF j_bound' jth'] have nw: "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b sb\<^sub>j". have "R \<inter> outstanding_refs is_Write\<^sub>s\<^sub>b sb\<^sub>j = {}" proof - note dist = ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] from non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound' jth']] dist have "outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<inter> \<O>\<^sub>s\<^sub>b = {}" by auto moreover from outstanding_volatile_writes_unowned_by_others [OF j_bound' i_bound False [symmetric] jth' ts\<^sub>s\<^sub>b_i ] have "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<inter> \<O>\<^sub>s\<^sub>b = {}" by auto ultimately have "outstanding_refs is_Write\<^sub>s\<^sub>b sb\<^sub>j \<inter> \<O>\<^sub>s\<^sub>b = {}" by (auto simp add: misc_outstanding_refs_convs) with R_owned show ?thesis by blast qed then have "\<forall>a\<in>outstanding_refs is_Write\<^sub>s\<^sub>b sb\<^sub>j. a \<in> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<longrightarrow> a \<in> read_only \<S>\<^sub>s\<^sub>b" by (auto simp add: in_read_only_convs) from no_write_to_read_only_memory_read_only_reads_eq [OF nw this] show ?thesis . qed qed qed have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" split: instr.splits) from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' "is\<^sub>s\<^sub>b") next from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps []" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') from read_tmps_distinct_nth_update [OF i_bound this] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> read_tmps [] = {}" by (clarsimp) from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" proof - from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] obtain valid_store_sops': "\<forall>sop\<in>store_sops is\<^sub>s\<^sub>b'. valid_sop sop" by (auto simp add: "is\<^sub>s\<^sub>b" ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') from valid_sops_nth_update [OF i_bound _ valid_store_sops', where sb= "[]" ] show ?thesis by (auto simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" proof - from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] obtain dd_is: "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b') is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b') from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> \<Union>(fst ` write_sops []) = {}" by (auto simp add: write_sops_append) from valid_data_dependency_nth_update [OF i_bound dd_is this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b') qed have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps (RMW a t (D,f) cond ret A L R W # is\<^sub>s\<^sub>b') \<inter> dom \<theta>\<^sub>s\<^sub>b = {}" by (simp add: "is\<^sub>s\<^sub>b") moreover from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "t \<notin> load_tmps is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b") ultimately have "load_tmps is\<^sub>s\<^sub>b' \<inter> dom (\<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m\<^sub>s\<^sub>b a) (f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a))))) = {}" by auto from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<theta>\<^sub>s\<^sub>b') qed from enough_flushs_nth_update [OF i_bound, where sb="[]" ] have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" by (auto simp: ts\<^sub>s\<^sub>b' sb' sb) have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - have causal': "causal_program_history is\<^sub>s\<^sub>b' sb'" by (simp add: "is\<^sub>s\<^sub>b" sb sb') have "last_prog p\<^sub>s\<^sub>b sb' = p\<^sub>s\<^sub>b" by (simp add: sb' sb) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed from is_sim have "is": "is = RMW a t (D,f) cond ret A L R W # is\<^sub>s\<^sub>b'" by (simp add: suspends sb "is\<^sub>s\<^sub>b") from direct_memop_step.RMWWrite [where cond=cond and \<theta>=\<theta>\<^sub>s\<^sub>b and m=m, OF cond'] have "(RMW a t (D, f) cond ret A L R W # is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),m, \<D>, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b, \<S>) \<rightarrow> (is\<^sub>s\<^sub>b',\<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m a)))), (), m(a := f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a))), False, \<O>\<^sub>s\<^sub>b \<union> A - R, Map.empty, \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i this] have "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b',\<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m a)))), (), False, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)], m(a := f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a))),\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". moreover have tmps_commute: "\<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m\<^sub>s\<^sub>b a) (f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a)))) = (\<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - {t}))(t \<mapsto> ret (m\<^sub>s\<^sub>b a) (f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m\<^sub>s\<^sub>b a))))" apply (rule ext) apply (auto simp add: restrict_map_def domIff) done from a_unflushed ts\<^sub>s\<^sub>b_i sb have a_unflushed': "\<forall>j < length ts\<^sub>s\<^sub>b. (let (_,_,_,sb\<^sub>j,_,_,_) = ts\<^sub>s\<^sub>b!j in a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" by auto have all_shared_L: "\<forall>i p is \<O> \<R> \<D> acq \<theta> sb. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b ! i = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> L = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_shared: "x \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_L: "x \<in> L" have False proof (cases "i=j") case True with x_shared ts\<^sub>s\<^sub>b_i jth show False by (simp add: sb) next case False show False proof - from all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] have "all_shared sb\<^sub>j \<subseteq> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j". moreover have "all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<subseteq> all_shared sb\<^sub>j" using all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto moreover from A_unacquired_by_others [rule_format, OF _ False] jth j_bound have "A \<inter> all_acquired sb\<^sub>j = {}" by auto moreover from A_unowned_by_others [rule_format, OF _ False] jth j_bound have "A \<inter> \<O>\<^sub>j = {}" by (auto dest: all_shared_acquired_in) ultimately show False using L_subset x_L x_shared by blast qed qed } thus ?thesis by blast qed have all_shared_A: "\<forall>i p is \<O> \<R> \<D> \<theta> sb. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b ! i = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> A = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_shared: "x \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_A: "x \<in> A" have False proof (cases "i=j") case True with x_shared ts\<^sub>s\<^sub>b_i jth show False by (simp add: sb) next case False show False proof - from all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] have "all_shared sb\<^sub>j \<subseteq> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j". moreover have "all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<subseteq> all_shared sb\<^sub>j" using all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto moreover from A_unacquired_by_others [rule_format, OF _ False] jth j_bound have "A \<inter> all_acquired sb\<^sub>j = {}" by auto moreover from A_unowned_by_others [rule_format, OF _ False] jth j_bound have "A \<inter> \<O>\<^sub>j = {}" by (auto dest: all_shared_acquired_in) ultimately show False using x_A x_shared by blast qed qed } thus ?thesis by blast qed hence all_shared_L: "\<forall>i p is \<O> \<R> \<D> \<theta> sb. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b ! i = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> L = {}" using L_subset by blast have all_unshared_R: "\<forall>i p is \<O> \<R> \<D> \<theta> sb. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b ! i = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> R = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_unshared: "x \<in> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_R: "x \<in> R" have False proof (cases "i=j") case True with x_unshared ts\<^sub>s\<^sub>b_i jth show False by (simp add: sb) next case False show False proof - from unshared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] have "all_unshared sb\<^sub>j \<subseteq> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j". moreover have "all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<subseteq> all_unshared sb\<^sub>j" using all_unshared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto moreover note ownership_distinct [OF i_bound j_bound False ts\<^sub>s\<^sub>b_i jth] ultimately show False using R_owned x_R x_unshared by blast qed qed } thus ?thesis by blast qed have all_acquired_R: "\<forall>i p is \<O> \<R> \<D> \<theta> sb. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b ! i = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> R = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_acq: "x \<in> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_R: "x \<in> R" have False proof (cases "i=j") case True with x_acq ts\<^sub>s\<^sub>b_i jth show False by (simp add: sb) next case False show False proof - from x_acq have "x \<in> all_acquired sb\<^sub>j" using all_acquired_append [of "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j"] by auto moreover note ownership_distinct [OF i_bound j_bound False ts\<^sub>s\<^sub>b_i jth] ultimately show False using R_owned x_R by blast qed qed } thus ?thesis by blast qed have all_shared_R: "\<forall>i p is \<O> \<R> \<D> \<theta> sb. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b ! i = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> R = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_shared: "x \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_R: "x \<in> R" have False proof (cases "i=j") case True with x_shared ts\<^sub>s\<^sub>b_i jth show False by (simp add: sb) next case False show False proof - from all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] have "all_shared sb\<^sub>j \<subseteq> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j". moreover have "all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<subseteq> all_shared sb\<^sub>j" using all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto moreover note ownership_distinct [OF i_bound j_bound False ts\<^sub>s\<^sub>b_i jth] ultimately show False using R_owned x_R x_shared by blast qed qed } thus ?thesis by blast qed from share_all_until_volatile_write_commute [OF \<open>ownership_distinct ts\<^sub>s\<^sub>b\<close> \<open>sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> all_shared_L all_shared_A all_acquired_R all_unshared_R all_shared_R] have share_commute: "share_all_until_volatile_write ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L = share_all_until_volatile_write ts\<^sub>s\<^sub>b (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq: "i \<noteq> j" have "release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) (dom \<S>\<^sub>s\<^sub>b \<union> R - L) \<R>\<^sub>j = release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j" proof - { fix a assume a_in: "a \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" have "(a \<in> (dom \<S>\<^sub>s\<^sub>b \<union> R - L)) = (a \<in> dom \<S>\<^sub>s\<^sub>b)" proof - from A_unowned_by_others [rule_format, OF j_bound neq ] jth A_unacquired_by_others [rule_format, OF _ neq] j_bound have A_dist: "A \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {}" by (auto dest: all_shared_acquired_in) from all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] a_in all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] have a_in: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto with ownership_distinct [OF i_bound j_bound neq ts\<^sub>s\<^sub>b_i jth] have "a \<notin> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb)" by auto with A_dist R_owned A_R A_shared_owned L_subset a_in obtain "a \<notin> R" and "a \<notin> L" by fastforce then show ?thesis by auto qed } then show ?thesis apply - apply (rule release_all_shared_exchange) apply auto done qed } note release_commute = this have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b(a := f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m\<^sub>s\<^sub>b a))),\<S>\<^sub>s\<^sub>b') \<sim> (ts[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b(t \<mapsto> ret (m a) (f (\<theta>\<^sub>s\<^sub>b(t\<mapsto>m a)))),(), False,\<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)],m(a := f (\<theta>\<^sub>s\<^sub>b(t \<mapsto> m a))),\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" apply (rule sim_config.intros) apply (simp only: m_a ) apply (simp only: m) apply (simp only: flush_all_until_volatile_write_update_other [OF a_unflushed', symmetric] ts\<^sub>s\<^sub>b') apply (simp add: flush_all_until_volatile_nth_update_unused [OF i_bound ts\<^sub>s\<^sub>b_i, simplified sb] sb') apply (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' m flush_all_until_volatile_nth_update_unused [OF i_bound ts\<^sub>s\<^sub>b_i, simplified sb]) using share_all_until_volatile_write_RMW_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified is\<^sub>s\<^sub>b sb]] apply (clarsimp simp add: \<S> ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' is\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' sb share_commute) using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim apply (clarsimp simp add: Let_def nth_list_update ts\<^sub>s\<^sub>b' sb' sb \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' ex_not m_a split: if_split_asm) apply (rule conjI) apply clarsimp apply (rule tmps_commute) apply clarsimp apply (frule (2) release_commute) apply clarsimp apply fastforce done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_sops' valid_dd' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply) next case (SBHGhost A L R W) then obtain "is\<^sub>s\<^sub>b": "is\<^sub>s\<^sub>b = Ghost A L R W# is\<^sub>s\<^sub>b'" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=\<R>\<^sub>s\<^sub>b" and \<theta>\<^sub>s\<^sub>b': "\<theta>\<^sub>s\<^sub>b' = \<theta>\<^sub>s\<^sub>b" and \<D>\<^sub>s\<^sub>b': "\<D>\<^sub>s\<^sub>b'=\<D>\<^sub>s\<^sub>b" and sb': "sb'=sb@[Ghost\<^sub>s\<^sub>b A L R W]" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b' = m\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" by auto from safe_memop_flush_sb [simplified is\<^sub>s\<^sub>b] obtain L_subset: "L \<subseteq> A" and A_shared_owned: "A \<subseteq> dom (share ?drop_sb \<S>) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" and R_acq: "R \<subseteq> acquired True sb \<O>\<^sub>s\<^sub>b" and A_R: "A \<inter> R = {}" and A_unowned_by_others_ts: "\<forall>j<length (map owned ts). i\<noteq>j \<longrightarrow> (A \<inter> (owned (ts!j) \<union> dom (released (ts!j))) = {})" by cases auto from A_unowned_by_others_ts ts_sim leq have A_unowned_by_others: "\<forall>j<length ts\<^sub>s\<^sub>b. i\<noteq>j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,\<O>\<^sub>j,_) = ts\<^sub>s\<^sub>b!j in A \<inter> (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<union> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)) = {})" apply (clarsimp simp add: Let_def) subgoal for j apply (drule_tac x=j in spec) apply (force simp add: dom_release_takeWhile) done done have A_unused_by_others: "\<forall>j<length (map \<O>_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j, sb\<^sub>j) = map \<O>_sb ts\<^sub>s\<^sub>b! j in A \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j = {})" proof - { fix j \<O>\<^sub>j sb\<^sub>j assume j_bound: "j < length (map owned ts\<^sub>s\<^sub>b)" assume neq_i_j: "i\<noteq>j" assume ts\<^sub>s\<^sub>b_j: "(map \<O>_sb ts\<^sub>s\<^sub>b)!j = (\<O>\<^sub>j,sb\<^sub>j)" assume conflict: "A \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {}" have False proof - from j_bound leq have j_bound': "j < length (map owned ts)" by auto from j_bound have j_bound'': "j < length ts\<^sub>s\<^sub>b" by auto from j_bound' have j_bound''': "j < length ts" by simp from conflict obtain a' where a'_in: "a' \<in> A" and a'_in_j: "a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" by auto let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" from ts_sim [rule_format, OF j_bound''] ts\<^sub>s\<^sub>b_j j_bound'' obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<theta>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>j \<R>\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j,\<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j, release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (force simp add: Let_def) done have "a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b suspends\<^sub>j" proof - from a'_in_j have "a' \<in> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (?take_sb\<^sub>j @ ?drop_sb\<^sub>j)" by simp thus ?thesis apply (simp only: outstanding_refs_append suspends\<^sub>j) apply (auto simp add: outstanding_refs_conv dest: set_takeWhileD) done qed from split_volatile_Write\<^sub>s\<^sub>b_in_outstanding_refs [OF this] obtain sop v ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop v A' L' R' W' # zs" (is "suspends\<^sub>j = ?suspends") by blast from direct_memop_step.Ghost [where \<theta>=\<theta>\<^sub>s\<^sub>b and m="flush ?drop_sb m"] have "(Ghost A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m, \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, share ?drop_sb \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m, \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R, augment_rels (dom (share ?drop_sb \<S>)) R (release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b), share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound_ts' [simplified is\<^sub>s\<^sub>b] ts'_i [simplified is\<^sub>s\<^sub>b] this [simplified is\<^sub>s\<^sub>b]] have store_step: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d (?ts'[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),\<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R,augment_rels (dom (share ?drop_sb \<S>)) R (release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b))], flush ?drop_sb m,share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_A, ?m_A, ?share_A)") by (simp add: is\<^sub>s\<^sub>b) from i_bound' have i_bound'': "i < length ?ts_A" by simp from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts_A_j: "?ts_A!j = (hd_prog p\<^sub>j (ys @ Write\<^sub>s\<^sub>b True a' sop v A' L' R' W' # zs), is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (ys @ Write\<^sub>s\<^sub>b True a' sop v A' L' R' W' # zs)), (), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (simp add: split_suspends\<^sub>j) from j_bound''' i_bound' neq_i_j have j_bound'''': "j < length ?ts_A" by simp from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j reads_consis] have reads_consis_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m] have reads_consis_flush_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A suspends\<^sub>j". hence reads_consis_m_A_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A ys" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops ys. valid_sop sop" apply (simp only: write_sops_append ) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b ys = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from flush_store_buffer_append [ OF j_bound'''' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_A_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_m_A_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?share_A"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W' # zs) @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W' # zs)" and steps_ys: "(?ts_A, ?m_A, ?share_A) \<Rightarrow>\<^sub>d\<^sup>* (?ts_A[j:= (last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W' # zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W' # zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j') ], flush ys ?m_A, share ys ?share_A)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto) note conflict_computation = rtranclp_trans [OF rtranclp_r_rtranclp [OF steps_flush_sb, OF store_step] steps_ys] from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Write\<^sub>s\<^sub>b True a' sop v A' L' R' W']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Write True a' sop A' L' R' W' #is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from j_bound''' have j_bound_ys: "j < length ?ts_ys" by auto from j_bound_ys neq_i_j have ts_ys_j: "?ts_ys!j=(last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a' sop v A' L' R' W'# zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by auto from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j, simplified is\<^sub>j'] have a_unowned: "\<forall>i < length ?ts_ys. j\<noteq>i \<longrightarrow> (let (\<O>\<^sub>i) = map owned ?ts_ys!i in a' \<notin> \<O>\<^sub>i)" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done from a'_in a_unowned [rule_format, of i] neq_i_j i_bound' A_R show False by (auto simp add: Let_def) qed } thus ?thesis by (auto simp add: Let_def) qed have A_unaquired_by_others: "\<forall>j<length (map \<O>_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j, sb\<^sub>j) = map \<O>_sb ts\<^sub>s\<^sub>b! j in A \<inter> all_acquired sb\<^sub>j = {})" proof - { fix j \<O>\<^sub>j sb\<^sub>j assume j_bound: "j < length (map owned ts\<^sub>s\<^sub>b)" assume neq_i_j: "i\<noteq>j" assume ts\<^sub>s\<^sub>b_j: "(map \<O>_sb ts\<^sub>s\<^sub>b)!j = (\<O>\<^sub>j,sb\<^sub>j)" assume conflict: "A \<inter> all_acquired sb\<^sub>j \<noteq> {}" have False proof - from j_bound leq have j_bound': "j < length (map owned ts)" by auto from j_bound have j_bound'': "j < length ts\<^sub>s\<^sub>b" by auto from j_bound' have j_bound''': "j < length ts" by simp from conflict obtain a' where a'_in: "a' \<in> A" and a'_in_j: "a' \<in> all_acquired sb\<^sub>j" by auto let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" from ts_sim [rule_format, OF j_bound''] ts\<^sub>s\<^sub>b_j j_bound'' obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<theta>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>j \<R>\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (force simp add: Let_def) done from a'_in_j all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "a' \<in> all_acquired ?take_sb\<^sub>j \<or> a' \<in> all_acquired suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) thus False proof assume "a' \<in> all_acquired ?take_sb\<^sub>j" with A_unowned_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound a'_in show False by (auto dest: all_acquired_unshared_acquired) next assume conflict_drop: "a' \<in> all_acquired suspends\<^sub>j" from split_all_acquired_in [OF conflict_drop] (* FIXME: exract common parts *) show False proof assume "\<exists>sop a'' v ys zs A L R W. suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a'' sop v A L R W# zs \<and> a' \<in> A" then obtain a'' sop' v' ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs" (is "suspends\<^sub>j = ?suspends") and a'_A': "a' \<in> A'" by auto from direct_memop_step.Ghost [where \<theta>=\<theta>\<^sub>s\<^sub>b and m="flush ?drop_sb m"] have "(Ghost A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m,\<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b,share ?drop_sb \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m, \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R, augment_rels (dom (share ?drop_sb \<S>)) R (release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b), share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound_ts' [simplified is\<^sub>s\<^sub>b] ts'_i [simplified is\<^sub>s\<^sub>b] this [simplified is\<^sub>s\<^sub>b]] have store_step: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d (?ts'[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b',\<theta>\<^sub>s\<^sub>b, (),\<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R, augment_rels (dom (share ?drop_sb \<S>)) R (release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b))], flush ?drop_sb m,share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_A, ?m_A, ?share_A)") by (simp add: is\<^sub>s\<^sub>b) from i_bound' have i_bound'': "i < length ?ts_A" by simp from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts_A_j: "?ts_A!j = (hd_prog p\<^sub>j (ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs), is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (ys @ Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs)), (), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j, release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (simp add: split_suspends\<^sub>j) from j_bound''' i_bound' neq_i_j have j_bound'''': "j < length ?ts_A" by simp from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j reads_consis] have reads_consis_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m] have reads_consis_flush_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A suspends\<^sub>j". hence reads_consis_m_A_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A ys" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops ys. valid_sop sop" apply (simp only: write_sops_append ) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b ys = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from flush_store_buffer_append [ OF j_bound'''' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_A_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_m_A_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?share_A"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs) @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs)" and steps_ys: "(?ts_A, ?m_A, ?share_A) \<Rightarrow>\<^sub>d\<^sup>* (?ts_A[j:= (last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W' # zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j') ], flush ys ?m_A,share ys ?share_A)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto) note conflict_computation = rtranclp_trans [OF rtranclp_r_rtranclp [OF steps_flush_sb, OF store_step] steps_ys] from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Write True a'' sop' A' L' R' W'#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from j_bound''' have j_bound_ys: "j < length ?ts_ys" by auto from j_bound_ys neq_i_j have ts_ys_j: "?ts_ys!j=(last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by auto from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j, simplified is\<^sub>j'] have A'_unowned: "\<forall>i < length ?ts_ys. j\<noteq>i \<longrightarrow> (let (\<O>\<^sub>i) = map owned ?ts_ys!i in A' \<inter> \<O>\<^sub>i = {})" apply cases apply (fastforce simp add: Let_def is\<^sub>s\<^sub>b)+ done from a'_in a'_A' A'_unowned [rule_format, of i] neq_i_j i_bound' A_R show False by (auto simp add: Let_def) next assume "\<exists>A L R W ys zs. suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A L R W # zs \<and> a' \<in> A" then obtain ys zs A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs" (is "suspends\<^sub>j = ?suspends") and a'_A': "a' \<in> A'" by auto from direct_memop_step.Ghost [where \<theta>=\<theta>\<^sub>s\<^sub>b and m="flush ?drop_sb m"] have "(Ghost A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m, \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, share ?drop_sb \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m, \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R, augment_rels (dom (share ?drop_sb \<S>)) R (release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b), share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound_ts' [simplified is\<^sub>s\<^sub>b] ts'_i [simplified is\<^sub>s\<^sub>b] this [simplified is\<^sub>s\<^sub>b]] have store_step: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d (?ts'[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R,augment_rels (dom (share ?drop_sb \<S>)) R (release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b))], flush ?drop_sb m,share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_A, ?m_A, ?share_A)") by (simp add: is\<^sub>s\<^sub>b) from i_bound' have i_bound'': "i < length ?ts_A" by simp from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts_A_j: "?ts_A!j = (hd_prog p\<^sub>j (ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs), is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)), (),\<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (simp add: split_suspends\<^sub>j) from j_bound''' i_bound' neq_i_j have j_bound'''': "j < length ?ts_A" by simp from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j reads_consis] have reads_consis_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m] have reads_consis_flush_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A suspends\<^sub>j". hence reads_consis_m_A_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A ys" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops ys. valid_sop sop" apply (simp only: write_sops_append ) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b ys = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from flush_store_buffer_append [ OF j_bound'''' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_A_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_m_A_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?share_A"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs) @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)" and steps_ys: "(?ts_A, ?m_A, ?share_A) \<Rightarrow>\<^sub>d\<^sup>* (?ts_A[j:= (last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j') ], flush ys ?m_A, share ys ?share_A)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto) note conflict_computation = rtranclp_trans [OF rtranclp_r_rtranclp [OF steps_flush_sb, OF store_step] steps_ys] from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Ghost A' L' R' W'#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from j_bound''' have j_bound_ys: "j < length ?ts_ys" by auto from j_bound_ys neq_i_j have ts_ys_j: "?ts_ys!j=(last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Write\<^sub>s\<^sub>b True a'' sop' v' A' L' R' W'# zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by auto from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j, simplified is\<^sub>j'] have A'_unowned: "\<forall>i < length ?ts_ys. j\<noteq>i \<longrightarrow> (let (\<O>\<^sub>i) = map owned ?ts_ys!i in A' \<inter> \<O>\<^sub>i = {})" apply cases apply (fastforce simp add: Let_def is\<^sub>s\<^sub>b)+ done from a'_in a'_A' A'_unowned [rule_format, of i] neq_i_j i_bound' A_R show False by (auto simp add: Let_def) qed qed qed } thus ?thesis by (auto simp add: Let_def) qed have A_no_read_only_reads_by_others: "\<forall>j<length (map \<O>_sb ts\<^sub>s\<^sub>b). i \<noteq> j \<longrightarrow> (let (\<O>\<^sub>j, sb\<^sub>j) = map \<O>_sb ts\<^sub>s\<^sub>b! j in A \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) = {})" proof - { fix j \<O>\<^sub>j sb\<^sub>j assume j_bound: "j < length (map owned ts\<^sub>s\<^sub>b)" assume neq_i_j: "i\<noteq>j" assume ts\<^sub>s\<^sub>b_j: "(map \<O>_sb ts\<^sub>s\<^sub>b)!j = (\<O>\<^sub>j,sb\<^sub>j)" let ?take_sb\<^sub>j = "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" let ?drop_sb\<^sub>j = "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume conflict: "A \<inter> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j \<noteq> {}" have False proof - from j_bound leq have j_bound': "j < length (map owned ts)" by auto from j_bound have j_bound'': "j < length ts\<^sub>s\<^sub>b" by auto from j_bound' have j_bound''': "j < length ts" by simp from conflict obtain a' where a'_in: "a' \<in> A" and a'_in_j: "a' \<in> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto from ts_sim [rule_format, OF j_bound''] ts\<^sub>s\<^sub>b_j j_bound'' obtain p\<^sub>j suspends\<^sub>j "is\<^sub>s\<^sub>b\<^sub>j" \<D>\<^sub>s\<^sub>b\<^sub>j \<D>\<^sub>j \<R>\<^sub>j \<theta>\<^sub>s\<^sub>b\<^sub>j "is\<^sub>j" where ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j, sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" and suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" apply (cases "ts\<^sub>s\<^sub>b!j") apply (force simp add: Let_def) done from split_in_read_only_reads [OF a'_in_j [simplified suspends\<^sub>j [symmetric]]] obtain t v ys zs where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Read\<^sub>s\<^sub>b False a' t v# zs" (is "suspends\<^sub>j = ?suspends") and a'_unacq: "a' \<notin> acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j)" by blast from direct_memop_step.Ghost [where \<theta>=\<theta>\<^sub>s\<^sub>b and m="flush ?drop_sb m"] have "(Ghost A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m, \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b, release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, share ?drop_sb \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), flush ?drop_sb m, \<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R, augment_rels (dom (share ?drop_sb \<S>)) R (release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b), share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound_ts' [simplified is\<^sub>s\<^sub>b] ts'_i [simplified is\<^sub>s\<^sub>b] this [simplified is\<^sub>s\<^sub>b]] have store_step: "(?ts', flush ?drop_sb m, share ?drop_sb \<S>) \<Rightarrow>\<^sub>d (?ts'[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),\<D>\<^sub>s\<^sub>b, acquired True sb \<O>\<^sub>s\<^sub>b \<union> A - R,augment_rels (dom (share ?drop_sb \<S>)) R (release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b))], flush ?drop_sb m,share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" (is " _ \<Rightarrow>\<^sub>d (?ts_A, ?m_A, ?share_A)") by (simp add: is\<^sub>s\<^sub>b) from i_bound' have i_bound'': "i < length ?ts_A" by simp from valid_program_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from ts\<^sub>j neq_i_j j_bound have ts_A_j: "?ts_A!j = (hd_prog p\<^sub>j (ys @ Read\<^sub>s\<^sub>b False a' t v# zs), is\<^sub>j, \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (ys @ Read\<^sub>s\<^sub>b False a' t v# zs)), (),\<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,release ?take_sb\<^sub>j (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j)" by (simp add: split_suspends\<^sub>j) from j_bound''' i_bound' neq_i_j have j_bound'''': "j < length ?ts_A" by simp from valid_last_prog [OF j_bound'' ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". then have lp: "last_prog p\<^sub>j ?suspends = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_reads [OF j_bound'' ts\<^sub>s\<^sub>b_j] have reads_consis: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound'' ts\<^sub>s\<^sub>b_j reads_consis] have reads_consis_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) from outstanding_non_write_non_vol_reads_drop_disj [OF i_bound j_bound'' neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] have "outstanding_refs is_Write\<^sub>s\<^sub>b ?drop_sb \<inter> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b suspends\<^sub>j = {}" by (simp add: suspends\<^sub>j) from reads_consistent_flush_independent [OF this reads_consis_m] have reads_consis_flush_m: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A suspends\<^sub>j". hence reads_consis_m_A_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?m_A ys" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_history [OF j_bound'' ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from valid_write_sops [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops ys. valid_sop sop" apply (simp only: write_sops_append ) apply auto done from read_tmps_distinct [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b ys = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) from flush_store_buffer_append [ OF j_bound'''' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts_A_j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_m_A_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="?share_A"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs (Read\<^sub>s\<^sub>b False a' t v # zs) @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs (Read\<^sub>s\<^sub>b False a' t v # zs)" and steps_ys: "(?ts_A, ?m_A, ?share_A) \<Rightarrow>\<^sub>d\<^sup>* (?ts_A[j:= (last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Read\<^sub>s\<^sub>b False a' t v # zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j') ], flush ys ?m_A, share ys ?share_A)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto) note conflict_computation = rtranclp_trans [OF rtranclp_r_rtranclp [OF steps_flush_sb, OF store_step] steps_ys] from cph have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ((ys @ [Read\<^sub>s\<^sub>b False a' t v]) @ zs)" by simp from causal_program_history_suffix [OF this] have cph': "causal_program_history is\<^sub>s\<^sub>b\<^sub>j zs". interpret causal\<^sub>j: causal_program_history "is\<^sub>s\<^sub>b\<^sub>j" "zs" by (rule cph') from causal\<^sub>j.causal_program_history [of "[]", simplified, OF refl] is\<^sub>j' obtain is\<^sub>j'' where is\<^sub>j': "is\<^sub>j' = Read False a' t#is\<^sub>j''" and is\<^sub>j'': "instrs zs @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j'' @ prog_instrs zs" by clarsimp from j_bound''' have j_bound_ys: "j < length ?ts_ys" by auto from j_bound_ys neq_i_j have ts_ys_j: "?ts_ys!j=(last_prog (hd_prog p\<^sub>j (Read\<^sub>s\<^sub>b False a' t v# zs)) ys, is\<^sub>j', \<theta>\<^sub>s\<^sub>b\<^sub>j |` (dom \<theta>\<^sub>s\<^sub>b\<^sub>j - read_tmps (Read\<^sub>s\<^sub>b False a' t v# zs)),(), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j),\<R>\<^sub>j')" by auto from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have "safe_delayed (?ts_ys,?m_ys,?shared_ys)". from safe_delayedE [OF this j_bound_ys ts_ys_j, simplified is\<^sub>j'] have "a' \<in> acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<or> a' \<in> read_only (share ys (share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" apply cases apply (auto simp add: Let_def is\<^sub>s\<^sub>b) done with a'_unacq have a'_ro: "a' \<in> read_only (share ys (share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" by auto from a'_in have a'_not_ro: "a' \<notin> read_only (share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs) have "a' \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof - { assume a_notin: "a' \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" from weak_sharing_consis [OF j_bound'' ts\<^sub>s\<^sub>b_j] have "weak_sharing_consistent \<O>\<^sub>j sb\<^sub>j". with weak_sharing_consistent_append [of \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "weak_sharing_consistent (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) suspends\<^sub>j" by (auto simp add: suspends\<^sub>j) with split_suspends\<^sub>j have weak_consis: "weak_sharing_consistent (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ys" by (simp add: weak_sharing_consistent_append) from all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "all_acquired ys \<subseteq> all_acquired sb\<^sub>j" apply (clarsimp) apply (clarsimp simp add: suspends\<^sub>j [symmetric] split_suspends\<^sub>j all_acquired_append) done with a_notin acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b [of sb\<^sub>j \<O>\<^sub>j] all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "a' \<notin> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j \<union> all_acquired ys" by auto from read_only_share_unowned [OF weak_consis this a'_ro] have "a' \<in> read_only (share ?drop_sb \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" . with a'_not_ro have False by auto } thus ?thesis by blast qed moreover from A_unaquired_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have "A \<inter> all_acquired sb\<^sub>j = {}" by (auto simp add: Let_def) moreover from A_unowned_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have "A \<inter> \<O>\<^sub>j = {}" by (auto simp add: Let_def dest: all_shared_acquired_in) moreover note a'_in ultimately show False by auto qed } thus ?thesis by (auto simp add: Let_def) qed have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb @ [Ghost\<^sub>s\<^sub>b A L R W]) " by (auto simp add: non_volatile_owned_or_read_only_append) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix i\<^sub>1 j p\<^sub>1 "is\<^sub>1" \<O>\<^sub>1 \<R>\<^sub>1 \<D>\<^sub>1 xs\<^sub>1 sb\<^sub>1 p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume i\<^sub>1_bound: "i\<^sub>1 < length ts\<^sub>s\<^sub>b'" assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume i\<^sub>1_j: "i\<^sub>1 \<noteq> j" assume ts_i\<^sub>1: "ts\<^sub>s\<^sub>b'!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" proof (cases "i\<^sub>1=i") case True with i\<^sub>1_j have i_j: "i\<noteq>j" by simp from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') hence j_bound'': "j < length (map owned ts\<^sub>s\<^sub>b)" by simp from ts_j i_j have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from outstanding_volatile_writes_unowned_by_others [OF i_bound j_bound' i_j ts\<^sub>s\<^sub>b_i ts_j'] have "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}". with ts_i\<^sub>1 True i_bound show ?thesis by (clarsimp simp add: ts\<^sub>s\<^sub>b' sb' outstanding_refs_append acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) next case False note i\<^sub>1_i = this from i\<^sub>1_bound have i\<^sub>1_bound': "i\<^sub>1 < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_i\<^sub>1 False have ts_i\<^sub>1': "ts\<^sub>s\<^sub>b!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" by (simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "j=i") case True from i\<^sub>1_bound' have i\<^sub>1_bound'': "i\<^sub>1 < length (map owned ts\<^sub>s\<^sub>b)" by simp from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' i_bound i\<^sub>1_i ts_i\<^sub>1' ts\<^sub>s\<^sub>b_i] have "(\<O>\<^sub>s\<^sub>b \<union> all_acquired sb) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}". moreover from A_unused_by_others [rule_format, OF _ False [symmetric]] False ts_i\<^sub>1 i\<^sub>1_bound have "A \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" by (auto simp add: Let_def ts\<^sub>s\<^sub>b') ultimately show ?thesis using ts_j True ts\<^sub>s\<^sub>b' by (auto simp add: i_bound ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' all_acquired_append) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j False have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' j_bound' i\<^sub>1_j ts_i\<^sub>1' ts_j'] show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" . qed qed qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof fix n m fix p\<^sub>n "is\<^sub>n" \<O>\<^sub>n \<R>\<^sub>n \<D>\<^sub>n \<theta>\<^sub>n sb\<^sub>n p\<^sub>m "is\<^sub>m" \<O>\<^sub>m \<R>\<^sub>m \<D>\<^sub>m \<theta>\<^sub>m sb\<^sub>m assume n_bound: "n < length ts\<^sub>s\<^sub>b'" and m_bound: "m < length ts\<^sub>s\<^sub>b'" and neq_n_m: "n\<noteq>m" and nth: "ts\<^sub>s\<^sub>b'!n = (p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" and mth: "ts\<^sub>s\<^sub>b'!m =(p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" from n_bound have n_bound': "n < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from m_bound have m_bound': "m < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') show "(\<O>\<^sub>m \<union> all_acquired sb\<^sub>m) \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<O>\<^sub>n) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) = {}" proof (cases "m=i") case True with neq_n_m have neq_n_i: "n\<noteq>i" by auto with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') note read_only_reads_unowned [OF n_bound' i_bound neq_n_i nth' ts\<^sub>s\<^sub>b_i] moreover from A_no_read_only_reads_by_others [rule_format, OF _ neq_n_i [symmetric]] n_bound' nth' have "A \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<O>\<^sub>n) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) = {}" by auto ultimately show ?thesis using True ts\<^sub>s\<^sub>b_i nth' mth n_bound' m_bound' by (auto simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' all_acquired_append) next case False note neq_m_i = this with m_bound mth i_bound have mth': "ts\<^sub>s\<^sub>b!m = (p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" by (auto simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "n=i") case True note read_only_reads_unowned [OF i_bound m_bound' neq_m_i [symmetric] ts\<^sub>s\<^sub>b_i mth'] then show ?thesis using True neq_m_i ts\<^sub>s\<^sub>b_i nth mth n_bound' m_bound' apply (case_tac "outstanding_refs (is_volatile_Write\<^sub>s\<^sub>b) sb = {}") apply (clarsimp simp add: outstanding_vol_write_take_drop_appends acquired_append read_only_reads_append ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b')+ done next case False with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_reads_unowned [OF n_bound' m_bound' neq_n_m nth' mth'] False neq_m_i show ?thesis by (clarsimp) qed qed qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof - have "\<forall>j<length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (p\<^sub>j, is\<^sub>j,\<theta>\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j,\<R>\<^sub>j) = ts\<^sub>s\<^sub>b ! j in (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb') \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {})" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume neq_i_j: "i \<noteq> j" assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j, is\<^sub>j, \<theta>\<^sub>j, sb\<^sub>j, \<D>\<^sub>j, \<O>\<^sub>j,\<R>\<^sub>j)" have "(\<O>\<^sub>s\<^sub>b \<union> all_acquired sb') \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {}" proof - { fix a' assume a'_in_i: "a' \<in> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb')" assume a'_in_j: "a' \<in> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j)" have False proof - from a'_in_i have "a' \<in> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb) \<or> a' \<in> A" by (simp add: sb' all_acquired_append) then show False proof assume "a' \<in> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb)" with ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] a'_in_j show ?thesis by auto next assume "a' \<in> A" moreover have j_bound': "j < length (map owned ts\<^sub>s\<^sub>b)" using j_bound by auto from A_unowned_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound obtain "A \<inter> acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j = {}" and "A \<inter> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) = {}" by (auto simp add: Let_def) moreover from A_unaquired_by_others [rule_format, OF _ neq_i_j] ts\<^sub>s\<^sub>b_j j_bound have "A \<inter> all_acquired sb\<^sub>j = {}" by auto ultimately show ?thesis using a'_in_j by (auto dest: all_shared_acquired_in) qed qed } then show ?thesis by auto qed } then show ?thesis by (fastforce simp add: Let_def) qed from ownership_distinct_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb') qed qed have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" proof - from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b sb) sb". with valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] valid_implies_valid_prog_hd [OF i_bound ts\<^sub>s\<^sub>b_i valid] have "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b (sb@[Ghost\<^sub>s\<^sub>b A L R W])) (sb@ [Ghost\<^sub>s\<^sub>b A L R W])" apply - apply (rule history_consistent_appendI) apply (auto simp add: hd_prog_append_Ghost\<^sub>s\<^sub>b) done from valid_history_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<theta>\<^sub>s\<^sub>b') qed have valid_reads': "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b'" proof - from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b sb" . from reads_consistent_snoc_Ghost\<^sub>s\<^sub>b [OF this] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b (sb @ [Ghost\<^sub>s\<^sub>b A L R W])". from valid_reads_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b') qed have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (sb @ [Ghost\<^sub>s\<^sub>b A L R W])" by (auto simp add: non_volatile_writes_unshared_append) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' \<S>\<^sub>s\<^sub>b') next from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have consis': "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb". from A_shared_owned have "A \<subseteq> dom (share ?drop_sb \<S>) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" by (simp add: sharing_consistent_append acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) moreover have "dom (share ?drop_sb \<S>) \<subseteq> dom \<S> \<union> dom (share sb \<S>\<^sub>s\<^sub>b)" proof fix a' assume a'_in: "a' \<in> dom (share ?drop_sb \<S>)" from share_unshared_in [OF a'_in] show "a' \<in> dom \<S> \<union> dom (share sb \<S>\<^sub>s\<^sub>b)" proof assume "a' \<in> dom (share ?drop_sb Map.empty)" from share_mono_in [OF this] share_append [of ?take_sb ?drop_sb] have "a' \<in> dom (share sb \<S>\<^sub>s\<^sub>b)" by auto thus ?thesis by simp next assume "a' \<in> dom \<S> \<and> a' \<notin> all_unshared ?drop_sb" thus ?thesis by auto qed qed ultimately have A_subset: "A \<subseteq> dom \<S> \<union> dom (share sb \<S>\<^sub>s\<^sub>b) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" by auto have "A \<subseteq> dom (share sb \<S>\<^sub>s\<^sub>b) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" proof - { fix x assume x_A: "x \<in> A" have "x \<in> dom (share sb \<S>\<^sub>s\<^sub>b) \<union> acquired True sb \<O>\<^sub>s\<^sub>b" proof - { assume "x \<in> dom \<S>" from share_all_until_volatile_write_share_acquired [OF \<open>sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> i_bound ts\<^sub>s\<^sub>b_i this [simplified \<S>]] A_unowned_by_others x_A have ?thesis by (fastforce simp add: Let_def) } with A_subset show ?thesis using x_A by auto qed } thus ?thesis by blast qed with consis' L_subset A_R R_acq have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb @ [Ghost\<^sub>s\<^sub>b A L R W])" by (simp add: sharing_consistent_append acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b) from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' \<S>\<^sub>s\<^sub>b') next from read_only_unowned_nth_update [OF i_bound read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] ] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b (sb @ [Ghost\<^sub>s\<^sub>b A L R W])" by (simp add: no_write_to_read_only_memory_append) from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound this] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb') qed have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b'" by (simp add: "is\<^sub>s\<^sub>b") from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') next from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps (sb @ [Ghost\<^sub>s\<^sub>b A L R W])" by (auto simp add: distinct_read_tmps_append) from read_tmps_distinct_nth_update [OF i_bound this] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> read_tmps (sb @ [Ghost\<^sub>s\<^sub>b A L R W]) ={}" by (auto simp add: read_tmps_append "is\<^sub>s\<^sub>b") from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' sb') qed have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" proof - from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] obtain valid_store_sops': "\<forall>sop\<in>store_sops is\<^sub>s\<^sub>b'. valid_sop sop" by (auto simp add: "is\<^sub>s\<^sub>b") from valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have valid_write_sops': "\<forall>sop\<in>write_sops (sb@ [Ghost\<^sub>s\<^sub>b A L R W]). valid_sop sop" by (auto simp add: write_sops_append) from valid_sops_nth_update [OF i_bound valid_write_sops' valid_store_sops'] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" proof - from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] obtain dd_is: "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b') is\<^sub>s\<^sub>b'" by (auto simp add: "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b') from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> \<Union>(fst ` write_sops (sb@ [Ghost\<^sub>s\<^sub>b A L R W])) ={}" by (auto simp add: write_sops_append "is\<^sub>s\<^sub>b") from valid_data_dependency_nth_update [OF i_bound dd_is this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b' \<inter> dom \<theta>\<^sub>s\<^sub>b = {}" by (auto simp add: "is\<^sub>s\<^sub>b") from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b') qed have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" proof - from clean_no_outstanding_volatile_Write\<^sub>s\<^sub>b [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<not> \<D>\<^sub>s\<^sub>b \<longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Ghost\<^sub>s\<^sub>b A L R W])= {}" by (auto simp add: outstanding_refs_append) from enough_flushs_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b') qed have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . then have causal': "causal_program_history is\<^sub>s\<^sub>b' (sb@[Ghost\<^sub>s\<^sub>b A L R W])" by (auto simp: causal_program_history_Ghost "is\<^sub>s\<^sub>b") from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". hence "last_prog p\<^sub>s\<^sub>b (sb @ [Ghost\<^sub>s\<^sub>b A L R W]) = p\<^sub>s\<^sub>b" by (simp add: last_prog_append_Ghost\<^sub>s\<^sub>b) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb') qed show ?thesis proof (cases "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}") case True from True have flush_all: "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = sb" by (auto simp add: outstanding_refs_conv) from True have suspend_nothing: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = []" by (auto simp add: outstanding_refs_conv) hence suspends_empty: "suspends = []" by (simp add: suspends) from suspends_empty is_sim have "is": "is =Ghost A L R W# is\<^sub>s\<^sub>b'" by (simp add: "is\<^sub>s\<^sub>b") with suspends_empty ts_i have ts_i: "ts!i = (p\<^sub>s\<^sub>b, Ghost A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp from direct_memop_step.Ghost have "(Ghost A L R W# is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),m, \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b, \<S>) \<rightarrow> (is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (), m, \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R, augment_rels (dom \<S>) R (release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b), \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". from direct_computation.concurrent_step.Memop [OF i_bound' ts_i this] have "(ts, m, \<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b, (),\<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R, augment_rels (dom \<S>) R (release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b))], m,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". moreover from suspend_nothing have suspend_nothing': "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = []" by (simp add: sb') have all_shared_A: "\<forall>j p is \<O> \<R> \<D> \<theta> sb. j < length ts\<^sub>s\<^sub>b \<longrightarrow> i \<noteq> j \<longrightarrow> ts\<^sub>s\<^sub>b ! j = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> A = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j, \<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_shared: "x \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_A: "x \<in> A" have False proof - from all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] have "all_shared sb\<^sub>j \<subseteq> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j". moreover have "all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<subseteq> all_shared sb\<^sub>j" using all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto moreover from A_unaquired_by_others [rule_format, OF _ neq_i_j] jth j_bound have "A \<inter> all_acquired sb\<^sub>j = {}" by auto moreover from A_unowned_by_others [rule_format, OF _ neq_i_j] jth j_bound have "A \<inter> \<O>\<^sub>j = {}" by (auto dest: all_shared_acquired_in) ultimately show False using x_A x_shared by blast qed } thus ?thesis by blast qed hence all_shared_L: "\<forall>j p is \<O> \<R> \<D> \<theta> sb. j < length ts\<^sub>s\<^sub>b \<longrightarrow> i \<noteq> j \<longrightarrow> ts\<^sub>s\<^sub>b ! j = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> L = {}" using L_subset by blast have all_shared_A: "\<forall>j p is \<O> \<R> \<D> \<theta> sb. j < length ts\<^sub>s\<^sub>b \<longrightarrow> i \<noteq> j \<longrightarrow> ts\<^sub>s\<^sub>b ! j = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> A = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume neq_i_j: "i \<noteq> j" assume x_shared: "x \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_A: "x \<in> A" have False proof - from all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] have "all_shared sb\<^sub>j \<subseteq> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j". moreover have "all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<subseteq> all_shared sb\<^sub>j" using all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto moreover from A_unaquired_by_others [rule_format, OF _ neq_i_j] jth j_bound have "A \<inter> all_acquired sb\<^sub>j = {}" by auto moreover from A_unowned_by_others [rule_format, OF _ neq_i_j] jth j_bound have "A \<inter> \<O>\<^sub>j = {}" by (auto dest: all_shared_acquired_in) ultimately show False using x_A x_shared by blast qed } thus ?thesis by blast qed hence all_shared_L: "\<forall>j p is \<O> \<R> \<D> \<theta> sb. j < length ts\<^sub>s\<^sub>b \<longrightarrow> i \<noteq> j \<longrightarrow> ts\<^sub>s\<^sub>b ! j = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> L = {}" using L_subset by blast have all_unshared_R: "\<forall>j p is \<O> \<R> \<D> \<theta> sb. j < length ts\<^sub>s\<^sub>b \<longrightarrow> i \<noteq> j \<longrightarrow> ts\<^sub>s\<^sub>b ! j = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> R = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_unshared: "x \<in> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_R: "x \<in> R" have False proof - from unshared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] have "all_unshared sb\<^sub>j \<subseteq> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j". moreover have "all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<subseteq> all_unshared sb\<^sub>j" using all_unshared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto moreover note ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] ultimately show False using R_acq x_R x_unshared acquired_all_acquired [of True sb \<O>\<^sub>s\<^sub>b] by blast qed } thus ?thesis by blast qed have all_acquired_R: "\<forall>j p is \<O> \<R> \<D> \<theta> sb. j < length ts\<^sub>s\<^sub>b \<longrightarrow> i \<noteq> j \<longrightarrow> ts\<^sub>s\<^sub>b ! j = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> R = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume neq_i_j: "i \<noteq> j" assume x_acq: "x \<in> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_R: "x \<in> R" have False proof - from x_acq have "x \<in> all_acquired sb\<^sub>j" using all_acquired_append [of "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j"] by auto moreover note ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] ultimately show False using R_acq x_R acquired_all_acquired [of True sb \<O>\<^sub>s\<^sub>b] by blast qed } thus ?thesis by blast qed have all_shared_R: "\<forall>j p is \<O> \<R> \<D> \<theta> sb. j < length ts\<^sub>s\<^sub>b \<longrightarrow> i \<noteq> j \<longrightarrow> ts\<^sub>s\<^sub>b ! j = (p, is, \<theta>, sb, \<D>, \<O>,\<R>) \<longrightarrow> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<inter> R = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume neq_i_j: "i \<noteq> j" assume x_shared: "x \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_R: "x \<in> R" have False proof - from all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] have "all_shared sb\<^sub>j \<subseteq> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j". moreover have "all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<subseteq> all_shared sb\<^sub>j" using all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto moreover note ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] ultimately show False using R_acq x_R x_shared acquired_all_acquired [of True sb \<O>\<^sub>s\<^sub>b] by blast qed } thus ?thesis by blast qed note share_commute = share_all_until_volatile_write_append_Ghost\<^sub>s\<^sub>b [OF True \<open>ownership_distinct ts\<^sub>s\<^sub>b\<close> \<open>sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> i_bound ts\<^sub>s\<^sub>b_i all_shared_L all_shared_A all_acquired_R all_unshared_R all_shared_R] from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Ghost\<^sub>s\<^sub>b A L R W]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "\<forall>a \<in> R. (a \<in> (dom (share sb \<S>\<^sub>s\<^sub>b)) ) = (a \<in> dom \<S>)" proof - { fix a assume a_R: "a \<in> R" have "(a \<in> (dom (share sb \<S>\<^sub>s\<^sub>b)) ) = (a \<in> dom \<S>)" proof - from a_R R_acq acquired_all_acquired [of True sb \<O>\<^sub>s\<^sub>b] have "a \<in> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by auto from share_all_until_volatile_write_thread_local' [OF ownership_distinct_ts\<^sub>s\<^sub>b sharing_consis_ts\<^sub>s\<^sub>b i_bound ts\<^sub>s\<^sub>b_i this] suspend_nothing show ?thesis by (auto simp add: domIff \<S>) qed } then show ?thesis by auto qed from augment_rels_shared_exchange [OF this] have rel_commute: "augment_rels (dom \<S>) R (release sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b) = release (sb @ [Ghost\<^sub>s\<^sub>b A L R W]) (dom \<S>\<^sub>s\<^sub>b') \<R>\<^sub>s\<^sub>b" by (clarsimp simp add: release_append \<S>\<^sub>s\<^sub>b') have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts[i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b', \<theta>\<^sub>s\<^sub>b,(), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R, augment_rels (dom \<S>) R (release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b))], m,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" apply (rule sim_config.intros) apply (simp add: m ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb' \<theta>\<^sub>s\<^sub>b' flush_all_until_volatile_write_append_Ghost_commute [OF i_bound ts\<^sub>s\<^sub>b_i]) apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' share_commute) using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i True \<D>' apply (clarsimp simp add: Let_def nth_list_update outstanding_refs_conv ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb' \<D>\<^sub>s\<^sub>b' suspend_nothing' flush_all rel_commute acquired_append split: if_split_asm) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_sops' valid_dd' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' by auto next case False then obtain r where r_in: "r \<in> set sb" and volatile_r: "is_volatile_Write\<^sub>s\<^sub>b r" by (auto simp add: outstanding_refs_conv) from takeWhile_dropWhile_real_prefix [OF r_in, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)", simplified, OF volatile_r] obtain a' v' sb'' A'' L'' R'' W'' sop' where sb_split: "sb = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ Write\<^sub>s\<^sub>b True a' sop' v' A'' L'' R'' W''# sb''" and drop: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = Write\<^sub>s\<^sub>b True a' sop' v' A'' L'' R'' W''# sb''" apply (auto) subgoal for y ys apply (case_tac y) apply auto done done from drop suspends have suspends: "suspends = Write\<^sub>s\<^sub>b True a' sop' v' A'' L'' R'' W''# sb''" by simp have "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts, m, \<S>)" by auto moreover have "Write\<^sub>s\<^sub>b True a' sop' v' A'' L'' R'' W''\<in> set sb" by (subst sb_split) auto note drop_app = dropWhile_append1 [OF this, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)", simplified] from takeWhile_append1 [where P="Not \<circ> is_volatile_Write\<^sub>s\<^sub>b", OF r_in] volatile_r have takeWhile_app: "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Ghost\<^sub>s\<^sub>b A L R W])) = (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" by simp note share_commute = share_all_until_volatile_write_append_Ghost\<^sub>s\<^sub>b' [OF False i_bound ts\<^sub>s\<^sub>b_i] from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Ghost\<^sub>s\<^sub>b A L R W]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "(ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_all_until_volatile_write_append_Ghost_commute [OF i_bound ts\<^sub>s\<^sub>b_i] ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' sb') apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' share_commute) using leq apply (simp add: ts\<^sub>s\<^sub>b') using i_bound i_bound' ts_sim ts_i is_sim \<D>' apply (clarsimp simp add: Let_def nth_list_update is_sim drop_app read_tmps_append suspends prog_instrs_append_Ghost\<^sub>s\<^sub>b instrs_append_Ghost\<^sub>s\<^sub>b hd_prog_append_Ghost\<^sub>s\<^sub>b drop "is\<^sub>s\<^sub>b" ts\<^sub>s\<^sub>b' sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<theta>\<^sub>s\<^sub>b' \<D>\<^sub>s\<^sub>b' takeWhile_app split: if_split_asm) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply ) qed qed next case (StoreBuffer i p\<^sub>s\<^sub>b "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b sb \<D>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b \<R>\<^sub>s\<^sub>b sb' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b') then obtain ts\<^sub>s\<^sub>b': "ts\<^sub>s\<^sub>b' = ts\<^sub>s\<^sub>b[i := (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, sb', \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b',\<R>\<^sub>s\<^sub>b')]" and i_bound: "i < length ts\<^sub>s\<^sub>b" and ts\<^sub>s\<^sub>b_i: "ts\<^sub>s\<^sub>b ! i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b,sb, \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)" and flush: "(m\<^sub>s\<^sub>b,sb,\<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<rightarrow>\<^sub>f (m\<^sub>s\<^sub>b',sb',\<O>\<^sub>s\<^sub>b',\<R>\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b')" by auto from sim obtain m: "m = flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b" and \<S>: "\<S> = share_all_until_volatile_write ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b" and leq: "length ts\<^sub>s\<^sub>b = length ts" and ts_sim: "\<forall>i<length ts\<^sub>s\<^sub>b. let (p, is\<^sub>s\<^sub>b, \<theta>, sb,\<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>) = ts\<^sub>s\<^sub>b ! i; suspends = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb in \<exists>is \<D>. instrs suspends @ is\<^sub>s\<^sub>b = is @ prog_instrs suspends \<and> \<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb \<noteq> {}) \<and> ts ! i = (hd_prog p suspends, is, \<theta> |` (dom \<theta> - read_tmps suspends), (), \<D>, acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b, release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) (dom \<S>\<^sub>s\<^sub>b) \<R>)" by cases blast from i_bound leq have i_bound': "i < length ts" by auto have split_sb: "sb = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb" (is "sb = ?take_sb@?drop_sb") by simp from ts_sim [rule_format, OF i_bound] ts\<^sub>s\<^sub>b_i obtain suspends "is" \<D> where suspends: "suspends = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb" and is_sim: "instrs suspends @ is\<^sub>s\<^sub>b = is @ prog_instrs suspends" and \<D>: "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb \<noteq> {})" and ts_i: "ts ! i = (hd_prog p\<^sub>s\<^sub>b suspends, is, \<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - read_tmps suspends), (),\<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by (auto simp add: Let_def) from flush_step_preserves_valid [OF i_bound ts\<^sub>s\<^sub>b_i flush valid] have valid': "valid ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') from flush obtain r where sb: "sb=r#sb'" by (cases) auto from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b sb) sb". then have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b sb') sb'" by (auto simp add: sb intro: history_consistent_hd_prog split: memref.splits option.splits) from valid_history_nth_update [OF i_bound this] have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have dist_sb': "distinct_read_tmps sb'" by (simp add: sb split: memref.splits) have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b". from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') next from read_tmps_distinct_nth_update [OF i_bound dist_sb'] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b \<inter> read_tmps sb' = {}" by (auto simp add: sb split: memref.splits) from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') qed from load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b \<inter> \<Union>(fst ` write_sops sb') = {}" by (auto simp add: sb split: memref.splits) from valid_data_dependency_nth_update [OF i_bound data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] this] have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] valid_sops_nth_update [OF i_bound] have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" by (cases r) (auto simp add: sb ts\<^sub>s\<^sub>b') have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] have "load_tmps is\<^sub>s\<^sub>b \<inter> dom \<theta>\<^sub>s\<^sub>b = {}". from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" proof - from clean_no_outstanding_volatile_Write\<^sub>s\<^sub>b [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<not> \<D>\<^sub>s\<^sub>b \<longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb' = {}" by (auto simp add: sb split: if_split_asm) from enough_flushs_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb) qed show ?thesis proof (cases r) case (Write\<^sub>s\<^sub>b volatile a sop v A L R W) from flush this have m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b' = (m\<^sub>s\<^sub>b(a := v))" by cases (auto simp add: sb) have non_volatile_owned: "\<not> volatile \<longrightarrow> a \<in> \<O>\<^sub>s\<^sub>b" proof (cases volatile) case True thus ?thesis by simp next case False with outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "a \<in> \<O>\<^sub>s\<^sub>b" by (simp add: sb Write\<^sub>s\<^sub>b) thus ?thesis by simp qed have a_unowned_by_others: "\<forall>j < length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,\<O>\<^sub>j,_) = ts\<^sub>s\<^sub>b ! j in a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j)" proof (unfold Let_def, clarify del: notI) fix j p\<^sub>j "is\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq: "i \<noteq> j" assume ts_j: "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" proof (cases volatile) case True from outstanding_volatile_writes_unowned_by_others [OF i_bound j_bound neq ts\<^sub>s\<^sub>b_i ts_j] show ?thesis by (simp add: sb Write\<^sub>s\<^sub>b True) next case False with non_volatile_owned have "a \<in> \<O>\<^sub>s\<^sub>b" by simp with ownership_distinct [OF i_bound j_bound neq ts\<^sub>s\<^sub>b_i ts_j] show ?thesis by blast qed qed from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have reads_consis: "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b sb" . { fix j fix p\<^sub>j is\<^sub>s\<^sub>b\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b!j=(p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume neq_i_j: "i\<noteq>j" have "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" proof assume "a \<in> outstanding_refs is_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" hence "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" by (simp add: outstanding_refs_is_non_volatile_Write\<^sub>s\<^sub>b_takeWhile_conv) hence "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" using outstanding_refs_append [of _ "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] by auto with non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound ts\<^sub>s\<^sub>b_j]] have "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto with a_unowned_by_others [rule_format, OF j_bound neq_i_j] ts\<^sub>s\<^sub>b_j show False by auto qed } note a_notin_others = this from a_notin_others have a_notin_others': "\<forall>j < length ts\<^sub>s\<^sub>b. i \<noteq> j \<longrightarrow> (let (_,_,_,sb\<^sub>j,_,_,_) = ts\<^sub>s\<^sub>b!j in a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j))" by (fastforce simp add: Let_def) obtain D f where sop: "sop=(D,f)" by (cases sop) auto from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] sop sb Write\<^sub>s\<^sub>b obtain D_tmps: "D \<subseteq> dom \<theta>\<^sub>s\<^sub>b" and f_v: "f \<theta>\<^sub>s\<^sub>b = v" and D_sb': "D \<inter> read_tmps sb' = {}" by auto let ?\<theta> = "(\<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - read_tmps sb'))" from D_tmps D_sb' have D_tmps': "D \<subseteq> dom ?\<theta>" by auto from valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i, rule_format, of sop] have "valid_sop sop" by (auto simp add: sb Write\<^sub>s\<^sub>b) from this [simplified sop] interpret valid_sop "(D,f)" . from D_tmps D_sb' have "((dom \<theta>\<^sub>s\<^sub>b - read_tmps sb') \<inter> D) = D" by blast with valid_sop [OF refl D_tmps] valid_sop [OF refl D_tmps'] f_v have f_v': "f ?\<theta> = v" by auto have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . then have causal': "causal_program_history is\<^sub>s\<^sub>b sb'" by (simp add: sb Write\<^sub>s\<^sub>b causal_program_history_def) from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". hence "last_prog p\<^sub>s\<^sub>b sb' = p\<^sub>s\<^sub>b" by (simp add: sb Write\<^sub>s\<^sub>b) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed show ?thesis proof (cases volatile) case True note volatile = this from flush Write\<^sub>s\<^sub>b volatile obtain \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b \<union> A - R" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'= \<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b' = Map.empty" by cases (auto simp add: sb) from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] obtain A_shared_owned: "A \<subseteq> dom \<S>\<^sub>s\<^sub>b \<union> \<O>\<^sub>s\<^sub>b" and L_subset: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owned: "R \<subseteq> \<O>\<^sub>s\<^sub>b" by (clarsimp simp add: sb Write\<^sub>s\<^sub>b volatile) from sb Write\<^sub>s\<^sub>b True have take_empty: "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = []" by (auto simp add: outstanding_refs_conv) from sb Write\<^sub>s\<^sub>b True have suspend_all: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = sb" by (auto simp add: outstanding_refs_conv) hence suspends_all: "suspends = sb" by (simp add: suspends) from is_sim have is_sim: "Write True a (D, f) A L R W# instrs sb' @ is\<^sub>s\<^sub>b = is @ prog_instrs sb'" by (simp add: True Write\<^sub>s\<^sub>b suspends_all sb sop) from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] interpret causal_program_history "is\<^sub>s\<^sub>b" sb . from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have last_prog: "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". from causal_program_history [of "[Write\<^sub>s\<^sub>b True a (D, f) v A L R W]" sb'] is_sim obtain is' where "is": "is = Write True a (D, f) A L R W# is'" and is'_sim: "instrs sb'@is\<^sub>s\<^sub>b = is' @ prog_instrs sb'" by (auto simp add: sb Write\<^sub>s\<^sub>b volatile sop) from causal_program_history have causal_program_history_sb': "causal_program_history is\<^sub>s\<^sub>b sb'" apply - apply (rule causal_program_history.intro) apply (auto simp add: sb Write\<^sub>s\<^sub>b) done from ts_i have ts_i: "ts ! i = (hd_prog p\<^sub>s\<^sub>b sb', Write True a (D, f) A L R W# is', ?\<theta>, (), \<D>,acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by (simp add: suspends_all sb Write\<^sub>s\<^sub>b "is") let ?ts' = "ts[i := (hd_prog p\<^sub>s\<^sub>b sb', is', ?\<theta>, (), True, acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R, Map.empty)]" from i_bound' have ts'_i: "?ts'!i = (hd_prog p\<^sub>s\<^sub>b sb', is', ?\<theta>, (),True, acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)" by simp from no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have a_not_ro: "a \<notin> read_only \<S>\<^sub>s\<^sub>b" by (clarsimp simp add: sb Write\<^sub>s\<^sub>b volatile) { fix j fix p\<^sub>j is\<^sub>s\<^sub>b\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b!j=(p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume neq_i_j: "i\<noteq>j" have "a \<notin> unforwarded_non_volatile_reads (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) {}" proof let ?take_sb\<^sub>j = "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" let ?drop_sb\<^sub>j = "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" assume a_in: "a \<in> unforwarded_non_volatile_reads ?drop_sb\<^sub>j {}" from a_unowned_by_others [rule_format, OF j_bound neq_i_j] ts\<^sub>s\<^sub>b_j obtain a_unowned: "a \<notin> \<O>\<^sub>j" and a_unacq: "a \<notin> all_acquired sb\<^sub>j" by auto with all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b [of sb\<^sub>j \<O>\<^sub>j] have a_unacq_take: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" by (auto simp add: ) note nvo_j = outstanding_non_volatile_refs_owned_or_read_only [OF j_bound ts\<^sub>s\<^sub>b_j] from non_volatile_owned_or_read_only_drop [OF nvo_j] have nvo_drop_j: "non_volatile_owned_or_read_only True (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" . note consis_j = sharing_consis [OF j_bound ts\<^sub>s\<^sub>b_j] with sharing_consistent_append [of \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j ?drop_sb\<^sub>j] obtain consis_take_j: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j ?take_sb\<^sub>j" and consis_drop_j: "sharing_consistent (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by auto from in_unforwarded_non_volatile_reads_non_volatile_Read\<^sub>s\<^sub>b [OF a_in] have a_in': "a \<in> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j". note reads_consis_j = valid_reads [OF j_bound ts\<^sub>s\<^sub>b_j] from reads_consistent_drop [OF this] have reads_consis_drop_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) (flush ?take_sb\<^sub>j m\<^sub>s\<^sub>b) ?drop_sb\<^sub>j". from read_only_share_all_shared [of a ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b] a_not_ro all_shared_acquired_or_owned [OF consis_take_j] all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] a_unowned a_unacq have a_not_ro_j: "a \<notin> read_only (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b)" by auto from ts_sim [rule_format, OF j_bound] ts\<^sub>s\<^sub>b_j j_bound obtain suspends\<^sub>j "is\<^sub>j" \<D>\<^sub>j \<R>\<^sub>j where suspends\<^sub>j: "suspends\<^sub>j = ?drop_sb\<^sub>j" and is\<^sub>j: "instrs suspends\<^sub>j @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j @ prog_instrs suspends\<^sub>j" and \<D>\<^sub>j: "\<D>\<^sub>s\<^sub>b\<^sub>j = (\<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<noteq> {})" and ts\<^sub>j: "ts!j = (hd_prog p\<^sub>j suspends\<^sub>j, is\<^sub>j, \<theta>\<^sub>j |` (dom \<theta>\<^sub>j - read_tmps suspends\<^sub>j),(), \<D>\<^sub>j, acquired True ?take_sb\<^sub>j \<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp: Let_def) from valid_last_prog [OF j_bound ts\<^sub>s\<^sub>b_j] have last_prog: "last_prog p\<^sub>j sb\<^sub>j = p\<^sub>j". from j_bound i_bound' leq have j_bound_ts': "j < length ts" by simp from read_only_read_acquired_unforwarded_acquire_witness [OF nvo_drop_j consis_drop_j a_not_ro_j a_unacq_take a_in] have False proof assume "\<exists>sop a' v ys zs A L R W. ?drop_sb\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop v A L R W # zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys \<and> a'\<noteq>a" with suspends\<^sub>j obtain a' sop' v' ys zs' A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs'" (is "suspends\<^sub>j=?suspends") and a_A': "a \<in> A'" and no_write: "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b (ys @ [Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'])" by (auto simp add: outstanding_refs_append) from last_prog have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from sharing_consis [OF j_bound ts\<^sub>s\<^sub>b_j] have sharing_consis_j: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". then have A'_R': "A' \<inter> R' = {}" by (simp add: sharing_consistent_append [of _ _ ?take_sb\<^sub>j ?drop_sb\<^sub>j, simplified] suspends\<^sub>j [symmetric] split_suspends\<^sub>j sharing_consistent_append) from valid_program_history [OF j_bound ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from valid_reads [OF j_bound ts\<^sub>s\<^sub>b_j] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']" and sb'="zs'", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts\<^sub>j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="\<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs' @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs'" and steps_ys: "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts[j:=(last_prog (hd_prog p\<^sub>j (Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# zs')) (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']), is\<^sub>j', \<theta>\<^sub>j |` (dom \<theta>\<^sub>j - read_tmps zs'), (), True, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) m, share (ys@[Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W']) \<S>)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append outstanding_refs_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j ts_i have ts_ys_i: "?ts_ys!i = (hd_prog p\<^sub>s\<^sub>b sb', Write True a (D, f) A L R W# is', ?\<theta>, (), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = steps_ys from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have safe: "safe_delayed (?ts_ys,?m_ys,?shared_ys)". with safe_delayedE [OF safe i_bound_ys ts_ys_i] have a_unowned: "\<forall>j < length ?ts_ys. i\<noteq>j \<longrightarrow> (let (\<O>\<^sub>j) = map owned ?ts_ys!j in a \<notin> \<O>\<^sub>j)" apply cases apply (auto simp add: Let_def sb) done from a_A' a_unowned [rule_format, of j] neq_i_j j_bound leq A'_R' show False by (auto simp add: Let_def) next assume "\<exists>A L R W ys zs. ?drop_sb\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A L R W# zs \<and> a \<in> A \<and> a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b ys" with suspends\<^sub>j obtain ys zs' A' L' R' W' where split_suspends\<^sub>j: "suspends\<^sub>j = ys @ Ghost\<^sub>s\<^sub>b A' L' R' W'# zs'" (is "suspends\<^sub>j=?suspends") and a_A': "a \<in> A'" and no_write: "a \<notin> outstanding_refs is_Write\<^sub>s\<^sub>b (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W'])" by (auto simp add: outstanding_refs_append) from last_prog have lp: "last_prog p\<^sub>j suspends\<^sub>j = p\<^sub>j" apply - apply (rule last_prog_same_append [where sb="?take_sb\<^sub>j"]) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from valid_program_history [OF j_bound ts\<^sub>s\<^sub>b_j] have "causal_program_history is\<^sub>s\<^sub>b\<^sub>j sb\<^sub>j". then have cph: "causal_program_history is\<^sub>s\<^sub>b\<^sub>j ?suspends" apply - apply (rule causal_program_history_suffix [where sb="?take_sb\<^sub>j"] ) apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp add: split_suspends\<^sub>j) done from valid_reads [OF j_bound ts\<^sub>s\<^sub>b_j] have reads_consis_j: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j". from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> j_bound ts\<^sub>s\<^sub>b_j this] have reads_consis_m_j: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m suspends\<^sub>j" by (simp add: m suspends\<^sub>j) hence reads_consis_ys: "reads_consistent True (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) m (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W'])" by (simp add: split_suspends\<^sub>j reads_consistent_append) from valid_write_sops [OF j_bound ts\<^sub>s\<^sub>b_j] have "\<forall>sop\<in>write_sops (?take_sb\<^sub>j@?suspends). valid_sop sop" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain valid_sops_take: "\<forall>sop\<in>write_sops ?take_sb\<^sub>j. valid_sop sop" and valid_sops_drop: "\<forall>sop\<in>write_sops (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']). valid_sop sop" apply (simp only: write_sops_append) apply auto done from read_tmps_distinct [OF j_bound ts\<^sub>s\<^sub>b_j] have "distinct_read_tmps (?take_sb\<^sub>j@suspends\<^sub>j)" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) then obtain read_tmps_take_drop: "read_tmps ?take_sb\<^sub>j \<inter> read_tmps suspends\<^sub>j = {}" and distinct_read_tmps_drop: "distinct_read_tmps suspends\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply (simp only: distinct_read_tmps_append) done from valid_history [OF j_bound ts\<^sub>s\<^sub>b_j] have h_consis: "history_consistent \<theta>\<^sub>j (hd_prog p\<^sub>j (?take_sb\<^sub>j@suspends\<^sub>j)) (?take_sb\<^sub>j@suspends\<^sub>j)" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) apply simp done from sharing_consis [OF j_bound ts\<^sub>s\<^sub>b_j] have sharing_consis_j: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". then have A'_R': "A' \<inter> R' = {}" by (simp add: sharing_consistent_append [of _ _ ?take_sb\<^sub>j ?drop_sb\<^sub>j, simplified] suspends\<^sub>j [symmetric] split_suspends\<^sub>j sharing_consistent_append) have last_prog_hd_prog: "last_prog (hd_prog p\<^sub>j sb\<^sub>j) ?take_sb\<^sub>j = (hd_prog p\<^sub>j suspends\<^sub>j)" proof - from last_prog have "last_prog p\<^sub>j (?take_sb\<^sub>j@?drop_sb\<^sub>j) = p\<^sub>j" by simp from last_prog_hd_prog_append' [OF h_consis] this have "last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j = hd_prog p\<^sub>j suspends\<^sub>j" by (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) moreover have "last_prog (hd_prog p\<^sub>j (?take_sb\<^sub>j @ suspends\<^sub>j)) ?take_sb\<^sub>j = last_prog (hd_prog p\<^sub>j suspends\<^sub>j) ?take_sb\<^sub>j" apply (simp only: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) by (rule last_prog_hd_prog_append) ultimately show ?thesis by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) qed from history_consistent_appendD [OF valid_sops_take read_tmps_take_drop h_consis] last_prog_hd_prog have hist_consis': "history_consistent \<theta>\<^sub>j (hd_prog p\<^sub>j suspends\<^sub>j) suspends\<^sub>j" by (simp add: split_suspends\<^sub>j [symmetric] suspends\<^sub>j) from reads_consistent_drop_volatile_writes_no_volatile_reads [OF reads_consis_j] have no_vol_read: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) = {}" by (auto simp add: outstanding_refs_append suspends\<^sub>j [symmetric] split_suspends\<^sub>j ) have acq_simp: "acquired True (ys @ [Ghost\<^sub>s\<^sub>b A' L' R' W']) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) = acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R'" by (simp add: acquired_append) from flush_store_buffer_append [where sb="ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']" and sb'="zs'", simplified, OF j_bound_ts' is\<^sub>j [simplified split_suspends\<^sub>j] cph [simplified suspends\<^sub>j] ts\<^sub>j [simplified split_suspends\<^sub>j] refl lp [simplified split_suspends\<^sub>j] reads_consis_ys hist_consis' [simplified split_suspends\<^sub>j] valid_sops_drop distinct_read_tmps_drop [simplified split_suspends\<^sub>j] no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_vol_read], where \<S>="\<S>"] obtain is\<^sub>j' \<R>\<^sub>j' where is\<^sub>j': "instrs zs' @ is\<^sub>s\<^sub>b\<^sub>j = is\<^sub>j' @ prog_instrs zs'" and steps_ys: "(ts, m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts[j:=(last_prog (hd_prog p\<^sub>j (Ghost\<^sub>s\<^sub>b A' L' R' W'# zs')) (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']), is\<^sub>j', \<theta>\<^sub>j |` (dom \<theta>\<^sub>j - read_tmps zs'), (), \<D>\<^sub>j \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b ys \<noteq> {}, acquired True ys (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) \<union> A' - R',\<R>\<^sub>j')], flush (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) m, share (ys@[Ghost\<^sub>s\<^sub>b A' L' R' W']) \<S>)" (is "(_,_,_) \<Rightarrow>\<^sub>d\<^sup>* (?ts_ys,?m_ys,?shared_ys)") by (auto simp add: acquired_append outstanding_refs_append) from i_bound' have i_bound_ys: "i < length ?ts_ys" by auto from i_bound' neq_i_j ts_i have ts_ys_i: "?ts_ys!i = (hd_prog p\<^sub>s\<^sub>b sb', Write True a (D, f) A L R W# is', ?\<theta>, (), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by simp note conflict_computation = steps_ys from safe_reach_safe_rtrancl [OF safe_reach conflict_computation] have safe: "safe_delayed (?ts_ys,?m_ys,?shared_ys)". with safe_delayedE [OF safe i_bound_ys ts_ys_i] have a_unowned: "\<forall>j < length ?ts_ys. i\<noteq>j \<longrightarrow> (let (\<O>\<^sub>j) = map owned ?ts_ys!j in a \<notin> \<O>\<^sub>j)" apply cases apply (auto simp add: Let_def sb) done from a_A' a_unowned [rule_format, of j] neq_i_j j_bound leq A'_R' show False by (auto simp add: Let_def) qed then show False by simp qed } note a_notin_unforwarded_non_volatile_reads_drop = this have valid_reads': "valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix j p\<^sub>j "is\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b' sb\<^sub>j" proof (cases "i=j") case True from reads_consis ts_j j_bound sb show ?thesis by (clarsimp simp add: True m\<^sub>s\<^sub>b' Write\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' volatile reads_consistent_pending_write_antimono) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') moreover from ts_j False have ts_j': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" using j_bound by (simp add: ts\<^sub>s\<^sub>b') ultimately have consis_m: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j" by (rule valid_reads) from a_unowned_by_others [rule_format, OF j_bound' False] ts_j' have a_unowned:"a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by simp let ?take_sb\<^sub>j = "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" let ?drop_sb\<^sub>j = "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" from a_unowned acquired_reads_all_acquired [of True ?take_sb\<^sub>j \<O>\<^sub>j] all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have a_not_acq_reads: "a \<notin> acquired_reads True ?take_sb\<^sub>j \<O>\<^sub>j" by auto moreover note a_unfw= a_notin_unforwarded_non_volatile_reads_drop [OF j_bound' ts_j' False] ultimately show ?thesis using reads_consistent_mem_eq_on_unforwarded_non_volatile_reads_drop [where W="{}" and A="unforwarded_non_volatile_reads ?drop_sb\<^sub>j {} \<union> acquired_reads True ?take_sb\<^sub>j \<O>\<^sub>j" and m'= "(m\<^sub>s\<^sub>b(a:=v))", OF _ _ _ consis_m] by (fastforce simp add: m\<^sub>s\<^sub>b') qed qed have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof fix j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j p\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume ts\<^sub>s\<^sub>b'_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b' \<O>\<^sub>j sb\<^sub>j" proof (cases "j=i") case True from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) (\<O>\<^sub>s\<^sub>b \<union> A - R) sb'" by (auto simp add: sb Write\<^sub>s\<^sub>b volatile non_volatile_owned_or_read_only_pending_write_antimono) then show ?thesis using True i_bound ts\<^sub>s\<^sub>b'_j by (auto simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' sb \<O>\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') with ts\<^sub>s\<^sub>b'_j False i_bound have ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') note nvo = outstanding_non_volatile_refs_owned_or_read_only [OF j_bound' ts\<^sub>s\<^sub>b_j] from read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] R_owned have "R \<inter> read_only \<S>\<^sub>s\<^sub>b = {}" by auto with read_only_reads_unowned [OF j_bound' i_bound False ts\<^sub>s\<^sub>b_j ts\<^sub>s\<^sub>b_i] L_subset have "\<forall>a\<in>read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j). a \<in> read_only \<S>\<^sub>s\<^sub>b \<longrightarrow> a \<in> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (auto simp add: in_read_only_convs sb Write\<^sub>s\<^sub>b volatile) from non_volatile_owned_or_read_only_read_only_reads_eq' [OF nvo this] have "non_volatile_owned_or_read_only False (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<O>\<^sub>j sb\<^sub>j". thus ?thesis by (simp add: \<S>\<^sub>s\<^sub>b') qed qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix i\<^sub>1 j p\<^sub>1 "is\<^sub>1" \<O>\<^sub>1 \<R>\<^sub>1 \<D>\<^sub>1 xs\<^sub>1 sb\<^sub>1 p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume i\<^sub>1_bound: "i\<^sub>1 < length ts\<^sub>s\<^sub>b'" assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume i\<^sub>1_j: "i\<^sub>1 \<noteq> j" assume ts_i\<^sub>1: "ts\<^sub>s\<^sub>b'!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j, xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" proof (cases "i\<^sub>1=i") case True from i\<^sub>1_j True have neq_i_j: "i\<noteq>j" by auto from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j neq_i_j have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from outstanding_volatile_writes_unowned_by_others [OF i_bound j_bound' neq_i_j ts\<^sub>s\<^sub>b_i ts_j'] ts_i\<^sub>1 i_bound ts\<^sub>s\<^sub>b_i True show ?thesis by (clarsimp simp add: ts\<^sub>s\<^sub>b' sb Write\<^sub>s\<^sub>b volatile) next case False note i\<^sub>1_i = this from i\<^sub>1_bound have i\<^sub>1_bound': "i\<^sub>1 < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b' sb) hence i\<^sub>1_bound'': "i\<^sub>1 < length (map owned ts\<^sub>s\<^sub>b)" by auto from ts_i\<^sub>1 False have ts_i\<^sub>1': "ts\<^sub>s\<^sub>b!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" by (simp add: ts\<^sub>s\<^sub>b' sb) show ?thesis proof (cases "j=i") case True from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' i_bound i\<^sub>1_i ts_i\<^sub>1' ts\<^sub>s\<^sub>b_i ] have "(\<O>\<^sub>s\<^sub>b \<union> all_acquired sb) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}". then show ?thesis using True i\<^sub>1_i ts_j ts\<^sub>s\<^sub>b_i i_bound by (auto simp add: sb Write\<^sub>s\<^sub>b volatile ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j False have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' j_bound' i\<^sub>1_j ts_i\<^sub>1' ts_j'] show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" . qed qed qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof fix n m fix p\<^sub>n "is\<^sub>n" \<O>\<^sub>n \<R>\<^sub>n \<D>\<^sub>n \<theta>\<^sub>n sb\<^sub>n p\<^sub>m "is\<^sub>m" \<O>\<^sub>m \<R>\<^sub>m \<D>\<^sub>m \<theta>\<^sub>m sb\<^sub>m assume n_bound: "n < length ts\<^sub>s\<^sub>b'" and m_bound: "m < length ts\<^sub>s\<^sub>b'" and neq_n_m: "n\<noteq>m" and nth: "ts\<^sub>s\<^sub>b'!n = (p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" and mth: "ts\<^sub>s\<^sub>b'!m =(p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" from n_bound have n_bound': "n < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from m_bound have m_bound': "m < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') show "(\<O>\<^sub>m \<union> all_acquired sb\<^sub>m) \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<O>\<^sub>n) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) = {}" proof (cases "m=i") case True with neq_n_m have neq_n_i: "n\<noteq>i" by auto with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') note read_only_reads_unowned [OF n_bound' i_bound neq_n_i nth' ts\<^sub>s\<^sub>b_i] then show ?thesis using True ts\<^sub>s\<^sub>b_i neq_n_i nth mth n_bound' m_bound' L_subset by (auto simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb Write\<^sub>s\<^sub>b volatile) next case False note neq_m_i = this with m_bound mth i_bound have mth': "ts\<^sub>s\<^sub>b!m = (p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" by (auto simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "n=i") case True from read_only_reads_append [of "(\<O>\<^sub>s\<^sub>b \<union> A - R)" "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n)"] have "read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) (\<O>\<^sub>s\<^sub>b \<union> A - R)) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<subseteq> read_only_reads (\<O>\<^sub>s\<^sub>b \<union> A - R) sb\<^sub>n" by auto with ts\<^sub>s\<^sub>b_i nth mth neq_m_i n_bound' True read_only_reads_unowned [OF i_bound m_bound' False [symmetric] ts\<^sub>s\<^sub>b_i mth'] show ?thesis by (auto simp add: ts\<^sub>s\<^sub>b' sb \<O>\<^sub>s\<^sub>b' Write\<^sub>s\<^sub>b volatile) next case False with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_reads_unowned [OF n_bound' m_bound' neq_n_m nth' mth'] False neq_m_i show ?thesis by (clarsimp) qed qed qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix i\<^sub>1 j p\<^sub>1 "is\<^sub>1" \<O>\<^sub>1 \<R>\<^sub>1 \<D>\<^sub>1 xs\<^sub>1 sb\<^sub>1 p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume i\<^sub>1_bound: "i\<^sub>1 < length ts\<^sub>s\<^sub>b'" assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume i\<^sub>1_j: "i\<^sub>1 \<noteq> j" assume ts_i\<^sub>1: "ts\<^sub>s\<^sub>b'!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "(\<O>\<^sub>1 \<union> all_acquired sb\<^sub>1) \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j)= {}" proof (cases "i\<^sub>1=i") case True with i\<^sub>1_j have i_j: "i\<noteq>j" by simp from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') hence j_bound'': "j < length (map owned ts\<^sub>s\<^sub>b)" by simp from ts_j i_j have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from ownership_distinct [OF i_bound j_bound' i_j ts\<^sub>s\<^sub>b_i ts_j'] show ?thesis using ts\<^sub>s\<^sub>b_i True ts_i\<^sub>1 i_bound \<O>\<^sub>s\<^sub>b' by (auto simp add: ts\<^sub>s\<^sub>b' sb Write\<^sub>s\<^sub>b volatile) next case False note i\<^sub>1_i = this from i\<^sub>1_bound have i\<^sub>1_bound': "i\<^sub>1 < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') hence i\<^sub>1_bound'': "i\<^sub>1 < length (map owned ts\<^sub>s\<^sub>b)" by simp from ts_i\<^sub>1 False have ts_i\<^sub>1': "ts\<^sub>s\<^sub>b!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" by (simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "j=i") case True from ownership_distinct [OF i\<^sub>1_bound' i_bound i\<^sub>1_i ts_i\<^sub>1' ts\<^sub>s\<^sub>b_i] show ?thesis using ts\<^sub>s\<^sub>b_i True ts_j i_bound \<O>\<^sub>s\<^sub>b' by (auto simp add: ts\<^sub>s\<^sub>b' sb Write\<^sub>s\<^sub>b volatile) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j False have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from ownership_distinct [OF i\<^sub>1_bound' j_bound' i\<^sub>1_j ts_i\<^sub>1' ts_j'] show ?thesis . qed qed qed qed have valid_sharing': "valid_sharing (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_writes_unshared (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "non_volatile_writes_unshared (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) sb\<^sub>j" proof (cases "i=j") case True with outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] i_bound jth ts\<^sub>s\<^sub>b_i show ?thesis by (clarsimp simp add: ts\<^sub>s\<^sub>b' sb Write\<^sub>s\<^sub>b volatile) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') from jth False have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from outstanding_non_volatile_writes_unshared [OF j_bound' jth'] have unshared: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb\<^sub>j". have "\<forall>a\<in>dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) - dom \<S>\<^sub>s\<^sub>b. a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" proof - { fix a assume a_in: "a \<in> dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) - dom \<S>\<^sub>s\<^sub>b" hence a_R: "a \<in> R" by clarsimp assume a_in_j: "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" have False proof - from non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound' jth']] a_in_j have "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto moreover with ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] a_R R_owned show False by blast qed } thus ?thesis by blast qed from non_volatile_writes_unshared_no_outstanding_non_volatile_Write\<^sub>s\<^sub>b [OF unshared this] show ?thesis . qed qed next show "sharing_consis (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "sharing_consistent (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<O>\<^sub>j sb\<^sub>j" proof (cases "i=j") case True with i_bound jth ts\<^sub>s\<^sub>b_i sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] show ?thesis by (clarsimp simp add: ts\<^sub>s\<^sub>b' sb Write\<^sub>s\<^sub>b volatile \<O>\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') from jth False have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from sharing_consis [OF j_bound' jth'] have consis: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". have acq_cond: "all_acquired sb\<^sub>j \<inter> dom \<S>\<^sub>s\<^sub>b - dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" proof - { fix a assume a_acq: "a \<in> all_acquired sb\<^sub>j" assume "a \<in> dom \<S>\<^sub>s\<^sub>b" assume a_L: "a \<in> L" have False proof - from ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] have "A \<inter> all_acquired sb\<^sub>j = {}" by (auto simp add: sb Write\<^sub>s\<^sub>b volatile) with a_acq a_L L_subset show False by blast qed } thus ?thesis by auto qed have uns_cond: "all_unshared sb\<^sub>j \<inter> dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) - dom \<S>\<^sub>s\<^sub>b = {}" proof - { fix a assume a_uns: "a \<in> all_unshared sb\<^sub>j" assume "a \<notin> L" assume a_R: "a \<in> R" have False proof - from unshared_acquired_or_owned [OF consis] a_uns have "a \<in> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j" by auto with ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] R_owned a_R show False by blast qed } thus ?thesis by auto qed from sharing_consistent_preservation [OF consis acq_cond uns_cond] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed qed next show "read_only_unowned (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "\<O>\<^sub>j \<inter> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" proof (cases "i=j") case True from read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] R_owned A_R have "(\<O>\<^sub>s\<^sub>b \<union> A - R) \<inter> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs ) with jth ts\<^sub>s\<^sub>b_i i_bound True show ?thesis by (auto simp add: \<O>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') with False jth have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_unowned [OF j_bound' jth'] have "\<O>\<^sub>j \<inter> read_only \<S>\<^sub>s\<^sub>b = {}". moreover from ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] R_owned have "(\<O>\<^sub>s\<^sub>b \<union> A) \<inter> \<O>\<^sub>j = {}" by (auto simp add: sb Write\<^sub>s\<^sub>b volatile) moreover note R_owned A_R ultimately show ?thesis by (fastforce simp add: in_read_only_convs split: if_split_asm) qed qed next show "unowned_shared (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (unfold_locales) show "- \<Union>((\<lambda>(_,_, _, _,_, \<O>,_). \<O>) ` set ts\<^sub>s\<^sub>b') \<subseteq> dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" proof - have s: "\<Union>((\<lambda>(_,_, _, _,_, \<O>,_). \<O>) ` set ts\<^sub>s\<^sub>b') = \<Union>((\<lambda>(_,_, _, _,_, \<O>,_). \<O>) ` set ts\<^sub>s\<^sub>b) \<union> A - R" apply (unfold ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') apply (rule acquire_release_ownership_nth_update [OF R_owned i_bound ts\<^sub>s\<^sub>b_i]) apply (rule local.ownership_distinct_axioms) done note unowned_shared L_subset A_R then show ?thesis apply (simp only: s) apply auto done qed qed next show "no_outstanding_write_to_read_only_memory (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "no_write_to_read_only_memory (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) sb\<^sub>j" proof (cases "i=j") case True with jth ts\<^sub>s\<^sub>b_i i_bound no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] show ?thesis by (auto simp add: sb ts\<^sub>s\<^sub>b' Write\<^sub>s\<^sub>b volatile) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') with False jth have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from no_outstanding_write_to_read_only_memory [OF j_bound' jth'] have nw: "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b sb\<^sub>j". have "R \<inter> outstanding_refs is_Write\<^sub>s\<^sub>b sb\<^sub>j = {}" proof - note dist = ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] from non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound' jth']] dist have "outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<inter> \<O>\<^sub>s\<^sub>b = {}" by auto moreover from outstanding_volatile_writes_unowned_by_others [OF j_bound' i_bound False [symmetric] jth' ts\<^sub>s\<^sub>b_i ] have "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<inter> \<O>\<^sub>s\<^sub>b = {}" by auto ultimately have "outstanding_refs is_Write\<^sub>s\<^sub>b sb\<^sub>j \<inter> \<O>\<^sub>s\<^sub>b = {}" by (auto simp add: misc_outstanding_refs_convs) with R_owned show ?thesis by blast qed then have "\<forall>a\<in>outstanding_refs is_Write\<^sub>s\<^sub>b sb\<^sub>j. a \<in> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<longrightarrow> a \<in> read_only \<S>\<^sub>s\<^sub>b" by (auto simp add: in_read_only_convs) from no_write_to_read_only_memory_read_only_reads_eq [OF nw this] show ?thesis . qed qed qed from direct_memop_step.WriteVolatile [OF] have "(Write True a (D, f) A L R W# is', ?\<theta>, (), m,\<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b,\<S>) \<rightarrow> (is', ?\<theta>, (), m (a := v),True, acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R, Map.empty,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (simp add: f_v' [symmetric]) from direct_computation.Memop [OF i_bound' ts_i this] have store_step: "(ts, m, \<S>) \<Rightarrow>\<^sub>d (?ts', m(a := v),\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". have sb'_split: "sb' = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb' @ dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb'" by simp from reads_consis have no_vol_reads: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b sb' = {}" by (simp add: sb Write\<^sub>s\<^sub>b True) hence "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = {}" by (auto simp add: outstanding_refs_conv dest: set_takeWhileD) moreover have "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = {}" proof - have "\<forall>r \<in> set (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb'). \<not> (is_volatile_Write\<^sub>s\<^sub>b r)" by (auto dest: set_takeWhileD) thus ?thesis by (simp add: outstanding_refs_conv) qed ultimately have no_volatile: "outstanding_refs is_volatile (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = {}" by (auto simp add: outstanding_refs_conv is_volatile_split) moreover from no_vol_reads have "\<forall>r \<in> set sb'. \<not> is_volatile_Read\<^sub>s\<^sub>b r" by (fastforce simp add: outstanding_refs_conv is_volatile_Read\<^sub>s\<^sub>b_def split: memref.splits) hence "\<forall>r \<in> set sb'. (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) r = (Not \<circ> is_volatile) r" by (auto simp add: is_volatile_split) hence takeWhile_eq: "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = (takeWhile (Not \<circ> is_volatile) sb')" apply - apply (rule takeWhile_cong) apply auto done from leq have leq': "length ts\<^sub>s\<^sub>b = length ?ts'" by simp hence i_bound_ts': "i < length ?ts'" using i_bound by simp from is'_sim have is'_sim_split: "instrs (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb' @ dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') @ is\<^sub>s\<^sub>b = is' @ prog_instrs (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb' @ dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" by (simp add: sb'_split [symmetric]) from reads_consistent_flush_all_until_volatile_write [OF \<open>valid_ownership_and_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> i_bound ts\<^sub>s\<^sub>b_i reads_consis] have "reads_consistent True (acquired True ?take_sb \<O>\<^sub>s\<^sub>b) m (Write\<^sub>s\<^sub>b True a (D,f) v A L R W#sb')" by (simp add: m sb Write\<^sub>s\<^sub>b volatile) hence "reads_consistent True (acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R) (m(a:=v)) sb'" by simp from reads_consistent_takeWhile [OF this] have r_consis': "reads_consistent True (acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R) (m(a:=v)) (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')". from last_prog have last_prog_sb': "last_prog p\<^sub>s\<^sub>b sb' = p\<^sub>s\<^sub>b" by (simp add: sb Write\<^sub>s\<^sub>b ) from valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<forall>sop \<in> write_sops sb'. valid_sop sop" by (auto simp add: sb Write\<^sub>s\<^sub>b) hence valid_sop': "\<forall>sop\<in>write_sops (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb'). valid_sop sop" by (fastforce dest: set_takeWhileD simp add: in_write_sops_conv) from no_volatile have no_volatile_Read\<^sub>s\<^sub>b: "outstanding_refs is_volatile_Read\<^sub>s\<^sub>b (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = {}" by (auto simp add: outstanding_refs_conv is_volatile_Read\<^sub>s\<^sub>b_def split: memref.splits) from flush_store_buffer_append [OF i_bound_ts' is'_sim_split, simplified, OF causal_program_history_sb' ts'_i refl last_prog_sb' r_consis' hist_consis' valid_sop' dist_sb' no_volatile_Read\<^sub>s\<^sub>b_volatile_reads_consistent [OF no_volatile_Read\<^sub>s\<^sub>b], where \<S>="(\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)"] obtain is'' where is''_sim: "instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') @ is\<^sub>s\<^sub>b = is'' @ prog_instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" and steps: "(?ts', m(a := v), \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<Rightarrow>\<^sub>d\<^sup>* (ts[i := (last_prog (hd_prog p\<^sub>s\<^sub>b (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')) (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb'), is'', \<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - read_tmps (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')), (), True, acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R), release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (dom (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)) Map.empty)], flush (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (m(a := v)), share (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" by (auto) note sim_flush = r_rtranclp_rtranclp [OF store_step steps] moreover note flush_commute = flush_flush_all_until_volatile_write_Write\<^sub>s\<^sub>b_volatile_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified sb Write\<^sub>s\<^sub>b True] outstanding_refs_is_Write\<^sub>s\<^sub>b_takeWhile_disj a_notin_others'] from last_prog_hd_prog_append' [where sb="(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" and sb'="(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')", simplified sb'_split [symmetric], OF hist_consis' last_prog_sb'] have last_prog_eq: "last_prog (hd_prog p\<^sub>s\<^sub>b (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')) (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') = hd_prog p\<^sub>s\<^sub>b (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')". have take_emtpy: "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (r#sb) = []" by (simp add: Write\<^sub>s\<^sub>b True) have dist_sb': "\<forall>i p is \<O> \<R> \<D> \<theta> sb. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b ! i = (p, is, \<theta>, sb, \<D>, \<O>, \<R>) \<longrightarrow> (all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<union> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<union> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)) \<inter> (all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<union> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<union> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')) = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j, \<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_shared: "x \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<union> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<union> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_sb': "x \<in> (all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<union> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<union> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb'))" have False proof (cases "i=j") case True with x_shared ts\<^sub>s\<^sub>b_i jth show False by (simp add: sb volatile Write\<^sub>s\<^sub>b) next case False from x_shared all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] unshared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] all_unshared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] all_acquired_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] have "x \<in> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j " by auto moreover from x_sb' all_shared_acquired_or_owned [OF sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i]] unshared_acquired_or_owned [OF sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i]] all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')"] all_unshared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')"] all_acquired_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')"] have "x \<in> all_acquired sb \<union> \<O>\<^sub>s\<^sub>b" by (auto simp add: sb Write\<^sub>s\<^sub>b volatile) moreover note ownership_distinct [OF i_bound j_bound False ts\<^sub>s\<^sub>b_i jth] ultimately show False by blast qed } thus ?thesis by blast qed have dist_R_L_A: "\<forall>j p is \<O> \<R> \<D> \<theta> sb. j < length ts\<^sub>s\<^sub>b \<longrightarrow> i\<noteq> j\<longrightarrow> ts\<^sub>s\<^sub>b ! j = (p, is, \<theta>, sb, \<D>, \<O>, \<R>) \<longrightarrow> (all_shared sb \<union> all_unshared sb \<union> all_acquired sb) \<inter> (R \<union> L \<union> A) = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j, \<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_shared: "x \<in> all_shared sb\<^sub>j \<union> all_unshared sb\<^sub>j \<union> all_acquired sb\<^sub>j" assume x_R_L_A: "x \<in> R \<union> L \<union> A" have False proof - from x_shared all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] unshared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] have "x \<in> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j " by auto moreover from x_R_L_A R_owned L_subset have "x \<in> all_acquired sb \<union> \<O>\<^sub>s\<^sub>b" by (auto simp add: sb Write\<^sub>s\<^sub>b volatile) moreover note ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] ultimately show False by blast qed } thus ?thesis by blast qed from local.ownership_distinct_axioms have "ownership_distinct ts\<^sub>s\<^sub>b" . from local.sharing_consis_axioms have "sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b". note share_commute= share_all_until_volatile_write_flush_commute [OF take_empty \<open>ownership_distinct ts\<^sub>s\<^sub>b\<close> \<open>sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> i_bound ts\<^sub>s\<^sub>b_i dist_sb' dist_R_L_A] have rel_commute_empty: "release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (dom \<S> \<union> R - L) Map.empty = release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (dom \<S>\<^sub>s\<^sub>b \<union> R - L) Map.empty" proof - { fix a assume a_in: "a \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" have "(a \<in> (dom \<S> \<union> R - L)) = (a \<in> (dom \<S>\<^sub>s\<^sub>b \<union> R - L))" proof - from all_shared_acquired_or_owned [OF sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i]] a_in all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')"] have "a \<in> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb " by (auto simp add: sb Write\<^sub>s\<^sub>b volatile) from share_all_until_volatile_write_thread_local [OF \<open>ownership_distinct ts\<^sub>s\<^sub>b\<close> \<open>sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> i_bound ts\<^sub>s\<^sub>b_i this] have "\<S> a = \<S>\<^sub>s\<^sub>b a" by (auto simp add: sb Write\<^sub>s\<^sub>b volatile \<S>) then show ?thesis by (auto simp add: domIff) qed } then show ?thesis apply - apply (rule release_all_shared_exchange) apply auto done qed { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq: "i \<noteq> j" have "release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) (dom \<S>\<^sub>s\<^sub>b \<union> R - L) \<R>\<^sub>j = release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j" proof - { fix a assume a_in: "a \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" have "(a \<in> (dom \<S>\<^sub>s\<^sub>b \<union> R - L)) = (a \<in> dom \<S>\<^sub>s\<^sub>b)" proof - from ownership_distinct [OF i_bound j_bound neq ts\<^sub>s\<^sub>b_i jth] have A_dist: "A \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {}" by (auto simp add: sb Write\<^sub>s\<^sub>b volatile) from all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] a_in all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] have a_in: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto with ownership_distinct [OF i_bound j_bound neq ts\<^sub>s\<^sub>b_i jth] have "a \<notin> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb)" by auto with A_dist R_owned A_R A_shared_owned L_subset a_in obtain "a \<notin> R" and "a \<notin> L" by fastforce then show ?thesis by auto qed } then show ?thesis apply - apply (rule release_all_shared_exchange) apply auto done qed } note release_commute = this have "(ts\<^sub>s\<^sub>b [i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, sb', \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b \<union> A - R,Map.empty)],m\<^sub>s\<^sub>b(a:=v),\<S>\<^sub>s\<^sub>b') \<sim> (ts[i := (last_prog (hd_prog p\<^sub>s\<^sub>b (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')) (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb'), is'', \<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - read_tmps (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')), (),True, acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (acquired True ?take_sb \<O>\<^sub>s\<^sub>b \<union> A - R), release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (dom (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)) Map.empty)], flush (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (m(a := v)), share (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') (\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L))" apply (rule sim_config.intros) apply (simp add: flush_commute m) apply (clarsimp simp add: \<S>\<^sub>s\<^sub>b' \<S> share_commute simp del: restrict_restrict) using leq apply simp using i_bound i_bound' ts_sim \<D> apply (clarsimp simp add: Let_def nth_list_update is''_sim last_prog_eq sb Write\<^sub>s\<^sub>b volatile \<S>\<^sub>s\<^sub>b' rel_commute_empty split: if_split_asm ) apply (rule conjI) apply blast apply clarsimp apply (frule (2) release_commute) apply clarsimp apply fastforce done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply simp add: \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' ) next case False note non_vol = this from flush Write\<^sub>s\<^sub>b False obtain \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b' = \<R>\<^sub>s\<^sub>b" by cases (auto simp add: sb) from non_volatile_owned non_vol have a_owned: "a \<in> \<O>\<^sub>s\<^sub>b" by simp { fix j fix p\<^sub>j is\<^sub>s\<^sub>b\<^sub>j \<O>\<^sub>j \<D>\<^sub>s\<^sub>b\<^sub>j \<theta>\<^sub>j \<R>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b!j=(p\<^sub>j,is\<^sub>s\<^sub>b\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>s\<^sub>b\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume neq_i_j: "i\<noteq>j" have "a \<notin> unforwarded_non_volatile_reads (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) {}" proof let ?take_sb\<^sub>j = "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" let ?drop_sb\<^sub>j = "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" assume a_in: "a \<in> unforwarded_non_volatile_reads ?drop_sb\<^sub>j {}" from a_unowned_by_others [rule_format, OF j_bound neq_i_j] ts\<^sub>s\<^sub>b_j obtain a_unowned: "a \<notin> \<O>\<^sub>j" and a_unacq: "a \<notin> all_acquired sb\<^sub>j" by auto with all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] acquired_takeWhile_non_volatile_Write\<^sub>s\<^sub>b [of sb\<^sub>j \<O>\<^sub>j] have a_unacq_take: "a \<notin> acquired True ?take_sb\<^sub>j \<O>\<^sub>j" by (auto ) note nvo_j = outstanding_non_volatile_refs_owned_or_read_only [OF j_bound ts\<^sub>s\<^sub>b_j] from non_volatile_owned_or_read_only_drop [OF nvo_j] have nvo_drop_j: "non_volatile_owned_or_read_only True (share ?take_sb\<^sub>j \<S>\<^sub>s\<^sub>b) (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" . from in_unforwarded_non_volatile_reads_non_volatile_Read\<^sub>s\<^sub>b [OF a_in] have a_in': "a \<in> outstanding_refs is_non_volatile_Read\<^sub>s\<^sub>b ?drop_sb\<^sub>j". from non_volatile_owned_or_read_only_outstanding_refs [OF nvo_drop_j] a_in' have "a \<in> acquired True ?take_sb\<^sub>j \<O>\<^sub>j \<union> all_acquired ?drop_sb\<^sub>j \<union> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" by (auto simp add: misc_outstanding_refs_convs) moreover from acquired_append [of True ?take_sb\<^sub>j ?drop_sb\<^sub>j \<O>\<^sub>j] acquired_all_acquired [of True ?take_sb\<^sub>j \<O>\<^sub>j] all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have "acquired True ?take_sb\<^sub>j \<O>\<^sub>j \<union> all_acquired ?drop_sb\<^sub>j \<subseteq> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto ultimately have "a \<in> read_only_reads (acquired True ?take_sb\<^sub>j \<O>\<^sub>j) ?drop_sb\<^sub>j" using a_owned ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i ts\<^sub>s\<^sub>b_j] by auto with read_only_reads_unowned [OF j_bound i_bound neq_i_j [symmetric] ts\<^sub>s\<^sub>b_j ts\<^sub>s\<^sub>b_i] a_owned show False by auto qed } note a_notin_unforwarded_non_volatile_reads_drop = this (* FIXME: the same proof as in volatile, case. depends on a_notin_unforwarded_non_volatile_reads_drop *) have valid_reads': "valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix j p\<^sub>j "is\<^sub>j" \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b' sb\<^sub>j" proof (cases "i=j") case True from reads_consis ts_j j_bound sb show ?thesis by (clarsimp simp add: True m\<^sub>s\<^sub>b' Write\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' False reads_consistent_pending_write_antimono) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') moreover from ts_j False have ts_j': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" using j_bound by (simp add: ts\<^sub>s\<^sub>b') ultimately have consis_m: "reads_consistent False \<O>\<^sub>j m\<^sub>s\<^sub>b sb\<^sub>j" by (rule valid_reads) from a_unowned_by_others [rule_format, OF j_bound' False] ts_j' have a_unowned:"a \<notin> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by simp let ?take_sb\<^sub>j = "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" let ?drop_sb\<^sub>j = "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j" from a_unowned acquired_reads_all_acquired [of True ?take_sb\<^sub>j \<O>\<^sub>j] all_acquired_append [of ?take_sb\<^sub>j ?drop_sb\<^sub>j] have a_not_acq_reads: "a \<notin> acquired_reads True ?take_sb\<^sub>j \<O>\<^sub>j" by auto moreover note a_unfw= a_notin_unforwarded_non_volatile_reads_drop [OF j_bound' ts_j' False] ultimately show ?thesis using reads_consistent_mem_eq_on_unforwarded_non_volatile_reads_drop [where W="{}" and A="unforwarded_non_volatile_reads ?drop_sb\<^sub>j {} \<union> acquired_reads True ?take_sb\<^sub>j \<O>\<^sub>j" and m'= "(m\<^sub>s\<^sub>b(a:=v))", OF _ _ _ consis_m] by (fastforce simp add: m\<^sub>s\<^sub>b') qed qed have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] sb have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb'" by (auto simp add: Write\<^sub>s\<^sub>b False) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' Write\<^sub>s\<^sub>b False \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof - from sb have out: "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb' \<subseteq> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb" by (auto simp add: Write\<^sub>s\<^sub>b False) have acq: "all_acquired sb' \<subseteq> all_acquired sb" by (auto simp add: Write\<^sub>s\<^sub>b False sb) from outstanding_volatile_writes_unowned_by_others_store_buffer [OF i_bound ts\<^sub>s\<^sub>b_i out acq] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' Write\<^sub>s\<^sub>b False \<O>\<^sub>s\<^sub>b') qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof - have ro: "read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<subseteq> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" by (auto simp add: sb Write\<^sub>s\<^sub>b non_vol) have "\<O>\<^sub>s\<^sub>b \<union> all_acquired sb' \<subseteq> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by (auto simp add: sb Write\<^sub>s\<^sub>b non_vol) from read_only_reads_unowned_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i ro this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb \<O>\<^sub>s\<^sub>b') qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof - have acq: "all_acquired sb' \<subseteq> all_acquired sb" by (auto simp add: Write\<^sub>s\<^sub>b False sb) with ownership_distinct_instructions_read_value_store_buffer_independent [OF i_bound ts\<^sub>s\<^sub>b_i] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' Write\<^sub>s\<^sub>b False \<O>\<^sub>s\<^sub>b') qed qed have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb'" by (auto simp add: sb Write\<^sub>s\<^sub>b False) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb'" by (auto simp add: sb Write\<^sub>s\<^sub>b False) from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from read_only_unowned_nth_update [OF i_bound read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] ] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b sb'" by (auto simp add: sb Write\<^sub>s\<^sub>b False) from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound this] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb) qed from is_sim obtain is_sim: "instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') @ is\<^sub>s\<^sub>b = is @ prog_instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" by (simp add: suspends sb Write\<^sub>s\<^sub>b False) have "(ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts,m,\<S>)" by blast moreover note flush_commute = flush_all_until_volatile_write_Write\<^sub>s\<^sub>b_non_volatile_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified sb Write\<^sub>s\<^sub>b non_vol] outstanding_refs_is_Write\<^sub>s\<^sub>b_takeWhile_disj a_notin_others'] note share_commute = share_all_until_volatile_write_update_sb [of sb' sb, OF _ i_bound ts\<^sub>s\<^sub>b_i, simplified sb Write\<^sub>s\<^sub>b False, simplified] have "(ts\<^sub>s\<^sub>b [i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b,\<theta>\<^sub>s\<^sub>b, sb', \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)], m\<^sub>s\<^sub>b(a:=v),\<S>\<^sub>s\<^sub>b') \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute) apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' share_commute) using leq apply simp using i_bound i_bound' is_sim ts_i ts_sim \<D> apply (clarsimp simp add: Let_def nth_list_update suspends sb Write\<^sub>s\<^sub>b False \<S>\<^sub>s\<^sub>b' split: if_split_asm ) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' m\<^sub>s\<^sub>b' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_program_history' valid' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply) qed next case (Read\<^sub>s\<^sub>b volatile a t v) from flush this obtain m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b'=m\<^sub>s\<^sub>b" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=\<R>\<^sub>s\<^sub>b" by cases (auto simp add: sb) have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] sb have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb'" by (auto simp add: Read\<^sub>s\<^sub>b) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' Read\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof - from sb have out: "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb' \<subseteq> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb" by (auto simp add: Read\<^sub>s\<^sub>b) have acq: "all_acquired sb' \<subseteq> all_acquired sb" by (auto simp add: Read\<^sub>s\<^sub>b sb) from outstanding_volatile_writes_unowned_by_others_store_buffer [OF i_bound ts\<^sub>s\<^sub>b_i out acq] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' Read\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b') qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof - have ro: "read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<subseteq> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" by (auto simp add: sb Read\<^sub>s\<^sub>b) have "\<O>\<^sub>s\<^sub>b \<union> all_acquired sb' \<subseteq> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by (auto simp add: sb Read\<^sub>s\<^sub>b) from read_only_reads_unowned_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i ro this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb \<O>\<^sub>s\<^sub>b') qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof - have acq: "all_acquired sb' \<subseteq> all_acquired sb" by (auto simp add: Read\<^sub>s\<^sub>b sb) with ownership_distinct_instructions_read_value_store_buffer_independent [OF i_bound ts\<^sub>s\<^sub>b_i] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' Read\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b') qed qed have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb'" by (auto simp add: sb Read\<^sub>s\<^sub>b) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb'" by (auto simp add: sb Read\<^sub>s\<^sub>b) from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from read_only_unowned_nth_update [OF i_bound read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] ] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b sb'" by (auto simp add: sb Read\<^sub>s\<^sub>b) from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound this] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb) qed have valid_reads': "valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b sb'" by (simp add: sb Read\<^sub>s\<^sub>b) from valid_reads_nth_update [OF i_bound this] show ?thesis by (simp add: m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') qed have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . then have causal': "causal_program_history is\<^sub>s\<^sub>b sb'" by (simp add: sb Read\<^sub>s\<^sub>b causal_program_history_def) from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". hence "last_prog p\<^sub>s\<^sub>b sb' = p\<^sub>s\<^sub>b" by (simp add: sb Read\<^sub>s\<^sub>b) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed from is_sim have is_sim: "instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') @ is\<^sub>s\<^sub>b = is @ prog_instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" by (simp add: sb Read\<^sub>s\<^sub>b suspends) from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have \<theta>\<^sub>s\<^sub>b_v: "\<theta>\<^sub>s\<^sub>b t = Some v" by (simp add: history_consistent_access_last_read sb Read\<^sub>s\<^sub>b split:option.splits) have "(ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts,m,\<S>)" by blast moreover note flush_commute= flush_all_until_volatile_write_Read\<^sub>s\<^sub>b_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified sb Read\<^sub>s\<^sub>b]] note share_commute = share_all_until_volatile_write_update_sb [of sb' sb, OF _ i_bound ts\<^sub>s\<^sub>b_i, simplified sb Read\<^sub>s\<^sub>b, simplified] have "(ts\<^sub>s\<^sub>b [i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, sb',\<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b')],m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute) apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' share_commute) using leq apply simp using i_bound i_bound' ts_sim ts_i is_sim \<D> apply (clarsimp simp add: Let_def nth_list_update sb suspends Read\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' split: if_split_asm) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' m\<^sub>s\<^sub>b' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_sharing' valid_program_history' valid' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply) next case (Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis) from flush this obtain m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b'=m\<^sub>s\<^sub>b" and \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'=\<R>\<^sub>s\<^sub>b" by cases (auto simp add: sb) have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] sb have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb'" by (auto simp add: Prog\<^sub>s\<^sub>b) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' Prog\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof - from sb have out: "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb' \<subseteq> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb" by (auto simp add: Prog\<^sub>s\<^sub>b) have acq: "all_acquired sb' \<subseteq> all_acquired sb" by (auto simp add: Prog\<^sub>s\<^sub>b sb) from outstanding_volatile_writes_unowned_by_others_store_buffer [OF i_bound ts\<^sub>s\<^sub>b_i out acq] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' Prog\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b') qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof - have ro: "read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') \<subseteq> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" by (auto simp add: sb Prog\<^sub>s\<^sub>b) have "\<O>\<^sub>s\<^sub>b \<union> all_acquired sb' \<subseteq> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by (auto simp add: sb Prog\<^sub>s\<^sub>b) from read_only_reads_unowned_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i ro this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' sb \<O>\<^sub>s\<^sub>b') qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof - have acq: "all_acquired sb' \<subseteq> all_acquired sb" by (auto simp add: Prog\<^sub>s\<^sub>b sb) with ownership_distinct_instructions_read_value_store_buffer_independent [OF i_bound ts\<^sub>s\<^sub>b_i] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' Prog\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b') qed qed have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb'" by (auto simp add: sb Prog\<^sub>s\<^sub>b) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b sb'" by (auto simp add: sb Prog\<^sub>s\<^sub>b) from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from read_only_unowned_nth_update [OF i_bound read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] ] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b sb'" by (auto simp add: sb Prog\<^sub>s\<^sub>b) from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound this] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' sb) qed have valid_reads': "valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b sb'" by (simp add: sb Prog\<^sub>s\<^sub>b) from valid_reads_nth_update [OF i_bound this] show ?thesis by (simp add: m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') qed have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . then have causal': "causal_program_history is\<^sub>s\<^sub>b sb'" by (simp add: sb Prog\<^sub>s\<^sub>b causal_program_history_def) from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". hence "last_prog p\<^sub>2 sb' = p\<^sub>s\<^sub>b" by (simp add: sb Prog\<^sub>s\<^sub>b) from last_prog_to_last_prog_same [OF this] have "last_prog p\<^sub>s\<^sub>b sb' = p\<^sub>s\<^sub>b". from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed from is_sim have is_sim: "instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') @ is\<^sub>s\<^sub>b = is @ prog_instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" by (simp add: suspends sb Prog\<^sub>s\<^sub>b) have "(ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts,m,\<S>)" by blast moreover note flush_commute = flush_all_until_volatile_write_Prog\<^sub>s\<^sub>b_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified sb Prog\<^sub>s\<^sub>b]] note share_commute = share_all_until_volatile_write_update_sb [of sb' sb, OF _ i_bound ts\<^sub>s\<^sub>b_i, simplified sb Prog\<^sub>s\<^sub>b, simplified] have "(ts\<^sub>s\<^sub>b [i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, sb',\<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)],m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute) apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' share_commute) using leq apply simp using i_bound i_bound' ts_sim ts_i is_sim \<D> apply (clarsimp simp add: Let_def nth_list_update sb suspends Prog\<^sub>s\<^sub>b \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' split: if_split_asm) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' m\<^sub>s\<^sub>b' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_sharing' valid_program_history' valid' ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply) next case (Ghost\<^sub>s\<^sub>b A L R W) from flush Ghost\<^sub>s\<^sub>b obtain \<O>\<^sub>s\<^sub>b': "\<O>\<^sub>s\<^sub>b'=\<O>\<^sub>s\<^sub>b \<union> A - R" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L" and \<R>\<^sub>s\<^sub>b': "\<R>\<^sub>s\<^sub>b'= augment_rels (dom \<S>\<^sub>s\<^sub>b) R \<R>\<^sub>s\<^sub>b" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b'=m\<^sub>s\<^sub>b" by cases (auto simp add: sb) from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] obtain A_shared_owned: "A \<subseteq> dom \<S>\<^sub>s\<^sub>b \<union> \<O>\<^sub>s\<^sub>b" and L_subset: "L \<subseteq> A" and A_R: "A \<inter> R = {}" and R_owned: "R \<subseteq> \<O>\<^sub>s\<^sub>b" by (clarsimp simp add: sb Ghost\<^sub>s\<^sub>b) have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof fix j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j \<theta>\<^sub>j sb\<^sub>j p\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume ts\<^sub>s\<^sub>b'_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b' \<O>\<^sub>j sb\<^sub>j" proof (cases "j=i") case True from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) (\<O>\<^sub>s\<^sub>b \<union> A - R) sb'" by (auto simp add: sb Ghost\<^sub>s\<^sub>b non_volatile_owned_or_read_only_pending_write_antimono) then show ?thesis using True i_bound ts\<^sub>s\<^sub>b'_j by (auto simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' sb \<O>\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') with ts\<^sub>s\<^sub>b'_j False i_bound have ts\<^sub>s\<^sub>b_j: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') note nvo = outstanding_non_volatile_refs_owned_or_read_only [OF j_bound' ts\<^sub>s\<^sub>b_j] from read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] R_owned have "R \<inter> read_only \<S>\<^sub>s\<^sub>b = {}" by auto with read_only_reads_unowned [OF j_bound' i_bound False ts\<^sub>s\<^sub>b_j ts\<^sub>s\<^sub>b_i] L_subset have "\<forall>a\<in>read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<O>\<^sub>j) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j). a \<in> read_only \<S>\<^sub>s\<^sub>b \<longrightarrow> a \<in> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L )" by (auto simp add: in_read_only_convs sb Ghost\<^sub>s\<^sub>b) from non_volatile_owned_or_read_only_read_only_reads_eq' [OF nvo this] have "non_volatile_owned_or_read_only False (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<O>\<^sub>j sb\<^sub>j". thus ?thesis by (simp add: \<S>\<^sub>s\<^sub>b') qed qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix i\<^sub>1 j p\<^sub>1 "is\<^sub>1" \<O>\<^sub>1 \<R>\<^sub>1 \<D>\<^sub>1 xs\<^sub>1 sb\<^sub>1 p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume i\<^sub>1_bound: "i\<^sub>1 < length ts\<^sub>s\<^sub>b'" assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume i\<^sub>1_j: "i\<^sub>1 \<noteq> j" assume ts_i\<^sub>1: "ts\<^sub>s\<^sub>b'!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" proof (cases "i\<^sub>1=i") case True from i\<^sub>1_j True have neq_i_j: "i\<noteq>j" by auto from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j neq_i_j have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from outstanding_volatile_writes_unowned_by_others [OF i_bound j_bound' neq_i_j ts\<^sub>s\<^sub>b_i ts_j'] ts_i\<^sub>1 i_bound ts\<^sub>s\<^sub>b_i True show ?thesis by (clarsimp simp add: ts\<^sub>s\<^sub>b' sb Ghost\<^sub>s\<^sub>b) next case False note i\<^sub>1_i = this from i\<^sub>1_bound have i\<^sub>1_bound': "i\<^sub>1 < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b' sb) hence i\<^sub>1_bound'': "i\<^sub>1 < length (map owned ts\<^sub>s\<^sub>b)" by auto from ts_i\<^sub>1 False have ts_i\<^sub>1': "ts\<^sub>s\<^sub>b!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" by (simp add: ts\<^sub>s\<^sub>b' sb) show ?thesis proof (cases "j=i") case True from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' i_bound i\<^sub>1_i ts_i\<^sub>1' ts\<^sub>s\<^sub>b_i ] have "(\<O>\<^sub>s\<^sub>b \<union> all_acquired sb) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}". then show ?thesis using True i\<^sub>1_i ts_j ts\<^sub>s\<^sub>b_i i_bound by (auto simp add: sb Ghost\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j False have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from outstanding_volatile_writes_unowned_by_others [OF i\<^sub>1_bound' j_bound' i\<^sub>1_j ts_i\<^sub>1' ts_j'] show "(\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) \<inter> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>1 = {}" . qed qed qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof fix n m fix p\<^sub>n "is\<^sub>n" \<O>\<^sub>n \<R>\<^sub>n \<D>\<^sub>n \<theta>\<^sub>n sb\<^sub>n p\<^sub>m "is\<^sub>m" \<O>\<^sub>m \<R>\<^sub>m \<D>\<^sub>m \<theta>\<^sub>m sb\<^sub>m assume n_bound: "n < length ts\<^sub>s\<^sub>b'" and m_bound: "m < length ts\<^sub>s\<^sub>b'" and neq_n_m: "n\<noteq>m" and nth: "ts\<^sub>s\<^sub>b'!n = (p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" and mth: "ts\<^sub>s\<^sub>b'!m =(p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" from n_bound have n_bound': "n < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from m_bound have m_bound': "m < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') show "(\<O>\<^sub>m \<union> all_acquired sb\<^sub>m) \<inter> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<O>\<^sub>n) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) = {}" proof (cases "m=i") case True with neq_n_m have neq_n_i: "n\<noteq>i" by auto with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') note read_only_reads_unowned [OF n_bound' i_bound neq_n_i nth' ts\<^sub>s\<^sub>b_i] then show ?thesis using True ts\<^sub>s\<^sub>b_i neq_n_i nth mth n_bound' m_bound' L_subset by (auto simp add: ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b' sb Ghost\<^sub>s\<^sub>b) next case False note neq_m_i = this with m_bound mth i_bound have mth': "ts\<^sub>s\<^sub>b!m = (p\<^sub>m, is\<^sub>m, \<theta>\<^sub>m, sb\<^sub>m, \<D>\<^sub>m, \<O>\<^sub>m,\<R>\<^sub>m)" by (auto simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "n=i") case True from read_only_reads_append [of "(\<O>\<^sub>s\<^sub>b \<union> A - R)" "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n)"] have "read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) (\<O>\<^sub>s\<^sub>b \<union> A - R)) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>n) \<subseteq> read_only_reads (\<O>\<^sub>s\<^sub>b \<union> A - R) sb\<^sub>n" by auto with ts\<^sub>s\<^sub>b_i nth mth neq_m_i n_bound' True read_only_reads_unowned [OF i_bound m_bound' False [symmetric] ts\<^sub>s\<^sub>b_i mth'] show ?thesis by (auto simp add: ts\<^sub>s\<^sub>b' sb \<O>\<^sub>s\<^sub>b' Ghost\<^sub>s\<^sub>b) next case False with n_bound nth i_bound have nth': "ts\<^sub>s\<^sub>b!n =(p\<^sub>n, is\<^sub>n, \<theta>\<^sub>n, sb\<^sub>n, \<D>\<^sub>n, \<O>\<^sub>n,\<R>\<^sub>n)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_reads_unowned [OF n_bound' m_bound' neq_n_m nth' mth'] False neq_m_i show ?thesis by (clarsimp) qed qed qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix i\<^sub>1 j p\<^sub>1 "is\<^sub>1" \<O>\<^sub>1 \<R>\<^sub>1 \<D>\<^sub>1 xs\<^sub>1 sb\<^sub>1 p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume i\<^sub>1_bound: "i\<^sub>1 < length ts\<^sub>s\<^sub>b'" assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume i\<^sub>1_j: "i\<^sub>1 \<noteq> j" assume ts_i\<^sub>1: "ts\<^sub>s\<^sub>b'!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" assume ts_j: "ts\<^sub>s\<^sub>b'!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "(\<O>\<^sub>1 \<union> all_acquired sb\<^sub>1) \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j)= {}" proof (cases "i\<^sub>1=i") case True with i\<^sub>1_j have i_j: "i\<noteq>j" by simp from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') hence j_bound'': "j < length (map owned ts\<^sub>s\<^sub>b)" by simp from ts_j i_j have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from ownership_distinct [OF i_bound j_bound' i_j ts\<^sub>s\<^sub>b_i ts_j'] show ?thesis using ts\<^sub>s\<^sub>b_i True ts_i\<^sub>1 i_bound \<O>\<^sub>s\<^sub>b' by (auto simp add: ts\<^sub>s\<^sub>b' sb Ghost\<^sub>s\<^sub>b) next case False note i\<^sub>1_i = this from i\<^sub>1_bound have i\<^sub>1_bound': "i\<^sub>1 < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') hence i\<^sub>1_bound'': "i\<^sub>1 < length (map owned ts\<^sub>s\<^sub>b)" by simp from ts_i\<^sub>1 False have ts_i\<^sub>1': "ts\<^sub>s\<^sub>b!i\<^sub>1 = (p\<^sub>1,is\<^sub>1,xs\<^sub>1,sb\<^sub>1,\<D>\<^sub>1,\<O>\<^sub>1,\<R>\<^sub>1)" by (simp add: ts\<^sub>s\<^sub>b') show ?thesis proof (cases "j=i") case True from ownership_distinct [OF i\<^sub>1_bound' i_bound i\<^sub>1_i ts_i\<^sub>1' ts\<^sub>s\<^sub>b_i] show ?thesis using ts\<^sub>s\<^sub>b_i True ts_j i_bound \<O>\<^sub>s\<^sub>b' by (auto simp add: ts\<^sub>s\<^sub>b' sb Ghost\<^sub>s\<^sub>b) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (simp add: ts\<^sub>s\<^sub>b') from ts_j False have ts_j': "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (simp add: ts\<^sub>s\<^sub>b') from ownership_distinct [OF i\<^sub>1_bound' j_bound' i\<^sub>1_j ts_i\<^sub>1' ts_j'] show ?thesis . qed qed qed qed have valid_sharing': "valid_sharing (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_writes_unshared (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "non_volatile_writes_unshared (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) sb\<^sub>j" proof (cases "i=j") case True with outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] i_bound jth ts\<^sub>s\<^sub>b_i show ?thesis by (clarsimp simp add: ts\<^sub>s\<^sub>b' sb Ghost\<^sub>s\<^sub>b) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') from jth False have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from j_bound jth i_bound False have j: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb\<^sub>j" apply - apply (rule outstanding_non_volatile_writes_unshared) apply (auto simp add: ts\<^sub>s\<^sub>b') done from jth False have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from outstanding_non_volatile_writes_unshared [OF j_bound' jth'] have unshared: "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b sb\<^sub>j". have "\<forall>a\<in>dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) - dom \<S>\<^sub>s\<^sub>b. a \<notin> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" proof - { fix a assume a_in: "a \<in> dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) - dom \<S>\<^sub>s\<^sub>b" hence a_R: "a \<in> R" by clarsimp assume a_in_j: "a \<in> outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j" have False proof - from non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound' jth']] a_in_j have "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto moreover with ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] a_R R_owned show False by blast qed } thus ?thesis by blast qed from non_volatile_writes_unshared_no_outstanding_non_volatile_Write\<^sub>s\<^sub>b [OF unshared this] show ?thesis . qed qed next show "sharing_consis (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (unfold_locales) fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j acq\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "sharing_consistent (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<O>\<^sub>j sb\<^sub>j" proof (cases "i=j") case True with i_bound jth ts\<^sub>s\<^sub>b_i sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] show ?thesis by (clarsimp simp add: ts\<^sub>s\<^sub>b' sb Ghost\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') from jth False have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from sharing_consis [OF j_bound' jth'] have consis: "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>j sb\<^sub>j". have acq_cond: "all_acquired sb\<^sub>j \<inter> dom \<S>\<^sub>s\<^sub>b - dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" proof - { fix a assume a_acq: "a \<in> all_acquired sb\<^sub>j" assume "a \<in> dom \<S>\<^sub>s\<^sub>b" assume a_L: "a \<in> L" have False proof - from ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] have "A \<inter> all_acquired sb\<^sub>j = {}" by (auto simp add: sb Ghost\<^sub>s\<^sub>b) with a_acq a_L L_subset show False by blast qed } thus ?thesis by auto qed have uns_cond: "all_unshared sb\<^sub>j \<inter> dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) - dom \<S>\<^sub>s\<^sub>b = {}" proof - { fix a assume a_uns: "a \<in> all_unshared sb\<^sub>j" assume "a \<notin> L" assume a_R: "a \<in> R" have False proof - from unshared_acquired_or_owned [OF consis] a_uns have "a \<in> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j" by auto with ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] R_owned a_R show False by blast qed } thus ?thesis by auto qed from sharing_consistent_preservation [OF consis acq_cond uns_cond] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed qed next show "unowned_shared (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof (unfold_locales) show "- \<Union>((\<lambda>(_,_, _, _,_, \<O>,_). \<O>) ` set ts\<^sub>s\<^sub>b') \<subseteq> dom (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" proof - have s: "\<Union>((\<lambda>(_,_, _, _,_, \<O>,_). \<O>) ` set ts\<^sub>s\<^sub>b') = \<Union>((\<lambda>(_,_, _, _,_, \<O>,_). \<O>) ` set ts\<^sub>s\<^sub>b) \<union> A - R" apply (unfold ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') apply (rule acquire_release_ownership_nth_update [OF R_owned i_bound ts\<^sub>s\<^sub>b_i]) apply (rule local.ownership_distinct_axioms) done note unowned_shared L_subset A_R then show ?thesis apply (simp only: s) apply auto done qed qed next show "read_only_unowned (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "\<O>\<^sub>j \<inter> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" proof (cases "i=j") case True from read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] have "(\<O>\<^sub>s\<^sub>b \<union> A - R ) \<inter> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) = {}" by (auto simp add: in_read_only_convs ) with jth ts\<^sub>s\<^sub>b_i i_bound True show ?thesis by (auto simp add: \<O>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b') next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') with False jth have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from read_only_unowned [OF j_bound' jth'] have "\<O>\<^sub>j \<inter> read_only \<S>\<^sub>s\<^sub>b = {}". moreover from ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] R_owned have "(\<O>\<^sub>s\<^sub>b \<union> A) \<inter> \<O>\<^sub>j = {}" by (auto simp add: sb Ghost\<^sub>s\<^sub>b) moreover note R_owned A_R ultimately show ?thesis by (fastforce simp add: in_read_only_convs split: if_split_asm) qed qed next show "no_outstanding_write_to_read_only_memory (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) ts\<^sub>s\<^sub>b'" proof fix j p\<^sub>j "is\<^sub>j" "\<O>\<^sub>j" \<R>\<^sub>j \<D>\<^sub>j xs\<^sub>j sb\<^sub>j assume j_bound: "j < length ts\<^sub>s\<^sub>b'" assume jth: "ts\<^sub>s\<^sub>b' ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" show "no_write_to_read_only_memory (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) sb\<^sub>j" proof (cases "i=j") case True with jth ts\<^sub>s\<^sub>b_i i_bound no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] show ?thesis by (auto simp add: sb ts\<^sub>s\<^sub>b' Ghost\<^sub>s\<^sub>b) next case False from j_bound have j_bound': "j < length ts\<^sub>s\<^sub>b" by (auto simp add: ts\<^sub>s\<^sub>b') with False jth have jth': "ts\<^sub>s\<^sub>b ! j = (p\<^sub>j,is\<^sub>j,xs\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" by (auto simp add: ts\<^sub>s\<^sub>b') from no_outstanding_write_to_read_only_memory [OF j_bound' jth'] have nw: "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b sb\<^sub>j". have "R \<inter> outstanding_refs is_Write\<^sub>s\<^sub>b sb\<^sub>j = {}" proof - note dist = ownership_distinct [OF i_bound j_bound' False ts\<^sub>s\<^sub>b_i jth'] from non_volatile_owned_or_read_only_outstanding_non_volatile_writes [OF outstanding_non_volatile_refs_owned_or_read_only [OF j_bound' jth']] dist have "outstanding_refs is_non_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<inter> \<O>\<^sub>s\<^sub>b = {}" by auto moreover from outstanding_volatile_writes_unowned_by_others [OF j_bound' i_bound False [symmetric] jth' ts\<^sub>s\<^sub>b_i ] have "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb\<^sub>j \<inter> \<O>\<^sub>s\<^sub>b = {}" by auto ultimately have "outstanding_refs is_Write\<^sub>s\<^sub>b sb\<^sub>j \<inter> \<O>\<^sub>s\<^sub>b = {}" by (auto simp add: misc_outstanding_refs_convs) with R_owned show ?thesis by blast qed then have "\<forall>a\<in>outstanding_refs is_Write\<^sub>s\<^sub>b sb\<^sub>j. a \<in> read_only (\<S>\<^sub>s\<^sub>b \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<longrightarrow> a \<in> read_only \<S>\<^sub>s\<^sub>b" by (auto simp add: in_read_only_convs) from no_write_to_read_only_memory_read_only_reads_eq [OF nw this] show ?thesis . qed qed qed have valid_reads': "valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have "reads_consistent False (\<O>\<^sub>s\<^sub>b \<union> A - R) m\<^sub>s\<^sub>b sb'" by (simp add: sb Ghost\<^sub>s\<^sub>b) from valid_reads_nth_update [OF i_bound this] show ?thesis by (simp add: m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<O>\<^sub>s\<^sub>b') qed have valid_program_history': "valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . then have causal': "causal_program_history is\<^sub>s\<^sub>b sb'" by (simp add: sb Ghost\<^sub>s\<^sub>b causal_program_history_def) from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". hence "last_prog p\<^sub>s\<^sub>b sb' = p\<^sub>s\<^sub>b" by (simp add: sb Ghost\<^sub>s\<^sub>b) from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed from is_sim have is_sim: "instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb') @ is\<^sub>s\<^sub>b = is @ prog_instrs (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb')" by (simp add: sb Ghost\<^sub>s\<^sub>b suspends) have "(ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts,m,\<S>)" by blast moreover note flush_commute = flush_all_until_volatile_write_Ghost\<^sub>s\<^sub>b_commute [OF i_bound ts\<^sub>s\<^sub>b_i [simplified sb Ghost\<^sub>s\<^sub>b]] have dist_R_L_A: "\<forall>j p is \<O> \<R> \<D> \<theta> sb. j < length ts\<^sub>s\<^sub>b \<longrightarrow> i\<noteq> j\<longrightarrow> ts\<^sub>s\<^sub>b ! j = (p, is, \<theta>, sb, \<D>, \<O>, \<R>) \<longrightarrow> (all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<union> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<union> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)) \<inter> (R \<union> L \<union> A) = {}" proof - { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq_i_j: "i \<noteq> j" assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j, \<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume x_shared: "x \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<union> all_unshared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) \<union> all_acquired (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" assume x_R_L_A: "x \<in> R \<union> L \<union> A" have False proof - from x_shared all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] unshared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] all_unshared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] all_acquired_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] have "x \<in> all_acquired sb\<^sub>j \<union> \<O>\<^sub>j " by auto moreover from x_R_L_A R_owned L_subset have "x \<in> all_acquired sb \<union> \<O>\<^sub>s\<^sub>b" by (auto simp add: sb Ghost\<^sub>s\<^sub>b) moreover note ownership_distinct [OF i_bound j_bound neq_i_j ts\<^sub>s\<^sub>b_i jth] ultimately show False by blast qed } thus ?thesis by blast qed { fix j p\<^sub>j is\<^sub>j \<O>\<^sub>j \<R>\<^sub>j \<D>\<^sub>j \<theta>\<^sub>j sb\<^sub>j x assume jth: "ts\<^sub>s\<^sub>b!j = (p\<^sub>j,is\<^sub>j,\<theta>\<^sub>j,sb\<^sub>j,\<D>\<^sub>j,\<O>\<^sub>j,\<R>\<^sub>j)" assume j_bound: "j < length ts\<^sub>s\<^sub>b" assume neq: "i \<noteq> j" have "release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) (dom \<S>\<^sub>s\<^sub>b \<union> R - L) \<R>\<^sub>j = release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j) (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>j" proof - { fix a assume a_in: "a \<in> all_shared (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" have "(a \<in> (dom \<S>\<^sub>s\<^sub>b \<union> R - L)) = (a \<in> dom \<S>\<^sub>s\<^sub>b)" proof - from ownership_distinct [OF i_bound j_bound neq ts\<^sub>s\<^sub>b_i jth] have A_dist: "A \<inter> (\<O>\<^sub>j \<union> all_acquired sb\<^sub>j) = {}" by (auto simp add: sb Ghost\<^sub>s\<^sub>b) from all_shared_acquired_or_owned [OF sharing_consis [OF j_bound jth]] a_in all_shared_append [of "(takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)" "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb\<^sub>j)"] have a_in: "a \<in> \<O>\<^sub>j \<union> all_acquired sb\<^sub>j" by auto with ownership_distinct [OF i_bound j_bound neq ts\<^sub>s\<^sub>b_i jth] have "a \<notin> (\<O>\<^sub>s\<^sub>b \<union> all_acquired sb)" by auto with A_dist R_owned A_R A_shared_owned L_subset a_in obtain "a \<notin> R" and "a \<notin> L" by fastforce then show ?thesis by auto qed } then show ?thesis apply - apply (rule release_all_shared_exchange) apply auto done qed } note release_commute = this from ownership_distinct_axioms have "ownership_distinct ts\<^sub>s\<^sub>b". from sharing_consis_axioms have "sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b". note share_commute = share_all_until_volatile_write_Ghost\<^sub>s\<^sub>b_commute [OF \<open>ownership_distinct ts\<^sub>s\<^sub>b\<close> \<open>sharing_consis \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> i_bound ts\<^sub>s\<^sub>b_i [simplified sb Ghost\<^sub>s\<^sub>b] dist_R_L_A] have "(ts\<^sub>s\<^sub>b [i := (p\<^sub>s\<^sub>b,is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, sb', \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b \<union> A - R,augment_rels (dom \<S>\<^sub>s\<^sub>b) R \<R>\<^sub>s\<^sub>b)],m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute) apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' share_commute) using leq apply simp using i_bound i_bound' ts_sim ts_i is_sim \<D> apply (clarsimp simp add: Let_def nth_list_update sb suspends Ghost\<^sub>s\<^sub>b \<R>\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' split: if_split_asm) apply (rule conjI) apply fastforce apply clarsimp apply (frule (2) release_commute) apply clarsimp apply auto done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_program_history' valid' m\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply simp add: \<O>\<^sub>s\<^sub>b' \<R>\<^sub>s\<^sub>b') qed next case (Program i p\<^sub>s\<^sub>b "is\<^sub>s\<^sub>b" \<theta>\<^sub>s\<^sub>b sb \<D>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b \<R>\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis) then obtain ts\<^sub>s\<^sub>b': "ts\<^sub>s\<^sub>b' = ts\<^sub>s\<^sub>b[i := (p\<^sub>s\<^sub>b', is\<^sub>s\<^sub>b@mis, \<theta>\<^sub>s\<^sub>b, sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis], \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)]" and i_bound: "i < length ts\<^sub>s\<^sub>b" and ts\<^sub>s\<^sub>b_i: "ts\<^sub>s\<^sub>b ! i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b,\<theta>\<^sub>s\<^sub>b,sb, \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)" and prog: "\<theta>\<^sub>s\<^sub>b\<turnstile> p\<^sub>s\<^sub>b \<rightarrow>\<^sub>p (p\<^sub>s\<^sub>b',mis)" and \<S>\<^sub>s\<^sub>b': "\<S>\<^sub>s\<^sub>b'=\<S>\<^sub>s\<^sub>b" and m\<^sub>s\<^sub>b': "m\<^sub>s\<^sub>b'=m\<^sub>s\<^sub>b" by auto from sim obtain m: "m = flush_all_until_volatile_write ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b" and \<S>: "\<S> = share_all_until_volatile_write ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b" and leq: "length ts\<^sub>s\<^sub>b = length ts" and ts_sim: "\<forall>i<length ts\<^sub>s\<^sub>b. let (p, is\<^sub>s\<^sub>b, \<theta>, sb, \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>) = ts\<^sub>s\<^sub>b ! i; suspends = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb in \<exists>is \<D>. instrs suspends @ is\<^sub>s\<^sub>b = is @ prog_instrs suspends \<and> \<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb \<noteq> {}) \<and> ts ! i = (hd_prog p suspends, is, \<theta> |` (dom \<theta> - read_tmps suspends), (), \<D>, acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b, release (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) (dom \<S>\<^sub>s\<^sub>b) \<R>)" by cases blast from i_bound leq have i_bound': "i < length ts" by auto have split_sb: "sb = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb" (is "sb = ?take_sb@?drop_sb") by simp from ts_sim [rule_format, OF i_bound] ts\<^sub>s\<^sub>b_i obtain suspends "is" \<D> where suspends: "suspends = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb" and is_sim: "instrs suspends @ is\<^sub>s\<^sub>b = is @ prog_instrs suspends" and \<D>: "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb \<noteq> {})" and ts_i: "ts ! i = (hd_prog p\<^sub>s\<^sub>b suspends, is, \<theta>\<^sub>s\<^sub>b |` (dom \<theta>\<^sub>s\<^sub>b - read_tmps suspends), (), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b, release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by (auto simp add: Let_def) from prog_step_preserves_valid [OF i_bound ts\<^sub>s\<^sub>b_i prog valid] have valid': "valid ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') have valid_own': "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) show "outstanding_non_volatile_refs_owned_or_read_only \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof - from outstanding_non_volatile_refs_owned_or_read_only [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_owned_or_read_only False \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])" by (auto simp add: non_volatile_owned_or_read_only_append) from outstanding_non_volatile_refs_owned_or_read_only_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') qed next show "outstanding_volatile_writes_unowned_by_others ts\<^sub>s\<^sub>b'" proof - have out: "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]) \<subseteq> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb" by (auto simp add: outstanding_refs_conv ) from outstanding_volatile_writes_unowned_by_others_store_buffer [OF i_bound ts\<^sub>s\<^sub>b_i this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' all_acquired_append) qed next show "read_only_reads_unowned ts\<^sub>s\<^sub>b'" proof - have ro: "read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])) \<subseteq> read_only_reads (acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb) \<O>\<^sub>s\<^sub>b) (dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb)" apply (case_tac "outstanding_refs (is_volatile_Write\<^sub>s\<^sub>b) sb = {}") apply (simp_all add: outstanding_vol_write_take_drop_appends acquired_append read_only_reads_append ) done have "\<O>\<^sub>s\<^sub>b \<union> all_acquired (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]) \<subseteq> \<O>\<^sub>s\<^sub>b \<union> all_acquired sb" by (auto simp add: all_acquired_append) from read_only_reads_unowned_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i ro this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' ) qed next show "ownership_distinct ts\<^sub>s\<^sub>b'" proof - from ownership_distinct_instructions_read_value_store_buffer_independent [OF i_bound ts\<^sub>s\<^sub>b_i, where sb'="(sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])"] show ?thesis by (simp add: ts\<^sub>s\<^sub>b' all_acquired_append) qed qed from valid_last_prog [OF i_bound ts\<^sub>s\<^sub>b_i] have last_prog: "last_prog p\<^sub>s\<^sub>b sb = p\<^sub>s\<^sub>b". have valid_hist': "valid_history program_step ts\<^sub>s\<^sub>b'" proof - from valid_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b sb) sb". from history_consistent_append_Prog\<^sub>s\<^sub>b [OF prog this last_prog] have hist_consis': "history_consistent \<theta>\<^sub>s\<^sub>b (hd_prog p\<^sub>s\<^sub>b' (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])) (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])". from valid_history_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed have valid_reads': "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b'" proof - from valid_reads [OF i_bound ts\<^sub>s\<^sub>b_i] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b sb" . from reads_consistent_snoc_Prog\<^sub>s\<^sub>b [OF this] have "reads_consistent False \<O>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])". from valid_reads_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed have valid_sharing': "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" proof (intro_locales) from outstanding_non_volatile_writes_unshared [OF i_bound ts\<^sub>s\<^sub>b_i] have "non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])" by (auto simp add: non_volatile_writes_unshared_append) from outstanding_non_volatile_writes_unshared_nth_update [OF i_bound this] show "outstanding_non_volatile_writes_unshared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from sharing_consis [OF i_bound ts\<^sub>s\<^sub>b_i] have "sharing_consistent \<S>\<^sub>s\<^sub>b \<O>\<^sub>s\<^sub>b (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])" by (auto simp add: sharing_consistent_append) from sharing_consis_nth_update [OF i_bound this] show "sharing_consis \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from read_only_unowned_nth_update [OF i_bound read_only_unowned [OF i_bound ts\<^sub>s\<^sub>b_i] ] show "read_only_unowned \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b') next from unowned_shared_nth_update [OF i_bound ts\<^sub>s\<^sub>b_i subset_refl] show "unowned_shared \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b') next from no_outstanding_write_to_read_only_memory [OF i_bound ts\<^sub>s\<^sub>b_i] have "no_write_to_read_only_memory \<S>\<^sub>s\<^sub>b (sb @ [Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])" by (simp add: no_write_to_read_only_memory_append) from no_outstanding_write_to_read_only_memory_nth_update [OF i_bound this] show "no_outstanding_write_to_read_only_memory \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" by (simp add: \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b') qed have tmps_distinct': "tmps_distinct ts\<^sub>s\<^sub>b'" proof (intro_locales) from load_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_load_tmps is\<^sub>s\<^sub>b". with distinct_load_tmps_prog_step [OF i_bound ts\<^sub>s\<^sub>b_i prog valid] have "distinct_load_tmps (is\<^sub>s\<^sub>b@mis)" by (auto simp add: distinct_load_tmps_append) from load_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') next from read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] have "distinct_read_tmps (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])" by (simp add: distinct_read_tmps_append) from read_tmps_distinct_nth_update [OF i_bound this] show "read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') next from load_tmps_read_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] distinct_load_tmps_prog_step [OF i_bound ts\<^sub>s\<^sub>b_i prog valid] have "load_tmps (is\<^sub>s\<^sub>b@mis) \<inter> read_tmps (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]) = {}" by (auto simp add: read_tmps_append load_tmps_append) from load_tmps_read_tmps_distinct_nth_update [OF i_bound this] show "load_tmps_read_tmps_distinct ts\<^sub>s\<^sub>b'" by (simp add: ts\<^sub>s\<^sub>b') qed have valid_dd': "valid_data_dependency ts\<^sub>s\<^sub>b'" proof - from data_dependency_consistent_instrs [OF i_bound ts\<^sub>s\<^sub>b_i] have "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b) is\<^sub>s\<^sub>b". with valid_data_dependency_prog_step [OF i_bound ts\<^sub>s\<^sub>b_i prog valid] load_tmps_write_tmps_distinct [OF i_bound ts\<^sub>s\<^sub>b_i] obtain "data_dependency_consistent_instrs (dom \<theta>\<^sub>s\<^sub>b) (is\<^sub>s\<^sub>b@mis)" "load_tmps (is\<^sub>s\<^sub>b@mis) \<inter> \<Union>(fst ` write_sops (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])) = {}" by (force simp add: load_tmps_append data_dependency_consistent_instrs_append write_sops_append) from valid_data_dependency_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed have load_tmps_fresh': "load_tmps_fresh ts\<^sub>s\<^sub>b'" proof - from load_tmps_fresh [OF i_bound ts\<^sub>s\<^sub>b_i] load_tmps_fresh_prog_step [OF i_bound ts\<^sub>s\<^sub>b_i prog valid] have "load_tmps (is\<^sub>s\<^sub>b@mis) \<inter> dom \<theta>\<^sub>s\<^sub>b = {}" by (auto simp add: load_tmps_append) from load_tmps_fresh_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed have enough_flushs': "enough_flushs ts\<^sub>s\<^sub>b'" proof - from clean_no_outstanding_volatile_Write\<^sub>s\<^sub>b [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<not> \<D>\<^sub>s\<^sub>b \<longrightarrow> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]) = {}" by (auto simp add: outstanding_refs_append) from enough_flushs_nth_update [OF i_bound this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed have valid_sops': "valid_sops ts\<^sub>s\<^sub>b'" proof - from valid_store_sops [OF i_bound ts\<^sub>s\<^sub>b_i] valid_sops_prog_step [OF prog] valid_implies_valid_prog[OF i_bound ts\<^sub>s\<^sub>b_i valid] have valid_store: "\<forall>sop\<in>store_sops (is\<^sub>s\<^sub>b@mis). valid_sop sop" by (auto simp add: store_sops_append) from valid_write_sops [OF i_bound ts\<^sub>s\<^sub>b_i] have "\<forall>sop\<in>write_sops (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]). valid_sop sop" by (auto simp add: write_sops_append) from valid_sops_nth_update [OF i_bound this valid_store] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed have valid_program_history':"valid_program_history ts\<^sub>s\<^sub>b'" proof - from valid_program_history [OF i_bound ts\<^sub>s\<^sub>b_i] have "causal_program_history is\<^sub>s\<^sub>b sb" . from causal_program_history_Prog\<^sub>s\<^sub>b [OF this] have causal': "causal_program_history (is\<^sub>s\<^sub>b@mis) (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])". from last_prog_append_Prog\<^sub>s\<^sub>b have "last_prog p\<^sub>s\<^sub>b' (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]) = p\<^sub>s\<^sub>b'". from valid_program_history_nth_update [OF i_bound causal' this] show ?thesis by (simp add: ts\<^sub>s\<^sub>b') qed show ?thesis proof (cases "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b sb = {}") case True from True have flush_all: "takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = sb" by (auto simp add: outstanding_refs_conv) from True have suspend_nothing: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = []" by (auto simp add: outstanding_refs_conv) hence suspends_empty: "suspends = []" by (simp add: suspends) from suspends_empty is_sim have "is": "is = is\<^sub>s\<^sub>b" by (simp) from ts_i have ts_i: "ts ! i = (p\<^sub>s\<^sub>b, is\<^sub>s\<^sub>b, \<theta>\<^sub>s\<^sub>b, (), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)" by (simp add: suspends_empty "is") from direct_computation.Program [OF i_bound' ts_i prog] have "(ts,m,\<S>) \<Rightarrow>\<^sub>d (ts[i := (p\<^sub>s\<^sub>b', is\<^sub>s\<^sub>b @ mis, \<theta>\<^sub>s\<^sub>b, (), \<D>, acquired True ?take_sb \<O>\<^sub>s\<^sub>b,release ?take_sb (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b)], m, \<S>)". moreover note flush_commute = flush_all_until_volatile_write_append_Prog\<^sub>s\<^sub>b_commute [OF i_bound ts\<^sub>s\<^sub>b_i] from True have suspend_nothing': "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])) = []" by (auto simp add: outstanding_refs_conv) note share_commute = share_all_until_volatile_write_update_sb [OF share_append_Prog\<^sub>s\<^sub>b i_bound ts\<^sub>s\<^sub>b_i] from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "(ts\<^sub>s\<^sub>b [i := (p\<^sub>s\<^sub>b',is\<^sub>s\<^sub>b@mis, \<theta>\<^sub>s\<^sub>b, sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis], \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)], m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts[i:=(p\<^sub>s\<^sub>b', is\<^sub>s\<^sub>b @ mis, \<theta>\<^sub>s\<^sub>b, (), \<D>, acquired True (takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])) \<O>\<^sub>s\<^sub>b, release (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]) (dom \<S>\<^sub>s\<^sub>b) \<R>\<^sub>s\<^sub>b )],m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute) apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' share_commute) using leq apply simp using i_bound i_bound' ts_sim ts_i \<D>' apply (clarsimp simp add: Let_def nth_list_update flush_all suspend_nothing' Prog\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b' release_append_Prog\<^sub>s\<^sub>b release_append split: if_split_asm) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' m\<^sub>s\<^sub>b' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_sharing' valid_program_history' valid' \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply simp add: acquired_append_Prog\<^sub>s\<^sub>b release_append_Prog\<^sub>s\<^sub>b release_append flush_all) next case False then obtain r where r_in: "r \<in> set sb" and volatile_r: "is_volatile_Write\<^sub>s\<^sub>b r" by (auto simp add: outstanding_refs_conv) from takeWhile_dropWhile_real_prefix [OF r_in, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)", simplified, OF volatile_r] obtain a' v' sb'' sop' A' L' R' W' where sb_split: "sb = takeWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" and drop: "dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb = Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" apply (auto) subgoal for y apply (case_tac y) apply auto done done from drop suspends have suspends': "suspends = Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W'# sb''" by simp have "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts, m, \<S>)" by auto moreover note flush_commute= flush_all_until_volatile_write_append_Prog\<^sub>s\<^sub>b_commute [OF i_bound ts\<^sub>s\<^sub>b_i] have "Write\<^sub>s\<^sub>b True a' sop' v' A' L' R' W' \<in> set sb" by (subst sb_split) auto from dropWhile_append1 [OF this, of "(Not \<circ> is_volatile_Write\<^sub>s\<^sub>b)"] have drop_app_comm: "(dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) (sb @ [Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis])) = dropWhile (Not \<circ> is_volatile_Write\<^sub>s\<^sub>b) sb @ [Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]" by simp note share_commute = share_all_until_volatile_write_update_sb [OF share_append_Prog\<^sub>s\<^sub>b i_bound ts\<^sub>s\<^sub>b_i] from \<D> have \<D>': "\<D>\<^sub>s\<^sub>b = (\<D> \<or> outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis]) \<noteq> {})" by (auto simp: outstanding_refs_append) have "(ts\<^sub>s\<^sub>b [i := (p\<^sub>s\<^sub>b',is\<^sub>s\<^sub>b@mis,\<theta>\<^sub>s\<^sub>b, sb@[Prog\<^sub>s\<^sub>b p\<^sub>s\<^sub>b p\<^sub>s\<^sub>b' mis], \<D>\<^sub>s\<^sub>b, \<O>\<^sub>s\<^sub>b,\<R>\<^sub>s\<^sub>b)], m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b') \<sim> (ts,m,\<S>)" apply (rule sim_config.intros) apply (simp add: m flush_commute) apply (clarsimp simp add: \<S> \<S>\<^sub>s\<^sub>b' share_commute) using leq apply simp using i_bound i_bound' ts_sim ts_i is_sim suspends suspends' [simplified suspends] \<D>' apply (clarsimp simp add: Let_def nth_list_update Prog\<^sub>s\<^sub>b drop_app_comm instrs_append prog_instrs_append read_tmps_append hd_prog_append_Prog\<^sub>s\<^sub>b acquired_append_Prog\<^sub>s\<^sub>b release_append_Prog\<^sub>s\<^sub>b release_append \<S>\<^sub>s\<^sub>b' split: if_split_asm) done ultimately show ?thesis using valid_own' valid_hist' valid_reads' valid_sharing' tmps_distinct' m\<^sub>s\<^sub>b' valid_dd' valid_sops' load_tmps_fresh' enough_flushs' valid_sharing' valid_program_history' valid' \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' by (auto simp del: fun_upd_apply) qed qed qed theorem (in xvalid_program) concurrent_direct_steps_simulates_store_buffer_history_steps: assumes step_sb: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b')" assumes valid_own: "valid_ownership \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" assumes valid_sb_reads: "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" assumes valid_hist: "valid_history program_step ts\<^sub>s\<^sub>b" assumes valid_sharing: "valid_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" assumes tmps_distinct: "tmps_distinct ts\<^sub>s\<^sub>b" assumes valid_sops: "valid_sops ts\<^sub>s\<^sub>b" assumes valid_dd: "valid_data_dependency ts\<^sub>s\<^sub>b" assumes load_tmps_fresh: "load_tmps_fresh ts\<^sub>s\<^sub>b" assumes enough_flushs: "enough_flushs ts\<^sub>s\<^sub>b" assumes valid_program_history: "valid_program_history ts\<^sub>s\<^sub>b" assumes valid: "valid ts\<^sub>s\<^sub>b" shows "\<And>ts \<S> m. (ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>) \<Longrightarrow> safe_reach_direct safe_delayed (ts,m,\<S>) \<Longrightarrow> valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<and> valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<and> valid_history program_step ts\<^sub>s\<^sub>b' \<and> valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b' \<and> tmps_distinct ts\<^sub>s\<^sub>b' \<and> valid_data_dependency ts\<^sub>s\<^sub>b' \<and> valid_sops ts\<^sub>s\<^sub>b' \<and> load_tmps_fresh ts\<^sub>s\<^sub>b' \<and> enough_flushs ts\<^sub>s\<^sub>b' \<and> valid_program_history ts\<^sub>s\<^sub>b' \<and> valid ts\<^sub>s\<^sub>b' \<and> (\<exists>ts' m' \<S>'. (ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>') \<and> (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b') \<sim> (ts',m',\<S>'))" using step_sb valid_own valid_sb_reads valid_hist valid_sharing tmps_distinct valid_sops valid_dd load_tmps_fresh enough_flushs valid_program_history valid proof (induct rule: converse_rtranclp_induct_sbh_steps) case refl thus ?case by auto next case (step ts\<^sub>s\<^sub>b m\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b'' m\<^sub>s\<^sub>b'' \<S>\<^sub>s\<^sub>b'') note first = \<open>(ts\<^sub>s\<^sub>b, m\<^sub>s\<^sub>b, \<S>\<^sub>s\<^sub>b) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>s\<^sub>b'', m\<^sub>s\<^sub>b'', \<S>\<^sub>s\<^sub>b'')\<close> note sim = \<open>(ts\<^sub>s\<^sub>b, m\<^sub>s\<^sub>b, \<S>\<^sub>s\<^sub>b) \<sim> (ts, m, \<S>)\<close> note safe_reach = \<open>safe_reach_direct safe_delayed (ts, m, \<S>)\<close> note valid_own = \<open>valid_ownership \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> note valid_reads = \<open>valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> note valid_hist = \<open>valid_history program_step ts\<^sub>s\<^sub>b\<close> note valid_sharing = \<open>valid_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> note tmps_distinct = \<open>tmps_distinct ts\<^sub>s\<^sub>b\<close> note valid_sops = \<open>valid_sops ts\<^sub>s\<^sub>b\<close> note valid_dd = \<open>valid_data_dependency ts\<^sub>s\<^sub>b\<close> note load_tmps_fresh = \<open>load_tmps_fresh ts\<^sub>s\<^sub>b\<close> note enough_flushs = \<open>enough_flushs ts\<^sub>s\<^sub>b\<close> note valid_prog_hist = \<open>valid_program_history ts\<^sub>s\<^sub>b\<close> note valid = \<open>valid ts\<^sub>s\<^sub>b\<close> from concurrent_direct_steps_simulates_store_buffer_history_step [OF first valid_own valid_reads valid_hist valid_sharing tmps_distinct valid_sops valid_dd load_tmps_fresh enough_flushs valid_prog_hist valid sim safe_reach] obtain ts'' m'' \<S>'' where valid_own'': "valid_ownership \<S>\<^sub>s\<^sub>b'' ts\<^sub>s\<^sub>b''" and valid_reads'': "valid_reads m\<^sub>s\<^sub>b'' ts\<^sub>s\<^sub>b''" and valid_hist'': "valid_history program_step ts\<^sub>s\<^sub>b''" and valid_sharing'': "valid_sharing \<S>\<^sub>s\<^sub>b'' ts\<^sub>s\<^sub>b''" and tmps_dist'': "tmps_distinct ts\<^sub>s\<^sub>b''" and valid_dd'': "valid_data_dependency ts\<^sub>s\<^sub>b''" and valid_sops'': "valid_sops ts\<^sub>s\<^sub>b''" and load_tmps_fresh'': "load_tmps_fresh ts\<^sub>s\<^sub>b''" and enough_flushs'': "enough_flushs ts\<^sub>s\<^sub>b''" and valid_prog_hist'': "valid_program_history ts\<^sub>s\<^sub>b''"and valid'': "valid ts\<^sub>s\<^sub>b''" and steps: "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts'', m'', \<S>'')" and sim: "(ts\<^sub>s\<^sub>b'', m\<^sub>s\<^sub>b'',\<S>\<^sub>s\<^sub>b'') \<sim> (ts'', m'',\<S>'')" by blast from step.hyps (3) [OF sim safe_reach_steps [OF safe_reach steps] valid_own'' valid_reads'' valid_hist'' valid_sharing'' tmps_dist'' valid_sops'' valid_dd'' load_tmps_fresh'' enough_flushs'' valid_prog_hist'' valid'' ] obtain ts' m' \<S>' where valid: "valid_ownership \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" "valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" "valid_history program_step ts\<^sub>s\<^sub>b'" "valid_sharing \<S>\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b'" "tmps_distinct ts\<^sub>s\<^sub>b'" "valid_data_dependency ts\<^sub>s\<^sub>b'" "valid_sops ts\<^sub>s\<^sub>b'" "load_tmps_fresh ts\<^sub>s\<^sub>b'" "enough_flushs ts\<^sub>s\<^sub>b'" "valid_program_history ts\<^sub>s\<^sub>b'" "valid ts\<^sub>s\<^sub>b'" and last: "(ts'', m'', \<S>'') \<Rightarrow>\<^sub>d\<^sup>* (ts', m', \<S>')" and sim': "(ts\<^sub>s\<^sub>b', m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b') \<sim> (ts', m',\<S>')" by blast note steps also note last finally show ?case using valid sim' by blast qed (* FIXME: move up *) sublocale initial\<^sub>s\<^sub>b \<subseteq> tmps_distinct .. locale xvalid_program_progress = program_progress + xvalid_program theorem (in xvalid_program_progress) concurrent_direct_execution_simulates_store_buffer_history_execution: assumes exec_sb: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b')" assumes init: "initial\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b" assumes valid: "valid ts\<^sub>s\<^sub>b" (* FIXME: move into initial ?*) assumes sim: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" assumes safe: "safe_reach_direct safe_free_flowing (ts,m,\<S>)" shows "\<exists>ts' m' \<S>'. (ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>') \<and> (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b') \<sim> (ts',m',\<S>')" proof - from init interpret ini: initial\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b . from safe_free_flowing_implies_safe_delayed' [OF init sim safe] have safe_delayed: "safe_reach_direct safe_delayed (ts, m, \<S>)". from local.ini.valid_ownership_axioms have "valid_ownership \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b" . from local.ini.valid_reads_axioms have "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b". from local.ini.valid_history_axioms have "valid_history program_step ts\<^sub>s\<^sub>b". from local.ini.valid_sharing_axioms have "valid_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b". from local.ini.tmps_distinct_axioms have "tmps_distinct ts\<^sub>s\<^sub>b". from local.ini.valid_sops_axioms have "valid_sops ts\<^sub>s\<^sub>b". from local.ini.valid_data_dependency_axioms have "valid_data_dependency ts\<^sub>s\<^sub>b". from local.ini.load_tmps_fresh_axioms have "load_tmps_fresh ts\<^sub>s\<^sub>b". from local.ini.enough_flushs_axioms have "enough_flushs ts\<^sub>s\<^sub>b". from local.ini.valid_program_history_axioms have "valid_program_history ts\<^sub>s\<^sub>b". from concurrent_direct_steps_simulates_store_buffer_history_steps [OF exec_sb \<open>valid_ownership \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> \<open>valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> \<open>valid_history program_step ts\<^sub>s\<^sub>b\<close> \<open>valid_sharing \<S>\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<close> \<open>tmps_distinct ts\<^sub>s\<^sub>b\<close> \<open>valid_sops ts\<^sub>s\<^sub>b\<close> \<open>valid_data_dependency ts\<^sub>s\<^sub>b\<close> \<open>load_tmps_fresh ts\<^sub>s\<^sub>b\<close> \<open>enough_flushs ts\<^sub>s\<^sub>b\<close> \<open>valid_program_history ts\<^sub>s\<^sub>b\<close> valid sim safe_delayed] show ?thesis by auto qed lemma filter_is_Write\<^sub>s\<^sub>b_Cons_Write\<^sub>s\<^sub>b: "filter is_Write\<^sub>s\<^sub>b xs = Write\<^sub>s\<^sub>b volatile a sop v A L R W#ys \<Longrightarrow> \<exists>rs rws. (\<forall>r \<in> set rs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r) \<and> xs=rs@Write\<^sub>s\<^sub>b volatile a sop v A L R W#rws \<and> ys=filter is_Write\<^sub>s\<^sub>b rws" proof (induct xs) case Nil thus ?case by simp next case (Cons x xs) note feq = \<open>filter is_Write\<^sub>s\<^sub>b (x#xs) = Write\<^sub>s\<^sub>b volatile a sop v A L R W# ys\<close> show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile' a' sop' v' A' L' R' W') with feq obtain "volatile'=volatile" "a'=a" "v'=v" "sop'=sop" "A'=A" "L'=L" "R'=R" "W'=W" "ys = filter is_Write\<^sub>s\<^sub>b xs" by auto thus ?thesis apply - apply (rule_tac x="[]" in exI) apply (rule_tac x="xs" in exI) apply (simp add: Write\<^sub>s\<^sub>b) done next case (Read\<^sub>s\<^sub>b volatile' a' t' v') from feq have "filter is_Write\<^sub>s\<^sub>b xs = Write\<^sub>s\<^sub>b volatile a sop v A L R W#ys" by (simp add: Read\<^sub>s\<^sub>b) from Cons.hyps [OF this] obtain rs rws where "\<forall>r \<in> set rs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r" and "xs=rs @ Write\<^sub>s\<^sub>b volatile a sop v A L R W# rws" and "ys=filter is_Write\<^sub>s\<^sub>b rws" by clarsimp then show ?thesis apply - apply (rule_tac x="Read\<^sub>s\<^sub>b volatile' a' t' v'#rs" in exI) apply (rule_tac x="rws" in exI) apply (simp add: Read\<^sub>s\<^sub>b) done next case (Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis) from feq have "filter is_Write\<^sub>s\<^sub>b xs = Write\<^sub>s\<^sub>b volatile a sop v A L R W#ys" by (simp add: Prog\<^sub>s\<^sub>b) from Cons.hyps [OF this] obtain rs rws where "\<forall>r \<in> set rs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r" and "xs=rs @ Write\<^sub>s\<^sub>b volatile a sop v A L R W# rws" and "ys=filter is_Write\<^sub>s\<^sub>b rws" by clarsimp then show ?thesis apply - apply (rule_tac x="Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis#rs" in exI) apply (rule_tac x="rws" in exI) apply (simp add: Prog\<^sub>s\<^sub>b) done next case (Ghost\<^sub>s\<^sub>b A' L' R' W') from feq have "filter is_Write\<^sub>s\<^sub>b xs = Write\<^sub>s\<^sub>b volatile a sop v A L R W # ys" by (simp add: Ghost\<^sub>s\<^sub>b) from Cons.hyps [OF this] obtain rs rws where "\<forall>r \<in> set rs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r" and "xs=rs @ Write\<^sub>s\<^sub>b volatile a sop v A L R W# rws" and "ys=filter is_Write\<^sub>s\<^sub>b rws" by clarsimp then show ?thesis apply - apply (rule_tac x="Ghost\<^sub>s\<^sub>b A' L' R' W'#rs" in exI) apply (rule_tac x="rws" in exI) apply (simp add: Ghost\<^sub>s\<^sub>b) done qed qed lemma filter_is_Write\<^sub>s\<^sub>b_empty: "filter is_Write\<^sub>s\<^sub>b xs = [] \<Longrightarrow> (\<forall>r \<in> set xs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r)" proof (induct xs) case Nil thus ?case by simp next case (Cons x xs) note feq = \<open>filter is_Write\<^sub>s\<^sub>b (x#xs) = []\<close> show ?case proof (cases x) case (Write\<^sub>s\<^sub>b volatile' a' v') with feq have False by simp thus ?thesis .. next case (Read\<^sub>s\<^sub>b a' v') from feq have "filter is_Write\<^sub>s\<^sub>b xs = []" by (simp add: Read\<^sub>s\<^sub>b) from Cons.hyps [OF this] obtain "\<forall>r \<in> set xs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r" by clarsimp then show ?thesis by (simp add: Read\<^sub>s\<^sub>b) next case (Prog\<^sub>s\<^sub>b p\<^sub>2 p\<^sub>2 mis) from feq have "filter is_Write\<^sub>s\<^sub>b xs = []" by (simp add: Prog\<^sub>s\<^sub>b) from Cons.hyps [OF this] obtain "\<forall>r \<in> set xs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r" by clarsimp then show ?thesis by (simp add: Prog\<^sub>s\<^sub>b) next case (Ghost\<^sub>s\<^sub>b A' L' R' W') from feq have "filter is_Write\<^sub>s\<^sub>b xs = []" by (simp add: Ghost\<^sub>s\<^sub>b) from Cons.hyps [OF this] obtain "\<forall>r \<in> set xs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r" by clarsimp then show ?thesis by (simp add: Ghost\<^sub>s\<^sub>b) qed qed lemma flush_reads_program: "\<And>\<O> \<S> \<R> . \<forall>r \<in> set sb. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r \<Longrightarrow> \<exists>\<O>' \<R>' \<S>'. (m,sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f\<^sup>* (m,[],\<O>',\<R>',\<S>')" proof (induct sb) case Nil thus ?case by auto next case (Cons x sb) note \<open>\<forall>r\<in>set (x # sb). is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r\<close> then obtain x: "is_Read\<^sub>s\<^sub>b x \<or> is_Prog\<^sub>s\<^sub>b x \<or> is_Ghost\<^sub>s\<^sub>b x" and sb: "\<forall>r\<in>set sb. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r" by (cases x) auto { assume "is_Read\<^sub>s\<^sub>b x" then obtain volatile a t v where x: "x=Read\<^sub>s\<^sub>b volatile a t v" by (cases x) auto have "(m,Read\<^sub>s\<^sub>b volatile a t v#sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m,sb,\<O>,\<R>,\<S>)" by (rule Read\<^sub>s\<^sub>b) also from Cons.hyps [OF sb] obtain \<O>' \<S>' acq' \<R>' where "(m, sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f\<^sup>* (m, [],\<O>',\<R>',\<S>')" by blast finally have ?case by (auto simp add: x) } moreover { assume "is_Prog\<^sub>s\<^sub>b x" then obtain p\<^sub>1 p\<^sub>2 mis where x: "x=Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis" by (cases x) auto have "(m,Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis#sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m,sb,\<O>,\<R>,\<S>)" by (rule Prog\<^sub>s\<^sub>b) also from Cons.hyps [OF sb] obtain \<O>' \<R>' \<S>' acq' where "(m, sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f\<^sup>* (m, [],\<O>',\<R>',\<S>')" by blast finally have ?case by (auto simp add: x) } moreover { assume "is_Ghost\<^sub>s\<^sub>b x" then obtain A L R W where x: "x=Ghost\<^sub>s\<^sub>b A L R W" by (cases x) auto have "(m,Ghost\<^sub>s\<^sub>b A L R W#sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m,sb,\<O> \<union> A - R,augment_rels (dom \<S>) R \<R>,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (rule Ghost) also from Cons.hyps [OF sb] obtain \<O>' \<S>' \<R>' acq' where "(m, sb,\<O> \<union> A - R ,augment_rels (dom \<S>) R \<R>,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L) \<rightarrow>\<^sub>f\<^sup>* (m, [],\<O>',\<R>',\<S>')" by blast finally have ?case by (auto simp add: x) } ultimately show ?case using x by blast qed lemma flush_progress: "\<exists>m' \<O>' \<S>' \<R>'. (m,r#sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m',sb,\<O>',\<R>',\<S>')" proof (cases r) case (Write\<^sub>s\<^sub>b volatile a sop v A L R W) from flush_step.Write\<^sub>s\<^sub>b [OF refl refl refl, of m volatile a sop v A L R W sb \<O> \<R> \<S>] show ?thesis by (auto simp add: Write\<^sub>s\<^sub>b) next case (Read\<^sub>s\<^sub>b volatile a t v) from flush_step.Read\<^sub>s\<^sub>b [of m volatile a t v sb \<O> \<R> \<S>] show ?thesis by (auto simp add: Read\<^sub>s\<^sub>b) next case (Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis) from flush_step.Prog\<^sub>s\<^sub>b [of m p\<^sub>1 p\<^sub>2 mis sb \<O> \<R> \<S>] show ?thesis by (auto simp add: Prog\<^sub>s\<^sub>b) next case (Ghost\<^sub>s\<^sub>b A L R W) from flush_step.Ghost [of m A L R W sb \<O> \<R> \<S>] show ?thesis by (auto simp add: Ghost\<^sub>s\<^sub>b) qed lemma flush_empty: assumes steps: "(m, sb,\<O>,\<R>, \<S>) \<rightarrow>\<^sub>f\<^sup>* (m', sb',\<O>',\<R>',\<S>')" shows "sb=[] \<Longrightarrow> m'=m \<and> sb'=[] \<and> \<O>'=\<O> \<and> \<R>'=\<R> \<and> \<S>'=\<S> " using steps apply (induct rule: converse_rtranclp_induct5) apply (auto elim: flush_step.cases) done lemma flush_append: assumes steps: "(m, sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f\<^sup>* (m', sb',\<O>',\<R>',\<S>')" shows "\<And>xs. (m, sb@xs,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f\<^sup>* (m', sb'@xs,\<O>',\<R>',\<S>')" using steps proof (induct rule: converse_rtranclp_induct5) case refl thus ?case by auto next case (step m sb \<O> \<R> \<S> m'' sb'' \<O>'' \<R>'' \<S>'') note first= \<open>(m,sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m'',sb'',\<O>'',\<R>'',\<S>'')\<close> note rest = \<open>(m'', sb'',\<O>'',\<R>'',\<S>'') \<rightarrow>\<^sub>f\<^sup>* (m', sb',\<O>',\<R>',\<S>')\<close> from step.hyps (3) have append_rest: "(m'', sb''@xs,\<O>'',\<R>'',\<S>'') \<rightarrow>\<^sub>f\<^sup>* (m', sb'@xs,\<O>',\<R>',\<S>')". from first show ?case proof (cases) case (Write\<^sub>s\<^sub>b volatile A R W L a sop v) then obtain sb: "sb=Write\<^sub>s\<^sub>b volatile a sop v A L R W#sb''" and m'': "m''=m(a:=v)" and \<O>'': "\<O>''=(if volatile then \<O> \<union> A - R else \<O>)" and \<R>'': "\<R>''=(if volatile then Map.empty else \<R>)" and \<S>'': "\<S>''=(if volatile then \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L else \<S>)" by auto have "(m,Write\<^sub>s\<^sub>b volatile a sop v A L R W#sb''@xs,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m(a:=v),sb''@xs,if volatile then \<O> \<union> A - R else \<O>,if volatile then Map.empty else \<R>, if volatile then \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L else \<S>)" apply (rule flush_step.Write\<^sub>s\<^sub>b) apply auto done hence "(m,sb@xs,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m'',sb''@xs,\<O>'',\<R>'',\<S>'')" by (simp add: sb m'' \<O>'' \<R>'' \<S>'') also note append_rest finally show ?thesis . next case (Read\<^sub>s\<^sub>b volatile a t v) then obtain sb: "sb=Read\<^sub>s\<^sub>b volatile a t v #sb''" and m'': "m''=m" and \<O>'': "\<O>''=\<O>" and \<S>'': "\<S>''=\<S>" and \<R>'': "\<R>''=\<R>" by auto have "(m,Read\<^sub>s\<^sub>b volatile a t v#sb''@xs,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m,sb''@xs,\<O>,\<R>,\<S>)" by (rule flush_step.Read\<^sub>s\<^sub>b) hence "(m,sb@xs,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m'',sb''@xs,\<O>'',\<R>'',\<S>'')" by (simp add: sb m'' \<O>'' \<R>'' \<S>'' ) also note append_rest finally show ?thesis . next case (Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis) then obtain sb: "sb=Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis#sb''" and m'': "m''=m" and \<O>'': "\<O>''=\<O>" and \<S>'': "\<S>''=\<S>" and \<R>'': "\<R>''=\<R>" by auto have "(m,Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis#sb''@xs,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m,sb''@xs,\<O>,\<R>,\<S>)" by (rule flush_step.Prog\<^sub>s\<^sub>b) hence "(m,sb@xs,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m'',sb''@xs,\<O>'',\<R>'',\<S>'')" by (simp add: sb m'' \<O>'' \<R>'' \<S>'' ) also note append_rest finally show ?thesis . next case (Ghost A L R W) then obtain sb: "sb=Ghost\<^sub>s\<^sub>b A L R W#sb''" and m'': "m''=m" and \<O>'': "\<O>''=\<O> \<union> A - R" and \<S>'': "\<S>''=\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L" and \<R>'': "\<R>''=augment_rels (dom \<S>) R \<R>" by auto have "(m,Ghost\<^sub>s\<^sub>b A L R W#sb''@xs,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m,sb''@xs,\<O> \<union> A - R,augment_rels (dom \<S>) R \<R>,\<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (rule flush_step.Ghost) hence "(m,sb@xs,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m'',sb''@xs,\<O>'',\<R>'',\<S>'')" by (simp add: sb m'' \<O>'' \<R>'' \<S>'' ) also note append_rest finally show ?thesis . qed qed (* theorem flush_simulates_filter_writes: assumes step: "(m,sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>f (m',sb',\<O>',\<R>',\<S>')" shows "\<And>sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<S>\<^sub>h. sb=filter is_Write\<^sub>s\<^sub>b sb\<^sub>h \<Longrightarrow> \<exists>sb\<^sub>h' \<O>\<^sub>h' \<R>\<^sub>h' \<S>\<^sub>h'. (m,sb\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m',sb\<^sub>h',\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h') \<and> sb'=filter is_Write\<^sub>s\<^sub>b sb\<^sub>h'" using step proof (induct rule: flush_step_induct) case (Write\<^sub>s\<^sub>b \<O>' volatile \<O> A R \<S>' \<S> W L \<R>' \<R> m a D f v sb) note filter_Write\<^sub>s\<^sub>b = `Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h` note \<O>' = `\<O>' = (if volatile then \<O> \<union> A - R else \<O>)` note \<R>' = `\<R>'= (if volatile then empty else \<R>)` note \<S>' = `\<S>' = (if volatile then \<S> \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L else \<S>)` from filter_is_Write\<^sub>s\<^sub>b_Cons_Write\<^sub>s\<^sub>b [OF filter_Write\<^sub>s\<^sub>b [symmetric]] obtain rs rws where rs_reads: "\<forall>r\<in>set rs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r" and sb\<^sub>h: "sb\<^sub>h = rs @ Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# rws" and sb: "sb = filter is_Write\<^sub>s\<^sub>b rws" by blast from flush_reads_program [OF rs_reads] obtain \<O>\<^sub>h' \<R>\<^sub>h' \<S>\<^sub>h' acq\<^sub>h' where "(m, rs,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m, [],\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h')" by blast from flush_append [OF this] have "(m, rs@Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# rws,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m, Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# rws,\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h')" by simp also from flush_step.Write\<^sub>s\<^sub>b [OF refl refl refl, of m volatile a "(D,f)" v A L R W rws \<O>\<^sub>h' \<R>\<^sub>h' \<S>\<^sub>h'] obtain \<O>\<^sub>h'' \<R>\<^sub>h'' \<S>\<^sub>h'' where "(m, Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# rws,\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h') \<rightarrow>\<^sub>f (m(a:=v), rws, \<O>\<^sub>h'',\<R>\<^sub>h'',\<S>\<^sub>h'')" by auto finally have "(m, sb\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m(a:=v), rws,\<O>\<^sub>h'',\<R>\<^sub>h'',\<S>\<^sub>h'')" by (simp add: sb\<^sub>h sb) with sb show ?case by blast next case (Read\<^sub>s\<^sub>b m volatile a t v sb) note `Read\<^sub>s\<^sub>b volatile a t v # sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h` from this [symmetric] have r_in: "Read\<^sub>s\<^sub>b volatile a t v \<in> set (filter is_Write\<^sub>s\<^sub>b sb\<^sub>h)" by auto have "\<forall>r \<in> set (filter is_Write\<^sub>s\<^sub>b sb\<^sub>h). is_Write\<^sub>s\<^sub>b r" by auto from this [rule_format, OF r_in] have False by simp thus ?case .. next case (Prog\<^sub>s\<^sub>b m p\<^sub>1 p\<^sub>2 mis sb) note `Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis # sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h` from this [symmetric] have r_in: "Prog\<^sub>s\<^sub>b p\<^sub>1 p\<^sub>2 mis \<in> set (filter is_Write\<^sub>s\<^sub>b sb\<^sub>h)" by auto have "\<forall>r \<in> set (filter is_Write\<^sub>s\<^sub>b sb\<^sub>h). is_Write\<^sub>s\<^sub>b r" by auto from this [rule_format, OF r_in] have False by simp thus ?case .. next case (Ghost m A L R W sb) note `Ghost\<^sub>s\<^sub>b A L R W# sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h` from this [symmetric] have r_in: "Ghost\<^sub>s\<^sub>b A L R W\<in> set (filter is_Write\<^sub>s\<^sub>b sb\<^sub>h)" by auto have "\<forall>r \<in> set (filter is_Write\<^sub>s\<^sub>b sb\<^sub>h). is_Write\<^sub>s\<^sub>b r" by auto from this [rule_format, OF r_in] have False by simp thus ?case .. qed *) (* FIXME: move up *) lemmas store_buffer_step_induct = store_buffer_step.induct [split_format (complete), consumes 1, case_names SBWrite\<^sub>s\<^sub>b] theorem flush_simulates_filter_writes: assumes step: "(m,sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>w (m',sb',\<O>',\<R>',\<S>')" shows "\<And>sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<S>\<^sub>h. sb=filter is_Write\<^sub>s\<^sub>b sb\<^sub>h \<Longrightarrow> \<exists>sb\<^sub>h' \<O>\<^sub>h' \<R>\<^sub>h' \<S>\<^sub>h'. (m,sb\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m',sb\<^sub>h',\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h') \<and> sb'=filter is_Write\<^sub>s\<^sub>b sb\<^sub>h' \<and> (sb'=[] \<longrightarrow> sb\<^sub>h'=[])" using step proof (induct rule: store_buffer_step_induct) case (SBWrite\<^sub>s\<^sub>b m volatile a D f v A L R W sb \<O> \<R> \<S>) note filter_Write\<^sub>s\<^sub>b = \<open>Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h\<close> from filter_is_Write\<^sub>s\<^sub>b_Cons_Write\<^sub>s\<^sub>b [OF filter_Write\<^sub>s\<^sub>b [symmetric]] obtain rs rws where rs_reads: "\<forall>r\<in>set rs. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r" and sb\<^sub>h: "sb\<^sub>h = rs @ Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# rws" and sb: "sb = filter is_Write\<^sub>s\<^sub>b rws" by blast from flush_reads_program [OF rs_reads] obtain \<O>\<^sub>h' \<R>\<^sub>h' \<S>\<^sub>h' acq\<^sub>h' where "(m, rs,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m, [],\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h')" by blast from flush_append [OF this] have "(m, rs@Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# rws,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m, Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# rws,\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h')" by simp also from flush_step.Write\<^sub>s\<^sub>b [OF refl refl refl, of m volatile a "(D,f)" v A L R W rws \<O>\<^sub>h' \<R>\<^sub>h' \<S>\<^sub>h'] obtain \<O>\<^sub>h'' \<R>\<^sub>h'' \<S>\<^sub>h'' where "(m, Write\<^sub>s\<^sub>b volatile a (D,f) v A L R W# rws,\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h') \<rightarrow>\<^sub>f (m(a:=v), rws, \<O>\<^sub>h'',\<R>\<^sub>h'',\<S>\<^sub>h'')" by auto finally have steps: "(m, sb\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m(a:=v), rws,\<O>\<^sub>h'',\<R>\<^sub>h'',\<S>\<^sub>h'')" by (simp add: sb\<^sub>h sb) show ?case proof (cases "sb") case Cons with steps sb show ?thesis by fastforce next case Nil from filter_is_Write\<^sub>s\<^sub>b_empty [OF sb [simplified Nil, symmetric]] have "\<forall>r\<in>set rws. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r". from flush_reads_program [OF this] obtain \<O>\<^sub>h''' \<R>\<^sub>h''' \<S>\<^sub>h''' acq\<^sub>h''' where "(m(a:=v), rws,\<O>\<^sub>h'',\<R>\<^sub>h'',\<S>\<^sub>h'') \<rightarrow>\<^sub>f\<^sup>* (m(a:=v), [],\<O>\<^sub>h''',\<R>\<^sub>h''',\<S>\<^sub>h''')" by blast with steps have "(m, sb\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m(a:=v), [],\<O>\<^sub>h''',\<R>\<^sub>h''',\<S>\<^sub>h''')" by force with sb Nil show ?thesis by fastforce qed qed lemma bufferd_val_filter_is_Write\<^sub>s\<^sub>b_eq_ext: "buffered_val (filter is_Write\<^sub>s\<^sub>b sb) a = buffered_val sb a" by (induct sb) (auto split: memref.splits) lemma bufferd_val_filter_is_Write\<^sub>s\<^sub>b_eq: "buffered_val (filter is_Write\<^sub>s\<^sub>b sb) = buffered_val sb" by (rule ext) (rule bufferd_val_filter_is_Write\<^sub>s\<^sub>b_eq_ext) lemma outstanding_refs_is_volatile_Write\<^sub>s\<^sub>b_filter_writes: "outstanding_refs is_volatile_Write\<^sub>s\<^sub>b (filter is_Write\<^sub>s\<^sub>b xs) = outstanding_refs is_volatile_Write\<^sub>s\<^sub>b xs" by (induct xs) (auto simp add: is_volatile_Write\<^sub>s\<^sub>b_def split: memref.splits) subsection \<open>Simulation of Store Buffer Machine without History by Store Buffer Machine with History\<close> theorem (in valid_program) concurrent_history_steps_simulates_store_buffer_step: assumes step_sb: "(ts,m,\<S>) \<Rightarrow>\<^sub>s\<^sub>b (ts',m',\<S>')" assumes sim: "ts \<sim>\<^sub>h ts\<^sub>h" shows "\<exists>ts\<^sub>h' \<S>\<^sub>h'. (ts\<^sub>h,m,\<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h',m',\<S>\<^sub>h') \<and> ts' \<sim>\<^sub>h ts\<^sub>h'" proof - interpret sbh_computation: computation sbh_memop_step flush_step program_step "\<lambda>p p' is sb. sb @ [Prog\<^sub>s\<^sub>b p p' is]" . from step_sb show ?thesis proof (cases rule: concurrent_step_cases) case (Memop i _ p "is" \<theta> sb \<D> \<O> \<R> _ _ is' \<theta>' sb' _ \<D>' \<O>' \<R>') then obtain ts': "ts' = ts[i := (p, is', \<theta>', sb', \<D>', \<O>',\<R>')]" and i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, \<theta>, sb, \<D>, \<O>,\<R>)" and step_sb: "(is, \<theta>, sb, m, \<D>, \<O>, \<R>,\<S>) \<rightarrow>\<^sub>s\<^sub>b (is', \<theta>', sb', m', \<D>', \<O>', \<R>',\<S>')" by auto from sim obtain lts_eq: "length ts = length ts\<^sub>h" and sim_loc: "\<forall>i < length ts. (\<exists>\<O>' \<D>' \<R>'. let (p,is, \<theta>, sb,\<D>, \<O>,\<R>) = ts\<^sub>h!i in ts!i=(p,is, \<theta>, filter is_Write\<^sub>s\<^sub>b sb,\<D>',\<O>',\<R>') \<and> (filter is_Write\<^sub>s\<^sub>b sb = [] \<longrightarrow> sb=[]))" by cases (auto) from lts_eq i_bound have i_bound': "i < length ts\<^sub>h" by simp from step_sb show ?thesis proof (cases) case (SBReadBuffered a v volatile t) then obtain "is": "is = Read volatile a t#is'" and \<O>': "\<O>'=\<O>" and \<S>': "\<S>'=\<S>" and \<R>': "\<R>'=\<R>" and \<D>': "\<D>'=\<D>" and m': "m'=m" and \<theta>': "\<theta>'=\<theta>(t\<mapsto>v)" and sb': "sb' = sb" and buf_val: "buffered_val sb a = Some v" by auto from sim_loc [rule_format, OF i_bound] ts_i "is" obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,Read volatile a t#is',\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" and sb_empty: "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h = [] \<longrightarrow> sb\<^sub>h=[]" by (auto simp add: Let_def) from buf_val have buf_val': "buffered_val sb\<^sub>h a = Some v" by (simp add: bufferd_val_filter_is_Write\<^sub>s\<^sub>b_eq sb) let ?ts\<^sub>h_i' = "(p, is', \<theta>(t \<mapsto> v), sb\<^sub>h @ [Read\<^sub>s\<^sub>b volatile a t v], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)" let ?ts\<^sub>h' = "ts\<^sub>h[i := ?ts\<^sub>h_i']" from sbh_memop_step.SBHReadBuffered [OF buf_val'] have "(Read volatile a t # is', \<theta>, sb\<^sub>h, m,\<D>\<^sub>h, \<O>\<^sub>h, \<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>s\<^sub>b\<^sub>h (is', \<theta>(t \<mapsto> v), sb\<^sub>h@ [Read\<^sub>s\<^sub>b volatile a t v], m, \<D>\<^sub>h, \<O>\<^sub>h, \<R>\<^sub>h, \<S>\<^sub>h)". from sbh_computation.Memop [OF i_bound' ts\<^sub>h_i this] have step: "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (?ts\<^sub>h', m, \<S>\<^sub>h)". from sb have sb: "sb = filter is_Write\<^sub>s\<^sub>b (sb\<^sub>h @ [Read\<^sub>s\<^sub>b volatile a t v])" by simp show ?thesis proof (cases "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h = []") case False have "ts [i := (p,is',\<theta>(t \<mapsto> v),sb,\<D>,\<O>,\<R>)] \<sim>\<^sub>h ?ts\<^sub>h'" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb sb_empty False apply (auto simp add: Let_def nth_list_update) done with step show ?thesis by (auto simp del: fun_upd_apply simp add: \<S>' m' ts' \<O>' \<theta>' \<D>' sb' \<R>') next case True with sb_empty have empty: "sb\<^sub>h=[]" by simp from i_bound' have "?ts\<^sub>h'!i = ?ts\<^sub>h_i'" by auto from sbh_computation.StoreBuffer [OF _ this, simplified empty, simplified, OF _ flush_step.Read\<^sub>s\<^sub>b, of m \<S>\<^sub>h] i_bound' have "(?ts\<^sub>h', m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>h[i := (p, is', \<theta>(t \<mapsto> v), [], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)], m, \<S>\<^sub>h)" by (simp add: empty list_update_overwrite) with step have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h[i := (p, is', \<theta>(t \<mapsto> v), [], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)], m,\<S>\<^sub>h)" by force moreover have "ts [i := (p,is',\<theta>(t \<mapsto> v),sb,\<D>,\<O>,\<R>)] \<sim>\<^sub>h ts\<^sub>h[i := (p, is', \<theta>(t \<mapsto> v), [], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb empty apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp del: fun_upd_apply simp add: \<S>' m' ts' \<O>' \<theta>' \<D>' sb' \<R>') qed next case (SBReadUnbuffered a volatile t) then obtain "is": "is = Read volatile a t#is'" and \<O>': "\<O>'=\<O>" and \<R>': "\<R>'=\<R>" and \<S>': "\<S>'=\<S>" and \<D>': "\<D>'=\<D>" and m': "m'=m" and \<theta>': "\<theta>'=\<theta>(t\<mapsto>m a)" and sb': "sb' = sb" and buf: "buffered_val sb a = None" by auto from sim_loc [rule_format, OF i_bound] ts_i "is" obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,Read volatile a t#is',\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" and sb_empty: "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h = [] \<longrightarrow> sb\<^sub>h=[]" by (auto simp add: Let_def) from buf have buf': "buffered_val sb\<^sub>h a = None" by (simp add: bufferd_val_filter_is_Write\<^sub>s\<^sub>b_eq sb) let ?ts\<^sub>h_i' = "(p, is', \<theta>(t \<mapsto> m a), sb\<^sub>h @ [Read\<^sub>s\<^sub>b volatile a t (m a)], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)" let ?ts\<^sub>h' = "ts\<^sub>h[i := ?ts\<^sub>h_i']" from sbh_memop_step.SBHReadUnbuffered [OF buf'] have "(Read volatile a t # is',\<theta>, sb\<^sub>h, m, \<D>\<^sub>h, \<O>\<^sub>h, \<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>s\<^sub>b\<^sub>h (is', \<theta>(t \<mapsto> (m a)), sb\<^sub>h@ [Read\<^sub>s\<^sub>b volatile a t (m a)], m,\<D>\<^sub>h, \<O>\<^sub>h, \<R>\<^sub>h,\<S>\<^sub>h)". from sbh_computation.Memop [OF i_bound' ts\<^sub>h_i this] have step: "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (?ts\<^sub>h', m, \<S>\<^sub>h)". moreover from sb have sb: "sb = filter is_Write\<^sub>s\<^sub>b (sb\<^sub>h @ [Read\<^sub>s\<^sub>b volatile a t (m a)])" by simp show ?thesis proof (cases "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h = []") case False have "ts [i := (p,is',\<theta> (t\<mapsto>m a),sb,\<D>,\<O>,\<R>)] \<sim>\<^sub>h ?ts\<^sub>h'" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb sb_empty False apply (auto simp add: Let_def nth_list_update) done with step show ?thesis by (auto simp del: fun_upd_apply simp add: \<S>' m' ts' \<O>' \<R>' \<D>' \<theta>' sb') next case True with sb_empty have empty: "sb\<^sub>h=[]" by simp from i_bound' have "?ts\<^sub>h'!i = ?ts\<^sub>h_i'" by auto from sbh_computation.StoreBuffer [OF _ this, simplified empty, simplified, OF _ flush_step.Read\<^sub>s\<^sub>b, of m \<S>\<^sub>h] i_bound' have "(?ts\<^sub>h', m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>h[i := (p, is', \<theta>(t \<mapsto> (m a)), [], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)], m, \<S>\<^sub>h)" by (simp add: empty) with step have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h[i := (p, is', \<theta>(t \<mapsto> m a), [], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)], m, \<S>\<^sub>h)" by force moreover have "ts [i := (p,is',\<theta>(t \<mapsto> m a),sb,\<D>,\<O>,\<R>)] \<sim>\<^sub>h ts\<^sub>h[i := (p, is', \<theta>(t \<mapsto> m a), [], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb empty apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp del: fun_upd_apply simp add: \<S>' m' ts' \<O>' \<theta>' \<D>' sb' \<R>') qed next case (SBWriteNonVolatile a D f A L R W) then obtain "is": "is = Write False a (D, f) A L R W#is'" and \<O>': "\<O>'=\<O>" and \<R>': "\<R>'=\<R>" and \<S>': "\<S>'=\<S>" and \<D>': "\<D>'=\<D>" and m': "m'=m" and \<theta>': "\<theta>'=\<theta>" and sb': "sb' = sb@[Write\<^sub>s\<^sub>b False a (D, f) (f \<theta>) A L R W]" by auto from sim_loc [rule_format, OF i_bound] ts_i obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,Write False a (D,f) A L R W#is',\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" by (auto simp add: Let_def "is") from sbh_memop_step.SBHWriteNonVolatile have "(Write False a (D, f) A L R W# is',\<theta>, sb\<^sub>h, m, \<D>\<^sub>h, \<O>\<^sub>h, \<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>s\<^sub>b\<^sub>h (is', \<theta>, sb\<^sub>h @ [Write\<^sub>s\<^sub>b False a (D, f) (f \<theta>) A L R W], m,\<D>\<^sub>h, \<O>\<^sub>h, \<R>\<^sub>h,\<S>\<^sub>h)". from sbh_computation.Memop [OF i_bound' ts\<^sub>h_i this] have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>h[i := (p, is',\<theta>, sb\<^sub>h @ [Write\<^sub>s\<^sub>b False a (D, f) (f \<theta>) A L R W], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)], m, \<S>\<^sub>h)". moreover have "ts [i := (p,is',\<theta>,sb @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>) A L R W],\<D>,\<O>,\<R>)] \<sim>\<^sub>h ts\<^sub>h[i := (p,is',\<theta>, sb\<^sub>h @ [Write\<^sub>s\<^sub>b False a (D,f) (f \<theta>) A L R W],\<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp add: \<S>' m' \<theta>' \<O>' \<R>' \<D>' ts' sb') next case (SBWriteVolatile a D f A L R W) then obtain "is": "is = Write True a (D, f) A L R W#is'" and \<O>': "\<O>'=\<O>" and \<R>': "\<R>'=\<R>" and \<S>': "\<S>'=\<S>" and \<D>': "\<D>'=\<D>" and m': "m'=m" and \<theta>': "\<theta>'=\<theta>" and sb': "sb' = sb@[Write\<^sub>s\<^sub>b True a (D, f) (f \<theta>) A L R W]" by auto from sim_loc [rule_format, OF i_bound] ts_i "is" obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,Write True a (D,f) A L R W#is',\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" by (auto simp add: Let_def) from sbh_computation.Memop [OF i_bound' ts\<^sub>h_i SBHWriteVolatile ] have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>h[i := (p, is',\<theta>, sb\<^sub>h @ [Write\<^sub>s\<^sub>b True a (D, f) (f \<theta>) A L R W], True, \<O>\<^sub>h,\<R>\<^sub>h)], m, \<S>\<^sub>h)". moreover have "ts [i := (p,is',\<theta>,sb @ [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>) A L R W],\<D>,\<O>,\<R>)] \<sim>\<^sub>h ts\<^sub>h[i := (p,is', \<theta>, sb\<^sub>h @ [Write\<^sub>s\<^sub>b True a (D,f) (f \<theta>) A L R W],True, \<O>\<^sub>h,\<R>\<^sub>h)]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp add: ts' \<O>' \<theta>' m' sb' \<D>' \<R>' \<S>') next case SBFence then obtain "is": "is = Fence #is'" and \<O>': "\<O>'=\<O>" and \<R>': "\<R>'=\<R>" and \<S>': "\<S>'=\<S>" and \<D>': "\<D>'=\<D>" and m': "m'=m" and \<theta>': "\<theta>'=\<theta>" and sb: "sb = []" and sb': "sb' = []" by auto from sim_loc [rule_format, OF i_bound] ts_i sb "is" obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,Fence # is',\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "[] = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" by (auto simp add: Let_def) from filter_is_Write\<^sub>s\<^sub>b_empty [OF sb [symmetric]] have "\<forall>r \<in> set sb\<^sub>h. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r". from flush_reads_program [OF this] obtain \<O>\<^sub>h' \<S>\<^sub>h' \<R>\<^sub>h' where flsh: "(m, sb\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m, [],\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h')" by blast let ?ts\<^sub>h' = "ts\<^sub>h[i := (p,Fence # is', \<theta>, [], \<D>\<^sub>h, \<O>\<^sub>h',\<R>\<^sub>h')]" from sbh_computation.store_buffer_steps [OF flsh i_bound' ts\<^sub>h_i] have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (?ts\<^sub>h', m, \<S>\<^sub>h')". also from i_bound' have i_bound'': "i < length ?ts\<^sub>h'" by auto from i_bound' have ts\<^sub>h'_i: "?ts\<^sub>h'!i = (p,Fence#is',\<theta>,[],\<D>\<^sub>h,\<O>\<^sub>h',\<R>\<^sub>h')" by simp from sbh_computation.Memop [OF i_bound'' ts\<^sub>h'_i SBHFence] i_bound' have "(?ts\<^sub>h', m, \<S>\<^sub>h') \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>h[i := (p, is',\<theta>, [], False, \<O>\<^sub>h',Map.empty)], m,\<S>\<^sub>h')" by (simp) finally have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h[i := (p, is', \<theta>, [],False, \<O>\<^sub>h',Map.empty)],m, \<S>\<^sub>h')". moreover have "ts [i := (p,is',\<theta>,[],\<D>,\<O>,\<R>)] \<sim>\<^sub>h ts\<^sub>h[i := (p,is', \<theta>, [],False, \<O>\<^sub>h',Map.empty)]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp add: ts' \<O>' \<theta>' m' sb' \<D>' \<S>' \<R>') next case (SBRMWReadOnly cond t a D f ret A L R W) then obtain "is": "is = RMW a t (D, f) cond ret A L R W#is'" and \<O>': "\<O>'=\<O>" and \<R>': "\<R>'=\<R>" and \<S>': "\<S>'=\<S>" and \<D>': "\<D>'=\<D>" and m': "m'=m" and \<theta>': "\<theta>'=\<theta>(t \<mapsto> m a)" and sb: "sb=[]" and sb': "sb' = []" and cond: "\<not> cond (\<theta>(t \<mapsto> m a))" by auto from sim_loc [rule_format, OF i_bound] ts_i sb "is" obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,RMW a t (D, f) cond ret A L R W# is',\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "[] = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" by (auto simp add: Let_def) from filter_is_Write\<^sub>s\<^sub>b_empty [OF sb [symmetric]] have "\<forall>r \<in> set sb\<^sub>h. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r". from flush_reads_program [OF this] obtain \<O>\<^sub>h' \<S>\<^sub>h' \<R>\<^sub>h' where flsh: "(m, sb\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m, [],\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h')" by blast let ?ts\<^sub>h' = "ts\<^sub>h[i := (p,RMW a t (D, f) cond ret A L R W# is',\<theta>, [], \<D>\<^sub>h, \<O>\<^sub>h',\<R>\<^sub>h')]" from sbh_computation.store_buffer_steps [OF flsh i_bound' ts\<^sub>h_i] have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (?ts\<^sub>h', m, \<S>\<^sub>h')". also from i_bound' have i_bound'': "i < length ?ts\<^sub>h'" by auto from i_bound' have ts\<^sub>h'_i: "?ts\<^sub>h'!i = (p,RMW a t (D, f) cond ret A L R W#is',\<theta>,[],\<D>\<^sub>h,\<O>\<^sub>h',\<R>\<^sub>h')" by simp note step= SBHRMWReadOnly [where cond=cond and \<theta>=\<theta> and m=m, OF cond ] from sbh_computation.Memop [OF i_bound'' ts\<^sub>h'_i step ] i_bound' have "(?ts\<^sub>h', m, \<S>\<^sub>h') \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>h[i := (p, is',\<theta>(t\<mapsto>m a), [], False, \<O>\<^sub>h',Map.empty)],m, \<S>\<^sub>h')" by (simp) finally have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h[i := (p, is',\<theta>(t\<mapsto>m a), [], False, \<O>\<^sub>h',Map.empty)],m, \<S>\<^sub>h')". moreover have "ts [i := (p,is',\<theta>(t\<mapsto>m a),[],\<D>,\<O>,\<R>)] \<sim>\<^sub>h ts\<^sub>h[i := (p,is', \<theta>(t\<mapsto>m a), [], False, \<O>\<^sub>h',Map.empty)]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp add: ts' \<O>' \<theta>' m' sb' \<D>' \<S>' \<R>') next case (SBRMWWrite cond t a D f ret A L R W) then obtain "is": "is = RMW a t (D, f) cond ret A L R W#is'" and \<O>': "\<O>'=\<O>" and \<R>': "\<R>'=\<R>" and \<S>': "\<S>'=\<S>" and \<D>': "\<D>'=\<D>" and m': "m'=m(a := f (\<theta>(t \<mapsto> (m a))))" and \<theta>': "\<theta>'=\<theta>(t \<mapsto> ret (m a) (f (\<theta>(t \<mapsto> (m a)))))" and sb: "sb=[]" and sb': "sb' = []" and cond: "cond (\<theta>(t \<mapsto> m a))" by auto from sim_loc [rule_format, OF i_bound] ts_i sb "is" obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h acq\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,RMW a t (D, f) cond ret A L R W# is',\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "[] = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" by (auto simp add: Let_def) from filter_is_Write\<^sub>s\<^sub>b_empty [OF sb [symmetric]] have "\<forall>r \<in> set sb\<^sub>h. is_Read\<^sub>s\<^sub>b r \<or> is_Prog\<^sub>s\<^sub>b r \<or> is_Ghost\<^sub>s\<^sub>b r". from flush_reads_program [OF this] obtain \<O>\<^sub>h' \<S>\<^sub>h' \<R>\<^sub>h' where flsh: "(m, sb\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m, [],\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h')" by blast let ?ts\<^sub>h' = "ts\<^sub>h[i := (p,RMW a t (D, f) cond ret A L R W# is',\<theta>, [], \<D>\<^sub>h, \<O>\<^sub>h',\<R>\<^sub>h')]" from sbh_computation.store_buffer_steps [OF flsh i_bound' ts\<^sub>h_i] have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (?ts\<^sub>h', m, \<S>\<^sub>h')". also from i_bound' have i_bound'': "i < length ?ts\<^sub>h'" by auto from i_bound' have ts\<^sub>h'_i: "?ts\<^sub>h'!i = (p,RMW a t (D, f) cond ret A L R W#is',\<theta>,[],\<D>\<^sub>h,\<O>\<^sub>h',\<R>\<^sub>h')" by simp note step= SBHRMWWrite [where cond=cond and \<theta>=\<theta> and m=m, OF cond] from sbh_computation.Memop [OF i_bound'' ts\<^sub>h'_i step ] i_bound' have "(?ts\<^sub>h', m, \<S>\<^sub>h') \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>h[i := (p, is', \<theta>(t \<mapsto> ret (m a) (f (\<theta>(t \<mapsto> (m a))))), [], False, \<O>\<^sub>h' \<union> A - R,Map.empty)], m(a := f (\<theta>(t \<mapsto> (m a)))),\<S>\<^sub>h' \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (simp) finally have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h[i := (p, is', \<theta>(t \<mapsto> ret (m a) (f (\<theta>(t \<mapsto> (m a))))), [], False, \<O>\<^sub>h' \<union> A - R,Map.empty)], m(a := f (\<theta>(t \<mapsto> (m a)))),\<S>\<^sub>h' \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)". moreover have "ts [i := (p,is',\<theta>(t \<mapsto> ret (m a) (f (\<theta>(t \<mapsto> (m a))))),[],\<D>,\<O>,\<R>)] \<sim>\<^sub>h ts\<^sub>h[i := (p,is',\<theta>(t \<mapsto> ret (m a) (f (\<theta>(t \<mapsto> (m a))))), [],False, \<O>\<^sub>h' \<union> A - R,Map.empty)]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp add: ts' \<O>' \<theta>' m' sb' \<D>' \<S>' \<R>') next case (SBGhost A L R W) then obtain "is": "is = Ghost A L R W#is'" and \<O>': "\<O>'=\<O>" and \<R>': "\<R>'=\<R>" and \<S>': "\<S>'=\<S>" and \<D>': "\<D>'=\<D>" and m': "m'=m" and \<theta>': "\<theta>'=\<theta>" and sb': "sb' = sb" by auto from sim_loc [rule_format, OF i_bound] ts_i "is" obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,Ghost A L R W# is',\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" and sb_empty: "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h = [] \<longrightarrow> sb\<^sub>h=[]" by (auto simp add: Let_def) let ?ts\<^sub>h_i' = "(p, is', \<theta>, sb\<^sub>h@[Ghost\<^sub>s\<^sub>b A L R W],\<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)" let ?ts\<^sub>h' = "ts\<^sub>h[i := ?ts\<^sub>h_i']" note step= SBHGhost from sbh_computation.Memop [OF i_bound' ts\<^sub>h_i step ] i_bound' have step: "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (?ts\<^sub>h',m, \<S>\<^sub>h)" by (simp) from sb have sb: "sb = filter is_Write\<^sub>s\<^sub>b (sb\<^sub>h @ [Ghost\<^sub>s\<^sub>b A L R W])" by simp show ?thesis proof (cases "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h = []") case False have "ts [i := (p,is',\<theta>,sb,\<D>,\<O>,\<R>)] \<sim>\<^sub>h ?ts\<^sub>h'" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb sb_empty False apply (auto simp add: Let_def nth_list_update) done with step show ?thesis by (auto simp del: fun_upd_apply simp add: \<S>' m' ts' \<O>' \<D>' \<theta>' sb' \<R>') next case True with sb_empty have empty: "sb\<^sub>h=[]" by simp from i_bound' have "?ts\<^sub>h'!i = ?ts\<^sub>h_i'" by auto from sbh_computation.StoreBuffer [OF _ this, simplified empty, simplified, OF _ flush_step.Ghost, of m \<S>\<^sub>h] i_bound' have "(?ts\<^sub>h', m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>h[i := (p, is', \<theta>, [], \<D>\<^sub>h, \<O>\<^sub>h \<union> A - R,augment_rels (dom \<S>\<^sub>h) R \<R>\<^sub>h)], m, \<S>\<^sub>h \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by (simp add: empty) with step have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h[i := (p, is', \<theta>, [], \<D>\<^sub>h, \<O>\<^sub>h \<union> A - R,augment_rels (dom \<S>\<^sub>h) R \<R>\<^sub>h)], m, \<S>\<^sub>h \<oplus>\<^bsub>W\<^esub> R \<ominus>\<^bsub>A\<^esub> L)" by force moreover have "ts [i := (p,is',\<theta>,sb,\<D>,\<O>,\<R>)] \<sim>\<^sub>h ts\<^sub>h[i := (p, is', \<theta>, [], \<D>\<^sub>h, \<O>\<^sub>h \<union> A - R,augment_rels (dom \<S>\<^sub>h) R \<R>\<^sub>h)]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb empty apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp del: fun_upd_apply simp add: \<S>' m' ts' \<O>' \<theta>' \<D>' sb' \<R>') qed qed next case (Program i _ p "is" \<theta> sb \<D> \<O> \<R> p' "is'") then obtain ts': "ts' = ts[i := (p', is@is',\<theta>, sb, \<D>, \<O>,\<R>)]" and i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, \<theta>,sb,\<D>, \<O>,\<R>)" and prog_step: "\<theta>\<turnstile> p \<rightarrow>\<^sub>p (p', is')" and \<S>': "\<S>'=\<S>" and m': "m'=m" by auto from sim obtain lts_eq: "length ts = length ts\<^sub>h" and sim_loc: "\<forall>i < length ts. (\<exists>\<O>' \<D>' \<R>'. let (p,is,\<theta>, sb, \<D>, \<O>,\<R>) = ts\<^sub>h!i in ts!i=(p,is, \<theta>, filter is_Write\<^sub>s\<^sub>b sb,\<D>',\<O>',\<R>') \<and> (filter is_Write\<^sub>s\<^sub>b sb = [] \<longrightarrow> sb = []))" by cases auto from sim_loc [rule_format, OF i_bound] ts_i obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h acq\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,is,\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" and sb_empty: "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h = [] \<longrightarrow> sb\<^sub>h=[]" by (auto simp add: Let_def) from lts_eq i_bound have i_bound': "i < length ts\<^sub>h" by simp let ?ts\<^sub>h_i' = "(p', is @ is',\<theta>, sb\<^sub>h @ [Prog\<^sub>s\<^sub>b p p' is'], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)" let ?ts\<^sub>h' = "ts\<^sub>h[i := ?ts\<^sub>h_i']" from sbh_computation.Program [OF i_bound' ts\<^sub>h_i prog_step] have step: "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (?ts\<^sub>h',m, \<S>\<^sub>h)". show ?thesis proof (cases "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h = []") case False have "ts[i := (p', is@is', \<theta>, sb,\<D>, \<O>,\<R>)] \<sim>\<^sub>h ?ts\<^sub>h'" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb False sb_empty apply (auto simp add: Let_def nth_list_update) done with step show ?thesis by (auto simp add: ts' \<S>' m') next case True with sb_empty have empty: "sb\<^sub>h=[]" by simp from i_bound' have "?ts\<^sub>h'!i = ?ts\<^sub>h_i'" by auto from sbh_computation.StoreBuffer [OF _ this, simplified empty, simplified, OF _ flush_step.Prog\<^sub>s\<^sub>b, of m \<S>\<^sub>h] i_bound' have "(?ts\<^sub>h', m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>h[i := (p', is@is', \<theta>, [], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)], m, \<S>\<^sub>h)" by (simp add: empty) with step have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h[i := (p', is@is', \<theta>, [], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)], m, \<S>\<^sub>h) " by force moreover have "ts[i := (p', is@is', \<theta>, sb,\<D>, \<O>,\<R>)] \<sim>\<^sub>h ts\<^sub>h[i := (p', is@is', \<theta>, [], \<D>\<^sub>h, \<O>\<^sub>h,\<R>\<^sub>h)]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb empty apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp del: fun_upd_apply simp add: \<S>' m' ts') qed next case (StoreBuffer i _ p "is" \<theta> sb \<D> \<O> \<R> _ _ _ sb' \<O>' \<R>') then obtain ts': "ts' = ts[i := (p, is,\<theta>, sb', \<D>, \<O>',\<R>')]" and i_bound: "i < length ts" and ts_i: "ts ! i = (p, is,\<theta>,sb, \<D>, \<O>,\<R>)" and sb_step: "(m,sb,\<O>,\<R>,\<S>) \<rightarrow>\<^sub>w (m', sb',\<O>',\<R>',\<S>')" by auto from sim obtain lts_eq: "length ts = length ts\<^sub>h" and sim_loc: "\<forall>i < length ts. (\<exists>\<O>' \<D>' \<R>'. let (p,is, \<theta>, sb,\<D>, \<O>,\<R>) = ts\<^sub>h!i in ts!i=(p,is, \<theta>, filter is_Write\<^sub>s\<^sub>b sb,\<D>',\<O>',\<R>') \<and> (filter is_Write\<^sub>s\<^sub>b sb = [] \<longrightarrow> sb=[]))" by cases auto from sim_loc [rule_format, OF i_bound] ts_i obtain sb\<^sub>h \<O>\<^sub>h \<R>\<^sub>h \<D>\<^sub>h acq\<^sub>h where ts\<^sub>h_i: "ts\<^sub>h!i = (p,is,\<theta>,sb\<^sub>h,\<D>\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h)" and sb: "sb = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h" and sb_empty: "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h = [] \<longrightarrow> sb\<^sub>h=[]" by (auto simp add: Let_def) from lts_eq i_bound have i_bound': "i < length ts\<^sub>h" by simp from flush_simulates_filter_writes [OF sb_step sb, of \<O>\<^sub>h \<R>\<^sub>h \<S>\<^sub>h] obtain sb\<^sub>h' \<O>\<^sub>h' \<R>\<^sub>h' \<S>\<^sub>h' where flush': "(m, sb\<^sub>h,\<O>\<^sub>h,\<R>\<^sub>h,\<S>\<^sub>h) \<rightarrow>\<^sub>f\<^sup>* (m', sb\<^sub>h',\<O>\<^sub>h',\<R>\<^sub>h',\<S>\<^sub>h')" and sb': "sb' = filter is_Write\<^sub>s\<^sub>b sb\<^sub>h'" and sb'_empty: "filter is_Write\<^sub>s\<^sub>b sb\<^sub>h' = [] \<longrightarrow> sb\<^sub>h'=[]" by auto from sb_step obtain volatile a sop v A L R W where "sb=Write\<^sub>s\<^sub>b volatile a sop v A L R W#sb'" by cases force from sbh_computation.store_buffer_steps [OF flush' i_bound' ts\<^sub>h_i] have "(ts\<^sub>h, m, \<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h[i := (p, is, \<theta>, sb\<^sub>h',\<D>\<^sub>h, \<O>\<^sub>h',\<R>\<^sub>h')], m', \<S>\<^sub>h')". moreover have "ts[i := (p, is, \<theta>, sb',\<D>, \<O>',\<R>')] \<sim>\<^sub>h ts\<^sub>h[i := (p, is, \<theta>, sb\<^sub>h',\<D>\<^sub>h, \<O>\<^sub>h',\<R>\<^sub>h')]" apply (rule sim_history_config.intros) using lts_eq apply simp using sim_loc i_bound i_bound' sb sb' sb'_empty apply (auto simp add: Let_def nth_list_update) done ultimately show ?thesis by (auto simp add: ts' ) qed qed theorem (in valid_program) concurrent_history_steps_simulates_store_buffer_steps: assumes step_sb: "(ts,m,\<S>) \<Rightarrow>\<^sub>s\<^sub>b\<^sup>* (ts',m',\<S>')" shows "\<And>ts\<^sub>h \<S>\<^sub>h. ts \<sim>\<^sub>h ts\<^sub>h \<Longrightarrow> \<exists>ts\<^sub>h' \<S>\<^sub>h'. (ts\<^sub>h,m,\<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h',m',\<S>\<^sub>h') \<and> ts' \<sim>\<^sub>h ts\<^sub>h'" using step_sb proof (induct rule: converse_rtranclp_induct_sbh_steps) case refl thus ?case by auto next case (step ts m \<S> ts'' m'' \<S>'' ) have first: "(ts,m,\<S>) \<Rightarrow>\<^sub>s\<^sub>b (ts'',m'',\<S>'')" by fact have sim: "ts \<sim>\<^sub>h ts\<^sub>h" by fact from concurrent_history_steps_simulates_store_buffer_step [OF first sim, of \<S>\<^sub>h] obtain ts\<^sub>h'' \<S>\<^sub>h'' where exec: "(ts\<^sub>h,m,\<S>\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h'',m'',\<S>\<^sub>h'')" and sim: "ts'' \<sim>\<^sub>h ts\<^sub>h''" by auto from step.hyps (3) [OF sim, of \<S>\<^sub>h''] obtain ts\<^sub>h' \<S>\<^sub>h' where exec_rest: "(ts\<^sub>h'',m'',\<S>\<^sub>h'') \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h',m',\<S>\<^sub>h')" and sim': "ts' \<sim>\<^sub>h ts\<^sub>h'" by auto note exec also note exec_rest finally show ?case using sim' by blast qed theorem (in xvalid_program_progress) concurrent_direct_execution_simulates_store_buffer_execution: assumes exec_sb: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,x) \<Rightarrow>\<^sub>s\<^sub>b\<^sup>* (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',x')" assumes init: "initial\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b" assumes valid: "valid ts\<^sub>s\<^sub>b" (* FIXME: move into initial ?*) assumes sim: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" assumes safe: "safe_reach_direct safe_free_flowing (ts,m,\<S>)" shows "\<exists>ts\<^sub>h' \<S>\<^sub>h' ts' m' \<S>'. (ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h',m\<^sub>s\<^sub>b',\<S>\<^sub>h') \<and> ts\<^sub>s\<^sub>b' \<sim>\<^sub>h ts\<^sub>h' \<and> (ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>') \<and> (ts\<^sub>h',m\<^sub>s\<^sub>b',\<S>\<^sub>h') \<sim> (ts',m',\<S>')" proof - from init interpret ini: initial\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b . from concurrent_history_steps_simulates_store_buffer_steps [OF exec_sb ini.history_refl, of \<S>\<^sub>s\<^sub>b] obtain ts\<^sub>h' \<S>\<^sub>h' where sbh: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h',m\<^sub>s\<^sub>b',\<S>\<^sub>h')" and sim_sbh: "ts\<^sub>s\<^sub>b' \<sim>\<^sub>h ts\<^sub>h'" by auto from concurrent_direct_execution_simulates_store_buffer_history_execution [OF sbh init valid sim safe] obtain ts' m' \<S>' where d: "(ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>')" and d_sim: "(ts\<^sub>h',m\<^sub>s\<^sub>b',\<S>\<^sub>h') \<sim> (ts',m',\<S>')" by auto with sbh sim_sbh show ?thesis by blast qed inductive sim_direct_config:: "('p,'p store_buffer,'dirty,'owns,'rels) thread_config list \<Rightarrow> ('p,unit,bool,'owns','rels') thread_config list \<Rightarrow> bool" ("_ \<sim>\<^sub>d _ " [60,60] 100) where "\<lbrakk>length ts = length ts\<^sub>d; \<forall>i < length ts. (\<exists>\<O>' \<D>' \<R>'. let (p,is, \<theta>,sb,\<D>, \<O>,\<R>) = ts\<^sub>d!i in ts!i=(p,is, \<theta>, [] ,\<D>',\<O>',\<R>')) \<rbrakk> \<Longrightarrow> ts \<sim>\<^sub>d ts\<^sub>d" lemma empty_sb_sims: assumes empty: "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts\<^sub>s\<^sub>b \<longrightarrow> ts\<^sub>s\<^sub>b!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[]" assumes sim_h: "ts\<^sub>s\<^sub>b \<sim>\<^sub>h ts\<^sub>h" assumes sim_d: "(ts\<^sub>h,m\<^sub>h,\<S>\<^sub>h) \<sim> (ts,m,\<S>)" shows "ts\<^sub>s\<^sub>b \<sim>\<^sub>d ts \<and> m\<^sub>h=m \<and> length ts\<^sub>s\<^sub>b = length ts" proof- from sim_h empty have empty': "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts\<^sub>h \<longrightarrow> ts\<^sub>h!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[]" apply (cases) apply clarsimp subgoal for i apply (drule_tac x=i in spec) apply (auto simp add: Let_def) done done from sim_h sim_config_emptyE [OF empty' sim_d] show ?thesis apply cases apply clarsimp apply (rule sim_direct_config.intros) apply clarsimp apply clarsimp using empty' subgoal for i apply (drule_tac x=i in spec) apply (drule_tac x=i in spec) apply (drule_tac x=i in spec) apply (auto simp add: Let_def) done done qed lemma empty_d_sims: assumes sim: "ts\<^sub>s\<^sub>b \<sim>\<^sub>d ts" shows "\<exists>ts\<^sub>h. ts\<^sub>s\<^sub>b \<sim>\<^sub>h ts\<^sub>h \<and> (ts\<^sub>h,m,\<S>) \<sim> (ts,m,\<S>)" proof - from sim obtain leq: "length ts\<^sub>s\<^sub>b = length ts" and sim: "\<forall>i < length ts\<^sub>s\<^sub>b. (\<exists>\<O>' \<D>' \<R>'. let (p,is, \<theta>,sb,\<D>, \<O>,\<R>) = ts!i in ts\<^sub>s\<^sub>b!i=(p,is, \<theta>, [] ,\<D>',\<O>',\<R>'))" by cases auto define ts\<^sub>h where "ts\<^sub>h \<equiv> map (\<lambda>(p,is, \<theta>,sb,\<D>, \<O>,\<R>). (p,is, \<theta>,[]::'a memref list,\<D>, \<O>,\<R>)) ts" have "ts\<^sub>s\<^sub>b \<sim>\<^sub>h ts\<^sub>h" apply (rule sim_history_config.intros) using leq sim apply (auto simp add: ts\<^sub>h_def Let_def leq) done moreover have empty: "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts\<^sub>h \<longrightarrow> ts\<^sub>h!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[]" apply (clarsimp simp add: ts\<^sub>h_def Let_def) subgoal for i apply (case_tac "ts!i") apply auto done done have "(ts\<^sub>h,m,\<S>) \<sim> (ts,m,\<S>)" apply (rule sim_config_emptyI [OF empty]) apply (clarsimp simp add: ts\<^sub>h_def) apply (clarsimp simp add: ts\<^sub>h_def Let_def) subgoal for i apply (case_tac "ts!i") apply auto done done ultimately show ?thesis by blast qed theorem (in xvalid_program_progress) concurrent_direct_execution_simulates_store_buffer_execution_empty: assumes exec_sb: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,x) \<Rightarrow>\<^sub>s\<^sub>b\<^sup>* (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',x')" assumes init: "initial\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b" assumes valid: "valid ts\<^sub>s\<^sub>b" (* FIXME: move into initial ?*) assumes empty: "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts\<^sub>s\<^sub>b' \<longrightarrow> ts\<^sub>s\<^sub>b'!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[]" assumes sim: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" assumes safe: "safe_reach_direct safe_free_flowing (ts,m,\<S>)" shows "\<exists>ts' \<S>'. (ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m\<^sub>s\<^sub>b',\<S>') \<and> ts\<^sub>s\<^sub>b' \<sim>\<^sub>d ts'" proof - from concurrent_direct_execution_simulates_store_buffer_execution [OF exec_sb init valid sim safe] obtain ts\<^sub>h' \<S>\<^sub>h' ts' m' \<S>' where "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h',m\<^sub>s\<^sub>b',\<S>\<^sub>h')" and sim_h: "ts\<^sub>s\<^sub>b' \<sim>\<^sub>h ts\<^sub>h'" and exec: "(ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>')" and sim: "(ts\<^sub>h',m\<^sub>s\<^sub>b',\<S>\<^sub>h') \<sim> (ts',m',\<S>')" by auto from empty_sb_sims [OF empty sim_h sim] obtain "ts\<^sub>s\<^sub>b' \<sim>\<^sub>d ts'" "m\<^sub>s\<^sub>b' = m'" "length ts\<^sub>s\<^sub>b' = length ts'" by auto thus ?thesis using exec by blast qed locale initial\<^sub>d = simple_ownership_distinct + read_only_unowned + unowned_shared + fixes valid assumes empty_is: "\<lbrakk>i < length ts; ts!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<rbrakk> \<Longrightarrow> is=[]" assumes empty_rels: "\<lbrakk>i < length ts; ts!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<rbrakk> \<Longrightarrow> \<R>=Map.empty" assumes valid_init: "valid (map (\<lambda>(p,is, \<theta>,sb,\<D>, \<O>,\<R>). (p,is, \<theta>,[],\<D>, \<O>,\<R>)) ts)" locale empty_store_buffers = fixes ts::"('p,'p store_buffer,bool,owns,rels) thread_config list" assumes empty_sb: "\<lbrakk>i < length ts; ts!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<rbrakk> \<Longrightarrow> sb=[]" lemma initial_d_sb: assumes init: "initial\<^sub>d ts \<S> valid" shows "initial\<^sub>s\<^sub>b (map (\<lambda>(p,is, \<theta>,sb,\<D>, \<O>,\<R>). (p,is, \<theta>,[],\<D>, \<O>,\<R>)) ts) \<S>" (is "initial\<^sub>s\<^sub>b ?map \<S>") proof - from init interpret ini: initial\<^sub>d ts \<S> . show ?thesis proof (intro_locales) show "simple_ownership_distinct ?map" apply (clarsimp simp add: simple_ownership_distinct_def) subgoal for i j apply (case_tac "ts!i") apply (case_tac "ts!j") apply (cut_tac i=i and j=j in ini.simple_ownership_distinct) apply clarsimp apply clarsimp apply clarsimp apply assumption apply assumption apply auto done done next show "read_only_unowned \<S> ?map" apply (clarsimp simp add: read_only_unowned_def) subgoal for i apply (case_tac "ts!i") apply (cut_tac i=i in ini.read_only_unowned) apply clarsimp apply assumption apply auto done done next show "unowned_shared \<S> ?map" apply (clarsimp simp add: unowned_shared_def') apply (rule ini.unowned_shared') apply clarsimp subgoal for a i apply (case_tac "ts!i") apply auto done done next show "initial\<^sub>s\<^sub>b_axioms ?map" apply (unfold_locales) subgoal for i apply (case_tac "ts!i") apply simp done subgoal for i apply (case_tac "ts!i") apply clarsimp apply (rule_tac i=i in ini.empty_is) apply clarsimp apply fastforce done subgoal for i apply (case_tac "ts!i") apply clarsimp apply (rule_tac i=i in ini.empty_rels) apply clarsimp apply fastforce done done qed qed theorem (in xvalid_program_progress) store_buffer_execution_result_sequential_consistent: assumes exec_sb: "(ts\<^sub>s\<^sub>b,m,x) \<Rightarrow>\<^sub>s\<^sub>b\<^sup>* (ts\<^sub>s\<^sub>b',m',x')" assumes empty': "empty_store_buffers ts\<^sub>s\<^sub>b'" assumes sim: "ts\<^sub>s\<^sub>b \<sim>\<^sub>d ts" assumes init: "initial\<^sub>d ts \<S> valid" assumes safe: "safe_reach_direct safe_free_flowing (ts,m,\<S>)" shows "\<exists>ts' \<S>'. (ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>') \<and> ts\<^sub>s\<^sub>b' \<sim>\<^sub>d ts'" proof - from empty' have empty': "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts\<^sub>s\<^sub>b' \<longrightarrow> ts\<^sub>s\<^sub>b'!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[]" by (auto simp add: empty_store_buffers_def) define ts\<^sub>h where "ts\<^sub>h \<equiv> map (\<lambda>(p,is, \<theta>,sb,\<D>, \<O>,\<R>). (p,is, \<theta>,[]::'a memref list,\<D>, \<O>,\<R>)) ts" from initial_d_sb [OF init] have init_h:"initial\<^sub>s\<^sub>b ts\<^sub>h \<S>" by (simp add: ts\<^sub>h_def) from initial\<^sub>d.valid_init [OF init] have valid_h: "valid ts\<^sub>h" by (simp add: ts\<^sub>h_def) from sim obtain leq: "length ts\<^sub>s\<^sub>b = length ts" and sim: "\<forall>i < length ts\<^sub>s\<^sub>b. (\<exists>\<O>' \<D>' \<R>'. let (p,is, \<theta>,sb,\<D>, \<O>,\<R>) = ts!i in ts\<^sub>s\<^sub>b!i=(p,is, \<theta>, [] ,\<D>',\<O>',\<R>'))" by cases auto have sim_h: "ts\<^sub>s\<^sub>b \<sim>\<^sub>h ts\<^sub>h" apply (rule sim_history_config.intros) using leq sim apply (auto simp add: ts\<^sub>h_def Let_def leq) done from concurrent_history_steps_simulates_store_buffer_steps [OF exec_sb sim_h, of \<S>] obtain ts\<^sub>h' \<S>\<^sub>h' where steps_h: "(ts\<^sub>h,m,\<S>) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>h',m',\<S>\<^sub>h')" and sim_h': "ts\<^sub>s\<^sub>b' \<sim>\<^sub>h ts\<^sub>h'" by auto moreover have empty: "\<forall>i p is xs sb \<D> \<O> \<R>. i < length ts\<^sub>h \<longrightarrow> ts\<^sub>h!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<longrightarrow> sb=[]" apply (clarsimp simp add: ts\<^sub>h_def Let_def) subgoal for i apply (case_tac "ts!i") apply auto done done have sim': "(ts\<^sub>h,m,\<S>) \<sim> (ts,m,\<S>)" apply (rule sim_config_emptyI [OF empty]) apply (clarsimp simp add: ts\<^sub>h_def) apply (clarsimp simp add: ts\<^sub>h_def Let_def) subgoal for i apply (case_tac "ts!i") apply auto done done from concurrent_direct_execution_simulates_store_buffer_history_execution [OF steps_h init_h valid_h sim' safe] obtain ts' m'' \<S>'' where steps: "(ts, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts', m'', \<S>'')" and sim': "(ts\<^sub>h', m', \<S>\<^sub>h') \<sim> (ts', m'', \<S>'')" by blast from empty_sb_sims [OF empty' sim_h' sim'] steps show ?thesis by auto qed locale initial\<^sub>v = simple_ownership_distinct + read_only_unowned + unowned_shared + fixes valid assumes empty_is: "\<lbrakk>i < length ts; ts!i=(p,is,xs,sb,\<D>,\<O>,\<R>)\<rbrakk> \<Longrightarrow> is=[]" assumes valid_init: "valid (map (\<lambda>(p,is, \<theta>,sb,\<D>, \<O>,\<R>). (p,is, \<theta>,[],\<D>, \<O>,Map.empty)) ts)" (* term "initial\<^sub>v" context xvalid_program_progress begin term "safe_reach safe_free_flowing (ts,m,\<S>)" theorem (in xvalid_program_progress) store_buffer_execution_result_sequential_consistent': assumes exec_sb: "(ts\<^sub>s\<^sub>b,m,x) \<Rightarrow>\<^sub>s\<^sub>b\<^sup>* (ts\<^sub>s\<^sub>b',m',x')" assumes sim: "ts\<^sub>s\<^sub>b \<sim>\<^sub>d ts" assumes safe: " safe_reach safe_free_flowing (ts,m,\<S>)" shows "\<exists>ts' \<S>'. (ts,m,\<S>) \<Rightarrow>\<^sub>v\<^sup>* (ts',m',\<S>') " *) theorem (in xvalid_program_progress) store_buffer_execution_result_sequential_consistent': assumes exec_sb: "(ts\<^sub>s\<^sub>b,m,x) \<Rightarrow>\<^sub>s\<^sub>b\<^sup>* (ts\<^sub>s\<^sub>b',m',x')" assumes empty': "empty_store_buffers ts\<^sub>s\<^sub>b'" assumes sim: "ts\<^sub>s\<^sub>b \<sim>\<^sub>d ts" assumes init: "initial\<^sub>v ts \<S> valid" assumes safe: "safe_reach_virtual safe_free_flowing (ts,m,\<S>)" shows "\<exists>ts' \<S>'. (ts,m,\<S>) \<Rightarrow>\<^sub>v\<^sup>* (ts',m',\<S>') \<and> ts\<^sub>s\<^sub>b' \<sim>\<^sub>d ts'" proof - define ts\<^sub>d where "ts\<^sub>d == (map (\<lambda>(p,is, \<theta>,sb,\<D>, \<O>,\<R>'). (p,is, \<theta>,sb,\<D>, \<O>,Map.empty::rels)) ts)" have rem_ts: "remove_rels ts\<^sub>d = ts" apply (rule nth_equalityI) apply (simp add: ts\<^sub>d_def remove_rels_def) apply (clarsimp simp add: ts\<^sub>d_def remove_rels_def) subgoal for i apply (case_tac "ts!i") apply clarsimp done done from sim have sim': "ts\<^sub>s\<^sub>b \<sim>\<^sub>d ts\<^sub>d" apply cases apply (rule sim_direct_config.intros) apply (auto simp add: ts\<^sub>d_def) done have init': "initial\<^sub>d ts\<^sub>d \<S> valid" proof (intro_locales) from init have "simple_ownership_distinct ts" by (simp add: initial\<^sub>v_def) then show "simple_ownership_distinct ts\<^sub>d" apply (clarsimp simp add: ts\<^sub>d_def simple_ownership_distinct_def) subgoal for i j apply (case_tac "ts!i") apply (case_tac "ts!j") apply force done done next from init have "read_only_unowned \<S> ts" by (simp add: initial\<^sub>v_def) then show "read_only_unowned \<S> ts\<^sub>d" apply (clarsimp simp add: ts\<^sub>d_def read_only_unowned_def) subgoal for i apply (case_tac "ts!i") apply force done done next from init have "unowned_shared \<S> ts" by (simp add: initial\<^sub>v_def) then show "unowned_shared \<S> ts\<^sub>d" apply (clarsimp simp add: ts\<^sub>d_def unowned_shared_def) apply force done next have eq: "((\<lambda>(p, is, \<theta>, sb, \<D>, \<O>, \<R>). (p, is, \<theta>, [], \<D>, \<O>, \<R>)) \<circ> (\<lambda>(p, is, \<theta>, sb, \<D>, \<O>, \<R>'). (p, is, \<theta>, (), \<D>, \<O>, Map.empty))) = (\<lambda>(p, is, \<theta>, sb, \<D>, \<O>, \<R>'). (p, is, \<theta>, [], \<D>, \<O>, Map.empty))" apply (rule ext) subgoal for x apply (case_tac x) apply auto done done from init have "initial\<^sub>v_axioms ts valid" by (simp add: initial\<^sub>v_def) then show "initial\<^sub>d_axioms ts\<^sub>d valid" apply (clarsimp simp add: ts\<^sub>d_def initial\<^sub>v_axioms_def initial\<^sub>d_axioms_def eq) apply (rule conjI) apply clarsimp subgoal for i apply (case_tac "ts!i") apply force done apply clarsimp subgoal for i apply (case_tac "ts!i") apply force done done qed { fix ts\<^sub>d' m' \<S>' assume exec: "(ts\<^sub>d, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts\<^sub>d', m', \<S>')" have "safe_free_flowing (ts\<^sub>d', m', \<S>')" proof - from virtual_simulates_direct_steps [OF exec] have exec_v: "(ts, m, \<S>) \<Rightarrow>\<^sub>v\<^sup>* (remove_rels ts\<^sub>d', m', \<S>')" by (simp add: rem_ts) have eq: "map (owned \<circ> (\<lambda>(p, is, \<theta>, sb, \<D>, \<O>, \<R>). (p, is, \<theta>, (), \<D>, \<O>, ()))) ts\<^sub>d' = map owned ts\<^sub>d'" by auto from exec_v safe have "safe_free_flowing (remove_rels ts\<^sub>d', m', \<S>')" by (auto simp add: safe_reach_def) then show ?thesis by (auto simp add: safe_free_flowing_def remove_rels_def owned_def eq) qed } hence safe': "safe_reach_direct safe_free_flowing (ts\<^sub>d, m, \<S>)" by (simp add: safe_reach_def) from store_buffer_execution_result_sequential_consistent [OF exec_sb empty' sim' init' safe'] obtain ts\<^sub>d' \<S>' where exec_d: "(ts\<^sub>d, m, \<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts\<^sub>d', m', \<S>')" and sim_d: "ts\<^sub>s\<^sub>b' \<sim>\<^sub>d ts\<^sub>d'" by blast from virtual_simulates_direct_steps [OF exec_d] have "(ts, m, \<S>) \<Rightarrow>\<^sub>v\<^sup>* (remove_rels ts\<^sub>d', m', \<S>')" by (simp add: rem_ts) moreover from sim_d have "ts\<^sub>s\<^sub>b' \<sim>\<^sub>d remove_rels ts\<^sub>d'" apply (cases) apply (rule sim_direct_config.intros) apply (auto simp add: remove_rels_def) done ultimately show ?thesis by auto qed subsection \<open>Plug Together the Two Simulations\<close> corollary (in xvalid_program) concurrent_direct_steps_simulates_store_buffer_step: assumes step_sb: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<Rightarrow>\<^sub>s\<^sub>b (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b')" assumes sim_h: "ts\<^sub>s\<^sub>b \<sim>\<^sub>h ts\<^sub>s\<^sub>b\<^sub>h" assumes sim: "(ts\<^sub>s\<^sub>b\<^sub>h,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b\<^sub>h) \<sim> (ts,m,\<S>) " assumes valid_own: "valid_ownership \<S>\<^sub>s\<^sub>b\<^sub>h ts\<^sub>s\<^sub>b\<^sub>h" assumes valid_sb_reads: "valid_reads m\<^sub>s\<^sub>b ts\<^sub>s\<^sub>b\<^sub>h" assumes valid_hist: "valid_history program_step ts\<^sub>s\<^sub>b\<^sub>h" assumes valid_sharing: "valid_sharing \<S>\<^sub>s\<^sub>b\<^sub>h ts\<^sub>s\<^sub>b\<^sub>h" assumes tmps_distinct: "tmps_distinct ts\<^sub>s\<^sub>b\<^sub>h" assumes valid_sops: "valid_sops ts\<^sub>s\<^sub>b\<^sub>h" assumes valid_dd: "valid_data_dependency ts\<^sub>s\<^sub>b\<^sub>h" assumes load_tmps_fresh: "load_tmps_fresh ts\<^sub>s\<^sub>b\<^sub>h" assumes enough_flushs: "enough_flushs ts\<^sub>s\<^sub>b\<^sub>h" assumes valid_program_history: "valid_program_history ts\<^sub>s\<^sub>b\<^sub>h" assumes valid: "valid ts\<^sub>s\<^sub>b\<^sub>h" assumes safe_reach: "safe_reach_direct safe_delayed (ts,m,\<S>)" shows "\<exists>ts\<^sub>s\<^sub>b\<^sub>h' \<S>\<^sub>s\<^sub>b\<^sub>h'. (ts\<^sub>s\<^sub>b\<^sub>h,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>s\<^sub>b\<^sub>h',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b\<^sub>h') \<and> ts\<^sub>s\<^sub>b' \<sim>\<^sub>h ts\<^sub>s\<^sub>b\<^sub>h' \<and> valid_ownership \<S>\<^sub>s\<^sub>b\<^sub>h' ts\<^sub>s\<^sub>b\<^sub>h' \<and> valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b\<^sub>h' \<and> valid_history program_step ts\<^sub>s\<^sub>b\<^sub>h' \<and> valid_sharing \<S>\<^sub>s\<^sub>b\<^sub>h' ts\<^sub>s\<^sub>b\<^sub>h' \<and> tmps_distinct ts\<^sub>s\<^sub>b\<^sub>h' \<and> valid_data_dependency ts\<^sub>s\<^sub>b\<^sub>h' \<and> valid_sops ts\<^sub>s\<^sub>b\<^sub>h' \<and> load_tmps_fresh ts\<^sub>s\<^sub>b\<^sub>h' \<and> enough_flushs ts\<^sub>s\<^sub>b\<^sub>h' \<and> valid_program_history ts\<^sub>s\<^sub>b\<^sub>h' \<and> valid ts\<^sub>s\<^sub>b\<^sub>h' \<and> (\<exists>ts' \<S>' m'. (ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>') \<and> (ts\<^sub>s\<^sub>b\<^sub>h',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b\<^sub>h') \<sim> (ts',m',\<S>'))" proof - from concurrent_history_steps_simulates_store_buffer_step [OF step_sb sim_h] obtain ts\<^sub>s\<^sub>b\<^sub>h' \<S>\<^sub>s\<^sub>b\<^sub>h' where steps_h: "(ts\<^sub>s\<^sub>b\<^sub>h,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b\<^sub>h) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h\<^sup>* (ts\<^sub>s\<^sub>b\<^sub>h',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b\<^sub>h')" and sim_h': "ts\<^sub>s\<^sub>b' \<sim>\<^sub>h ts\<^sub>s\<^sub>b\<^sub>h'" by blast moreover from concurrent_direct_steps_simulates_store_buffer_history_steps [OF steps_h valid_own valid_sb_reads valid_hist valid_sharing tmps_distinct valid_sops valid_dd load_tmps_fresh enough_flushs valid_program_history valid sim safe_reach] obtain m' ts' \<S>' where "(ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>')" "(ts\<^sub>s\<^sub>b\<^sub>h', m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b\<^sub>h') \<sim> (ts', m', \<S>')" "valid_ownership \<S>\<^sub>s\<^sub>b\<^sub>h' ts\<^sub>s\<^sub>b\<^sub>h'" "valid_reads m\<^sub>s\<^sub>b' ts\<^sub>s\<^sub>b\<^sub>h'" "valid_history program_step ts\<^sub>s\<^sub>b\<^sub>h'" "valid_sharing \<S>\<^sub>s\<^sub>b\<^sub>h' ts\<^sub>s\<^sub>b\<^sub>h'" "tmps_distinct ts\<^sub>s\<^sub>b\<^sub>h'" "valid_data_dependency ts\<^sub>s\<^sub>b\<^sub>h'" "valid_sops ts\<^sub>s\<^sub>b\<^sub>h'" "load_tmps_fresh ts\<^sub>s\<^sub>b\<^sub>h'" "enough_flushs ts\<^sub>s\<^sub>b\<^sub>h'" "valid_program_history ts\<^sub>s\<^sub>b\<^sub>h'" "valid ts\<^sub>s\<^sub>b\<^sub>h'" by blast ultimately show ?thesis by blast qed (* ******************* Some tuned version for presentations ********************************** *) lemma conj_commI: "P \<and> Q \<Longrightarrow> Q \<and> P" by simp lemma def_to_eq: "P = Q \<Longrightarrow> P \<equiv> Q" by simp context xvalid_program begin definition "invariant ts \<S> m \<equiv> valid_ownership \<S> ts \<and> valid_reads m ts \<and> valid_history program_step ts \<and> valid_sharing \<S> ts \<and> tmps_distinct ts \<and> valid_data_dependency ts \<and> valid_sops ts \<and> load_tmps_fresh ts \<and> enough_flushs ts \<and> valid_program_history ts \<and> valid ts" definition "ownership_inv \<equiv> valid_ownership" definition "sharing_inv \<equiv> valid_sharing" definition "temporaries_inv ts \<equiv> tmps_distinct ts \<and> load_tmps_fresh ts" definition "history_inv ts m \<equiv> valid_history program_step ts \<and> valid_program_history ts \<and> valid_reads m ts" definition "data_dependency_inv ts \<equiv> valid_data_dependency ts \<and> load_tmps_fresh ts \<and> valid_sops ts" definition "barrier_inv \<equiv> enough_flushs" lemma invariant_grouped_def: "invariant ts \<S> m \<equiv> ownership_inv \<S> ts \<and> sharing_inv \<S> ts \<and> temporaries_inv ts \<and> data_dependency_inv ts \<and> history_inv ts m \<and> barrier_inv ts \<and> valid ts" apply (rule def_to_eq) apply (auto simp add: ownership_inv_def sharing_inv_def barrier_inv_def temporaries_inv_def history_inv_def data_dependency_inv_def invariant_def) done theorem (in xvalid_program) simulation': assumes step_sb: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<Rightarrow>\<^sub>s\<^sub>b\<^sub>h (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b')" assumes sim: "(ts\<^sub>s\<^sub>b,m\<^sub>s\<^sub>b,\<S>\<^sub>s\<^sub>b) \<sim> (ts,m,\<S>)" assumes inv: "invariant ts\<^sub>s\<^sub>b \<S>\<^sub>s\<^sub>b m\<^sub>s\<^sub>b" assumes safe_reach: "safe_reach_direct safe_delayed (ts,m,\<S>)" shows "invariant ts\<^sub>s\<^sub>b' \<S>\<^sub>s\<^sub>b' m\<^sub>s\<^sub>b' \<and> (\<exists>ts' \<S>' m'. (ts,m,\<S>) \<Rightarrow>\<^sub>d\<^sup>* (ts',m',\<S>') \<and> (ts\<^sub>s\<^sub>b',m\<^sub>s\<^sub>b',\<S>\<^sub>s\<^sub>b') \<sim> (ts',m',\<S>'))" using inv sim safe_reach apply (unfold invariant_def) apply (simp only: conj_assoc) apply (rule "concurrent_direct_steps_simulates_store_buffer_history_step" [OF step_sb]) apply simp_all done lemmas (in xvalid_program) simulation = conj_commI [OF simulation'] end end
Formal statement is: lemma ZfunD: "Zfun f F \<Longrightarrow> 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F" Informal statement is: If $f$ is a Z-function and $r > 0$, then $f$ is eventually less than $r$.
If $f$ is a real-valued function that converges to $-\infty$ as $x$ approaches $-\infty$ along a filter $F$, and $n$ is an odd positive integer, then $f^n$ converges to $-\infty$ as $x$ approaches $-\infty$ along $F$.
[STATEMENT] lemma tensor_smult_distr_right: "(\<alpha> + \<beta>) \<cdot> A = \<alpha> \<cdot> A + \<beta> \<cdot> A" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<alpha> + \<beta>) \<cdot> A = \<alpha> \<cdot> A + \<beta> \<cdot> A [PROOF STEP] unfolding plus_def plus_base_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<alpha> + \<beta>) \<cdot> A = (if dims (\<alpha> \<cdot> A) = dims (\<beta> \<cdot> A) then tensor_from_vec (dims (\<alpha> \<cdot> A)) (vec_plus (vec (\<alpha> \<cdot> A)) (vec (\<beta> \<cdot> A))) else undefined) [PROOF STEP] by (auto; metis smult_def vec_smult_def vec_smult_distr_right)
module bgrid_diagnostics_mod !----------------------------------------------------------------------- use bgrid_horiz_mod, only: horiz_grid_type use bgrid_vert_mod, only: vert_grid_type, compute_pres_full, & compute_pres_half, compute_pres_depth use bgrid_masks_mod, only: grid_mask_type use bgrid_prog_var_mod, only: prog_var_type use bgrid_change_grid_mod, only: change_grid, TEMP_GRID, WIND_GRID use diag_manager_mod, only: diag_axis_init, register_diag_field, & register_static_field, send_data use time_manager_mod, only: time_type use fms_mod, only: file_exist, open_namelist_file, & error_mesg, NOTE, check_nml_error, & mpp_pe, mpp_root_pe, stdlog, & close_file, write_version_number use constants_mod, only: GRAV, KAPPA, RDGAS use field_manager_mod, only: MODEL_ATMOS use tracer_manager_mod, only: get_tracer_names, get_number_tracers implicit none private public :: bgrid_diagnostics_init, & bgrid_diagnostics, & bgrid_diagnostics_tend !----------------------------------------------------------------------- !------------------------- axis names ---------------------------------- character(len=8) :: axiset = 'dynamics' character(len=8) :: mod_name = 'dynamics' !----------------------------------------------------------------------- integer, parameter :: MXTR = 10 real, parameter :: GINV = 1./GRAV !----------------------------------------------------------------------- ! axis and field identifiers for the diag manager integer :: id_hlonb, id_hlon , id_hlatb, id_hlat , & id_vlonb, id_vlon , id_vlatb, id_vlat , & id_phalf, id_pfull, id_hlat_wgt, id_vlat_wgt integer :: id_bk , id_pk , id_zsurf, id_res , id_wspd, & id_ps , id_ucomp, id_vcomp, id_temp , id_pres_full, & id_omega, id_div , id_vor , id_pgfx , id_pgfy, & id_udt , id_vdt , id_tdt , id_pres_half, & id_alm , id_aph , id_theta, id_mfew, id_mfns, id_slp integer, allocatable :: id_tracer(:), id_tracer_tend(:) integer :: id_ucomp_sq, id_vcomp_sq, id_temp_sq, id_omega_sq, & id_ucomp_vcomp, id_omega_temp !----------------------------------------------------------------------- ! need to save surface geopotential height argument to initialization call ! the surface height will be needed for computing sea level pressure real, pointer, dimension(:,:) :: zsurfg !----------------------------------------------------------------------- character(len=128) :: version = '$Id: bgrid_diagnostics.f90,v 11.0 2004/09/28 19:07:18 fms Exp $' character(len=128) :: tag = '$Name: latest $' !----------------------------------------------------------------------- contains !####################################################################### subroutine bgrid_diagnostics_init ( Time, Hgrid, Vgrid, Var, & fis, res, & mass_axes, vel_axes ) !----------------------------------------------------------------------- ! setup/write netcdf metadata and static fields !----------------------------------------------------------------------- ! Time = current/initial time ! Hgrid = horizontal grid constants ! Vgrid = vertical grid constants ! fis = geopotential height of the surface ! res = reciprocal of eta at the surface ! mass_axes = axis identifiers for the temperature (mass) grid ! vel_axes = axis identifiers for the velocity grid ! NOTE: The axes identifiers are for the lon, lat, pfull, and ! phalf axes, respectively. They are returned by the diag_manager. !----------------------------------------------------------------------- type(time_type), intent(in) :: Time type(horiz_grid_type), intent(in) :: Hgrid type (vert_grid_type), intent(in) :: Vgrid type (prog_var_type), intent(in) :: Var real, intent(in), dimension(Hgrid%ilb:,Hgrid%jlb:), target :: fis, res integer, dimension(4), intent(out) :: mass_axes, vel_axes !----------------------------------------------------------------------- real, dimension(Hgrid%Tmp%isg:Hgrid%Tmp%ieg+1) :: hlonb real, dimension(Hgrid%Vel%isg:Hgrid%Vel%ieg+1) :: vlonb real, dimension(Hgrid%Tmp%jsg:Hgrid%Tmp%jeg+1) :: hlatb real, dimension(Hgrid%Vel%jsg:Hgrid%Vel%jeg+1) :: vlatb real, dimension(Hgrid%Tmp%isg:Hgrid%Tmp%ieg) :: hlon real, dimension(Hgrid%Vel%isg:Hgrid%Vel%ieg) :: vlon real, dimension(Hgrid%Tmp%jsg:Hgrid%Tmp%jeg) :: hlat real, dimension(Hgrid%Vel%jsg:Hgrid%Vel%jeg) :: vlat real, dimension(Hgrid%Tmp%js:Hgrid%Tmp%je) :: hlat_wgt real, dimension(Hgrid%Vel%js:Hgrid%Vel%je) :: vlat_wgt real, dimension(1,1) :: psurf real, dimension(1,1,Vgrid%nlev) :: pfull real, dimension(1,1,Vgrid%nlev+1) :: phalf real :: vrange(2), trange(2), prange(2) real :: rad2deg integer :: i, j, n, unit, io, ierr, ntprog integer :: isg, ieg, hsg, heg, vsg, veg integer :: is, ie, hs, he, vs, ve integer :: uflx_axes(4), vflx_axes(4) logical :: used character(len=128) :: tname character(len=256) :: longname, units !--------------------------- set up axes ------------------------------- ! compute grid indices is = Hgrid % Tmp % is; ie = Hgrid % Tmp % ie hs = Hgrid % Tmp % js; he = Hgrid % Tmp % je vs = Hgrid % Vel % js; ve = Hgrid % Vel % je ! global grid indices isg = Hgrid % Tmp % isg; ieg = Hgrid % Tmp % ieg hsg = Hgrid % Tmp % jsg; heg = Hgrid % Tmp % jeg vsg = Hgrid % Vel % jsg; veg = Hgrid % Vel % jeg ! grid box boundaries in degrees rad2deg = 90./acos(0.0) hlonb(isg:ieg+1) = Hgrid % Tmp % blong(isg:ieg+1) * rad2deg hlatb(hsg:heg+1) = Hgrid % Tmp % blatg(hsg:heg+1) * rad2deg vlonb(isg:ieg+1) = Hgrid % Vel % blong(isg:ieg+1) * rad2deg vlatb(vsg:veg+1) = Hgrid % Vel % blatg(vsg:veg+1) * rad2deg ! grid box centers in degrees do i = isg, ieg hlon(i) = 0.5*(hlonb(i)+hlonb(i+1)) vlon(i) = 0.5*(vlonb(i)+vlonb(i+1)) enddo do j = hsg, heg hlat(j) = 0.5*(hlatb(j)+hlatb(j+1)) enddo do j = vsg, veg vlat(j) = 0.5*(vlatb(j)+vlatb(j+1)) enddo ! compute a reference profile of pressure based on psurf = 1000 hPa psurf = reshape ( (/ 100000. /), (/ 1, 1 /) ) call compute_pres_full (Vgrid, psurf, pfull) call compute_pres_half (Vgrid, psurf, phalf) ! in units of hPa pfull = pfull*0.01 phalf = phalf*0.01 !----- initialize mass axes ------ id_hlonb = diag_axis_init ( 'lonb', hlonb, 'degrees_E', 'x', & 'longitude edges', set_name='atmos', & Domain2=Hgrid%Tmp%Domain_nohalo ) id_hlon = diag_axis_init ( 'lon', hlon, 'degrees_E', 'x', & 'longitude', set_name='atmos', & edges=id_hlonb, & Domain2=Hgrid%Tmp%Domain_nohalo ) id_hlatb = diag_axis_init ( 'latb', hlatb, 'degrees_N', 'y', & 'latitude edges', set_name='atmos', & Domain2=Hgrid%Tmp%Domain_nohalo ) id_hlat = diag_axis_init ( 'lat', hlat, 'degrees_N', 'y', & 'latitude', set_name='atmos', & edges=id_hlatb, & Domain2=Hgrid%Tmp%Domain_nohalo ) !----- initialize velocity axes ------ id_vlonb = diag_axis_init ( 'vlonb', vlonb, 'degrees_E', 'x', & 'longitude edges', set_name='atmos', & Domain2=Hgrid%Vel%Domain_nohalo ) id_vlon = diag_axis_init ( 'vlon', vlon, 'degrees_E', 'x', & 'longitude', set_name='atmos', & edges=id_vlonb, & Domain2=Hgrid%Vel%Domain_nohalo ) id_vlatb = diag_axis_init ( 'vlatb', vlatb, 'degrees_N', 'y', & 'latitude edges', set_name='atmos', & Domain2=Hgrid%Vel%Domain_nohalo ) id_vlat = diag_axis_init ( 'vlat', vlat, 'degrees_N', 'y', & 'latitude', set_name='atmos', & edges=id_vlatb, & Domain2=Hgrid%Vel%Domain_nohalo ) !----- initialize vertical axes ----- id_phalf = diag_axis_init ( 'phalf', phalf(1,1,:), 'hPa', 'z', & 'approx half pressure level', & direction=-1, set_name='atmos' ) id_pfull = diag_axis_init ( 'pfull', pfull(1,1,:), 'hPa', 'z', & 'approx full pressure level', & direction=-1, edges=id_phalf, & set_name='atmos' ) !----------------------------------------------------------------------- !-------- initialize and output variables with no time axis ------------ mass_axes = (/ id_hlon, id_hlat, id_pfull, id_phalf /) vel_axes = (/ id_vlon, id_vlat, id_pfull, id_phalf /) uflx_axes = (/ id_vlon, id_hlat, id_pfull, id_phalf /) vflx_axes = (/ id_hlon, id_vlat, id_pfull, id_phalf /) ! valid range for some fields vrange = (/ -400., +400. /) ! momentum trange = (/ 100., 400. /) ! temperature prange = (/ -1., 107500. /) ! pressure !----------------------------------------------------------------------- !---- register static fields ------- id_bk = register_static_field ( mod_name, 'bk', (/id_phalf/), & 'vertical coordinate sigma value', 'none' ) id_pk = register_static_field ( mod_name, 'pk', (/id_phalf/), & 'vertical coordinate reference pressure value (ak*pref)', 'pascals' ) id_zsurf = register_static_field ( mod_name, 'zsurf', mass_axes(1:2),& 'surface height', 'm' ) id_res = register_static_field ( mod_name, 'res', mass_axes(1:2), & 'reciprocal of sigma/eta at the surface', 'none' ) id_alm = register_static_field ( mod_name, 'alm', mass_axes(1:2), & 'actual longitudes for temperature grid', 'degrees_E' ) id_aph = register_static_field ( mod_name, 'aph', mass_axes(1:2), & 'actual latitudes for temperature grid', 'degrees_N' ) ! these changes cannot be implemented until changes to diag_manager ! initialize fields useful for computing offline global averages ! ! id_hlat_wgt = register_static_field ( mod_name, 'lat_wgt', & ! (/id_hlat/), 'latitude weight for mass grid', 'none' ) ! ! id_vlat_wgt = register_static_field ( mod_name, 'vlat_wgt', & ! (/id_vlat/), 'latitude weight for momentum grid', 'none' ) if ( id_bk > 0 ) & used = send_data ( id_bk, Vgrid%eta, Time ) if ( id_pk > 0 ) & used = send_data ( id_pk, Vgrid%peta, Time ) if ( id_zsurf > 0 ) & used = send_data ( id_zsurf, fis(is:ie,hs:he)*GINV, Time ) if ( id_res > 0 ) & used = send_data ( id_res, res(is:ie,hs:he), Time ) if ( id_alm > 0 ) & used = send_data ( id_alm, Hgrid%Tmp%alm(is:ie,hs:he)*rad2deg, Time ) if ( id_aph > 0 ) & used = send_data ( id_aph, Hgrid%Tmp%aph(is:ie,hs:he)*rad2deg, Time ) ! if ( id_hlat_wgt > 0 ) then ! hlat_wgt = sin(Hgrid%Tmp%blatg(hs+1:he+1))-sin(Hgrid%Tmp%blatg(hs:he)) ! used = send_data ( id_hlat_wgt, hlat_wgt, Time ) ! endif ! ! if ( id_vlat_wgt > 0 ) then ! vlat_wgt = sin(Hgrid%Vel%blatg(vs+1:ve+1))-sin(Hgrid%Vel%blatg(vs:ve)) ! used = send_data ( id_vlat_wgt, vlat_wgt, Time ) ! endif !---- register non-static fields ------- id_ps = register_diag_field ( mod_name, 'ps', mass_axes(1:2), & Time, 'surface pressure', 'pascals' ) id_slp = register_diag_field ( mod_name, 'slp', mass_axes(1:2), & Time, 'sea level pressure', 'pascals' ) id_ucomp = register_diag_field ( mod_name, 'ucomp', vel_axes(1:3), & Time, 'zonal wind component', 'm/sec', & missing_value=vrange(1), range=vrange ) id_vcomp = register_diag_field ( mod_name, 'vcomp', vel_axes(1:3), & Time, 'meridional wind component', 'm/sec', & missing_value=vrange(1), range=vrange ) id_temp = register_diag_field ( mod_name, 'temp', mass_axes(1:3), & Time, 'temperature', 'deg_k', & missing_value=trange(1), range=trange ) id_pres_full = register_diag_field ( mod_name, 'pres_full', mass_axes(1:3), & Time, 'pressure at full model levels', 'pascals', & missing_value=prange(1), range=prange ) ! pressure at half levels id_pres_half = register_diag_field ( mod_name, 'pres_half', & (/ id_hlon, id_hlat, id_phalf /), Time, & 'pressure at half model levels', 'pascals', & missing_value=prange(1), range=prange ) id_omega = register_diag_field ( mod_name, 'omega', mass_axes(1:3),& Time, 'omega vertical velocity', & 'pascals/sec', & missing_value=-999. ) id_theta = register_diag_field ( mod_name, 'theta', mass_axes(1:3), & Time, 'potential temperature', 'deg_k', & missing_value=-999. ) id_mfew = register_diag_field ( mod_name, 'mfew', uflx_axes(1:3), & Time, 'Zonal mass flux', 'Pa-m2/s', & missing_value=-1.e30 ) id_mfns = register_diag_field ( mod_name, 'mfns', vflx_axes(1:3), & Time, 'Meridional mass flux', 'Pa-m2/s', & missing_value=-1.e30 ) ! write version (to log file) call write_version_number (version,tag) ! register diagnostics for all tracers allocate (id_tracer(Var%ntrace)) if (mpp_pe() == mpp_root_pe()) write(stdlog(),100) trim(mod_name) do n = 1, Var%ntrace call get_tracer_names ( MODEL_ATMOS, n, tname, longname, units ) if (mpp_pe() == mpp_root_pe()) write(stdlog(),110) trim(tname),trim(longname),trim(units) id_tracer(n) = register_diag_field ( mod_name, trim(tname), & mass_axes(1:3), Time, trim(longname), & trim(units), missing_value=-999. ) enddo 100 format ('Diagnostics for the following tracer fields are available for module name = ',a) 110 format (3x,a,' (',a,'; ',a,')') !-------- register second-moment quantities ------- ! (for now we are only saving fields on the same grids) id_ucomp_sq = register_diag_field ( mod_name, 'ucomp_sq', vel_axes(1:3), & Time, 'zonal wind component squared', 'm2/s2', & missing_value=-1., range=(/0.,vrange(2)**2/) ) id_vcomp_sq = register_diag_field ( mod_name, 'vcomp_sq', vel_axes(1:3), & Time, 'meridional wind component squared', 'm2/s2', & missing_value=-1., range=(/0.,vrange(2)**2/) ) id_temp_sq = register_diag_field ( mod_name, 'temp_sq', mass_axes(1:3), & Time, 'temperature squared', 'deg_K**2', & missing_value=-1., range=(/0.,trange(2)**2/) ) id_omega_sq = register_diag_field ( mod_name, 'omega_sq', mass_axes(1:3),& Time, 'omega vertical velocity squared', & 'Pa**2/s**2', missing_value=-999. ) id_ucomp_vcomp = register_diag_field ( mod_name, 'ucomp_vcomp', vel_axes(1:3),& Time, 'zonal times meridional wind components', 'm2/s2', & missing_value=-1. ) id_omega_temp = register_diag_field ( mod_name, 'omega_temp', mass_axes(1:3),& Time, 'omega vertical velocity time temperature',& 'Pascals*deg_K/sec', missing_value=-999. ) !-------- wind speed, divergence, vorticity ---------------------------- id_wspd = register_diag_field ( mod_name, 'wspd', vel_axes(1:3), & Time, 'wind speed', 'm/s', missing_value=-999.,& range=(/0.,vrange(2)/) ) id_div = register_diag_field ( mod_name, 'div', mass_axes(1:3), & Time, 'divergence', '1/s', missing_value=-999. ) id_vor = register_diag_field ( mod_name, 'vor', mass_axes(1:3), & Time, 'relative vorticity', '1/s', missing_value=-999. ) !--------- pressure gradient components (NOT USED) --------------------- ! id_pgfx = register_diag_field ( mod_name, 'pgfx', vel_axes(1:3), & ! Time, 'zonal pressure gradient force', & ! 'm/s2', missing_value=-999. ) ! id_pgfy = register_diag_field ( mod_name, 'pgfy', vel_axes(1:3), & ! Time, 'meridional pressure gradient force', & ! 'm/s2', missing_value=-999. ) !----------------------------------------------------------------------- ! -------- tendencies --------- id_udt = register_diag_field ( mod_name, 'udt_dyn', vel_axes(1:3), & Time, 'zonal wind tendency for dynamics', & 'm/s2', missing_value=-999. ) id_vdt = register_diag_field ( mod_name, 'vdt_dyn', vel_axes(1:3), & Time, 'meridional wind tendency for dynamics', & 'm/s2', missing_value=-999. ) id_tdt = register_diag_field ( mod_name, 'tdt_dyn', mass_axes(1:3), & Time, 'temperature tendency for dynamics', & 'deg_k/sec', missing_value=-999. ) ! tendencies for prognostic tracers only call get_number_tracers ( MODEL_ATMOS, num_prog=ntprog ) allocate (id_tracer_tend(ntprog)) do n = 1, ntprog call get_tracer_names ( MODEL_ATMOS, n, tname, longname, units ) tname = trim(tname) //'_dt_dyn' longname = trim(longname)//' tendency for dynamics' units = trim(units) //'/s' if (units == 'none') units = '1/sec' if (mpp_pe() == mpp_root_pe()) write(stdlog(),110) trim(tname),trim(longname),trim(units) id_tracer_tend(n) = register_diag_field ( mod_name, trim(tname), & mass_axes(1:3), Time, trim(longname), & trim(units), missing_value=-999. ) enddo ! save surface geopotential height for computing sea level pressure zsurfg => fis !----------------------------------------------------------------------- end subroutine bgrid_diagnostics_init !####################################################################### subroutine bgrid_diagnostics ( Hgrid, Vgrid, Var, Masks, Time, & omega, div, mfew, mfns ) !----------------------------------------------------------------------- ! write netcdf fields !----------------------------------------------------------------------- ! Hgrid = horizontal grid constants ! Vgrid = vertical grid constants ! Var = prognostic variables at diagnostics Time ! Masks = grid box masks for step-mountain topography ! Time = diagnostics time ! omega = omega (vertical velocity) diagnostic !----------------------------------------------------------------------- type(horiz_grid_type), intent(in) :: Hgrid type (vert_grid_type), intent(in) :: Vgrid type (prog_var_type), intent(in) :: Var type(grid_mask_type), intent(in) :: Masks type(time_type), intent(in) :: Time real, intent(in), dimension(Hgrid%ilb:,Hgrid%jlb:,:) :: & omega, div, mfew, mfns ! real, intent(in), dimension(Hgrid%ilb:,Hgrid%jlb:,:), optional ::& ! div, pgfx, pgfy real, dimension(Hgrid%ilb:Hgrid%iub,Hgrid%jlb:Hgrid%jub) :: slp real, dimension(Hgrid%ilb:Hgrid%iub,Hgrid%jlb:Hgrid%jub, & Vgrid%nlev) :: wspd, vor, dp, udp, vdp real, dimension(Hgrid%ilb:Hgrid%iub,Hgrid%jlb:Hgrid%jub, & Vgrid%nlev+1) :: ph logical, dimension(Hgrid%ilb:Hgrid%iub,Hgrid%jlb:Hgrid%jub, & Vgrid%nlev+1) :: lmask !----------------------------------------------------------------------- integer :: is, ie, hs, he, vs, ve, n, j, k logical :: used !----------------------------------------------------------------------- is = Hgrid % Tmp % is; ie = Hgrid % Tmp % ie hs = Hgrid % Tmp % js; he = Hgrid % Tmp % je vs = Hgrid % Vel % js; ve = Hgrid % Vel % je !----------------------------------------------------------------------- !---------------- surface fields --------------------------------------- if ( id_ps > 0 ) & used = send_data ( id_ps , Var%ps(is:ie,hs:he), Time ) !---------------- 3d momentum fields (u & v) --------------------------- if ( id_ucomp > 0 ) & used = send_data ( id_ucomp, Var%u(is:ie,vs:ve,:), Time, & mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) if ( id_vcomp > 0 ) & used = send_data ( id_vcomp, Var%v(is:ie,vs:ve,:), Time, & mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) if ( id_temp > 0 ) & used = send_data ( id_temp, Var%t(is:ie,hs:he,:), Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) do n = 1, Var%ntrace if ( id_tracer(n) > 0 ) & used = send_data ( id_tracer(n), Var%r(is:ie,hs:he,:,n), Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) enddo if ( id_omega > 0 ) & used = send_data ( id_omega, omega(is:ie,hs:he,:), Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) ! pressure at full levels ! Note: not computational efficient to recompute pfull if ( id_pres_full > 0 ) then call compute_pres_full (Vgrid, Var%pssl, dp) used = send_data ( id_pres_full, dp(is:ie,hs:he,:), Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) endif ! pressure at half (interface) levels ! Note: not computational efficient to recompute phalf if ( id_pres_half > 0 ) then call compute_pres_half (Vgrid, Var%pssl, ph) lmask(is:ie,hs:he,1) = .true. lmask(is:ie,hs:he,2:Vgrid%nlev+1) = Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 used = send_data ( id_pres_half, ph(is:ie,hs:he,:), Time, & mask=lmask(is:ie,hs:he,:) ) endif !--- sea level pressure --- if ( id_slp > 0 ) then if ( id_pres_full <= 0 ) call compute_pres_full (Vgrid, Var%pssl, dp) call sea_level_pressure ( Var%ps, zsurfg, dp, Var%t, slp ) used = send_data ( id_slp, slp(is:ie,hs:he), Time ) endif ! potential temperature (compute pfull if necessary) if ( id_theta > 0 ) then if ( id_pres_full <= 0 .and. id_slp <= 0 ) call compute_pres_full (Vgrid, Var%pssl, dp) dp = Var%t * (1000.e2/dp)**KAPPA used = send_data ( id_theta, dp(is:ie,hs:he,:), Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) endif !--------- second moment quantities ---------- if ( id_ucomp_sq > 0 ) & used = send_data ( id_ucomp_sq, Var%u(is:ie,vs:ve,:)**2, Time, & mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) if ( id_vcomp_sq > 0 ) & used = send_data ( id_vcomp_sq, Var%v(is:ie,vs:ve,:)**2, Time, & mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) if ( id_temp_sq > 0 ) & used = send_data ( id_temp_sq, Var%t(is:ie,hs:he,:)**2, Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) if ( id_omega_sq > 0 ) & used = send_data ( id_omega_sq, omega(is:ie,hs:he,:)**2, Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) if ( id_ucomp_vcomp > 0 ) used = send_data ( id_ucomp_vcomp, & Var%u(is:ie,vs:ve,:)*Var%v(is:ie,vs:ve,:), Time, & mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) if ( id_omega_temp > 0 ) used = send_data ( id_omega_temp, & omega(is:ie,hs:he,:)*Var%t(is:ie,hs:he,:), Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) !------------ wind speed, divergence, vorticity ------------------------ if ( id_wspd > 0 ) then wspd(is:ie,vs:ve,:) = sqrt & ( Var%u(is:ie,vs:ve,:)*Var%u(is:ie,vs:ve,:) + & Var%v(is:ie,vs:ve,:)*Var%v(is:ie,vs:ve,:) ) used = send_data ( id_wspd, wspd(is:ie,vs:ve,:), Time, & mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) endif if ( id_div > 0 ) then used = send_data ( id_div, div(is:ie,hs:he,:), Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) endif if ( id_vor > 0 ) then !if ( id_vor > 0 .or. id_div > 0 ) then !--- precompute quantities common to both vor and div --- call compute_pres_depth (Vgrid, Var%pssl, dp) call change_grid (Hgrid, TEMP_GRID, WIND_GRID, dp, udp) vdp = Var%v * udp ! note: using udp to store dp at vel pts udp = Var%u * udp !if ( id_vor > 0 ) then call compute_vorticity (Hgrid, dp, udp, vdp, vor ) used = send_data ( id_vor, vor(is:ie,hs:he,:), Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) !endif !if ( id_div > 0 ) then ! call compute_divergence (Hgrid, dp, udp, vdp, div ) ! used = send_data ( id_div, div(is:ie,hs:he,:), Time, & ! mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) !endif endif !------- mass fluxes (without topography masks) ----------- if ( id_mfew > 0 ) then used = send_data ( id_mfew, mfew(is:ie,hs:he,:), Time ) endif if ( id_mfns > 0 ) then used = send_data ( id_mfns, mfns(is:ie,vs:ve,:), Time ) endif !--------------- pressure gradient components -------------------------- !------------------------ NOT USED ------------------------------------- ! if ( id_pgfx > 0 .and. present(pgfx) ) & ! used = send_data ( id_pgfx, pgfx(is:ie,vs:ve,:), Time, & ! mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) ! if ( id_pgfy > 0 .and. present(pgfy) ) & ! used = send_data ( id_pgfy, pgfy(is:ie,vs:ve,:), Time, & ! mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) !----------------------------------------------------------------------- end subroutine bgrid_diagnostics !####################################################################### subroutine bgrid_diagnostics_tend ( Hgrid, Var_dt, Masks, Time ) !----------------------------------------------------------------------- ! Hgrid = horizontal grid constants ! Var_dt = prognostic variables tendencies FROM ONLY THE DYNAMICS ! Masks = grid box masks for step-mountain topography ! Time = diagnostics time !----------------------------------------------------------------------- type(horiz_grid_type), intent(in) :: Hgrid type (prog_var_type), intent(in) :: Var_dt type(grid_mask_type), intent(in) :: Masks type(time_type), intent(in) :: Time !----------------------------------------------------------------------- integer :: is, ie, hs, he, vs, ve, n logical :: used !----------------------------------------------------------------------- ! compute domain indices is = Hgrid % Tmp % is; ie = Hgrid % Tmp % ie hs = Hgrid % Tmp % js; he = Hgrid % Tmp % je vs = Hgrid % Vel % js; ve = Hgrid % Vel % je !----------------------------------------------------------------------- !---------------- 3d prognostic fields --------------------------- if ( id_udt > 0 ) & used = send_data ( id_udt, Var_dt%u(is:ie,vs:ve,:), Time, & mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) if ( id_vdt > 0 ) & used = send_data ( id_vdt, Var_dt%v(is:ie,vs:ve,:), Time, & mask=Masks%Vel%mask(is:ie,vs:ve,:) > 0.5 ) if ( id_tdt > 0 ) & used = send_data ( id_tdt, Var_dt%t(is:ie,hs:he,:), Time, & mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) do n = 1, Var_dt%ntrace if ( id_tracer_tend(n) > 0 ) & used = send_data ( id_tracer_tend(n), Var_dt%r(is:ie,hs:he,:,n), & Time, mask=Masks%Tmp%mask(is:ie,hs:he,:) > 0.5 ) enddo !----------------------------------------------------------------------- end subroutine bgrid_diagnostics_tend !####################################################################### subroutine compute_vorticity ( Hgrid, dp, udp, vdp, vor ) !----------------------------------------------------------------------- ! Computes relative vorticity on B-grid ! Hgrid = horizontal grid constants ! dp = pressure thickness of model layers at temperature points ! udp = zonal wind, u * dp, at velocity points ! vdp = meridional wind, v * dp, at velocity points ! vor = relative vorticity (1/s) at temperature points !----------------------------------------------------------------------- type(horiz_grid_type), intent(in) :: Hgrid real, intent(in), dimension(Hgrid%ilb:,Hgrid%jlb:,:) :: dp, udp, vdp real, intent(out), dimension(Hgrid%ilb:,Hgrid%jlb:,:) :: vor real,dimension(Hgrid%ilb:Hgrid%iub,Hgrid%jlb:Hgrid%jub) :: & vdy, udx, few, fns integer :: i, j, k, is, ie, js, je is = Hgrid % Tmp % is; ie = Hgrid % Tmp % ie js = Hgrid % Tmp % js; je = Hgrid % Tmp % je do k = 1, size(dp,3) do j = js-1, je vdy(:,j) = vdp(:,j,k)*Hgrid%Vel%dy udx(:,j) = udp(:,j,k)*Hgrid%Vel%dx(j) enddo do j = js, je do i = is-1, ie fns(i,j) = (vdy(i,j-1)+vdy(i,j))*0.5 enddo enddo do j = js-1, je do i = is, ie few(i,j) = (udx(i-1,j)+udx(i,j))*0.5 enddo enddo ! ------ vorticity ------ do j = js, je do i = is, ie vor(i,j,k)=((fns(i,j)-fns(i-1,j))-(few(i,j)-few(i,j-1))) & /(dp(i,j,k)*Hgrid%Tmp%area(j)) enddo enddo enddo end subroutine compute_vorticity !####################################################################### subroutine compute_divergence ( Hgrid, dp, udp, vdp, div ) !----------------------------------------------------------------------- ! Computes divergence on B-grid ! Hgrid = horizontal grid constants ! dp = pressure thickness of model layers at temperature points ! udp = zonal wind, u * dp, at velocity points ! vdp = meridional wind, v * dp, at velocity points ! div = divergence (1/s) at temperature points !----------------------------------------------------------------------- type(horiz_grid_type), intent(in) :: Hgrid real, intent(in), dimension(Hgrid%ilb:,Hgrid%jlb:,:) :: dp, udp, vdp real, intent(out), dimension(Hgrid%ilb:,Hgrid%jlb:,:) :: div real,dimension(Hgrid%ilb:Hgrid%iub,Hgrid%jlb:Hgrid%jub) :: & udy, vdx, few, fns integer :: i, j, k, is, ie, js, je is = Hgrid % Tmp % is; ie = Hgrid % Tmp % ie js = Hgrid % Tmp % js; je = Hgrid % Tmp % je do k = 1, size(dp,3) do j = js-1, je udy(:,j) = udp(:,j,k)*Hgrid%Vel%dy vdx(:,j) = vdp(:,j,k)*Hgrid%Vel%dx(j) enddo do j = js, je do i = is-1, ie few(i,j) = (udy(i,j-1)+udy(i,j))*0.5 enddo enddo do j = js-1, je do i = is, ie fns(i,j) = (vdx(i-1,j)+vdx(i,j))*0.5 enddo enddo ! ------ divergence ------ do j = js, je do i = is, ie div(i,j,k)=((few(i,j)+fns(i,j))-(few(i-1,j)+fns(i,j-1))) & /(dp(i,j,k)*Hgrid%Tmp%area(j)) enddo enddo enddo end subroutine compute_divergence !####################################################################### subroutine sea_level_pressure ( psurf, zsurf, pfull, tfull, slp ) real, intent(in), dimension(:,:) :: psurf, zsurf real, intent(in), dimension(:,:,:) :: pfull, tfull real, intent(out), dimension(:,:) :: slp ! psurf = surface pressure ! zsurf = surface geopotential height in meters^2/sec^2 ! pfull = pressure at full model levels ! tfull = temperature at full model levels ! slp = sea level pressure in pascals integer :: i, j, k, kr real :: sig, tbot real, parameter :: TLAPSE = 6.5e-3 real, parameter :: GORG = GRAV/(RDGAS*TLAPSE) real, parameter :: MRGOG = -1./GORG do j = 1, size(psurf,2) do i = 1, size(psurf,1) if ( abs(zsurf(i,j)) > 0.0001 ) then !---- get ref level for temp ---- do k = 1, size(tfull,3) sig = pfull(i,j,k)/psurf(i,j) if ( sig > 0.8 ) then kr = k exit endif enddo tbot = tfull(i,j,kr) * sig ** MRGOG slp(i,j) = psurf(i,j) * ( 1.0 + TLAPSE * zsurf(i,j) / (tbot*GRAV) ) ** GORG else slp(i,j) = psurf(i,j) endif enddo enddo end subroutine sea_level_pressure !####################################################################### end module bgrid_diagnostics_mod
From Coq Require Import List ssreflect. From Mon Require Import Base. From Mon.SM Require Export SMSyntax. From Mon.sprop Require Import SPropBase SPropMonadicStructures. From Equations Require Equations. (******************************************************************************) (** *) (** Denotation from SM to Gallina *) (** *) (******************************************************************************) (** Denotation of types (discrete order case) *) Section ToType. Context (M:Type -> Type). Fixpoint to_type (c:ctype) {struct c} : Type := match c with | CM A => M A | CProd C1 C2 => to_type C1 × to_type C2 | @CArr A C => forall (x:A), to_type (C x) | CArrC C1 C2 => to_type C1 -> to_type C2 end. End ToType. Notation "⦑ C | M ⦒" := (to_type M C). Section ICTermToTerm. Context (M:Monad). Definition icterm_to_term {Γ c} (ct : icterm Γ c) : substitution (to_type M) Γ -> ⦑ c |M⦒. Proof. induction ct ; intro σ. exact ret. exact (bind (IHct2 σ) (IHct1 σ)). exact (npair (IHct1 σ) (IHct2 σ)). destruct c ; inversion H ; exact (nfst (IHct σ)). destruct c ; inversion H ; exact (nsnd (IHct σ)). intro v ; apply (X v σ). destruct c ; inversion H ; exact (IHct σ v). exact (Substitution.dlookup _ _ σ H). intro x ; exact (IHct (ConsSubst x σ)). destruct c ; inversion H ; exact (IHct1 σ (IHct2 σ)). Defined. End ICTermToTerm. Notation "⦑ t | σ | M ⦒" := (icterm_to_term M t σ). (** Denotation commutes to substitution *) Section ICTermToTermSubst. Import DepElim. Context (M:Monad). Lemma map_subst_comp : forall {Γ var1 var2 var3} (σ : substitution var1 Γ) (f : forall c, var1 c -> var2 c) (g: forall c, var2 c -> var3 c), map_subst g (map_subst f σ) = map_subst (fun c x => g c (f c x)) σ. Proof. unfold map_subst. intros. rewrite <- Substitution.dmap_compose. reflexivity. Qed. (* Lemma to_term_weaken0 {Γ1 Γ2 c} (t:icterm (Γ1++Γ2) c) : *) (* forall c0 (x:⦑c0|M⦒) (σ1 : substitution (to_type M) Γ1) *) (* (σ2 : substitution (to_type M) Γ2), *) (* ⦑ rename0 t (weaken_renaming c0) | appSubst σ1 (ConsSubst x σ2) |M⦒ *) (* = ⦑ t | appSubst σ1 σ2 |M⦒. *) Import Equations. Import EqNotations. Import Substitution. Import FunctionalExtensionality. Lemma to_term_rename {Γ1 c} (t:icterm Γ1 c) : forall Γ2 (σ : substitution (to_type M) Γ2) (ρ : irenaming Γ2 Γ1), ⦑ rename0 t ρ | σ |M⦒ = ⦑ t | renaming_subst_act ρ σ |M⦒. Proof. induction t ; intros Γ2 σ ρ ; simpl. reflexivity. f_equal ; [apply IHt2 | apply IHt1]. f_equal ; [apply IHt1 | apply IHt2]. destruct c ; inversion H ; destruct H ; erewrite IHt ; reflexivity. destruct c ; inversion H ; destruct H ; erewrite IHt ; reflexivity. extensionality v ; apply H. destruct c ; inversion H ; destruct H ; erewrite IHt ; reflexivity. rewrite dlookup_renaming_subst_act. set (z := dlookup n Γ ρ H). destruct z as [n' [Hn Hlkp]]. simpl. symmetry. change (rew ?H in ?x = ?y) with (x =⟨H⟩ y). apply (fun_app_above ctype _ _ Hlkp (icterm Γ2) (to_type M)(fun c ct => @icterm_to_term M Γ2 c ct σ) (ICVar n' (StrictProp.unbox Hn))). extensionality x. move: renaming_weaken (IHt _ (ConsSubst x σ) (cons_renaming c1 ρ)). unfold renaming_subst_act ; unfold cons_renaming. simp dmap; unfold lkp_tyvar_subst ; simp_dlookup. move=> -> //. destruct c ; inversion H ; destruct H; erewrite IHt1 ; erewrite IHt2 ; reflexivity. Qed. Lemma to_term_weaken {Γ c} (t:icterm Γ c) : forall c0 (x:⦑c0|M⦒) (σ : substitution (to_type M) Γ), ⦑ ↑ t | ConsSubst x σ |M⦒ = ⦑ t |σ |M⦒. Proof. intros ; move: (to_term_rename t (c0::Γ) (ConsSubst x σ) (@weaken_renaming c0 nil _)) ; unfold weaken_renaming=> //. rewrite renaming_weaken renaming_subst_act_id //. Qed. Import FunctionalExtensionality. Lemma to_term_isubst {Γ c} (t:icterm Γ c) : forall Γ' (σ : substitution (to_type M) Γ') (ρ : isubstitution Γ' Γ), ⦑ isubst t ρ | σ |M⦒ = ⦑ t | map_subst (fun c m => ⦑ m | σ |M⦒) ρ |M⦒. Proof. induction t ; simpl ; intros Γ' σ ρ. reflexivity. f_equal ; auto. f_equal ; auto. destruct c ; destruct H ; rewrite IHt ; reflexivity. destruct c ; destruct H ; rewrite IHt ; reflexivity. extensionality x ; auto. destruct c ; destruct H ; rewrite IHt ; reflexivity. rewrite dlookup_dmap ; reflexivity. extensionality x; rewrite IHt; simpl; rewrite map_subst_comp; unfold ConsSubst ; do 2 f_equal ; unfold map_subst; apply dmap_ext=> // ? ?; rewrite to_term_weaken; reflexivity. destruct c ; destruct H ; rewrite IHt1; rewrite IHt2; reflexivity. Qed. End ICTermToTermSubst. (** Denotation preserves the equational theory *) Section ICeqToEq. Import DepElim. Context (M:Monad). Let var_eq c := {p:⦑c |M⦒ × ⦑c|M⦒ ⫳ nfst p = nsnd p}. Let efst c (m:var_eq c) := nfst (dfst m). Let esnd c (m:var_eq c) := nsnd (dfst m). (* Let eeq c (m:var_eq c) := dsnd m. *) Import FunctionalExtensionality. Definition icterm_diagonal {Γ c} (ct : icterm Γ c) : forall (σ : substitution var_eq Γ), ⦑ct | map_subst efst σ |M⦒ = ⦑ ct | map_subst esnd σ |M⦒. Proof. induction ct ; simpl ; intros σ. reflexivity. f_equal ; auto. f_equal ; auto. destruct c ; destruct H ; erewrite IHct ; [reflexivity|..] ; eassumption. destruct c ; destruct H ; erewrite IHct ; [reflexivity|..] ; eassumption. extensionality v ; auto. destruct c ; destruct H ; simpl; erewrite IHct ; [reflexivity|..] ; eassumption. rewrite !Substitution.dlookup_dmap ; exact (dsnd (Substitution.dlookup n Γ σ H)). extensionality x; exact (IHct (ConsSubst (dpair _ ⟨x, x⟩ eq_refl) σ)). destruct c ; destruct H ; rewrite IHct1 ; rewrite IHct2 ; reflexivity. Qed. Import Substitution. Lemma map_subst_id Γ σ : map_subst (fun c m => @icterm_to_term M Γ c m σ) (id_isubst Γ) = σ. Proof. apply (dlist_extensionality _ _ _ eq_refl _) => n. revert Γ σ; induction n; move=> ? σ H ; dependent elimination σ ; simp_dlookup. simp dmap ; simp_dlookup; by []. simpl in IHn |- *. rewrite dlookup_dmap. simp_dlookup. rewrite <- IHn. rewrite !dlookup_dmap. apply to_term_weaken. Qed. Definition iceq_to_eq {Γ c} {ct1 ct2 : icterm Γ c} (Heq : ct1 ≅ ct2) : forall (σ : substitution var_eq Γ), ⦑ct1 | map_subst efst σ |M⦒ = ⦑ ct2 | map_subst esnd σ |M⦒. Proof. induction Heq ; simpl ; intros σ. 1-3:unfold bind ; unfold ret. rewrite monad_law1 ; rewrite icterm_diagonal ; reflexivity. rewrite monad_law2 ; rewrite icterm_diagonal ; reflexivity. rewrite monad_law3 ; rewrite 3!icterm_diagonal ; reflexivity. f_equal ; auto. destruct H ; apply icterm_diagonal. destruct H ; apply icterm_diagonal. destruct H ; rewrite icterm_diagonal ; reflexivity. f_equal ; auto. destruct c ; destruct H ; rewrite IHHeq ; reflexivity. destruct c ; destruct H ; rewrite IHHeq ; reflexivity. destruct H ; rewrite icterm_diagonal ; reflexivity. destruct H ; extensionality v ; rewrite icterm_diagonal; reflexivity. extensionality v ; auto. destruct c ; destruct H ; dependent destruction Heq ; rewrite IHHeq ; reflexivity. destruct H ; unfold isubst_one; rewrite to_term_isubst; simpl; rewrite map_subst_id; pose (hd := dpair _ ⟨⦑ct2 | map_subst efst σ |M⦒, ⦑ct2 | map_subst esnd σ |M⦒⟩ (icterm_diagonal ct2 σ) : var_eq _); apply (icterm_diagonal ct1 (ConsSubst hd σ)). destruct H ; extensionality x; cbn; rewrite to_term_weaken; rewrite icterm_diagonal; reflexivity. extensionality x; apply (IHHeq (ConsSubst (dpair _ ⟨x,x⟩ eq_refl) σ)). destruct c ; destruct H ; rewrite IHHeq1 ; rewrite IHHeq2 ; reflexivity. apply icterm_diagonal. symmetry ; rewrite icterm_diagonal ; rewrite <- (icterm_diagonal ct1) ; apply IHHeq. transitivity ⦑ ct2 | map_subst esnd σ |M⦒ ; [|rewrite <- (icterm_diagonal ct2)] ; auto. Qed. End ICeqToEq. (******************************************************************************) (** *) (** Logical relation on the denotation *) (** *) (******************************************************************************) (** Relational interpretation of types *) Section ToRel. Context (M1 M2 : Type -> Type). Context (R : forall A, M1 A -> M2 A -> Type). Fixpoint to_rel (c:ctype) : ⦑ c |M1⦒ -> ⦑ c |M2⦒ -> Type := match c with | CM A => R A | CProd c1 c2 => fun '⟨x11, x21⟩ '⟨x12, x22⟩ => to_rel c1 x11 x12 × to_rel c2 x21 x22 | CArr c => fun f1 f2 => forall x, to_rel (c x) (f1 x) (f2 x) | CArrC c1 c2 => fun f1 f2 => forall x1 x2, to_rel c1 x1 x2 -> to_rel c2 (f1 x1) (f2 x2) end. End ToRel. (** Covariance restriction on SM types *) Fixpoint covariant (c:ctype) : Prop := match c with | CM _ => True | CProd c1 c2 => covariant c1 /\ covariant c2 | CArr Cs => forall x, covariant (Cs x) | CArrC _ _ => False end. (** (Functional) Special case when the SM type is covariant *) Section ToFunction. Context (M1 M2 : Type -> Type). Context (θ : forall A, M1 A -> M2 A). Context (c:ctype) (c_cov : covariant c). Definition to_function : ⦑ c |M1⦒ -> ⦑ c |M2⦒. Proof. induction c as [A| | |]. exact (θ A). intros [] ; destruct c_cov ; simpl ; intuition ; auto. intros ? x ; simpl in c_cov ; specialize c_cov with x; auto. contradiction c_cov. Defined. End ToFunction. Section ToFunctionLemmas. Context (M1 M2 M3 : Type -> Type). Context (c:ctype) (c_cov : covariant c). Import FunctionalExtensionality. Lemma to_function_id : forall m, to_function M1 M1 (fun A => id) c c_cov m = m. Proof. induction c ; simpl. intros ; reflexivity. intros [? ?] ; destruct c_cov ; f_equal ; auto. intros ? ; extensionality x; auto. inversion c_cov. Qed. Context (f : forall A, M1 A -> M2 A) (g: forall A, M2 A -> M3 A). Lemma to_function_comp : forall m, to_function M2 M3 g c c_cov (to_function M1 M2 f c c_cov m) = to_function M1 M3 (fun _ x => g _ (f _ x)) c c_cov m. Proof. induction c ; simpl. intros ; reflexivity. intros [? ?] ; destruct c_cov ; f_equal ; auto. intros ? ; extensionality x; auto. inversion c_cov. Qed. End ToFunctionLemmas. (** Compatibility of the special case to the general case *) Section ToRelToFunction. Context (M1 M2 : Type -> Type). Context (θ : forall A, M1 A -> M2 A). Let R := fun A (m1: M1 A) (m2 : M2 A) => θ A m1 = m2. Import FunctionalExtensionality. Fixpoint to_rel_to_function (c:ctype) : forall (c_cov : covariant c) x1 x2, to_rel M1 M2 R c x1 x2 -> to_function M1 M2 θ c c_cov x1 = x2 with to_function_to_rel (c:ctype) : forall (c_cov : covariant c) x1 x2, to_function M1 M2 θ c c_cov x1 = x2 -> to_rel M1 M2 R c x1 x2. Proof. all:destruct c ; simpl. intros ? ? ? ; trivial. intros [] [] [] [] ; f_equal ; auto. intros ? ? ? ? ; extensionality x ; auto. intros []. intros ? ? ? ; trivial. intros [] [] [] H ; injection H ; clear H ; intros ? ? ; split ; eapply to_function_to_rel ; eassumption. intros ? ? ? H ? ; apply (f_equal (fun f => f x)) in H; eapply to_function_to_rel; eassumption. intros []. Defined. End ToRelToFunction. (** Relational interpretation of terms (aka. fundamental lemma of logical relations)*) Section ICTermToRel. Import DepElim. Context (M1 M2 : Monad). Context (R : forall A, M1 A -> M2 A -> Prop). Context (Runit : forall A (x:A), R A (ret x) (ret x)). Context (Rbind : forall A B (m1 : M1 A) (m2 : M2 A) (f1 : A -> M1 B) (f2 : A -> M2 B), R A m1 m2 -> (forall x:A, R B (f1 x) (f2 x)) -> R B (bind m1 f1) (bind m2 f2)). Let MR := to_rel M1 M2 R. Record rel_val (c:ctype) := MkRelVal { fst : to_type M1 c ; snd : to_type M2 c ; rel : MR c fst snd }. Definition icterm_to_rel_witness {Γ c} (ct:icterm Γ c) : forall σ : substitution rel_val Γ, to_rel M1 M2 R c ⦑ ct | map_subst fst σ |M1⦒ ⦑ ct | map_subst snd σ |M2⦒. Proof. induction ct ; simpl. - intros ? ; apply Runit. - intros σ ; apply Rbind ; [ apply IHct2 | apply IHct1 ]. - intro σ ; constructor; [apply IHct1| apply IHct2]. - intro σ; destruct c ; destruct H ; exact (nfst (IHct σ)). - intro σ; destruct c ; destruct H ; exact (nsnd (IHct σ)). - intros σ x ; apply (X x). - intro σ. destruct c ; destruct H ; apply (IHct σ). - intros σ ; rewrite /map_subst ; erewrite 2!Substitution.dlookup_dmap ; apply rel. - intros σ x1 x2 r. apply (IHct (ConsSubst (MkRelVal c1 x1 x2 r) σ)). - intros σ; destruct c ; destruct H ; apply IHct1; apply IHct2. Defined. End ICTermToRel. (** Functional interpretation of terms (in the special case where our types are covariant) *) Section ICTermToFunction. Context (M1 M2 : Monad). Context (F : forall A, M1 A -> M2 A). Context (Funit : forall A (x:A), F A (ret x) = (ret x)). Context (Fbind : forall A B (m : M1 A) (f : A -> M1 B), F B (bind m f) = bind (F A m) (fun x => F B (f x))). Let R := fun A (m1 : M1 A) (m2: M2 A) => F A m1 = m2. Let MF := to_function M1 M2 F. Let val_cov (c:ctype) :=to_type M1 c × covariant c. Definition val_cov_to_rel_val (c:ctype) (p : val_cov c) : rel_val M1 M2 R c := MkRelVal M1 M2 R c (nfst p) (MF c (nsnd p) (nfst p)) (to_function_to_rel M1 M2 F c (nsnd p) _ _ eq_refl). Import FunctionalExtensionality. Program Definition icterm_to_fun_witness {Γ c} (ct:icterm Γ c) (Hcov : covariant c) := fun (σ : substitution val_cov Γ) => let ρ := map_subst val_cov_to_rel_val σ in to_rel_to_function M1 M2 F c Hcov _ _ (icterm_to_rel_witness M1 M2 R (Funit) _ ct ρ). Next Obligation. assert ((fun x => F _ (f1 x)) = f2) as <- by (extensionality x ; apply H0). apply Fbind. Qed. Eval cbn in icterm_to_fun_witness. (* TODO : give the following type to icterm_to_fun_witness *) (* forall (σ : substitution val_cov Γ), *) (* MF c Hcov ⦑ ct [map_subst (fun c => nfst) σ] |M1⦒ = *) (* ⦑ ct [map_subst (fun c p => MF c (nsnd p) (nfst p)) σ] |M2⦒. *) End ICTermToFunction. (******************************************************************************) (** *) (** Algebra structure on the denotation *) (** *) (******************************************************************************) (** Special case for the algebra structure on the dependent product that was not given in general *) Set Primitive Projections. Section AlgStruct. Context (M:Monad). Record AlgStruct A := mkAlgStruct { algstr_map :> M A -> A ; algstr_ret : forall a, algstr_map (monad_ret M a) = a ; algstr_bind : forall X (m : M X) f, algstr_map (monad_bind m (fun x => monad_ret _ (algstr_map (f x)))) = algstr_map (monad_bind m f) }. Definition homomorphism {A B} (αA : AlgStruct A) (αB : AlgStruct B) (f : A -> B) := forall m, f (αA m) = αB (f <$> m). Lemma homormorphism_comp {A B C} (HA : AlgStruct A) (HB : AlgStruct B) (HC : AlgStruct C) (f : A -> B) (g: B -> C) (Hf : homomorphism HA HB f) (Hg : homomorphism HB HC g) : homomorphism HA HC (fun x => g (f x)). Proof. move=> m ; rewrite Hf Hg map_functorial //. Qed. Lemma homomorphism_id {A} (HA:AlgStruct A) : homomorphism HA HA id. Proof. move=> m ; rewrite map_id //. Qed. End AlgStruct. Section FreeAlgStruct. Context (M:Monad). Import FunctionalExtensionality. Program Definition freeAlgStruct A : AlgStruct M (M A) := mkAlgStruct _ _ (fun mm => bind mm id) _ _. Next Obligation. cbv ; rewrite monad_law1 ; reflexivity. Qed. Next Obligation. cbv. rewrite !monad_law3. f_equal ; extensionality x. rewrite monad_law1 ; reflexivity. Qed. Section Homomorphism. Context {A B} (αB : AlgStruct M B) (f: A -> B). Definition free_extension (m:M A) : B := αB (f <$> m). Lemma free_extension_homomorphism : homomorphism M (freeAlgStruct A) αB free_extension. Proof. move=> m /=. rewrite /free_extension /map /bind monad_law3 algstr_bind //. Qed. End Homomorphism. End FreeAlgStruct. Section NProductAlgStruct. Context M A B (HA : AlgStruct M A) (HB : AlgStruct M B). Import FunctionalExtensionality. Program Definition nprodAlgStruct : AlgStruct M (A × B) := mkAlgStruct _ _ (fun m => npair (HA (nfst <$> m)) (HB (nsnd <$> m))) _ _. Next Obligation. cbv ; destruct a ; f_equal ; rewrite monad_law1 ; rewrite algstr_ret ; reflexivity. Qed. Next Obligation. f_equal ; cbv ; rewrite !monad_law3 ; match goal with | [|- _ = ?t ] => match t with | context c [monad_bind m ?f] => rewrite <- (algstr_bind _ _ _ _ _ f) end end ; do 2 f_equal ; extensionality x ; rewrite monad_law1 ; reflexivity. Qed. Lemma proj1_homomorphism : homomorphism M nprodAlgStruct HA nfst. Proof. move=> m ; rewrite /nprodAlgStruct //. Qed. Lemma proj2_homomorphism : homomorphism M nprodAlgStruct HB nsnd. Proof. move=> m ; rewrite /nprodAlgStruct //. Qed. Section PairingHomomorphism. Context {C} (HC : AlgStruct M C) (fA : C -> A) (fB : C -> B) (HfA : homomorphism M HC HA fA) (HfB : homomorphism M HC HB fB). Definition pairing (c:C) : A × B := ⟨fA c, fB c⟩. Lemma pairing_homomorphism : homomorphism M HC nprodAlgStruct pairing. Proof. move=> m. rewrite /pairing /nprodAlgStruct /= 2!map_functorial HfA HfB //. Qed. End PairingHomomorphism. End NProductAlgStruct. Section DependentProductAlgebra. Context (M:Monad) A B (HB : forall a:A, AlgStruct M (B a)). Import FunctionalExtensionality. Program Definition DepProdAlg : AlgStruct M (forall a, B a) := mkAlgStruct _ _ (fun m x => HB x (bind m (fun f => ret (f x)))) _ _. Next Obligation. intros ; simpl; extensionality x. cbv ; rewrite monad_law1. rewrite algstr_ret. reflexivity. Qed. Next Obligation. intros ; extensionality a. cbv; rewrite !monad_law3. match goal with | [|- _ = ?t ] => match t with | context c [monad_bind m ?f] => rewrite <- (algstr_bind _ _ _ _ _ f) end end. f_equal. f_equal. extensionality x. cbv. rewrite monad_law1. reflexivity. Qed. Section EvalHomomorphism. Context (a:A). Definition eval (f:forall a, B a) : B a := f a. Lemma eval_homorphism : homomorphism M DepProdAlg (HB a) eval. Proof. move=> ? //. Qed. End EvalHomomorphism. Section AbsHomomorphism. Context {C} (HC : AlgStruct M C) (f : forall a, C -> B a) (Hf : forall a, homomorphism M HC (HB a) (f a)). Lemma abs_homomorphism : homomorphism M HC DepProdAlg (fun c a => f a c). Proof. move=> x ; rewrite /homomorphism /DepProdAlg /= ; extensionality a; rewrite (Hf a) /map /bind monad_law3. do 2 f_equal ; extensionality a0 ; rewrite monad_law1 //. Qed. End AbsHomomorphism. End DependentProductAlgebra. (** Algebra structure on the denotation *) Section ToAlgebra. Context (M:Monad) (c : ctype). Definition ctype_alg : AlgStruct M ⦑ c |M⦒. Proof. induction c as [A| c1 IHc1 c2 IHc2 | |]. apply freeAlgStruct. apply (nprodAlgStruct _ _ _ IHc1 IHc2). apply (DepProdAlg _ _ _ X). apply (DepProdAlg _ _ _ (fun _ => IHc0_2)). Defined. End ToAlgebra.
lemma isCont_inverse_function2: fixes f g :: "real \<Rightarrow> real" shows "\<lbrakk>a < x; x < b; \<And>z. \<lbrakk>a \<le> z; z \<le> b\<rbrakk> \<Longrightarrow> g (f z) = z; \<And>z. \<lbrakk>a \<le> z; z \<le> b\<rbrakk> \<Longrightarrow> isCont f z\<rbrakk> \<Longrightarrow> isCont g (f x)"
Registered Owner: HP Shipping Ltd - UK - Operator: Hebridean Island Cruises - UK - an All Leisure Group comp. April 09-2009 Hebridean Island Cruises has filed for administration. The Hebridean Spirit has been loss making for some time and although it has now been sold it has impacted on the funding of the remaining group. This means that unfortunately the company that owns the Hebridean Princess has filed for administration. April 22 -2009 All Leisure group plc, which operates Swan Hellenic and Voyages of Discovery, is pleased to announce that it has purchased the unique small cruise ship, Hebridean Princess. All Leisure group plc is keen to ensure that the Hebridean Princess will continue to offer distinctive cruises around the Scottish Highlands and islands and through the Norwegian fjords and will continue to operate from its head office in Skipton. All Leisure Holidays Ltd has entered into an agreement for the sale and leaseback of the Hebridean Princess cruise vessel and certain related assets to HP Shipping for GBP2.9 million in cash. HP Shipping is a new company which is wholly owned by a syndicate of private investors, including Roger Allard. March 2010 - The work, undertaken at the Middlesbrough yard of A&P Tees, was the final part of a four-year programme to ensure the 1964-built Hebridean Island Cruises vessel complies fully with new design and construction regulations coming into force later this year. In addition, many public areas were refreshed with new carpets, upholstery, furniture and lighting in lounges and new carpets, bulkheads and deckheads in most of the passenger alleyways. The Tiree Lounge, Library, Conservatory, Look Out Lounge and Columba Restaurant all received attention with the lounges having been totally refurbished. In other work, the engines and auxillary engines underwent a full overhaul, the teak decks received attention and crew accommodation was upgraded. The hull colour has been returned to the traditional dark blue after spending last year in a different livery. Former name: Ferry Columba converted to cruiseship in 1989.
David Wall, one of the UK’s greatest male dancers, died on June 18, 2013. Kevin O’Hare, director of The Royal Ballet, and Tamara Rojo, director of English National Ballet, have led tributes to Wall as a dancer, teacher and coach. Cloud Dance Festival, a showcase for new contemporary ballet and dance, returns this year with Lacuna, a programme at London’s Bernie Grant Arts Centre from July 5 to 7. English National Ballet (ENB) has announced plans for the 2013–14 season, including new works by Akram Khan, Liam Scarlett and Russell Maliphant, the company’s first performances at London’s Barbican Theatre and a guest appearance by Carlos Acosta. Esther Williams, who has died aged 91, swam through some of Hollywood’s most elaborate musical spectacles in the 1940s and 1950s. A champion swimmer turned movie star, she had a magnificent, athletic figure and a smile that kept its natural brightness even as she emerged from Technicolor pools, fountains and firework displays. Principals Alina Cojocaru and Johan Kobborg will leave The Royal Ballet at the end of the 2012–13 season. They are leaving the company to pursue other other artistic challenges.
State Before: R : Type u_1 inst✝³ : CommRing R M : Submonoid R S : Type ?u.2970634 inst✝² : CommRing S inst✝¹ : Algebra R S P : Type ?u.2970871 inst✝ : CommRing P a c : R b d : { x // x ∈ M } ⊢ mk a b + -mk c d = mk a b + mk (-c) d State After: no goals Tactic: rw [neg_mk] State Before: R : Type u_1 inst✝³ : CommRing R M : Submonoid R S : Type ?u.2970634 inst✝² : CommRing S inst✝¹ : Algebra R S P : Type ?u.2970871 inst✝ : CommRing P a c : R b d : { x // x ∈ M } ⊢ mk (↑b * -c + ↑d * a) (b * d) = mk (↑d * a - ↑b * c) (b * d) State After: case e_x R : Type u_1 inst✝³ : CommRing R M : Submonoid R S : Type ?u.2970634 inst✝² : CommRing S inst✝¹ : Algebra R S P : Type ?u.2970871 inst✝ : CommRing P a c : R b d : { x // x ∈ M } ⊢ ↑b * -c + ↑d * a = ↑d * a - ↑b * c Tactic: congr State Before: case e_x R : Type u_1 inst✝³ : CommRing R M : Submonoid R S : Type ?u.2970634 inst✝² : CommRing S inst✝¹ : Algebra R S P : Type ?u.2970871 inst✝ : CommRing P a c : R b d : { x // x ∈ M } ⊢ ↑b * -c + ↑d * a = ↑d * a - ↑b * c State After: no goals Tactic: ring
-- ------------------ -- Demostrar que -- s ∩ (s ∪ t) = s -- ------------------ import data.set.basic open set variable {α : Type} variables s t : set α example : s ∩ (s ∪ t) = s := sorry
## R file to play with analysis indta <- read.csv("../data/200104-GDO_data_wide_sarcoma.csv") mydta <- indta[indta$Tumour.Type.2== "Gastrointestinal stromal sarcoma (GIST)", ] ##View(mydta) ##colnames(mydta) selectcols <- c("Year", "Tumour.Type.3", "Age", "Incidence", "Population", "Incidence.Rate", "Incidence.Rate.LCI..95..", "Incidence.Rate.UCI..95..","Routes.Population", "Two.Week.Wait", "Two.Week.Wait.percentage", "Two.Week.Wait.LCI", "Two.Week.Wait.UCI", "GP.Referral", "GP.Referral.percentage", "GP.Referral.LCI", "GP.Referral.UCI", "Other.Outpatient", "Other.Outpatient.percentage", "Other.Outpatient.LCI", "Other.Outpatient.UCI", "Inpatient.Elective", "Inpatient.Elective.percentage", "Inpatient.Elective.LCI", "Inpatient.Elective.UCI","Emergency.Presentation", "Emergency.Presentation.percentage", "Emergency.Presentation.LCI", "Emergency.Presentation.UCI", "DCO", "DCO.percentage", "DCO.LCI", "DCO.UCI", "Unknown.Route", "Unknown.Route.percentage", "Unknown.Route.LCI", "Unknown.Route.UCI", "Route.not.classified", "Route.not.classified.percentage","Route.not.classified.LCI", "Route.not.classified.UCI") colids <- which(colnames(mydta) %in% selectcols) mydta2 <- mydta[,colids] View(mydta2) library("ggplot2") library("tidyr") myyr <- c(2013, 2014, 2015, 2016, 2017) mydta3 <- mydta2[mydta2$Year%in%myyr,] mydta3[,4:41]<-apply(mydta3[,4:41],2,function(ind) as.double(as.character(ind))) mydta3$Year <- as.integer(as.character(mydta3$Year)) mydta4<- gather(mydta3, "key", "route", Two.Week.Wait.percentage, GP.Referral.percentage, Other.Outpatient.percentage, Inpatient.Elective.percentage, Emergency.Presentation.percentage, DCO.percentage, Unknown.Route.percentage, Route.not.classified.percentage) mydta4$key <- substr(mydta4$key, 1, nchar(mydta4$key)-11) unique(mydta4$key) myordkey <- rev(c("GP.Referral","Emergency.Presentation", "Other.Outpatient", "Two.Week.Wait", "Inpatient.Elective", "DCO", "Route.not.classified" , "Unknown.Route")) mydta4<-mydta4[order(match(mydta4$key, myordkey)),] mydta4$key <- factor(mydta4$key, levels=myordkey) ## number not rate mydta5<- gather(mydta3, "key", "route", Two.Week.Wait, GP.Referral, Other.Outpatient, Inpatient.Elective, Emergency.Presentation, DCO, Unknown.Route, Route.not.classified) unique(mydta5$key) myordkey <- rev(c("GP.Referral","Emergency.Presentation", "Other.Outpatient", "Two.Week.Wait", "Inpatient.Elective", "DCO", "Route.not.classified" , "Unknown.Route")) mydta5<-mydta5[order(match(mydta5$key, myordkey)),] mydta5$key <- factor(mydta5$key, levels=myordkey) ## plot 1 - incidence rate by year ggplot(data = mydta3[mydta3$Age=="All ages",], aes(x = Year, y = Incidence.Rate, group=Tumour.Type.3)) + geom_line(aes(color=Tumour.Type.3, linetype=Tumour.Type.3), size=1) + geom_point(aes(color=Tumour.Type.3, shape=Tumour.Type.3), size=3) + geom_segment(aes(x = Year, xend = Year, y = Incidence.Rate.LCI..95.., yend = Incidence.Rate.UCI..95.., colour = Tumour.Type.3), size = 1) + ylim(0,1.8) + labs(title = "Crude GIST Incidence (95%CI) by year", x = "Year", y = "Incidence rate (per 100,000 population)") + theme(legend.title=element_blank()) ##plot 2 - number by year t.inc<- mydta3$Age=="All ages" & mydta3$Tumour.Type.3!="All" ggplot(data = mydta3[t.inc,], aes(x = Year, y = Incidence)) + geom_col(aes(fill=Tumour.Type.3))+ labs(title = "Number GIST diagnosed by year", x = "Year", y = "Number") + theme(legend.title=element_blank()) ##plot 2 - route by year p <- ggplot(mydta4[mydta4$Age=="All ages" & mydta4$Tumour.Type.3=="All",], aes(x = Year, y = route))+ geom_col(aes(fill = key), width = 0.7) + labs(title = "Routes by year", x = "Year", y = "Percentage (%)") ## plot 3 - Stomach by age group and year bp <- ggplot(data = mydta3[mydta3$Tumour.Type.3=="Stomach" & mydta3$Age!="All ages",], aes(x = Year, y = Incidence.Rate, group=Age)) + geom_line(aes(color=Age, linetype=Age), size=1) + geom_point(aes(color=Age, shape=Age), size=3) + geom_segment(aes(x = Year, xend = Year, y = Incidence.Rate.LCI..95.., yend = Incidence.Rate.UCI..95.., colour = Age), size = 1) + labs(title = "GIST Stomach Tumour Incidence (95%CI)", x = "Year", y = "Incidence rate (per 100,000 population)") + theme(legend.title=element_blank()) bp <- ggplot(data = mydta3[mydta3$Tumour.Type.3=="Stomach" & mydta3$Age!="All ages",], aes(x = Year, y = Incidence, group=Age)) + geom_col(aes(fill=Age)) + labs(title = "GIST Stomach Tumour Number by year", x = "Year", y = "Number diagnosed") + theme(legend.title=element_blank()) ##plot 3 - stomach route by age p <- ggplot(mydta5[mydta5$Tumour.Type.3=="Stomach" & (mydta5$Age!="All ages"),], aes(x=Age,y=route))+ geom_col(aes(fill = key), width = 0.7) + labs(title = "Stomatch routes (2013-16) by age group", x = "Age group", y = "Number (total 2013-16)") p <- ggplot(mydta5[mydta5$Tumour.Type.3=="Stomach",], aes(Age))+ geom_bar(position="fill",aes(y=route,fill = key), width = 0.7, stat="identity") + scale_y_continuous(labels = scales::percent) + labs(title = "Stomatch routes (2013-16) by age group", x = "Age group", y = "Percentage (%)")
module x00-playpen where -- prove properties of inductive naturals and operations on them via induction import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong; sym) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎) open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _^_) *-assoc : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p) *-assoc m n p = {!!} +-xx : ∀ (n : ℕ) → (n ^ 3) ∸ ((n * n) * n) ≡ zero +-xx zero = refl +-xx (suc n) = {!!} {- begin (n * (n ^ 2)) ∸ ((n * n) * n) ≡⟨⟩ (n * (n * (n ^ 1))) ∸ ((n * n) * n) ≡⟨⟩ (n * (n * (n * (n ^ 0)))) ∸ ((n * n) * n) ≡⟨⟩ (n * (n * (n * 1 ))) ∸ ((n * n) * n) ≡⟨⟩ (n * (n * n )) ∸ ((n * n) * n) ≡⟨ cong ( ((n * (n * n))) ∸_) (*-assoc n n n) ⟩ (n * (n * n )) ∸ ( n * (n * n)) ∎ -}
[STATEMENT] lemma pair_measurable[measurable]: assumes "f \<in> X \<rightarrow>\<^sub>M Y" and "g \<in> X' \<rightarrow>\<^sub>M Y'" shows "map_prod f g \<in> X \<Otimes>\<^sub>M X' \<rightarrow>\<^sub>M Y \<Otimes>\<^sub>M Y'" [PROOF STATE] proof (prove) goal (1 subgoal): 1. map_prod f g \<in> X \<Otimes>\<^sub>M X' \<rightarrow>\<^sub>M Y \<Otimes>\<^sub>M Y' [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: f \<in> X \<rightarrow>\<^sub>M Y g \<in> X' \<rightarrow>\<^sub>M Y' goal (1 subgoal): 1. map_prod f g \<in> X \<Otimes>\<^sub>M X' \<rightarrow>\<^sub>M Y \<Otimes>\<^sub>M Y' [PROOF STEP] by(auto simp add: measurable_pair_iff)