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