src/HOL/Transitive_Closure.thy
changeset 30954 cf50e67bc1d1
parent 30549 d2d7874648bd
child 30971 7fbebf75b3ef
     1.1 --- a/src/HOL/Transitive_Closure.thy	Mon Apr 20 09:32:09 2009 +0200
     1.2 +++ b/src/HOL/Transitive_Closure.thy	Mon Apr 20 09:32:40 2009 +0200
     1.3 @@ -630,6 +630,139 @@
     1.4  
     1.5  declare trancl_into_rtrancl [elim]
     1.6  
     1.7 +subsection {* The power operation on relations *}
     1.8 +
     1.9 +text {* @{text "R ^^ n = R O ... O R"}, the n-fold composition of @{text R} *}
    1.10 +
    1.11 +primrec relpow :: "('a \<times> 'a) set \<Rightarrow> nat \<Rightarrow> ('a \<times> 'a) set" (infixr "^^" 80) where
    1.12 +    "R ^^ 0 = Id"
    1.13 +  | "R ^^ Suc n = R O (R ^^ n)"
    1.14 +
    1.15 +notation (latex output)
    1.16 +  relpow ("(_\<^bsup>_\<^esup>)" [1000] 1000)
    1.17 +
    1.18 +notation (HTML output)
    1.19 +  relpow ("(_\<^bsup>_\<^esup>)" [1000] 1000)
    1.20 +
    1.21 +lemma rel_pow_1 [simp]:
    1.22 +  "R ^^ 1 = R"
    1.23 +  by simp
    1.24 +
    1.25 +lemma rel_pow_0_I: 
    1.26 +  "(x, x) \<in> R ^^ 0"
    1.27 +  by simp
    1.28 +
    1.29 +lemma rel_pow_Suc_I:
    1.30 +  "(x, y) \<in>  R ^^ n \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> (x, z) \<in> R ^^ Suc n"
    1.31 +  by auto
    1.32 +
    1.33 +lemma rel_pow_Suc_I2:
    1.34 +  "(x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ n \<Longrightarrow> (x, z) \<in> R ^^ Suc n"
    1.35 +  by (induct n arbitrary: z) (simp, fastsimp)
    1.36 +
    1.37 +lemma rel_pow_0_E:
    1.38 +  "(x, y) \<in> R ^^ 0 \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> P"
    1.39 +  by simp
    1.40 +
    1.41 +lemma rel_pow_Suc_E:
    1.42 +  "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<And>y. (x, y) \<in> R ^^ n \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> P) \<Longrightarrow> P"
    1.43 +  by auto
    1.44 +
    1.45 +lemma rel_pow_E:
    1.46 +  "(x, z) \<in>  R ^^ n \<Longrightarrow>  (n = 0 \<Longrightarrow> x = z \<Longrightarrow> P)
    1.47 +   \<Longrightarrow> (\<And>y m. n = Suc m \<Longrightarrow> (x, y) \<in>  R ^^ m \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> P)
    1.48 +   \<Longrightarrow> P"
    1.49 +  by (cases n) auto
    1.50 +
    1.51 +lemma rel_pow_Suc_D2:
    1.52 +  "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<exists>y. (x, y) \<in> R \<and> (y, z) \<in> R ^^ n)"
    1.53 +  apply (induct n arbitrary: x z)
    1.54 +   apply (blast intro: rel_pow_0_I elim: rel_pow_0_E rel_pow_Suc_E)
    1.55 +  apply (blast intro: rel_pow_Suc_I elim: rel_pow_0_E rel_pow_Suc_E)
    1.56 +  done
    1.57 +
    1.58 +lemma rel_pow_Suc_E2:
    1.59 +  "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<And>y. (x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ n \<Longrightarrow> P) \<Longrightarrow> P"
    1.60 +  by (blast dest: rel_pow_Suc_D2)
    1.61 +
    1.62 +lemma rel_pow_Suc_D2':
    1.63 +  "\<forall>x y z. (x, y) \<in> R ^^ n \<and> (y, z) \<in> R \<longrightarrow> (\<exists>w. (x, w) \<in> R \<and> (w, z) \<in> R ^^ n)"
    1.64 +  by (induct n) (simp_all, blast)
    1.65 +
    1.66 +lemma rel_pow_E2:
    1.67 +  "(x, z) \<in> R ^^ n \<Longrightarrow>  (n = 0 \<Longrightarrow> x = z \<Longrightarrow> P)
    1.68 +     \<Longrightarrow> (\<And>y m. n = Suc m \<Longrightarrow> (x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ m \<Longrightarrow> P)
    1.69 +   \<Longrightarrow> P"
    1.70 +  apply (cases n, simp)
    1.71 +  apply (cut_tac n=nat and R=R in rel_pow_Suc_D2', simp, blast)
    1.72 +  done
    1.73 +
    1.74 +lemma rtrancl_imp_UN_rel_pow:
    1.75 +  assumes "p \<in> R^*"
    1.76 +  shows "p \<in> (\<Union>n. R ^^ n)"
    1.77 +proof (cases p)
    1.78 +  case (Pair x y)
    1.79 +  with assms have "(x, y) \<in> R^*" by simp
    1.80 +  then have "(x, y) \<in> (\<Union>n. R ^^ n)" proof induct
    1.81 +    case base show ?case by (blast intro: rel_pow_0_I)
    1.82 +  next
    1.83 +    case step then show ?case by (blast intro: rel_pow_Suc_I)
    1.84 +  qed
    1.85 +  with Pair show ?thesis by simp
    1.86 +qed
    1.87 +
    1.88 +lemma rel_pow_imp_rtrancl:
    1.89 +  assumes "p \<in> R ^^ n"
    1.90 +  shows "p \<in> R^*"
    1.91 +proof (cases p)
    1.92 +  case (Pair x y)
    1.93 +  with assms have "(x, y) \<in> R ^^ n" by simp
    1.94 +  then have "(x, y) \<in> R^*" proof (induct n arbitrary: x y)
    1.95 +    case 0 then show ?case by simp
    1.96 +  next
    1.97 +    case Suc then show ?case
    1.98 +      by (blast elim: rel_pow_Suc_E intro: rtrancl_into_rtrancl)
    1.99 +  qed
   1.100 +  with Pair show ?thesis by simp
   1.101 +qed
   1.102 +
   1.103 +lemma rtrancl_is_UN_rel_pow:
   1.104 +  "R^* = (\<Union>n. R ^^ n)"
   1.105 +  by (blast intro: rtrancl_imp_UN_rel_pow rel_pow_imp_rtrancl)
   1.106 +
   1.107 +lemma rtrancl_power:
   1.108 +  "p \<in> R^* \<longleftrightarrow> (\<exists>n. p \<in> R ^^ n)"
   1.109 +  by (simp add: rtrancl_is_UN_rel_pow)
   1.110 +
   1.111 +lemma trancl_power:
   1.112 +  "p \<in> R^+ \<longleftrightarrow> (\<exists>n > 0. p \<in> R ^^ n)"
   1.113 +  apply (cases p)
   1.114 +  apply simp
   1.115 +  apply (rule iffI)
   1.116 +   apply (drule tranclD2)
   1.117 +   apply (clarsimp simp: rtrancl_is_UN_rel_pow)
   1.118 +   apply (rule_tac x="Suc x" in exI)
   1.119 +   apply (clarsimp simp: rel_comp_def)
   1.120 +   apply fastsimp
   1.121 +  apply clarsimp
   1.122 +  apply (case_tac n, simp)
   1.123 +  apply clarsimp
   1.124 +  apply (drule rel_pow_imp_rtrancl)
   1.125 +  apply (drule rtrancl_into_trancl1) apply auto
   1.126 +  done
   1.127 +
   1.128 +lemma rtrancl_imp_rel_pow:
   1.129 +  "p \<in> R^* \<Longrightarrow> \<exists>n. p \<in> R ^^ n"
   1.130 +  by (auto dest: rtrancl_imp_UN_rel_pow)
   1.131 +
   1.132 +lemma single_valued_rel_pow:
   1.133 +  fixes R :: "('a * 'a) set"
   1.134 +  shows "single_valued R \<Longrightarrow> single_valued (R ^^ n)"
   1.135 +  apply (induct n arbitrary: R)
   1.136 +  apply simp_all
   1.137 +  apply (rule single_valuedI)
   1.138 +  apply (fast dest: single_valuedD elim: rel_pow_Suc_E)
   1.139 +  done
   1.140  
   1.141  subsection {* Setup of transitivity reasoner *}
   1.142