src/HOL/Transitive_Closure.thy
author berghofe
Wed Nov 27 17:07:05 2002 +0100 (2002-11-27)
changeset 13726 9550a6f4ed4a
parent 13704 854501b1e957
child 13867 1fdecd15437f
permissions -rw-r--r--
Replaced some blasts by rules.
nipkow@10213
     1
(*  Title:      HOL/Transitive_Closure.thy
nipkow@10213
     2
    ID:         $Id$
nipkow@10213
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
nipkow@10213
     4
    Copyright   1992  University of Cambridge
nipkow@10213
     5
*)
nipkow@10213
     6
wenzelm@12691
     7
header {* Reflexive and Transitive closure of a relation *}
wenzelm@12691
     8
wenzelm@12691
     9
theory Transitive_Closure = Inductive:
wenzelm@12691
    10
wenzelm@12691
    11
text {*
wenzelm@12691
    12
  @{text rtrancl} is reflexive/transitive closure,
wenzelm@12691
    13
  @{text trancl} is transitive closure,
wenzelm@12691
    14
  @{text reflcl} is reflexive closure.
wenzelm@12691
    15
wenzelm@12691
    16
  These postfix operators have \emph{maximum priority}, forcing their
wenzelm@12691
    17
  operands to be atomic.
wenzelm@12691
    18
*}
nipkow@10213
    19
berghofe@11327
    20
consts
wenzelm@12691
    21
  rtrancl :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_^*)" [1000] 999)
berghofe@11327
    22
berghofe@11327
    23
inductive "r^*"
wenzelm@12691
    24
  intros
berghofe@12823
    25
    rtrancl_refl [intro!, CPure.intro!, simp]: "(a, a) : r^*"
berghofe@12823
    26
    rtrancl_into_rtrancl [CPure.intro]: "(a, b) : r^* ==> (b, c) : r ==> (a, c) : r^*"
berghofe@11327
    27
berghofe@13704
    28
consts
wenzelm@12691
    29
  trancl :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_^+)" [1000] 999)
berghofe@13704
    30
berghofe@13704
    31
inductive "r^+"
berghofe@13704
    32
  intros
berghofe@13704
    33
    r_into_trancl [intro, CPure.intro]: "(a, b) : r ==> (a, b) : r^+"
berghofe@13704
    34
    trancl_into_trancl [CPure.intro]: "(a, b) : r^+ ==> (b, c) : r ==> (a,c) : r^+"
nipkow@10213
    35
nipkow@10213
    36
syntax
wenzelm@12691
    37
  "_reflcl" :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_^=)" [1000] 999)
nipkow@10213
    38
translations
wenzelm@12691
    39
  "r^=" == "r \<union> Id"
nipkow@10213
    40
wenzelm@10827
    41
syntax (xsymbols)
wenzelm@12691
    42
  rtrancl :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_\\<^sup>*)" [1000] 999)
wenzelm@12691
    43
  trancl :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_\\<^sup>+)" [1000] 999)
wenzelm@12691
    44
  "_reflcl" :: "('a \<times> 'a) set => ('a \<times> 'a) set"    ("(_\\<^sup>=)" [1000] 999)
wenzelm@12691
    45
wenzelm@12691
    46
wenzelm@12691
    47
subsection {* Reflexive-transitive closure *}
wenzelm@12691
    48
wenzelm@12691
    49
lemma r_into_rtrancl [intro]: "!!p. p \<in> r ==> p \<in> r^*"
wenzelm@12691
    50
  -- {* @{text rtrancl} of @{text r} contains @{text r} *}
wenzelm@12691
    51
  apply (simp only: split_tupled_all)
wenzelm@12691
    52
  apply (erule rtrancl_refl [THEN rtrancl_into_rtrancl])
wenzelm@12691
    53
  done
wenzelm@12691
    54
wenzelm@12691
    55
lemma rtrancl_mono: "r \<subseteq> s ==> r^* \<subseteq> s^*"
wenzelm@12691
    56
  -- {* monotonicity of @{text rtrancl} *}
