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