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