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