src/HOL/Power.thy
changeset 30960 fec1a04b7220
parent 30730 4d3565f2cb0e
child 30996 648d02b124d8
equal deleted inserted replaced
30959:458e55fd0a33 30960:fec1a04b7220
     1 (*  Title:      HOL/Power.thy
     1 (*  Title:      HOL/Power.thy
     2     ID:         $Id$
       
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1997  University of Cambridge
     3     Copyright   1997  University of Cambridge
     5 
       
     6 *)
     4 *)
     7 
     5 
     8 header{*Exponentiation*}
     6 header {* Exponentiation *}
     9 
     7 
    10 theory Power
     8 theory Power
    11 imports Nat
     9 imports Nat
    12 begin
    10 begin
    13 
    11 
    14 class power =
    12 subsection {* Powers for Arbitrary Monoids *}
    15   fixes power :: "'a \<Rightarrow> nat \<Rightarrow> 'a"            (infixr "^" 80)
    13 
    16 
    14 class recpower = monoid_mult
    17 subsection{*Powers for Arbitrary Monoids*}
    15 begin
    18 
    16 
    19 class recpower = monoid_mult + power +
    17 primrec power :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixr "^" 80) where
    20   assumes power_0 [simp]: "a ^ 0       = 1"
    18     power_0: "a ^ 0 = 1"
    21   assumes power_Suc [simp]: "a ^ Suc n = a * (a ^ n)"
    19   | power_Suc: "a ^ Suc n = a * a ^ n"
       
    20 
       
    21 end
    22 
    22 
    23 lemma power_0_Suc [simp]: "(0::'a::{recpower,semiring_0}) ^ (Suc n) = 0"
    23 lemma power_0_Suc [simp]: "(0::'a::{recpower,semiring_0}) ^ (Suc n) = 0"
    24   by simp
    24   by simp
    25 
    25 
    26 text{*It looks plausible as a simprule, but its effect can be strange.*}
    26 text{*It looks plausible as a simprule, but its effect can be strange.*}
   358   apply (subst power_Suc)
   358   apply (subst power_Suc)
   359   apply auto
   359   apply auto
   360 done
   360 done
   361 
   361 
   362 
   362 
   363 subsection{*Exponentiation for the Natural Numbers*}
   363 subsection {* Exponentiation for the Natural Numbers *}
   364 
   364 
   365 instantiation nat :: recpower
   365 instance nat :: recpower ..
   366 begin
       
   367 
       
   368 primrec power_nat where
       
   369   "p ^ 0 = (1\<Colon>nat)"
       
   370   | "p ^ (Suc n) = (p\<Colon>nat) * (p ^ n)"
       
   371 
       
   372 instance proof
       
   373   fix z n :: nat
       
   374   show "z^0 = 1" by simp
       
   375   show "z^(Suc n) = z * (z^n)" by simp
       
   376 qed
       
   377 
       
   378 declare power_nat.simps [simp del]
       
   379 
       
   380 end
       
   381 
   366 
   382 lemma of_nat_power:
   367 lemma of_nat_power:
   383   "of_nat (m ^ n) = (of_nat m::'a::{semiring_1,recpower}) ^ n"
   368   "of_nat (m ^ n) = (of_nat m::'a::{semiring_1,recpower}) ^ n"
   384 by (induct n, simp_all add: of_nat_mult)
   369 by (induct n, simp_all add: of_nat_mult)
   385 
   370 
   389 lemma nat_zero_less_power_iff [simp]: "(x^n > 0) = (x > (0::nat) | n=0)"
   374 lemma nat_zero_less_power_iff [simp]: "(x^n > 0) = (x > (0::nat) | n=0)"
   390 by (induct "n", auto)
   375 by (induct "n", auto)
   391 
   376 
   392 lemma nat_power_eq_Suc_0_iff [simp]: 
   377 lemma nat_power_eq_Suc_0_iff [simp]: 
   393   "((x::nat)^m = Suc 0) = (m = 0 | x = Suc 0)"
   378   "((x::nat)^m = Suc 0) = (m = 0 | x = Suc 0)"
   394 by (induct_tac m, auto)
   379 by (induct m, auto)
   395 
   380 
   396 lemma power_Suc_0[simp]: "(Suc 0)^n = Suc 0"
   381 lemma power_Suc_0[simp]: "(Suc 0)^n = Suc 0"
   397 by simp
   382 by simp
   398 
   383 
   399 text{*Valid for the naturals, but what if @{text"0<i<1"}?
   384 text{*Valid for the naturals, but what if @{text"0<i<1"}?