wenzelm@12691
    57
  apply (rule subsetI)
wenzelm@12691
    58
  apply (simp only: split_tupled_all)
wenzelm@12691
    59
  apply (erule rtrancl.induct)
wenzelm@12691
    60
   apply (rule_tac [2] rtrancl_into_rtrancl)
wenzelm@12691
    61
    apply blast+
wenzelm@12691
    62
  done
wenzelm@12691
    63
berghofe@12823
    64
theorem rtrancl_induct [consumes 1, induct set: rtrancl]:
wenzelm@12937
    65
  assumes a: "(a, b) : r^*"
wenzelm@12937
    66
    and cases: "P a" "!!y z. [| (a, y) : r^*; (y, z) : r; P y |] ==> P z"
wenzelm@12937
    67
  shows "P b"
wenzelm@12691
    68
proof -
wenzelm@12691
    69
  from a have "a = a --> P b"
berghofe@12823
    70
    by (induct "%x y. x = a --> P y" a b) (rules intro: cases)+
wenzelm@12691
    71
  thus ?thesis by rules
wenzelm@12691
    72
qed
wenzelm@12691
    73
wenzelm@12691
    74
ML_setup {*
wenzelm@12691
    75
  bind_thm ("rtrancl_induct2", split_rule
wenzelm@12691
    76
    (read_instantiate [("a","(ax,ay)"), ("b","(bx,by)")] (thm "rtrancl_induct")));
wenzelm@12691
    77
*}
wenzelm@12691
    78
wenzelm@12691
    79
lemma trans_rtrancl: "trans(r^*)"
wenzelm@12691
    80
  -- {* transitivity of transitive closure!! -- by induction *}
berghofe@12823
    81
proof (rule transI)
berghofe@12823
    82
  fix x y z
berghofe@12823
    83
  assume "(x, y) \<in> r\<^sup>*"
berghofe@12823
    84
  assume "(y, z) \<in> r\<^sup>*"
berghofe@12823
    85
  thus "(x, z) \<in> r\<^sup>*" by induct (rules!)+
berghofe@12823
    86
qed
wenzelm@12691
    87
wenzelm@12691
    88
lemmas rtrancl_trans = trans_rtrancl [THEN transD, standard]
wenzelm@12691
    89
wenzelm@12691
    90
lemma rtranclE:
wenzelm@12691
    91
  "[| (a::'a,b) : r^*;  (a = b) ==> P;
wenzelm@12691
    92
      !!y.[| (a,y) : r^*; (y,b) : r |] ==> P
wenzelm@12691
    93
   |] ==> P"
wenzelm@12691
    94
  -- {* elimination of @{text rtrancl} -- by induction on a special formula *}
wenzelm@12691
    95
proof -
wenzelm@12691
    96
  assume major: "(a::'a,b) : r^*"
wenzelm@12691
    97
  case rule_context
wenzelm@12691
    98
  show ?thesis
wenzelm@12691
    99
    apply (subgoal_tac "(a::'a) = b | (EX y. (a,y) : r^* & (y,b) : r)")
wenzelm@12691
   100
     apply (rule_tac [2] major [THEN rtrancl_induct])
wenzelm@12691
   101
      prefer 2 apply (blast!)
wenzelm@12691
   102
      prefer 2 apply (blast!)
wenzelm@12691
   103
    apply (erule asm_rl exE disjE conjE prems)+
wenzelm@12691
   104
    done
wenzelm@12691
   105
qed
wenzelm@12691
   106
berghofe@12823
   107
lemma converse_rtrancl_into_rtrancl:
berghofe@12823
   108
  "(a, b) \<in> r \<Longrightarrow> (b, c) \<in> r\<^sup>* \<Longrightarrow> (a, c) \<in> r\<^sup>*"
berghofe@12823
   109
  by (rule rtrancl_trans) rules+
wenzelm@12691
   110
wenzelm@12691
   111
text {*
wenzelm@12691
   112
  \medskip More @{term "r^*"} equations and inclusions.
wenzelm@12691
   113
*}
wenzelm@12691
   114
