src/HOL/Binomial.thy
author haftmann
Mon, 04 Jul 2016 19:46:19 +0200
changeset 63372 492b49535094
parent 63367 6c731c8b7f03
child 63373 487d764fca4a
permissions -rw-r--r--
relating gbinomial and binomial, still using distinct definitions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
     1
(*  Title       : Binomial.thy
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     2
    Author      : Jacques D. Fleuriot
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     3
    Copyright   : 1998  University of Cambridge
15094
a7d1a3fdc30d conversion of Hyperreal/{Fact,Filter} to Isar scripts
paulson
parents: 12196
diff changeset
     4
    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
63363
bd483ddb17f2 more correct comment
haftmann
parents: 63317
diff changeset
     5
    Various additions by Jeremy Avigad.
61554
84901b8aa4f5 added acknowledgement in Binomial.thy
eberlm
parents: 61552
diff changeset
     6
    Additional binomial identities by Chaitanya Mangla and Manuel Eberl
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     7
*)
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     8
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
     9
section\<open>Factorial Function, Binomial Coefficients and Binomial Theorem\<close>
15094
a7d1a3fdc30d conversion of Hyperreal/{Fact,Filter} to Isar scripts
paulson
parents: 12196
diff changeset
    10
59669
de7792ea4090 renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents: 59667
diff changeset
    11
theory Binomial
33319
74f0dcc0b5fb moved algebraic classes to Ring_and_Field
haftmann
parents: 32558
diff changeset
    12
imports Main
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15094
diff changeset
    13
begin
15094
a7d1a3fdc30d conversion of Hyperreal/{Fact,Filter} to Isar scripts
paulson
parents: 12196
diff changeset
    14
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
    15
subsection \<open>Factorial\<close>
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    16
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    17
definition (in semiring_char_0) fact :: "nat \<Rightarrow> 'a"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    18
where
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    19
  "fact n = of_nat (\<Prod>{1..n})"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    20
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    21
lemma fact_altdef': "fact n = of_nat (\<Prod>{1..n})"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    22
  by (fact fact_def)
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
    23
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    24
lemma fact_altdef_nat: "fact n = \<Prod>{1..n}"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    25
  by (simp add: fact_def)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    26
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    27
lemma fact_altdef: "fact n = (\<Prod>i=1..n. of_nat i)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    28
  by (simp add: fact_def)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    29
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    30
lemma fact_0 [simp]: "fact 0 = 1"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    31
  by (simp add: fact_def)
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    32
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    33
lemma fact_1 [simp]: "fact 1 = 1"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    34
  by (simp add: fact_def)
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    35
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    36
lemma fact_Suc_0 [simp]: "fact (Suc 0) = Suc 0"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    37
  by (simp add: fact_def)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    38
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    39
lemma fact_Suc [simp]: "fact (Suc n) = of_nat (Suc n) * fact n"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    40
  by (simp add: fact_def atLeastAtMostSuc_conv algebra_simps)
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
    41
62347
2230b7047376 generalized some lemmas;
haftmann
parents: 62344
diff changeset
    42
lemma of_nat_fact [simp]:
2230b7047376 generalized some lemmas;
haftmann
parents: 62344
diff changeset
    43
  "of_nat (fact n) = fact n"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    44
  by (simp add: fact_def)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
    45
62347
2230b7047376 generalized some lemmas;
haftmann
parents: 62344
diff changeset
    46
lemma of_int_fact [simp]:
2230b7047376 generalized some lemmas;
haftmann
parents: 62344
diff changeset
    47
  "of_int (fact n) = fact n"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    48
  by (simp only: fact_def of_int_of_nat_eq)
62347
2230b7047376 generalized some lemmas;
haftmann
parents: 62344
diff changeset
    49
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    50
lemma fact_reduce: "n > 0 \<Longrightarrow> fact n = of_nat n * fact (n - 1)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    51
  by (cases n) auto
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
    52
59733
cd945dc13bec more general type class for factorial. Now allows code generation (?)
paulson <lp15@cam.ac.uk>
parents: 59730
diff changeset
    53
lemma fact_nonzero [simp]: "fact n \<noteq> (0::'a::{semiring_char_0,semiring_no_zero_divisors})"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    54
  apply (induct n)
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    55
  apply auto
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    56
  using of_nat_eq_0_iff by fastforce
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    57
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    58
lemma fact_mono_nat: "m \<le> n \<Longrightarrow> fact m \<le> (fact n :: nat)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    59
  by (induct n) (auto simp: le_Suc_eq)
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
    60
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
    61
lemma fact_in_Nats: "fact n \<in> \<nat>" by (induction n) auto
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
    62
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
    63
lemma fact_in_Ints: "fact n \<in> \<int>" by (induction n) auto
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
    64
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    65
context
60241
wenzelm
parents: 59867
diff changeset
    66
  assumes "SORT_CONSTRAINT('a::linordered_semidom)"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
    67
begin
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
    68
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    69
  lemma fact_mono: "m \<le> n \<Longrightarrow> fact m \<le> (fact n :: 'a)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    70
    by (metis of_nat_fact of_nat_le_iff fact_mono_nat)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
    71
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    72
  lemma fact_ge_1 [simp]: "fact n \<ge> (1 :: 'a)"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
    73
    by (metis le0 fact_0 fact_mono)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
    74
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    75
  lemma fact_gt_zero [simp]: "fact n > (0 :: 'a)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    76
    using fact_ge_1 less_le_trans zero_less_one by blast
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
    77
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    78
  lemma fact_ge_zero [simp]: "fact n \<ge> (0 :: 'a)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    79
    by (simp add: less_imp_le)
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
    80
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    81
  lemma fact_not_neg [simp]: "~ (fact n < (0 :: 'a))"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    82
    by (simp add: not_less_iff_gr_or_eq)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
    83
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    84
  lemma fact_le_power:
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    85
      "fact n \<le> (of_nat (n^n) ::'a)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    86
  proof (induct n)
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    87
    case (Suc n)
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    88
    then have *: "fact n \<le> (of_nat (Suc n ^ n) ::'a)"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61554
diff changeset
    89
      by (rule order_trans) (simp add: power_mono del: of_nat_power)
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    90
    have "fact (Suc n) = (of_nat (Suc n) * fact n ::'a)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    91
      by (simp add: algebra_simps)
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    92
    also have "... \<le> (of_nat (Suc n) * of_nat (Suc n ^ n) ::'a)"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61554
diff changeset
    93
      by (simp add: "*" ordered_comm_semiring_class.comm_mult_left_mono del: of_nat_power)
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    94
    also have "... \<le> (of_nat (Suc n ^ Suc n) ::'a)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    95
      by (metis of_nat_mult order_refl power_Suc)
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    96
    finally show ?case .
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
    97
  qed simp
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
    98
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
    99
end
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
   100
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   101
text\<open>Note that @{term "fact 0 = fact 1"}\<close>
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   102
lemma fact_less_mono_nat: "\<lbrakk>0 < m; m < n\<rbrakk> \<Longrightarrow> fact m < (fact n :: nat)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   103
  by (induct n) (auto simp: less_Suc_eq)
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
   104
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   105
lemma fact_less_mono:
60241
wenzelm
parents: 59867
diff changeset
   106
  "\<lbrakk>0 < m; m < n\<rbrakk> \<Longrightarrow> fact m < (fact n :: 'a::linordered_semidom)"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   107
  by (metis of_nat_fact of_nat_less_iff fact_less_mono_nat)
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
   108
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   109
lemma fact_ge_Suc_0_nat [simp]: "fact n \<ge> Suc 0"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   110
  by (metis One_nat_def fact_ge_1)
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
   111
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   112
lemma dvd_fact:
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   113
  shows "1 \<le> m \<Longrightarrow> m \<le> n \<Longrightarrow> m dvd fact n"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   114
  by (induct n) (auto simp: dvdI le_Suc_eq)
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
   115
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
   116
lemma fact_ge_self: "fact n \<ge> n"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
   117
  by (cases "n = 0") (simp_all add: dvd_imp_le dvd_fact)
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
   118
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   119
lemma fact_dvd: "n \<le> m \<Longrightarrow> fact n dvd (fact m :: 'a :: {semiring_div,linordered_semidom})"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   120
  by (induct m) (auto simp: le_Suc_eq)
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
   121
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   122
lemma fact_mod: "m \<le> n \<Longrightarrow> fact n mod (fact m :: 'a :: {semiring_div,linordered_semidom}) = 0"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   123
  by (auto simp add: fact_dvd)
40033
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   124
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   125
lemma fact_div_fact:
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   126
  assumes "m \<ge> n"
