1 (* Title: HOL/Library/Graphs.thy |
1 (* Title: HOL/Library/Graphs.thy |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: Alexander Krauss, TU Muenchen |
3 Author: Alexander Krauss, TU Muenchen |
4 *) |
4 *) |
5 |
5 |
|
6 header "" |
|
7 |
6 theory Graphs |
8 theory Graphs |
7 imports Main SCT_Misc Kleene_Algebras ExecutableSet |
9 imports Main SCT_Misc Kleene_Algebras ExecutableSet |
8 begin |
10 begin |
9 |
11 |
10 |
12 subsection {* Basic types, Size Change Graphs *} |
11 section {* Basic types, Size Change Graphs *} |
|
12 |
13 |
13 datatype ('a, 'b) graph = |
14 datatype ('a, 'b) graph = |
14 Graph "('a \<times> 'b \<times> 'a) set" |
15 Graph "('a \<times> 'b \<times> 'a) set" |
15 |
16 |
16 fun dest_graph :: "('a, 'b) graph \<Rightarrow> ('a \<times> 'b \<times> 'a) set" |
17 fun dest_graph :: "('a, 'b) graph \<Rightarrow> ('a \<times> 'b \<times> 'a) set" |
38 ("_ \<turnstile> _ \<leadsto>\<^bsup>_\<^esup> _") |
39 ("_ \<turnstile> _ \<leadsto>\<^bsup>_\<^esup> _") |
39 where |
40 where |
40 "has_edge G n e n' = ((n, e, n') \<in> dest_graph G)" |
41 "has_edge G n e n' = ((n, e, n') \<in> dest_graph G)" |
41 |
42 |
42 |
43 |
43 |
44 subsection {* Graph composition *} |
44 section {* Graph composition *} |
|
45 |
45 |
46 fun grcomp :: "('n, 'e::times) graph \<Rightarrow> ('n, 'e) graph \<Rightarrow> ('n, 'e) graph" |
46 fun grcomp :: "('n, 'e::times) graph \<Rightarrow> ('n, 'e) graph \<Rightarrow> ('n, 'e) graph" |
47 where |
47 where |
48 "grcomp (Graph G) (Graph H) = |
48 "grcomp (Graph G) (Graph H) = |
49 Graph {(p,b,q) | p b q. |
49 Graph {(p,b,q) | p b q. |
129 lemma in_grzero: |
129 lemma in_grzero: |
130 "has_edge 0 p b q = False" |
130 "has_edge 0 p b q = False" |
131 by (simp add:graph_zero_def has_edge_def) |
131 by (simp add:graph_zero_def has_edge_def) |
132 |
132 |
133 |
133 |
134 |
134 subsubsection {* Multiplicative Structure *} |
135 subsection {* Multiplicative Structure *} |
|
136 |
135 |
137 instance graph :: (type, times) mult_zero |
136 instance graph :: (type, times) mult_zero |
138 graph_mult_def: "G * H == grcomp G H" |
137 graph_mult_def: "G * H == grcomp G H" |
139 proof |
138 proof |
140 fix a :: "('a, 'b) graph" |
139 fix a :: "('a, 'b) graph" |
295 apply (auto simp: tcl_is_SUP in_SUP) |
294 apply (auto simp: tcl_is_SUP in_SUP) |
296 apply (rule_tac x = "n - 1" in exI, auto) |
295 apply (rule_tac x = "n - 1" in exI, auto) |
297 done |
296 done |
298 |
297 |
299 |
298 |
300 |
299 subsection {* Infinite Paths *} |
301 section {* Infinite Paths *} |
|
302 |
300 |
303 types ('n, 'e) ipath = "('n \<times> 'e) sequence" |
301 types ('n, 'e) ipath = "('n \<times> 'e) sequence" |
304 |
302 |
305 definition has_ipath :: "('n, 'e) graph \<Rightarrow> ('n, 'e) ipath \<Rightarrow> bool" |
303 definition has_ipath :: "('n, 'e) graph \<Rightarrow> ('n, 'e) ipath \<Rightarrow> bool" |
306 where |
304 where |
307 "has_ipath G p = |
305 "has_ipath G p = |
308 (\<forall>i. has_edge G (fst (p i)) (snd (p i)) (fst (p (Suc i))))" |
306 (\<forall>i. has_edge G (fst (p i)) (snd (p i)) (fst (p (Suc i))))" |
309 |
307 |
310 |
308 |
311 |
309 subsection {* Finite Paths *} |
312 section {* Finite Paths *} |
|
313 |
310 |
314 types ('n, 'e) fpath = "('n \<times> ('e \<times> 'n) list)" |
311 types ('n, 'e) fpath = "('n \<times> ('e \<times> 'n) list)" |
315 |
312 |
316 inductive2 has_fpath :: "('n, 'e) graph \<Rightarrow> ('n, 'e) fpath \<Rightarrow> bool" |
313 inductive2 has_fpath :: "('n, 'e) graph \<Rightarrow> ('n, 'e) fpath \<Rightarrow> bool" |
317 for G :: "('n, 'e) graph" |
314 for G :: "('n, 'e) graph" |
468 by (auto simp:end_node_def nth.simps intro:has_fpath.intros split:nat.split) |
465 by (auto simp:end_node_def nth.simps intro:has_fpath.intros split:nat.split) |
469 thus ?case using Suc by auto |
466 thus ?case using Suc by auto |
470 qed |
467 qed |
471 |
468 |
472 |
469 |
473 |
470 subsection {* Sub-Paths *} |
474 |
|
475 |
|
476 section {* Sub-Paths *} |
|
477 |
|
478 |
471 |
479 definition sub_path :: "('n, 'e) ipath \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> ('n, 'e) fpath" |
472 definition sub_path :: "('n, 'e) ipath \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> ('n, 'e) fpath" |
480 ("(_\<langle>_,_\<rangle>)") |
473 ("(_\<langle>_,_\<rangle>)") |
481 where |
474 where |
482 "p\<langle>i,j\<rangle> = |
475 "p\<langle>i,j\<rangle> = |