src/HOL/Hyperreal/Fact.ML
author berghofe
Fri, 01 Jul 2005 13:54:12 +0200
changeset 16633 208ebc9311f2
parent 14334 6137d24eef79
permissions -rw-r--r--
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification of premises of congruence rules.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     1
(*  Title       : Fact.ML
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     2
    Author      : Jacques D. Fleuriot
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     3
    Copyright   : 1998  University of Cambridge
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     4
    Description : Factorial function
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     5
*)
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     6
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     7
Goal "0 < fact n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     8
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     9
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    10
qed "fact_gt_zero";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    11
Addsimps [fact_gt_zero];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    12
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    13
Goal "fact n ~= 0";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    14
by (Simp_tac 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    15
qed "fact_not_eq_zero";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    16
Addsimps [fact_not_eq_zero];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    17
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    18
Goal "real (fact n) ~= 0";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    19
by Auto_tac; 
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    20
qed "real_of_nat_fact_not_zero";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    21
Addsimps [real_of_nat_fact_not_zero];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    22
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    23
Goal "0 < real(fact n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    24
by Auto_tac; 
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    25
qed "real_of_nat_fact_gt_zero";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    26
Addsimps [real_of_nat_fact_gt_zero];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    27
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    28
Goal "0 <= real(fact n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    29
by (Simp_tac 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    30
qed "real_of_nat_fact_ge_zero";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    31
Addsimps [real_of_nat_fact_ge_zero];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    32
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    33
Goal "1 <= fact n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    34
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    35
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    36
qed "fact_ge_one";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    37
Addsimps [fact_ge_one];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    38
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    39
Goal "m <= n ==> fact m <= fact n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    40
by (dtac le_imp_less_or_eq 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    41
by (auto_tac (claset() addSDs [less_imp_Suc_add],simpset()));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    42
by (induct_tac "k" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    43
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    44
qed "fact_mono";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    45
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    46
Goal "[| 0 < m; m < n |] ==> fact m < fact n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    47
by (dres_inst_tac [("m","m")] less_imp_Suc_add 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    48
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    49
by (induct_tac "k" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    50
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    51
qed "fact_less_mono";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    52
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    53
Goal "0 < inverse (real (fact n))";
14334
6137d24eef79 tweaking of lemmas in RealDef, RealOrd
paulson
parents: 12196
diff changeset
    54
by (auto_tac (claset(),simpset() addsimps [positive_imp_inverse_positive]));
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    55
qed "inv_real_of_nat_fact_gt_zero";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    56
Addsimps [inv_real_of_nat_fact_gt_zero];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    57
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    58
Goal "0 <= inverse (real (fact n))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    59
by (auto_tac (claset() addIs [order_less_imp_le],simpset()));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    60
qed "inv_real_of_nat_fact_ge_zero";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    61
Addsimps [inv_real_of_nat_fact_ge_zero];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    62
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    63
Goal "ALL m. ma < Suc m --> fact (Suc m - ma) = (Suc m - ma) * fact (m - ma)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    64
by (induct_tac "ma" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    65
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    66
by (dres_inst_tac [("x","m - 1")] spec 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    67
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    68
qed_spec_mp "fact_diff_Suc";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    69
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    70
Goal "fact 0 = 1";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    71
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    72
qed "fact_num0";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    73
Addsimps [fact_num0];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    74
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    75
Goal "fact m = (if m=0 then 1 else m * fact (m - 1))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    76
by (case_tac "m" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    77
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    78
qed "fact_num_eq_if";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    79
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    80
Goal "fact (m + n) = (if (m + n = 0) then 1 else (m + n) * (fact (m + n - 1)))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    81
by (case_tac "m+n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    82
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    83
qed "fact_add_num_eq_if";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    84
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    85
Goal "fact (m + n) = (if (m = 0) then fact n \
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    86
\     else (m + n) * (fact ((m - 1) + n)))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    87
by (case_tac "m" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    88
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    89
qed "fact_add_num_eq_if2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    90