wenzelm@12691
   115
lemma rtrancl_idemp [simp]: "(r^*)^* = r^*"
wenzelm@12691
   116
  apply auto
wenzelm@12691
   117
  apply (erule rtrancl_induct)
wenzelm@12691
   118
   apply (rule rtrancl_refl)
wenzelm@12691
   119
  apply (blast intro: rtrancl_trans)
wenzelm@12691
   120
  done
wenzelm@12691
   121
wenzelm@12691
   122
lemma rtrancl_idemp_self_comp [simp]: "R^* O R^* = R^*"
wenzelm@12691
   123
  apply (rule set_ext)
wenzelm@12691
   124
  apply (simp only: split_tupled_all)
wenzelm@12691
   125
  apply (blast intro: rtrancl_trans)
wenzelm@12691
   126
  done
wenzelm@12691
   127
wenzelm@12691
   128
lemma rtrancl_subset_rtrancl: "r \<subseteq> s^* ==> r^* \<subseteq> s^*"
wenzelm@12691
   129
  apply (drule rtrancl_mono)
wenzelm@12691
   130
  apply simp
wenzelm@12691
   131
  done
wenzelm@12691
   132
wenzelm@12691
   133
lemma rtrancl_subset: "R \<subseteq> S ==> S \<subseteq> R^* ==> S^* = R^*"
wenzelm@12691
   134
  apply (drule rtrancl_mono)
wenzelm@12691
   135
  apply (drule rtrancl_mono)
wenzelm@12691
   136
  apply simp
wenzelm@12691
   137
  apply blast
wenzelm@12691
   138
  done
wenzelm@12691
   139
wenzelm@12691
   140
lemma rtrancl_Un_rtrancl: "(R^* \<union> S^*)^* = (R \<union> S)^*"
wenzelm@12691
   141
  by (blast intro!: rtrancl_subset intro: r_into_rtrancl rtrancl_mono [THEN subsetD])
wenzelm@12691
   142
wenzelm@12691
   143
lemma rtrancl_reflcl [simp]: "(R^=)^* = R^*"
wenzelm@12691
   144
  by (blast intro!: rtrancl_subset intro: r_into_rtrancl)
wenzelm@12691
   145
wenzelm@12691
   146
lemma rtrancl_r_diff_Id: "(r - Id)^* = r^*"
wenzelm@12691
   147
  apply (rule sym)
wenzelm@12691
   148
  apply (rule rtrancl_subset)
wenzelm@12691
   149
   apply blast
wenzelm@12691
   150
  apply clarify
wenzelm@12691
   151
  apply (rename_tac a b)
wenzelm@12691
   152
  apply (case_tac "a = b")
wenzelm@12691
   153
   apply blast
wenzelm@12691
   154
  apply (blast intro!: r_into_rtrancl)
wenzelm@12691
   155
  done
wenzelm@12691
   156
berghofe@12823
   157
theorem rtrancl_converseD:
wenzelm@12937
   158
  assumes r: "(x, y) \<in> (r^-1)^*"
wenzelm@12937
   159
  shows "(y, x) \<in> r^*"
berghofe@12823
   160
proof -
berghofe@12823
   161
  from r show ?thesis
berghofe@12823
   162
    by induct (rules intro: rtrancl_trans dest!: converseD)+
berghofe@12823
   163
qed
wenzelm@12691
   164
berghofe@12823
   165
theorem rtrancl_converseI:
wenzelm@12937
   166
  assumes r: "(y, x) \<in> r^*"
wenzelm@12937
   167
  shows "(x, y) \<in> (r^-1)^*"
berghofe@12823
   168
proof -
berghofe@12823
   169
  from r show ?thesis
berghofe@12823
   170
    by induct (rules intro: rtrancl_trans converseI)+
berghofe@12823
   171
qed
wenzelm@12691
   172
wenzelm@12691
   173
lemma rtrancl_converse: "(r^-1)^* = (r^*)^-1"
wenzelm@12691
   174
  by (fast dest!: rtrancl_converseD intro!: rtrancl_converseI)
