src/HOL/Power.ML
author paulson
Thu Jul 01 10:33:50 1999 +0200 (1999-07-01)
changeset 6865 5577ffe4c2f1
parent 5143 b94cd208f073
child 7084 4af4f4d8035c
permissions -rw-r--r--
now div and mod are overloaded; dvd is polymorphic
paulson@3390
     1
(*  Title:      HOL/Power.ML
paulson@3390
     2
    ID:         $Id$
paulson@3390
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@3390
     4
    Copyright   1997  University of Cambridge
paulson@3390
     5
paulson@3390
     6
The (overloaded) exponentiation operator, ^ :: [nat,nat]=>nat
paulson@3390
     7
Also binomial coefficents
paulson@3390
     8
*)
paulson@3390
     9
paulson@3390
    10
(*** Simple laws about Power ***)
paulson@3390
    11
wenzelm@5069
    12
Goal "!!i::nat. i ^ (j+k) = (i^j) * (i^k)";
paulson@3390
    13
by (induct_tac "k" 1);
wenzelm@4089
    14
by (ALLGOALS (asm_simp_tac (simpset() addsimps mult_ac)));
paulson@3390
    15
qed "power_add";
paulson@3390
    16
wenzelm@5069
    17
Goal "!!i::nat. i ^ (j*k) = (i^j) ^ k";
paulson@3390
    18
by (induct_tac "k" 1);
wenzelm@4089
    19
by (ALLGOALS (asm_simp_tac (simpset() addsimps [power_add])));
paulson@3390
    20
qed "power_mult";
paulson@3390
    21
paulson@5143
    22
Goal "0 < i ==> 0 < i^n";
paulson@3390
    23
by (induct_tac "n" 1);
wenzelm@4089
    24
by (ALLGOALS (asm_simp_tac (simpset() addsimps [zero_less_mult_iff])));
paulson@3390
    25
qed "zero_less_power";
paulson@3390
    26
paulson@6865
    27
Goalw [dvd_def] "!!(m::nat) (i::nat). m<=n ==> i^m dvd i^n";
paulson@3457
    28
by (etac (not_less_iff_le RS iffD2 RS add_diff_inverse RS subst) 1);
wenzelm@4089
    29
by (asm_simp_tac (simpset() addsimps [power_add]) 1);
paulson@3390
    30
by (Blast_tac 1);
paulson@3390
    31
qed "le_imp_power_dvd";
paulson@3390
    32
paulson@5143
    33
Goal "[| 0 < i; i^m < i^n |] ==> m<n";
paulson@3457
    34
by (rtac ccontr 1);
paulson@3457
    35
by (dtac (leI RS le_imp_power_dvd RS dvd_imp_le RS leD) 1);
paulson@3457
    36
by (etac zero_less_power 1);
paulson@3390
    37
by (contr_tac 1);
paulson@3390
    38
qed "power_less_imp_less";
paulson@3390
    39
paulson@6865
    40
Goal "k^j dvd n --> i<j --> k^i dvd (n::nat)";
paulson@3390
    41
by (induct_tac "j" 1);
wenzelm@4089
    42
by (ALLGOALS (simp_tac (simpset() addsimps [less_Suc_eq])));
paulson@3390
    43
by (stac mult_commute 1);
wenzelm@4089
    44
by (blast_tac (claset() addSDs [dvd_mult_left]) 1);
paulson@3390
    45
qed_spec_mp "power_less_dvd";
paulson@3390
    46
paulson@3390
    47
wenzelm@3396
    48
(*** Binomial Coefficients, following Andy Gordon and Florian Kammueller ***)
paulson@3390
    49
wenzelm@5069
    50
Goal "(n choose 0) = 1";
paulson@3390
    51
by (exhaust_tac "n" 1);
paulson@3390
    52
by (ALLGOALS Asm_simp_tac);
paulson@3390
    53
qed "binomial_n_0";
paulson@3390
    54
wenzelm@5069
    55
Goal "(0 choose Suc k) = 0";
paulson@3390
    56
by (Simp_tac 1);
paulson@3390
    57
qed "binomial_0_Suc";
paulson@3390
    58
wenzelm@5069
    59
Goal "(Suc n choose Suc k) = (n choose k) + (n choose Suc k)";
paulson@3390
    60
by (Simp_tac 1);
paulson@3390
    61
qed "binomial_Suc_Suc";
paulson@3390
    62
paulson@3390
    63
Addsimps [binomial_n_0, binomial_0_Suc, binomial_Suc_Suc];
paulson@3390
    64
Delsimps [binomial_0, binomial_Suc];
paulson@3390
    65
paulson@3390
    66
wenzelm@5069
    67
Goal "!k. n<k --> (n choose k) = 0";
paulson@3390
    68
by (induct_tac "n" 1);
paulson@3390
    69
by (ALLGOALS (rtac allI THEN' exhaust_tac "k"));
paulson@3390
    70
by (ALLGOALS Asm_simp_tac);
paulson@3390
    71
qed_spec_mp "less_imp_binomial_eq_0";
paulson@3390
    72
wenzelm@5069
    73
Goal "(n choose n) = 1";
paulson@3390
    74
by (induct_tac "n" 1);
wenzelm@4089
    75
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_imp_binomial_eq_0])));
paulson@3390
    76
qed "binomial_n_n";
paulson@3390
    77
Addsimps [binomial_n_n];
paulson@3390
    78
wenzelm@5069
    79
Goal "(Suc n choose n) = Suc n";
paulson@3390
    80
by (induct_tac "n" 1);
paulson@3390
    81
by (ALLGOALS Asm_simp_tac);
paulson@3390
    82
qed "binomial_Suc_n";
paulson@3390
    83
Addsimps [binomial_Suc_n];
paulson@3390
    84
wenzelm@5069
    85
Goal "(n choose 1) = n";
paulson@3390
    86
by (induct_tac "n" 1);
paulson@3390
    87
by (ALLGOALS Asm_simp_tac);
paulson@3390
    88
qed "binomial_1";
paulson@3390
    89
Addsimps [binomial_1];