40033
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   127
  shows "(fact m) div (fact n) = \<Prod>{n + 1..m}"
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   128
proof -
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   129
  obtain d where "d = m - n" by auto
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   130
  from assms this have "m = n + d" by auto
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   131
  have "fact (n + d) div (fact n) = \<Prod>{n + 1..n + d}"
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   132
  proof (induct d)
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   133
    case 0
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   134
    show ?case by simp
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   135
  next
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   136
    case (Suc d')
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   137
    have "fact (n + Suc d') div fact n = Suc (n + d') * fact (n + d') div fact n"
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   138
      by simp
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   139
    also from Suc.hyps have "... = Suc (n + d') * \<Prod>{n + 1..n + d'}"
40033
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   140
      unfolding div_mult1_eq[of _ "fact (n + d')"] by (simp add: fact_mod)
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   141
    also have "... = \<Prod>{n + 1..n + Suc d'}"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   142
      by (simp add: atLeastAtMostSuc_conv)
40033
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   143
    finally show ?case .
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   144
  qed
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   145
  from this \<open>m = n + d\<close> show ?thesis by simp
40033
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   146
qed
84200d970bf0 added some facts about factorial and dvd, div and mod
bulwahn
parents: 35644
diff changeset
   147
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   148
lemma fact_num_eq_if:
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   149
    "fact m = (if m=0 then 1 else of_nat m * fact (m - 1))"
32036
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
   150
by (cases m) auto
8a9228872fbd Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents: 30242
diff changeset
   151
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   152
lemma fact_eq_rev_setprod_nat: "fact k = (\<Prod>i<k. k - i)"
50224
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 46240
diff changeset
   153
  unfolding fact_altdef_nat
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 57113
diff changeset
   154
  by (rule setprod.reindex_bij_witness[where i="\<lambda>i. k - i" and j="\<lambda>i. k - i"]) auto
50224
aacd6da09825 add binomial_ge_n_over_k_pow_k
hoelzl
parents: 46240
diff changeset
   155
50240
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   156
lemma fact_div_fact_le_pow:
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   157
  assumes "r \<le> n" shows "fact n div fact (n - r) \<le> n ^ r"
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   158
proof -
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   159
  have "\<And>r. r \<le> n \<Longrightarrow> \<Prod>{n - r..n} = (n - r) * \<Prod>{Suc (n - r)..n}"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   160
    by (subst setprod.insert[symmetric]) (auto simp: atLeastAtMost_insertL)
50240
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   161
  with assms show ?thesis
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   162
    by (induct r rule: nat.induct) (auto simp add: fact_div_fact Suc_diff_Suc mult_le_mono)
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   163
qed
019d642d422d add upper bounds for factorial and binomial; add equation for binomial using nat-division (both from AFP/Girth_Chromatic)
hoelzl
parents: 50224
diff changeset
   164
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61738
diff changeset
   165
lemma fact_numeral:  \<comment>\<open>Evaluation for specific numerals\<close>
57113
7e95523302e6 New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
paulson <lp15@cam.ac.uk>
parents: 50240
diff changeset
   166
  "fact (numeral k) = (numeral k) * (fact (pred_numeral k))"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   167
  by (metis fact_Suc numeral_eq_Suc of_nat_numeral)
57113
7e95523302e6 New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
paulson <lp15@cam.ac.uk>
parents: 50240
diff changeset
   168
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   169
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   170
text \<open>This development is based on the work of Andy Gordon and
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   171
  Florian Kammueller.\<close>
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   172
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   173
subsection \<open>Basic definitions and lemmas\<close>
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   174
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   175
text \<open>Combinatorial definition\<close>
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   176
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   177
definition binomial :: "nat \<Rightarrow> nat \<Rightarrow> nat" (infixl "choose" 65)
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   178
where
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   179
  "n choose k = card {K\<in>Pow {..<n}. card K = k}"
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   180
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   181
theorem n_subsets:
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   182
  assumes "finite A"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   183
  shows "card {B. B \<subseteq> A \<and> card B = k} = card A choose k"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   184
proof -
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   185
  from assms obtain f where bij: "bij_betw f {..<card A} A"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   186
    by (blast elim: bij_betw_nat_finite)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   187
  then have [simp]: "card (f ` C) = card C" if "C \<subseteq> {..<card A}" for C
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   188
    by (meson bij_betw_imp_inj_on bij_betw_subset card_image that)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   189
  from bij have "bij_betw (image f) (Pow {..<card A}) (Pow A)"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   190
    by (rule bij_betw_Pow)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   191
  then have "inj_on (image f) (Pow {..<card A})"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   192
    by (rule bij_betw_imp_inj_on)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   193
  moreover have "{K. K \<subseteq> {..<card A} \<and> card K = k} \<subseteq> Pow {..<card A}"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   194
    by auto
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   195
  ultimately have "inj_on (image f) {K. K \<subseteq> {..<card A} \<and> card K = k}"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   196
    by (rule inj_on_subset)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   197
  then have "card {K. K \<subseteq> {..<card A} \<and> card K = k} =
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   198
    card (image f ` {K. K \<subseteq> {..<card A} \<and> card K = k})" (is "_ = card ?C")
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   199
    by (simp add: card_image)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   200
  also have "?C = {K. K \<subseteq> f ` {..<card A} \<and> card K = k}"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   201
    by (auto elim!: subset_imageE)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   202
  also have "f ` {..<card A} = A"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   203
    by (meson bij bij_betw_def)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   204
  finally show ?thesis
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   205
    by (simp add: binomial_def)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   206
qed
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   207
    
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   208
text \<open>Recursive characterization\<close>
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   209
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   210
lemma binomial_n_0 [simp, code]:
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   211
  "n choose 0 = 1"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   212
proof -
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   213
  have "{K \<in> Pow {..<n}. card K = 0} = {{}}"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   214
    by (auto dest: subset_eq_range_finite) 
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   215
  then show ?thesis
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   216
    by (simp add: binomial_def)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   217
qed
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   218
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   219
lemma binomial_0_Suc [simp, code]:
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   220
  "0 choose Suc k = 0"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   221
  by (simp add: binomial_def)
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   222
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   223
lemma binomial_Suc_Suc [simp, code]:
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   224
  "Suc n choose Suc k = (n choose k) + (n choose Suc k)"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   225
proof -
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   226
  let ?P = "\<lambda>n k. {K. K \<subseteq> {..<n} \<and> card K = k}"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   227
  let ?Q = "?P (Suc n) (Suc k)"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   228
  have inj: "inj_on (insert n) (?P n k)"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   229
    by rule auto
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   230
  have disjoint: "insert n ` ?P n k \<inter> ?P n (Suc k) = {}"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   231
    by auto
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   232
  have "?Q = {K\<in>?Q. n \<in> K} \<union> {K\<in>?Q. n \<notin> K}"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   233
    by auto
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   234
  also have "{K\<in>?Q. n \<in> K} = insert n ` ?P n k" (is "?A = ?B")
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   235
  proof (rule set_eqI)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   236
    fix K
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   237
    have K_finite: "finite K" if "K \<subseteq> insert n {..<n}"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   238
      using that by (rule finite_subset) simp_all
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   239
    have Suc_card_K: "Suc (card K - Suc 0) = card K" if "n \<in> K"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   240
      and "finite K"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   241
    proof -
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   242
      from \<open>n \<in> K\<close> obtain L where "K = insert n L" and "n \<notin> L"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   243
        by (blast elim: Set.set_insert)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   244
      with that show ?thesis by (simp add: card_insert)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   245
    qed
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   246
    show "K \<in> ?A \<longleftrightarrow> K \<in> ?B"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   247
      by (subst in_image_insert_iff)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   248
        (auto simp add: card_insert subset_eq_range_finite Diff_subset_conv K_finite Suc_card_K)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   249
  qed    
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   250
  also have "{K\<in>?Q. n \<notin> K} = ?P n (Suc k)"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   251
    by (auto simp add: lessThan_Suc)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   252
  finally show ?thesis using inj disjoint
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   253
    by (simp add: binomial_def card_Un_disjoint card_image)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   254
qed
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   255
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   256
lemma binomial_eq_0:
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   257
  "n < k \<Longrightarrow> n choose k = 0"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   258
  by (auto simp add: binomial_def dest: subset_eq_range_card)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   259
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   260
lemma zero_less_binomial: "k \<le> n \<Longrightarrow> n choose k > 0"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   261
  by (induct n k rule: diff_induct) simp_all
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   262
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   263
lemma binomial_eq_0_iff [simp]:
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   264
  "n choose k = 0 \<longleftrightarrow> n < k"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   265
  by (metis binomial_eq_0 less_numeral_extra(3) not_less zero_less_binomial)
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   266
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   267
lemma zero_less_binomial_iff [simp]:
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   268
  "n choose k > 0 \<longleftrightarrow> k \<le> n"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   269
  by (metis binomial_eq_0_iff not_less0 not_less zero_less_binomial)
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   270
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   271
lemma binomial_n_n [simp]: "n choose n = 1"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   272
  by (induct n) (simp_all add: binomial_eq_0)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   273
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   274
lemma binomial_Suc_n [simp]: "Suc n choose n = Suc n"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   275
  by (induct n) simp_all
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   276
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   277
lemma binomial_1 [simp]: "n choose Suc 0 = n"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   278
  by (induct n) simp_all
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   279
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   280
lemma choose_reduce_nat:
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   281
  "0 < (n::nat) \<Longrightarrow> 0 < k \<Longrightarrow>
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   282
    (n choose k) = ((n - 1) choose (k - 1)) + ((n - 1) choose k)"
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   283
  using binomial_Suc_Suc [of "n - 1" "k - 1"] by simp
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   284
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   285
lemma Suc_times_binomial_eq:
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   286
  "Suc n * (n choose k) = (Suc n choose Suc k) * Suc k"
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   287
  apply (induct n arbitrary: k)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   288
  apply simp apply arith
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   289
  apply (case_tac k)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   290
   apply (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq binomial_eq_0)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   291
  done
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   292
60141
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   293
lemma binomial_le_pow2: "n choose k \<le> 2^n"
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   294
  apply (induct n arbitrary: k)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   295
  apply (case_tac k) apply simp_all
60141
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   296
  apply (case_tac k)
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   297
  apply auto
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   298
  apply (simp add: add_le_mono mult_2)
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   299
  done
60141
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   300
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   301
text\<open>The absorption property\<close>
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   302
lemma Suc_times_binomial:
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   303
  "Suc k * (Suc n choose Suc k) = Suc n * (n choose k)"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   304
  using Suc_times_binomial_eq by auto
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   305
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   306
text\<open>This is the well-known version of absorption, but it's harder to use because of the
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   307
  need to reason about division.\<close>
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   308
lemma binomial_Suc_Suc_eq_times:
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   309
    "(Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   310
  by (simp add: Suc_times_binomial_eq del: mult_Suc mult_Suc_right)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   311
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   312
text\<open>Another version of absorption, with -1 instead of Suc.\<close>
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   313
lemma times_binomial_minus1_eq:
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   314
  "0 < k \<Longrightarrow> k * (n choose k) = n * ((n - 1) choose (k - 1))"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   315
  using Suc_times_binomial_eq [where n = "n - 1" and k = "k - 1"]
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   316
  by (auto split add: nat_diff_split)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   317
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   318
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   319
subsection \<open>The binomial theorem (courtesy of Tobias Nipkow):\<close>
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   320
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   321
text\<open>Avigad's version, generalized to any commutative ring\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   322
theorem binomial_ring: "(a+b::'a::{comm_ring_1,power})^n =
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   323
  (\<Sum>k=0..n. (of_nat (n choose k)) * a^k * b^(n-k))" (is "?P n")
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   324
proof (induct n)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   325
  case 0 then show "?P 0" by simp
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   326
next
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   327
  case (Suc n)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   328
  have decomp: "{0..n+1} = {0} Un {n+1} Un {1..n}"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   329
    by auto
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   330
  have decomp2: "{0..n} = {0} Un {1..n}"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   331
    by auto
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   332
  have "(a+b)^(n+1) =
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   333
      (a+b) * (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k))"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   334
    using Suc.hyps by simp
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   335
  also have "\<dots> = a*(\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k)) +
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   336
                   b*(\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k))"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   337
    by (rule distrib_right)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   338
  also have "\<dots> = (\<Sum>k=0..n. of_nat (n choose k) * a^(k+1) * b^(n-k)) +
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   339
                  (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k+1))"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   340
    by (auto simp add: setsum_right_distrib ac_simps)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   341
  also have "\<dots> = (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n+1-k)) +
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   342
                  (\<Sum>k=1..n+1. of_nat (n choose (k - 1)) * a^k * b^(n+1-k))"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   343
    by (simp add:setsum_shift_bounds_cl_Suc_ivl Suc_diff_le field_simps
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   344
        del:setsum_cl_ivl_Suc)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   345
  also have "\<dots> = a^(n+1) + b^(n+1) +
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   346
                  (\<Sum>k=1..n. of_nat (n choose (k - 1)) * a^k * b^(n+1-k)) +
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   347
                  (\<Sum>k=1..n. of_nat (n choose k) * a^k * b^(n+1-k))"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   348
    by (simp add: decomp2)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   349
  also have
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   350
      "\<dots> = a^(n+1) + b^(n+1) +
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   351
            (\<Sum>k=1..n. of_nat(n+1 choose k) * a^k * b^(n+1-k))"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   352
    by (auto simp add: field_simps setsum.distrib [symmetric] choose_reduce_nat)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   353
  also have "\<dots> = (\<Sum>k=0..n+1. of_nat (n+1 choose k) * a^k * b^(n+1-k))"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   354
    using decomp by (simp add: field_simps)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   355
  finally show "?P (Suc n)" by simp
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   356
qed
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   357
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   358
text\<open>Original version for the naturals\<close>
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   359
corollary binomial: "(a+b::nat)^n = (\<Sum>k=0..n. (of_nat (n choose k)) * a^k * b^(n-k))"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   360
    using binomial_ring [of "int a" "int b" n]
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   361
  by (simp only: of_nat_add [symmetric] of_nat_mult [symmetric] of_nat_power [symmetric]
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   362
           of_nat_setsum [symmetric]
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   363
           of_nat_eq_iff of_nat_id)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   364
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   365
lemma binomial_fact_lemma: "k \<le> n \<Longrightarrow> fact k * fact (n - k) * (n choose k) = fact n"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   366
proof (induct n arbitrary: k rule: nat_less_induct)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   367
  fix n k assume H: "\<forall>m<n. \<forall>x\<le>m. fact x * fact (m - x) * (m choose x) =
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   368
                      fact m" and kn: "k \<le> n"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   369
  let ?ths = "fact k * fact (n - k) * (n choose k) = fact n"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   370
  { assume "n=0" then have ?ths using kn by simp }
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   371
  moreover
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   372
  { assume "k=0" then have ?ths using kn by simp }
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   373
  moreover
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   374
  { assume nk: "n=k" then have ?ths by simp }
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   375
  moreover
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   376
  { fix m h assume n: "n = Suc m" and h: "k = Suc h" and hm: "h < m"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   377
    from n have mn: "m < n" by arith
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   378
    from hm have hm': "h \<le> m" by arith
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   379
    from hm h n kn have km: "k \<le> m" by arith
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   380
    have "m - h = Suc (m - Suc h)" using  h km hm by arith
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   381
    with km h have th0: "fact (m - h) = (m - h) * fact (m - k)"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   382
      by simp
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   383
    from n h th0
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   384
    have "fact k * fact (n - k) * (n choose k) =
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   385
        k * (fact h * fact (m - h) * (m choose h)) +
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   386
        (m - h) * (fact k * fact (m - k) * (m choose k))"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   387
      by (simp add: field_simps)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   388
    also have "\<dots> = (k + (m - h)) * fact m"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   389
      using H[rule_format, OF mn hm'] H[rule_format, OF mn km]
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   390
      by (simp add: field_simps)
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   391
    finally have ?ths using h n km by simp }
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   392
  moreover have "n=0 \<or> k = 0 \<or> k = n \<or> (\<exists>m h. n = Suc m \<and> k = Suc h \<and> h < m)"
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   393
    using kn by presburger
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   394
  ultimately show ?ths by blast
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   395
qed
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   396
63372
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   397
lemma binomial_fact':
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   398
  assumes "k \<le> n"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   399
  shows "n choose k = fact n div (fact k * fact (n - k))"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   400
  using binomial_fact_lemma [OF assms]
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   401
  by (metis fact_nonzero mult_eq_0_iff nonzero_mult_divide_cancel_left)
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   402
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   403
lemma binomial_fact:
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   404
  assumes kn: "k \<le> n"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   405
  shows "(of_nat (n choose k) :: 'a::field_char_0) =
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   406
         (fact n) / (fact k * fact(n - k))"
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   407
  using binomial_fact_lemma[OF kn]
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   408
  apply (simp add: field_simps)
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   409
  by (metis mult.commute of_nat_fact of_nat_mult)
59658
0cc388370041 sin, cos generalised from type real to any "'a::{real_normed_field,banach}", including complex
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   410
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   411
lemma choose_row_sum: "(\<Sum>k=0..n. n choose k) = 2^n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   412
  using binomial [of 1 "1" n]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   413
  by (simp add: numeral_2_eq_2)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   414
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   415
lemma sum_choose_lower: "(\<Sum>k=0..n. (r+k) choose k) = Suc (r+n) choose n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   416
  by (induct n) auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   417
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   418
lemma sum_choose_upper: "(\<Sum>k=0..n. k choose m) = Suc n choose Suc m"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   419
  by (induct n) auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   420
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   421
lemma choose_alternating_sum:
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   422
  "n > 0 \<Longrightarrow> (\<Sum>i\<le>n. (-1)^i * of_nat (n choose i)) = (0 :: 'a :: comm_ring_1)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   423
  using binomial_ring[of "-1 :: 'a" 1 n] by (simp add: atLeast0AtMost mult_of_nat_commute zero_power)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   424
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   425
lemma choose_even_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   426
  assumes "n > 0"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   427
  shows   "2 * (\<Sum>i\<le>n. if even i then of_nat (n choose i) else 0) = (2 ^ n :: 'a :: comm_ring_1)"
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   428
proof -
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   429
  have "2 ^ n = (\<Sum>i\<le>n. of_nat (n choose i)) + (\<Sum>i\<le>n. (-1) ^ i * of_nat (n choose i) :: 'a)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   430
    using choose_row_sum[of n]
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   431
    by (simp add: choose_alternating_sum assms atLeast0AtMost of_nat_setsum[symmetric])
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   432
  also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) + (-1) ^ i * of_nat (n choose i))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   433
    by (simp add: setsum.distrib)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   434
  also have "\<dots> = 2 * (\<Sum>i\<le>n. if even i then of_nat (n choose i) else 0)"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   435
    by (subst setsum_right_distrib, intro setsum.cong) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   436
  finally show ?thesis ..
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   437
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   438
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   439
lemma choose_odd_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   440
  assumes "n > 0"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   441
  shows   "2 * (\<Sum>i\<le>n. if odd i then of_nat (n choose i) else 0) = (2 ^ n :: 'a :: comm_ring_1)"
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   442
proof -
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   443
  have "2 ^ n = (\<Sum>i\<le>n. of_nat (n choose i)) - (\<Sum>i\<le>n. (-1) ^ i * of_nat (n choose i) :: 'a)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   444
    using choose_row_sum[of n]
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   445
    by (simp add: choose_alternating_sum assms atLeast0AtMost of_nat_setsum[symmetric])
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   446
  also have "\<dots> = (\<Sum>i\<le>n. of_nat (n choose i) - (-1) ^ i * of_nat (n choose i))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   447
    by (simp add: setsum_subtractf)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   448
  also have "\<dots> = 2 * (\<Sum>i\<le>n. if odd i then of_nat (n choose i) else 0)"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   449
    by (subst setsum_right_distrib, intro setsum.cong) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   450
  finally show ?thesis ..
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   451
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   452
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   453
lemma choose_row_sum': "(\<Sum>k\<le>n. (n choose k)) = 2 ^ n"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   454
  using choose_row_sum[of n] by (simp add: atLeast0AtMost)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   455
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   456
lemma natsum_reverse_index:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   457
  fixes m::nat
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   458
  shows "(\<And>k. m \<le> k \<Longrightarrow> k \<le> n \<Longrightarrow> g k = f (m + n - k)) \<Longrightarrow> (\<Sum>k=m..n. f k) = (\<Sum>k=m..n. g k)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   459
  by (rule setsum.reindex_bij_witness[where i="\<lambda>k. m+n-k" and j="\<lambda>k. m+n-k"]) auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   460
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   461
text\<open>NW diagonal sum property\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   462
lemma sum_choose_diagonal:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   463
  assumes "m\<le>n" shows "(\<Sum>k=0..m. (n-k) choose (m-k)) = Suc n choose m"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   464