wenzelm@12691
   175
berghofe@12823
   176
theorem converse_rtrancl_induct:
wenzelm@12937
   177
  assumes major: "(a, b) : r^*"
wenzelm@12937
   178
    and cases: "P b" "!!y z. [| (y, z) : r; (z, b) : r^*; P z |] ==> P y"
wenzelm@12937
   179
  shows "P a"
wenzelm@12691
   180
proof -
berghofe@12823
   181
  from rtrancl_converseI [OF major]
wenzelm@12691
   182
  show ?thesis
berghofe@12823
   183
    by induct (rules intro: cases dest!: converseD rtrancl_converseD)+
wenzelm@12691
   184
qed
wenzelm@12691
   185
wenzelm@12691
   186
ML_setup {*
wenzelm@12691
   187
  bind_thm ("converse_rtrancl_induct2", split_rule
wenzelm@12691
   188
    (read_instantiate [("a","(ax,ay)"),("b","(bx,by)")] (thm "converse_rtrancl_induct")));
wenzelm@12691
   189
*}
wenzelm@12691
   190
wenzelm@12691
   191
lemma converse_rtranclE:
wenzelm@12691
   192
  "[| (x,z):r^*;
wenzelm@12691
   193
      x=z ==> P;
wenzelm@12691
   194
      !!y. [| (x,y):r; (y,z):r^* |] ==> P
wenzelm@12691
   195
   |] ==> P"
wenzelm@12691
   196
proof -
wenzelm@12691
   197
  assume major: "(x,z):r^*"
wenzelm@12691
   198
  case rule_context
wenzelm@12691
   199
  show ?thesis
wenzelm@12691
   200
    apply (subgoal_tac "x = z | (EX y. (x,y) : r & (y,z) : r^*)")
wenzelm@12691
   201
     apply (rule_tac [2] major [THEN converse_rtrancl_induct])
berghofe@13726
   202
      prefer 2 apply rules
berghofe@13726
   203
     prefer 2 apply rules
wenzelm@12691
   204
    apply (erule asm_rl exE disjE conjE prems)+
wenzelm@12691
   205
    done
wenzelm@12691
   206
qed
wenzelm@12691
   207
wenzelm@12691
   208
ML_setup {*
wenzelm@12691
   209
  bind_thm ("converse_rtranclE2", split_rule
wenzelm@12691
   210
    (read_instantiate [("x","(xa,xb)"), ("z","(za,zb)")] (thm "converse_rtranclE")));
wenzelm@12691
   211
*}
wenzelm@12691
   212
wenzelm@12691
   213
lemma r_comp_rtrancl_eq: "r O r^* = r^* O r"
wenzelm@12691
   214
  by (blast elim: rtranclE converse_rtranclE
wenzelm@12691
   215
    intro: rtrancl_into_rtrancl converse_rtrancl_into_rtrancl)
wenzelm@12691
   216
wenzelm@12691
   217
wenzelm@12691
   218
subsection {* Transitive closure *}
wenzelm@10331
   219
berghofe@13704
   220
lemma trancl_mono: "!!p. p \<in> r^+ ==> r \<subseteq> s ==> p \<in> s^+"
berghofe@13704
   221
  apply (simp only: split_tupled_all)
berghofe@13704
   222
  apply (erule trancl.induct)
berghofe@13704
   223
  apply (rules dest: subsetD)+
wenzelm@12691
   224
  done
wenzelm@12691
   225
berghofe@13704
   226
lemma r_into_trancl': "!!p. p : r ==> p : r^+"
berghofe@13704
   227
  by (simp only: split_tupled_all) (erule r_into_trancl)
berghofe@13704
   228
wenzelm@12691
   229
text {*
wenzelm@12691
   230
  \medskip Conversions between @{text trancl} and @{text rtrancl}.
wenzelm@12691
   231
*}
wenzelm@12691
   232
berghofe@13704
   233
lemma trancl_into_rtrancl: "(a, b) \<in> r^+ ==> (a, b) \<in> r^*"
berghofe@13704
   234
  by (erule trancl.induct) rules+
