src/HOL/Fact.thy
author haftmann
Wed Dec 03 15:58:44 2008 +0100 (2008-12-03)
changeset 28952 15a4b2cf8c34
parent 28944 src/HOL/Hyperreal/Fact.thy@e27abf0db984
child 29693 708dcf7dec9f
permissions -rw-r--r--
made repository layout more coherent with logical distribution structure; stripped some $Id$s
     1 (*  Title       : Fact.thy
     2     Author      : Jacques D. Fleuriot
     3     Copyright   : 1998  University of Cambridge
     4     Conversion to Isar and new proofs by Lawrence C Paulson, 2004
     5 *)
     6 
     7 header{*Factorial Function*}
     8 
     9 theory Fact
    10 imports RealDef
    11 begin
    12 
    13 consts fact :: "nat => nat"
    14 primrec
    15   fact_0:     "fact 0 = 1"
    16   fact_Suc:   "fact (Suc n) = (Suc n) * fact n"
    17 
    18 
    19 lemma fact_gt_zero [simp]: "0 < fact n"
    20 by (induct n) auto
    21 
    22 lemma fact_not_eq_zero [simp]: "fact n \<noteq> 0"
    23 by simp
    24 
    25 lemma real_of_nat_fact_not_zero [simp]: "real (fact n) \<noteq> 0"
    26 by auto
    27 
    28 lemma real_of_nat_fact_gt_zero [simp]: "0 < real(fact n)"
    29 by auto
    30 
    31 lemma real_of_nat_fact_ge_zero [simp]: "0 \<le> real(fact n)"
    32 by simp
    33 
    34 lemma fact_ge_one [simp]: "1 \<le> fact n"
    35 by (induct n) auto
    36 
    37 lemma fact_mono: "m \<le> n ==> fact m \<le> fact n"
    38 apply (drule le_imp_less_or_eq)
    39 apply (auto dest!: less_imp_Suc_add)
    40 apply (induct_tac k, auto)
    41 done
    42 
    43 text{*Note that @{term "fact 0 = fact 1"}*}
    44 lemma fact_less_mono: "[| 0 < m; m < n |] ==> fact m < fact n"
    45 apply (drule_tac m = m in less_imp_Suc_add, auto)
    46 apply (induct_tac k, auto)
    47 done
    48 
    49 lemma inv_real_of_nat_fact_gt_zero [simp]: "0 < inverse (real (fact n))"
    50 by (auto simp add: positive_imp_inverse_positive)
    51 
    52 lemma inv_real_of_nat_fact_ge_zero [simp]: "0 \<le> inverse (real (fact n))"
    53 by (auto intro: order_less_imp_le)
    54 
    55 lemma fact_diff_Suc [rule_format]:
    56   "n < Suc m ==> fact (Suc m - n) = (Suc m - n) * fact (m - n)"
    57 apply (induct n arbitrary: m)
    58 apply auto
    59 apply (drule_tac x = "m - 1" in meta_spec, auto)
    60 done
    61 
    62 lemma fact_num0 [simp]: "fact 0 = 1"
    63 by auto
    64 
    65 lemma fact_num_eq_if: "fact m = (if m=0 then 1 else m * fact (m - 1))"
    66 by (cases m) auto
    67 
    68 lemma fact_add_num_eq_if:
    69   "fact (m + n) = (if m + n = 0 then 1 else (m + n) * fact (m + n - 1))"
    70 by (cases "m + n") auto
    71 
    72 lemma fact_add_num_eq_if2:
    73   "fact (m + n) = (if m = 0 then fact n else (m + n) * fact ((m - 1) + n))"
    74 by (cases m) auto
    75 
    76 end