src/HOL/Library/Binomial.thy
author chaieb
Thu, 23 Jul 2009 21:12:57 +0200
changeset 32159 4082bd9824c9
parent 32158 4dc119d4fc8b
child 32161 abda97d2deea
permissions -rw-r--r--
More theorems about pochhammer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Binomial.thy
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
     2
    Author:     Lawrence C Paulson, Amine Chaieb
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     3
    Copyright   1997  University of Cambridge
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     4
*)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     5
21263
wenzelm
parents: 21256
diff changeset
     6
header {* Binomial Coefficients *}
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     7
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     8
theory Binomial
31287
6c593b431f04 use class field_char_0
huffman
parents: 31166
diff changeset
     9
imports Fact SetInterval Presburger Main Rational
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    10
begin
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    11
21263
wenzelm
parents: 21256
diff changeset
    12
text {* This development is based on the work of Andy Gordon and
wenzelm
parents: 21256
diff changeset
    13
  Florian Kammueller. *}
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    14
29931
a1960091c34d new primrec
haftmann
parents: 29918
diff changeset
    15
primrec binomial :: "nat \<Rightarrow> nat \<Rightarrow> nat" (infixl "choose" 65) where
21263
wenzelm
parents: 21256
diff changeset
    16
  binomial_0: "(0 choose k) = (if k = 0 then 1 else 0)"
29931
a1960091c34d new primrec
haftmann
parents: 29918
diff changeset
    17
  | binomial_Suc: "(Suc n choose k) =
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    18
                 (if k = 0 then 1 else (n choose (k - 1)) + (n choose k))"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    19
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    20
lemma binomial_n_0 [simp]: "(n choose 0) = 1"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    21
by (cases n) simp_all
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    22
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    23
lemma binomial_0_Suc [simp]: "(0 choose Suc k) = 0"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    24
by simp
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    25
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    26
lemma binomial_Suc_Suc [simp]:
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    27
  "(Suc n choose Suc k) = (n choose k) + (n choose Suc k)"
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    28
by simp
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    29
21263
wenzelm
parents: 21256
diff changeset
    30
lemma binomial_eq_0: "!!k. n < k ==> (n choose k) = 0"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    31
by (induct n) auto
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    32
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    33
declare binomial_0 [simp del] binomial_Suc [simp del]
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    34
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    35
lemma binomial_n_n [simp]: "(n choose n) = 1"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    36
by (induct n) (simp_all add: binomial_eq_0)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    37
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    38
lemma binomial_Suc_n [simp]: "(Suc n choose n) = Suc n"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    39
by (induct n) simp_all
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    40
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    41
lemma binomial_1 [simp]: "(n choose Suc 0) = n"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    42
by (induct n) simp_all
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    43
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    44
lemma zero_less_binomial: "k \<le> n ==> (n choose k) > 0"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    45
by (induct n k rule: diff_induct) simp_all
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    46
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    47
lemma binomial_eq_0_iff: "(n choose k = 0) = (n<k)"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    48
apply (safe intro!: binomial_eq_0)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    49
apply (erule contrapos_pp)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    50
apply (simp add: zero_less_binomial)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    51
done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    52
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    53
lemma zero_less_binomial_iff: "(n choose k > 0) = (k\<le>n)"
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    54
by(simp add: linorder_not_less binomial_eq_0_iff neq0_conv[symmetric]
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    55
        del:neq0_conv)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    56
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    57
(*Might be more useful if re-oriented*)
21263
wenzelm
parents: 21256
diff changeset
    58
lemma Suc_times_binomial_eq:
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    59
  "!!k. k \<le> n ==> Suc n * (n choose k) = (Suc n choose Suc k) * Suc k"
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    60
apply (induct n)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    61
apply (simp add: binomial_0)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    62
apply (case_tac k)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    63
apply (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq
21263
wenzelm
parents: 21256
diff changeset
    64
    binomial_eq_0)
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
    65
done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    66
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    67
text{*This is the well-known version, but it's harder to use because of the
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    68
  need to reason about division.*}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    69
lemma binomial_Suc_Suc_eq_times:
21263
wenzelm
parents: 21256
diff changeset
    70
    "k \<le> n ==> (Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k"