wenzelm@12691
   235
berghofe@13704
   236
lemma rtrancl_into_trancl1: assumes r: "(a, b) \<in> r^*"
berghofe@13704
   237
  shows "!!c. (b, c) \<in> r ==> (a, c) \<in> r^+" using r
berghofe@13704
   238
  by induct rules+
wenzelm@12691
   239
wenzelm@12691
   240
lemma rtrancl_into_trancl2: "[| (a,b) : r;  (b,c) : r^* |]   ==>  (a,c) : r^+"
wenzelm@12691
   241
  -- {* intro rule from @{text r} and @{text rtrancl} *}
wenzelm@12691
   242
  apply (erule rtranclE)
berghofe@13704
   243
   apply rules
wenzelm@12691
   244
  apply (rule rtrancl_trans [THEN rtrancl_into_trancl1])
wenzelm@12691
   245
   apply (assumption | rule r_into_rtrancl)+
wenzelm@12691
   246
  done
wenzelm@12691
   247
berghofe@13704
   248
lemma trancl_induct [consumes 1, induct set: trancl]:
berghofe@13704
   249
  assumes a: "(a,b) : r^+"
berghofe@13704
   250
  and cases: "!!y. (a, y) : r ==> P y"
berghofe@13704
   251
    "!!y z. (a,y) : r^+ ==> (y, z) : r ==> P y ==> P z"
berghofe@13704
   252
  shows "P b"
wenzelm@12691
   253
  -- {* Nice induction rule for @{text trancl} *}
wenzelm@12691
   254
proof -
berghofe@13704
   255
  from a have "a = a --> P b"
berghofe@13704
   256
    by (induct "%x y. x = a --> P y" a b) (rules intro: cases)+
berghofe@13704
   257
  thus ?thesis by rules
wenzelm@12691
   258
qed
wenzelm@12691
   259
wenzelm@12691
   260
lemma trancl_trans_induct:
wenzelm@12691
   261
  "[| (x,y) : r^+;
wenzelm@12691
   262
      !!x y. (x,y) : r ==> P x y;
wenzelm@12691
   263
      !!x y z. [| (x,y) : r^+; P x y; (y,z) : r^+; P y z |] ==> P x z
wenzelm@12691
   264
   |] ==> P x y"
wenzelm@12691
   265
  -- {* Another induction rule for trancl, incorporating transitivity *}
wenzelm@12691
   266
proof -
wenzelm@12691
   267
  assume major: "(x,y) : r^+"
wenzelm@12691
   268
  case rule_context
wenzelm@12691
   269
  show ?thesis
berghofe@13704
   270
    by (rules intro: r_into_trancl major [THEN trancl_induct] prems)
wenzelm@12691
   271
qed
wenzelm@12691
   272
berghofe@13704
   273
inductive_cases tranclE: "(a, b) : r^+"
wenzelm@10980
   274
wenzelm@12691
   275
lemma trans_trancl: "trans(r^+)"
wenzelm@12691
   276
  -- {* Transitivity of @{term "r^+"} *}
berghofe@13704
   277
proof (rule transI)
berghofe@13704
   278
  fix x y z
berghofe@13704
   279
  assume "(x, y) \<in> r^+"
berghofe@13704
   280
  assume "(y, z) \<in> r^+"
berghofe@13704
   281
  thus "(x, z) \<in> r^+" by induct (rules!)+
berghofe@13704
   282
qed
wenzelm@12691
   283
wenzelm@12691
   284
lemmas trancl_trans = trans_trancl [THEN transD, standard]
wenzelm@12691
   285
berghofe@13704
   286
lemma rtrancl_trancl_trancl: assumes r: "(x, y) \<in> r^*"
berghofe@13704
   287
  shows "!!z. (y, z) \<in> r^+ ==> (x, z) \<in> r^+" using r
berghofe@13704
   288
  by induct (rules intro: trancl_trans)+
wenzelm@12691
   289
wenzelm@12691
   290
