src/HOL/SizeChange/Graphs.thy
author haftmann
Thu, 29 Nov 2007 17:08:26 +0100
changeset 25502 9200b36280c0
parent 25314 5eaf3e8b50a4
child 25764 878c37886eed
permissions -rw-r--r--
instance command as rudimentary class target
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25314
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
     1
(*  Title:      HOL/Library/Graphs.thy
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
     2
    ID:         $Id$
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
     3
    Author:     Alexander Krauss, TU Muenchen
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
     4
*)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
     5
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
     6
header {* General Graphs as Sets *}
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
     7
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
     8
theory Graphs
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
     9
imports Main Misc_Tools Kleene_Algebras
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    10
begin
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    11
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    12
subsection {* Basic types, Size Change Graphs *}
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    13
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    14
datatype ('a, 'b) graph = 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    15
  Graph "('a \<times> 'b \<times> 'a) set"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    16
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    17
fun dest_graph :: "('a, 'b) graph \<Rightarrow> ('a \<times> 'b \<times> 'a) set"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    18
  where "dest_graph (Graph G) = G"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    19
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    20
lemma graph_dest_graph[simp]:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    21
  "Graph (dest_graph G) = G"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    22
  by (cases G) simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    23
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    24
lemma split_graph_all:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    25
  "(\<And>gr. PROP P gr) \<equiv> (\<And>set. PROP P (Graph set))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    26
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    27
  fix set
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    28
  assume "\<And>gr. PROP P gr"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    29
  then show "PROP P (Graph set)" .
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    30
next
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    31
  fix gr
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    32
  assume "\<And>set. PROP P (Graph set)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    33
  then have "PROP P (Graph (dest_graph gr))" .
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    34
  then show "PROP P gr" by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    35
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    36
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    37
definition 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    38
  has_edge :: "('n,'e) graph \<Rightarrow> 'n \<Rightarrow> 'e \<Rightarrow> 'n \<Rightarrow> bool"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    39
