src/HOL/Relation_Power.thy
author haftmann
Mon Aug 14 13:46:06 2006 +0200 (2006-08-14)
changeset 20380 14f9f2a1caa6
parent 18398 5d63a8b35688
child 20503 503ac4c5ef91
permissions -rw-r--r--
simplified code generator setup
nipkow@10213
     1
(*  Title:      HOL/Relation_Power.thy
nipkow@10213
     2
    ID:         $Id$
nipkow@10213
     3
    Author:     Tobias Nipkow
nipkow@10213
     4
    Copyright   1996  TU Muenchen
paulson@15410
     5
*)
nipkow@11306
     6
paulson@15410
     7
header{*Powers of Relations and Functions*}
nipkow@10213
     8
nipkow@15131
     9
theory Relation_Power
nipkow@15140
    10
imports Nat
nipkow@15131
    11
begin
nipkow@10213
    12
nipkow@10213
    13
instance
wenzelm@18398
    14
  set :: (type) power ..
paulson@15410
    15
      --{* only type @{typ "('a * 'a) set"} should be in class @{text power}!*}
nipkow@10213
    16
paulson@15410
    17
(*R^n = R O ... O R, the n-fold composition of R*)
nipkow@10213
    18
primrec (relpow)
nipkow@10213
    19
  "R^0 = Id"
nipkow@10213
    20
  "R^(Suc n) = R O (R^n)"
nipkow@10213
    21
nipkow@11305
    22
nipkow@11306
    23
instance
paulson@15410
    24
  fun :: (type, type) power ..
paulson@15410
    25
      --{* only type @{typ "'a => 'a"} should be in class @{text power}!*}
nipkow@11305
    26
paulson@15410
    27
(*f^n = f o ... o f, the n-fold composition of f*)
nipkow@11305
    28
primrec (funpow)
nipkow@11305
    29
  "f^0 = id"
nipkow@11305
    30
  "f^(Suc n) = f o (f^n)"
nipkow@11305
    31
paulson@15410
    32
text{*WARNING: due to the limits of Isabelle's type classes, exponentiation on
paulson@15410
    33
functions and relations has too general a domain, namely @{typ "('a * 'b)set"}
paulson@15410
    34
and @{typ "'a => 'b"}.  Explicit type constraints may therefore be necessary.
paulson@15410
    35
For example, @{term "range(f^n) = A"} and @{term "Range(R^n) = B"} need
paulson@15410
    36
constraints.*}
paulson@15410
    37
nipkow@15112
    38
lemma funpow_add: "f ^ (m+n) = f^m o f^n"
wenzelm@18398
    39
  by (induct m) simp_all
nipkow@15112
    40
nipkow@18049
    41
lemma funpow_swap1: "f((f^n) x) = (f^n)(f x)"
nipkow@18049
    42
proof -
nipkow@18049
    43
  have "f((f^n) x) = (f^(n+1)) x" by simp
wenzelm@18398
    44
  also have "\<dots>  = (f^n o f^1) x" by (simp only: funpow_add)
nipkow@18049
    45
  also have "\<dots> = (f^n)(f x)" by simp
nipkow@18049
    46
  finally show ?thesis .
nipkow@18049
    47
qed
nipkow@18049
    48
wenzelm@18398
    49
lemma rel_pow_1 [simp]:
wenzelm@18398
    50
  fixes R :: "('a*'a)set"
wenzelm@18398
    51
  shows "R^1 = R"
wenzelm@18398
    52
  by simp
paulson@15410
    53
paulson@15410
    54
lemma rel_pow_0_I: "(x,x) : R^0"
wenzelm@18398
    55
  by simp
paulson@15410
    56
paulson@15410
    57
lemma rel_pow_Suc_I: "[| (x,y) : R^n; (y,z):R |] ==> (x,z):R^(Suc n)"
wenzelm@18398
    58
  by auto
paulson@15410
    59
wenzelm@18398
    60
lemma rel_pow_Suc_I2:
wenzelm@18398
    61
    "(x, y) : R \<Longrightarrow> (y, z) : R^n \<Longrightarrow> (x,z) : R^(Suc n)"
wenzelm@18398
    62
  apply (induct n fixing: z)
wenzelm@18398
    63
   apply simp
wenzelm@18398
    64
  apply fastsimp
wenzelm@18398
    65
  done
paulson@15410
    66
paulson@15410
    67
lemma rel_pow_0_E: "[| (x,y) : R^0; x=y ==> P |] ==> P"
wenzelm@18398
    68
  by simp
paulson@15410
    69
wenzelm@18398
    70
lemma rel_pow_Suc_E:
wenzelm@18398
    71
    "[| (x,z) : R^(Suc n);  !!y. [| (x,y) : R^n; (y,z) : R |] ==> P |] ==> P"
wenzelm@18398
    72
  by auto
paulson@15410
    73
wenzelm@18398
    74
lemma rel_pow_E:
wenzelm@18398
    75
    "[| (x,z) : R^n;  [| n=0; x = z |] ==> P;
wenzelm@18398
    76
        !!y m. [| n = Suc m; (x,y) : R^m; (y,z) : R |] ==> P
