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