Theory Containers_DFS_Ex
section ‹Formalisation of depth-first search using Containers›
theory Containers_DFS_Ex imports
"../Containers"
"HOL-Library.Transitive_Closure_Table"
begin
subsection ‹Auxiliary stuff›
definition restrict :: "('a × 'a) set ⇒ 'a set ⇒ ('a × 'a) set" (infixl "↿" 60)
where "R ↿ A = {(a, b) ∈ R. b ∈ A}"
lemma in_restrict [iff]: "(a, b) ∈ R ↿ A ⟷ (a, b) ∈ R ∧ b ∈ A"
by(simp add: restrict_def)
lemma restrict_UNIV [simp]: "R ↿ UNIV = R"
by auto
lemma restrict_restrict [simp]: "R ↿ A ↿ B = R ↿ (A ∩ B)"
by auto
lemma rtrancl_restrict_reachable:
assumes x: "(x, y) ∈ R⇧*"
and z: "(z, y) ∉ R⇧*"
shows "(x, y) ∈ (R ↿ - R⇧* `` {z})⇧*"
using x
proof(induction rule: converse_rtrancl_induct)
case (step x x')
from ‹(x, x') ∈ R› z ‹(x', y) ∈ R⇧*›
have "(x, x') ∈ R ↿ - R⇧* `` {z}" by(auto intro: rtrancl_trans converse_rtrancl_into_rtrancl)
thus ?case using step.IH by(rule converse_rtrancl_into_rtrancl)
qed simp
lemma rtrancl_restrict_start:
assumes "(x, y) ∈ R⇧*"
shows "(x, y) ∈ (R ↿ - {x})⇧*"
proof -
let ?R = "λx y. (x, y) ∈ R"
define z where "z ≡ x"
with assms obtain xs where "rtrancl_path ?R x xs y" "z ∉ set xs"
by(auto simp add: rtrancl_def rtranclp_eq_rtrancl_path elim: rtrancl_path_distinct)
thus "(x, y) ∈ (R ↿ - {z})⇧*"
by induction(auto intro: converse_rtrancl_into_rtrancl)
qed
lemma (in comp_fun_commute) fold_set_union_disj:
assumes "finite A" "finite B" "A ∩ B = {}"
shows "Finite_Set.fold f z (A ∪ B) = Finite_Set.fold f (Finite_Set.fold f z A) B"
using assms(2,1,3) by induction simp_all
lemma Image_insert [simp]:
fixes A :: "'a set"
assumes "NO_MATCH ({} :: 'a set) A"
shows "R `` insert x A = R `` {x} ∪ (R `` A)"
by(auto)
subsection ‹Declarative definition›