theory Check_Connected_Impl imports "~/P/afp/thys/Simpl/Vcg" begin text {* Implemenation *} type_synonym IVertex = nat type_synonym IEdge_Id = nat type_synonym IEdge = "IVertex \ IVertex" type_synonym IGraph = "nat \ nat \ (IEdge_Id \ IEdge)" (* last vertex vs. set/list of vertices? *) abbreviation iedge_cnt :: "IGraph \ nat" where "iedge_cnt G \ fst (snd G)" abbreviation iedges :: "IGraph \ IEdge_Id \ IEdge" where "iedges G \ snd (snd G)" definition has_unique_edges_inv1 :: "IGraph \ nat \ bool" where "has_unique_edges_inv1 G k \ \i < k. \j < iedge_cnt G. i \ j \ iedges G i \ iedges G j" definition has_unique_edges_inv2 :: "IGraph \ nat \ nat \ bool" where "has_unique_edges_inv2 G i k \ \j < k. i \ j \ iedges G i \ iedges G j" procedures has_unique_edges (G :: IGraph | R :: bool) where i :: nat j :: nat e1 :: IEdge e2 :: IEdge in " ANNO G. \ \G = G \ \R :== True ;; \i :== 0 ;; TRY WHILE \i < iedge_cnt \G INV \ has_unique_edges_inv1 \G \i \ \i \ iedge_cnt \G \ \R = True \ \G = G\ DO \e1 :== iedges \G \i ;; \j :== 0 ;; WHILE \j < iedge_cnt \G INV \ has_unique_edges_inv2 \G \i \j \ \e1 = iedges \G \i \ \i < iedge_cnt \G \ \j \ iedge_cnt \G \ has_unique_edges_inv1 \G \i \ \R = True \ \G = G\ DO \e2 :== iedges \G \j ;; IF \i \ \j \ fst \e1 = fst \e2 \ snd \e1 = snd \e2 THEN \R :== False ;; THROW FI ;; \j :== \j + 1 OD ;; \i :== \i + 1 OD CATCH SKIP END \ \G = G \ \R = has_unique_edges_inv1 \G (iedge_cnt \G) \ " procedures is_proper_graph (G :: IGraph | R :: bool) "\R :== CALL has_unique_edges(\G)" lemma has_unique_edges_inv1_step: "has_unique_edges_inv1 G (Suc i) \ has_unique_edges_inv1 G i \ (\j < iedge_cnt G. i \ j \ iedges G i \ iedges G j)" by (auto simp: has_unique_edges_inv1_def less_Suc_eq) lemma has_unique_edges_inv2_step: "has_unique_edges_inv2 G i (Suc j) \ has_unique_edges_inv2 G i j \ (i \ j \ iedges G i \ iedges G j)" by (auto simp: has_unique_edges_inv2_def less_Suc_eq) lemma (in has_unique_edges_impl) has_unique_edges_spec: "\ \ \ \G = G \ \R :== PROC has_unique_edges(\G) \ \R = has_unique_edges_inv1 G (iedge_cnt G) \" apply vcg apply (simp_all add: has_unique_edges_inv1_step has_unique_edges_inv2_step) apply (auto simp add: has_unique_edges_inv1_def has_unique_edges_inv2_def prod_eq_iff) done lemma (in has_unique_edges_impl) "\ \ \ \G = G \ \R :== CALL has_unique_edges(\G) \ \R \ has_unique_edges_inv1 G (iedge_cnt G) \" apply vcg_step apply vcg_step oops end