Skip to content

Commit daea920

Browse files
committed
continued work on the L-reduction
1 parent af8d572 commit daea920

File tree

2 files changed

+574
-234
lines changed

2 files changed

+574
-234
lines changed

graphs/GraphAdjMap.thy

Lines changed: 57 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ lemma invar_set_of_list: "invar (set_of_list xs)"
152152
lemma set_of_list: "set (set_of_list xs) = List.set xs"
153153
using set_insert_all by (auto simp: set_specs)
154154

155+
lemma isin_set_of_list: "isin (set_of_list xs) x \<longleftrightarrow> x \<in> List.set xs"
156+
using invar_set_of_list set_of_list by (auto simp: set_specs)
157+
158+
(* lemma set_of_list_comm: "isin (set_of_list (xs @ ys)) x \<longleftrightarrow> isin (set_of_list (ys @ xs)) x"
159+
by (auto simp: isin_set_of_list simp del: set_of_list.simps) *)
160+
155161
end
156162

157163
section \<open>Abstract Adjacency Map\<close>
@@ -358,8 +364,8 @@ lemma ugraph_adj_map_invarI:
358364
using assms by auto
359365

360366
lemma adj_vertices_neq:
361-
assumes "ugraph_adj_map_invar G"
362-
shows "isin (\<N> G u) v \<and> u \<noteq> v \<longleftrightarrow> isin (\<N> G u) v"
367+
assumes "ugraph_adj_map_invar G" "isin (\<N> G u) v"
368+
shows "u \<noteq> v"
363369
using assms by auto
364370

365371
lemma vertices_def2:
@@ -436,6 +442,41 @@ qed
436442
lemma vs_uedges: "Vs (set_of_uedge ` (uedges G)) = vertices G"
437443
using vs_uedges_subset_vertices vertices_subset_vs_uedges by auto
438444

445+
lemma rep_idem: "rep (rep e) = rep e"
446+
proof -
447+
obtain u v where [simp]: "e = uEdge u v"
448+
by (cases e)
449+
then consider "rep e = uEdge u v" | "rep e = uEdge v u"
450+
using is_rep by auto
451+
thus ?thesis
452+
using is_rep by cases auto
453+
qed
454+
455+
lemma rep_simps:
456+
assumes "rep e = uEdge u v"
457+
shows "rep e = rep (uEdge u v)" "rep e = rep (uEdge v u)"
458+
"rep (uEdge u v) = uEdge u v" "rep (uEdge v u) = uEdge u v"
459+
proof -
460+
show "rep e = rep (uEdge u v)"
461+
apply (subst assms[symmetric])
462+
apply (rule rep_idem[symmetric])
463+
done
464+
thus "rep e = rep (uEdge v u)"
465+
by (auto simp add: is_rep)
466+
thus "rep (uEdge u v) = uEdge u v" "rep (uEdge v u) = uEdge u v"
467+
using assms by (auto simp add: is_rep)
468+
qed
469+
470+
lemma repE:
471+
assumes "rep e = uEdge u v"
472+
obtains "e = uEdge u v" | "e = uEdge v u"
473+
using assms is_rep by (cases e) (metis uedge.inject)
474+
475+
lemma rep_cases:
476+
assumes "rep e = rep (uEdge u v)"
477+
obtains "rep e = uEdge u v" | "rep e = uEdge v u"
478+
using assms is_rep by auto
479+
439480
end
440481

441482
locale ugraph_adj_map_by_linorder = \<comment> \<open>Represent an undirected graph by a anti-symmetric digraph.
@@ -540,7 +581,7 @@ qed *)
540581

541582
end
542583