paulson@15410
    77
     |] ==> P"
wenzelm@18398
    78
  by (cases n) auto
paulson@15410
    79
wenzelm@18398
    80
lemma rel_pow_Suc_D2:
wenzelm@18398
    81
    "(x, z) : R^(Suc n) \<Longrightarrow> (\<exists>y. (x,y) : R & (y,z) : R^n)"
wenzelm@18398
    82
  apply (induct n fixing: x z)
wenzelm@18398
    83
   apply (blast intro: rel_pow_0_I elim: rel_pow_0_E rel_pow_Suc_E)
wenzelm@18398
    84
  apply (blast intro: rel_pow_Suc_I elim: rel_pow_0_E rel_pow_Suc_E)
wenzelm@18398
    85
  done
paulson@15410
    86
paulson@15410
    87
lemma rel_pow_Suc_D2':
wenzelm@18398
    88
    "\<forall>x y z. (x,y) : R^n & (y,z) : R --> (\<exists>w. (x,w) : R & (w,z) : R^n)"
wenzelm@18398
    89
  by (induct n) (simp_all, blast)
paulson@15410
    90
wenzelm@18398
    91
lemma rel_pow_E2:
wenzelm@18398
    92
    "[| (x,z) : R^n;  [| n=0; x = z |] ==> P;
wenzelm@18398
    93
        !!y m. [| n = Suc m; (x,y) : R; (y,z) : R^m |] ==> P
paulson@15410
    94
     |] ==> P"
wenzelm@18398
    95
  apply (case_tac n, simp)
wenzelm@18398
    96
  apply (cut_tac n=nat and R=R in rel_pow_Suc_D2', simp, blast)
wenzelm@18398
    97
  done
paulson@15410
    98
paulson@15410
    99
lemma rtrancl_imp_UN_rel_pow: "!!p. p:R^* ==> p : (UN n. R^n)"
wenzelm@18398
   100
  apply (simp only: split_tupled_all)
wenzelm@18398
   101
  apply (erule rtrancl_induct)
wenzelm@18398
   102
   apply (blast intro: rel_pow_0_I rel_pow_Suc_I)+
wenzelm@18398
   103
  done
paulson@15410
   104
paulson@15410
   105
lemma rel_pow_imp_rtrancl: "!!p. p:R^n ==> p:R^*"
wenzelm@18398
   106
  apply (simp only: split_tupled_all)
wenzelm@18398
   107
  apply (induct n)
wenzelm@18398
   108
   apply (blast intro: rtrancl_refl elim: rel_pow_0_E)
wenzelm@18398
   109
  apply (blast elim: rel_pow_Suc_E intro: rtrancl_into_rtrancl)
wenzelm@18398
   110
  done
paulson@15410
   111
paulson@15410
   112
lemma rtrancl_is_UN_rel_pow: "R^* = (UN n. R^n)"
wenzelm@18398
   113
  by (blast intro: rtrancl_imp_UN_rel_pow rel_pow_imp_rtrancl)
paulson@15410
   114
paulson@15410
   115
wenzelm@18398
   116
lemma single_valued_rel_pow:
wenzelm@18398
   117
    "!!r::('a * 'a)set. single_valued r ==> single_valued (r^n)"
wenzelm@18398
   118
  apply (rule single_valuedI)
wenzelm@18398
   119
  apply (induct n)
wenzelm@18398
   120
   apply simp
wenzelm@18398
   121
  apply (fast dest: single_valuedD elim: rel_pow_Suc_E)
wenzelm@18398
   122
  done
paulson@15410
   123
paulson@15410
   124
ML
paulson@15410
   125
{*
paulson@15410
   126
val funpow_add = thm "funpow_add";
paulson@15410
   127
val rel_pow_1 = thm "rel_pow_1";
paulson@15410
   128
val rel_pow_0_I = thm "rel_pow_0_I";
paulson@15410
   129
val rel_pow_Suc_I = thm "rel_pow_Suc_I";
paulson@15410
   130
val rel_pow_Suc_I2 = thm "rel_pow_Suc_I2";
paulson@15410
   131
val rel_pow_0_E = thm "rel_pow_0_E";
paulson@15410
   132
val rel_pow_Suc_E = thm "rel_pow_Suc_E";
paulson@15410
   133
val rel_pow_E = thm "rel_pow_E";
paulson@15410
   134
val rel_pow_Suc_D2 = thm "rel_pow_Suc_D2";
paulson@15410
   135
val rel_pow_Suc_D2 = thm "rel_pow_Suc_D2";
paulson@15410
   136
val rel_pow_E2 = thm "rel_pow_E2";
paulson@15410
   137
val rtrancl_imp_UN_rel_pow = thm "rtrancl_imp_UN_rel_pow";
paulson@15410
   138
val rel_pow_imp_rtrancl = thm "rel_pow_imp_rtrancl";
paulson@15410
   139
val rtrancl_is_UN_rel_pow = thm "rtrancl_is_UN_rel_pow";
paulson@15410
   140
val single_valued_rel_pow = thm "single_valued_rel_pow";
paulson@15410
   141
*}
paulson@15410
   142
nipkow@10213
   143
end