src/HOL/Hyperreal/Fact.thy
author nipkow
Mon Aug 16 14:22:27 2004 +0200 (2004-08-16)
changeset 15131 c69542757a4d
parent 15094 a7d1a3fdc30d
child 15140 322485b816ac
permissions -rw-r--r--
New theory header syntax.
paulson@15094
     1
(*  Title       : Fact.thy
paulson@12196
     2
    Author      : Jacques D. Fleuriot
paulson@12196
     3
    Copyright   : 1998  University of Cambridge
paulson@15094
     4
    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
paulson@12196
     5
*)
paulson@12196
     6
paulson@15094
     7
header{*Factorial Function*}
paulson@15094
     8
nipkow@15131
     9
theory Fact
nipkow@15131
    10
import Real
nipkow@15131
    11
begin
paulson@15094
    12
paulson@15094
    13
consts fact :: "nat => nat"
paulson@15094
    14
primrec
paulson@15094
    15
   fact_0:     "fact 0 = 1"
paulson@15094
    16
   fact_Suc:   "fact (Suc n) = (Suc n) * fact n"
paulson@15094
    17
paulson@15094
    18
paulson@15094
    19
lemma fact_gt_zero [simp]: "0 < fact n"
paulson@15094
    20
by (induct "n", auto)
paulson@15094
    21
paulson@15094
    22
lemma fact_not_eq_zero [simp]: "fact n \<noteq> 0"
paulson@15094
    23
by simp
paulson@15094
    24
paulson@15094
    25
lemma real_of_nat_fact_not_zero [simp]: "real (fact n) \<noteq> 0"
paulson@15094
    26
by auto
paulson@15094
    27
paulson@15094
    28
lemma real_of_nat_fact_gt_zero [simp]: "0 < real(fact n)"
paulson@15094
    29
by auto
paulson@15094
    30
paulson@15094
    31
lemma real_of_nat_fact_ge_zero [simp]: "0 \<le> real(fact n)"
paulson@15094
    32
by simp
paulson@15094
    33
paulson@15094
    34
lemma fact_ge_one [simp]: "1 \<le> fact n"
paulson@15094
    35
by (induct "n", auto)
paulson@12196
    36
paulson@15094
    37
lemma fact_mono: "m \<le> n ==> fact m \<le> fact n"
paulson@15094
    38
apply (drule le_imp_less_or_eq)
paulson@15094
    39
apply (auto dest!: less_imp_Suc_add)
paulson@15094
    40
apply (induct_tac "k", auto)
paulson@15094
    41
done
paulson@15094
    42
paulson@15094
    43
text{*Note that @{term "fact 0 = fact 1"}*}
paulson@15094
    44
lemma fact_less_mono: "[| 0 < m; m < n |] ==> fact m < fact n"
paulson@15094
    45
apply (drule_tac m = m in less_imp_Suc_add, auto)
paulson@15094
    46
apply (induct_tac "k", auto)
paulson@15094
    47
done
paulson@15094
    48
paulson@15094
    49
lemma inv_real_of_nat_fact_gt_zero [simp]: "0 < inverse (real (fact n))"
paulson@15094
    50
by (auto simp add: positive_imp_inverse_positive)
paulson@15094
    51
paulson@15094
    52
lemma inv_real_of_nat_fact_ge_zero [simp]: "0 \<le> inverse (real (fact n))"
paulson@15094
    53
by (auto intro: order_less_imp_le)
paulson@15094
    54
paulson@15094
    55
lemma fact_diff_Suc [rule_format]:
paulson@15094
    56
     "\<forall>m. n < Suc m --> fact (Suc m - n) = (Suc m - n) * fact (m - n)"
paulson@15094
    57
apply (induct n, auto)
paulson@15094
    58
apply (drule_tac x = "m - 1" in spec, auto)
paulson@15094
    59
done
paulson@15094
    60
paulson@15094
    61
lemma fact_num0 [simp]: "fact 0 = 1"
paulson@15094
    62
by auto
paulson@15094
    63
paulson@15094
    64
lemma fact_num_eq_if: "fact m = (if m=0 then 1 else m * fact (m - 1))"
paulson@15094
    65
by (case_tac "m", auto)
paulson@15094
    66
paulson@15094
    67
lemma fact_add_num_eq_if:
paulson@15094
    68
     "fact (m+n) = (if (m+n = 0) then 1 else (m+n) * (fact (m + n - 1)))"
paulson@15094
    69
by (case_tac "m+n", auto)
paulson@15094
    70
paulson@15094
    71
lemma fact_add_num_eq_if2:
paulson@15094
    72
     "fact (m+n) = (if m=0 then fact n else (m+n) * (fact ((m - 1) + n)))"
paulson@15094
    73
by (case_tac "m", auto)
paulson@15094
    74
paulson@12196
    75
nipkow@15131
    76
end