543-
locale complete_graph_for_ugraph_adj_map =
584+
locale graph_of_vertices_for_ugraph_adj_map =
544585
ugraph_adj_map_fold_vset map_empty update map_delete lookup map_invar set_empty insert set_delete
545586
isin set set_invar union inter diff rep fold_vset
546587
for map_empty :: "'map" and update :: "'v \<Rightarrow> 'vset \<Rightarrow> 'map \<Rightarrow> 'map" and map_delete lookup
@@ -582,7 +623,7 @@ lemma non_empty_neighborhood_isin_X:
582623
assumes "set_invar X"
583624
and "\<And>x. isin X x \<Longrightarrow> set_invar (n x)" \<comment> \<open>Every neighborhood satisfies the invariants.\<close>
584625
and "\<And>x. isin X x \<Longrightarrow> \<exists>y. isin (n x) y" \<comment> \<open>Every neighborhood is non-empty.\<close>
585-
and "\<And>x y. isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
626+
and "\<And>x y. isin X x \<Longrightarrow> isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
586627
and "isin (\<N> (graph_of_vertices n X) u) v"
587628
shows "isin X u"
588629
using assms set_specs graph_of_vertices_neighborhood by (cases "isin X u") auto
@@ -591,7 +632,7 @@ lemma isin_neighborhood_isin_X:
591632
assumes "set_invar X"
592633
and "\<And>x. isin X x \<Longrightarrow> set_invar (n x)" \<comment> \<open>Every neighborhood satisfies the invariants.\<close>
593634
and "\<And>x. isin X x \<Longrightarrow> \<exists>y. isin (n x) y" \<comment> \<open>Every neighborhood is non-empty.\<close>
594-
and "\<And>x y. isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
635+
and "\<And>x y. isin X x \<Longrightarrow> isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
595636
and "isin (\<N> (graph_of_vertices n X) u) v"
596637
shows "isin X v"
597638
proof -
@@ -605,7 +646,7 @@ lemma vertices_graph_of_vertices:
605646
assumes "set_invar X"
606647
and "\<And>x. isin X x \<Longrightarrow> set_invar (n x)" \<comment> \<open>Every neighborhood satisfies the invariants.\<close>
607648
and "\<And>x. isin X x \<Longrightarrow> \<exists>y. isin (n x) y" \<comment> \<open>Every neighborhood is non-empty.\<close>
608-
and "\<And>x y. isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
649+
and "\<And>x y. isin X x \<Longrightarrow> isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
609650
shows "vertices (graph_of_vertices n X) = set X" (is "vertices ?G\<^sub>X = set X")
610651
proof (rule equalityI[OF subsetI subsetI])
611652
fix v
@@ -631,18 +672,18 @@ lemma finite_graph_of_vertices:
631672
assumes "set_invar X"
632673
and "\<And>x. isin X x \<Longrightarrow> set_invar (n x)" \<comment> \<open>Every neighborhood satisfies the invariants.\<close>
633674
and "\<And>x. isin X x \<Longrightarrow> \<exists>y. isin (n x) y" \<comment> \<open>Every neighborhood is non-empty.\<close>
634-
and "\<And>x y. isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
675+
and "\<And>x y. isin X x \<Longrightarrow> isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
635676
shows "finite (uedges (graph_of_vertices n X))"
636677
using assms finite_sets uedges_finite vertices_graph_of_vertices by auto
637678

638679
lemma invar_graph_of_vertices:
639680
assumes "set_invar X"
640681
and "\<And>x. isin X x \<Longrightarrow> set_invar (n x)" \<comment> \<open>Every neighborhood satisfies the invariants.\<close>
641682
and "\<And>x. isin X x \<Longrightarrow> \<exists>y. isin (n x) y" \<comment> \<open>Every neighborhood is non-empty.\<close>
642-
and "\<And>x y. isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
683+
and "\<And>x y. isin X x \<Longrightarrow> isin (n x) y \<Longrightarrow> isin X y" \<comment> \<open>Every neighborhood can only be a subset of \<open>X\<close>.\<close>
643684
\<comment> \<open>The following assumptions are needed to obtain a valid undirected graph.\<close>
644-
and "\<And>x. \<not> isin (n x) x" \<comment> \<open>The neighborhood function is irreflexive.\<close>
645-
and "\<And>x y. isin (n x) y \<Longrightarrow> isin (n y) x" \<comment> \<open>The neighborhood function is symmetric.\<close>
685+
and "\<And>x. isin X x \<Longrightarrow> \<not> isin (n x) x" \<comment> \<open>The neighborhood function is irreflexive.\<close>
686+
and "\<And>x y. isin X x \<Longrightarrow> isin (n x) y \<Longrightarrow> isin (n y) x" \<comment> \<open>The neighborhood function is symmetric.\<close>
646687
shows "ugraph_adj_map_invar (graph_of_vertices n X)" (is "ugraph_adj_map_invar ?G\<^sub>X")
647688
proof (intro ugraph_adj_map_invarI)
648689
show "map_invar ?G\<^sub>X"
@@ -652,85 +693,21 @@ proof (intro ugraph_adj_map_invarI)
652693
show "finite (uedges ?G\<^sub>X)"
653694
using assms by (intro finite_graph_of_vertices)
654695
show "\<And>v. \<not> isin (\<N> ?G\<^sub>X v) v"
655-
using assms(1,5) graph_of_vertices_neighborhood set_specs by (auto split: if_splits)
696+
using assms(1,5) graph_of_vertices_neighborhood set_specs
697+
by (auto simp del: graph_of_vertices.simps split: if_splits)
656698
show "\<And>u v. isin (\<N> ?G\<^sub>X u) v \<longrightarrow> isin (\<N> ?G\<^sub>X v) u"
657699
proof
658700
fix u v
659701
assume "isin (\<N> ?G\<^sub>X u) v"
660-
hence "isin (n u) v"
702+
hence "isin X u" and "isin (n u) v"
661703
using assms(1) graph_of_vertices_neighborhood set_specs by (auto split: if_splits)
704+
hence "isin X v" and "isin (n v) u"
705+
using assms(4,6) by blast+
662706
thus "isin (\<N> ?G\<^sub>X v) u"
663-
using assms(1,4,6) graph_of_vertices_neighborhood by auto
707+
using assms(1) graph_of_vertices_neighborhood by auto
664708
qed
665709
qed
666710

