RTree.thy
author zhangx
Wed, 06 Jan 2016 20:46:14 +0800
changeset 63 b620a2a0806a
parent 62 031d2ae9c9b8
child 64 b4bcd1edbb6d
permissions -rw-r--r--
ExtGG.thy finished, but more comments are needed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     1
theory RTree
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
     2
imports "~~/src/HOL/Library/Transitive_Closure_Table" Max
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     3
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     4
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     5
section {* A theory of relational trees *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     6
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     7
inductive_cases path_nilE [elim!]: "rtrancl_path r x [] y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     8
inductive_cases path_consE [elim!]: "rtrancl_path r x (z#zs) y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     9
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    10
subsection {* Definitions *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    11
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    12
text {*
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
    13
  In this theory, we are going to give a notion of of `Relational Graph` and
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    14
  its derived notion `Relational Tree`. Given a binary relation @{text "r"},
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    15
  the `Relational Graph of @{text "r"}` is the graph, the edges of which
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    16
  are those in @{text "r"}. In this way, any binary relation can be viewed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    17
  as a `Relational Graph`. Note, this notion of graph includes infinite graphs. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    18
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    19
  A `Relation Graph` @{text "r"} is said to be a `Relational Tree` if it is both
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    20
  {\em single valued} and {\em acyclic}. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    21
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    22
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    23
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    24
  The following @{text "sgv"} specifies that relation @{text "r"} is {\em single valued}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    25
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    26
locale sgv = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    27
  fixes r
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    28
  assumes sgv: "single_valued r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    29
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    30
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    31
  The following @{text "rtree"} specifies that @{text "r"} is a 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    32
  {\em Relational Tree}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    33
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    34
locale rtree = sgv + 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    35
  assumes acl: "acyclic r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    36
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    37
text {* 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    38
  The following two auxiliary functions @{text "rel_of"} and @{text "pred_of"} 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    39
  transfer between the predicate and set representation of binary relations.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    40
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    41
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    42
definition "rel_of r = {(x, y) | x y. r x y}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    43
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    44
definition "pred_of r = (\<lambda> x y. (x, y) \<in> r)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    45
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    46
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    47
  To reason about {\em Relational Graph}, a notion of path is 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    48
  needed, which is given by the following @{text "rpath"} (short 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    49
  for `relational path`). 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    50
  The path @{text "xs"} in proposition @{text "rpath r x xs y"} is 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    51
  a path leading from @{text "x"} to @{text "y"}, which serves as a 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    52
  witness of the fact @{text "(x, y) \<in> r^*"}. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    53
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    54
  @{text "rpath"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    55
  is simply a wrapper of the @{text "rtrancl_path"} defined in the imported 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    56
  theory @{text "Transitive_Closure_Table"}, which defines 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    57
  a notion of path for the predicate form of binary relations. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    58
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    59
definition "rpath r x xs y = rtrancl_path (pred_of r) x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    60
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    61
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    62
  Given a path @{text "ps"}, @{text "edges_on ps"} is the 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    63
  set of edges along the path, which is defined as follows:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    64
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    65
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    66
definition "edges_on ps = {(a,b) | a b. \<exists> xs ys. ps = xs@[a,b]@ys}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    67
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    68
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    69
   The following @{text "indep"} defines a notion of independence. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    70
   Two nodes @{text "x"} and @{text "y"} are said to be independent
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    71
   (expressed as @{text "indep x y"}),  if neither one is reachable 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    72
   from the other in relational graph @{text "r"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    73
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    74
definition "indep r x y = (((x, y) \<notin> r^*) \<and> ((y, x) \<notin> r^*))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    75
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    76
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    77
  In relational tree @{text "r"}, the sub tree of node @{text "x"} is written
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    78
  @{text "subtree r x"}, which is defined to be the set of nodes (including itself) 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    79
  which can reach @{text "x"} by following some path in @{text "r"}:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    80
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    81
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    82
definition "subtree r x = {y . (y, x) \<in> r^*}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    83
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
    84
definition "ancestors r x = {y. (x, y) \<in> r^+}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
    85
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
    86
definition "root r x = (ancestors r x = {})"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
    87
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    88
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    89
  The following @{text "edge_in r x"} is the set of edges
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    90
  contained in the sub-tree of @{text "x"}, with @{text "r"} as the underlying graph.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    91
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    92
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    93
definition "edges_in r x = {(a, b) | a b. (a, b) \<in> r \<and> b \<in> subtree r x}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    94
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    95
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    96
  The following lemma @{text "edges_in_meaning"} shows the intuitive meaning 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    97
  of `an edge @{text "(a, b)"} is in the sub-tree of @{text "x"}`, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    98
  i.e., both @{text "a"} and @{text "b"} are in the sub-tree.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    99
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   100
lemma edges_in_meaning: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   101
  "edges_in r x = {(a, b) | a b. (a, b) \<in> r \<and> a \<in> subtree r x \<and> b \<in> subtree r x}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   102
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   103
  { fix a b
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   104
    assume h: "(a, b) \<in> r" "b \<in> subtree r x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   105
    moreover have "a \<in> subtree r x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   106
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   107
      from h(2)[unfolded subtree_def] have "(b, x) \<in> r^*" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   108
      with h(1) have "(a, x) \<in> r^*" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   109
      thus ?thesis by (auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   110
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   111
    ultimately have "((a, b) \<in> r \<and> a \<in> subtree r x \<and> b \<in> subtree r x)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   112
      by (auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   113
  } thus ?thesis by (auto simp:edges_in_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   114
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   115
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   116
text {*
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   117
  The following lemma shows the meaning of @{term "edges_in"} from the other side, 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   118
  which says: for the edge @{text "(a,b)"} to be outside of the sub-tree of @{text "x"}, 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   119
  it is sufficient to show that @{text "b"} is.
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   120
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   121
lemma edges_in_refutation:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   122
  assumes "b \<notin> subtree r x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   123
  shows "(a, b) \<notin> edges_in r x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   124
  using assms by (unfold edges_in_def subtree_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   125
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   126
definition "children r x = {y. (y, x) \<in> r}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   127
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   128
locale fbranch =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   129
  fixes r
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   130
  assumes fb: "\<forall> x \<in> Range r . finite (children r x)"
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   131
begin
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   132
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   133
lemma finite_children: "finite (children r x)"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   134
proof(cases "children r x = {}")
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   135
  case True
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   136
  thus ?thesis by auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   137
next
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   138
  case False
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   139
  then obtain y where "(y, x) \<in> r" by (auto simp:children_def)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   140
  hence "x \<in> Range r" by auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   141
  from fb[rule_format, OF this]
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   142
  show ?thesis .
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   143
qed
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   144
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 60
diff changeset
   145
end
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   146
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   147
locale fsubtree = fbranch + 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   148
   assumes wf: "wf r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   149
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   150
(* ccc *)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   151
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   152
subsection {* Auxiliary lemmas *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   153
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   154
lemma index_minimize:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   155
  assumes "P (i::nat)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   156
  obtains j where "P j" and "\<forall> k < j. \<not> P k" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   157
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   158
  have "\<exists> j. P j \<and> (\<forall> k < j. \<not> P k)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   159
  using assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   160
  proof(induct i rule:less_induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   161
    case (less t)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   162
    show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   163
    proof(cases "\<forall> j < t. \<not> P j")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   164
      case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   165
      with less (2) show ?thesis by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   166
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   167
      case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   168
      then obtain j where "j < t" "P j" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   169
      from less(1)[OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   170
      show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   171
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   172
  qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   173
  with that show ?thesis by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   174
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   175
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   176
subsection {* Properties of Relational Graphs and Relational Trees *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   177
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   178
subsubsection {* Properties of @{text "rel_of"} and @{text "pred_of"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   179
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   180
text {* The following lemmas establish bijectivity of the two functions *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   181
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   182
lemma pred_rel_eq: "pred_of (rel_of r) = r" by (auto simp:rel_of_def pred_of_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   183
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   184
lemma rel_pred_eq: "rel_of (pred_of r) = r" by (auto simp:rel_of_def pred_of_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   185
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   186
lemma rel_of_star: "rel_of (r^**) = (rel_of r)^*"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   187
  by (unfold rel_of_def rtranclp_rtrancl_eq, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   188
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   189
lemma pred_of_star: "pred_of (r^*) = (pred_of r)^**"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   190
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   191
  { fix x y
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   192
    have "pred_of (r^*) x y = (pred_of r)^** x y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   193
    by (unfold pred_of_def rtranclp_rtrancl_eq, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   194
  } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   195
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   196
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   197
lemma star_2_pstar: "(x, y) \<in> r^* = (pred_of (r^*)) x y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   198
  by (simp add: pred_of_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   199
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   200
subsubsection {* Properties of @{text "rpath"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   201
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   202
text {* Induction rule for @{text "rpath"}: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   203
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   204
lemma rpath_induct [consumes 1, case_names rbase rstep, induct pred: rpath]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   205
  assumes "rpath r x1 x2 x3"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   206
    and "\<And>x. P x [] x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   207
    and "\<And>x y ys z. (x, y) \<in> r \<Longrightarrow> rpath r y ys z \<Longrightarrow> P y ys z \<Longrightarrow> P x (y # ys) z"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   208
  shows "P x1 x2 x3"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   209
  using assms[unfolded rpath_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   210
  by (induct, auto simp:pred_of_def rpath_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   211
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   212
lemma rpathE: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   213
  assumes "rpath r x xs y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   214
  obtains (base) "y = x" "xs = []"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   215
     | (step) z zs where "(x, z) \<in> r" "rpath r z zs y" "xs = z#zs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   216
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   217
  by (induct, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   218
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   219
text {* Introduction rule for empty path *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   220
lemma rbaseI [intro!]: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   221
  assumes "x = y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   222
  shows "rpath r x [] y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   223
  by  (unfold rpath_def assms, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   224
         rule Transitive_Closure_Table.rtrancl_path.base)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   225
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   226
text {* Introduction rule for non-empty path *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   227
lemma rstepI [intro!]: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   228
  assumes "(x, y) \<in> r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   229
    and "rpath r y ys z"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   230
  shows "rpath r x (y#ys) z" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   231
proof(unfold rpath_def, rule Transitive_Closure_Table.rtrancl_path.step)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   232
  from assms(1) show "pred_of r x y" by (auto simp:pred_of_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   233
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   234
  from assms(2) show "rtrancl_path (pred_of r) y ys z"  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   235
  by (auto simp:pred_of_def rpath_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   236
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   237
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   238
text {* Introduction rule for @{text "@"}-path *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   239
lemma rpath_appendI [intro]: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   240
  assumes "rpath r x xs a" and "rpath r a ys y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   241
  shows "rpath r x (xs @ ys) y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   242
  using assms 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   243
  by (unfold rpath_def, auto intro:rtrancl_path_trans)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   244
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   245
text {* Elimination rule for empty path *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   246
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   247
lemma rpath_cases [cases pred:rpath]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   248
  assumes "rpath r a1 a2 a3"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   249
  obtains (rbase)  "a1 = a3" and "a2 = []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   250
    | (rstep)  y :: "'a" and ys :: "'a list"  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   251
         where "(a1, y) \<in> r" and "a2 = y # ys" and "rpath r y ys a3"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   252
  using assms [unfolded rpath_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   253
  by (cases, auto simp:rpath_def pred_of_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   254
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   255
lemma rpath_nilE [elim!, cases pred:rpath]: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   256
  assumes "rpath r x [] y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   257
  obtains "y = x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   258
  using assms[unfolded rpath_def] by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   259
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   260
-- {* This is a auxiliary lemmas used only in the proof of @{text "rpath_nnl_lastE"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   261
lemma rpath_nnl_last:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   262
  assumes "rtrancl_path r x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   263
  and "xs \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   264
  obtains xs' where "xs = xs'@[y]"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   265
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   266
  from append_butlast_last_id[OF `xs \<noteq> []`, symmetric] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   267
  obtain xs' y' where eq_xs: "xs = (xs' @ y' # [])" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   268
  with assms(1)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   269
  have "rtrancl_path r x ... y" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   270
  hence "y = y'" by (rule rtrancl_path_appendE, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   271
  with eq_xs have "xs = xs'@[y]" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   272
  from that[OF this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   273
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   274
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   275
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   276
  Elimination rule for non-empty paths constructed with @{text "#"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   277
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   278
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   279
lemma rpath_ConsE [elim!, cases pred:rpath]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   280
  assumes "rpath r x (y # ys) x2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   281
  obtains (rstep) "(x, y) \<in> r" and "rpath r y ys x2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   282
  using assms[unfolded rpath_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   283
  by (cases, auto simp:rpath_def pred_of_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   284
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   285
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   286
  Elimination rule for non-empty path, where the destination node 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   287
  @{text "y"} is shown to be at the end of the path.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   288
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   289
lemma rpath_nnl_lastE: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   290
  assumes "rpath r x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   291
  and "xs \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   292
  obtains xs' where "xs = xs'@[y]"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   293
  using assms[unfolded rpath_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   294
  by (rule rpath_nnl_last, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   295
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   296
text {* Other elimination rules of @{text "rpath"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   297
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   298
lemma rpath_appendE:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   299
  assumes "rpath r x (xs @ [a] @ ys) y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   300
  obtains "rpath r x (xs @ [a]) a" and "rpath r a ys y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   301
  using rtrancl_path_appendE[OF assms[unfolded rpath_def, simplified], folded rpath_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   302
  by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   303
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   304
lemma rpath_subE: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   305
  assumes "rpath r x (xs @ [a] @ ys @ [b] @ zs) y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   306
  obtains "rpath r x (xs @ [a]) a" and "rpath r a (ys @ [b]) b" and "rpath r b zs y" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   307
  using assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   308
 by (elim rpath_appendE, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   309
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   310
text {* Every path has a unique end point. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   311
lemma rpath_dest_eq:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   312
  assumes "rpath r x xs x1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   313
  and "rpath r x xs x2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   314
  shows "x1 = x2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   315
  using assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   316
  by (induct, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   317
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   318
subsubsection {* Properites of @{text "edges_on"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   319
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   320
lemma edges_on_unfold:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   321
  "edges_on (a # b # xs) = {(a, b)} \<union> edges_on (b # xs)" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   322
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   323
  { fix c d
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   324
    assume "(c, d) \<in> ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   325
    then obtain l1 l2 where h: "(a # b # xs) = l1 @ [c, d] @ l2" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   326
        by (auto simp:edges_on_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   327
    have "(c, d) \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   328
    proof(cases "l1")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   329
      case Nil
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   330
      with h have "(c, d) = (a, b)" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   331
      thus ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   332
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   333
      case (Cons e es)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   334
      from h[unfolded this] have "b#xs = es@[c, d]@l2" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   335
      thus ?thesis by (auto simp:edges_on_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   336
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   337
  } moreover
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   338
  { fix c d
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   339
    assume "(c, d) \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   340
    moreover have "(a, b) \<in> ?L" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   341
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   342
      have "(a # b # xs) = []@[a,b]@xs" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   343
      hence "\<exists> l1 l2. (a # b # xs) = l1@[a,b]@l2" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   344
      thus ?thesis by (unfold edges_on_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   345
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   346
    moreover {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   347
        assume "(c, d) \<in> edges_on (b#xs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   348
        then obtain l1 l2 where "b#xs = l1@[c, d]@l2" by (unfold edges_on_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   349
        hence "a#b#xs = (a#l1)@[c,d]@l2" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   350
        hence "\<exists> l1 l2. (a # b # xs) = l1@[c,d]@l2" by metis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   351
        hence "(c,d) \<in> ?L" by (unfold edges_on_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   352
    }
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   353
    ultimately have "(c, d) \<in> ?L" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   354
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   355
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   356
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   357
lemma edges_on_len:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   358
  assumes "(a,b) \<in> edges_on l"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   359
  shows "length l \<ge> 2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   360
  using assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   361
  by (unfold edges_on_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   362
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   363
text {* Elimination of @{text "edges_on"} for non-empty path *}
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   364
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   365
lemma edges_on_consE [elim, cases set:edges_on]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   366
  assumes "(a,b) \<in> edges_on (x#xs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   367
  obtains (head)  xs' where "x = a" and "xs = b#xs'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   368
      |  (tail)  "(a,b) \<in> edges_on xs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   369
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   370
  from assms obtain l1 l2 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   371
  where h: "(x#xs) = l1 @ [a,b] @ l2" by (unfold edges_on_def, blast)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   372
  have "(\<exists> xs'. x = a \<and> xs = b#xs') \<or> ((a,b) \<in> edges_on xs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   373
  proof(cases "l1")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   374
    case Nil with h 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   375
    show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   376
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   377
    case (Cons e el)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   378
    from h[unfolded this] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   379
    have "xs = el @ [a,b] @ l2" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   380
    thus ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   381
      by (unfold edges_on_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   382
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   383
  thus ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   384
  proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   385
    assume "(\<exists>xs'. x = a \<and> xs = b # xs')"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   386
    then obtain xs' where "x = a" "xs = b#xs'" by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   387
    from that(1)[OF this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   388
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   389
    assume "(a, b) \<in> edges_on xs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   390
    from that(2)[OF this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   391
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   392
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   393
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   394
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   395
  Every edges on the path is a graph edges:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   396
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   397
lemma rpath_edges_on:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   398
  assumes "rpath r x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   399
  shows "(edges_on (x#xs)) \<subseteq> r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   400
  using assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   401
proof(induct arbitrary:y)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   402
  case (rbase x)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   403
  thus ?case by (unfold edges_on_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   404
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   405
  case (rstep x y ys z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   406
  show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   407
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   408
    { fix a b
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   409
      assume "(a, b) \<in> edges_on (x # y # ys)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   410
      hence "(a, b) \<in> r" by (cases, insert rstep, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   411
    } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   412
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   413
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   414
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   415
text {* @{text "edges_on"} is mono with respect to @{text "#"}-operation: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   416
lemma edges_on_Cons_mono:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   417
   shows "edges_on xs \<subseteq> edges_on (x#xs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   418
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   419
  { fix a b
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   420
    assume "(a, b) \<in> edges_on xs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   421
    then obtain l1 l2 where "xs = l1 @ [a,b] @ l2" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   422
      by (auto simp:edges_on_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   423
    hence "x # xs = (x#l1) @ [a, b] @ l2" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   424
    hence "(a, b) \<in> edges_on (x#xs)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   425
      by (unfold edges_on_def, blast)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   426
  } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   427
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   428
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   429
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   430
  The following rule @{text "rpath_transfer"} is used to show 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   431
  that one path is intact as long as all the edges on it are intact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   432
  with the change of graph.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   433
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   434
  If @{text "x#xs"} is path in graph @{text "r1"} and 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   435
  every edges along the path is also in @{text "r2"}, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   436
  then @{text "x#xs"} is also a edge in graph @{text "r2"}:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   437
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   438
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   439
lemma rpath_transfer:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   440
  assumes "rpath r1 x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   441
  and "edges_on (x#xs) \<subseteq> r2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   442
  shows "rpath r2 x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   443
  using assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   444
proof(induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   445
  case (rstep x y ys z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   446
  show ?case 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   447
  proof(rule rstepI)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   448
    show "(x, y) \<in> r2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   449
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   450
      have "(x, y) \<in> edges_on  (x # y # ys)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   451
          by (unfold edges_on_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   452
     with rstep(4) show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   453
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   454
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   455
    show "rpath r2 y ys z" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   456
     using rstep edges_on_Cons_mono[of "y#ys" "x"] by (auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   457
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   458
qed (unfold rpath_def, auto intro!:Transitive_Closure_Table.rtrancl_path.base)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   459
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   460
lemma edges_on_rpathI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   461
  assumes "edges_on (a#xs@[b]) \<subseteq> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   462
  shows "rpath r a (xs@[b]) b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   463
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   464
proof(induct xs arbitrary: a b)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   465
  case Nil
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   466
  moreover have "(a, b) \<in> edges_on (a # [] @ [b])"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   467
      by (unfold edges_on_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   468
  ultimately have "(a, b) \<in> r" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   469
  thus ?case by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   470
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   471
  case (Cons x xs a b)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   472
  from this(2) have "edges_on (x # xs @ [b]) \<subseteq> r" by (simp add:edges_on_unfold)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   473
  from Cons(1)[OF this] have " rpath r x (xs @ [b]) b" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   474
  moreover from Cons(2) have "(a, x) \<in> r" by (auto simp:edges_on_unfold)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   475
  ultimately show ?case by (auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   476
qed
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   477
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   478
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   479
  The following lemma extracts the path from @{text "x"} to @{text "y"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   480
  from proposition @{text "(x, y) \<in> r^*"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   481
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   482
lemma star_rpath:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   483
  assumes "(x, y) \<in> r^*"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   484
  obtains xs where "rpath r x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   485
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   486
  have "\<exists> xs. rpath r x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   487
  proof(unfold rpath_def, rule iffD1[OF rtranclp_eq_rtrancl_path])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   488
    from assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   489
    show "(pred_of r)\<^sup>*\<^sup>* x y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   490
      apply (fold pred_of_star)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   491
      by (auto simp:pred_of_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   492
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   493
  from that and this show ?thesis by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   494
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   495
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   496
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   497
  The following lemma uses the path @{text "xs"} from @{text "x"} to @{text "y"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   498
  as a witness to show @{text "(x, y) \<in> r^*"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   499
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   500
lemma rpath_star: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   501
  assumes "rpath r x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   502
  shows "(x, y) \<in> r^*"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   503
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   504
  from iffD2[OF rtranclp_eq_rtrancl_path] and assms[unfolded rpath_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   505
  have "(pred_of r)\<^sup>*\<^sup>* x y" by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   506
  thus ?thesis by (simp add: pred_of_star star_2_pstar)
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 58
diff changeset
   507
qed  
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   508
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   509
lemma subtree_transfer:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   510
  assumes "a \<in> subtree r1 a'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   511
  and "r1 \<subseteq> r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   512
  shows "a \<in> subtree r2 a'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   513
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   514
  from assms(1)[unfolded subtree_def] 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   515
  have "(a, a') \<in> r1^*" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   516
  from star_rpath[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   517
  obtain xs where rp: "rpath r1 a xs a'" by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   518
  hence "rpath r2 a xs a'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   519
  proof(rule rpath_transfer)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   520
    from rpath_edges_on[OF rp] and assms(2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   521
    show "edges_on (a # xs) \<subseteq> r2" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   522
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   523
  from rpath_star[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   524
  show ?thesis by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   525
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   526
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   527
lemma subtree_rev_transfer:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   528
  assumes "a \<notin> subtree r2 a'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   529
  and "r1 \<subseteq> r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   530
  shows "a \<notin> subtree r1 a'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   531
  using assms and subtree_transfer by metis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   532
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   533
text {*
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   534
  The following lemmas establishes a relation from paths in @{text "r"}
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   535
  to @{text "r^+"} relation.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   536
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   537
lemma rpath_plus: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   538
  assumes "rpath r x xs y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   539
  and "xs \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   540
  shows "(x, y) \<in> r^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   541
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   542
  from assms(2) obtain e es where "xs = e#es" by (cases xs, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   543
  from assms(1)[unfolded this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   544
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   545
  proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   546
    case rstep
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   547
    show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   548
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   549
      from rpath_star[OF rstep(2)] have "(e, y) \<in> r\<^sup>*" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   550
      with rstep(1) show "(x, y) \<in> r^+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   551
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   552
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   553
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   554
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   555
lemma plus_rpath: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   556
  assumes "(x, y) \<in> r^+"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   557
  obtains xs where "rpath r x xs y" and "xs \<noteq> []"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   558
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   559
  from assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   560
  show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   561
  proof(cases rule:converse_tranclE[consumes 1])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   562
    case 1
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   563
    hence "rpath r x [y] y" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   564
    from that[OF this] show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   565
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   566
    case (2 z)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   567
    from 2(2) have "(z, y) \<in> r^*" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   568
    from star_rpath[OF this] obtain xs where "rpath r z xs y" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   569
    from rstepI[OF 2(1) this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   570
    have "rpath r x (z # xs) y" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   571
    from that[OF this] show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   572
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   573
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   574
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   575
subsubsection {* Properties of @{text "subtree"} and @{term "ancestors"}*}
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   576
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   577
lemma ancestors_subtreeI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   578
  assumes "b \<in> ancestors r a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   579
  shows "a \<in> subtree r b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   580
  using assms by (auto simp:subtree_def ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   581
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 58
diff changeset
   582
lemma ancestors_Field:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 58
diff changeset
   583
  assumes "b \<in> ancestors r a"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 58
diff changeset
   584
  obtains "a \<in> Domain r" "b \<in> Range r"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 58
diff changeset
   585
  using assms 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 58
diff changeset
   586
  apply (unfold ancestors_def, simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 58
diff changeset
   587
  by (metis Domain.DomainI Range.intros trancl_domain trancl_range)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 58
diff changeset
   588
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   589
lemma subtreeE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   590
  assumes "a \<in> subtree r b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   591
  obtains "a = b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   592
      | "a \<noteq> b" and "b \<in> ancestors r a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   593
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   594
  from assms have "(a, b) \<in> r^*" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   595
  from rtranclD[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   596
  have " a = b \<or> a \<noteq> b \<and> (a, b) \<in> r\<^sup>+" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   597
  with that[unfolded ancestors_def] show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   598
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   599
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   600
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   601
lemma subtree_Field:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   602
  "subtree r x \<subseteq> Field r \<union> {x}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   603
proof
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   604
  fix y
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   605
  assume "y \<in> subtree r x"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   606
  thus "y \<in> Field r \<union> {x}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   607
  proof(cases rule:subtreeE)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   608
    case 1
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   609
    thus ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   610
  next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   611
    case 2
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   612
    thus ?thesis apply (auto simp:ancestors_def)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   613
    using Field_def tranclD by fastforce 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   614
  qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   615
qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   616
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   617
lemma subtree_ancestorsI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   618
  assumes "a \<in> subtree r b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   619
  and "a \<noteq> b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   620
  shows "b \<in> ancestors r a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   621
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   622
  by (auto elim!:subtreeE)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   623
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   624
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   625
  @{text "subtree"} is mono with respect to the underlying graph.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   626
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   627
lemma subtree_mono:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   628
  assumes "r1 \<subseteq> r2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   629
  shows "subtree r1 x \<subseteq> subtree r2 x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   630
proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   631
  fix c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   632
  assume "c \<in> subtree r1 x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   633
  hence "(c, x) \<in> r1^*" by (auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   634
  from star_rpath[OF this] obtain xs 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   635
  where rp:"rpath r1 c xs x" by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   636
  hence "rpath r2 c xs x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   637
  proof(rule rpath_transfer)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   638
    from rpath_edges_on[OF rp] have "edges_on (c # xs) \<subseteq> r1" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   639
    with assms show "edges_on (c # xs) \<subseteq> r2" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   640
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   641
  thus "c \<in> subtree r2 x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   642
    by (rule rpath_star[elim_format], auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   643
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   644
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   645
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   646
  The following lemma characterizes the change of sub-tree of @{text "x"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   647
  with the removal of an outside edge @{text "(a,b)"}. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   648
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   649
  Note that, according to lemma @{thm edges_in_refutation}, the assumption
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   650
  @{term "b \<notin> subtree r x"} amounts to saying @{text "(a, b)"} 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   651
  is outside the sub-tree of @{text "x"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   652
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   653
lemma subtree_del_outside: (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   654
    assumes "b \<notin> subtree r x" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   655
    shows "subtree (r - {(a, b)}) x = (subtree r x)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   656
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   657
  { fix c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   658
    assume "c \<in> (subtree r x)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   659
    hence "(c, x) \<in> r^*" by (auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   660
    hence "c \<in> subtree (r - {(a, b)}) x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   661
    proof(rule star_rpath)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   662
      fix xs
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   663
      assume rp: "rpath r c xs x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   664
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   665
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   666
        from rp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   667
        have "rpath  (r - {(a, b)}) c xs x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   668
        proof(rule rpath_transfer)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   669
          from rpath_edges_on[OF rp] have "edges_on (c # xs) \<subseteq> r" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   670
          moreover have "(a, b) \<notin> edges_on (c#xs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   671
          proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   672
            assume "(a, b) \<in> edges_on (c # xs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   673
            then obtain l1 l2 where h: "c#xs = l1@[a,b]@l2" by (auto simp:edges_on_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   674
            hence "tl (c#xs) = tl (l1@[a,b]@l2)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   675
            then obtain l1' where eq_xs_b: "xs = l1'@[b]@l2" by (cases l1, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   676
            from rp[unfolded this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   677
            show False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   678
            proof(rule rpath_appendE)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   679
              assume "rpath r b l2 x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   680
              thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   681
              by(rule rpath_star[elim_format], insert assms(1), auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   682
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   683
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   684
          ultimately show "edges_on (c # xs) \<subseteq> r - {(a,b)}" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   685
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   686
        thus ?thesis by (rule rpath_star[elim_format], auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   687
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   688
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   689
  } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   690
    fix c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   691
    assume "c \<in> subtree (r - {(a, b)}) x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   692
    moreover have "... \<subseteq> (subtree r x)" by (rule subtree_mono, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   693
    ultimately have "c \<in> (subtree r x)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   694
  } ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   695
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   696
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   697
(* ddd *)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   698
lemma subset_del_subtree_outside: (* ddd *)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   699
    assumes "Range r' \<inter> subtree r x = {}" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   700
    shows "subtree (r - r') x = (subtree r x)" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   701
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   702
  { fix c
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   703
    assume "c \<in> (subtree r x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   704
    hence "(c, x) \<in> r^*" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   705
    hence "c \<in> subtree (r - r') x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   706
    proof(rule star_rpath)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   707
      fix xs
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   708
      assume rp: "rpath r c xs x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   709
      show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   710
      proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   711
        from rp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   712
        have "rpath  (r - r') c xs x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   713
        proof(rule rpath_transfer)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   714
          from rpath_edges_on[OF rp] have "edges_on (c # xs) \<subseteq> r" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   715
          moreover {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   716
              fix a b
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   717
              assume h: "(a, b) \<in> r'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   718
              have "(a, b) \<notin> edges_on (c#xs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   719
              proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   720
                assume "(a, b) \<in> edges_on (c # xs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   721
                then obtain l1 l2 where "c#xs = (l1@[a])@[b]@l2" by (auto simp:edges_on_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   722
                hence "tl (c#xs) = tl (l1@[a,b]@l2)" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   723
                then obtain l1' where eq_xs_b: "xs = l1'@[b]@l2" by (cases l1, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   724
                from rp[unfolded this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   725
                show False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   726
                proof(rule rpath_appendE)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   727
                  assume "rpath r b l2 x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   728
                  from rpath_star[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   729
                  have "b \<in> subtree r x" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   730
                  with assms (1) and h show ?thesis by (auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   731
                qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   732
             qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   733
         } ultimately show "edges_on (c # xs) \<subseteq> r - r'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   734
        qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   735
        thus ?thesis by (rule rpath_star[elim_format], auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   736
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   737
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   738
  } moreover {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   739
    fix c
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   740
    assume "c \<in> subtree (r - r') x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   741
    moreover have "... \<subseteq> (subtree r x)" by (rule subtree_mono, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   742
    ultimately have "c \<in> (subtree r x)" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   743
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   744
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   745
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   746
lemma subtree_insert_ext:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   747
    assumes "b \<in> subtree r x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   748
    shows "subtree (r \<union> {(a, b)}) x = (subtree r x) \<union> (subtree r a)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   749
    using assms by (auto simp:subtree_def rtrancl_insert)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   750
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   751
lemma subtree_insert_next:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   752
    assumes "b \<notin> subtree r x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   753
    shows "subtree (r \<union> {(a, b)}) x = (subtree r x)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   754
    using assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   755
    by (auto simp:subtree_def rtrancl_insert)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   756
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   757
lemma set_add_rootI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   758
  assumes "root r a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   759
  and "a \<notin> Domain r1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   760
  shows "root (r \<union> r1) a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   761
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   762
  let ?r = "r \<union> r1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   763
  { fix a'
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   764
    assume "a' \<in> ancestors ?r a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   765
    hence "(a, a') \<in> ?r^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   766
    from tranclD[OF this] obtain z where "(a, z) \<in> ?r" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   767
    moreover have "(a, z) \<notin> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   768
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   769
      assume "(a, z) \<in> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   770
      with assms(1) show False 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   771
        by (auto simp:root_def ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   772
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   773
    ultimately have "(a, z) \<in> r1" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   774
    with assms(2) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   775
    have False by (auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   776
  } thus ?thesis by (auto simp:root_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   777
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   778
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   779
lemma ancestors_mono:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   780
  assumes "r1 \<subseteq> r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   781
  shows "ancestors r1 x \<subseteq> ancestors r2 x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   782
proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   783
 fix a
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   784
 assume "a \<in> ancestors r1 x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   785
 hence "(x, a) \<in> r1^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   786
 from plus_rpath[OF this] obtain xs where 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   787
    h: "rpath r1 x xs a" "xs \<noteq> []" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   788
 have "rpath r2 x xs a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   789
 proof(rule rpath_transfer[OF h(1)])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   790
  from rpath_edges_on[OF h(1)] and assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   791
  show "edges_on (x # xs) \<subseteq> r2" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   792
 qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   793
 from rpath_plus[OF this h(2)]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   794
 show "a \<in> ancestors r2 x" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   795
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   796
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   797
lemma subtree_refute:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   798
  assumes "x \<notin> ancestors r y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   799
  and "x \<noteq> y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   800
  shows "y \<notin> subtree r x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   801
proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   802
   assume "y \<in> subtree r x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   803
   thus False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   804
     by(elim subtreeE, insert assms, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   805
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   806
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   807
subsubsection {* Properties about relational trees *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   808
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   809
context rtree 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   810
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   811
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   812
lemma ancestors_headE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   813
  assumes "c \<in> ancestors r a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   814
  assumes "(a, b) \<in> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   815
  obtains "b = c"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   816
     |   "c \<in> ancestors r b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   817
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   818
  from assms(1) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   819
  have "(a, c) \<in> r^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   820
  hence "b = c \<or> c \<in> ancestors r b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   821
  proof(cases rule:converse_tranclE[consumes 1])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   822
    case 1
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   823
    with assms(2) and sgv have "b = c" by (auto simp:single_valued_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   824
    thus ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   825
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   826
    case (2 y)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   827
    from 2(1) and assms(2) and sgv have "y = b" by (auto simp:single_valued_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   828
    from 2(2)[unfolded this] have "c \<in> ancestors r b" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   829
    thus ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   830
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   831
  with that show ?thesis by metis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   832
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   833
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   834
lemma ancestors_accum:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   835
  assumes "(a, b) \<in> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   836
  shows "ancestors r a = ancestors r b \<union> {b}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   837
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   838
  { fix c
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   839
    assume "c \<in> ancestors r a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   840
    hence "(a, c) \<in> r^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   841
    hence "c \<in> ancestors r b \<union> {b}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   842
    proof(cases rule:converse_tranclE[consumes 1])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   843
      case 1
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   844
      with sgv assms have "c = b" by (unfold single_valued_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   845
      thus ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   846
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   847
      case (2 c')
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   848
      with sgv assms have "c' = b" by (unfold single_valued_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   849
      from 2(2)[unfolded this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   850
      show ?thesis by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   851
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   852
  } moreover {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   853
    fix c
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   854
    assume "c \<in> ancestors r b \<union> {b}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   855
    hence "c = b \<or> c \<in> ancestors r b" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   856
    hence "c \<in> ancestors r a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   857
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   858
      assume "c = b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   859
      from assms[folded this] 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   860
      show ?thesis by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   861
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   862
      assume "c \<in> ancestors r b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   863
      with assms show ?thesis by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   864
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   865
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   866
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   867
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   868
lemma rootI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   869
  assumes h: "\<And> x'. x' \<noteq> x \<Longrightarrow> x \<notin> subtree r' x'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   870
  and "r' \<subseteq> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   871
  shows "root r' x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   872
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   873
  from acyclic_subset[OF acl assms(2)]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   874
  have acl': "acyclic r'" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   875
  { fix x'
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   876
    assume "x' \<in> ancestors r' x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   877
    hence h1: "(x, x') \<in> r'^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   878
    have "x' \<noteq> x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   879
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   880
      assume eq_x: "x' = x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   881
      from h1[unfolded this] and acl'
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   882
      show False by (auto simp:acyclic_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   883
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   884
    moreover from h1 have "x \<in> subtree r' x'" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   885
    ultimately have False using h by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   886
  } thus ?thesis by (auto simp:root_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   887
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   888
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   889
lemma rpath_overlap_oneside: (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   890
  assumes "rpath r x xs1 x1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   891
  and "rpath r x xs2 x2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   892
  and "length xs1 \<le> length xs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   893
  obtains xs3 where "xs2 = xs1 @ xs3"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   894
proof(cases "xs1 = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   895
  case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   896
  with that show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   897
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   898
  case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   899
  have "\<forall> i \<le> length xs1. take i xs1 = take i xs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   900
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   901
     { assume "\<not> (\<forall> i \<le> length xs1. take i xs1 = take i xs2)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   902
       then obtain i where "i \<le> length xs1 \<and> take i xs1 \<noteq> take i xs2" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   903
       from this(1) have "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   904
       proof(rule index_minimize)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   905
          fix j
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   906
          assume h1: "j \<le> length xs1 \<and> take j xs1 \<noteq> take j xs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   907
          and h2: " \<forall>k<j. \<not> (k \<le> length xs1 \<and> take k xs1 \<noteq> take k xs2)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   908
          -- {* @{text "j - 1"} is the branch point between @{text "xs1"} and @{text "xs2"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   909
          let ?idx = "j - 1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   910
          -- {* A number of inequalities concerning @{text "j - 1"} are derived first *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   911
          have lt_i: "?idx < length xs1" using False h1 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   912
            by (metis Suc_diff_1 le_neq_implies_less length_greater_0_conv lessI less_imp_diff_less)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   913
          have lt_i': "?idx < length xs2" using lt_i and assms(3) by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   914
          have lt_j: "?idx < j" using h1 by (cases j, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   915
          -- {* From thesis inequalities, a number of equations concerning @{text "xs1"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   916
                 and @{text "xs2"} are derived *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   917
          have eq_take: "take ?idx xs1 = take ?idx xs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   918
            using h2[rule_format, OF lt_j] and h1 by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   919
          have eq_xs1: " xs1 = take ?idx xs1 @ xs1 ! (?idx) # drop (Suc (?idx)) xs1" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   920
            using id_take_nth_drop[OF lt_i] .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   921
          have eq_xs2: "xs2 = take ?idx xs2 @ xs2 ! (?idx) # drop (Suc (?idx)) xs2" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   922
              using id_take_nth_drop[OF lt_i'] .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   923
          -- {* The branch point along the path is finally pinpointed *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   924
          have neq_idx: "xs1!?idx \<noteq> xs2!?idx" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   925
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   926
            have "take j xs1 = take ?idx xs1 @ [xs1 ! ?idx]"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   927
                using eq_xs1 Suc_diff_1 lt_i lt_j take_Suc_conv_app_nth by fastforce 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   928
            moreover have eq_tk2: "take j xs2 = take ?idx xs2 @ [xs2 ! ?idx]"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   929
                using Suc_diff_1 lt_i' lt_j take_Suc_conv_app_nth by fastforce 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   930
            ultimately show ?thesis using eq_take h1 by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   931
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   932
          show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   933
          proof(cases " take (j - 1) xs1 = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   934
            case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   935
            have "(x, xs1!?idx) \<in> r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   936
            proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   937
                from eq_xs1[unfolded True, simplified, symmetric] assms(1) 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   938
                have "rpath r x ( xs1 ! ?idx # drop (Suc ?idx) xs1) x1" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   939
                from this[unfolded rpath_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   940
                show ?thesis by (auto simp:pred_of_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   941
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   942
            moreover have "(x, xs2!?idx) \<in> r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   943
            proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   944
              from eq_xs2[folded eq_take, unfolded True, simplified, symmetric] assms(2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   945
              have "rpath r x ( xs2 ! ?idx # drop (Suc ?idx) xs2) x2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   946
              from this[unfolded rpath_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   947
              show ?thesis by (auto simp:pred_of_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   948
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   949
            ultimately show ?thesis using neq_idx sgv[unfolded single_valued_def] by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   950
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   951
           case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   952
           then obtain e es where eq_es: "take ?idx xs1 = es@[e]" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   953
            using rev_exhaust by blast 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   954
           have "(e, xs1!?idx) \<in> r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   955
           proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   956
            from eq_xs1[unfolded eq_es] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   957
            have "xs1 = es@[e, xs1!?idx]@drop (Suc ?idx) xs1" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   958
            hence "(e, xs1!?idx) \<in> edges_on xs1" by (simp add:edges_on_def, metis)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   959
            with rpath_edges_on[OF assms(1)] edges_on_Cons_mono[of xs1 x]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   960
            show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   961
           qed moreover have "(e, xs2!?idx) \<in> r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   962
           proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   963
            from eq_xs2[folded eq_take, unfolded eq_es]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   964
            have "xs2 = es@[e, xs2!?idx]@drop (Suc ?idx) xs2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   965
            hence "(e, xs2!?idx) \<in> edges_on xs2" by (simp add:edges_on_def, metis)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   966
            with rpath_edges_on[OF assms(2)] edges_on_Cons_mono[of xs2 x]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   967
            show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   968
           qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   969
           ultimately show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   970
              using sgv[unfolded single_valued_def] neq_idx by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   971
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   972
       qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   973
     } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   974
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   975
  from this[rule_format, of "length xs1"]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   976
  have "take (length xs1) xs1 = take (length xs1) xs2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   977
  moreover have "xs2 = take (length xs1) xs2 @ drop (length xs1) xs2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   978
  ultimately have "xs2 = xs1 @ drop (length xs1) xs2" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   979
  from that[OF this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   980
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   981
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   982
lemma rpath_overlap [consumes 2, cases pred:rpath]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   983
  assumes "rpath r x xs1 x1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   984
  and "rpath r x xs2 x2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   985
  obtains (less_1) xs3 where "xs2 = xs1 @ xs3"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   986
     |    (less_2) xs3 where "xs1 = xs2 @ xs3"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   987
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   988
  have "length xs1 \<le> length xs2 \<or> length xs2 \<le> length xs1" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   989
  with assms rpath_overlap_oneside that show ?thesis by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   990
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   991
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   992
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   993
  As a corollary of @{thm "rpath_overlap_oneside"}, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   994
  the following two lemmas gives one important property of relation tree, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   995
  i.e. there is at most one path between any two nodes.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   996
  Similar to the proof of @{thm rpath_overlap}, we starts with
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   997
  the one side version first.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   998
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   999
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1000
lemma rpath_unique_oneside:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1001
  assumes "rpath r x xs1 y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1002
    and "rpath r x xs2 y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1003
    and "length xs1 \<le> length xs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1004
  shows "xs1 = xs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1005
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1006
  from rpath_overlap_oneside[OF assms] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1007
  obtain xs3 where less_1: "xs2 = xs1 @ xs3" by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1008
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1009
  proof(cases "xs3 = []") 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1010
    case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1011
    from less_1[unfolded this] show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1012
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1013
    case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1014
    note FalseH = this
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1015
    show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1016
    proof(cases "xs1 = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1017
      case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1018
      have "(x, x) \<in> r^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1019
      proof(rule rpath_plus)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1020
        from assms(1)[unfolded True] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1021
        have "y = x" by (cases rule:rpath_nilE, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1022
        from assms(2)[unfolded this] show "rpath r x xs2 x" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1023
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1024
        from less_1 and False show "xs2 \<noteq> []" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1025
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1026
      with acl show ?thesis by (unfold acyclic_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1027
    next 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1028
      case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1029
      then obtain e es where eq_xs1: "xs1 = es@[e]" using rev_exhaust by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1030
      from assms(2)[unfolded less_1 this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1031
      have "rpath r x (es @ [e] @ xs3) y" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1032
      thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1033
      proof(cases rule:rpath_appendE)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1034
        case 1
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1035
        from rpath_dest_eq [OF 1(1)[folded eq_xs1] assms(1)]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1036
        have "e = y" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1037
        from rpath_plus [OF 1(2)[unfolded this] FalseH]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1038
        have "(y, y) \<in> r^+" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1039
        with acl show ?thesis by (unfold acyclic_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1040
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1041
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1042
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1043
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1044
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1045
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1046
  The following is the full version of path uniqueness.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1047
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1048
lemma rpath_unique:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1049
  assumes "rpath r x xs1 y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1050
    and "rpath r x xs2 y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1051
  shows "xs1 = xs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1052
proof(cases "length xs1 \<le> length xs2")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1053
   case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1054
   from rpath_unique_oneside[OF assms this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1055
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1056
  case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1057
  hence "length xs2 \<le> length xs1" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1058
  from rpath_unique_oneside[OF assms(2,1) this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1059
  show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1060
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1061
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1062
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1063
  The following lemma shows that the `independence` relation is symmetric.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1064
  It is an obvious auxiliary lemma which will be used later. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1065
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1066
lemma sym_indep: "indep r x y \<Longrightarrow> indep r y x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1067
  by (unfold indep_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1068
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1069
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1070
  This is another `obvious` lemma about trees, which says trees rooted at 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1071
  independent nodes are disjoint.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1072
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1073
lemma subtree_disjoint:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1074
  assumes "indep r x y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1075
  shows "subtree r x \<inter> subtree r y = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1076
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1077
  { fix z x y xs1 xs2 xs3
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1078
      assume ind: "indep r x y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1079
      and rp1: "rpath r z xs1 x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1080
      and rp2: "rpath r z xs2 y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1081
      and h: "xs2 = xs1 @ xs3"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1082
      have False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1083
      proof(cases "xs1 = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1084
        case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1085
        from rp1[unfolded this] have "x = z" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1086
        from rp2[folded this] rpath_star ind[unfolded indep_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1087
        show ?thesis by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1088
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1089
        case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1090
        then obtain e es where eq_xs1: "xs1 = es@[e]" using rev_exhaust by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1091
        from rp2[unfolded h this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1092
        have "rpath r z (es @ [e] @ xs3) y" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1093
        thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1094
        proof(cases rule:rpath_appendE)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1095
          case 1
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1096
          have "e = x" using 1(1)[folded eq_xs1] rp1 rpath_dest_eq by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1097
          from rpath_star[OF 1(2)[unfolded this]] ind[unfolded indep_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1098
          show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1099
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1100
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1101
  } note my_rule = this
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1102
  { fix z
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1103
    assume h: "z \<in> subtree r x" "z \<in> subtree r y"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1104
    from h(1) have "(z, x) \<in> r^*" by (unfold subtree_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1105
    then obtain xs1 where rp1: "rpath r z xs1 x" using star_rpath by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1106
    from h(2) have "(z, y) \<in> r^*" by (unfold subtree_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1107
    then obtain xs2 where rp2: "rpath r z xs2 y" using star_rpath by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1108
    from rp1 rp2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1109
    have False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1110
    by (cases, insert my_rule[OF sym_indep[OF assms(1)] rp2 rp1] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1111
                  my_rule[OF assms(1) rp1 rp2], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1112
  } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1113
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1114
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1115
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1116
  The following lemma @{text "subtree_del"} characterizes the change of sub-tree of 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1117
  @{text "x"} with the removal of an inside edge @{text "(a, b)"}. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1118
  Note that, the case for the removal of an outside edge has already been dealt with
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1119
  in lemma @{text "subtree_del_outside"}). 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1120
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1121
  This lemma is underpinned by the following two `obvious` facts:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1122
  \begin{enumearte}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1123
  \item
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1124
  In graph @{text "r"}, for an inside edge @{text "(a,b) \<in> edges_in r x"},  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1125
  every node @{text "c"} in the sub-tree of @{text "a"} has a path
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1126
  which goes first from @{text "c"} to @{text "a"}, then through edge @{text "(a, b)"}, and 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1127
  finally reaches @{text "x"}. By the uniqueness of path in a tree,
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1128
  all paths from sub-tree of @{text "a"} to @{text "x"} are such constructed, therefore 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1129
  must go through @{text "(a, b)"}. The consequence is: with the removal of @{text "(a,b)"},
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1130
  all such paths will be broken. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1131
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1132
  \item
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1133
  On the other hand, all paths not originate from within the sub-tree of @{text "a"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1134
  will not be affected by the removal of edge @{text "(a, b)"}. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1135
  The reason is simple: if the path is affected by the removal, it must 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1136
  contain @{text "(a, b)"}, then it must originate from within the sub-tree of @{text "a"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1137
  \end{enumearte}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1138
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1139
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1140
lemma subtree_del_inside: (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1141
    assumes "(a,b) \<in> edges_in r x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1142
    shows "subtree (r - {(a, b)}) x = (subtree r x) - subtree r a"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1143
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1144
  from assms have asm: "b \<in> subtree r x" "(a, b) \<in> r" by (auto simp:edges_in_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1145
  -- {* The proof follows a common pattern to prove the equality of sets. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1146
  { -- {* The `left to right` direction.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1147
       *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1148
    fix c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1149
    -- {* Assuming @{text "c"} is inside the sub-tree of @{text "x"} in the reduced graph *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1150
    assume h: "c \<in> subtree (r - {(a, b)}) x" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1151
    -- {* We are going to show that @{text "c"} can not be in the sub-tree of @{text "a"} in 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1152
          the original graph. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1153
    -- {* In other words, all nodes inside the sub-tree of @{text "a"} in the original 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1154
          graph will be removed from the sub-tree of @{text "x"} in the reduced graph. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1155
    -- {* The reason, as analyzed before, is that all paths from within the 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1156
          sub-tree of @{text "a"} are broken with the removal of edge @{text "(a,b)"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1157
       *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1158
    have "c \<in> (subtree r x) - subtree r a" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1159
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1160
      let ?r' = "r - {(a, b)}" -- {* The reduced graph is abbreviated as @{text "?r'"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1161
      from h have "(c, x) \<in> ?r'^*" by (auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1162
      -- {* Extract from the reduced graph the path @{text "xs"} from @{text "c"} to @{text "x"}. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1163
      then obtain xs where rp0: "rpath ?r' c xs x" by (rule star_rpath, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1164
      -- {* It is easy to show @{text "xs"} is also a path in the original graph *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1165
      hence rp1: "rpath r c xs x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1166
      proof(rule rpath_transfer)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1167
          from rpath_edges_on[OF rp0] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1168
          show "edges_on (c # xs) \<subseteq> r" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1169
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1170
      -- {* @{text "xs"} is used as the witness to show that @{text "c"} 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1171
                   in the sub-tree of @{text "x"} in the original graph. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1172
      hence "c \<in> subtree r x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1173
         by (rule rpath_star[elim_format], auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1174
      -- {* The next step is to show that @{text "c"} can not be in the sub-tree of @{text "a"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1175
            in the original graph. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1176
      -- {* We need to use the fact that all paths originate from within sub-tree of @{text "a"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1177
             are broken. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1178
      moreover have "c \<notin> subtree r a"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1179
      proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1180
        -- {* Proof by contradiction, suppose otherwise *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1181
        assume otherwise: "c \<in> subtree r a"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1182
        -- {* Then there is a path in original graph leading from @{text "c"} to @{text "a"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1183
        obtain xs1 where rp_c: "rpath r c xs1 a" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1184
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1185
          from otherwise have "(c, a) \<in> r^*" by (auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1186
          thus ?thesis by (rule star_rpath, auto intro!:that)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1187
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1188
        -- {* Starting from this path, we are going to construct a fictional 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1189
                  path from @{text "c"} to @{text "x"}, which, as explained before,
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1190
              is broken, so that contradiction can be derived. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1191
        -- {* First, there is a path from @{text "b"} to @{text "x"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1192
        obtain ys where rp_b: "rpath r b ys x" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1193
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1194
          from asm have "(b, x) \<in> r^*" by (auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1195
          thus ?thesis by (rule star_rpath, auto intro!:that)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1196
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1197
        -- {* The paths @{text "xs1"} and @{text "ys"} can be 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1198
                 tied together using @{text "(a,b)"} to form a path 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1199
               from @{text "c"} to @{text "x"}: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1200
        have "rpath r c (xs1 @ b # ys) x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1201
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1202
          from rstepI[OF asm(2) rp_b] have "rpath r a (b # ys) x" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1203
          from rpath_appendI[OF rp_c this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1204
          show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1205
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1206
        -- {* By the uniqueness of path between two nodes of a tree, we have: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1207
        from rpath_unique[OF rp1 this] have eq_xs: "xs = xs1 @ b # ys" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1208
        -- {* Contradiction can be derived from from this fictional path . *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1209
        show False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1210
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1211
          -- {* It can be shown that @{term "(a,b)"} is on this fictional path. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1212
          have "(a, b) \<in> edges_on (c#xs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1213
          proof(cases "xs1 = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1214
            case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1215
            from rp_c[unfolded this] have "rpath r c [] a" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1216
            hence eq_c: "c = a" by (rule rpath_nilE, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1217
            hence "c#xs = a#xs" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1218
            from this and eq_xs have "c#xs = a # xs1 @ b # ys" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1219
            from this[unfolded True] have "c#xs = []@[a,b]@ys" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1220
            thus ?thesis by (auto simp:edges_on_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1221
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1222
            case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1223
            from rpath_nnl_lastE[OF rp_c this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1224
            obtain xs' where "xs1 = xs'@[a]" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1225
            from eq_xs[unfolded this] have "c#xs = (c#xs')@[a,b]@ys" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1226
            thus ?thesis by (unfold edges_on_def, blast)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1227
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1228
          -- {* It can also be shown that @{term "(a,b)"} is not on this fictional path. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1229
          moreover have "(a, b) \<notin> edges_on (c#xs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1230
              using rpath_edges_on[OF rp0] by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1231
          -- {* Contradiction is thus derived. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1232
          ultimately show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1233
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1234
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1235
      ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1236
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1237
  } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1238
    -- {* The `right to left` direction.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1239
       *} 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1240
     fix c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1241
   -- {* Assuming that @{text "c"} is in the sub-tree of @{text "x"}, but
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1242
         outside of the sub-tree of @{text "a"} in the original graph, *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1243
   assume h: "c \<in> (subtree r x) - subtree r a"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1244
   -- {* we need to show that in the reduced graph, @{text "c"} is still in 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1245
         the sub-tree of @{text "x"}. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1246
   have "c \<in> subtree (r - {(a, b)}) x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1247
   proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1248
      -- {* The proof goes by showing that the path from @{text "c"} to @{text "x"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1249
            in the original graph is not affected by the removal of @{text "(a,b)"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1250
         *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1251
      from h have "(c, x) \<in> r^*" by (unfold subtree_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1252
      -- {* Extract the path @{text "xs"} from @{text "c"} to @{text "x"} in the original graph. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1253
      from star_rpath[OF this] obtain xs where rp: "rpath r c xs x" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1254
      -- {* Show that it is also a path in the reduced graph. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1255
      hence "rpath (r - {(a, b)}) c xs x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1256
      -- {* The proof goes by using rule @{thm rpath_transfer} *} 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1257
      proof(rule rpath_transfer)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1258
        -- {* We need to show all edges on the path are still in the reduced graph. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1259
        show "edges_on (c # xs) \<subseteq> r - {(a, b)}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1260
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1261
          -- {* It is easy to show that all the edges are in the original graph. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1262
          from rpath_edges_on [OF rp] have " edges_on (c # xs) \<subseteq> r" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1263
          -- {* The essential part is to show that @{text "(a, b)"} is not on the path. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1264
          moreover have "(a,b) \<notin> edges_on (c#xs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1265
          proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1266
            -- {* Proof by contradiction, suppose otherwise: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1267
            assume otherwise: "(a, b) \<in> edges_on (c#xs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1268
            -- {* Then @{text "(a, b)"} is in the middle of the path. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1269
                  with @{text "l1"} and @{text "l2"} be the nodes in 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1270
                  the front and rear respectively. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1271
              then obtain l1 l2 where eq_xs: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1272
                "c#xs = l1 @ [a, b] @ l2" by (unfold edges_on_def, blast)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1273
            -- {* From this, it can be shown that @{text "c"} is 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1274
                      in the sub-tree of @{text "a"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1275
            have "c \<in> subtree r a" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1276
            proof(cases "l1 = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1277
              case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1278
              -- {* If @{text "l1"} is null, it can be derived that @{text "c = a"}. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1279
              with eq_xs have "c = a" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1280
              -- {* So, @{text "c"} is obviously in the sub-tree of @{text "a"}. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1281
              thus ?thesis by (unfold subtree_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1282
            next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1283
              case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1284
              -- {* When @{text "l1"} is not null, it must have a tail @{text "es"}: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1285
              then obtain e es where "l1 = e#es" by (cases l1, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1286
              -- {* The relation of this tail with @{text "xs"} is derived: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1287
              with eq_xs have "xs = es@[a,b]@l2" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1288
              -- {* From this, a path from @{text "c"} to @{text "a"} is made visible: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1289
              from rp[unfolded this] have "rpath r c (es @ [a] @ (b#l2)) x" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1290
              thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1291
              proof(cases rule:rpath_appendE)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1292
                -- {* The path from @{text "c"} to @{text "a"} is extraced 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1293
                             using @{thm "rpath_appendE"}: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1294
                case 1
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1295
                from rpath_star[OF this(1)] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1296
                -- {* The extracted path servers as a witness that @{text "c"} is 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1297
                          in the sub-tree of @{text "a"}: *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1298
                show ?thesis by (simp add:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1299
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1300
          qed with h show False by auto         
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1301
         qed ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1302
       qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1303
     qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1304
     -- {* From , it is shown that @{text "c"} is in the sub-tree of @{text "x"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1305
           inthe reduced graph. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1306
     from rpath_star[OF this] show ?thesis by (auto simp:subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1307
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1308
  } 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1309
  -- {* The equality of sets is derived from the two directions just proved. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1310
  ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1311
qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1312
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1313
lemma  set_del_rootI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1314
  assumes "r1 \<subseteq> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1315
  and "a \<in> Domain r1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1316
  shows "root (r - r1) a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1317
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1318
   let ?r = "r - r1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1319
  { fix a' 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1320
    assume neq: "a' \<noteq> a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1321
    have "a \<notin> subtree ?r a'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1322
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1323
      assume "a \<in> subtree ?r a'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1324
      hence "(a, a') \<in> ?r^*" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1325
      from star_rpath[OF this] obtain xs
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1326
      where rp: "rpath ?r a xs a'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1327
      from rpathE[OF this] and neq
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1328
      obtain z zs where h: "(a, z) \<in> ?r" "rpath ?r z zs a'" "xs = z#zs" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1329
      from assms(2) obtain z' where z'_in: "(a, z') \<in> r1" by (auto simp:DomainE)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1330
      with assms(1) have "(a, z') \<in> r" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1331
      moreover from h(1) have "(a, z) \<in> r" by simp 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1332
      ultimately have "z' = z" using sgv by (auto simp:single_valued_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1333
      from z'_in[unfolded this] and h(1) show False by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1334
   qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1335
  } thus ?thesis by (intro rootI, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1336
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1337
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1338
lemma edge_del_no_rootI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1339
  assumes "(a, b) \<in> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1340
  shows "root (r - {(a, b)}) a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1341
  by (rule set_del_rootI, insert assms, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1342
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1343
lemma ancestors_children_unique:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1344
  assumes "z1 \<in> ancestors r x \<inter> children r y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1345
  and "z2 \<in> ancestors r x \<inter> children r y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1346
  shows "z1 = z2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1347
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1348
  from assms have h:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1349
     "(x, z1) \<in> r^+" "(z1, y) \<in> r" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1350
     "(x, z2) \<in> r^+" "(z2, y) \<in> r" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1351
  by (auto simp:ancestors_def children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1352
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1353
  -- {* From this, a path containing @{text "z1"} is obtained. *}
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1354
  from plus_rpath[OF h(1)] obtain xs1 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1355
     where h1: "rpath r x xs1 z1" "xs1 \<noteq> []" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1356
  from rpath_nnl_lastE[OF this] obtain xs1' where eq_xs1: "xs1 = xs1' @ [z1]"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1357
    by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1358
  from h(2) have h2: "rpath r z1 [y] y" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1359
  from rpath_appendI[OF h1(1) h2, unfolded eq_xs1]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1360
  have rp1: "rpath r x (xs1' @ [z1, y]) y" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1361
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1362
  -- {* Then, another path containing @{text "z2"} is obtained. *}
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1363
  from plus_rpath[OF h(3)] obtain xs2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1364
     where h3: "rpath r x xs2 z2" "xs2 \<noteq> []" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1365
  from rpath_nnl_lastE[OF this] obtain xs2' where eq_xs2: "xs2 = xs2' @ [z2]"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1366
    by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1367
  from h(4) have h4: "rpath r z2 [y] y" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1368
  from rpath_appendI[OF h3(1) h4, unfolded eq_xs2]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1369
     have "rpath r x (xs2' @ [z2, y]) y" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1370
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1371
  -- {* Finally @{text "z1 = z2"} is proved by uniqueness of path. *}
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1372
  from rpath_unique[OF rp1 this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1373
  have "xs1' @ [z1, y] = xs2' @ [z2, y]" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1374
  thus ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1375
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1376
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1377
lemma ancestors_childrenE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1378
  assumes "y \<in> ancestors r x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1379
  obtains "x \<in> children r y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1380
      | z where "z \<in> ancestors r x \<inter> children r y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1381
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1382
  from assms(1) have "(x, y) \<in> r^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1383
  from tranclD2[OF this] obtain z where 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1384
     h: "(x, z) \<in> r\<^sup>*" "(z, y) \<in> r" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1385
  from h(1)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1386
  show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1387
  proof(cases rule:rtranclE)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1388
    case base
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1389
    from h(2)[folded this] have "x \<in> children r y" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1390
              by (auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1391
    thus ?thesis by (intro that, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1392
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1393
    case (step u)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1394
    hence "z \<in> ancestors r x" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1395
    moreover from h(2) have "z \<in> children r y" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1396
              by (auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1397
    ultimately show ?thesis by (intro that, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1398
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1399
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1400
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1401
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1402
end (* of rtree *)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1403
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1404
lemma subtree_children:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1405
  "subtree r x = {x} \<union> (\<Union> (subtree r ` (children r x)))" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1406
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1407
  { fix z
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1408
    assume "z \<in> ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1409
    hence "z \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1410
    proof(cases rule:subtreeE[consumes 1])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1411
      case 2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1412
      hence "(z, x) \<in> r^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1413
      thus ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1414
      proof(rule tranclE)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1415
        assume "(z, x) \<in> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1416
        hence "z \<in> children r x" by (unfold children_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1417
        moreover have "z \<in> subtree r z" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1418
        ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1419
      next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1420
        fix c
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1421
        assume h: "(z, c) \<in> r\<^sup>+" "(c, x) \<in> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1422
        hence "c \<in> children r x" by (auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1423
        moreover from h have "z \<in> subtree r c" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1424
        ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1425
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1426
    qed auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1427
  } moreover {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1428
    fix z
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1429
    assume h: "z \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1430
    have "x \<in> subtree r x" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1431
    moreover {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1432
       assume "z \<in> \<Union>(subtree r ` children r x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1433
       then obtain y where "(y, x) \<in> r" "(z, y) \<in> r^*" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1434
        by (auto simp:subtree_def children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1435
       hence "(z, x) \<in> r^*" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1436
       hence "z \<in> ?L" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1437
    } ultimately have "z \<in> ?L" using h by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1438
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1439
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1440
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1441
context fsubtree 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1442
begin
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1443
  
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1444
lemma finite_subtree:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1445
  shows "finite (subtree r x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1446
proof(induct rule:wf_induct[OF wf])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1447
  case (1 x)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1448
  have "finite (\<Union>(subtree r ` children r x))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1449
  proof(rule finite_Union)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1450
    show "finite (subtree r ` children r x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1451
    proof(cases "children r x = {}")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1452
      case True
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1453
      thus ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1454
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1455
      case False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1456
      hence "x \<in> Range r" by (auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1457
      from fb[rule_format, OF this] 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1458
      have "finite (children r x)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1459
      thus ?thesis by (rule finite_imageI)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1460
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1461
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1462
    fix M 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1463
    assume "M \<in> subtree r ` children r x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1464
    then obtain y where h: "y \<in> children r x" "M = subtree r y" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1465
    hence "(y, x) \<in> r" by (auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1466
    from 1[rule_format, OF this, folded h(2)]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1467
    show "finite M" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1468
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1469
  thus ?case
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1470
    by (unfold subtree_children finite_Un, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1471
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1472
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1473
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1474
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1475
definition "pairself f = (\<lambda>(a, b). (f a, f b))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1476
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1477
definition "rel_map f r = (pairself f ` r)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1478
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1479
lemma rel_mapE: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1480
  assumes "(a, b) \<in> rel_map f r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1481
  obtains c d 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1482
  where "(c, d) \<in> r" "(a, b) = (f c, f d)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1483
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1484
  by (unfold rel_map_def pairself_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1485
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1486
lemma rel_mapI: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1487
  assumes "(a, b) \<in> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1488
    and "c = f a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1489
    and "d = f b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1490
  shows "(c, d) \<in> rel_map f r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1491
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1492
  by (unfold rel_map_def pairself_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1493
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1494
lemma map_appendE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1495
  assumes "map f zs = xs @ ys"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1496
  obtains xs' ys' 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1497
  where "zs = xs' @ ys'" "xs = map f xs'" "ys = map f ys'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1498
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1499
  have "\<exists> xs' ys'. zs = xs' @ ys' \<and> xs = map f xs' \<and> ys = map f ys'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1500
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1501
  proof(induct xs arbitrary:zs ys)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1502
    case (Nil zs ys)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1503
    thus ?case by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1504
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1505
    case (Cons x xs zs ys)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1506
    note h = this
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1507
    show ?case
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1508
    proof(cases zs)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1509
      case (Cons e es)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1510
      with h have eq_x: "map f es = xs @ ys" "x = f e" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1511
      from h(1)[OF this(1)]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1512
      obtain xs' ys' where "es = xs' @ ys'" "xs = map f xs'" "ys = map f ys'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1513
        by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1514
      with Cons eq_x
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1515
      have "zs = (e#xs') @ ys' \<and> x # xs = map f (e#xs') \<and> ys = map f ys'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1516
      thus ?thesis by metis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1517
    qed (insert h, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1518
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1519
  thus ?thesis by (auto intro!:that)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1520
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1521
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1522
lemma rel_map_mono:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1523
  assumes "r1 \<subseteq> r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1524
  shows "rel_map f r1 \<subseteq> rel_map f r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1525
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1526
  by (auto simp:rel_map_def pairself_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1527
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1528
lemma rel_map_compose [simp]:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1529
    shows "rel_map f1 (rel_map f2 r) = rel_map (f1 o f2) r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1530
    by (auto simp:rel_map_def pairself_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1531
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1532
lemma edges_on_map: "edges_on (map f xs) = rel_map f (edges_on xs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1533
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1534
  { fix a b
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1535
    assume "(a, b) \<in> edges_on (map f xs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1536
    then obtain l1 l2 where eq_map: "map f xs = l1 @ [a, b] @ l2" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1537
      by (unfold edges_on_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1538
    hence "(a, b) \<in> rel_map f (edges_on xs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1539
      by (auto elim!:map_appendE intro!:rel_mapI simp:edges_on_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1540
  } moreover { 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1541
    fix a b
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1542
    assume "(a, b) \<in> rel_map f (edges_on xs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1543
    then obtain c d where 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1544
        h: "(c, d) \<in> edges_on xs" "(a, b) = (f c, f d)" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1545
             by (elim rel_mapE, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1546
    then obtain l1 l2 where
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1547
        eq_xs: "xs = l1 @ [c, d] @ l2" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1548
             by (auto simp:edges_on_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1549
    hence eq_map: "map f xs = map f l1 @ [f c, f d] @ map f l2" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1550
    have "(a, b) \<in> edges_on (map f xs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1551
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1552
      from h(2) have "[f c, f d] = [a, b]" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1553
      from eq_map[unfolded this] show ?thesis by (auto simp:edges_on_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1554
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1555
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1556
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1557
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1558
lemma image_id:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1559
  assumes "\<And> x. x \<in> A \<Longrightarrow> f x = x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1560
  shows "f ` A = A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1561
  using assms by (auto simp:image_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1562
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1563
lemma rel_map_inv_id:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1564
  assumes "inj_on f ((Domain r) \<union> (Range r))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1565
  shows "(rel_map (inv_into ((Domain r) \<union> (Range r)) f \<circ> f) r) = r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1566
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1567
 let ?f = "(inv_into (Domain r \<union> Range r) f \<circ> f)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1568
 {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1569
  fix a b
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1570
  assume h0: "(a, b) \<in> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1571
  have "pairself ?f (a, b) = (a, b)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1572
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1573
    from assms h0 have "?f a = a" by (auto intro:inv_into_f_f)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1574
    moreover have "?f b = b"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1575
      by (insert h0, simp, intro inv_into_f_f[OF assms], auto intro!:RangeI)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1576
    ultimately show ?thesis by (auto simp:pairself_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1577
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1578
 } thus ?thesis by (unfold rel_map_def, intro image_id, case_tac x, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1579
qed 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1580
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1581
lemma rel_map_acyclic:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1582
  assumes "acyclic r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1583
  and "inj_on f ((Domain r) \<union> (Range r))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1584
  shows "acyclic (rel_map f r)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1585
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1586
  let ?D = "Domain r \<union> Range r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1587
  { fix a 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1588
    assume "(a, a) \<in> (rel_map f r)^+" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1589
    from plus_rpath[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1590
    obtain xs where rp: "rpath (rel_map f r) a xs a" "xs \<noteq> []" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1591
    from rpath_nnl_lastE[OF this] obtain xs' where eq_xs: "xs = xs'@[a]" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1592
    from rpath_edges_on[OF rp(1)]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1593
    have h: "edges_on (a # xs) \<subseteq> rel_map f r" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1594
    from edges_on_map[of "inv_into ?D f" "a#xs"]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1595
    have "edges_on (map (inv_into ?D f) (a # xs)) = rel_map (inv_into ?D f) (edges_on (a # xs))" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1596
    with rel_map_mono[OF h, of "inv_into ?D f"]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1597
    have "edges_on (map (inv_into ?D f) (a # xs)) \<subseteq> rel_map ((inv_into ?D f) o f) r" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1598
    from this[unfolded eq_xs]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1599
    have subr: "edges_on (map (inv_into ?D f) (a # xs' @ [a])) \<subseteq> rel_map (inv_into ?D f \<circ> f) r" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1600
    have "(map (inv_into ?D f) (a # xs' @ [a])) = (inv_into ?D f a) # map (inv_into ?D f) xs' @ [inv_into ?D f a]"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1601
      by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1602
    from edges_on_rpathI[OF subr[unfolded this]]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1603
    have "rpath (rel_map (inv_into ?D f \<circ> f) r) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1604
                      (inv_into ?D f a) (map (inv_into ?D f) xs' @ [inv_into ?D f a]) (inv_into ?D f a)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1605
    hence "(inv_into ?D f a, inv_into ?D f a) \<in> (rel_map (inv_into ?D f \<circ> f) r)^+"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1606
        by (rule rpath_plus, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1607
    moreover have "(rel_map (inv_into ?D f \<circ> f) r) = r" by (rule rel_map_inv_id[OF assms(2)])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1608
    moreover note assms(1) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1609
    ultimately have False by (unfold acyclic_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1610
  } thus ?thesis by (auto simp:acyclic_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1611
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1612
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1613
lemma relpow_mult: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1614
  "((r::'a rel) ^^ m) ^^ n = r ^^ (m*n)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1615
proof(induct n arbitrary:m)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1616
  case (Suc k m)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1617
  thus ?case
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1618
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1619
    have h: "(m * k + m) = (m + m * k)" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1620
    show ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1621
      apply (simp add:Suc relpow_add[symmetric])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1622
      by (unfold h, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1623
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1624
qed simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1625
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1626
lemma compose_relpow_2:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1627
  assumes "r1 \<subseteq> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1628
  and "r2 \<subseteq> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1629
  shows "r1 O r2 \<subseteq> r ^^ (2::nat)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1630
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1631
  { fix a b
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1632
    assume "(a, b) \<in> r1 O r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1633
    then obtain e where "(a, e) \<in> r1" "(e, b) \<in> r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1634
      by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1635
    with assms have "(a, e) \<in> r" "(e, b) \<in> r" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1636
    hence "(a, b) \<in> r ^^ (Suc (Suc 0))" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1637
  } thus ?thesis by (auto simp:numeral_2_eq_2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1638
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1639
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1640
lemma acyclic_compose:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1641
  assumes "acyclic r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1642
  and "r1 \<subseteq> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1643
  and "r2 \<subseteq> r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1644
  shows "acyclic (r1 O r2)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1645
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1646
  { fix a
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1647
    assume "(a, a) \<in> (r1 O r2)^+"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1648
    from trancl_mono[OF this compose_relpow_2[OF assms(2, 3)]]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1649
    have "(a, a) \<in> (r ^^ 2) ^+" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1650
    from trancl_power[THEN iffD1, OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1651
    obtain n where h: "(a, a) \<in> (r ^^ 2) ^^ n" "n > 0" by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1652
    from this(1)[unfolded relpow_mult] have h2: "(a, a) \<in> r ^^ (2 * n)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1653
    have "(a, a) \<in> r^+" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1654
    proof(cases rule:trancl_power[THEN iffD2])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1655
      from h(2) h2 show "\<exists>n>0. (a, a) \<in> r ^^ n" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1656
        by (rule_tac x = "2*n" in exI, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1657
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1658
    with assms have "False" by (auto simp:acyclic_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1659
  } thus ?thesis by (auto simp:acyclic_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1660
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1661
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1662
lemma children_compose_unfold: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1663
  "children (r1 O r2) x = \<Union> (children r1 ` (children r2 x))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1664
  by (auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1665
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1666
lemma fbranch_compose:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1667
  assumes "fbranch r1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1668
  and "fbranch r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1669
  shows "fbranch (r1 O r2)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1670
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1671
  {  fix x
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1672
     assume "x\<in>Range (r1 O r2)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1673
     then obtain y z where h: "(y, z) \<in> r1" "(z, x) \<in> r2" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1674
     have "finite (children (r1 O r2) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1675
     proof(unfold children_compose_unfold, rule finite_Union)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1676
      show "finite (children r1 ` children r2 x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1677
      proof(rule finite_imageI)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1678
        from h(2) have "x \<in> Range r2" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1679
        from assms(2)[unfolded fbranch_def, rule_format, OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1680
        show "finite (children r2 x)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1681
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1682
     next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1683
       fix M
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1684
       assume "M \<in> children r1 ` children r2 x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1685
       then obtain y where h1: "y \<in> children r2 x" "M = children r1 y" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1686
       show "finite M"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1687
       proof(cases "children r1 y = {}")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1688
          case True
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1689
          with h1(2) show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1690
       next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1691
          case False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1692
          hence "y \<in> Range r1" by (unfold children_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1693
          from assms(1)[unfolded fbranch_def, rule_format, OF this, folded h1(2)]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1694
          show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1695
       qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1696
     qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1697
  } thus ?thesis by (unfold fbranch_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1698
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1699
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1700
lemma finite_fbranchI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1701
  assumes "finite r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1702
  shows "fbranch r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1703
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1704
  { fix x 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1705
    assume "x \<in>Range r"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1706
    have "finite (children r x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1707
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1708
      have "{y. (y, x) \<in> r} \<subseteq> Domain r" by (auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1709
      from rev_finite_subset[OF finite_Domain[OF assms] this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1710
      have "finite {y. (y, x) \<in> r}" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1711
      thus ?thesis by (unfold children_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1712
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1713
  } thus ?thesis by (auto simp:fbranch_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1714
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1715
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1716
lemma subset_fbranchI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1717
  assumes "fbranch r1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1718
  and "r2 \<subseteq> r1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1719
  shows "fbranch r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1720
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1721
  { fix x
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1722
    assume "x \<in>Range r2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1723
    with assms(2) have "x \<in> Range r1" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1724
    from assms(1)[unfolded fbranch_def, rule_format, OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1725
    have "finite (children r1 x)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1726
    hence "finite (children r2 x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1727
    proof(rule rev_finite_subset)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1728
      from assms(2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1729
      show "children r2 x \<subseteq> children r1 x" by (auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1730
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1731
  } thus ?thesis by (auto simp:fbranch_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1732
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1733
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1734
lemma children_subtree: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1735
  shows "children r x \<subseteq> subtree r x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1736
  by (auto simp:children_def subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1737
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1738
lemma children_union_kept:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1739
  assumes "x \<notin> Range r'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1740
  shows "children (r \<union> r') x = children r x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1741
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1742
  by (auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1743
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1744
end