wenzelm
parents: 21256
diff changeset
    71
  by (simp add: Suc_times_binomial_eq div_mult_self_is_m zero_less_Suc
wenzelm
parents: 21256
diff changeset
    72
    del: mult_Suc mult_Suc_right)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    73
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    74
text{*Another version, with -1 instead of Suc.*}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    75
lemma times_binomial_minus1_eq:
21263
wenzelm
parents: 21256
diff changeset
    76
    "[|k \<le> n;  0<k|] ==> (n choose k) * k = n * ((n - 1) choose (k - 1))"
wenzelm
parents: 21256
diff changeset
    77
  apply (cut_tac n = "n - 1" and k = "k - 1" in Suc_times_binomial_eq)
wenzelm
parents: 21256
diff changeset
    78
  apply (simp split add: nat_diff_split, auto)
wenzelm
parents: 21256
diff changeset
    79
  done
wenzelm
parents: 21256
diff changeset
    80
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    81
25378
dca691610489 tuned document;
wenzelm
parents: 25162
diff changeset
    82
subsection {* Theorems about @{text "choose"} *}
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    83
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    84
text {*
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    85
  \medskip Basic theorem about @{text "choose"}.  By Florian
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    86
  Kamm\"uller, tidied by LCP.
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    87
*}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    88
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    89
lemma card_s_0_eq_empty:
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    90
    "finite A ==> card {B. B \<subseteq> A & card B = 0} = 1"
31166
a90fe83f58ea "{x. P x & x=t & Q x}" is now rewritten to "if P t & Q t then {t} else {}"
nipkow
parents: 31021
diff changeset
    91
by (simp cong add: conj_cong add: finite_subset [THEN card_0_eq])
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    92
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    93
lemma choose_deconstruct: "finite M ==> x \<notin> M
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    94
  ==> {s. s <= insert x M & card(s) = Suc k}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    95
       = {s. s <= M & card(s) = Suc k} Un
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    96
         {s. EX t. t <= M & card(t) = k & s = insert x t}"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    97
  apply safe
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    98
   apply (auto intro: finite_subset [THEN card_insert_disjoint])
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    99
  apply (drule_tac x = "xa - {x}" in spec)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   100
  apply (subgoal_tac "x \<notin> xa", auto)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   101
  apply (erule rev_mp, subst card_Diff_singleton)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   102
  apply (auto intro: finite_subset)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   103
  done
29918
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   104
(*
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   105
lemma "finite(UN y. {x. P x y})"
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   106
apply simp
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   107
lemma Collect_ex_eq
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   108
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   109
lemma "{x. EX y. P x y} = (UN y. {x. P x y})"
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   110
apply blast
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   111
*)
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   112
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   113
lemma finite_bex_subset[simp]:
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   114
  "finite B \<Longrightarrow> (!!A. A<=B \<Longrightarrow> finite{x. P x A}) \<Longrightarrow> finite{x. EX A<=B. P x A}"
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   115
apply(subgoal_tac "{x. EX A<=B. P x A} = (UN A:Pow B. {x. P x A})")
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   116
 apply simp
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   117
apply blast
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   118
done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   119
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   120
text{*There are as many subsets of @{term A} having cardinality @{term k}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   121
 as there are sets obtained from the former by inserting a fixed element
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   122
 @{term x} into each.*}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   123
lemma constr_bij:
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   124
   "[|finite A; x \<notin> A|] ==>
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   125
    card {B. EX C. C <= A & card(C) = k & B = insert x C} =
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   126
    card {B. B <= A & card(B) = k}"
29918
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   127
apply (rule_tac f = "%s. s - {x}" and g = "insert x" in card_bij_eq)
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   128
     apply (auto elim!: equalityE simp add: inj_on_def)
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   129
apply (subst Diff_insert0, auto)
214755b03df3 more finiteness
nipkow
parents: 29906
diff changeset
   130