667-
(* fun complete_graph :: "'vset \<Rightarrow> 'map" where
668-
"complete_graph X = fold_vset (\<lambda>v. update v (set_delete v X)) X map_empty" *)
669-
670-
fun neighborhood_compl :: "'vset \<Rightarrow> 'v \<Rightarrow> 'vset" ("\<N>\<^sub>C") where
671-
"neighborhood_compl X v = (if isin X v then set_delete v X else set_empty)"
672-
673-
lemma neighborhood_compl_sym:
674-
assumes "set_invar X" "isin (\<N>\<^sub>C X x) y"
675-
shows "isin (\<N>\<^sub>C X y) x"
676-
proof -
677-
have "isin X x"
678-
using assms set_specs by fastforce
679-
thus ?thesis
680-
using assms set_specs by auto
681-
qed
682-
683-
fun complete_graph :: "'vset \<Rightarrow> 'map" where
684-
"complete_graph X = graph_of_vertices (\<N>\<^sub>C X) X"
685-
686-
lemma map_invar_complete_graph: "set_invar X \<Longrightarrow> map_invar (complete_graph X)"
687-
using map_invar_graph_of_vertices by auto
688-
689-
lemma complete_graph_neighborhood: "set_invar X \<Longrightarrow> \<N> (complete_graph X) = \<N>\<^sub>C X"
690-
using graph_of_vertices_neighborhood by auto
691-
692-
lemma vertices_complete_graph:
693-
assumes "set_invar X"
694-
and "\<And>x. isin X x \<Longrightarrow> \<exists>y. isin (set_delete x X) y" \<comment> \<open>The set \<open>X\<close> contains at least two vertices.\<close>
695-
shows "vertices (complete_graph X) = set X" (is "vertices ?G\<^sub>X = set X")
696-
using assms vertices_graph_of_vertices set_specs by fastforce
697-
698-
lemma invar_complete_graph:
699-
assumes "set_invar X"
700-
and "\<And>x. isin X x \<Longrightarrow> \<exists>y. isin (set_delete x X) y" \<comment> \<open>The set \<open>X\<close> contains at least two vertices.\<close>
701-
shows "ugraph_adj_map_invar (complete_graph X)"
702-
using assms set_specs
703-
proof (simp del: graph_of_vertices.simps; intro invar_graph_of_vertices)
704-
show "\<And>x y. isin (\<N>\<^sub>C X x) y \<Longrightarrow> isin X y"
705-
using assms set_specs
706-
proof -
707-
fix x y
708-
assume "isin (\<N>\<^sub>C X x) y"
709-
moreover hence "\<N>\<^sub>C X x = set_delete x X"
710-
using assms set_specs by auto
711-
ultimately show "isin X y"
712-
using assms set_specs by auto
713-
qed
714-
show "\<And>x y. isin (\<N>\<^sub>C X x) y \<Longrightarrow> isin (\<N>\<^sub>C X y) x"
715-
using assms neighborhood_compl_sym by auto
716-
qed auto
717-
718-
lemma complete_graph_is_complete:
719-
assumes "set_invar X"
720-
and "\<And>x. isin X x \<Longrightarrow> \<exists>y. isin (set_delete x X) y" \<comment> \<open>The set \<open>X\<close> contains at least two vertices.\<close>
721-
shows "is_complete (set_of_uedge ` uedges (complete_graph X))" (is "is_complete ?E")
722-
proof (intro is_completeI)
723-
let ?f="\<lambda>v. set_delete v X"
724-
fix u v
725-
assume "u \<in> Vs ?E" "v \<in> Vs ?E" "u \<noteq> v"
726-
hence "isin X u" and "isin (?f u) v"
727-
using assms set_specs by (auto simp: vs_uedges vertices_complete_graph[OF assms,symmetric])
728-
hence "isin (\<N> (complete_graph X) u) v"
729-
using assms complete_graph_neighborhood by (auto simp: neighborhood_def)
730-
thus "{u,v} \<in> ?E"
731-
by (intro isin_neighborhood_set_edge)
732-
qed
733-
734711
end
735712

736713
(* TODO: move below to other thy *)

0 commit comments

Comments
 (0)