lemma finite_simp: "{(u,v). u ∈ front ∧ v ∈ (Pair_Graph.neighbourhood (Graph.digraph_abs G) u) ∧ v ∉ vis} = {(u,v). u ∈ front} ∩ {(u,v). v ∈ (Pair_Graph.neighbourhood (Graph.digraph_abs G) u)} - {(u,v) . v ∈ vis}" "finite {(u, v)| v . v ∈ (s u)} = finite (s u)" using finite_image_iff[where f = snd and A = "{(u, v) |v. v ∈ s u}"] by (auto simp: inj_on_def image_def)
moreoverhave False if"?dv < ?dv' + 1" proof- have"?dv ≤ ?dv'" using that eSuc_plus_1 ileI1 by force moreoverhave"?dv ≠∞" using that enat_ord_simps(4) by fastforce moreoverhave"v ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state)" using assms by (auto simp: BFS_upd1_def Let_def elim!: invar_well_formed_props invar_subsets_props)
ultimatelyshow False using‹invar_dist_bounded bfs_state› apply(elim invar_props_elims) apply(drule dist_set_not_inf) using dual_order.trans dist_set_mem by (smt (verit, best)) qed ultimatelyshow ?thesis by force qed
lemma plus_lt_enat: "[(a::enat) ≠∞; b < c]==> a + b < a + c" using enat_add_left_cancel_less by presburger
lemma plus_one_side_lt_enat: "[(a::enat) ≠∞; 0 < b]==> a < a + b" using plus_lt_enat by auto
lemma invar_3_1_holds_upd1_new[invar_holds_intros]: "[BFS_call_1_conds bfs_state; invar_well_formed bfs_state; invar_subsets bfs_state ; invar_3_1 bfs_state; invar_3_2 bfs_state; invar_dist_bounded bfs_state; invar_current_reachable bfs_state] ==> invar_3_1 (BFS_upd1 bfs_state)" proof(intro invar_props_intros, goal_cases) case assms: (1 u v) obtain u' v' where
uv'[intro]: "u ∈ neighbourhood (Graph.digraph_abs G) u'""u' ∈ t_set (current bfs_state)" "v ∈ neighbourhood (Graph.digraph_abs G) v'""v' ∈ t_set (current bfs_state)" using assms(1,2,8,9) by (auto simp: BFS_upd1_def Let_def elim!: invar_well_formed_props) moreoverhence"distance_set (Graph.digraph_abs G) (t_set srcs) v' = distance_set (Graph.digraph_abs G) (t_set srcs) u'" (is"?d v' = ?d u'") using‹invar_3_1 bfs_state› by (auto elim: invar_props_elims) moreoverhave"distance_set (Graph.digraph_abs G) (t_set srcs) v = ?d v' + 1" using assms by (auto intro!: dist_current_plus_1_new) moreoverhave"distance_set (Graph.digraph_abs G) (t_set srcs) u = ?d u' + 1" using assms by (auto intro!: dist_current_plus_1_new) ultimatelyshow ?case by auto next case (2 u v) thenobtain v' where uv'[intro]: "v ∈ neighbourhood (Graph.digraph_abs G) v'""v' ∈ t_set (current bfs_state)" by (auto simp: BFS_upd1_def Let_def elim!: invar_well_formed_props invar_subsets_props) hence"distance_set (Graph.digraph_abs G) (t_set srcs) v = distance_set (Graph.digraph_abs G) (t_set srcs) v' + 1" (is"?d v = ?d v' + _") using2 by(fastforce intro!: dist_current_plus_1_new)
show ?case proof(cases "0 < ?d u") case in_srcs: True moreoverhave"?d v' < ∞" using‹?d v = ?d u›‹invar_well_formed bfs_state›‹invar_subsets bfs_state›‹v' ∈ t_set (current bfs_state)› ‹invar_current_reachable bfs_state› by (auto elim!: invar_well_formed_props invar_subsets_props invar_current_reachable_props) hence"?d v < ∞" using‹?d v = ?d v' + 1› by (simp add: plus_eq_infty_iff_enat) hence"?d u < ∞" using‹?d v = ?d u› by auto ultimatelyobtain u' where"?d u' + 1 = ?d u""u ∈ neighbourhood (Graph.digraph_abs G) u'" using distance_set_parent' by (metis srcs_invar(1)) hence"?d u' = ?d v'" using‹?d v = ?d v' + 1›‹?d v = ?d u› by auto hence"u' ∈ t_set (current bfs_state)" using‹invar_3_1 bfs_state› ‹v' ∈ t_set (current bfs_state)› by (auto elim!: invar_3_1_props) moreoverhave"?d u' < ?d u" using‹?d u < \∞› using zero_less_one not_infinity_eq by (fastforce intro!: plus_one_side_lt_enat simp: ‹?d u' + 1 = ?d u›[symmetric]) hence"u ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state)" using‹invar_3_2 bfs_state›‹u' ∈ t_set (current bfs_state)› by (auto elim!: invar_3_2_props dest: leD) ultimatelyshow ?thesis using‹invar_well_formed bfs_state›‹invar_subsets bfs_state›‹u ∈ neighbourhood (Graph.digraph_abs G) u'› apply(auto simp: BFS_upd1_def Let_def elim!: invar_well_formed_props invar_subsets_props) by blast next case not_in_srcs: False text‹Contradiction because if ‹u ∈ srcs› then distance srcs to a vertex in srcs is > 0. This is
because the distance from srcs to ‹u› is the same as that to ‹v›.› thenshow ?thesis using‹?d v = ?d u›‹?d v = ?d v' + 1› by auto qed qed
lemma invar_dist_props[invar_props_elims]: "invar_dist bfs_state ==> v ∈ dVs (Graph.digraph_abs G) - t_set srcs ==> [ [v ∈ (t_set (visited bfs_state) ∪ t_set (current bfs_state)) ==> distance_set (Graph.digraph_abs G) (t_set srcs) v = distance_set (Graph.digraph_abs (parents bfs_state)) (t_set srcs) v]==> P ] ==> P" unfolding invar_dist_def by auto
lemma invar_dist_intro[invar_props_intros]: "[∧v. [v ∈ dVs (Graph.digraph_abs G) - t_set srcs; v ∈ t_set (visited bfs_state)∪ t_set (current bfs_state)]==> (distance_set (Graph.digraph_abs G) (t_set srcs) v = distance_set (Graph.digraph_abs (parents bfs_state)) (t_set srcs) v)] ==> invar_dist bfs_state" unfolding invar_dist_def by auto
lemma invar_goes_through_current_props[invar_props_elims]: "invar_goes_through_current bfs_state ==> [[∧u v p. [u ∈t_set (visited bfs_state) ∪ t_set (current bfs_state); v ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state); Vwalk.vwalk_bet (Graph.digraph_abs G) u p v] ==> set p ∩ t_set (current bfs_state) ≠ {}] ==> P] ==> P" unfolding invar_goes_through_current_def by auto
lemma invar_goes_through_current_intro[invar_props_intros]: "[∧u v p. [u ∈t_set (visited bfs_state) ∪ t_set (current bfs_state); v ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state); Vwalk.vwalk_bet (Graph.digraph_abs G) u p v] ==> set p ∩ t_set (current bfs_state) ≠ {}] ==> invar_goes_through_current bfs_state" unfolding invar_goes_through_current_def by auto
lemma invar_goes_through_active_holds_upd1[invar_holds_intros]: "[BFS_call_1_conds bfs_state; invar_well_formed bfs_state; invar_subsets bfs_state; invar_goes_through_current bfs_state] ==> invar_goes_through_current (BFS_upd1 bfs_state)" proof(intro invar_props_intros, goal_cases) case (1 u v p) hence"v ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state)" by (auto simp: Let_def BFS_upd1_def elim!: invar_well_formed_props invar_subsets_props) show ?case proof(cases "u ∈ t_set (visited bfs_state) ∪ t_set (current bfs_state)") case u_in_visited: True have"Vwalk.vwalk_bet (Graph.digraph_abs G) u p v""set p ∩ t_set (current bfs_state) ≠ {}" using‹invar_goes_through_current bfs_state› ‹v ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state)› ‹vwalk_bet (Graph.digraph_abs G) u p v› u_in_visited by (auto elim!: invar_goes_through_current_props) moreoverhave"u ∈ set p" using‹Vwalk.vwalk_bet (Graph.digraph_abs G) u p v› by(auto intro: hd_of_vwalk_bet'') ultimatelyhave"∃ p1 x p2. p = p1 @ [x] @ p2 ∧ x ∈ t_set (current bfs_state) ∧ (∀y∈set p2. y ∉ (t_set (visited bfs_state) ∪ t_set (current bfs_state)) ∧ y ∉ (t_set (current bfs_state)))" using‹invar_goes_through_current bfs_state› u_in_visited ‹v ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state)› ‹invar_well_formed bfs_state›‹invar_subsets bfs_state› apply (intro list_2_preds[where ?P2.0 = "(λx. x ∈ t_set (current bfs_state))",
simplified list_inter_mem_iff[symmetric]]) by (fastforce elim!: invar_goes_through_current_props dest!: vwalk_bet_suff split_vwalk)+
thenobtain p1 x p2 where"p = p1 @ x # p2"and "x ∈ t_set (current bfs_state)"and
unvisited: "(∧y. y∈set p2 ==> y ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state))" by auto moreoverhave"last p = v" using‹vwalk_bet (Graph.digraph_abs G) u p v› by auto ultimatelyhave"v ∈ set p2" using‹v ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state)› ‹invar_well_formed bfs_state›‹invar_subsets bfs_state› by (auto elim: invar_props_elims) thenobtain v' p2' where"p2 = v' # p2'" by (cases p2) auto hence"v' ∈ neighbourhood (Graph.digraph_abs G) x" using‹p = p1 @ x # p2›‹Vwalk.vwalk_bet (Graph.digraph_abs G) u p v›
split_vwalk by fastforce moreoverhave"v' ∈ set p2" using‹p2 = v' # p2'› by auto ultimatelyhave"v' ∈ t_set (current (BFS_upd1 bfs_state))" using‹invar_well_formed bfs_state›‹invar_subsets bfs_state›‹x ∈ t_set (current bfs_state)› by(fastforce simp: BFS_upd1_def Let_def elim!: invar_well_formed_props invar_subsets_props dest!: unvisited) thenshow ?thesis by(auto intro!: invar_goes_through_current_intro simp: ‹p = p1 @ x # p2›‹p2 = v' # p2'›) next case u_not_in_visited: False hence"u ∈ t_set (current (BFS_upd1 bfs_state))" using‹invar_well_formed bfs_state› ‹u ∈ t_set (visited (BFS_upd1 bfs_state)) ∪ t_set (current (BFS_upd1 bfs_state))› by (auto simp: BFS_upd1_def Let_def elim: invar_props_elims) moreoverhave"u ∈ set p" using‹Vwalk.vwalk_bet (Graph.digraph_abs G) u p v› by (auto intro: hd_of_vwalk_bet'') ultimatelyshow ?thesis by(auto intro!: invar_goes_through_current_intro) qed qed
ultimatelyshow ?thesis using‹?dSrcsT v = ?dSrcsG v› by auto qed ultimatelyshow ?thesis by (auto simp: bfs_state'_def) next case v_not_in_tree: False
show ?thesis proof(rule ccontr, goal_cases) case1 moreoverhave‹invar_subsets bfs_state'› using‹BFS_call_1_conds bfs_state›‹invar_well_formed bfs_state›‹invar_subsets bfs_state› by (auto intro!: invar_subsets_holds_upd1 simp: bfs_state'_def) hence‹Graph.digraph_abs (parents bfs_state') ⊆ Graph.digraph_abs G› by (auto elim: invar_props_elims) ultimatelyhave"?dSrcsG v < ?dSrcsT' v" by (simp add: distance_set_subset order_less_le bfs_state'_def) hence"?dSrcsG v < ?dSrcsT' v" text‹because the tree is a subset of the Graph, which invar?› by (simp add: distance_set_subset order_less_le bfs_state'_def)
have"invar_current_no_out bfs_state'" using assms by(auto intro: invar_holds_intros simp: bfs_state'_def)
have **: "u ∈ t_set (current bfs_state') ∨ v ∈ t_set (current bfs_state')" if"(u,v) ∈ (Graph.digraph_abs (parents bfs_state')) - (Graph.digraph_abs (parents bfs_state))"for u v using‹invar_well_formed bfs_state›‹invar_subsets bfs_state› dVsI that by(fastforce dest: dVsI simp: bfs_state'_def dVs_def BFS_upd1_def Let_def
elim!: invar_well_formed_props invar_subsets_props)
have ?caseif"length p > 1" proof- have"u ∈ t_set (visited bfs_state) ∪ t_set (current bfs_state)" proof(rule ccontr, goal_cases) have"u ∈ dVs (Graph.digraph_abs (parents bfs_state'))" using assms(8) by (auto simp: bfs_state'_def) hence"u ∈ t_set (visited bfs_state') ∪ t_set (current bfs_state')" using‹invar_subsets bfs_state'› by (auto elim: invar_props_elims) moreovercase1 ultimatelyhave"u ∈ t_set (current bfs_state')" using assms by(auto simp: Let_def bfs_state'_def BFS_upd1_def elim!: invar_well_formed_props invar_subsets_props) moreoverobtain u' where"(u,u') ∈ Graph.digraph_abs (parents bfs_state')" using‹length p > 1› assms(8) ‹invar_subsets bfs_state› by (auto elim!: Vwalk.vwalk_bet_props
simp: eval_nat_numeral Suc_le_length_iff Suc_le_eq[symmetric] bfs_state'_def
split: if_splits) ultimatelyshow ?case using‹invar_current_no_out bfs_state'› by (auto elim!: invar_current_no_out_props) qed
show ?thesis proof(cases "v ∉ t_set (visited bfs_state) ∪ t_set (current bfs_state)") case v_not_visited: True show ?thesis proof(rule ccontr, goal_cases) case1
moreoverhave"vwalk_bet (Graph.digraph_abs G) u p v" by (metis ‹invar_subsets bfs_state'› assms(8) bfs_state'_def invar_subsets_props vwalk_bet_subset)
ultimatelyhave"length p - 1 > distance_set (Graph.digraph_abs G) (t_set srcs) v" using‹u ∈ t_set srcs›1 apply auto by (metis One_nat_def order_neq_le_trans vwalk_bet_dist_set)
hence"length p - 2 ≥ distance_set (Graph.digraph_abs G) (t_set srcs) v" using‹length p > 1› apply (auto simp: eval_nat_numeral) by (metis leD leI Suc_diff_Suc Suc_ile_eq) moreoverobtain p' v' where"p = p' @ [v', v]" using‹length p > 1› apply (clarsimp
simp: eval_nat_numeral Suc_le_length_iff Suc_le_eq[symmetric]
split: if_splits) by (metis append.right_neutral append_butlast_last_cancel assms(8) length_Cons
length_butlast length_tl list.sel(3) list.size(3) nat.simps(3) vwalk_bet_def) have"vwalk_bet (Graph.digraph_abs (parents bfs_state)) u (p' @ [v']) v'" proof(rule ccontr, goal_cases) case1 moreoverhave"vwalk_bet (Graph.digraph_abs (parents (BFS_upd1 bfs_state))) u (p' @ [v']) v'" using assms(8) ‹p = p' @ [v', v]› by (simp add: vwalk_bet_pref) ultimatelyshow ?case proof(elim vwalk_bet_not_vwalk_bet_elim_2[OF _ "1"], goal_cases) case1 thenshow ?case by (metis ‹distance_set (Graph.digraph_abs G) (t_set srcs) v ≤ enat (length p - 2)› ‹p = p' @ [v', v]›‹vwalk_bet (Graph.digraph_abs G) u p v› assms(3)
diff_is_0_eq distance_set_0 invar_subsets_def le_zero_eq length_append_singleton
list.sel(3) not_less_eq_eq subset_eq v_not_visited vwalk_bet_endpoints(2)
vwalk_bet_vertex_decompE zero_enat_def) next case (2 u'' v'') moreoverhence"u'' ∉ t_set (current bfs_state')" using‹invar_current_no_out bfs_state'›‹invar_subsets bfs_state'› by (auto simp: bfs_state'_def[symmetric] elim: invar_props_elims) ultimatelyhave"v'' ∈ t_set (current bfs_state')" using ** ‹invar_subsets bfs_state'› by (auto simp: bfs_state'_def[symmetric]) moreoverhence no_outgoing_v'': "(v'',u'') ∉ Graph.digraph_abs (parents bfs_state')" for u'' using‹invar_current_no_out bfs_state'› that by (auto elim: invar_props_elims) hence"last (p @ [v']) = v''" using that ‹vwalk_bet (Graph.digraph_abs (parents (BFS_upd1 bfs_state))) u (p' @ [v']) v'›[simplified bfs_state'_def[symmetric]] apply (clarsimp dest: v_in_edge_in_vwalk elim!: vwalk_bet_props intro!: no_outgoing_last) by (metis "2"(2) last_snoc no_outgoing_last v_in_edge_in_vwalk(2)) hence"v' = v''" using that by auto moreoverhave"(v',v) ∈ Graph.digraph_abs (parents bfs_state')" using‹p = p' @ [v', v]› assms(8) by (fastforce simp: bfs_state'_def [symmetric] dest: split_vwalk) ultimatelyshow ?case using that no_outgoing_v'' by auto qed qed hence"length (p' @ [v']) - 1 = distance_set (Graph.digraph_abs G) (t_set srcs) v'" using‹invar_parents_shortest_paths bfs_state›‹u ∈ t_set srcs› by (force elim!: invar_props_elims) hence"length p - 2 = distance_set (Graph.digraph_abs G) (t_set srcs) v'" (is"_ = ?dist v'") by (auto simp: ‹p = p' @ [v', v]›) hence"?dist v ≤ ?dist v'" using‹?dist v ≤ length p - 2› dual_order.trans by presburger hence"v ∈ t_set (visited bfs_state) ∪ t_set (current bfs_state) " using‹invar_subsets bfs_state›‹invar_dist_bounded bfs_state›‹u ∈ t_set srcs› ‹vwalk_bet (Graph.digraph_abs (parents bfs_state)) u (p' @ [v']) v'› by(blast elim!: invar_props_elims dest!: vwalk_bet_endpoints(2)) thus ?case using v_not_visited by auto qed next case v_visited: False
have"Vwalk.vwalk_bet (Graph.digraph_abs (parents bfs_state)) u p v" proof(rule ccontr, goal_cases) case1 thus ?case proof(elim vwalk_bet_not_vwalk_bet_elim_2[OF assms(8)], goal_cases) case1 thenshow ?case using that by auto next case (2 u' v') moreoverhence"u' ∉ t_set (current bfs_state')" using‹invar_current_no_out bfs_state'›‹invar_subsets bfs_state'› by (auto simp: bfs_state'_def[symmetric] elim: invar_props_elims) ultimatelyhave"v' ∈ t_set (current bfs_state')" using ** ‹invar_subsets bfs_state'› by (auto simp: bfs_state'_def[symmetric]) moreoverhence"(v',u') ∉ Graph.digraph_abs (parents bfs_state')"for u' using‹invar_current_no_out bfs_state'› by (auto elim: invar_props_elims) hence"last p = v'" using‹vwalk_bet (Graph.digraph_abs (parents (BFS_upd1 bfs_state))) u p v›[simplified bfs_state'_def[symmetric]] ‹(u',v') ∈ set (edges_of_vwalk p)› by (auto dest: v_in_edge_in_vwalk elim!: vwalk_bet_props intro!: no_outgoing_last) hence"v' = v" using‹vwalk_bet (Graph.digraph_abs (parents (BFS_upd1 bfs_state))) u p v› by auto ultimatelyshow ?case using v_visited ‹invar_well_formed bfs_state› by (auto simp: bfs_state'_def BFS_upd1_def Let_def elim: invar_props_elims) qed qed thenshow ?thesis using‹invar_parents_shortest_paths bfs_state›‹u ∈ t_set srcs› by (auto elim!: invar_props_elims) qed qed show ?case using‹1 < length p ==> length p - 1 = distance_set (Graph.digraph_abs G) (t_set srcs) v› ‹length p ≤ 1 ==> length p - 1 = distance_set (Graph.digraph_abs G) (t_set srcs) v› by fastforce qed
lemma BFS_terminates[termination_intros]: assumes"invar_well_formed BFS_state""invar_subsets BFS_state""invar_current_no_out BFS_state" shows"BFS_dom BFS_state" using wf_term_rel assms proof(induction rule: wf_induct_rule) case (less x) show ?case apply (rule BFS_domintros) by (auto intro: invar_holds_intros intro!: termination_intros less) qed
lemma not_vwalk_bet_empty[simp]: "¬ Vwalk.vwalk_bet (Graph.digraph_abs empty) u p v" using not_vwalk_bet_empty by (force simp add: Graph.digraph_abs_def Graph.neighb_def)+
show ?g4 using‹?g1›‹?g2›‹?g3› by (auto intro!: termination_intros)
show ?g5 "invar_3_3 initial_state""invar_parents_shortest_paths initial_state" "invar_current_no_out initial_state" by (auto simp add: initial_state_def intro!: invar_props_intros)
have *: "distance_set (Graph.digraph_abs G) (t_set srcs) v = 0"if"v ∈ t_set srcs"for v using that srcs_in_G by (fastforce intro: iffD2[OF distance_set_0[ where G = "(Graph.digraph_abs G)"]]) moreoverhave **: "v ∈ t_set srcs"if"distance_set (Graph.digraph_abs G) (t_set srcs) v = 0"for v using dist_set_inf i0_ne_infinity that by (force intro: iffD1[OF distance_set_0[ where G = "(Graph.digraph_abs G)"]]) ultimatelyshow"invar_3_1 initial_state""invar_3_2 initial_state""invar_dist_bounded initial_state" "invar_current_reachable initial_state" using dist_set_inf by(auto dest: dest: simp add: initial_state_def intro!: invar_props_intros dest!:)
show"invar_goes_through_current initial_state" by (auto simp add: initial_state_def dest: hd_of_vwalk_bet'' intro!: invar_props_intros) qed
lemma BFS_correct_1: "[u ∈ t_set srcs; t ∉ t_set (visited (BFS initial_state))] ==>∄p. vwalk_bet (Graph.digraph_abs G) u p t" apply(intro BFS_correct_1_ret_1[where bfs_state = "BFS initial_state"]) by(auto intro: invar_holds_intros ret_holds_intros)
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.