("_ \<turnstile> _ \<leadsto>\<^bsup>_\<^esup> _")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    40
where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    41
  "has_edge G n e n' = ((n, e, n') \<in> dest_graph G)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    42
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    43
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    44
subsection {* Graph composition *}
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    45
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    46
fun grcomp :: "('n, 'e::times) graph \<Rightarrow> ('n, 'e) graph  \<Rightarrow> ('n, 'e) graph"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    47
where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    48
  "grcomp (Graph G) (Graph H) = 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    49
  Graph {(p,b,q) | p b q. 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    50
  (\<exists>k e e'. (p,e,k)\<in>G \<and> (k,e',q)\<in>H \<and> b = e * e')}"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    51
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    52
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    53
declare grcomp.simps[code del]
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    54
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    55
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    56
lemma graph_ext:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    57
  assumes "\<And>n e n'. has_edge G n e n' = has_edge H n e n'"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    58
  shows "G = H"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    59
  using assms
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    60
  by (cases G, cases H) (auto simp:split_paired_all has_edge_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    61
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    62
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    63
instance graph :: (type, type) "{comm_monoid_add}"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    64
  graph_zero_def: "0 == Graph {}" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    65
  graph_plus_def: "G + H == Graph (dest_graph G \<union> dest_graph H)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    66
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    67
  fix x y z :: "('a,'b) graph"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    68
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    69
  show "x + y + z = x + (y + z)" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    70
   and "x + y = y + x" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    71
   and "0 + x = x"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    72
  unfolding graph_plus_def graph_zero_def 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    73
  by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    74
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    75
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    76
lemmas [code func del] = graph_plus_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    77
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    78
instance graph :: (type, type) "{distrib_lattice, complete_lattice}"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    79
  graph_leq_def: "G \<le> H \<equiv> dest_graph G \<subseteq> dest_graph H"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    80
  graph_less_def: "G < H \<equiv> dest_graph G \<subset> dest_graph H"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    81
  "inf G H \<equiv> Graph (dest_graph G \<inter> dest_graph H)"
25502
9200b36280c0 instance command as rudimentary class target
haftmann
parents: 25314
diff changeset
    82
  "sup (G \<Colon> ('a, 'b) graph)  H \<equiv> G + H"
25314
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    83
  Inf_graph_def: "Inf \<equiv> \<lambda>Gs. Graph (\<Inter>(dest_graph ` Gs))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    84
  Sup_graph_def: "Sup \<equiv> \<lambda>Gs. Graph (\<Union>(dest_graph ` Gs))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    85
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    86
  fix x y z :: "('a,'b) graph"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    87
  fix A :: "('a, 'b) graph set"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    88
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    89
  show "(x < y) = (x \<le> y \<and> x \<noteq> y)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    90
    unfolding graph_leq_def graph_less_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    91
    by (cases x, cases y) auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    92
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    93
  show "x \<le> x" unfolding graph_leq_def ..
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    94
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    95
  { assume "x \<le> y" "y \<le> z" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    96
    with order_trans show "x \<le> z"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    97
      unfolding graph_leq_def . }
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    98
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
    99
  { assume "x \<le> y" "y \<le> x" thus "x = y" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   100
      unfolding graph_leq_def 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   101
      by (cases x, cases y) simp }
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   102
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   103
  show "inf x y \<le> x" "inf x y \<le> y"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   104
    unfolding inf_graph_def graph_leq_def 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   105
    by auto    
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   106
  
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   107
  { assume "x \<le> y" "x \<le> z" thus "x \<le> inf y z"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   108
      unfolding inf_graph_def graph_leq_def 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   109
      by auto }
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   110
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   111
  show "x \<le> sup x y" "y \<le> sup x y"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   112
    unfolding sup_graph_def graph_leq_def graph_plus_def by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   113
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   114
  { assume "y \<le> x" "z \<le> x" thus "sup y z \<le> x"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   115
      unfolding sup_graph_def graph_leq_def graph_plus_def by auto }
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   116
  
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   117
  show "sup x (inf y z) = inf (sup x y) (sup x z)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   118
    unfolding inf_graph_def sup_graph_def graph_leq_def graph_plus_def by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   119
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   120
  { assume "x \<in> A" thus "Inf A \<le> x" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   121
      unfolding Inf_graph_def graph_leq_def by auto }
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   122
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   123
  { assume "\<And>x. x \<in> A \<Longrightarrow> z \<le> x" thus "z \<le> Inf A"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   124
    unfolding Inf_graph_def graph_leq_def by auto }
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   125
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   126
  { assume "x \<in> A" thus "x \<le> Sup A" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   127
      unfolding Sup_graph_def graph_leq_def by auto }
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   128
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   129
  { assume "\<And>x. x \<in> A \<Longrightarrow> x \<le> z" thus "Sup A \<le> z"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   130
    unfolding Sup_graph_def graph_leq_def by auto }
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   131
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   132
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   133
lemmas [code func del] = graph_leq_def graph_less_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   134
  inf_graph_def sup_graph_def Inf_graph_def Sup_graph_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   135
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   136
lemma in_grplus:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   137
  "has_edge (G + H) p b q = (has_edge G p b q \<or> has_edge H p b q)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   138
  by (cases G, cases H, auto simp:has_edge_def graph_plus_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   139
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   140
lemma in_grzero:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   141
  "has_edge 0 p b q = False"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   142
  by (simp add:graph_zero_def has_edge_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   143
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   144
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   145
subsubsection {* Multiplicative Structure *}
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   146
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   147
instance graph :: (type, times) mult_zero
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   148
  graph_mult_def: "G * H == grcomp G H" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   149
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   150
  fix a :: "('a, 'b) graph"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   151
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   152
  show "0 * a = 0" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   153
    unfolding graph_mult_def graph_zero_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   154
    by (cases a) (simp add:grcomp.simps)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   155
  show "a * 0 = 0" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   156
    unfolding graph_mult_def graph_zero_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   157
    by (cases a) (simp add:grcomp.simps)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   158
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   159
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   160
lemmas [code func del] = graph_mult_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   161
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   162
instance graph :: (type, one) one 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   163
  graph_one_def: "1 == Graph { (x, 1, x) |x. True}" ..
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   164
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   165
lemma in_grcomp:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   166
  "has_edge (G * H) p b q
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   167
  = (\<exists>k e e'. has_edge G p e k \<and> has_edge H k e' q \<and> b = e * e')"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   168
  by (cases G, cases H) (auto simp:graph_mult_def has_edge_def image_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   169
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   170
lemma in_grunit:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   171
  "has_edge 1 p b q = (p = q \<and> b = 1)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   172
  by (auto simp:graph_one_def has_edge_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   173
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   174
instance graph :: (type, semigroup_mult) semigroup_mult
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   175
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   176
  fix G1 G2 G3 :: "('a,'b) graph"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   177
  
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   178
  show "G1 * G2 * G3 = G1 * (G2 * G3)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   179
  proof (rule graph_ext, rule trans)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   180
    fix p J q
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   181
    show "has_edge ((G1 * G2) * G3) p J q =
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   182
      (\<exists>G i H j I.
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   183
      has_edge G1 p G i
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   184
      \<and> has_edge G2 i H j
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   185
      \<and> has_edge G3 j I q
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   186
      \<and> J = (G * H) * I)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   187
      by (simp only:in_grcomp) blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   188
    show "\<dots> = has_edge (G1 * (G2 * G3)) p J q"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   189
      by (simp only:in_grcomp mult_assoc) blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   190
  qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   191
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   192
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   193
fun grpow :: "nat \<Rightarrow> ('a::type, 'b::monoid_mult) graph \<Rightarrow> ('a, 'b) graph"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   194
where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   195
  "grpow 0 A = 1"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   196
| "grpow (Suc n) A = A * (grpow n A)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   197
25502
9200b36280c0 instance command as rudimentary class target
haftmann
parents: 25314
diff changeset
   198
instance graph :: (type, monoid_mult)
25314
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   199
  "{semiring_1,idem_add,recpower,star}"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   200
  graph_pow_def: "A ^ n == grpow n A"
25502
9200b36280c0 instance command as rudimentary class target
haftmann
parents: 25314
diff changeset
   201
  graph_star_def: "star (G \<Colon> ('a, 'b) graph) == (SUP n. G ^ n)" 
25314
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   202
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   203
  fix a b c :: "('a, 'b) graph"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   204
  
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   205
  show "1 * a = a" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   206
    by (rule graph_ext) (auto simp:in_grcomp in_grunit)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   207
  show "a * 1 = a"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   208
    by (rule graph_ext) (auto simp:in_grcomp in_grunit)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   209
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   210
  show "(a + b) * c = a * c + b * c"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   211
    by (rule graph_ext, simp add:in_grcomp in_grplus) blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   212
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   213
  show "a * (b + c) = a * b + a * c"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   214
    by (rule graph_ext, simp add:in_grcomp in_grplus) blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   215
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   216
  show "(0::('a,'b) graph) \<noteq> 1" unfolding graph_zero_def graph_one_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   217
    by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   218
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   219
  show "a + a = a" unfolding graph_plus_def by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   220
  
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   221
  show "a ^ 0 = 1" "\<And>n. a ^ (Suc n) = a * a ^ n"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   222
    unfolding graph_pow_def by simp_all
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   223
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   224
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   225
lemma graph_leqI:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   226
  assumes "\<And>n e n'. has_edge G n e n' \<Longrightarrow> has_edge H n e n'"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   227
  shows "G \<le> H"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   228
  using assms
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   229
  unfolding graph_leq_def has_edge_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   230
  by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   231
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   232
lemma in_graph_plusE:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   233
  assumes "has_edge (G + H) n e n'"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   234
  assumes "has_edge G n e n' \<Longrightarrow> P"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   235
  assumes "has_edge H n e n' \<Longrightarrow> P"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   236
  shows P
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   237
  using assms
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   238
  by (auto simp: in_grplus)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   239
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   240
lemma in_graph_compE:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   241
  assumes GH: "has_edge (G * H) n e n'"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   242
  obtains e1 k e2 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   243
  where "has_edge G n e1 k" "has_edge H k e2 n'" "e = e1 * e2"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   244
  using GH
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   245
  by (auto simp: in_grcomp)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   246
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   247
lemma 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   248
  assumes "x \<in> S k"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   249
  shows "x \<in> (\<Union>k. S k)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   250
  using assms by blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   251
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   252
lemma graph_union_least:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   253
  assumes "\<And>n. Graph (G n) \<le> C"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   254
  shows "Graph (\<Union>n. G n) \<le> C"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   255
  using assms unfolding graph_leq_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   256
  by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   257
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   258
lemma Sup_graph_eq:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   259
  "(SUP n. Graph (G n)) = Graph (\<Union>n. G n)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   260
proof (rule order_antisym)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   261
  show "(SUP n. Graph (G n)) \<le> Graph (\<Union>n. G n)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   262
    by  (rule SUP_leI) (auto simp add: graph_leq_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   263
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   264
  show "Graph (\<Union>n. G n) \<le> (SUP n. Graph (G n))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   265
  by (rule graph_union_least, rule le_SUPI', rule) 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   266
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   267
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   268
lemma has_edge_leq: "has_edge G p b q = (Graph {(p,b,q)} \<le> G)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   269
  unfolding has_edge_def graph_leq_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   270
  by (cases G) simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   271
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   272
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   273
lemma Sup_graph_eq2:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   274
  "(SUP n. G n) = Graph (\<Union>n. dest_graph (G n))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   275
  using Sup_graph_eq[of "\<lambda>n. dest_graph (G n)", simplified]
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   276
  by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   277
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   278
lemma in_SUP:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   279
  "has_edge (SUP x. Gs x) p b q = (\<exists>x. has_edge (Gs x) p b q)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   280
  unfolding Sup_graph_eq2 has_edge_leq graph_leq_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   281
  by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   282
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   283
instance graph :: (type, monoid_mult) kleene_by_complete_lattice
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   284
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   285
  fix a b c :: "('a, 'b) graph"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   286
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   287
  show "a \<le> b \<longleftrightarrow> a + b = b" unfolding graph_leq_def graph_plus_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   288
    by (cases a, cases b) auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   289
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   290
  from order_less_le show "a < b \<longleftrightarrow> a \<le> b \<and> a \<noteq> b" .
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   291
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   292
  show "a * star b * c = (SUP n. a * b ^ n * c)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   293
    unfolding graph_star_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   294
    by (rule graph_ext) (force simp:in_SUP in_grcomp)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   295
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   296
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   297
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   298
lemma in_star: 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   299
  "has_edge (star G) a x b = (\<exists>n. has_edge (G ^ n) a x b)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   300
  by (auto simp:graph_star_def in_SUP)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   301
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   302
lemma tcl_is_SUP:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   303
  "tcl (G::('a::type, 'b::monoid_mult) graph) =
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   304
  (SUP n. G ^ (Suc n))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   305
  unfolding tcl_def 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   306
  using star_cont[of 1 G G]
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   307
  by (simp add:power_Suc power_commutes)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   308
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   309
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   310
lemma in_tcl: 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   311
  "has_edge (tcl G) a x b = (\<exists>n>0. has_edge (G ^ n) a x b)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   312
  apply (auto simp: tcl_is_SUP in_SUP)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   313
  apply (rule_tac x = "n - 1" in exI, auto)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   314
  done
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   315
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   316
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   317
subsection {* Infinite Paths *}
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   318
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   319
types ('n, 'e) ipath = "('n \<times> 'e) sequence"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   320
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   321
definition has_ipath :: "('n, 'e) graph \<Rightarrow> ('n, 'e) ipath \<Rightarrow> bool"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   322
where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   323
  "has_ipath G p = 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   324
  (\<forall>i. has_edge G (fst (p i)) (snd (p i)) (fst (p (Suc i))))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   325
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   326
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   327
subsection {* Finite Paths *}
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   328
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   329
types ('n, 'e) fpath = "('n \<times> ('e \<times> 'n) list)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   330
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   331
inductive  has_fpath :: "('n, 'e) graph \<Rightarrow> ('n, 'e) fpath \<Rightarrow> bool" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   332
  for G :: "('n, 'e) graph"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   333
where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   334
  has_fpath_empty: "has_fpath G (n, [])"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   335
| has_fpath_join: "\<lbrakk>G \<turnstile> n \<leadsto>\<^bsup>e\<^esup> n'; has_fpath G (n', es)\<rbrakk> \<Longrightarrow> has_fpath G (n, (e, n')#es)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   336
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   337
definition 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   338
  "end_node p = 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   339
  (if snd p = [] then fst p else snd (snd p ! (length (snd p) - 1)))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   340
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   341
definition path_nth :: "('n, 'e) fpath \<Rightarrow> nat \<Rightarrow> ('n \<times> 'e \<times> 'n)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   342
where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   343
  "path_nth p k = (if k = 0 then fst p else snd (snd p ! (k - 1)), snd p ! k)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   344
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   345
lemma endnode_nth:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   346
  assumes "length (snd p) = Suc k"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   347
  shows "end_node p = snd (snd (path_nth p k))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   348
  using assms unfolding end_node_def path_nth_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   349
  by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   350
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   351
lemma path_nth_graph:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   352
  assumes "k < length (snd p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   353
  assumes "has_fpath G p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   354
  shows "(\<lambda>(n,e,n'). has_edge G n e n') (path_nth p k)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   355
using assms
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   356
proof (induct k arbitrary: p)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   357
  case 0 thus ?case 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   358
    unfolding path_nth_def by (auto elim:has_fpath.cases)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   359
next
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   360
  case (Suc k p)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   361
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   362
  from `has_fpath G p` show ?case 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   363
  proof (rule has_fpath.cases)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   364
    case goal1 with Suc show ?case by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   365
  next
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   366
    fix n e n' es
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   367
    assume st: "p = (n, (e, n') # es)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   368
       "G \<turnstile> n \<leadsto>\<^bsup>e\<^esup> n'"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   369
       "has_fpath G (n', es)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   370
    with Suc
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   371
    have "(\<lambda>(n, b, a). G \<turnstile> n \<leadsto>\<^bsup>b\<^esup> a) (path_nth (n', es) k)" by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   372
    with st show ?thesis by (cases k, auto simp:path_nth_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   373
  qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   374
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   375
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   376
lemma path_nth_connected:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   377
  assumes "Suc k < length (snd p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   378
  shows "fst (path_nth p (Suc k)) = snd (snd (path_nth p k))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   379
  using assms
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   380
  unfolding path_nth_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   381
  by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   382
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   383
definition path_loop :: "('n, 'e) fpath \<Rightarrow> ('n, 'e) ipath" ("omega")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   384
where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   385
  "omega p \<equiv> (\<lambda>i. (\<lambda>(n,e,n'). (n,e)) (path_nth p (i mod (length (snd p)))))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   386
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   387
lemma fst_p0: "fst (path_nth p 0) = fst p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   388
  unfolding path_nth_def by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   389
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   390
lemma path_loop_connect:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   391
  assumes "fst p = end_node p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   392
  and "0 < length (snd p)" (is "0 < ?l")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   393
  shows "fst (path_nth p (Suc i mod (length (snd p))))
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   394
  = snd (snd (path_nth p (i mod length (snd p))))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   395
  (is "\<dots> = snd (snd (path_nth p ?k))")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   396
proof -
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   397
  from `0 < ?l` have "i mod ?l < ?l" (is "?k < ?l")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   398
    by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   399
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   400
  show ?thesis 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   401
  proof (cases "Suc ?k < ?l")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   402
    case True
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   403
    hence "Suc ?k \<noteq> ?l" by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   404
    with path_nth_connected[OF True]
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   405
    show ?thesis
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   406
      by (simp add:mod_Suc)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   407
  next
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   408
    case False 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   409
    with `?k < ?l` have wrap: "Suc ?k = ?l" by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   410
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   411
    hence "fst (path_nth p (Suc i mod ?l)) = fst (path_nth p 0)" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   412
      by (simp add: mod_Suc)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   413
    also from fst_p0 have "\<dots> = fst p" .
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   414
    also have "\<dots> = end_node p" by fact
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   415
    also have "\<dots> = snd (snd (path_nth p ?k))" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   416
      by (auto simp: endnode_nth wrap)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   417
    finally show ?thesis .
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   418
  qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   419
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   420
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   421
lemma path_loop_graph:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   422
  assumes "has_fpath G p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   423
  and loop: "fst p = end_node p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   424
  and nonempty: "0 < length (snd p)" (is "0 < ?l")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   425
  shows "has_ipath G (omega p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   426
proof -
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   427
  {
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   428
    fix i 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   429
    from `0 < ?l` have "i mod ?l < ?l" (is "?k < ?l")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   430
      by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   431
    from this and `has_fpath G p`
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   432
    have pk_G: "(\<lambda>(n,e,n'). has_edge G n e n') (path_nth p ?k)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   433
      by (rule path_nth_graph)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   434
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   435
    from path_loop_connect[OF loop nonempty] pk_G
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   436
    have "has_edge G (fst (omega p i)) (snd (omega p i)) (fst (omega p (Suc i)))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   437
      unfolding path_loop_def has_edge_def split_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   438
      by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   439
  }
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   440
  then show ?thesis by (auto simp:has_ipath_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   441
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   442
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   443
definition prod :: "('n, 'e::monoid_mult) fpath \<Rightarrow> 'e"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   444
where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   445
  "prod p = foldr (op *) (map fst (snd p)) 1"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   446
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   447
lemma prod_simps[simp]:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   448
  "prod (n, []) = 1"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   449
  "prod (n, (e,n')#es) = e * (prod (n',es))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   450
unfolding prod_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   451
by simp_all
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   452
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   453
lemma power_induces_path:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   454
  assumes a: "has_edge (A ^ k) n G m"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   455
  obtains p 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   456
    where "has_fpath A p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   457
      and "n = fst p" "m = end_node p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   458
      and "G = prod p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   459
      and "k = length (snd p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   460
  using a
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   461
proof (induct k arbitrary:m n G thesis)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   462
  case (0 m n G)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   463
  let ?p = "(n, [])"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   464
  from 0 have "has_fpath A ?p" "m = end_node ?p" "G = prod ?p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   465
    by (auto simp:in_grunit end_node_def intro:has_fpath.intros)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   466
  thus ?case using 0 by (auto simp:end_node_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   467
next
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   468
  case (Suc k m n G)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   469
  hence "has_edge (A * A ^ k) n G m" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   470
    by (simp add:power_Suc power_commutes)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   471
  then obtain G' H j where 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   472
    a_A: "has_edge A n G' j"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   473
    and H_pow: "has_edge (A ^ k) j H m"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   474
    and [simp]: "G = G' * H"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   475
    by (auto simp:in_grcomp) 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   476
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   477
  from H_pow and Suc
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   478
  obtain p
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   479
    where p_path: "has_fpath A p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   480
    and [simp]: "j = fst p" "m = end_node p" "H = prod p" 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   481
    "k = length (snd p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   482
    by blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   483
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   484
  let ?p' = "(n, (G', j)#snd p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   485
  from a_A and p_path
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   486
  have "has_fpath A ?p'" "m = end_node ?p'" "G = prod ?p'"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   487
    by (auto simp:end_node_def nth.simps intro:has_fpath.intros split:nat.split)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   488
  thus ?case using Suc by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   489
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   490
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   491
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   492
subsection {* Sub-Paths *}
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   493
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   494
definition sub_path :: "('n, 'e) ipath \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> ('n, 'e) fpath"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   495
("(_\<langle>_,_\<rangle>)")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   496
where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   497
  "p\<langle>i,j\<rangle> =
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   498
  (fst (p i), map (\<lambda>k. (snd (p k), fst (p (Suc k)))) [i ..< j])"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   499
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   500
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   501
lemma sub_path_is_path: 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   502
  assumes ipath: "has_ipath G p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   503
  assumes l: "i \<le> j"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   504
  shows "has_fpath G (p\<langle>i,j\<rangle>)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   505
  using l
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   506
proof (induct i rule:inc_induct)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   507
  case base show ?case by (auto simp:sub_path_def intro:has_fpath.intros)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   508
next
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   509
  case (step i)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   510
  with ipath upt_rec[of i j]
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   511
  show ?case
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   512
    by (auto simp:sub_path_def has_ipath_def intro:has_fpath.intros)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   513
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   514
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   515
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   516
lemma sub_path_start[simp]:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   517
  "fst (p\<langle>i,j\<rangle>) = fst (p i)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   518
  by (simp add:sub_path_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   519
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   520
lemma nth_upto[simp]: "k < j - i \<Longrightarrow> [i ..< j] ! k = i + k"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   521
  by (induct k) auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   522
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   523
lemma sub_path_end[simp]:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   524
  "i < j \<Longrightarrow> end_node (p\<langle>i,j\<rangle>) = fst (p j)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   525
  by (auto simp:sub_path_def end_node_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   526
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   527
lemma foldr_map: "foldr f (map g xs) = foldr (f o g) xs"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   528
  by (induct xs) auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   529
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   530
lemma upto_append[simp]:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   531
  assumes "i \<le> j" "j \<le> k"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   532
  shows "[ i ..< j ] @ [j ..< k] = [i ..< k]"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   533
  using assms and upt_add_eq_append[of i j "k - j"]
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   534
  by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   535
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   536
lemma foldr_monoid: "foldr (op *) xs 1 * foldr (op *) ys 1
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   537
  = foldr (op *) (xs @ ys) (1::'a::monoid_mult)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   538
  by (induct xs) (auto simp:mult_assoc)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   539
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   540
lemma sub_path_prod:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   541
  assumes "i < j"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   542
  assumes "j < k"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   543
  shows "prod (p\<langle>i,k\<rangle>) = prod (p\<langle>i,j\<rangle>) * prod (p\<langle>j,k\<rangle>)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   544
  using assms
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   545
  unfolding prod_def sub_path_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   546
  by (simp add:map_compose[symmetric] comp_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   547
   (simp only:foldr_monoid map_append[symmetric] upto_append)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   548
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   549
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   550
lemma path_acgpow_aux:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   551
  assumes "length es = l"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   552
  assumes "has_fpath G (n,es)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   553
  shows "has_edge (G ^ l) n (prod (n,es)) (end_node (n,es))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   554
using assms
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   555
proof (induct l arbitrary:n es)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   556
  case 0 thus ?case
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   557
    by (simp add:in_grunit end_node_def) 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   558
next
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   559
  case (Suc l n es)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   560
  hence "es \<noteq> []" by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   561
  let ?n' = "snd (hd es)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   562
  let ?es' = "tl es"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   563
  let ?e = "fst (hd es)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   564
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   565
  from Suc have len: "length ?es' = l" by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   566
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   567
  from Suc
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   568
  have [simp]: "end_node (n, es) = end_node (?n', ?es')"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   569
    by (cases es) (auto simp:end_node_def nth.simps split:nat.split)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   570
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   571
  from `has_fpath G (n,es)`
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   572
  have "has_fpath G (?n', ?es')"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   573
    by (rule has_fpath.cases) (auto intro:has_fpath.intros)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   574
  with Suc len
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   575
  have "has_edge (G ^ l) ?n' (prod (?n', ?es')) (end_node (?n', ?es'))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   576
    by auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   577
  moreover
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   578
  from `es \<noteq> []`
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   579
  have "prod (n, es) = ?e * (prod (?n', ?es'))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   580
    by (cases es) auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   581
  moreover
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   582
  from `has_fpath G (n,es)` have c:"has_edge G n ?e ?n'"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   583
    by (rule has_fpath.cases) (insert `es \<noteq> []`, auto)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   584
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   585
  ultimately
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   586
  show ?case
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   587
     unfolding power_Suc 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   588
     by (auto simp:in_grcomp)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   589
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   590
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   591
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   592
lemma path_acgpow:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   593
   "has_fpath G p
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   594
  \<Longrightarrow> has_edge (G ^ length (snd p)) (fst p) (prod p) (end_node p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   595
by (cases p)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   596
   (rule path_acgpow_aux[of "snd p" "length (snd p)" _ "fst p", simplified])
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   597
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   598
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   599
lemma star_paths:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   600
  "has_edge (star G) a x b =
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   601
   (\<exists>p. has_fpath G p \<and> a = fst p \<and> b = end_node p \<and> x = prod p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   602
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   603
  assume "has_edge (star G) a x b"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   604
  then obtain n where pow: "has_edge (G ^ n) a x b"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   605
    by (auto simp:in_star)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   606
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   607
  then obtain p where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   608
    "has_fpath G p" "a = fst p" "b = end_node p" "x = prod p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   609
    by (rule power_induces_path)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   610
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   611
  thus "\<exists>p. has_fpath G p \<and> a = fst p \<and> b = end_node p \<and> x = prod p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   612
    by blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   613
next
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   614
  assume "\<exists>p. has_fpath G p \<and> a = fst p \<and> b = end_node p \<and> x = prod p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   615
  then obtain p where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   616
    "has_fpath G p" "a = fst p" "b = end_node p" "x = prod p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   617
    by blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   618
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   619
  hence "has_edge (G ^ length (snd p)) a x b"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   620
    by (auto intro:path_acgpow)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   621
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   622
  thus "has_edge (star G) a x b"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   623
    by (auto simp:in_star)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   624
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   625
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   626
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   627
lemma plus_paths:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   628
  "has_edge (tcl G) a x b =
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   629
   (\<exists>p. has_fpath G p \<and> a = fst p \<and> b = end_node p \<and> x = prod p \<and> 0 < length (snd p))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   630
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   631
  assume "has_edge (tcl G) a x b"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   632
  
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   633
  then obtain n where pow: "has_edge (G ^ n) a x b" and "0 < n"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   634
    by (auto simp:in_tcl)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   635
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   636
  from pow obtain p where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   637
    "has_fpath G p" "a = fst p" "b = end_node p" "x = prod p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   638
    "n = length (snd p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   639
    by (rule power_induces_path)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   640
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   641
  with `0 < n`
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   642
  show "\<exists>p. has_fpath G p \<and> a = fst p \<and> b = end_node p \<and> x = prod p \<and> 0 < length (snd p) "
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   643
    by blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   644
next
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   645
  assume "\<exists>p. has_fpath G p \<and> a = fst p \<and> b = end_node p \<and> x = prod p
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   646
    \<and> 0 < length (snd p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   647
  then obtain p where
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   648
    "has_fpath G p" "a = fst p" "b = end_node p" "x = prod p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   649
    "0 < length (snd p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   650
    by blast
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   651
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   652
  hence "has_edge (G ^ length (snd p)) a x b"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   653
    by (auto intro:path_acgpow)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   654
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   655
  with `0 < length (snd p)`
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   656
  show "has_edge (tcl G) a x b"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   657
    by (auto simp:in_tcl)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   658
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   659
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   660
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   661
definition
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   662
  "contract s p = 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   663
  (\<lambda>i. (fst (p (s i)), prod (p\<langle>s i,s (Suc i)\<rangle>)))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   664
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   665
lemma ipath_contract:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   666
  assumes [simp]: "increasing s"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   667
  assumes ipath: "has_ipath G p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   668
  shows "has_ipath (tcl G) (contract s p)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   669
  unfolding has_ipath_def 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   670
proof
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   671
  fix i
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   672
  let ?p = "p\<langle>s i,s (Suc i)\<rangle>"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   673
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   674
  from increasing_strict 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   675
	have "fst (p (s (Suc i))) = end_node ?p" by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   676
  moreover
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   677
  from increasing_strict[of s i "Suc i"] have "snd ?p \<noteq> []"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   678
    by (simp add:sub_path_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   679
  moreover
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   680
  from ipath increasing_weak[of s] have "has_fpath G ?p"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   681
    by (rule sub_path_is_path) auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   682
  ultimately
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   683
  show "has_edge (tcl G) 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   684
    (fst (contract s p i)) (snd (contract s p i)) (fst (contract s p (Suc i)))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   685
    unfolding contract_def plus_paths
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   686
    by (intro exI) auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   687
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   688
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   689
lemma prod_unfold:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   690
  "i < j \<Longrightarrow> prod (p\<langle>i,j\<rangle>) 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   691
  = snd (p i) * prod (p\<langle>Suc i, j\<rangle>)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   692
  unfolding prod_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   693
  by (simp add:sub_path_def upt_rec[of "i" j])
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   694
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   695
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   696
lemma sub_path_loop:
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   697
  assumes "0 < k"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   698
  assumes k: "k = length (snd loop)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   699
  assumes loop: "fst loop = end_node loop"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   700
  shows "(omega loop)\<langle>k * i,k * Suc i\<rangle> = loop" (is "?\<omega> = loop")
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   701
proof (rule prod_eqI)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   702
  show "fst ?\<omega> = fst loop"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   703
    by (auto simp:path_loop_def path_nth_def split_def k)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   704
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   705
  show "snd ?\<omega> = snd loop"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   706
  proof (rule nth_equalityI[rule_format])
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   707
    show leneq: "length (snd ?\<omega>) = length (snd loop)"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   708
      unfolding sub_path_def k by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   709
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   710
    fix j assume "j < length (snd (?\<omega>))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   711
    with leneq and k have "j < k" by simp
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   712
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   713
    have a: "\<And>i. fst (path_nth loop (Suc i mod k))
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   714
      = snd (snd (path_nth loop (i mod k)))"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   715
      unfolding k
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   716
      apply (rule path_loop_connect[OF loop])
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   717
      using `0 < k` and k
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   718
      apply auto
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   719
      done
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   720
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   721
    from `j < k` 
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   722
    show "snd ?\<omega> ! j = snd loop ! j"
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   723
      unfolding sub_path_def
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   724
      apply (simp add:path_loop_def split_def add_ac)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   725
      apply (simp add:a k[symmetric])
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   726
      apply (simp add:path_nth_def)
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   727
      done
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   728
  qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   729
qed
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   730
5eaf3e8b50a4 moved stuff about size change termination to its own session
krauss
parents:
diff changeset
   731
end