lemma trancl_into_trancl2: "(a, b) \<in> r ==> (b, c) \<in> r^+ ==> (a, c) \<in> r^+"
wenzelm@12691
   291
  by (erule transD [OF trans_trancl r_into_trancl])
wenzelm@12691
   292
wenzelm@12691
   293
lemma trancl_insert:
wenzelm@12691
   294
  "(insert (y, x) r)^+ = r^+ \<union> {(a, b). (a, y) \<in> r^* \<and> (x, b) \<in> r^*}"
wenzelm@12691
   295
  -- {* primitive recursion for @{text trancl} over finite relations *}
wenzelm@12691
   296
  apply (rule equalityI)
wenzelm@12691
   297
   apply (rule subsetI)
wenzelm@12691
   298
   apply (simp only: split_tupled_all)
wenzelm@12691
   299
   apply (erule trancl_induct)
wenzelm@12691
   300
    apply blast
wenzelm@12691
   301
   apply (blast intro: rtrancl_into_trancl1 trancl_into_rtrancl r_into_trancl trancl_trans)
wenzelm@12691
   302
  apply (rule subsetI)
wenzelm@12691
   303
  apply (blast intro: trancl_mono rtrancl_mono
wenzelm@12691
   304
    [THEN [2] rev_subsetD] rtrancl_trancl_trancl rtrancl_into_trancl2)
wenzelm@12691
   305
  done
wenzelm@12691
   306
berghofe@13704
   307
lemma trancl_converseI: "(x, y) \<in> (r^+)^-1 ==> (x, y) \<in> (r^-1)^+"
berghofe@13704
   308
  apply (drule converseD)
berghofe@13704
   309
  apply (erule trancl.induct)
berghofe@13704
   310
  apply (rules intro: converseI trancl_trans)+
wenzelm@12691
   311
  done
wenzelm@12691
   312
berghofe@13704
   313
lemma trancl_converseD: "(x, y) \<in> (r^-1)^+ ==> (x, y) \<in> (r^+)^-1"
berghofe@13704
   314
  apply (rule converseI)
berghofe@13704
   315
  apply (erule trancl.induct)
berghofe@13704
   316
  apply (rules dest: converseD intro: trancl_trans)+
berghofe@13704
   317
  done
wenzelm@12691
   318
berghofe@13704
   319
lemma trancl_converse: "(r^-1)^+ = (r^+)^-1"
berghofe@13704
   320
  by (fastsimp simp add: split_tupled_all
berghofe@13704
   321
    intro!: trancl_converseI trancl_converseD)
wenzelm@12691
   322
wenzelm@12691
   323
lemma converse_trancl_induct:
wenzelm@12691
   324
  "[| (a,b) : r^+; !!y. (y,b) : r ==> P(y);
wenzelm@12691
   325
      !!y z.[| (y,z) : r;  (z,b) : r^+;  P(z) |] ==> P(y) |]
wenzelm@12691
   326
    ==> P(a)"
wenzelm@12691
   327
proof -
wenzelm@12691
   328
  assume major: "(a,b) : r^+"
wenzelm@12691
   329
  case rule_context
wenzelm@12691
   330
  show ?thesis
wenzelm@12691
   331
    apply (rule major [THEN converseI, THEN trancl_converseI [THEN trancl_induct]])
wenzelm@12691
   332
     apply (rule prems)
wenzelm@12691
   333
     apply (erule converseD)
wenzelm@12691
   334
    apply (blast intro: prems dest!: trancl_converseD)
wenzelm@12691
   335
    done
wenzelm@12691
   336
qed
wenzelm@12691
   337
wenzelm@12691
   338
lemma tranclD: "(x, y) \<in> R^+ ==> EX z. (x, z) \<in> R \<and> (z, y) \<in> R^*"
wenzelm@12691
   339
  apply (erule converse_trancl_induct)
wenzelm@12691
   340
   apply auto
wenzelm@12691
   341
  apply (blast intro: rtrancl_trans)
wenzelm@12691
   342
  done
wenzelm@12691
   343
