record 'a clientState_d =
clientState +
dummy :: 'a ― ‹dummy field for new variables›
definition
― ‹DUPLICATED FROM Client.thy, but with "tok" removed›
― ‹Maybe want a special theory section to declare such maps›
non_dummy :: "'a clientState_d => clientState" where"non_dummy s = (|giv = giv s, ask = ask s, rel = rel s|)"
definition
― ‹Renaming map to put a Client into the standard form›
client_map :: "'a clientState_d => clientState*'a" where"client_map = funPair non_dummy dummy"
record allocState =
allocGiv :: "nat => nat list" ― ‹OUTPUT history: source of "giv" for i›
allocAsk :: "nat => nat list" ― ‹INPUT: allocator's copy of "ask" for i›
allocRel :: "nat => nat list" ― ‹INPUT: allocator's copy of "rel" for i›
record 'a allocState_d =
allocState +
dummy :: 'a ― ‹dummy field for new variables›
record 'a systemState =
allocState +
client :: "nat => clientState" ― ‹states of all clients›
dummy :: 'a ― ‹dummy field for new variables›
subsubsection‹Resource allocation system specification›
definition
― ‹spec (1)›
system_safety :: "'a systemState program set" where"system_safety = Always {s. (∑i ∈ lessThan Nclients. (tokens o giv o sub i o client)s) ≤ NbT + (∑i ∈ lessThan Nclients. (tokens o rel o sub i o client)s)}"
definition
― ‹spec (2)›
system_progress :: "'a systemState program set" where"system_progress = (INT i : lessThan Nclients. INT h. {s. h ≤ (ask o sub i o client)s} LeadsTo {s. h pfixLe (giv o sub i o client) s})"
definition
system_spec :: "'a systemState program set" where"system_spec = system_safety Int system_progress"
subsubsection‹Client specification (required)›
definition
― ‹spec (3)›
client_increasing :: "'a clientState_d program set" where"client_increasing = UNIV guarantees Increasing ask Int Increasing rel"
definition
― ‹spec (5)›
client_progress :: "'a clientState_d program set" where"client_progress = Increasing giv guarantees (INT h. {s. h ≤ giv s & h pfixGe ask s} LeadsTo {s. tokens h ≤ (tokens o rel) s})"
definition
― ‹spec: preserves part›
client_preserves :: "'a clientState_d program set" where"client_preserves = preserves giv Int preserves clientState_d.dummy"
definition
― ‹environmental constraints›
client_allowed_acts :: "'a clientState_d program set" where"client_allowed_acts = {F. AllowedActs F = insert Id (∪ (Acts ` preserves (funPair rel ask)))}"
definition
client_spec :: "'a clientState_d program set" where"client_spec = client_increasing Int client_bounded Int client_progress Int client_allowed_acts Int client_preserves"
subsubsection‹Allocator specification (required)›
definition
― ‹spec (6)›
alloc_increasing :: "'a allocState_d program set" where"alloc_increasing = UNIV guarantees (INT i : lessThan Nclients. Increasing (sub i o allocGiv))"
definition
― ‹spec (7)›
alloc_safety :: "'a allocState_d program set" where"alloc_safety = (INT i : lessThan Nclients. Increasing (sub i o allocRel)) guarantees Always {s. (∑i ∈ lessThan Nclients. (tokens o sub i o allocGiv)s) ≤ NbT + (∑i ∈ lessThan Nclients. (tokens o sub i o allocRel)s)}"
definition
― ‹spec (8)›
alloc_progress :: "'a allocState_d program set" where"alloc_progress = (INT i : lessThan Nclients. Increasing (sub i o allocAsk) Int Increasing (sub i o allocRel)) Int Always {s. ∀i<Nclients. ∀elt ∈ set ((sub i o allocAsk) s). elt ≤ NbT} Int (INT i : lessThan Nclients. INT h. {s. h ≤ (sub i o allocGiv)s & h pfixGe (sub i o allocAsk)s} LeadsTo {s. tokens h ≤ (tokens o sub i o allocRel)s}) guarantees (INT i : lessThan Nclients. INT h. {s. h ≤ (sub i o allocAsk) s} LeadsTo {s. h pfixLe (sub i o allocGiv) s})"
(*NOTE: to follow the original paper, the formula above should have had INTh.{s.hi\<le>(subioallocGiv)s&hipfixGe(subioallocAsk)s} LeadsTo {s.tokenshi\<le>(tokensosubioallocRel)s}) thushshouldhavebeenafunctionvariable.However,onlyhiisever
looked at.*)
definition
― ‹spec: preserves part›
alloc_preserves :: "'a allocState_d program set" where"alloc_preserves = preserves allocRel Int preserves allocAsk Int preserves allocState_d.dummy"
definition
― ‹environmental constraints›
alloc_allowed_acts :: "'a allocState_d program set" where"alloc_allowed_acts = {F. AllowedActs F = insert Id (∪(Acts ` (preserves allocGiv)))}"
definition
alloc_spec :: "'a allocState_d program set" where"alloc_spec = alloc_increasing Int alloc_safety Int alloc_progress Int alloc_allowed_acts Int alloc_preserves"
subsubsection‹Network specification›
definition
― ‹spec (9.1)›
network_ask :: "'a systemState program set" where"network_ask = (INT i : lessThan Nclients. Increasing (ask o sub i o client) guarantees ((sub i o allocAsk) Fols (ask o sub i o client)))"
definition
― ‹spec (9.2)›
network_giv :: "'a systemState program set" where"network_giv = (INT i : lessThan Nclients. Increasing (sub i o allocGiv) guarantees ((giv o sub i o client) Fols (sub i o allocGiv)))"
definition
― ‹spec (9.3)›
network_rel :: "'a systemState program set" where"network_rel = (INT i : lessThan Nclients. Increasing (rel o sub i o client) guarantees ((sub i o allocRel) Fols (rel o sub i o client)))"
definition
― ‹spec: preserves part›
network_preserves :: "'a systemState program set" where"network_preserves = preserves allocGiv Int (INT i : lessThan Nclients. preserves (rel o sub i o client) Int preserves (ask o sub i o client))"
definition
― ‹environmental constraints›
network_allowed_acts :: "'a systemState program set" where"network_allowed_acts = {F. AllowedActs F = insert Id (∪ (Acts ` (preserves allocRel ∩ (∩i<Nclients. preserves (giv ∘ sub i ∘ client)))))}"
definition
network_spec :: "'a systemState program set" where"network_spec = network_ask Int network_giv Int network_rel Int network_allowed_acts Int network_preserves"
subsubsection‹State mappings›
definition
sysOfAlloc :: "((nat => clientState) * 'a) allocState_d => 'a systemState" where"sysOfAlloc = (%s. let (cl,xtr) = allocState_d.dummy s in (| allocGiv = allocGiv s, allocAsk = allocAsk s, allocRel = allocRel s, client = cl, dummy = xtr|))"
(*For rewriting of specifications related by "guarantees"*) lemmas [simp] =
rename_image_constrains
rename_image_stable
rename_image_increasing
rename_image_invariant
rename_image_Constrains
rename_image_Stable
rename_image_Increasing
rename_image_Always
rename_image_leadsTo
rename_image_LeadsTo
rename_preserves
rename_image_preserves
lift_image_preserves
bij_image_INT
bij_is_inj [THEN image_Int]
bij_image_Collect_eq
ML ‹
(*Splits up conjunctions & intersections: like CONJUNCTS in the HOL system*) fun list_of_Int th =
(list_of_Int (th RS conjunct1) @ list_of_Int (th RS conjunct2))
handle THM _ => (list_of_Int (th RS @{thm IntD1}) @ list_of_Int (th RS @{thm IntD2}))
handle THM _ => (list_of_Int (th RS @{thm INT_D}))
handle THM _ => (list_of_Int (th RS @{thm bspec}))
handle THM _ => [th]; ›
lemmas lessThanBspec = lessThan_iff [THEN iffD2, THEN [2] bspec]
attribute_setup normalized = ‹ let funnormalizedth= normalized(thRSspec handleTHM_=>thRS@{thmlessThanBspec} handleTHM_=>thRS@{thmbspec} handleTHM_=>thRS(@{thmguarantees_INT_right_iff}RSiffD1)) handleTHM_=>th; in Scan.succeed(Thm.rule_attribute[](Knormalized)) end \<close>
(*** bijectivity of sysOfAlloc [MUST BE AUTOMATED] ***)
ML ‹
record_auto_tac ctxt =
let val ctxt' =
ctxt addSWrapper Record.split_wrapper
addsimps
[@{thm sysOfAlloc_def}, @{thm sysOfClient_def},
@{thm client_map_def}, @{thm non_dummy_def}, @{thm funPair_def},
@{thm o_apply}, @{thm Let_def}]
in auto_tac ctxt' end;
›
method_setup record_auto = ‹Scan.succeed (SIMPLE_METHOD o record_auto_tac)›
ML ‹ML_Thms.bind_thms ("allocRel_o_inv_sysOfAlloc_eq'", make_o_equivs 🍋 @{thm allocRel_o_inv_sysOfAlloc_eq})› declare allocRel_o_inv_sysOfAlloc_eq' [simp]
lemma rel_inv_client_map_drop_map: "(rel o inv client_map o drop_map i o inv sysOfClient) = rel o sub i o client" apply (simp add: o_def drop_map_def) done
ML ‹ML_Thms.bind_thms ("rel_inv_client_map_drop_map'", make_o_equivs 🍋 @{thm rel_inv_client_map_drop_map})› declare rel_inv_client_map_drop_map [simp]
lemma ask_inv_client_map_drop_map: "(ask o inv client_map o drop_map i o inv sysOfClient) = ask o sub i o client" apply (simp add: o_def drop_map_def) done
ML ‹ML_Thms.bind_thms ("ask_inv_client_map_drop_map'", make_o_equivs 🍋 @{thm ask_inv_client_map_drop_map})› declare ask_inv_client_map_drop_map [simp]
text‹* These preservation laws should be generated automatically *›
lemma Client_Allowed [simp]: "Allowed Client = preserves rel Int preserves ask" by (auto simp add: Allowed_def Client_AllowedActs safety_prop_Acts_iff)
lemma Network_Allowed [simp]: "Allowed Network = preserves allocRel Int (INT i: lessThan Nclients. preserves(giv o sub i o client))" by (auto simp add: Allowed_def Network_AllowedActs safety_prop_Acts_iff)
lemma fst_o_lift_map' [simp]: "(f ∘ sub i ∘ fst ∘ lift_map i ∘ g) = f o fst o g" apply (subst fst_o_lift_map [symmetric]) apply (simp only: o_assoc) done
(*The proofs of rename_Client_Increasing, rename_Client_Bounded and rename_Client_Progressaresimilar.Allrequirecopyingouttheoriginal Clientproperty.Aforwardproofcanbeconstructedasfollows:
(*Lifting Alloc_Increasing up to the level of systemState*) lemmas rename_Alloc_Increasing =
Alloc_Increasing
[THEN rename_guarantees_sysOfAlloc_I,
simplified surj_rename o_def sub_apply
rename_image_Increasing bij_sysOfAlloc
allocGiv_o_inv_sysOfAlloc_eq']
lemma System_Increasing_allocGiv: "i < Nclients ==> System ∈ Increasing (sub i o allocGiv)" apply (unfold System_def) apply (simp add: o_def) apply (rule rename_Alloc_Increasing [THEN guarantees_Join_I1, THEN guaranteesD]) apply auto done
ML ‹
.bind_thms ("System_Increasing'", list_of_Int @{thm System_Increasing}) ›
declare System_Increasing' [intro!]
text‹Follows consequences.
The "Always (INT ...) formulation expresses the general safety property
and allows it to be combined using ‹Always_Int_rule› below.›
lemma System_Follows_rel: "i < Nclients ==> System ∈ ((sub i o allocRel) Fols (rel o sub i o client))" apply (auto intro!: Network_Rel [THEN component_guaranteesD]) apply (simp add: ok_commute [of Network]) done
lemma System_Follows_ask: "i < Nclients ==> System ∈ ((sub i o allocAsk) Fols (ask o sub i o client))" apply (auto intro!: Network_Ask [THEN component_guaranteesD]) apply (simp add: ok_commute [of Network]) done
lemma System_Follows_allocGiv: "i < Nclients ==> System ∈ (giv o sub i o client) Fols (sub i o allocGiv)" apply (auto intro!: Network_Giv [THEN component_guaranteesD]
rename_Alloc_Increasing [THEN component_guaranteesD]) apply (simp_all add: o_def non_dummy_def ok_commute [of Network]) apply (auto intro!: rename_Alloc_Increasing [THEN component_guaranteesD]) done
lemma Always_giv_le_allocGiv: "System ∈ Always (INT i: lessThan Nclients. {s. (giv o sub i o client) s ≤ (sub i o allocGiv) s})" apply auto apply (erule System_Follows_allocGiv [THEN Follows_Bounded]) done
lemma Always_allocAsk_le_ask: "System ∈ Always (INT i: lessThan Nclients. {s. (sub i o allocAsk) s ≤ (ask o sub i o client) s})" apply auto apply (erule System_Follows_ask [THEN Follows_Bounded]) done
lemma Always_allocRel_le_rel: "System ∈ Always (INT i: lessThan Nclients. {s. (sub i o allocRel) s ≤ (rel o sub i o client) s})" by (auto intro!: Follows_Bounded System_Follows_rel)
subsection‹Proof of the safety property (1)›
text‹safety (1), step 1 is ‹System_Follows_rel››
text‹safety (1), step 2› (* i < Nclients ==> System : Increasing (sub i o allocRel) *) lemmas System_Increasing_allocRel = System_Follows_rel [THEN Follows_Increasing1]
(*Lifting Alloc_safety up to the level of systemState. Simplifyingwitho_defgetsridofthetranslationsbutitunfortunately
gets rid of the other "o"s too.*)
text‹safety (1), step 3› lemma System_sum_bounded: "System ∈ Always {s. (∑i ∈ lessThan Nclients. (tokens o sub i o allocGiv) s) ≤ NbT + (∑i ∈ lessThan Nclients. (tokens o sub i o allocRel) s)}" apply (simp add: o_apply) apply (insert Alloc_Safety [THEN rename_guarantees_sysOfAlloc_I]) apply (simp add: o_def) apply (erule component_guaranteesD) apply (auto simp add: System_Increasing_allocRel [simplified sub_apply o_def]) done
text‹Follows reasoning›
lemma Always_tokens_giv_le_allocGiv: "System ∈ Always (INT i: lessThan Nclients. {s. (tokens o giv o sub i o client) s ≤ (tokens o sub i o allocGiv) s})" apply (rule Always_giv_le_allocGiv [THEN Always_weaken]) apply (auto intro: tokens_mono_prefix simp add: o_apply) done
lemma Always_tokens_allocRel_le_rel: "System ∈ Always (INT i: lessThan Nclients. {s. (tokens o sub i o allocRel) s ≤ (tokens o rel o sub i o client) s})" apply (rule Always_allocRel_le_rel [THEN Always_weaken]) apply (auto intro: tokens_mono_prefix simp add: o_apply) done
text‹progress (2), step 1 is ‹System_Follows_ask› and ‹System_Follows_rel››
text‹progress (2), step 2; see also ‹System_Increasing_allocRel›› (* i < Nclients ==> System : Increasing (sub i o allocAsk) *) lemmas System_Increasing_allocAsk = System_Follows_ask [THEN Follows_Increasing1]
text‹progress (2), step 3: lifting ‹Client_Bounded› to systemState› lemma rename_Client_Bounded: "i ∈ I ==> rename sysOfClient (plam x: I. rename client_map Client) ∈ UNIV guarantees Always {s. ∀elt ∈ set ((ask o sub i o client) s). elt ≤ NbT}" using image_cong_simp [cong del] by rename_client_map
lemma System_Bounded_ask: "i < Nclients ==> System ∈ Always {s. ∀elt ∈ set ((ask o sub i o client) s). elt ≤ NbT}" apply (rule component_guaranteesD [OF rename_Client_Bounded Client_component_System]) apply auto done
lemma Collect_all_imp_eq: "{x. ∀y. P y ⟶ Q x y} = (INT y: {y. P y}. {x. Q x y})" apply blast done
text‹progress (2), step 5 is ‹System_Increasing_allocGiv››
text‹progress (2), step 6› (* i < Nclients ==> System : Increasing (giv o sub i o client) *) lemmas System_Increasing_giv = System_Follows_allocGiv [THEN Follows_Increasing1]
lemma rename_Client_Progress: "i ∈ I ==> rename sysOfClient (plam x: I. rename client_map Client) ∈ Increasing (giv o sub i o client) guarantees (INT h. {s. h ≤ (giv o sub i o client) s & h pfixGe (ask o sub i o client) s} LeadsTo {s. tokens h ≤ (tokens o rel o sub i o client) s})"
supply image_cong_simp [cong del] apply rename_client_map apply (simp add: Client_Progress [simplified o_def]) done
text‹progress (2), step 7› lemma System_Client_Progress: "System ∈ (INT i : (lessThan Nclients). INT h. {s. h ≤ (giv o sub i o client) s & h pfixGe (ask o sub i o client) s} LeadsTo {s. tokens h ≤ (tokens o rel o sub i o client) s})" apply (rule INT_I) (*Couldn't have just used Auto_tac since the "INT h" must be kept*) apply (rule component_guaranteesD [OF rename_Client_Progress Client_component_System]) apply (auto simp add: System_Increasing_giv) done
(*Concludes System:{s.k\<le>(subioallocGiv)s} LeadsTo {s.(subioallocAsk)s\<le>(askosubioclient)s}Int
{s. k \<le> (giv o sub i o client) s} *)
lemma System_lemma3: "i < Nclients ==> System ∈ {s. h ≤ (sub i o allocGiv) s & h pfixGe (sub i o allocAsk) s} LeadsTo {s. h ≤ (giv o sub i o client) s & h pfixGe (ask o sub i o client) s}" apply (rule single_LeadsTo_I) apply (rule_tac k1 = h and x1 = "(sub i o allocAsk) s" in System_lemma2 [THEN LeadsTo_weaken]) apply auto apply (blast intro: trans_Ge [THEN trans_genPrefix, THEN transD] prefix_imp_pfixGe) done
text‹progress (2), step 8: Client i's "release" action is visible system-wide› lemma System_Alloc_Client_Progress: "i < Nclients ==> System ∈ {s. h ≤ (sub i o allocGiv) s & h pfixGe (sub i o allocAsk) s} LeadsTo {s. tokens h ≤ (tokens o sub i o allocRel) s}" apply (rule LeadsTo_Trans) prefer2 apply (drule System_Follows_rel [THEN
mono_tokens [THEN mono_Follows_o, THEN [2] rev_subsetD], THEN Follows_LeadsTo]) apply (simp add: o_assoc) apply (rule LeadsTo_Trans) apply (cut_tac [2] System_Client_Progress) prefer2 apply (blast intro: LeadsTo_Basis) apply (erule System_lemma3) done
text‹Lifting ‹Alloc_Progress› up to the level of systemState›
text‹progress (2), step 9› lemma System_Alloc_Progress: "System ∈ (INT i : (lessThan Nclients). INT h. {s. h ≤ (sub i o allocAsk) s} LeadsTo {s. h pfixLe (sub i o allocGiv) s})" apply (simp only: o_apply sub_def) apply (insert Alloc_Progress [THEN rename_guarantees_sysOfAlloc_I]) apply (simp add: o_def del: INT_iff) apply (drule component_guaranteesD) apply (auto simp add:
System_Increasing_allocRel [simplified sub_apply o_def]
System_Increasing_allocAsk [simplified sub_apply o_def]
System_Bounded_allocAsk [simplified sub_apply o_def]
System_Alloc_Client_Progress [simplified sub_apply o_def]) done
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.