done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   131
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   132
text {*
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   133
  Main theorem: combinatorial statement about number of subsets of a set.
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   134
*}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   135
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   136
lemma n_sub_lemma:
21263
wenzelm
parents: 21256
diff changeset
   137
    "!!A. finite A ==> card {B. B <= A & card B = k} = (card A choose k)"
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   138
  apply (induct k)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   139
   apply (simp add: card_s_0_eq_empty, atomize)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   140
  apply (rotate_tac -1, erule finite_induct)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   141
   apply (simp_all (no_asm_simp) cong add: conj_cong
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   142
     add: card_s_0_eq_empty choose_deconstruct)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   143
  apply (subst card_Un_disjoint)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   144
     prefer 4 apply (force simp add: constr_bij)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   145
    prefer 3 apply force
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   146
   prefer 2 apply (blast intro: finite_Pow_iff [THEN iffD2]
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   147
     finite_subset [of _ "Pow (insert x F)", standard])
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   148
  apply (blast intro: finite_Pow_iff [THEN iffD2, THEN [2] finite_subset])
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   149
  done
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   150
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   151
theorem n_subsets:
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   152
    "finite A ==> card {B. B <= A & card B = k} = (card A choose k)"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   153
  by (simp add: n_sub_lemma)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   154
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   155
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   156
text{* The binomial theorem (courtesy of Tobias Nipkow): *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   157
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   158
theorem binomial: "(a+b::nat)^n = (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   159
proof (induct n)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   160
  case 0 thus ?case by simp
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   161
next
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   162
  case (Suc n)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   163
  have decomp: "{0..n+1} = {0} \<union> {n+1} \<union> {1..n}"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   164
    by (auto simp add:atLeastAtMost_def atLeast_def atMost_def)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   165
  have decomp2: "{0..n} = {0} \<union> {1..n}"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   166
    by (auto simp add:atLeastAtMost_def atLeast_def atMost_def)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   167
  have "(a+b::nat)^(n+1) = (a+b) * (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   168
    using Suc by simp
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   169
  also have "\<dots> =  a*(\<Sum>k=0..n. (n choose k) * a^k * b^(n-k)) +
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   170
                   b*(\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))"
21263
wenzelm
parents: 21256
diff changeset
   171
    by (rule nat_distrib)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   172
  also have "\<dots> = (\<Sum>k=0..n. (n choose k) * a^(k+1) * b^(n-k)) +
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   173
                  (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k+1))"
21263
wenzelm
parents: 21256
diff changeset
   174
    by (simp add: setsum_right_distrib mult_ac)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   175
  also have "\<dots> = (\<Sum>k=0..n. (n choose k) * a^k * b^(n+1-k)) +
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   176
                  (\<Sum>k=1..n+1. (n choose (k - 1)) * a^k * b^(n+1-k))"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   177
    by (simp add:setsum_shift_bounds_cl_Suc_ivl Suc_diff_le
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   178
             del:setsum_cl_ivl_Suc)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   179
  also have "\<dots> = a^(n+1) + b^(n+1) +
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   180
                  (\<Sum>k=1..n. (n choose (k - 1)) * a^k * b^(n+1-k)) +
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   181
                  (\<Sum>k=1..n. (n choose k) * a^k * b^(n+1-k))"
21263
wenzelm
parents: 21256
diff changeset
   182
    by (simp add: decomp2)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   183
  also have
21263
wenzelm
parents: 21256
diff changeset
   184
      "\<dots> = a^(n+1) + b^(n+1) + (\<Sum>k=1..n. (n+1 choose k) * a^k * b^(n+1-k))"
wenzelm
parents: 21256
diff changeset
   185
    by (simp add: nat_distrib setsum_addf binomial.simps)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   186
  also have "\<dots> = (\<Sum>k=0..n+1. (n+1 choose k) * a^k * b^(n+1-k))"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   187
    using decomp by simp
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   188
  finally show ?case by simp
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   189
qed
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   190
29906
80369da39838 section -> subsection
huffman
parents: 29694
diff changeset
   191
