theory Kruskal_Impl imports Kruskal_Refine Refine_Imperative_HOL.IICF begin
subsection‹Refinement III: concrete edges›
text‹Given a concrete representation of edges and their endpoints as a pair, we refine
Kruskal's algorithm to work on these concrete edges.›
locale Kruskal_concrete = Kruskal_interface E V vertices joins forest connected weight for E V vertices joins forest connected and weight :: "'edge ==> int" + fixes
α :: "'cedge ==> 'edge" and endpoints :: "'cedge ==> ('a*'a) nres" assumes
endpoints_refine: "α xi = x ==> endpoints xi ≤⇓ Id (a_endpoints x)" begin
subsection‹Refinement to Imperative/HOL with Sepref-Tool›
text‹Given implementations for the operations of getting a list of concrete edges
and getting the endpoints of a concrete edge we synthesize Kruskal in Imperative/HOL.›
locale Kruskal_Impl = Kruskal_concrete E V vertices joins forest connected weight α endpoints for E V vertices joins forest connected and weight :: "'edge ==> int" and α and endpoints :: "nat × int × nat ==> (nat × nat) nres"
+ fixes getEdges :: "(nat × int × nat) list nres" and getEdges_impl :: "(nat × int × nat) list Heap" and superE :: "(nat × int × nat) set" and endpoints_impl :: "(nat × int × nat) ==> (nat × nat) Heap" assumes
getEdges_refine: "getEdges ≤ SPEC (λL. α ` set L = E ∧ (∀(a,wv,b)∈set L. weight (α (a,wv,b)) = wv) ∧ set L ⊆ superE)" and
getEdges_impl: "(uncurry0 getEdges_impl, uncurry0 getEdges) ∈ unit_assnk→a list_assn (nat_assn ×a int_assn ×a nat_assn)" and
max_node_is_Max_V: "E = α ` set la ==> max_node la = Max (insert 0 V)" and
endpoints_impl: "( endpoints_impl, endpoints) ∈ (nat_assn ×a int_assn ×a nat_assn)k→a (nat_assn ×a nat_assn)" begin
lemma this_loc: "Kruskal_Impl E V vertices joins forest connected weight α endpoints getEdges getEdges_impl superE endpoints_impl"by unfold_locales
subsubsection‹Refinement IV: given an edge set›
text‹We now assume to have an implementation of the operation to obtain a list of the edges of
a graph. By sorting this list we refine @{term obtain_sorted_carrier'}.›
definition"obtain_sorted_carrier'' = do { l ← SPEC (λL. α ` set L = E ∧ (∀(a,wv,b)∈set L. weight (α (a,wv,b)) = wv) ∧ set L ⊆ superE); SPEC (λL. sorted_wrt edges_less_eq L ∧ set L = set l) }"
lemma wsorted'_sorted_wrt_edges_less_eq: assumes"∀(a,wv,b)∈set s. weight (α (a,wv,b)) = wv" "sorted_wrt edges_less_eq s" shows"wsorted' s" using assms apply - unfolding wsorted'_defunfolding edges_less_eq_def apply(rule sorted_wrt_mono_rel ) by (auto simp: case_prod_beta)
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.