src/HOL/Binomial.thy
author wenzelm
Wed, 13 Jul 2005 16:07:35 +0200
changeset 16813 67140ae50e77
parent 16732 1bbe526a552c
child 17508 c84af7f39a6b
permissions -rw-r--r--
removed ad-hoc atp_hook, cal_atp; removed depth_of; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16732
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Binomial.thy
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
     2
    ID:         $Id$
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
     3
    Author:     Lawrence C Paulson
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
     4
    Copyright   1997  University of Cambridge
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
     5
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
     6
*)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
     7
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
     8
header{*Binomial Coefficients*}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
     9
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    10
theory Binomial
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    11
imports SetInterval
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    12
begin
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    13
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    14
text{*This development is based on the work of Andy Gordon and
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    15
Florian Kammueller*}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    16
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    17
consts
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    18
  binomial :: "nat \<Rightarrow> nat \<Rightarrow> nat"      (infixl "choose" 65)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    19
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    20
primrec
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    21
  binomial_0:   "(0     choose k) = (if k = 0 then 1 else 0)"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    22
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    23
  binomial_Suc: "(Suc n choose k) =
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    24
                 (if k = 0 then 1 else (n choose (k - 1)) + (n choose k))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    25
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    26
lemma binomial_n_0 [simp]: "(n choose 0) = 1"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    27
by (case_tac "n", simp_all)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    28
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    29
lemma binomial_0_Suc [simp]: "(0 choose Suc k) = 0"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    30
by simp
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    31
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    32
lemma binomial_Suc_Suc [simp]:
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    33
     "(Suc n choose Suc k) = (n choose k) + (n choose Suc k)"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    34
by simp
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    35
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    36
lemma binomial_eq_0 [rule_format]: "\<forall>k. n < k --> (n choose k) = 0"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    37
apply (induct "n", auto)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    38
apply (erule allE)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    39
apply (erule mp, arith)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    40
done
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    41
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    42
declare binomial_0 [simp del] binomial_Suc [simp del]
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    43
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    44
lemma binomial_n_n [simp]: "(n choose n) = 1"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    45
apply (induct "n")
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    46
apply (simp_all add: binomial_eq_0)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    47
done
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    48
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    49
lemma binomial_Suc_n [simp]: "(Suc n choose n) = Suc n"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    50
by (induct "n", simp_all)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    51
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    52
lemma binomial_1 [simp]: "(n choose Suc 0) = n"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    53
by (induct "n", simp_all)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    54
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    55
lemma zero_less_binomial [rule_format]: "k \<le> n --> 0 < (n choose k)"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    56
by (rule_tac m = n and n = k in diff_induct, simp_all)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    57
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    58
lemma binomial_eq_0_iff: "(n choose k = 0) = (n<k)"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    59
apply (safe intro!: binomial_eq_0)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    60
apply (erule contrapos_pp)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    61
apply (simp add: zero_less_binomial)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    62
done
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    63
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    64
lemma zero_less_binomial_iff: "(0 < n choose k) = (k\<le>n)"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    65
by (simp add: linorder_not_less [symmetric] binomial_eq_0_iff [symmetric])
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    66
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    67
(*Might be more useful if re-oriented*)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    68
lemma Suc_times_binomial_eq [rule_format]:
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    69
     "\<forall>k. k \<le> n --> Suc n * (n choose k) = (Suc n choose Suc k) * Suc k"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    70
apply (induct "n")
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    71
apply (simp add: binomial_0, clarify)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    72
apply (case_tac "k")
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    73
apply (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    74
                      binomial_eq_0)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    75
done
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    76
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    77
text{*This is the well-known version, but it's harder to use because of the
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    78
  need to reason about division.*}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    79
lemma binomial_Suc_Suc_eq_times:
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    80
     "k \<le> n ==> (Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    81
by (simp add: Suc_times_binomial_eq div_mult_self_is_m zero_less_Suc
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    82
        del: mult_Suc mult_Suc_right)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    83
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    84
text{*Another version, with -1 instead of Suc.*}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    85
lemma times_binomial_minus1_eq:
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    86
     "[|k \<le> n;  0<k|] ==> (n choose k) * k = n * ((n - 1) choose (k - 1))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    87
apply (cut_tac n = "n - 1" and k = "k - 1" in Suc_times_binomial_eq)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    88
apply (simp split add: nat_diff_split, auto)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    89
done
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    90
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    91
subsubsection {* Theorems about @{text "choose"} *}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    92
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    93
text {*
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    94
  \medskip Basic theorem about @{text "choose"}.  By Florian
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    95
  Kamm\"uller, tidied by LCP.
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    96
*}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    97
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    98
lemma card_s_0_eq_empty:
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
    99
    "finite A ==> card {B. B \<subseteq> A & card B = 0} = 1"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   100
  apply (simp cong add: conj_cong add: finite_subset [THEN card_0_eq])
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   101
  apply (simp cong add: rev_conj_cong)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   102
  done
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   103
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   104
lemma choose_deconstruct: "finite M ==> x \<notin> M
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   105
  ==> {s. s <= insert x M & card(s) = Suc k}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   106
       = {s. s <= M & card(s) = Suc k} Un
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   107
         {s. EX t. t <= M & card(t) = k & s = insert x t}"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   108
  apply safe
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   109
   apply (auto intro: finite_subset [THEN card_insert_disjoint])
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   110
  apply (drule_tac x = "xa - {x}" in spec)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   111
  apply (subgoal_tac "x \<notin> xa", auto)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   112
  apply (erule rev_mp, subst card_Diff_singleton)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   113
  apply (auto intro: finite_subset)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   114
  done
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   115
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   116
text{*There are as many subsets of @{term A} having cardinality @{term k}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   117
 as there are sets obtained from the former by inserting a fixed element
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   118
 @{term x} into each.*}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   119
