src/HOL/Power.ML
author paulson
Thu Sep 23 13:06:31 1999 +0200 (1999-09-23)
changeset 7584 5be4bb8e4e3f
parent 7084 4af4f4d8035c
child 7844 6462cb4dfdc2
permissions -rw-r--r--
tidied; added lemma restrict_to_left
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@7084
    63
Goal "ALL k. n < k --> (n choose k) = 0";
paulson@7084
    64
by (induct_tac "n" 1);
paulson@7084
    65
by Auto_tac;
paulson@7084
    66
by (etac allE 1);
paulson@7084
    67
by (etac mp 1);
paulson@7084
    68
by (arith_tac 1);
paulson@7084
    69
qed_spec_mp "binomial_eq_0";
paulson@7084
    70
paulson@3390
    71
Addsimps [binomial_n_0, binomial_0_Suc, binomial_Suc_Suc];
paulson@3390
    72
Delsimps [binomial_0, binomial_Suc];
paulson@3390
    73
paulson@3390
    74
wenzelm@5069
    75
Goal "!k. n<k --> (n choose k) = 0";
paulson@3390
    76
by (induct_tac "n" 1);
paulson@3390
    77
by (ALLGOALS (rtac allI THEN' exhaust_tac "k"));
paulson@3390
    78
by (ALLGOALS Asm_simp_tac);
paulson@3390
    79
qed_spec_mp "less_imp_binomial_eq_0";
paulson@3390
    80
wenzelm@5069
    81
Goal "(n choose n) = 1";
paulson@3390
    82
by (induct_tac "n" 1);
wenzelm@4089
    83
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_imp_binomial_eq_0])));
paulson@3390
    84
qed "binomial_n_n";
paulson@3390
    85
Addsimps [binomial_n_n];
paulson@3390
    86
wenzelm@5069
    87
Goal "(Suc n choose n) = Suc n";
paulson@3390
    88
by (induct_tac "n" 1);
paulson@3390
    89
by (ALLGOALS Asm_simp_tac);
paulson@3390
    90
qed "binomial_Suc_n";
paulson@3390
    91
Addsimps [binomial_Suc_n];
paulson@3390
    92
wenzelm@5069
    93
Goal "(n choose 1) = n";
paulson@3390
    94
by (induct_tac "n" 1);
paulson@3390
    95
by (ALLGOALS Asm_simp_tac);
paulson@3390
    96
qed "binomial_1";
paulson@3390
    97
Addsimps [binomial_1];
paulson@7084
    98
paulson@7084
    99
Goal "k <= n --> 0 < (n choose k)";
paulson@7084
   100
by (res_inst_tac [("m","n"),("n","k")] diff_induct 1);
paulson@7084
   101
by (ALLGOALS Asm_simp_tac);
paulson@7084
   102
qed_spec_mp "zero_less_binomial";
paulson@7084
   103
paulson@7084
   104
(*Might be more useful if re-oriented*)
paulson@7084
   105
Goal "ALL k. k <= n --> Suc n * (n choose k) = (Suc n choose Suc k) * Suc k";
paulson@7084
   106
by (induct_tac "n" 1);
paulson@7084
   107
by (simp_tac (simpset() addsimps [binomial_0]) 1);
paulson@7084
   108
by (Clarify_tac 1);
paulson@7084
   109
by (exhaust_tac "k" 1);
paulson@7084
   110
by (auto_tac (claset(),
paulson@7084
   111
	      simpset() addsimps [add_mult_distrib, add_mult_distrib2,
paulson@7084
   112
				  le_Suc_eq, binomial_eq_0]));
paulson@7084
   113
qed_spec_mp "Suc_times_binomial_eq";
paulson@7084
   114
paulson@7084
   115
Goal "k <= n ==> (Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k";
paulson@7084
   116
by (asm_simp_tac
paulson@7084
   117
    (simpset_of Nat.thy addsimps [Suc_times_binomial_eq, 
paulson@7084
   118
				  div_mult_self_is_m]) 1);
paulson@7084
   119
qed "binomial_Suc_Suc_eq_times";
paulson@7084
   120