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