src/HOL/Hyperreal/Fact.thy
author nipkow
Sun Oct 21 14:53:44 2007 +0200 (2007-10-21)
changeset 25134 3d4953e88449
parent 25112 98824cc791c0
child 25162 ad4d5365d9d8
permissions -rw-r--r--
Eliminated most of the neq0_conv occurrences. As a result, many
theorems had to be rephrased with ~= 0 instead of > 0.
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
paulson@15241
    10
imports "../Real/Real"
nipkow@15131
    11
begin
paulson@15094
    12
paulson@15094
    13
consts fact :: "nat => nat"
paulson@15094
    14
primrec
wenzelm@19765
    15
  fact_0:     "fact 0 = 1"
wenzelm@19765
    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"
nipkow@25134
    20
by (induct n) auto
paulson@15094
    21
paulson@15094
    22
lemma fact_not_eq_zero [simp]: "fact n \<noteq> 0"
nipkow@25134
    23
by (simp add: neq0_conv)
paulson@15094
    24
paulson@15094
    25
lemma real_of_nat_fact_not_zero [simp]: "real (fact n) \<noteq> 0"
nipkow@25134
    26
by auto
paulson@15094
    27
paulson@15094
    28
lemma real_of_nat_fact_gt_zero [simp]: "0 < real(fact n)"
nipkow@25134
    29
by auto
paulson@15094
    30
paulson@15094
    31
lemma real_of_nat_fact_ge_zero [simp]: "0 \<le> real(fact n)"
nipkow@25134
    32
by simp
paulson@15094
    33
paulson@15094
    34
lemma fact_ge_one [simp]: "1 \<le> fact n"
nipkow@25134
    35
by (induct n) auto
paulson@12196
    36
paulson@15094
    37
lemma fact_mono: "m \<le> n ==> fact m \<le> fact n"
nipkow@25134
    38
apply (drule le_imp_less_or_eq)
nipkow@25134
    39
apply (auto dest!: less_imp_Suc_add)
nipkow@25134
    40
apply (induct_tac k, auto)
nipkow@25134
    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"
nipkow@25134
    45
apply (drule_tac m = m in less_imp_Suc_add, auto)
nipkow@25134
    46
apply (induct_tac k, auto)
nipkow@25134
    47
done
paulson@15094
    48
paulson@15094
    49
lemma inv_real_of_nat_fact_gt_zero [simp]: "0 < inverse (real (fact n))"
nipkow@25134
    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))"
nipkow@25134
    53
by (auto intro: order_less_imp_le)
paulson@15094
    54
paulson@15094
    55
lemma fact_diff_Suc [rule_format]:
nipkow@25134
    56
  "n < Suc m ==> fact (Suc m - n) = (Suc m - n) * fact (m - n)"
nipkow@25134
    57
apply (induct n arbitrary: m)
nipkow@25134
    58
apply auto
nipkow@25134
    59
apply (drule_tac x = "m - 1" in meta_spec, auto)
nipkow@25134
    60
done
paulson@15094
    61
paulson@15094
    62
lemma fact_num0 [simp]: "fact 0 = 1"
nipkow@25134
    63
by auto
paulson@15094
    64
paulson@15094
    65
lemma fact_num_eq_if: "fact m = (if m=0 then 1 else m * fact (m - 1))"
nipkow@25134
    66
by (cases m) auto
paulson@15094
    67
paulson@15094
    68
lemma fact_add_num_eq_if:
nipkow@25134
    69
  "fact (m + n) = (if m + n = 0 then 1 else (m + n) * fact (m + n - 1))"
nipkow@25134
    70
by (cases "m + n") auto
paulson@15094
    71
paulson@15094
    72
lemma fact_add_num_eq_if2:
nipkow@25134
    73
  "fact (m + n) = (if m = 0 then fact n else (m + n) * fact ((m - 1) + n))"
nipkow@25134
    74
by (cases m) auto
paulson@12196
    75
nipkow@15131
    76
end