Theory Graph
section ‹Graph›
theory Graph
imports Rotation
begin
syntax
"_UNION1" :: "pttrns ⇒ 'b set ⇒ 'b set" (‹(3⋃(‹unbreakable›⇘_⇙)/ _)› [0, 10] 10)
"_INTER1" :: "pttrns ⇒ 'b set ⇒ 'b set" (‹(3⋂(‹unbreakable›⇘_⇙)/ _)› [0, 10] 10)
"_UNION" :: "pttrn ⇒ 'a set ⇒ 'b set ⇒ 'b set" (‹(3⋃(‹unbreakable›⇘_∈_⇙)/ _)› [0, 0, 10] 10)
"_INTER" :: "pttrn ⇒ 'a set ⇒ 'b set ⇒ 'b set" (‹(3⋂(‹unbreakable›⇘_∈_⇙)/ _)› [0, 0, 10] 10)
subsection‹Notation›
type_synonym vertex = "nat"
consts
vertices :: "'a ⇒ vertex list"
edges :: "'a ⇒ (vertex × vertex) set" (‹ℰ›)
abbreviation vertices_set :: "'a ⇒ vertex set" (‹𝒱›) where
"𝒱 f ≡ set (vertices f)"
subsection ‹Faces›
text ‹
We represent faces by (distinct) lists of vertices and a face type.
›
datatype facetype = Final | Nonfinal
datatype face = Face "(vertex list)" facetype
consts final :: "'a ⇒ bool"
consts type :: "'a ⇒ facetype"
overloading
final_face ≡ "final :: face ⇒ bool"
type_face ≡ "type :: face ⇒ facetype"
vertices_face ≡ "vertices :: face ⇒ vertex list"
cong_face ≡ "pr_isomorphic :: face ⇒ face ⇒ bool"
begin
primrec final_face where
"final (Face vs f) = (case f of Final ⇒ True | Nonfinal ⇒ False)"
primrec type_face where
"type (Face vs f) = f"
primrec vertices_face where
"vertices (Face vs f) = vs"
definition cong_face :: "face ⇒ face ⇒ bool"
where "(f⇩1 :: face) ≅ f⇩2 ≡ vertices f⇩1 ≅ vertices f⇩2"
end
text ‹The following operation makes a face final.›
definition setFinal :: "face ⇒ face" where
"setFinal f ≡ Face (vertices f) Final"
text ‹The function ‹nextVertex› (written ‹f ∙ v›) is based on
‹nextElem›, that returns the successor of an element in a list.›
primrec nextElem :: "'a list ⇒ 'a ⇒ 'a ⇒ 'a" where
"nextElem [] b x = b"
|"nextElem (a#as) b x =
(if x=a then (case as of [] ⇒ b | (a'#as') ⇒ a') else nextElem as b x)"
definition nextVertex :: "face ⇒ vertex ⇒ vertex" (‹_ ∙› [999]) where
"f ∙ ≡ let vs = vertices f in nextElem vs (hd vs)"
text ‹‹nextVertices› is $n$-fold application of
‹nextvertex›.›
definition nextVertices :: "face ⇒ nat ⇒ vertex ⇒ vertex" (‹_⇗_⇖ ∙ _› [100, 0, 100]) where
"f⇗n⇖ ∙ v ≡ (f ∙ ^^ n) v"
lemma nextV2: "f⇗2⇖∙v = f∙ (f∙ v)"
by (simp add: nextVertices_def eval_nat_numeral)
overloading edges_face ≡ "edges :: face ⇒ (vertex × vertex) set"
begin
definition "ℰ f ≡ {(a, f ∙ a)|a. a ∈ 𝒱 f}"
end
consts op :: "'a ⇒ 'a" (‹_⇗op⇖› [1000] 999)
overloading op_vertices ≡ "Graph.op :: vertex list ⇒ vertex list"
begin
definition "(vs::vertex list)⇗op⇖ ≡ rev vs"
end
overloading op_graph ≡ "Graph.op :: face ⇒ face"
begin
primrec op_graph where "(Face vs f)⇗op⇖ = Face (rev vs) f"
end
lemma [simp]: "vertices ((f::face)⇗op⇖) = (vertices f)⇗op⇖"
by (induct f) (simp add: op_vertices_def)
lemma [simp]: "xs ≠ [] ⟹ hd (rev xs)= last xs"
by(induct xs) simp_all
definition prevVertex :: "face ⇒ vertex ⇒ vertex" (‹_⇗-1⇖ ∙› [100]) where
"f⇗-1⇖ ∙ v ≡ (let vs = vertices f in nextElem (rev vs) (last vs) v)"
abbreviation
triangle :: "face ⇒ bool" where
"triangle f == |vertices f| = 3"
subsection ‹Graphs›