wenzelm@12691
   344
lemma irrefl_tranclI: "r^-1 \<inter> r^+ = {} ==> (x, x) \<notin> r^+"
wenzelm@12691
   345
  apply (subgoal_tac "ALL y. (x, y) : r^+ --> x \<noteq> y")
wenzelm@12691
   346
   apply fast
wenzelm@12691
   347
  apply (intro strip)
wenzelm@12691
   348
  apply (erule trancl_induct)
wenzelm@12691
   349
   apply (auto intro: r_into_trancl)
wenzelm@12691
   350
  done
wenzelm@12691
   351
wenzelm@12691
   352
lemma irrefl_trancl_rD: "!!X. ALL x. (x, x) \<notin> r^+ ==> (x, y) \<in> r ==> x \<noteq> y"
wenzelm@12691
   353
  by (blast dest: r_into_trancl)
wenzelm@12691
   354
wenzelm@12691
   355
lemma trancl_subset_Sigma_aux:
wenzelm@12691
   356
    "(a, b) \<in> r^* ==> r \<subseteq> A \<times> A ==> a = b \<or> a \<in> A"
wenzelm@12691
   357
  apply (erule rtrancl_induct)
wenzelm@12691
   358
   apply auto
wenzelm@12691
   359
  done
wenzelm@12691
   360
wenzelm@12691
   361
lemma trancl_subset_Sigma: "r \<subseteq> A \<times> A ==> r^+ \<subseteq> A \<times> A"
berghofe@13704
   362
  apply (rule subsetI)
berghofe@13704
   363
  apply (simp only: split_tupled_all)
berghofe@13704
   364
  apply (erule tranclE)
berghofe@13704
   365
  apply (blast dest!: trancl_into_rtrancl trancl_subset_Sigma_aux)+
wenzelm@12691
   366
  done
nipkow@10996
   367
wenzelm@11090
   368
lemma reflcl_trancl [simp]: "(r^+)^= = r^*"
wenzelm@11084
   369
  apply safe
wenzelm@12691
   370
   apply (erule trancl_into_rtrancl)
wenzelm@11084
   371
  apply (blast elim: rtranclE dest: rtrancl_into_trancl1)
wenzelm@11084
   372
  done
nipkow@10996
   373
wenzelm@11090
   374
lemma trancl_reflcl [simp]: "(r^=)^+ = r^*"
wenzelm@11084
   375
  apply safe
wenzelm@11084
   376
   apply (drule trancl_into_rtrancl)
wenzelm@11084
   377
   apply simp
wenzelm@11084
   378
  apply (erule rtranclE)
wenzelm@11084
   379
   apply safe
wenzelm@11084
   380
   apply (rule r_into_trancl)
wenzelm@11084
   381
   apply simp
wenzelm@11084
   382
  apply (rule rtrancl_into_trancl1)
wenzelm@11084
   383
   apply (erule rtrancl_reflcl [THEN equalityD2, THEN subsetD])
wenzelm@11084
   384
  apply fast
wenzelm@11084
   385
  done
nipkow@10996
   386
wenzelm@11090
   387
lemma trancl_empty [simp]: "{}^+ = {}"
wenzelm@11084
   388
  by (auto elim: trancl_induct)
nipkow@10996
   389
wenzelm@11090
   390
lemma rtrancl_empty [simp]: "{}^* = Id"
wenzelm@11084
   391
  by (rule subst [OF reflcl_trancl]) simp
nipkow@10996
   392
wenzelm@11090
   393
lemma rtranclD: "(a, b) \<in> R^* ==> a = b \<or> a \<noteq> b \<and> (a, b) \<in> R^+"
wenzelm@11084
   394
  by (force simp add: reflcl_trancl [symmetric] simp del: reflcl_trancl)
wenzelm@11084
   395
nipkow@10996
   396
wenzelm@12691
   397
text {* @{text Domain} and @{text Range} *}
nipkow@10996
   398
wenzelm@11090
   399
lemma Domain_rtrancl [simp]: "Domain (R^*) = UNIV"
wenzelm@11084
   400
  by blast
