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