proof -
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   465
  have "(\<Sum>k=0..m. (n-k) choose (m-k)) = (\<Sum>k=0..m. (n-m+k) choose k)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   466
    by (rule natsum_reverse_index) (simp add: assms)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   467
  also have "... = Suc (n-m+m) choose m"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   468
    by (rule sum_choose_lower)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   469
  also have "... = Suc n choose m" using assms
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   470
    by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   471
  finally show ?thesis .
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   472
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   473
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   474
subsection\<open>Pochhammer's symbol : generalized rising factorial\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   475
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   476
text \<open>See @{url "http://en.wikipedia.org/wiki/Pochhammer_symbol"}\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   477
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   478
definition (in comm_semiring_1) pochhammer :: "'a \<Rightarrow> nat \<Rightarrow> 'a"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   479
where
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   480
  "pochhammer (a :: 'a) n = setprod (\<lambda>n. a + of_nat n) {..<n}"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   481
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   482
lemma pochhammer_Suc_setprod:
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   483
  "pochhammer a (Suc n) = setprod (\<lambda>n. a + of_nat n) {..n}"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   484
  by (simp add: pochhammer_def lessThan_Suc_atMost)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   485
 
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   486
lemma pochhammer_0 [simp]: "pochhammer a 0 = 1"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   487
  by (simp add: pochhammer_def)
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   488
 
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   489
lemma pochhammer_1 [simp]: "pochhammer a 1 = a"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   490
  by (simp add: pochhammer_def lessThan_Suc)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   491
 
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   492
lemma pochhammer_Suc0 [simp]: "pochhammer a (Suc 0) = a"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   493
  by (simp add: pochhammer_def lessThan_Suc)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   494
 
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   495
lemma pochhammer_Suc: "pochhammer a (Suc n) = pochhammer a n * (a + of_nat n)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   496
  by (simp add: pochhammer_def lessThan_Suc ac_simps)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   497
 
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   498
lemma pochhammer_of_nat: "pochhammer (of_nat x) n = of_nat (pochhammer x n)"
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   499
  by (simp add: pochhammer_def)
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   500
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   501
lemma pochhammer_of_int: "pochhammer (of_int x) n = of_int (pochhammer x n)"
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   502
  by (simp add: pochhammer_def)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   503
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   504
lemma setprod_nat_ivl_Suc: "setprod f {.. Suc n} = setprod f {..n} * f (Suc n)"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   505
proof -
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   506
  have "{..Suc n} = {..n} \<union> {Suc n}" by auto
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   507
  then show ?thesis by (simp add: field_simps)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   508
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   509
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   510
lemma setprod_nat_ivl_1_Suc: "setprod f {.. Suc n} = f 0 * setprod f {1.. Suc n}"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   511
proof -
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   512
  have "{..Suc n} = {0} \<union> {1 .. Suc n}" by auto
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   513
  then show ?thesis by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   514
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   515
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   516
lemma pochhammer_rec: "pochhammer a (Suc n) = a * pochhammer (a + 1) n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   517
proof (cases "n = 0")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   518
  case True
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   519
  then show ?thesis by (simp add: pochhammer_Suc_setprod)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   520
