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