(* Title: HOL/UNITY/Comp/AllocImpl.thy Author: Lawrence C Paulson, Cambridge University Computer Laboratory Copyright 1998 University of Cambridge *)
section‹Implementation of a multiple-client allocator from a single-client allocator›
theory AllocImpl imports AllocBase "../Follows""../PPROD"begin
(** State definitions. OUTPUT variables are locals **)
(*Type variable 'b is the type of items being merged*) record 'b merge = In :: "nat => 'b list"(*merge's INPUT histories: streams to merge*)
Out :: "'b list"(*merge's OUTPUT history: merged items*)
iOut :: "nat list"(*merge's OUTPUT history: origins of merged items*)
record ('a,'b) merge_d = "'b merge" +
dummy :: 'a (*dummy field for new variables*)
definition non_dummy :: "('a,'b) merge_d => 'b merge"where "non_dummy s = (|In = In s, Out = Out s, iOut = iOut s|)"
record 'b distr = In :: "'b list"(*items to distribute*)
iIn :: "nat list"(*destinations of items to distribute*)
Out :: "nat => 'b list"(*distributed items*)
record ('a,'b) distr_d = "'b distr" +
dummy :: 'a (*dummy field for new variables*)
record allocState =
giv :: "nat list"(*OUTPUT history: source of tokens*)
ask :: "nat list"(*INPUT: tokens requested from allocator*)
rel :: "nat list"(*INPUT: tokens released to allocator*)
record 'a allocState_d =
allocState +
dummy :: 'a (*dummy field for new variables*)
record 'a systemState =
allocState +
mergeRel :: "nat merge"
mergeAsk :: "nat merge"
distr :: "nat distr"
dummy :: 'a (*dummy field for new variables*)
(** Merge specification (the number of inputs is Nclients) ***)
definition (*spec (10)*)
merge_increasing :: "('a,'b) merge_d program set" where"merge_increasing = UNIV guarantees (Increasing merge.Out) Int (Increasing merge.iOut)"
definition (*spec (13)*)
merge_follows :: "('a,'b) merge_d program set" where"merge_follows = (∩i ∈ lessThan Nclients. Increasing (sub i o merge.In)) guarantees (∩i ∈ lessThan Nclients. (%s. nths (merge.Out s) {k. k < size(merge.iOut s) & merge.iOut s! k = i}) Fols (sub i o merge.In))"
definition (*spec: preserves part*)
merge_preserves :: "('a,'b) merge_d program set" where"merge_preserves = preserves merge.In Int preserves merge_d.dummy"
definition (*environmental constraints*)
merge_allowed_acts :: "('a,'b) merge_d program set" where"merge_allowed_acts = {F. AllowedActs F = insert Id (∪ (Acts ` preserves (funPair merge.Out iOut)))}"
definition
merge_spec :: "('a,'b) merge_d program set" where"merge_spec = merge_increasing Int merge_eqOut Int merge_bounded Int merge_follows Int merge_allowed_acts Int merge_preserves"
(** Distributor specification (the number of outputs is Nclients) ***)
definition (*spec (14)*)
distr_follows :: "('a,'b) distr_d program set" where"distr_follows = Increasing distr.In Int Increasing distr.iIn Int Always {s. ∀elt ∈ set (distr.iIn s). elt < Nclients} guarantees (∩i ∈ lessThan Nclients. (sub i o distr.Out) Fols (%s. nths (distr.In s) {k. k < size(distr.iIn s) & distr.iIn s ! k = i}))"
definition
distr_allowed_acts :: "('a,'b) distr_d program set" where"distr_allowed_acts = {D. AllowedActs D = insert Id (∪(Acts ` (preserves distr.Out)))}"
definition
distr_spec :: "('a,'b) distr_d program set" where"distr_spec = distr_follows Int distr_allowed_acts"
definition (*spec (20)*)
alloc_progress :: "'a allocState_d program set" where"alloc_progress = Increasing ask Int Increasing rel Int Always {s. ∀elt ∈ set (ask s). elt ≤ NbT} Int (∩h. {s. h ≤ giv s & h pfixGe (ask s)} LeadsTo {s. tokens h ≤ tokens (rel s)}) guarantees (∩h. {s. h ≤ ask s} LeadsTo {s. h pfixLe giv s})"
definition (*spec: preserves part*)
alloc_preserves :: "'a allocState_d program set" where"alloc_preserves = preserves rel Int preserves ask 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 giv)))}"
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"
lemma alloc_refinement_lemma: "!!f::nat=>nat. (∩i ∈ lessThan n. {s. f i ≤ g i s}) ⊆ {s. (∑x ∈ lessThan n. f x) ≤ (∑x ∈ lessThan n. g x s)}" apply (induct_tac "n") apply (auto simp add: lessThan_Suc) done
lemma alloc_refinement: "(∩i ∈ lessThan Nclients. Increasing (sub i o allocAsk) Int Increasing (sub i o allocRel)) Int Always {s. ∀i. i (∀elt ∈ set ((sub i o allocAsk) s). elt ≤ NbT)} Int (∩i ∈ lessThan Nclients. ∩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}) ⊆ (∩i ∈ lessThan Nclients. Increasing (sub i o allocAsk) Int Increasing (sub i o allocRel)) Int Always {s. ∀i. i (∀elt ∈ set ((sub i o allocAsk) s). elt ≤ NbT)} Int (∩hf. (∩i ∈ lessThan Nclients. {s. hf i ≤ (sub i o allocGiv)s & hf i pfixGe (sub i o allocAsk)s}) LeadsTo {s. (∑i ∈ lessThan Nclients. tokens (hf i)) ≤ (∑i ∈ lessThan Nclients. (tokens o sub i o allocRel)s)})" apply (auto simp add: ball_conj_distrib) apply (rename_tac F hf) apply (rule LeadsTo_weaken_R [OF Finite_stable_completion alloc_refinement_lemma], blast, blast) apply (subgoal_tac "F ∈ Increasing (tokens o (sub i o allocRel))") apply (simp add: Increasing_def o_assoc) apply (blast intro: mono_tokens [THEN mono_Increasing_o, THEN subsetD]) done
end
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-05-03)
¤
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.