nipkow@10996
   401
wenzelm@11090
   402
lemma Range_rtrancl [simp]: "Range (R^*) = UNIV"
wenzelm@11084
   403
  by blast
nipkow@10996
   404
wenzelm@11090
   405
lemma rtrancl_Un_subset: "(R^* \<union> S^*) \<subseteq> (R Un S)^*"
wenzelm@11084
   406
  by (rule rtrancl_Un_rtrancl [THEN subst]) fast
nipkow@10996
   407
wenzelm@11090
   408
lemma in_rtrancl_UnI: "x \<in> R^* \<or> x \<in> S^* ==> x \<in> (R \<union> S)^*"
wenzelm@11084
   409
  by (blast intro: subsetD [OF rtrancl_Un_subset])
nipkow@10996
   410
wenzelm@11090
   411
lemma trancl_domain [simp]: "Domain (r^+) = Domain r"
wenzelm@11084
   412
  by (unfold Domain_def) (blast dest: tranclD)
nipkow@10996
   413
wenzelm@11090
   414
lemma trancl_range [simp]: "Range (r^+) = Range r"
wenzelm@11084
   415
  by (simp add: Range_def trancl_converse [symmetric])
nipkow@10996
   416
paulson@11115
   417
lemma Not_Domain_rtrancl:
wenzelm@12691
   418
    "x ~: Domain R ==> ((x, y) : R^*) = (x = y)"
wenzelm@12691
   419
  apply auto
wenzelm@12691
   420
  by (erule rev_mp, erule rtrancl_induct, auto)
wenzelm@12691
   421
berghofe@11327
   422
wenzelm@12691
   423
text {* More about converse @{text rtrancl} and @{text trancl}, should
wenzelm@12691
   424
  be merged with main body. *}
kleing@12428
   425
wenzelm@12691
   426
lemma r_r_into_trancl: "(a, b) \<in> R ==> (b, c) \<in> R ==> (a, c) \<in> R^+"
kleing@12428
   427
  by (fast intro: trancl_trans)
kleing@12428
   428
kleing@12428
   429
lemma trancl_into_trancl [rule_format]:
wenzelm@12691
   430
    "(a, b) \<in> r\<^sup>+ ==> (b, c) \<in> r --> (a,c) \<in> r\<^sup>+"
wenzelm@12691
   431
  apply (erule trancl_induct)
kleing@12428
   432
   apply (fast intro: r_r_into_trancl)
kleing@12428
   433
  apply (fast intro: r_r_into_trancl trancl_trans)
kleing@12428
   434
  done
kleing@12428
   435
kleing@12428
   436
lemma trancl_rtrancl_trancl:
wenzelm@12691
   437
    "(a, b) \<in> r\<^sup>+ ==> (b, c) \<in> r\<^sup>* ==> (a, c) \<in> r\<^sup>+"
kleing@12428
   438
  apply (drule tranclD)
kleing@12428
   439
  apply (erule exE, erule conjE)
kleing@12428
   440
  apply (drule rtrancl_trans, assumption)
kleing@12428
   441
  apply (drule rtrancl_into_trancl2, assumption)
kleing@12428
   442
  apply assumption
kleing@12428
   443
  done
kleing@12428
   444
wenzelm@12691
   445
lemmas transitive_closure_trans [trans] =
wenzelm@12691
   446
  r_r_into_trancl trancl_trans rtrancl_trans
wenzelm@12691
   447
  trancl_into_trancl trancl_into_trancl2
wenzelm@12691
   448
  rtrancl_into_rtrancl converse_rtrancl_into_rtrancl
wenzelm@12691
   449
  rtrancl_trancl_trancl trancl_rtrancl_trancl
kleing@12428
   450
kleing@12428
   451
declare trancl_into_rtrancl [elim]
berghofe@11327
   452
berghofe@11327
   453
declare rtranclE [cases set: rtrancl]
berghofe@11327
   454
declare tranclE [cases set: trancl]
berghofe@11327
   455
nipkow@10213
   456
end