subsection{* Pochhammer's symbol : generalized raising factorial*}
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   192
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   193
definition "pochhammer (a::'a::comm_semiring_1) n = (if n = 0 then 1 else setprod (\<lambda>n. a + of_nat n) {0 .. n - 1})"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   194
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   195
lemma pochhammer_0[simp]: "pochhammer a 0 = 1" 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   196
  by (simp add: pochhammer_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   197
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   198
lemma pochhammer_1[simp]: "pochhammer a 1 = a" by (simp add: pochhammer_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   199
lemma pochhammer_Suc0[simp]: "pochhammer a (Suc 0) = a" 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   200
  by (simp add: pochhammer_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   201
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   202
lemma pochhammer_Suc_setprod: "pochhammer a (Suc n) = setprod (\<lambda>n. a + of_nat n) {0 .. n}"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   203
  by (simp add: pochhammer_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   204
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   205
lemma setprod_nat_ivl_Suc: "setprod f {0 .. Suc n} = setprod f {0..n} * f (Suc n)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   206
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   207
  have th: "finite {0..n}" "finite {Suc n}" "{0..n} \<inter> {Suc n} = {}" by auto
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   208
  have eq: "{0..Suc n} = {0..n} \<union> {Suc n}" by auto
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   209
  show ?thesis unfolding eq setprod_Un_disjoint[OF th] by simp
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   210
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   211
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   212
lemma setprod_nat_ivl_1_Suc: "setprod f {0 .. Suc n} = f 0 * setprod f {1.. Suc n}"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   213
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   214
  have th: "finite {0}" "finite {1..Suc n}" "{0} \<inter> {1.. Suc n} = {}" by auto
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   215
  have eq: "{0..Suc n} = {0} \<union> {1 .. Suc n}" by auto
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   216
  show ?thesis unfolding eq setprod_Un_disjoint[OF th] by simp
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   217
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   218
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   219
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   220
lemma pochhammer_Suc: "pochhammer a (Suc n) = pochhammer a n * (a + of_nat n)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   221
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   222
  {assume "n=0" then have ?thesis by simp}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   223
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   224
  {fix m assume m: "n = Suc m"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   225
    have ?thesis  unfolding m pochhammer_Suc_setprod setprod_nat_ivl_Suc ..}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   226
  ultimately show ?thesis by (cases n, auto)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   227
qed 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   228
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   229
lemma pochhammer_rec: "pochhammer a (Suc n) = a * pochhammer (a + 1) n"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   230
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   231
  {assume "n=0" then have ?thesis by (simp add: pochhammer_Suc_setprod)}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   232
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   233
  {assume n0: "n \<noteq> 0"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   234
    have th0: "finite {1 .. n}" "0 \<notin> {1 .. n}" by auto
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   235
    have eq: "insert 0 {1 .. n} = {0..n}" by auto
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   236
    have th1: "(\<Prod>n\<in>{1\<Colon>nat..n}. a + of_nat n) =
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   237
      (\<Prod>n\<in>{0\<Colon>nat..n - 1}. a + 1 + of_nat n)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   238
      apply (rule setprod_reindex_cong[where f = "Suc"])
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   239
      using n0 by (auto simp add: expand_fun_eq ring_simps)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   240
    have ?thesis apply (simp add: pochhammer_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   241
    unfolding setprod_insert[OF th0, unfolded eq]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   242
    using th1 by (simp add: ring_simps)}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   243
ultimately show ?thesis by blast
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   244
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   245
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   246
lemma fact_setprod: "fact n = setprod id {1 .. n}"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   247
  apply (induct n, simp)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   248
  apply (simp only: fact_Suc atLeastAtMostSuc_conv)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   249
  apply (subst setprod_insert)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   250
  by simp_all
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   251
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   252
lemma pochhammer_fact: "of_nat (fact n) = pochhammer 1 n"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   253
  unfolding fact_setprod
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   254
  
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   255
  apply (cases n, simp_all add: of_nat_setprod pochhammer_Suc_setprod)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   256
  apply (rule setprod_reindex_cong[where f=Suc])
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   257
  by (auto simp add: expand_fun_eq)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   258
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   259
lemma pochhammer_of_nat_eq_0_lemma: assumes kn: "k > n"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   260
  shows "pochhammer (- (of_nat n :: 'a:: idom)) k = 0"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   261
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   262
  from kn obtain h where h: "k = Suc h" by (cases k, auto)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   263
  {assume n0: "n=0" then have ?thesis using kn 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   264
      by (cases k, simp_all add: pochhammer_rec del: pochhammer_Suc)}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   265
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   266
  {assume n0: "n \<noteq> 0"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   267
    then have ?thesis apply (simp add: h pochhammer_Suc_setprod)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   268
  apply (rule_tac x="n" in bexI)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   269
  using h kn by auto}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   270
ultimately show ?thesis by blast
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   271
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   272
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   273
lemma pochhammer_of_nat_eq_0_lemma': assumes kn: "k \<le> n"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   274
  shows "pochhammer (- (of_nat n :: 'a:: {idom, ring_char_0})) k \<noteq> 0"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   275
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   276
  {assume "k=0" then have ?thesis by simp}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   277
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   278
  {fix h assume h: "k = Suc h"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   279
    then have ?thesis apply (simp add: pochhammer_Suc_setprod)
30843
3419ca741dbf cleaned up setprod_zero-related lemmas
nipkow
parents: 30663
diff changeset
   280
      using h kn by (auto simp add: algebra_simps)}
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   281
  ultimately show ?thesis by (cases k, auto)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   282
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   283
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   284
lemma pochhammer_of_nat_eq_0_iff: 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   285
  shows "pochhammer (- (of_nat n :: 'a:: {idom, ring_char_0})) k = 0 \<longleftrightarrow> k > n"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   286
  (is "?l = ?r")
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   287
  using pochhammer_of_nat_eq_0_lemma[of n k, where ?'a='a] 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   288
    pochhammer_of_nat_eq_0_lemma'[of k n, where ?'a = 'a]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   289
  by (auto simp add: not_le[symmetric])
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   290
32159
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   291
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   292
lemma pochhammer_eq_0_iff: 
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   293
  "pochhammer a n = (0::'a::field_char_0) \<longleftrightarrow> (EX k < n . a = - of_nat k) "
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   294
  apply (auto simp add: pochhammer_of_nat_eq_0_iff)
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   295
  apply (cases n, auto simp add: pochhammer_def algebra_simps group_add_class.eq_neg_iff_add_eq_0)
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   296
  apply (rule_tac x=x in exI)
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   297
  apply auto
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   298
  done
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   299
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   300
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   301
lemma pochhammer_eq_0_mono: 
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   302
  "pochhammer a n = (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a m = 0"
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   303
  unfolding pochhammer_eq_0_iff by auto 
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   304
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   305
lemma pochhammer_neq_0_mono: 
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   306
  "pochhammer a m \<noteq> (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a n \<noteq> 0"
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   307
  unfolding pochhammer_eq_0_iff by auto 
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   308
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   309
lemma pochhammer_minus:
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   310
  assumes kn: "k \<le> n" 
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   311
  shows "pochhammer (- b) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (b - of_nat k + 1) k"
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   312
proof-
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   313
  {assume k0: "k = 0" then have ?thesis by simp}
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   314
  moreover 
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   315
  {fix h assume h: "k = Suc h"
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   316
    have eq: "((- 1) ^ Suc h :: 'a) = setprod (%i. - 1) {0 .. h}"
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   317
      using setprod_constant[where A="{0 .. h}" and y="- 1 :: 'a"]
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   318
      by auto
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   319
    have ?thesis
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   320
      unfolding h h pochhammer_Suc_setprod eq setprod_timesf[symmetric]
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   321
      apply (rule strong_setprod_reindex_cong[where f = "%i. h - i"])
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   322
      apply (auto simp add: inj_on_def image_def h )
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   323
      apply (rule_tac x="h - x" in bexI)
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   324
      by (auto simp add: expand_fun_eq h of_nat_diff)}
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   325
  ultimately show ?thesis by (cases k, auto)
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   326
qed
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   327
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   328
lemma pochhammer_minus':
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   329
  assumes kn: "k \<le> n" 
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   330
  shows "pochhammer (b - of_nat k + 1) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (- b) k"
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   331
  unfolding pochhammer_minus[OF kn, where b=b]
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   332
  unfolding mult_assoc[symmetric]
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   333
  unfolding power_add[symmetric]
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   334
  apply simp
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   335
  done
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   336
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   337
lemma pochhammer_same: "pochhammer (- of_nat n) n = ((- 1) ^ n :: 'a::comm_ring_1) * of_nat (fact n)"
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   338
  unfolding pochhammer_minus[OF le_refl[of n]]
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   339
  by (simp add: of_nat_diff pochhammer_fact)
4082bd9824c9 More theorems about pochhammer
chaieb
parents: 32158
diff changeset
   340
29906
80369da39838 section -> subsection
huffman
parents: 29694
diff changeset
   341
subsection{* Generalized binomial coefficients *}
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   342
31287
6c593b431f04 use class field_char_0
huffman
parents: 31166
diff changeset
   343
definition gbinomial :: "'a::field_char_0 \<Rightarrow> nat \<Rightarrow> 'a" (infixl "gchoose" 65)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   344
  where "a gchoose n = (if n = 0 then 1 else (setprod (\<lambda>i. a - of_nat i) {0 .. n - 1}) / of_nat (fact n))"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   345
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   346
lemma gbinomial_0[simp]: "a gchoose 0 = 1" "0 gchoose (Suc n) = 0"
30843
3419ca741dbf cleaned up setprod_zero-related lemmas
nipkow
parents: 30663
diff changeset
   347
apply (simp_all add: gbinomial_def)
3419ca741dbf cleaned up setprod_zero-related lemmas
nipkow
parents: 30663
diff changeset
   348
apply (subgoal_tac "(\<Prod>i\<Colon>nat\<in>{0\<Colon>nat..n}. - of_nat i) = (0::'b)")
3419ca741dbf cleaned up setprod_zero-related lemmas
nipkow
parents: 30663
diff changeset
   349
 apply (simp del:setprod_zero_iff)
3419ca741dbf cleaned up setprod_zero-related lemmas
nipkow
parents: 30663
diff changeset
   350
apply simp
3419ca741dbf cleaned up setprod_zero-related lemmas
nipkow
parents: 30663
diff changeset
   351
done
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   352
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   353
lemma gbinomial_pochhammer: "a gchoose n = (- 1) ^ n * pochhammer (- a) n / of_nat (fact n)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   354
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   355
  {assume "n=0" then have ?thesis by simp}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   356
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   357
  {assume n0: "n\<noteq>0"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   358
    from n0 setprod_constant[of "{0 .. n - 1}" "- (1:: 'a)"]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   359
    have eq: "(- (1\<Colon>'a)) ^ n = setprod (\<lambda>i. - 1) {0 .. n - 1}"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   360
      by auto
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   361
    from n0 have ?thesis 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   362
      by (simp add: pochhammer_def gbinomial_def field_simps eq setprod_timesf[symmetric])}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   363
  ultimately show ?thesis by blast
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   364
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   365
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   366
lemma binomial_fact_lemma:
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   367
  "k \<le> n \<Longrightarrow> fact k * fact (n - k) * (n choose k) = fact n"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   368
proof(induct n arbitrary: k rule: nat_less_induct)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   369
  fix n k assume H: "\<forall>m<n. \<forall>x\<le>m. fact x * fact (m - x) * (m choose x) =
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   370
                      fact m" and kn: "k \<le> n"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   371
    let ?ths = "fact k * fact (n - k) * (n choose k) = fact n"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   372
  {assume "n=0" then have ?ths using kn by simp}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   373
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   374
  {assume "k=0" then have ?ths using kn by simp}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   375
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   376
  {assume nk: "n=k" then have ?ths by simp}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   377
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   378
  {fix m h assume n: "n = Suc m" and h: "k = Suc h" and hm: "h < m"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   379
    from n have mn: "m < n" by arith
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   380
    from hm have hm': "h \<le> m" by arith
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   381
    from hm h n kn have km: "k \<le> m" by arith
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   382
    have "m - h = Suc (m - Suc h)" using  h km hm by arith 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   383
    with km h have th0: "fact (m - h) = (m - h) * fact (m - k)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   384
      by simp
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   385
    from n h th0 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   386
    have "fact k * fact (n - k) * (n choose k) = k * (fact h * fact (m - h) * (m choose h)) +  (m - h) * (fact k * fact (m - k) * (m choose k))"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   387
      by (simp add: ring_simps)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   388
    also have "\<dots> = (k + (m - h)) * fact m"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   389
      using H[rule_format, OF mn hm'] H[rule_format, OF mn km]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   390
      by (simp add: ring_simps)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   391
    finally have ?ths using h n km by simp}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   392
  moreover have "n=0 \<or> k = 0 \<or> k = n \<or> (EX m h. n=Suc m \<and> k = Suc h \<and> h < m)" using kn by presburger
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   393
  ultimately show ?ths by blast
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   394
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   395
  
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   396
lemma binomial_fact: 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   397
  assumes kn: "k \<le> n" 
31287
6c593b431f04 use class field_char_0
huffman
parents: 31166
diff changeset
   398
  shows "(of_nat (n choose k) :: 'a::field_char_0) = of_nat (fact n) / (of_nat (fact k) * of_nat (fact (n - k)))"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   399
  using binomial_fact_lemma[OF kn]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   400
  by (simp add: field_simps fact_not_eq_zero of_nat_mult[symmetric])
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   401
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   402
lemma binomial_gbinomial: "of_nat (n choose k) = of_nat n gchoose k"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   403
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   404
  {assume kn: "k > n" 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   405
    from kn binomial_eq_0[OF kn] have ?thesis 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   406
      by (simp add: gbinomial_pochhammer field_simps
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   407
	pochhammer_of_nat_eq_0_iff)}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   408
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   409
  {assume "k=0" then have ?thesis by simp}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   410
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   411
  {assume kn: "k \<le> n" and k0: "k\<noteq> 0"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   412
    from k0 obtain h where h: "k = Suc h" by (cases k, auto)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   413
    from h
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   414
    have eq:"(- 1 :: 'a) ^ k = setprod (\<lambda>i. - 1) {0..h}"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   415
      by (subst setprod_constant, auto)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   416
    have eq': "(\<Prod>i\<in>{0..h}. of_nat n + - (of_nat i :: 'a)) = (\<Prod>i\<in>{n - h..n}. of_nat i)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   417
      apply (rule strong_setprod_reindex_cong[where f="op - n"])
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   418
      using h kn 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   419
      apply (simp_all add: inj_on_def image_iff Bex_def expand_set_eq)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   420
      apply clarsimp
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   421
      apply (presburger)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   422
      apply presburger
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   423
      by (simp add: expand_fun_eq ring_simps of_nat_add[symmetric] del: of_nat_add)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   424
    have th0: "finite {1..n - Suc h}" "finite {n - h .. n}" 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   425
"{1..n - Suc h} \<inter> {n - h .. n} = {}" and eq3: "{1..n - Suc h} \<union> {n - h .. n} = {1..n}" using h kn by auto
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   426
    from eq[symmetric]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   427
    have ?thesis using kn
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   428
      apply (simp add: binomial_fact[OF kn, where ?'a = 'a] 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   429
	gbinomial_pochhammer field_simps pochhammer_Suc_setprod)
30273
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29931
diff changeset
   430
      apply (simp add: pochhammer_Suc_setprod fact_setprod h of_nat_setprod setprod_timesf[symmetric] eq' del: One_nat_def power_Suc)
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   431
      unfolding setprod_Un_disjoint[OF th0, unfolded eq3, of "of_nat:: nat \<Rightarrow> 'a"] eq[unfolded h]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   432
      unfolding mult_assoc[symmetric] 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   433
      unfolding setprod_timesf[symmetric]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   434
      apply simp
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   435
      apply (rule strong_setprod_reindex_cong[where f= "op - n"])
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   436
      apply (auto simp add: inj_on_def image_iff Bex_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   437
      apply presburger
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   438
      apply (subgoal_tac "(of_nat (n - x) :: 'a) = of_nat n - of_nat x")
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   439
      apply simp
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   440
      by (rule of_nat_diff, simp)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   441
  }
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   442
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   443
  have "k > n \<or> k = 0 \<or> (k \<le> n \<and> k \<noteq> 0)" by arith
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   444
  ultimately show ?thesis by blast
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   445
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   446
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   447
lemma gbinomial_1[simp]: "a gchoose 1 = a"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   448
  by (simp add: gbinomial_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   449
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   450
lemma gbinomial_Suc0[simp]: "a gchoose (Suc 0) = a"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   451
  by (simp add: gbinomial_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   452
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   453
lemma gbinomial_mult_1: "a * (a gchoose n) = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))" (is "?l = ?r")
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   454
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   455
  have "?r = ((- 1) ^n * pochhammer (- a) n / of_nat (fact n)) * (of_nat n - (- a + of_nat n))"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   456
    unfolding gbinomial_pochhammer
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   457
    pochhammer_Suc fact_Suc of_nat_mult right_diff_distrib power_Suc
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   458
    by (simp add:  field_simps del: of_nat_Suc)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   459
  also have "\<dots> = ?l" unfolding gbinomial_pochhammer
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   460
    by (simp add: ring_simps)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   461
  finally show ?thesis ..
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   462
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   463
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   464
lemma gbinomial_mult_1': "(a gchoose n) * a = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   465
  by (simp add: mult_commute gbinomial_mult_1)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   466
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   467
lemma gbinomial_Suc: "a gchoose (Suc k) = (setprod (\<lambda>i. a - of_nat i) {0 .. k}) / of_nat (fact (Suc k))"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   468
  by (simp add: gbinomial_def)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   469
 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   470
lemma gbinomial_mult_fact:
31287
6c593b431f04 use class field_char_0
huffman
parents: 31166
diff changeset
   471
  "(of_nat (fact (Suc k)) :: 'a) * ((a::'a::field_char_0) gchoose (Suc k)) = (setprod (\<lambda>i. a - of_nat i) {0 .. k})"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   472
  unfolding gbinomial_Suc
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   473
  by (simp_all add: field_simps del: fact_Suc)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   474
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   475
lemma gbinomial_mult_fact':
31287
6c593b431f04 use class field_char_0
huffman
parents: 31166
diff changeset
   476
  "((a::'a::field_char_0) gchoose (Suc k)) * (of_nat (fact (Suc k)) :: 'a) = (setprod (\<lambda>i. a - of_nat i) {0 .. k})"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   477
  using gbinomial_mult_fact[of k a]
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   478
  apply (subst mult_commute) .
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   479
31287
6c593b431f04 use class field_char_0
huffman
parents: 31166
diff changeset
   480
lemma gbinomial_Suc_Suc: "((a::'a::field_char_0) + 1) gchoose (Suc k) = a gchoose k + (a gchoose (Suc k))"
29694
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   481
proof-
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   482
  {assume "k = 0" then have ?thesis by simp}
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   483
  moreover
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   484
  {fix h assume h: "k = Suc h"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   485
   have eq0: "(\<Prod>i\<in>{1..k}. (a + 1) - of_nat i) = (\<Prod>i\<in>{0..h}. a - of_nat i)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   486
     apply (rule strong_setprod_reindex_cong[where f = Suc])
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   487
     using h by auto
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   488
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   489
    have "of_nat (fact (Suc k)) * (a gchoose k + (a gchoose (Suc k))) = ((a gchoose Suc h) * of_nat (fact (Suc h)) * of_nat (Suc k)) + (\<Prod>i\<in>{0\<Colon>nat..Suc h}. a - of_nat i)" 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   490
      unfolding h
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   491
      apply (simp add: ring_simps del: fact_Suc)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   492
      unfolding gbinomial_mult_fact'
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   493
      apply (subst fact_Suc)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   494
      unfolding of_nat_mult 
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   495
      apply (subst mult_commute)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   496
      unfolding mult_assoc
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   497
      unfolding gbinomial_mult_fact
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   498
      by (simp add: ring_simps)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   499
    also have "\<dots> = (\<Prod>i\<in>{0..h}. a - of_nat i) * (a + 1)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   500
      unfolding gbinomial_mult_fact' setprod_nat_ivl_Suc
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   501
      by (simp add: ring_simps h)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   502
    also have "\<dots> = (\<Prod>i\<in>{0..k}. (a + 1) - of_nat i)"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   503
      using eq0
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   504
      unfolding h  setprod_nat_ivl_1_Suc
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   505
      by simp
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   506
    also have "\<dots> = of_nat (fact (Suc k)) * ((a + 1) gchoose (Suc k))"
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   507
      unfolding gbinomial_mult_fact ..
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   508
    finally have ?thesis by (simp del: fact_Suc) }
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   509
  ultimately show ?thesis by (cases k, auto)
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   510
qed
2f2558d7bc3e Added a formalization of generalized raising Factorials (Pochhammer's symbol) and binomial coefficients
chaieb
parents: 27487
diff changeset
   511
32158
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   512
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   513
lemma binomial_symmetric: assumes kn: "k \<le> n" 
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   514
  shows "n choose k = n choose (n - k)"
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   515
proof-
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   516
  from kn have kn': "n - k \<le> n" by arith
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   517
  from binomial_fact_lemma[OF kn] binomial_fact_lemma[OF kn']
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   518
  have "fact k * fact (n - k) * (n choose k) = fact (n - k) * fact (n - (n - k)) * (n choose (n - k))" by simp
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   519
  then show ?thesis using kn by simp
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   520
qed
4dc119d4fc8b Moved theorem binomial_symmetric from Formal_Power_Series to here
chaieb
parents: 31287
diff changeset
   521
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   522
end