next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   521
  case False
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   522
  have *: "finite {1 .. n}" "0 \<notin> {1 .. n}" by auto
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   523
  have eq: "insert 0 {1 .. n} = {..n}" by auto
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   524
  have **: "(\<Prod>n\<in>{1..n}. a + of_nat n) = (\<Prod>n\<in>{..<n}. a + 1 + of_nat n)"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   525
    apply (rule setprod.reindex_cong [where l = Suc])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   526
    using False
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   527
    apply (auto simp add: fun_eq_iff field_simps image_Suc_lessThan)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   528
    done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   529
  show ?thesis
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   530
    apply (simp add: pochhammer_def lessThan_Suc_atMost)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   531
    unfolding setprod.insert [OF *, unfolded eq]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   532
    using ** apply (simp add: field_simps)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   533
    done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   534
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   535
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   536
lemma pochhammer_rec': "pochhammer z (Suc n) = (z + of_nat n) * pochhammer z n"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   537
proof (induction n arbitrary: z)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   538
  case (Suc n z)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   539
  have "pochhammer z (Suc (Suc n)) = z * pochhammer (z + 1) (Suc n)"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   540
    by (simp add: pochhammer_rec)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   541
  also note Suc
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   542
  also have "z * ((z + 1 + of_nat n) * pochhammer (z + 1) n) =
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   543
               (z + of_nat (Suc n)) * pochhammer z (Suc n)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   544
    by (simp_all add: pochhammer_rec algebra_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   545
  finally show ?case .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   546
qed simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   547
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   548
lemma pochhammer_fact: "fact n = pochhammer 1 n"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   549
  apply (auto simp add: pochhammer_def fact_altdef)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   550
  apply (rule setprod.reindex_cong [where l = Suc])
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   551
  apply (auto simp add: image_Suc_lessThan)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   552
  done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   553
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   554
lemma pochhammer_of_nat_eq_0_lemma:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   555
  assumes "k > n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   556
  shows "pochhammer (- (of_nat n :: 'a:: idom)) k = 0"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   557
  using assms by (auto simp add: pochhammer_def)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   558
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   559
lemma pochhammer_of_nat_eq_0_lemma':
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   560
  assumes kn: "k \<le> n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   561
  shows "pochhammer (- (of_nat n :: 'a:: {idom,ring_char_0})) k \<noteq> 0"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   562
proof (cases k)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   563
  case 0
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   564
  then show ?thesis by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   565
next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   566
  case (Suc h)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   567
  then show ?thesis
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   568
    apply (simp add: pochhammer_Suc_setprod)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   569
    using Suc kn apply (auto simp add: algebra_simps)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   570
    done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   571
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   572
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   573
lemma pochhammer_of_nat_eq_0_iff:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   574
  shows "pochhammer (- (of_nat n :: 'a:: {idom,ring_char_0})) k = 0 \<longleftrightarrow> k > n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   575
  (is "?l = ?r")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   576
  using pochhammer_of_nat_eq_0_lemma[of n k, where ?'a='a]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   577
    pochhammer_of_nat_eq_0_lemma'[of k n, where ?'a = 'a]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   578
  by (auto simp add: not_le[symmetric])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   579
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   580
lemma pochhammer_eq_0_iff: "pochhammer a n = (0::'a::field_char_0) \<longleftrightarrow> (\<exists>k < n. a = - of_nat k)"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   581
  by (auto simp add: pochhammer_def eq_neg_iff_add_eq_0)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   582
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   583
lemma pochhammer_eq_0_mono:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   584
  "pochhammer a n = (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a m = 0"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   585
  unfolding pochhammer_eq_0_iff by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   586
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   587
lemma pochhammer_neq_0_mono:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   588
  "pochhammer a m \<noteq> (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a n \<noteq> 0"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   589
  unfolding pochhammer_eq_0_iff by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   590
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   591
lemma pochhammer_minus:
59862
44b3f4fa33ca New material and binomial fix
paulson <lp15@cam.ac.uk>
parents: 59733
diff changeset
   592
    "pochhammer (- b) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (b - of_nat k + 1) k"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   593
proof (cases k)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   594
  case 0
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   595
  then show ?thesis by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   596
next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   597
  case (Suc h)
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   598
  have eq: "((- 1) ^ Suc h :: 'a) = (\<Prod>i\<le>h. - 1)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   599
    using setprod_constant[where A="{.. h}" and y="- 1 :: 'a"]
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   600
    by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   601
  show ?thesis
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   602
    unfolding Suc pochhammer_Suc_setprod eq setprod.distrib[symmetric]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   603
    by (rule setprod.reindex_bij_witness[where i="op - h" and j="op - h"])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   604
       (auto simp: of_nat_diff)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   605
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   606
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   607
lemma pochhammer_minus':
59862
44b3f4fa33ca New material and binomial fix
paulson <lp15@cam.ac.uk>
parents: 59733
diff changeset
   608
    "pochhammer (b - of_nat k + 1) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (- b) k"
44b3f4fa33ca New material and binomial fix
paulson <lp15@cam.ac.uk>
parents: 59733
diff changeset
   609
  unfolding pochhammer_minus[where b=b]
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   610
  unfolding mult.assoc[symmetric]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   611
  unfolding power_add[symmetric]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   612
  by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   613
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   614
lemma pochhammer_same: "pochhammer (- of_nat n) n =
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   615
    ((- 1) ^ n :: 'a::{semiring_char_0,comm_ring_1,semiring_no_zero_divisors}) * (fact n)"
59862
44b3f4fa33ca New material and binomial fix
paulson <lp15@cam.ac.uk>
parents: 59733
diff changeset
   616
  unfolding pochhammer_minus
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   617
  by (simp add: of_nat_diff pochhammer_fact)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   618
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   619
lemma pochhammer_product':
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   620
  "pochhammer z (n + m) = pochhammer z n * pochhammer (z + of_nat n) m"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   621
proof (induction n arbitrary: z)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   622
  case (Suc n z)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   623
  have "pochhammer z (Suc n) * pochhammer (z + of_nat (Suc n)) m =
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   624
            z * (pochhammer (z + 1) n * pochhammer (z + 1 + of_nat n) m)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   625
    by (simp add: pochhammer_rec ac_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   626
  also note Suc[symmetric]
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   627
  also have "z * pochhammer (z + 1) (n + m) = pochhammer z (Suc (n + m))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   628
    by (subst pochhammer_rec) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   629
  finally show ?case by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   630
qed simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   631
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   632
lemma pochhammer_product:
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   633
  "m \<le> n \<Longrightarrow> pochhammer z n = pochhammer z m * pochhammer (z + of_nat m) (n - m)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   634
  using pochhammer_product'[of z m "n - m"] by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   635
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   636
lemma pochhammer_times_pochhammer_half:
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   637
  fixes z :: "'a :: field_char_0"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   638
  shows "pochhammer z (Suc n) * pochhammer (z + 1/2) (Suc n) = (\<Prod>k\<le>2*n+1. z + of_nat k / 2)"
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   639
proof (induction n)
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   640
  case (Suc n)
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62481
diff changeset
   641
  define n' where "n' = Suc n"
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   642
  have "pochhammer z (Suc n') * pochhammer (z + 1 / 2) (Suc n') =
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   643
          (pochhammer z n' * pochhammer (z + 1 / 2) n') *
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   644
          ((z + of_nat n') * (z + 1/2 + of_nat n'))" (is "_ = _ * ?A")
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   645
     by (simp_all add: pochhammer_rec' mult_ac)
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   646
  also have "?A = (z + of_nat (Suc (2 * n + 1)) / 2) * (z + of_nat (Suc (Suc (2 * n + 1))) / 2)"
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   647
    (is "_ = ?A") by (simp add: field_simps n'_def)
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   648
  also note Suc[folded n'_def]
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   649
  also have "(\<Prod>k\<le>2 * n + 1. z + of_nat k / 2) * ?A = (\<Prod>k\<le>2 * Suc n + 1. z + of_nat k / 2)"
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   650
    by (simp add: setprod_nat_ivl_Suc)
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   651
  finally show ?case by (simp add: n'_def)
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   652
qed (simp add: setprod_nat_ivl_Suc)
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   653
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   654
lemma pochhammer_double:
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   655
  fixes z :: "'a :: field_char_0"
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   656
  shows "pochhammer (2 * z) (2 * n) = of_nat (2^(2*n)) * pochhammer z n * pochhammer (z+1/2) n"
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   657
proof (induction n)
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   658
  case (Suc n)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   659
  have "pochhammer (2 * z) (2 * (Suc n)) = pochhammer (2 * z) (2 * n) *
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   660
          (2 * (z + of_nat n)) * (2 * (z + of_nat n) + 1)"
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   661
    by (simp add: pochhammer_rec' ac_simps)
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   662
  also note Suc
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   663
  also have "of_nat (2 ^ (2 * n)) * pochhammer z n * pochhammer (z + 1/2) n *
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   664
                 (2 * (z + of_nat n)) * (2 * (z + of_nat n) + 1) =
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   665
             of_nat (2 ^ (2 * (Suc n))) * pochhammer z (Suc n) * pochhammer (z + 1/2) (Suc n)"
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   666
    by (simp add: field_simps pochhammer_rec')
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   667
  finally show ?case .
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   668
qed simp
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   669
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63092
diff changeset
   670
lemma fact_double:
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63092
diff changeset
   671
  "fact (2 * n) = (2 ^ (2 * n) * pochhammer (1 / 2) n * fact n :: 'a :: field_char_0)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63092
diff changeset
   672
  using pochhammer_double[of "1/2::'a" n] by (simp add: pochhammer_fact)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63092
diff changeset
   673
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   674
lemma pochhammer_absorb_comp:
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   675
  "((r :: 'a :: comm_ring_1) - of_nat k) * pochhammer (- r) k = r * pochhammer (-r + 1) k"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   676
  (is "?lhs = ?rhs")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   677
proof -
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   678
  have "?lhs = -pochhammer (-r) (Suc k)" by (subst pochhammer_rec') (simp add: algebra_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   679
  also have "\<dots> = ?rhs" by (subst pochhammer_rec) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   680
  finally show ?thesis .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   681
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   682
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   683
63372
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   684
subsection \<open>Generalized binomial coefficients\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   685
63372
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   686
definition gbinomial :: "'a :: {semidom_divide, semiring_char_0} \<Rightarrow> nat \<Rightarrow> 'a" (infixl "gchoose" 65)
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   687
where
63372
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   688
  "a gchoose n = setprod (\<lambda>i. a - of_nat i) {..<n} div fact n"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   689
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   690
lemma gbinomial_Suc:
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   691
  "a gchoose (Suc k) = setprod (\<lambda>i. a - of_nat i) {..k} / fact (Suc k)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   692
  by (simp add: gbinomial_def lessThan_Suc_atMost)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   693
63372
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   694
lemma gbinomial_0 [simp]:
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   695
  fixes a :: "'a::field_char_0"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   696
  shows "a gchoose 0 = 1" "(0::'a) gchoose (Suc n) = 0"
59867
58043346ca64 given up separate type classes demanding `inverse 0 = 0`
haftmann
parents: 59862
diff changeset
   697
  by (simp_all add: gbinomial_def)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   698
63372
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   699
lemma gbinomial_pochhammer:
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   700
  fixes a :: "'a::field_char_0"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   701
  shows "a gchoose n = (- 1) ^ n * pochhammer (- a) n / (fact n)"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   702
proof (cases "n = 0")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   703
  case True
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   704
  then show ?thesis by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   705
next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   706
  case False
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   707
  then have eq: "(- 1) ^ n = (\<Prod>i<n. - 1)"
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
   708
    by (auto simp add: setprod_constant)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   709
  from False show ?thesis
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   710
    by (simp add: pochhammer_def gbinomial_def field_simps
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   711
      eq setprod.distrib[symmetric])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   712
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   713
61552
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   714
lemma gbinomial_pochhammer':
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   715
  "(s :: 'a :: field_char_0) gchoose n = pochhammer (s - of_nat n + 1) n / fact n"
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   716
proof -
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   717
  have "s gchoose n = ((-1)^n * (-1)^n) * pochhammer (s - of_nat n + 1) n / fact n"
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   718
    by (simp add: gbinomial_pochhammer pochhammer_minus mult_ac)
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   719
  also have "(-1 :: 'a)^n * (-1)^n = 1" by (subst power_add [symmetric]) simp
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   720
  finally show ?thesis by simp
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   721
qed
980dd46a03fb Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
eberlm
parents: 61531
diff changeset
   722
63372
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   723
lemma gbinomial_binomial:
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   724
  "n gchoose k = n choose k"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   725
proof (cases "k \<le> n")
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   726
  case False
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   727
  then have "n < k" by (simp add: not_le)
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   728
  then have "0 \<in> (op - n) ` {..<k}"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   729
    by auto
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   730
  then have "setprod (op - n) {..<k} = 0"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   731
    by (auto intro: setprod_zero)
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   732
  with \<open>n < k\<close> show ?thesis
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   733
    by (simp add: binomial_eq_0 gbinomial_def setprod_zero)
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   734
next
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   735
  case True
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   736
  then have "inj_on (op - n) {..<k}"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   737
    by (auto intro: inj_onI)
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   738
  then have "\<Prod>(op - n ` {..<k}) = setprod (op - n) {..<k}"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   739
    by (auto dest: setprod.reindex)
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   740
  also have "op - n ` {..<k} = {Suc (n - k)..n}"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   741
    using True by (auto simp add: image_def Bex_def) arith
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   742
  finally have *: "setprod (\<lambda>q. n - q) {..<k} = \<Prod>{Suc (n - k)..n}" ..
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   743
  from True have "(n choose k) = fact n div (fact k * fact (n - k))"
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   744
    by (rule binomial_fact')
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   745
  with * show ?thesis
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   746
    by (simp add: gbinomial_def mult.commute [of "fact k"] div_mult2_eq fact_div_fact)
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   747
qed
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   748
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   749
lemma binomial_gbinomial:
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   750
    "of_nat (n choose k) = (of_nat n gchoose k :: 'a::field_char_0)"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   751
proof -
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   752
  { assume kn: "k > n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   753
    then have ?thesis
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   754
      by (subst binomial_eq_0[OF kn])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   755
         (simp add: gbinomial_pochhammer field_simps  pochhammer_of_nat_eq_0_iff) }
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   756
  moreover
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   757
  { assume "k=0" then have ?thesis by simp }
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   758
  moreover
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   759
  { assume kn: "k \<le> n" and k0: "k\<noteq> 0"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   760
    from k0 obtain h where h: "k = Suc h" by (cases k) auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   761
    from h
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   762
    have eq:"(- 1 :: 'a) ^ k = setprod (\<lambda>i. - 1) {..h}"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   763
      by (subst setprod_constant) auto
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   764
    have eq': "(\<Prod>i\<le>h. of_nat n + - (of_nat i :: 'a)) = (\<Prod>i\<in>{n - h..n}. of_nat i)"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   765
        using h kn
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   766
      by (intro setprod.reindex_bij_witness[where i="op - n" and j="op - n"])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   767
         (auto simp: of_nat_diff)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   768
    have th0: "finite {1..n - Suc h}" "finite {n - h .. n}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   769
        "{1..n - Suc h} \<inter> {n - h .. n} = {}" and
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   770
        eq3: "{1..n - Suc h} \<union> {n - h .. n} = {1..n}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   771
      using h kn by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   772
    from eq[symmetric]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   773
    have ?thesis using kn
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   774
      apply (simp add: binomial_fact[OF kn, where ?'a = 'a]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   775
        gbinomial_pochhammer field_simps pochhammer_Suc_setprod)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   776
      apply (simp add: pochhammer_Suc_setprod fact_altdef h
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   777
        setprod.distrib[symmetric] eq' del: One_nat_def power_Suc)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   778
      unfolding setprod.union_disjoint[OF th0, unfolded eq3, of "of_nat:: nat \<Rightarrow> 'a"] eq[unfolded h]
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   779
      unfolding mult.assoc
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   780
      unfolding setprod.distrib[symmetric]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   781
      apply simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   782
      apply (intro setprod.reindex_bij_witness[where i="op - n" and j="op - n"])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   783
      apply (auto simp: of_nat_diff)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   784
      done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   785
  }
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   786
  moreover
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   787
  have "k > n \<or> k = 0 \<or> (k \<le> n \<and> k \<noteq> 0)" by arith
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   788
  ultimately show ?thesis by blast
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   789
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   790
63372
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   791
setup \<open>Sign.add_const_constraint (@{const_name gbinomial}, SOME @{typ "'a::field_char_0 \<Rightarrow> nat \<Rightarrow> 'a"})\<close>
492b49535094 relating gbinomial and binomial, still using distinct definitions
haftmann
parents: 63367
diff changeset
   792
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   793
lemma gbinomial_1[simp]: "a gchoose 1 = a"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   794
  by (simp add: gbinomial_def lessThan_Suc)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   795
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   796
lemma gbinomial_Suc0[simp]: "a gchoose (Suc 0) = a"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   797
  by (simp add: gbinomial_def lessThan_Suc)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   798
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   799
lemma gbinomial_mult_1:
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   800
  fixes a :: "'a :: field_char_0"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   801
  shows "a * (a gchoose n) =
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   802
    of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))"  (is "?l = ?r")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   803
proof -
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   804
  have "?r = ((- 1) ^n * pochhammer (- a) n / (fact n)) * (of_nat n - (- a + of_nat n))"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   805
    unfolding gbinomial_pochhammer
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   806
      pochhammer_Suc right_diff_distrib power_Suc
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   807
    apply (simp del: of_nat_Suc fact_Suc)
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   808
    apply (auto simp add: field_simps simp del: of_nat_Suc)
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   809
    done
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   810
  also have "\<dots> = ?l" unfolding gbinomial_pochhammer
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   811
    by (simp add: field_simps)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   812
  finally show ?thesis ..
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   813
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   814
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   815
lemma gbinomial_mult_1':
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   816
  fixes a :: "'a :: field_char_0"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   817
  shows "(a gchoose n) * a = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   818
  by (simp add: mult.commute gbinomial_mult_1)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   819
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   820
lemma gbinomial_mult_fact:
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   821
  fixes a :: "'a::field_char_0"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   822
  shows
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   823
   "fact (Suc k) * (a gchoose (Suc k)) =
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   824
    (setprod (\<lambda>i. a - of_nat i) {.. k})"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   825
  by (simp_all add: gbinomial_Suc field_simps del: fact_Suc)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   826
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   827
lemma gbinomial_mult_fact':
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   828
  fixes a :: "'a::field_char_0"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   829
  shows "(a gchoose (Suc k)) * fact (Suc k) = (setprod (\<lambda>i. a - of_nat i) {.. k})"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   830
  using gbinomial_mult_fact[of k a]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   831
  by (subst mult.commute)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   832
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   833
lemma gbinomial_Suc_Suc:
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   834
  fixes a :: "'a :: field_char_0"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   835
  shows "(a + 1) gchoose (Suc k) = a gchoose k + (a gchoose (Suc k))"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   836
proof (cases k)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   837
  case 0
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   838
  then show ?thesis by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   839
next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   840
  case (Suc h)
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   841
  have eq0: "(\<Prod>i\<in>{1..k}. (a + 1) - of_nat i) = (\<Prod>i\<in>{..h}. a - of_nat i)"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   842
    apply (rule setprod.reindex_cong [where l = Suc])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   843
      using Suc
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   844
      apply (auto simp add: image_Suc_atMost)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   845
    done
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   846
  have "fact (Suc k) * (a gchoose k + (a gchoose (Suc k))) =
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   847
        (a gchoose Suc h) * (fact (Suc (Suc h))) +
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   848
        (a gchoose Suc (Suc h)) * (fact (Suc (Suc h)))"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   849
    by (simp add: Suc field_simps del: fact_Suc)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   850
  also have "... = (a gchoose Suc h) * of_nat (Suc (Suc h) * fact (Suc h)) +
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   851
                   (\<Prod>i\<le>Suc h. a - of_nat i)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   852
    by (metis fact_Suc gbinomial_mult_fact' of_nat_fact of_nat_id)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   853
  also have "... = (fact (Suc h) * (a gchoose Suc h)) * of_nat (Suc (Suc h)) +
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   854
                   (\<Prod>i\<le>Suc h. a - of_nat i)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   855
    by (simp only: fact_Suc mult.commute mult.left_commute of_nat_fact of_nat_id of_nat_mult)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   856
  also have "... =  of_nat (Suc (Suc h)) * (\<Prod>i\<le>h. a - of_nat i) +
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   857
                    (\<Prod>i\<le>Suc h. a - of_nat i)"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   858
    by (metis gbinomial_mult_fact mult.commute)
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   859
  also have "... = (\<Prod>i\<le>Suc h. a - of_nat i) +
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   860
                   (of_nat h * (\<Prod>i\<le>h. a - of_nat i) + 2 * (\<Prod>i\<le>h. a - of_nat i))"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   861
    by (simp add: field_simps)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   862
  also have "... =
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   863
    ((a gchoose Suc h) * (fact (Suc h)) * of_nat (Suc k)) + (\<Prod>i\<in>{..Suc h}. a - of_nat i)"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   864
    unfolding gbinomial_mult_fact'
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   865
    by (simp add: comm_semiring_class.distrib field_simps Suc)
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   866
  also have "\<dots> = (\<Prod>i\<in>{..h}. a - of_nat i) * (a + 1)"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   867
    unfolding gbinomial_mult_fact' setprod_nat_ivl_Suc
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   868
      atMost_Suc
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   869
    by (simp add: field_simps Suc)
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   870
  also have "\<dots> = (\<Prod>i\<in>{..k}. (a + 1) - of_nat i)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
   871
    using eq0 setprod_nat_ivl_1_Suc
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   872
    by (simp add: Suc setprod_nat_ivl_1_Suc)
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   873
  also have "\<dots> = (fact (Suc k)) * ((a + 1) gchoose (Suc k))"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   874
    unfolding gbinomial_mult_fact ..
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   875
  finally show ?thesis
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   876
    by (metis fact_nonzero mult_cancel_left)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   877
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   878
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   879
lemma gbinomial_reduce_nat:
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   880
  fixes a :: "'a :: field_char_0"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   881
  shows "0 < k \<Longrightarrow> a gchoose k = (a - 1) gchoose (k - 1) + ((a - 1) gchoose k)"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   882
  by (metis Suc_pred' diff_add_cancel gbinomial_Suc_Suc)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   883
60141
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   884
lemma gchoose_row_sum_weighted:
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   885
  fixes r :: "'a::field_char_0"
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   886
  shows "(\<Sum>k = 0..m. (r gchoose k) * (r/2 - of_nat k)) = of_nat(Suc m) / 2 * (r gchoose (Suc m))"
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   887
proof (induct m)
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   888
  case 0 show ?case by simp
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   889
next
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   890
  case (Suc m)
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   891
  from Suc show ?case
61738
c4f6031f1310 New material about paths, winding numbers, etc. Added lemmas to divide_const_simps. Misc tuning.
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
   892
    by (simp add: field_simps distrib gbinomial_mult_1)
60141
833adf7db7d8 New material, mostly about limits. Consolidation.
paulson <lp15@cam.ac.uk>
parents: 59867
diff changeset
   893
qed
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   894
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   895
lemma binomial_symmetric:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   896
  assumes kn: "k \<le> n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   897
  shows "n choose k = n choose (n - k)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   898
proof-
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   899
  from kn have kn': "n - k \<le> n" by arith
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   900
  from binomial_fact_lemma[OF kn] binomial_fact_lemma[OF kn']
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   901
  have "fact k * fact (n - k) * (n choose k) =
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   902
    fact (n - k) * fact (n - (n - k)) * (n choose (n - k))" by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   903
  then show ?thesis using kn by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   904
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   905
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   906
lemma choose_rising_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   907
  "(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose (n + 1))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   908
  "(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose m)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   909
proof -
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   910
  show "(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose (n + 1))" by (induction m) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   911
  also have "... = ((n + m + 1) choose m)" by (subst binomial_symmetric) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   912
  finally show "(\<Sum>j\<le>m. ((n + j) choose n)) = ((n + m + 1) choose m)" .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   913
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   914
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   915
lemma choose_linear_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   916
  "(\<Sum>i\<le>n. i * (n choose i)) = n * 2 ^ (n - 1)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   917
proof (cases n)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   918
  case (Suc m)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   919
  have "(\<Sum>i\<le>n. i * (n choose i)) = (\<Sum>i\<le>Suc m. i * (Suc m choose i))" by (simp add: Suc)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   920
  also have "... = Suc m * 2 ^ m"
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   921
    by (simp only: setsum_atMost_Suc_shift Suc_times_binomial setsum_right_distrib[symmetric])
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   922
       (simp add: choose_row_sum')
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   923
  finally show ?thesis using Suc by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   924
qed simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   925
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   926
lemma choose_alternating_linear_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   927
  assumes "n \<noteq> 1"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   928
  shows   "(\<Sum>i\<le>n. (-1)^i * of_nat i * of_nat (n choose i) :: 'a :: comm_ring_1) = 0"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   929
proof (cases n)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   930
  case (Suc m)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   931
  with assms have "m > 0" by simp
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   932
  have "(\<Sum>i\<le>n. (-1) ^ i * of_nat i * of_nat (n choose i) :: 'a) =
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   933
            (\<Sum>i\<le>Suc m. (-1) ^ i * of_nat i * of_nat (Suc m choose i))" by (simp add: Suc)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   934
  also have "... = (\<Sum>i\<le>m. (-1) ^ (Suc i) * of_nat (Suc i * (Suc m choose Suc i)))"
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   935
    by (simp only: setsum_atMost_Suc_shift setsum_right_distrib[symmetric] mult_ac of_nat_mult) simp
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   936
  also have "... = -of_nat (Suc m) * (\<Sum>i\<le>m. (-1) ^ i * of_nat ((m choose i)))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   937
    by (subst setsum_right_distrib, rule setsum.cong[OF refl], subst Suc_times_binomial)
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
   938
       (simp add: algebra_simps)
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   939
  also have "(\<Sum>i\<le>m. (-1 :: 'a) ^ i * of_nat ((m choose i))) = 0"
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61738
diff changeset
   940
    using choose_alternating_sum[OF \<open>m > 0\<close>] by simp
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   941
  finally show ?thesis by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   942
qed simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   943
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   944
lemma vandermonde:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   945
  "(\<Sum>k\<le>r. (m choose k) * (n choose (r - k))) = (m + n) choose r"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   946
proof (induction n arbitrary: r)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   947
  case 0
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   948
  have "(\<Sum>k\<le>r. (m choose k) * (0 choose (r - k))) = (\<Sum>k\<le>r. if k = r then (m choose k) else 0)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   949
    by (intro setsum.cong) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   950
  also have "... = m choose r" by (simp add: setsum.delta)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   951
  finally show ?case by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   952
next
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   953
  case (Suc n r)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   954
  show ?case by (cases r) (simp_all add: Suc [symmetric] algebra_simps setsum.distrib Suc_diff_le)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   955
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   956
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   957
lemma choose_square_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   958
  "(\<Sum>k\<le>n. (n choose k)^2) = ((2*n) choose n)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   959
  using vandermonde[of n n n] by (simp add: power2_eq_square mult_2 binomial_symmetric [symmetric])
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   960
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   961
lemma pochhammer_binomial_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   962
  fixes a b :: "'a :: comm_ring_1"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   963
  shows "pochhammer (a + b) n = (\<Sum>k\<le>n. of_nat (n choose k) * pochhammer a k * pochhammer b (n - k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   964
proof (induction n arbitrary: a b)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   965
  case (Suc n a b)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   966
  have "(\<Sum>k\<le>Suc n. of_nat (Suc n choose k) * pochhammer a k * pochhammer b (Suc n - k)) =
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   967
            (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a (Suc i) * pochhammer b (n - i)) +
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   968
            ((\<Sum>i\<le>n. of_nat (n choose Suc i) * pochhammer a (Suc i) * pochhammer b (n - i)) +
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   969
            pochhammer b (Suc n))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   970
    by (subst setsum_atMost_Suc_shift) (simp add: ring_distribs setsum.distrib)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   971
  also have "(\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a (Suc i) * pochhammer b (n - i)) =
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   972
               a * pochhammer ((a + 1) + b) n"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   973
    by (subst Suc) (simp add: setsum_right_distrib pochhammer_rec mult_ac)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
   974
  also have "(\<Sum>i\<le>n. of_nat (n choose Suc i) * pochhammer a (Suc i) * pochhammer b (n - i)) + pochhammer b (Suc n) =
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   975
               (\<Sum>i=0..Suc n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc n - i))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   976
    by (subst setsum_head_Suc, simp, subst setsum_shift_bounds_cl_Suc_ivl) (simp add: atLeast0AtMost)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   977
  also have "... = (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc n - i))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   978
    using Suc by (intro setsum.mono_neutral_right) (auto simp: not_le binomial_eq_0)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   979
  also have "... = (\<Sum>i\<le>n. of_nat (n choose i) * pochhammer a i * pochhammer b (Suc (n - i)))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   980
    by (intro setsum.cong) (simp_all add: Suc_diff_le)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   981
  also have "... = b * pochhammer (a + (b + 1)) n"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   982
    by (subst Suc) (simp add: setsum_right_distrib mult_ac pochhammer_rec)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   983
  also have "a * pochhammer ((a + 1) + b) n + b * pochhammer (a + (b + 1)) n =
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   984
               pochhammer (a + b) (Suc n)" by (simp add: pochhammer_rec algebra_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   985
  finally show ?case ..
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   986
qed simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   987
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
   988
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   989
text\<open>Contributed by Manuel Eberl, generalised by LCP.
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
   990
  Alternative definition of the binomial coefficient as @{term "\<Prod>i<k. (n - i) / (k - i)"}\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   991
lemma gbinomial_altdef_of_nat:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   992
  fixes k :: nat
59867
58043346ca64 given up separate type classes demanding `inverse 0 = 0`
haftmann
parents: 59862
diff changeset
   993
    and x :: "'a :: {field_char_0,field}"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   994
  shows "x gchoose k = (\<Prod>i<k. (x - of_nat i) / of_nat (k - i) :: 'a)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   995
proof -
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   996
  have "(x gchoose k) = (\<Prod>i<k. x - of_nat i) / of_nat (fact k)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   997
    unfolding gbinomial_def
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   998
    by (auto simp: gr0_conv_Suc lessThan_Suc_atMost atLeast0AtMost)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
   999
  also have "\<dots> = (\<Prod>i<k. (x - of_nat i) / of_nat (k - i) :: 'a)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1000
    unfolding fact_eq_rev_setprod_nat of_nat_setprod
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1001
    by (auto simp add: setprod_dividef intro!: setprod.cong of_nat_diff[symmetric])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1002
  finally show ?thesis .
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1003
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1004
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1005
lemma gbinomial_ge_n_over_k_pow_k:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1006
  fixes k :: nat
59867
58043346ca64 given up separate type classes demanding `inverse 0 = 0`
haftmann
parents: 59862
diff changeset
  1007
    and x :: "'a :: linordered_field"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1008
  assumes "of_nat k \<le> x"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1009
  shows "(x / of_nat k :: 'a) ^ k \<le> x gchoose k"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1010
proof -
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1011
  have x: "0 \<le> x"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1012
    using assms of_nat_0_le_iff order_trans by blast
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1013
  have "(x / of_nat k :: 'a) ^ k = (\<Prod>i<k. x / of_nat k :: 'a)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1014
    by (simp add: setprod_constant)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1015
  also have "\<dots> \<le> x gchoose k"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1016
    unfolding gbinomial_altdef_of_nat
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1017
  proof (safe intro!: setprod_mono)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1018
    fix i :: nat
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1019
    assume ik: "i < k"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1020
    from assms have "x * of_nat i \<ge> of_nat (i * k)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1021
      by (metis mult.commute mult_le_cancel_right of_nat_less_0_iff of_nat_mult)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1022
    then have "x * of_nat k - x * of_nat i \<le> x * of_nat k - of_nat (i * k)" by arith
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1023
    then have "x * of_nat (k - i) \<le> (x - of_nat i) * of_nat k"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1024
      using ik
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
  1025
      by (simp add: algebra_simps zero_less_mult_iff of_nat_diff)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1026
    then have "x * of_nat (k - i) \<le> (x - of_nat i) * (of_nat k :: 'a)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1027
      unfolding of_nat_mult[symmetric] of_nat_le_iff .
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1028
    with assms show "x / of_nat k \<le> (x - of_nat i) / (of_nat (k - i) :: 'a)"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1029
      using \<open>i < k\<close> by (simp add: field_simps)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1030
  qed (simp add: x zero_le_divide_iff)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1031
  finally show ?thesis .
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1032
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1033
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1034
lemma gbinomial_negated_upper: "(a gchoose b) = (-1) ^ b * ((of_nat b - a - 1) gchoose b)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1035
  by (simp add: gbinomial_pochhammer pochhammer_minus algebra_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1036
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1037
lemma gbinomial_minus: "((-a) gchoose b) = (-1) ^ b * ((a + of_nat b - 1) gchoose b)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1038
  by (subst gbinomial_negated_upper) (simp add: add_ac)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1039
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1040
lemma Suc_times_gbinomial:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1041
  "of_nat (Suc b) * ((a + 1) gchoose (Suc b)) = (a + 1) * (a gchoose b)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1042
proof (cases b)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1043
  case (Suc b)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1044
  hence "((a + 1) gchoose (Suc (Suc b))) =
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1045
             (\<Prod>i\<le>Suc b. a + (1 - of_nat i)) / fact (b + 2)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1046
    by (simp add: field_simps gbinomial_def lessThan_Suc_atMost)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1047
  also have "(\<Prod>i\<le>Suc b. a + (1 - of_nat i)) = (a + 1) * (\<Prod>i\<le>b. a - of_nat i)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1048
    by (simp add: setprod_nat_ivl_1_Suc setprod_shift_bounds_cl_Suc_ivl atLeast0AtMost)
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1049
  also have "... / fact (b + 2) = (a + 1) / of_nat (Suc (Suc b)) * (a gchoose Suc b)"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1050
    by (simp_all add: gbinomial_def setprod_nat_ivl_1_Suc setprod_shift_bounds_cl_Suc_ivl lessThan_Suc_atMost)
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1051
  finally show ?thesis by (simp add: Suc field_simps del: of_nat_Suc)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1052
qed simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1053
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1054
lemma gbinomial_factors:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1055
  "((a + 1) gchoose (Suc b)) = (a + 1) / of_nat (Suc b) * (a gchoose b)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1056
proof (cases b)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1057
  case (Suc b)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1058
  hence "((a + 1) gchoose (Suc (Suc b))) =
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1059
             (\<Prod>i\<le>Suc b. a + (1 - of_nat i)) / fact (b + 2)"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1060
    by (simp add: field_simps gbinomial_def lessThan_Suc_atMost)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1061
  also have "(\<Prod>i\<le>Suc b. a + (1 - of_nat i)) = (a + 1) * (\<Prod>i = 0..b. a - of_nat i)"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1062
    by (simp add: setprod_nat_ivl_1_Suc setprod_shift_bounds_cl_Suc_ivl)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1063
  also have "... / fact (b + 2) = (a + 1) / of_nat (Suc (Suc b)) * (a gchoose Suc b)"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1064
    by (simp_all add: gbinomial_def setprod_nat_ivl_1_Suc setprod_shift_bounds_cl_Suc_ivl lessThan_Suc_atMost atLeast0AtMost)
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1065
  finally show ?thesis by (simp add: Suc)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1066
qed simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1067
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1068
lemma gbinomial_rec: "((r + 1) gchoose (Suc k)) = (r gchoose k) * ((r + 1) / of_nat (Suc k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1069
  using gbinomial_mult_1[of r k]
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1070
  by (subst gbinomial_Suc_Suc) (simp add: field_simps del: of_nat_Suc, simp add: algebra_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1071
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1072
lemma gbinomial_of_nat_symmetric: "k \<le> n \<Longrightarrow> (of_nat n) gchoose k = (of_nat n) gchoose (n - k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1073
  using binomial_symmetric[of k n] by (simp add: binomial_gbinomial [symmetric])
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1074
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1075
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1076
text \<open>The absorption identity (equation 5.5 \cite[p.~157]{GKP}):\[
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1077
{r \choose k} = \frac{r}{k}{r - 1 \choose k - 1},\quad \textnormal{integer } k \neq 0.
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1078
\]\<close>
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1079
lemma gbinomial_absorption':
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1080
  "k > 0 \<Longrightarrow> (r gchoose k) = (r / of_nat(k)) * (r - 1 gchoose (k - 1))"
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1081
  using gbinomial_rec[of "r - 1" "k - 1"]
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1082
  by (simp_all add: gbinomial_rec field_simps del: of_nat_Suc)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1083
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1084
text \<open>The absorption identity is written in the following form to avoid
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1085
division by $k$ (the lower index) and therefore remove the $k \neq 0$
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1086
restriction\cite[p.~157]{GKP}:\[
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1087
k{r \choose k} = r{r - 1 \choose k - 1}, \quad \textnormal{integer } k.
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1088
\]\<close>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1089
lemma gbinomial_absorption:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1090
  "of_nat (Suc k) * (r gchoose Suc k) = r * ((r - 1) gchoose k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1091
  using gbinomial_absorption'[of "Suc k" r] by (simp add: field_simps del: of_nat_Suc)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1092
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1093
text \<open>The absorption identity for natural number binomial coefficients:\<close>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1094
lemma binomial_absorption:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1095
  "Suc k * (n choose Suc k) = n * ((n - 1) choose k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1096
  by (cases n) (simp_all add: binomial_eq_0 Suc_times_binomial del: binomial_Suc_Suc mult_Suc)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1097
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1098
text \<open>The absorption companion identity for natural number coefficients,
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1099
following the proof by GKP \cite[p.~157]{GKP}:\<close>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1100
lemma binomial_absorb_comp:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1101
  "(n - k) * (n choose k) = n * ((n - 1) choose k)" (is "?lhs = ?rhs")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1102
proof (cases "n \<le> k")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1103
  case False
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1104
  then have "?rhs = Suc ((n - 1) - k) * (n choose Suc ((n - 1) - k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1105
    using binomial_symmetric[of k "n - 1"] binomial_absorption[of "(n - 1) - k" n]
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1106
    by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1107
  also from False have "Suc ((n - 1) - k) = n - k" by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1108
  also from False have "n choose \<dots> = n choose k" by (intro binomial_symmetric [symmetric]) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1109
  finally show ?thesis ..
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1110
qed auto
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1111
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1112
text \<open>The generalised absorption companion identity:\<close>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1113
lemma gbinomial_absorb_comp: "(r - of_nat k) * (r gchoose k) = r * ((r - 1) gchoose k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1114
  using pochhammer_absorb_comp[of r k] by (simp add: gbinomial_pochhammer)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1115
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1116
lemma gbinomial_addition_formula:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1117
  "r gchoose (Suc k) = ((r - 1) gchoose (Suc k)) + ((r - 1) gchoose k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1118
  using gbinomial_Suc_Suc[of "r - 1" k] by (simp add: algebra_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1119
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1120
lemma binomial_addition_formula:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1121
  "0 < n \<Longrightarrow> n choose (Suc k) = ((n - 1) choose (Suc k)) + ((n - 1) choose k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1122
  by (subst choose_reduce_nat) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1123
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1124
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1125
text \<open>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1126
  Equation 5.9 of the reference material \cite[p.~159]{GKP} is a useful
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1127
  summation formula, operating on both indices:\[
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1128
  \sum\limits_{k \leq n}{r + k \choose k} = {r + n + 1 \choose n},
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1129
   \quad \textnormal{integer } n.
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1130
  \]
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1131
\<close>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1132
lemma gbinomial_parallel_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1133
"(\<Sum>k\<le>n. (r + of_nat k) gchoose k) = (r + of_nat n + 1) gchoose n"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1134
proof (induction n)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1135
  case (Suc m)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1136
  thus ?case using gbinomial_Suc_Suc[of "(r + of_nat m + 1)" m] by (simp add: add_ac)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1137
qed auto
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1138
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1139
subsection \<open>Summation on the upper index\<close>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1140
text \<open>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1141
  Another summation formula is equation 5.10 of the reference material \cite[p.~160]{GKP},
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1142
  aptly named \emph{summation on the upper index}:\[\sum_{0 \leq k \leq n} {k \choose m} =
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1143
  {n + 1 \choose m + 1}, \quad \textnormal{integers } m, n \geq 0.\]
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1144
\<close>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1145
lemma gbinomial_sum_up_index:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1146
  "(\<Sum>k = 0..n. (of_nat k gchoose m) :: 'a :: field_char_0) = (of_nat n + 1) gchoose (m + 1)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1147
proof (induction n)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1148
  case 0
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1149
  show ?case using gbinomial_Suc_Suc[of 0 m] by (cases m) auto
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1150
next
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1151
  case (Suc n)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1152
  thus ?case using gbinomial_Suc_Suc[of "of_nat (Suc n) :: 'a" m] by (simp add: add_ac)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1153
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1154
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1155
lemma gbinomial_index_swap:
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1156
  "((-1) ^ m) * ((- (of_nat n) - 1) gchoose m) = ((-1) ^ n) * ((- (of_nat m) - 1) gchoose n)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1157
  (is "?lhs = ?rhs")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1158
proof -
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1159
  have "?lhs = (of_nat (m + n) gchoose m)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1160
    by (subst gbinomial_negated_upper) (simp add: power_mult_distrib [symmetric])
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1161
  also have "\<dots> = (of_nat (m + n) gchoose n)" by (subst gbinomial_of_nat_symmetric) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1162
  also have "\<dots> = ?rhs" by (subst gbinomial_negated_upper) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1163
  finally show ?thesis .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1164
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1165
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1166
lemma gbinomial_sum_lower_neg:
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1167
  "(\<Sum>k\<le>m. (r gchoose k) * (- 1) ^ k) = (- 1) ^ m * (r - 1 gchoose m)" (is "?lhs = ?rhs")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1168
proof -
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1169
  have "?lhs = (\<Sum>k\<le>m. -(r + 1) + of_nat k gchoose k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1170
    by (intro setsum.cong[OF refl]) (subst gbinomial_negated_upper, simp add: power_mult_distrib)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1171
  also have "\<dots>  = -r + of_nat m gchoose m" by (subst gbinomial_parallel_sum) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1172
  also have "\<dots> = ?rhs" by (subst gbinomial_negated_upper) (simp add: power_mult_distrib)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1173
  finally show ?thesis .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1174
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1175
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1176
lemma gbinomial_partial_row_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1177
"(\<Sum>k\<le>m. (r gchoose k) * ((r / 2) - of_nat k)) = ((of_nat m + 1)/2) * (r gchoose (m + 1))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1178
proof (induction m)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1179
  case (Suc mm)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1180
  hence "(\<Sum>k\<le>Suc mm. (r gchoose k) * (r / 2 - of_nat k)) =
61738
c4f6031f1310 New material about paths, winding numbers, etc. Added lemmas to divide_const_simps. Misc tuning.
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
  1181
             (r - of_nat (Suc mm)) * (r gchoose Suc mm) / 2" by (simp add: field_simps)
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1182
  also have "\<dots> = r * (r - 1 gchoose Suc mm) / 2" by (subst gbinomial_absorb_comp) (rule refl)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1183
  also have "\<dots> = (of_nat (Suc mm) + 1) / 2 * (r gchoose (Suc mm + 1))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1184
    by (subst gbinomial_absorption [symmetric]) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1185
  finally show ?case .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1186
qed simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1187
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1188
lemma setsum_bounds_lt_plus1: "(\<Sum>k<mm. f (Suc k)) = (\<Sum>k=1..mm. f k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1189
  by (induction mm) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1190
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1191
lemma gbinomial_partial_sum_poly:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1192
  "(\<Sum>k\<le>m. (of_nat m + r gchoose k) * x^k * y^(m-k)) =
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1193
       (\<Sum>k\<le>m. (-r gchoose k) * (-x)^k * (x + y)^(m-k))" (is "?lhs m = ?rhs m")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1194
proof (induction m)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1195
  case (Suc mm)
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62481
diff changeset
  1196
  define G where "G i k = (of_nat i + r gchoose k) * x^k * y^(i-k)" for i k
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62481
diff changeset
  1197
  define S where "S = ?lhs"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1198
  have SG_def: "S = (\<lambda>i. (\<Sum>k\<le>i. (G i k)))" unfolding S_def G_def ..
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1199
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1200
  have "S (Suc mm) = G (Suc mm) 0 + (\<Sum>k=Suc 0..Suc mm. G (Suc mm) k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1201
    using SG_def by (simp add: setsum_head_Suc atLeast0AtMost [symmetric])
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1202
  also have "(\<Sum>k=Suc 0..Suc mm. G (Suc mm) k) = (\<Sum>k=0..mm. G (Suc mm) (Suc k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1203
    by (subst setsum_shift_bounds_cl_Suc_ivl) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1204
  also have "\<dots> = (\<Sum>k=0..mm. ((of_nat mm + r gchoose (Suc k))
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1205
                    + (of_nat mm + r gchoose k)) * x^(Suc k) * y^(mm - k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1206
    unfolding G_def by (subst gbinomial_addition_formula) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1207
  also have "\<dots> = (\<Sum>k=0..mm. (of_nat mm + r gchoose (Suc k)) * x^(Suc k) * y^(mm - k))
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1208
                  + (\<Sum>k=0..mm. (of_nat mm + r gchoose k) * x^(Suc k) * y^(mm - k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1209
    by (subst setsum.distrib [symmetric]) (simp add: algebra_simps)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1210
  also have "(\<Sum>k=0..mm. (of_nat mm + r gchoose (Suc k)) * x^(Suc k) * y^(mm - k)) =
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1211
               (\<Sum>k<Suc mm. (of_nat mm + r gchoose (Suc k)) * x^(Suc k) * y^(mm - k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1212
    by (simp only: atLeast0AtMost lessThan_Suc_atMost)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1213
  also have "\<dots> = (\<Sum>k<mm. (of_nat mm + r gchoose Suc k) * x^(Suc k) * y^(mm-k))
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1214
                      + (of_nat mm + r gchoose (Suc mm)) * x^(Suc mm)" (is "_ = ?A + ?B")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1215
    by (subst setsum_lessThan_Suc) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1216
  also have "?A = (\<Sum>k=1..mm. (of_nat mm + r gchoose k) * x^k * y^(mm - k + 1))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1217
  proof (subst setsum_bounds_lt_plus1 [symmetric], intro setsum.cong[OF refl], clarify)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1218
    fix k assume "k < mm"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1219
    hence "mm - k = mm - Suc k + 1" by linarith
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1220
    thus "(of_nat mm + r gchoose Suc k) * x ^ Suc k * y ^ (mm - k) =
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1221
            (of_nat mm + r gchoose Suc k) * x ^ Suc k * y ^ (mm - Suc k + 1)" by (simp only:)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1222
  qed
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1223
  also have "\<dots> + ?B = y * (\<Sum>k=1..mm. (G mm k)) + (of_nat mm + r gchoose (Suc mm)) * x^(Suc mm)"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1224
    unfolding G_def by (subst setsum_right_distrib) (simp add: algebra_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1225
  also have "(\<Sum>k=0..mm. (of_nat mm + r gchoose k) * x^(Suc k) * y^(mm - k)) = x * (S mm)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1226
      unfolding S_def by (subst setsum_right_distrib) (simp add: atLeast0AtMost algebra_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1227
  also have "(G (Suc mm) 0) = y * (G mm 0)" by (simp add: G_def)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1228
  finally have "S (Suc mm) = y * ((G mm 0) + (\<Sum>k=1..mm. (G mm k)))
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1229
                + (of_nat mm + r gchoose (Suc mm)) * x^(Suc mm) + x * (S mm)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1230
    by (simp add: ring_distribs)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1231
  also have "(G mm 0) + (\<Sum>k=1..mm. (G mm k)) = S mm"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1232
    by (simp add: setsum_head_Suc[symmetric] SG_def atLeast0AtMost)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1233
  finally have "S (Suc mm) = (x + y) * (S mm) + (of_nat mm + r gchoose (Suc mm)) * x^(Suc mm)"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1234
    by (simp add: algebra_simps)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1235
  also have "(of_nat mm + r gchoose (Suc mm)) = (-1) ^ (Suc mm) * (-r gchoose (Suc mm))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1236
    by (subst gbinomial_negated_upper) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1237
  also have "(-1) ^ Suc mm * (- r gchoose Suc mm) * x ^ Suc mm =
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1238
                 (-r gchoose (Suc mm)) * (-x) ^ Suc mm" by (simp add: power_minus[of x])
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1239
  also have "(x + y) * S mm + \<dots> = (x + y) * ?rhs mm + (-r gchoose (Suc mm)) * (-x)^Suc mm"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1240
    unfolding S_def by (subst Suc.IH) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1241
  also have "(x + y) * ?rhs mm = (\<Sum>n\<le>mm. ((- r gchoose n) * (- x) ^ n * (x + y) ^ (Suc mm - n)))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1242
    by (subst setsum_right_distrib, rule setsum.cong) (simp_all add: Suc_diff_le)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1243
  also have "\<dots> + (-r gchoose (Suc mm)) * (-x)^Suc mm =
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1244
                 (\<Sum>n\<le>Suc mm. (- r gchoose n) * (- x) ^ n * (x + y) ^ (Suc mm - n))" by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1245
  finally show ?case unfolding S_def .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1246
qed simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1247
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1248
lemma gbinomial_partial_sum_poly_xpos:
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1249
  "(\<Sum>k\<le>m. (of_nat m + r gchoose k) * x^k * y^(m-k)) =
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1250
     (\<Sum>k\<le>m. (of_nat k + r - 1 gchoose k) * x^k * (x + y)^(m-k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1251
  apply (subst gbinomial_partial_sum_poly)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1252
  apply (subst gbinomial_negated_upper)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1253
  apply (intro setsum.cong, rule refl)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1254
  apply (simp add: power_mult_distrib [symmetric])
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1255
  done
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1256
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1257
lemma setsum_nat_symmetry:
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1258
  "(\<Sum>k = 0..(m::nat). f k) = (\<Sum>k = 0..m. f (m - k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1259
  by (rule setsum.reindex_bij_witness[where i="\<lambda>i. m - i" and j="\<lambda>i. m - i"]) auto
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1260
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1261
lemma binomial_r_part_sum: "(\<Sum>k\<le>m. (2 * m + 1 choose k)) = 2 ^ (2 * m)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1262
proof -
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1263
  have "2 * 2^(2*m) = (\<Sum>k = 0..(2 * m + 1). (2 * m + 1 choose k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1264
    using choose_row_sum[where n="2 * m + 1"] by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1265
  also have "(\<Sum>k = 0..(2 * m + 1). (2 * m + 1 choose k)) = (\<Sum>k = 0..m. (2 * m + 1 choose k))
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1266
                + (\<Sum>k = m+1..2*m+1. (2 * m + 1 choose k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1267
    using setsum_ub_add_nat[of 0 m "\<lambda>k. 2 * m + 1 choose k" "m+1"] by (simp add: mult_2)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1268
  also have "(\<Sum>k = m+1..2*m+1. (2 * m + 1 choose k)) =
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1269
                 (\<Sum>k = 0..m. (2 * m + 1 choose (k + (m + 1))))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1270
    by (subst setsum_shift_bounds_cl_nat_ivl [symmetric]) (simp add: mult_2)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1271
  also have "\<dots> = (\<Sum>k = 0..m. (2 * m + 1 choose (m - k)))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1272
    by (intro setsum.cong[OF refl], subst binomial_symmetric) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1273
  also have "\<dots> = (\<Sum>k = 0..m. (2 * m + 1 choose k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1274
    by (subst (2) setsum_nat_symmetry) (rule refl)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1275
  also have "\<dots> + \<dots> = 2 * \<dots>" by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1276
  finally show ?thesis by (subst (asm) mult_cancel1) (simp add: atLeast0AtMost)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1277
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1278
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1279
lemma gbinomial_r_part_sum:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1280
  "(\<Sum>k\<le>m. (2 * (of_nat m) + 1 gchoose k)) = 2 ^ (2 * m)" (is "?lhs = ?rhs")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1281
proof -
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1282
  have "?lhs = of_nat (\<Sum>k\<le>m. (2 * m + 1) choose k)"
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
  1283
    by (simp add: binomial_gbinomial add_ac)
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1284
  also have "\<dots> = of_nat (2 ^ (2 * m))" by (subst binomial_r_part_sum) (rule refl)
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
  1285
  finally show ?thesis by simp
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1286
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1287
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1288
lemma gbinomial_sum_nat_pow2:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1289
   "(\<Sum>k\<le>m. (of_nat (m + k) gchoose k :: 'a :: field_char_0) / 2 ^ k) = 2 ^ m" (is "?lhs = ?rhs")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1290
proof -
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1291
  have "2 ^ m * 2 ^ m = (2 ^ (2*m) :: 'a)" by (induction m) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1292
  also have "\<dots> = (\<Sum>k\<le>m. (2 * (of_nat m) + 1 gchoose k))" using gbinomial_r_part_sum ..
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1293
  also have "\<dots> = (\<Sum>k\<le>m. (of_nat (m + k) gchoose k) * 2 ^ (m - k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1294
    using gbinomial_partial_sum_poly_xpos[where x="1" and y="1" and r="of_nat m + 1" and m="m"]
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1295
    by (simp add: add_ac)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1296
  also have "\<dots> = 2 ^ m * (\<Sum>k\<le>m. (of_nat (m + k) gchoose k) / 2 ^ k)"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1297
    by (subst setsum_right_distrib) (simp add: algebra_simps power_diff)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1298
  finally show ?thesis by (subst (asm) mult_left_cancel) simp_all
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1299
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1300
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1301
lemma gbinomial_trinomial_revision:
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1302
  assumes "k \<le> m"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1303
  shows   "(r gchoose m) * (of_nat m gchoose k) = (r gchoose k) * (r - of_nat k gchoose (m - k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1304
proof -
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1305
  have "(r gchoose m) * (of_nat m gchoose k) =
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1306
            (r gchoose m) * fact m / (fact k * fact (m - k))"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1307
    using assms by (simp add: binomial_gbinomial [symmetric] binomial_fact)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1308
  also have "\<dots> = (r gchoose k) * (r - of_nat k gchoose (m - k))" using assms
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1309
    by (simp add: gbinomial_pochhammer power_diff pochhammer_product)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1310
  finally show ?thesis .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1311
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1312
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61076
diff changeset
  1313
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1314
text\<open>Versions of the theorems above for the natural-number version of "choose"\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1315
lemma binomial_altdef_of_nat:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1316
  fixes n k :: nat
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61738
diff changeset
  1317
    and x :: "'a :: {field_char_0,field}"  \<comment>\<open>the point is to constrain @{typ 'a}\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1318
  assumes "k \<le> n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1319
  shows "of_nat (n choose k) = (\<Prod>i<k. of_nat (n - i) / of_nat (k - i) :: 'a)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1320
using assms
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1321
by (simp add: gbinomial_altdef_of_nat binomial_gbinomial of_nat_diff)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1322
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1323
lemma binomial_ge_n_over_k_pow_k:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1324
  fixes k n :: nat
59867
58043346ca64 given up separate type classes demanding `inverse 0 = 0`
haftmann
parents: 59862
diff changeset
  1325
    and x :: "'a :: linordered_field"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1326
  assumes "k \<le> n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1327
  shows "(of_nat n / of_nat k :: 'a) ^ k \<le> of_nat (n choose k)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1328
by (simp add: assms gbinomial_ge_n_over_k_pow_k binomial_gbinomial of_nat_diff)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1329
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1330
lemma binomial_le_pow:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1331
  assumes "r \<le> n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1332
  shows "n choose r \<le> n ^ r"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1333
proof -
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1334
  have "n choose r \<le> fact n div fact (n - r)"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1335
    using \<open>r \<le> n\<close> by (subst binomial_fact_lemma[symmetric]) auto
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1336
  with fact_div_fact_le_pow [OF assms] show ?thesis by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1337
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1338
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1339
lemma binomial_altdef_nat: "(k::nat) \<le> n \<Longrightarrow>
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1340
    n choose k = fact n div (fact k * fact (n - k))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1341
 by (subst binomial_fact_lemma [symmetric]) auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1342
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
  1343
lemma choose_dvd: "k \<le> n \<Longrightarrow> fact k * fact (n - k) dvd (fact n :: 'a :: {semiring_div,linordered_semidom})"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
  1344
  unfolding dvd_def
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
  1345
  apply (rule exI [where x="of_nat (n choose k)"])
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
  1346
  using binomial_fact_lemma [of k n, THEN arg_cong [where f = of_nat and 'b='a]]
63366
209c4cbbc4cd define binomial coefficents directly via combinatorial definition
haftmann
parents: 63363
diff changeset
  1347
  apply auto
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1348
  done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1349
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1350
lemma fact_fact_dvd_fact:
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
  1351
    "fact k * fact n dvd (fact (k+n) :: 'a :: {semiring_div,linordered_semidom})"
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
  1352
by (metis add.commute add_diff_cancel_left' choose_dvd le_add2)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1353
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1354
lemma choose_mult_lemma:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1355
     "((m+r+k) choose (m+k)) * ((m+k) choose k) = ((m+r+k) choose k) * ((m+r) choose m)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1356
proof -
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1357
  have "((m+r+k) choose (m+k)) * ((m+k) choose k) =
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1358
        fact (m+r + k) div (fact (m + k) * fact (m+r - m)) * (fact (m + k) div (fact k * fact m))"
63092
a949b2a5f51d eliminated use of empty "assms";
wenzelm
parents: 63040
diff changeset
  1359
    by (simp add: binomial_altdef_nat)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1360
  also have "... = fact (m+r+k) div (fact r * (fact k * fact m))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1361
    apply (subst div_mult_div_if_dvd)
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
  1362
    apply (auto simp: algebra_simps fact_fact_dvd_fact)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1363
    apply (metis add.assoc add.commute fact_fact_dvd_fact)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1364
    done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1365
  also have "... = (fact (m+r+k) * fact (m+r)) div (fact r * (fact k * fact m) * fact (m+r))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1366
    apply (subst div_mult_div_if_dvd [symmetric])
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
  1367
    apply (auto simp add: algebra_simps)
62344
759d684c0e60 pulled out legacy aliasses and infamous dvd interpretations into theory appendix
haftmann
parents: 62142
diff changeset
  1368
    apply (metis fact_fact_dvd_fact dvd_trans nat_mult_dvd_cancel_disj)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1369
    done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1370
  also have "... = (fact (m+r+k) div (fact k * fact (m+r)) * (fact (m+r) div (fact r * fact m)))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1371
    apply (subst div_mult_div_if_dvd)
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
  1372
    apply (auto simp: fact_fact_dvd_fact algebra_simps)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1373
    done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1374
  finally show ?thesis
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1375
    by (simp add: binomial_altdef_nat mult.commute)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1376
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1377
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1378
text\<open>The "Subset of a Subset" identity\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1379
lemma choose_mult:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1380
  assumes "k\<le>m" "m\<le>n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1381
    shows "(n choose m) * (m choose k) = (n choose k) * ((n-k) choose (m-k))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1382
using assms choose_mult_lemma [of "m-k" "n-m" k]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1383
by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1384
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1385
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1386
subsection \<open>Binomial coefficients\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1387
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1388
lemma choose_one: "(n::nat) choose 1 = n"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1389
  by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1390
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1391
(*FIXME: messy and apparently unused*)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1392
lemma binomial_induct [rule_format]: "(ALL (n::nat). P n n) \<longrightarrow>
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1393
    (ALL n. P (Suc n) 0) \<longrightarrow> (ALL n. (ALL k < n. P n k \<longrightarrow> P n (Suc k) \<longrightarrow>
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1394
    P (Suc n) (Suc k))) \<longrightarrow> (ALL k <= n. P n k)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1395
  apply (induct n)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1396
  apply auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1397
  apply (case_tac "k = 0")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1398
  apply auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1399
  apply (case_tac "k = Suc n")
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1400
  apply (auto simp add: le_Suc_eq elim: lessE)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1401
  done
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1402
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1403
lemma card_UNION:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1404
  assumes "finite A" and "\<forall>k \<in> A. finite k"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1405
  shows "card (\<Union>A) = nat (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (- 1) ^ (card I + 1) * int (card (\<Inter>I)))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1406
  (is "?lhs = ?rhs")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1407
proof -
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1408
  have "?rhs = nat (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (- 1) ^ (card I + 1) * (\<Sum>_\<in>\<Inter>I. 1))" by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1409
  also have "\<dots> = nat (\<Sum>I | I \<subseteq> A \<and> I \<noteq> {}. (\<Sum>_\<in>\<Inter>I. (- 1) ^ (card I + 1)))" (is "_ = nat ?rhs")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1410
    by(subst setsum_right_distrib) simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1411
  also have "?rhs = (\<Sum>(I, _)\<in>Sigma {I. I \<subseteq> A \<and> I \<noteq> {}} Inter. (- 1) ^ (card I + 1))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1412
    using assms by(subst setsum.Sigma)(auto)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1413
  also have "\<dots> = (\<Sum>(x, I)\<in>(SIGMA x:UNIV. {I. I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I}). (- 1) ^ (card I + 1))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1414
    by (rule setsum.reindex_cong [where l = "\<lambda>(x, y). (y, x)"]) (auto intro: inj_onI simp add: split_beta)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1415
  also have "\<dots> = (\<Sum>(x, I)\<in>(SIGMA x:\<Union>A. {I. I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I}). (- 1) ^ (card I + 1))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1416
    using assms by(auto intro!: setsum.mono_neutral_cong_right finite_SigmaI2 intro: finite_subset[where B="\<Union>A"])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1417
  also have "\<dots> = (\<Sum>x\<in>\<Union>A. (\<Sum>I|I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I. (- 1) ^ (card I + 1)))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1418
    using assms by(subst setsum.Sigma) auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1419
  also have "\<dots> = (\<Sum>_\<in>\<Union>A. 1)" (is "setsum ?lhs _ = _")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1420
  proof(rule setsum.cong[OF refl])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1421
    fix x
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1422
    assume x: "x \<in> \<Union>A"
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62481
diff changeset
  1423
    define K where "K = {X \<in> A. x \<in> X}"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1424
    with \<open>finite A\<close> have K: "finite K" by auto
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1425
    let ?I = "\<lambda>i. {I. I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1426
    have "inj_on snd (SIGMA i:{1..card A}. ?I i)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1427
      using assms by(auto intro!: inj_onI)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1428
    moreover have [symmetric]: "snd ` (SIGMA i:{1..card A}. ?I i) = {I. I \<subseteq> A \<and> I \<noteq> {} \<and> x \<in> \<Inter>I}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1429
      using assms by(auto intro!: rev_image_eqI[where x="(card a, a)" for a]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1430
        simp add: card_gt_0_iff[folded Suc_le_eq]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1431
        dest: finite_subset intro: card_mono)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1432
    ultimately have "?lhs x = (\<Sum>(i, I)\<in>(SIGMA i:{1..card A}. ?I i). (- 1) ^ (i + 1))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1433
      by (rule setsum.reindex_cong [where l = snd]) fastforce
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1434
    also have "\<dots> = (\<Sum>i=1..card A. (\<Sum>I|I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. (- 1) ^ (i + 1)))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1435
      using assms by(subst setsum.Sigma) auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1436
    also have "\<dots> = (\<Sum>i=1..card A. (- 1) ^ (i + 1) * (\<Sum>I|I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. 1))"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1437
      by(subst setsum_right_distrib) simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1438
    also have "\<dots> = (\<Sum>i=1..card K. (- 1) ^ (i + 1) * (\<Sum>I|I \<subseteq> K \<and> card I = i. 1))" (is "_ = ?rhs")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1439
    proof(rule setsum.mono_neutral_cong_right[rule_format])
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1440
      show "{1..card K} \<subseteq> {1..card A}" using \<open>finite A\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1441
        by(auto simp add: K_def intro: card_mono)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1442
    next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1443
      fix i
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1444
      assume "i \<in> {1..card A} - {1..card K}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1445
      hence i: "i \<le> card A" "card K < i" by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1446
      have "{I. I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I} = {I. I \<subseteq> K \<and> card I = i}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1447
        by(auto simp add: K_def)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1448
      also have "\<dots> = {}" using \<open>finite A\<close> i
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1449
        by(auto simp add: K_def dest: card_mono[rotated 1])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1450
      finally show "(- 1) ^ (i + 1) * (\<Sum>I | I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. 1 :: int) = 0"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1451
        by(simp only:) simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1452
    next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1453
      fix i
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1454
      have "(\<Sum>I | I \<subseteq> A \<and> card I = i \<and> x \<in> \<Inter>I. 1) = (\<Sum>I | I \<subseteq> K \<and> card I = i. 1 :: int)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1455
        (is "?lhs = ?rhs")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1456
        by(rule setsum.cong)(auto simp add: K_def)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1457
      thus "(- 1) ^ (i + 1) * ?lhs = (- 1) ^ (i + 1) * ?rhs" by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1458
    qed simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1459
    also have "{I. I \<subseteq> K \<and> card I = 0} = {{}}" using assms
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1460
      by(auto simp add: card_eq_0_iff K_def dest: finite_subset)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1461
    hence "?rhs = (\<Sum>i = 0..card K. (- 1) ^ (i + 1) * (\<Sum>I | I \<subseteq> K \<and> card I = i. 1 :: int)) + 1"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1462
      by(subst (2) setsum_head_Suc)(simp_all )
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1463
    also have "\<dots> = (\<Sum>i = 0..card K. (- 1) * ((- 1) ^ i * int (card K choose i))) + 1"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1464
      using K by(subst n_subsets[symmetric]) simp_all
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1465
    also have "\<dots> = - (\<Sum>i = 0..card K. (- 1) ^ i * int (card K choose i)) + 1"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1466
      by(subst setsum_right_distrib[symmetric]) simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1467
    also have "\<dots> =  - ((-1 + 1) ^ card K) + 1"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1468
      by(subst binomial_ring)(simp add: ac_simps)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1469
    also have "\<dots> = 1" using x K by(auto simp add: K_def card_gt_0_iff)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1470
    finally show "?lhs x = 1" .
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1471
  qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1472
  also have "nat \<dots> = card (\<Union>A)" by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1473
  finally show ?thesis ..
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1474
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1475
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61738
diff changeset
  1476
text\<open>The number of nat lists of length \<open>m\<close> summing to \<open>N\<close> is
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1477
@{term "(N + m - 1) choose N"}:\<close>
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1478
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1479
lemma card_length_listsum_rec:
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1480
  assumes "m\<ge>1"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1481
  shows "card {l::nat list. length l = m \<and> listsum l = N} =
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1482
    (card {l. length l = (m - 1) \<and> listsum l = N} +
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1483
    card {l. length l = m \<and> listsum l + 1 =  N})"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1484
    (is "card ?C = (card ?A + card ?B)")
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1485
proof -
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1486
  let ?A'="{l. length l = m \<and> listsum l = N \<and> hd l = 0}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1487
  let ?B'="{l. length l = m \<and> listsum l = N \<and> hd l \<noteq> 0}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1488
  let ?f ="\<lambda> l. 0#l"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1489
  let ?g ="\<lambda> l. (hd l + 1) # tl l"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1490
  have 1: "\<And>xs x. xs \<noteq> [] \<Longrightarrow> x = hd xs \<Longrightarrow> x # tl xs = xs" by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1491
  have 2: "\<And>xs. (xs::nat list) \<noteq> [] \<Longrightarrow> listsum(tl xs) = listsum xs - hd xs"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1492
    by(auto simp add: neq_Nil_conv)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1493
  have f: "bij_betw ?f ?A ?A'"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1494
    apply(rule bij_betw_byWitness[where f' = tl])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1495
    using assms
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1496
    by (auto simp: 2 length_0_conv[symmetric] 1 simp del: length_0_conv)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1497
  have 3: "\<And>xs:: nat list. xs \<noteq> [] \<Longrightarrow> hd xs + (listsum xs - hd xs) = listsum xs"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1498
    by (metis 1 listsum_simps(2) 2)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1499
  have g: "bij_betw ?g ?B ?B'"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1500
    apply(rule bij_betw_byWitness[where f' = "\<lambda> l. (hd l - 1) # tl l"])
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1501
    using assms
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1502
    by (auto simp: 2 length_0_conv[symmetric] intro!: 3
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1503
      simp del: length_greater_0_conv length_0_conv)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1504
  { fix M N :: nat have "finite {xs. size xs = M \<and> set xs \<subseteq> {0..<N}}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1505
    using finite_lists_length_eq[OF finite_atLeastLessThan] conj_commute by auto }
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1506
    note fin = this
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1507
  have fin_A: "finite ?A" using fin[of _ "N+1"]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1508
    by (intro finite_subset[where ?A = "?A" and ?B = "{xs. size xs = m - 1 \<and> set xs \<subseteq> {0..<N+1}}"],
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1509
      auto simp: member_le_listsum_nat less_Suc_eq_le)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1510
  have fin_B: "finite ?B"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1511
    by (intro finite_subset[where ?A = "?B" and ?B = "{xs. size xs = m \<and> set xs \<subseteq> {0..<N}}"],
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1512
      auto simp: member_le_listsum_nat less_Suc_eq_le fin)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1513
  have uni: "?C = ?A' \<union> ?B'" by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1514
  have disj: "?A' \<inter> ?B' = {}" by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1515
  have "card ?C = card(?A' \<union> ?B')" using uni by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1516
  also have "\<dots> = card ?A + card ?B"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1517
    using card_Un_disjoint[OF _ _ disj] bij_betw_finite[OF f] bij_betw_finite[OF g]
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1518
      bij_betw_same_card[OF f] bij_betw_same_card[OF g] fin_A fin_B
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1519
    by presburger
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1520
  finally show ?thesis .
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1521
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1522
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61738
diff changeset
  1523
lemma card_length_listsum: \<comment>"By Holden Lee, tidied by Tobias Nipkow"
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1524
  "card {l::nat list. size l = m \<and> listsum l = N} = (N + m - 1) choose N"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1525
proof (cases m)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1526
  case 0 then show ?thesis
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1527
    by (cases N) (auto simp: cong: conj_cong)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1528
next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1529
  case (Suc m')
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1530
    have m: "m\<ge>1" by (simp add: Suc)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1531
    then show ?thesis
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1532
    proof (induct "N + m - 1" arbitrary: N m)
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61738
diff changeset
  1533
      case 0   \<comment> "In the base case, the only solution is [0]."
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1534
      have [simp]: "{l::nat list. length l = Suc 0 \<and> (\<forall>n\<in>set l. n = 0)} = {[0]}"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1535
        by (auto simp: length_Suc_conv)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1536
      have "m=1 \<and> N=0" using 0 by linarith
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1537
      then show ?case by simp
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1538
    next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1539
      case (Suc k)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1540
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1541
      have c1: "card {l::nat list. size l = (m - 1) \<and> listsum l =  N} =
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1542
        (N + (m - 1) - 1) choose N"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1543
      proof cases
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1544
        assume "m = 1"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1545
        with Suc.hyps have "N\<ge>1" by auto
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60604
diff changeset
  1546
        with \<open>m = 1\<close> show ?thesis by (simp add: binomial_eq_0)
59667
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1547
      next
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1548
        assume "m \<noteq> 1" thus ?thesis using Suc by fastforce
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1549
      qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1550
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1551
      from Suc have c2: "card {l::nat list. size l = m \<and> listsum l + 1 = N} =
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1552
        (if N>0 then ((N - 1) + m - 1) choose (N - 1) else 0)"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1553
      proof -
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1554
        have aux: "\<And>m n. n > 0 \<Longrightarrow> Suc m = n \<longleftrightarrow> m = n - 1" by arith
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1555
        from Suc have "N>0 \<Longrightarrow>
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1556
          card {l::nat list. size l = m \<and> listsum l + 1 = N} =
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1557
          ((N - 1) + m - 1) choose (N - 1)" by (simp add: aux)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1558
        thus ?thesis by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1559
      qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1560
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1561
      from Suc.prems have "(card {l::nat list. size l = (m - 1) \<and> listsum l = N} +
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1562
          card {l::nat list. size l = m \<and> listsum l + 1 = N}) = (N + m - 1) choose N"
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1563
        by (auto simp: c1 c2 choose_reduce_nat[of "N + m - 1" N] simp del: One_nat_def)
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1564
      thus ?case using card_length_listsum_rec[OF Suc.prems] by auto
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1565
    qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1566
qed
651ea265d568 Removal of the file HOL/Number_Theory/Binomial!! And class field_char_0 now declared in Int.thy
paulson <lp15@cam.ac.uk>
parents: 59658
diff changeset
  1567
60604
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1568
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61738
diff changeset
  1569
lemma Suc_times_binomial_add: \<comment> \<open>by Lukas Bulwahn\<close>
60604
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1570
  "Suc a * (Suc (a + b) choose Suc a) = Suc b * (Suc (a + b) choose a)"
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1571
proof -
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1572
  have dvd: "Suc a * (fact a * fact b) dvd fact (Suc (a + b))" for a b
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1573
    using fact_fact_dvd_fact[of "Suc a" "b", where 'a=nat]
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1574
    by (simp only: fact_Suc add_Suc[symmetric] of_nat_id mult.assoc)
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1575
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1576
  have "Suc a * (fact (Suc (a + b)) div (Suc a * fact a * fact b)) =
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1577
      Suc a * fact (Suc (a + b)) div (Suc a * (fact a * fact b))"
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1578
    by (subst div_mult_swap[symmetric]; simp only: mult.assoc dvd)
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1579
  also have "\<dots> = Suc b * fact (Suc (a + b)) div (Suc b * (fact a * fact b))"
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1580
    by (simp only: div_mult_mult1)
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1581
  also have "\<dots> = Suc b * (fact (Suc (a + b)) div (Suc b * (fact a * fact b)))"
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1582
    using dvd[of b a] by (subst div_mult_swap[symmetric]; simp only: ac_simps dvd)
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1583
  finally show ?thesis
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1584
    by (subst (1 2) binomial_altdef_nat)
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1585
       (simp_all only: ac_simps diff_Suc_Suc Suc_diff_le diff_add_inverse fact_Suc of_nat_id)
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1586
qed
dd4253d5dd82 tuned src/HOL/ex/Ballot
hoelzl
parents: 60301
diff changeset
  1587
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1588
lemma fact_code [code]:
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1589
  "fact n = (of_nat (fold_atLeastAtMost_nat (op *) 2 n 1) :: 'a :: semiring_char_0)"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1590
proof -
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1591
  have "fact n = (of_nat (\<Prod>{1..n}) :: 'a)" by (simp add: fact_altdef')
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1592
  also have "\<Prod>{1..n} = \<Prod>{2..n}"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1593
    by (intro setprod.mono_neutral_right) auto
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1594
  also have "\<dots> = fold_atLeastAtMost_nat (op *) 2 n 1"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1595
    by (simp add: setprod_atLeastAtMost_code)
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1596
  finally show ?thesis .
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1597
qed
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1598
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1599
lemma setprod_lessThan_fold_atLeastAtMost_nat:
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1600
  "setprod f {..<Suc n} = fold_atLeastAtMost_nat (times \<circ> f) 0 n 1"
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1601
  by (simp add: lessThan_Suc_atMost atLeast0AtMost [symmetric] setprod_atLeastAtMost_code comp_def)
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1602
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1603
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1604
lemma pochhammer_code [code]:
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1605
  "pochhammer a n = (if n = 0 then 1 else
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1606
       fold_atLeastAtMost_nat (\<lambda>n acc. (a + of_nat n) * acc) 0 (n - 1) 1)"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1607
  by (cases n) (simp_all add: pochhammer_def setprod_lessThan_fold_atLeastAtMost_nat comp_def)
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1608
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1609
lemma gbinomial_code [code]:
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1610
  "a gchoose n = (if n = 0 then 1 else
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1611
     fold_atLeastAtMost_nat (\<lambda>n acc. (a - of_nat n) * acc) 0 (n - 1) 1 / fact n)"
63367
6c731c8b7f03 simplified definitions of combinatorial functions
haftmann
parents: 63366
diff changeset
  1612
  by (cases n) (simp_all add: gbinomial_def setprod_lessThan_fold_atLeastAtMost_nat comp_def)
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1613
62142
18a217591310 Deleted problematic code equation in Binomial temporarily.
eberlm
parents: 62128
diff changeset
  1614
(*TODO: This code equation breaks Scala code generation in HOL-Codegenerator_Test. We have to figure out why and how to prevent that. *)
18a217591310 Deleted problematic code equation in Binomial temporarily.
eberlm
parents: 62128
diff changeset
  1615
18a217591310 Deleted problematic code equation in Binomial temporarily.
eberlm
parents: 62128
diff changeset
  1616
(*
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1617
lemma binomial_code [code]:
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1618
  "(n choose k) =
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1619
      (if k > n then 0
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1620
       else if 2 * k > n then (n choose (n - k))
62142
18a217591310 Deleted problematic code equation in Binomial temporarily.
eberlm
parents: 62128
diff changeset
  1621
       else (fold_atLeastAtMost_nat (op * ) (n-k+1) n 1 div fact k))"
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1622
proof -
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1623
  {
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1624
    assume "k \<le> n"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1625
    hence "{1..n} = {1..n-k} \<union> {n-k+1..n}" by auto
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1626
    hence "(fact n :: nat) = fact (n-k) * \<Prod>{n-k+1..n}"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1627
      by (simp add: setprod.union_disjoint fact_altdef_nat)
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1628
  }
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1629
  thus ?thesis by (auto simp: binomial_altdef_nat mult_ac setprod_atLeastAtMost_code)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62347
diff changeset
  1630
qed
62142
18a217591310 Deleted problematic code equation in Binomial temporarily.
eberlm
parents: 62128
diff changeset
  1631
*)
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 61799
diff changeset
  1632
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15094
diff changeset
  1633
end