lemma constr_bij:
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   120
   "[|finite A; x \<notin> A|] ==>
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   121
    card {B. EX C. C <= A & card(C) = k & B = insert x C} =
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   122
    card {B. B <= A & card(B) = k}"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   123
  apply (rule_tac f = "%s. s - {x}" and g = "insert x" in card_bij_eq)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   124
       apply (auto elim!: equalityE simp add: inj_on_def)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   125
    apply (subst Diff_insert0, auto)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   126
   txt {* finiteness of the two sets *}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   127
   apply (rule_tac [2] B = "Pow (A)" in finite_subset)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   128
   apply (rule_tac B = "Pow (insert x A)" in finite_subset)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   129
   apply fast+
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   130
  done
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   131
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   132
text {*
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   133
  Main theorem: combinatorial statement about number of subsets of a set.
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   134
*}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   135
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   136
lemma n_sub_lemma:
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   137
  "!!A. finite A ==> card {B. B <= A & card B = k} = (card A choose k)"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   138
  apply (induct k)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   139
   apply (simp add: card_s_0_eq_empty, atomize)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   140
  apply (rotate_tac -1, erule finite_induct)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   141
   apply (simp_all (no_asm_simp) cong add: conj_cong
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   142
     add: card_s_0_eq_empty choose_deconstruct)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   143
  apply (subst card_Un_disjoint)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   144
     prefer 4 apply (force simp add: constr_bij)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   145
    prefer 3 apply force
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   146
   prefer 2 apply (blast intro: finite_Pow_iff [THEN iffD2]
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   147
     finite_subset [of _ "Pow (insert x F)", standard])
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   148
  apply (blast intro: finite_Pow_iff [THEN iffD2, THEN [2] finite_subset])
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   149
  done
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   150
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   151
theorem n_subsets:
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   152
    "finite A ==> card {B. B <= A & card B = k} = (card A choose k)"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   153
  by (simp add: n_sub_lemma)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   154
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   155
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   156
text{* The binomial theorem (courtesy of Tobias Nipkow): *}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   157
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   158
theorem binomial: "(a+b::nat)^n = (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   159
proof (induct n)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   160
  case 0 thus ?case by simp
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   161
next
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   162
  case (Suc n)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   163
  have decomp: "{0..n+1} = {0} \<union> {n+1} \<union> {1..n}"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   164
    by (auto simp add:atLeastAtMost_def atLeast_def atMost_def)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   165
  have decomp2: "{0..n} = {0} \<union> {1..n}"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   166
    by (auto simp add:atLeastAtMost_def atLeast_def atMost_def)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   167
  have "(a+b::nat)^(n+1) = (a+b) * (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   168
    using Suc by simp
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   169
  also have "\<dots> =  a*(\<Sum>k=0..n. (n choose k) * a^k * b^(n-k)) +
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   170
                   b*(\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   171
    by(rule nat_distrib)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   172
  also have "\<dots> = (\<Sum>k=0..n. (n choose k) * a^(k+1) * b^(n-k)) +
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   173
                  (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k+1))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   174
    by(simp add: setsum_mult mult_ac)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   175
  also have "\<dots> = (\<Sum>k=0..n. (n choose k) * a^k * b^(n+1-k)) +
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   176
                  (\<Sum>k=1..n+1. (n choose (k - 1)) * a^k * b^(n+1-k))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   177
    by (simp add:setsum_shift_bounds_cl_Suc_ivl Suc_diff_le
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   178
             del:setsum_cl_ivl_Suc)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   179
  also have "\<dots> = a^(n+1) + b^(n+1) +
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   180
                  (\<Sum>k=1..n. (n choose (k - 1)) * a^k * b^(n+1-k)) +
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   181
                  (\<Sum>k=1..n. (n choose k) * a^k * b^(n+1-k))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   182
    by(simp add: decomp2)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   183
  also have
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   184
    "\<dots> = a^(n+1) + b^(n+1) + (\<Sum>k=1..n. (n+1 choose k) * a^k * b^(n+1-k))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   185
    by(simp add: nat_distrib setsum_addf binomial.simps)
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   186
  also have "\<dots> = (\<Sum>k=0..n+1. (n+1 choose k) * a^k * b^(n+1-k))"
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   187
    using decomp by simp
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   188
  finally show ?case by simp
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   189
qed
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   190
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   191
ML
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   192
{*
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   193
val binomial_n_0 = thm"binomial_n_0";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   194
val binomial_0_Suc = thm"binomial_0_Suc";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   195
val binomial_Suc_Suc = thm"binomial_Suc_Suc";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   196
val binomial_eq_0 = thm"binomial_eq_0";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   197
val binomial_n_n = thm"binomial_n_n";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   198
val binomial_Suc_n = thm"binomial_Suc_n";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   199
val binomial_1 = thm"binomial_1";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   200
val zero_less_binomial = thm"zero_less_binomial";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   201
val binomial_eq_0_iff = thm"binomial_eq_0_iff";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   202
val zero_less_binomial_iff = thm"zero_less_binomial_iff";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   203
val Suc_times_binomial_eq = thm"Suc_times_binomial_eq";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   204
val binomial_Suc_Suc_eq_times = thm"binomial_Suc_Suc_eq_times";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   205
val times_binomial_minus1_eq = thm"times_binomial_minus1_eq";
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   206
*}
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   207
1bbe526a552c Used to be part of Finite_Set (or was it SetInterval?)
nipkow
parents:
diff changeset
   208
end