theory Kruskal_Refine imports Kruskal SeprefUF begin
subsection‹Refinement I: cycle check by connectedness›
text‹As a first refinement step, the check for introduction of a cycle when adding an edge @{term e}
can be replaced by checking whether the edge's endpoints are already connected.
By this we can shift from an edge-centric perspective to a vertex-centric perspective.›
context Kruskal_interface begin
abbreviation"empty_forest ≡ {}"
abbreviation"a_endpoints e ≡ SPEC (λ(a,b). joins a b e )"
definition kruskal0 where"kruskal0 ≡ do { l ← obtain_sorted_carrier; spanning_forest ← nfoldli l (λ_. True) (λe T. do { ASSERT (e ∈ E); (a,b) ← a_endpoints e; ASSERT (joins a b e ∧ forest T ∧ e∈E ∧ T ⊆ E); if ¬ (a,b) ∈ connected T then do { ASSERT (e∉T); RETURN (insert e T) } else RETURN T }) empty_forest; RETURN spanning_forest }"
lemma if_subst: "(if indep (insert e T) then RETURN (insert e T) else RETURN T) = (if e∉ T ∧ indep (insert e T) then RETURN (insert e T) else RETURN T)" by auto
subsection‹Refinement II: connectedness by PER operation›
text‹Connectedness in the subgraph spanned by a set of edges is a partial equivalence relation and
can be represented in a disjoint sets. This data structure is maintained while executing Kruskal's
algorithm and can be used to efficiently check for connectedness (@{term per_compare}.›
definition corresponding_union_find :: "'a per ==> 'edge set ==> bool"where "corresponding_union_find uf T ≡ (∀a∈V. ∀b∈V. per_compare uf a b ⟷ ((a,b)∈ connected T ))"
definition"uf_graph_invar uf_T ≡ case uf_T of (uf, T) ==> corresponding_union_find uf T ∧ Domain uf = V"
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.