Replacing the theory Library/Binomial by Number_Theory/Binomial
authorpaulson <lp15@cam.ac.uk>
Wed Jan 29 12:51:37 2014 +0000 (2014-01-29)
changeset 55159608c157d743d
parent 55158 39bcdf19dd14
child 55160 2d69438b1b0c
child 55161 8eb891539804
Replacing the theory Library/Binomial by Number_Theory/Binomial
src/Doc/ROOT
src/Doc/Tutorial/Rules/Forward.thy
src/Doc/Tutorial/Rules/Primes.thy
src/Doc/Tutorial/Rules/TPrimes.thy
src/Doc/Tutorial/Sets/Examples.thy
src/HOL/Library/Binomial.thy
src/HOL/Library/Formal_Power_Series.thy
src/HOL/Library/Library.thy
src/HOL/ROOT
     1.1 --- a/src/Doc/ROOT	Mon Jan 27 17:13:33 2014 +0000
     1.2 +++ b/src/Doc/ROOT	Wed Jan 29 12:51:37 2014 +0000
     1.3 @@ -355,7 +355,7 @@
     1.4      "Rules/Blast"
     1.5      "Rules/Force"
     1.6    theories [pretty_margin = 64, thy_output_indent = 5]
     1.7 -    "Rules/Primes"
     1.8 +    "Rules/TPrimes"
     1.9      "Rules/Forward"
    1.10      "Rules/Tacticals"
    1.11      "Rules/find2"
     2.1 --- a/src/Doc/Tutorial/Rules/Forward.thy	Mon Jan 27 17:13:33 2014 +0000
     2.2 +++ b/src/Doc/Tutorial/Rules/Forward.thy	Wed Jan 29 12:51:37 2014 +0000
     2.3 @@ -1,4 +1,4 @@
     2.4 -theory Forward imports Primes begin
     2.5 +theory Forward imports TPrimes begin
     2.6  
     2.7  text{*\noindent
     2.8  Forward proof material: of, OF, THEN, simplify, rule_format.
     2.9 @@ -166,7 +166,7 @@
    2.10  example of "insert"
    2.11  *}
    2.12  
    2.13 -lemma relprime_dvd_mult: 
    2.14 +lemma relprime_dvd_mult:
    2.15        "\<lbrakk> gcd k n = 1; k dvd m*n \<rbrakk> \<Longrightarrow> k dvd m"
    2.16  apply (insert gcd_mult_distrib2 [of m k n])
    2.17  txt{*@{subgoals[display,indent=0,margin=65]}*}
     3.1 --- a/src/Doc/Tutorial/Rules/Primes.thy	Mon Jan 27 17:13:33 2014 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,155 +0,0 @@
     3.4 -(* EXTRACT from HOL/ex/Primes.thy*)
     3.5 -
     3.6 -(*Euclid's algorithm 
     3.7 -  This material now appears AFTER that of Forward.thy *)
     3.8 -theory Primes imports Main begin
     3.9 -
    3.10 -fun gcd :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
    3.11 -  "gcd m n = (if n=0 then m else gcd n (m mod n))"
    3.12 -
    3.13 -
    3.14 -text {*Now in Basic.thy!
    3.15 -@{thm[display]"dvd_def"}
    3.16 -\rulename{dvd_def}
    3.17 -*};
    3.18 -
    3.19 -
    3.20 -(*** Euclid's Algorithm ***)
    3.21 -
    3.22 -lemma gcd_0 [simp]: "gcd m 0 = m"
    3.23 -apply (simp);
    3.24 -done
    3.25 -
    3.26 -lemma gcd_non_0 [simp]: "0<n \<Longrightarrow> gcd m n = gcd n (m mod n)"
    3.27 -apply (simp)
    3.28 -done;
    3.29 -
    3.30 -declare gcd.simps [simp del];
    3.31 -
    3.32 -(*gcd(m,n) divides m and n.  The conjunctions don't seem provable separately*)
    3.33 -lemma gcd_dvd_both: "(gcd m n dvd m) \<and> (gcd m n dvd n)"
    3.34 -apply (induct_tac m n rule: gcd.induct)
    3.35 -  --{* @{subgoals[display,indent=0,margin=65]} *}
    3.36 -apply (case_tac "n=0")
    3.37 -txt{*subgoals after the case tac
    3.38 -@{subgoals[display,indent=0,margin=65]}
    3.39 -*};
    3.40 -apply (simp_all) 
    3.41 -  --{* @{subgoals[display,indent=0,margin=65]} *}
    3.42 -by (blast dest: dvd_mod_imp_dvd)
    3.43 -
    3.44 -
    3.45 -
    3.46 -text {*
    3.47 -@{thm[display] dvd_mod_imp_dvd}
    3.48 -\rulename{dvd_mod_imp_dvd}
    3.49 -
    3.50 -@{thm[display] dvd_trans}
    3.51 -\rulename{dvd_trans}
    3.52 -*}
    3.53 -
    3.54 -lemmas gcd_dvd1 [iff] = gcd_dvd_both [THEN conjunct1]
    3.55 -lemmas gcd_dvd2 [iff] = gcd_dvd_both [THEN conjunct2];
    3.56 -
    3.57 -
    3.58 -text {*
    3.59 -\begin{quote}
    3.60 -@{thm[display] gcd_dvd1}
    3.61 -\rulename{gcd_dvd1}
    3.62 -
    3.63 -@{thm[display] gcd_dvd2}
    3.64 -\rulename{gcd_dvd2}
    3.65 -\end{quote}
    3.66 -*};
    3.67 -
    3.68 -(*Maximality: for all m,n,k naturals, 
    3.69 -                if k divides m and k divides n then k divides gcd(m,n)*)
    3.70 -lemma gcd_greatest [rule_format]:
    3.71 -      "k dvd m \<longrightarrow> k dvd n \<longrightarrow> k dvd gcd m n"
    3.72 -apply (induct_tac m n rule: gcd.induct)
    3.73 -apply (case_tac "n=0")
    3.74 -txt{*subgoals after the case tac
    3.75 -@{subgoals[display,indent=0,margin=65]}
    3.76 -*};
    3.77 -apply (simp_all add: dvd_mod)
    3.78 -done
    3.79 -
    3.80 -text {*
    3.81 -@{thm[display] dvd_mod}
    3.82 -\rulename{dvd_mod}
    3.83 -*}
    3.84 -
    3.85 -(*just checking the claim that case_tac "n" works too*)
    3.86 -lemma "k dvd m \<longrightarrow> k dvd n \<longrightarrow> k dvd gcd m n"
    3.87 -apply (induct_tac m n rule: gcd.induct)
    3.88 -apply (case_tac "n")
    3.89 -apply (simp_all add: dvd_mod)
    3.90 -done
    3.91 -
    3.92 -
    3.93 -theorem gcd_greatest_iff [iff]: 
    3.94 -        "(k dvd gcd m n) = (k dvd m \<and> k dvd n)"
    3.95 -by (blast intro!: gcd_greatest intro: dvd_trans)
    3.96 -
    3.97 -
    3.98 -(**** The material below was omitted from the book ****)
    3.99 -
   3.100 -definition is_gcd :: "[nat,nat,nat] \<Rightarrow> bool" where        (*gcd as a relation*)
   3.101 -    "is_gcd p m n == p dvd m  \<and>  p dvd n  \<and>
   3.102 -                     (ALL d. d dvd m \<and> d dvd n \<longrightarrow> d dvd p)"
   3.103 -
   3.104 -(*Function gcd yields the Greatest Common Divisor*)
   3.105 -lemma is_gcd: "is_gcd (gcd m n) m n"
   3.106 -apply (simp add: is_gcd_def gcd_greatest);
   3.107 -done
   3.108 -
   3.109 -(*uniqueness of GCDs*)
   3.110 -lemma is_gcd_unique: "\<lbrakk> is_gcd m a b; is_gcd n a b \<rbrakk> \<Longrightarrow> m=n"
   3.111 -apply (simp add: is_gcd_def);
   3.112 -apply (blast intro: dvd_antisym)
   3.113 -done
   3.114 -
   3.115 -
   3.116 -text {*
   3.117 -@{thm[display] dvd_antisym}
   3.118 -\rulename{dvd_antisym}
   3.119 -
   3.120 -\begin{isabelle}
   3.121 -proof\ (prove):\ step\ 1\isanewline
   3.122 -\isanewline
   3.123 -goal\ (lemma\ is_gcd_unique):\isanewline
   3.124 -\isasymlbrakk is_gcd\ m\ a\ b;\ is_gcd\ n\ a\ b\isasymrbrakk \ \isasymLongrightarrow \ m\ =\ n\isanewline
   3.125 -\ 1.\ \isasymlbrakk m\ dvd\ a\ \isasymand \ m\ dvd\ b\ \isasymand \ (\isasymforall d.\ d\ dvd\ a\ \isasymand \ d\ dvd\ b\ \isasymlongrightarrow \ d\ dvd\ m);\isanewline
   3.126 -\ \ \ \ \ \ \ n\ dvd\ a\ \isasymand \ n\ dvd\ b\ \isasymand \ (\isasymforall d.\ d\ dvd\ a\ \isasymand \ d\ dvd\ b\ \isasymlongrightarrow \ d\ dvd\ n)\isasymrbrakk \isanewline
   3.127 -\ \ \ \ \isasymLongrightarrow \ m\ =\ n
   3.128 -\end{isabelle}
   3.129 -*};
   3.130 -
   3.131 -lemma gcd_assoc: "gcd (gcd k m) n = gcd k (gcd m n)"
   3.132 -  apply (rule is_gcd_unique)
   3.133 -  apply (rule is_gcd)
   3.134 -  apply (simp add: is_gcd_def);
   3.135 -  apply (blast intro: dvd_trans);
   3.136 -  done
   3.137 -
   3.138 -text{*
   3.139 -\begin{isabelle}
   3.140 -proof\ (prove):\ step\ 3\isanewline
   3.141 -\isanewline
   3.142 -goal\ (lemma\ gcd_assoc):\isanewline
   3.143 -gcd\ (gcd\ (k,\ m),\ n)\ =\ gcd\ (k,\ gcd\ (m,\ n))\isanewline
   3.144 -\ 1.\ gcd\ (k,\ gcd\ (m,\ n))\ dvd\ k\ \isasymand \isanewline
   3.145 -\ \ \ \ gcd\ (k,\ gcd\ (m,\ n))\ dvd\ m\ \isasymand \ gcd\ (k,\ gcd\ (m,\ n))\ dvd\ n
   3.146 -\end{isabelle}
   3.147 -*}
   3.148 -
   3.149 -
   3.150 -lemma gcd_dvd_gcd_mult: "gcd m n dvd gcd (k*m) n"
   3.151 -  apply (auto intro: dvd_trans [of _ m])
   3.152 -  done
   3.153 -
   3.154 -(*This is half of the proof (by dvd_antisym) of*)
   3.155 -lemma gcd_mult_cancel: "gcd k n = 1 \<Longrightarrow> gcd (k*m) n = gcd m n"
   3.156 -  oops
   3.157 -
   3.158 -end
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/Doc/Tutorial/Rules/TPrimes.thy	Wed Jan 29 12:51:37 2014 +0000
     4.3 @@ -0,0 +1,155 @@
     4.4 +(* EXTRACT from HOL/ex/Primes.thy*)
     4.5 +
     4.6 +(*Euclid's algorithm 
     4.7 +  This material now appears AFTER that of Forward.thy *)
     4.8 +theory TPrimes imports Main begin
     4.9 +
    4.10 +fun gcd :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
    4.11 +  "gcd m n = (if n=0 then m else gcd n (m mod n))"
    4.12 +
    4.13 +
    4.14 +text {*Now in Basic.thy!
    4.15 +@{thm[display]"dvd_def"}
    4.16 +\rulename{dvd_def}
    4.17 +*};
    4.18 +
    4.19 +
    4.20 +(*** Euclid's Algorithm ***)
    4.21 +
    4.22 +lemma gcd_0 [simp]: "gcd m 0 = m"
    4.23 +apply (simp);
    4.24 +done
    4.25 +
    4.26 +lemma gcd_non_0 [simp]: "0<n \<Longrightarrow> gcd m n = gcd n (m mod n)"
    4.27 +apply (simp)
    4.28 +done;
    4.29 +
    4.30 +declare gcd.simps [simp del];
    4.31 +
    4.32 +(*gcd(m,n) divides m and n.  The conjunctions don't seem provable separately*)
    4.33 +lemma gcd_dvd_both: "(gcd m n dvd m) \<and> (gcd m n dvd n)"
    4.34 +apply (induct_tac m n rule: gcd.induct)
    4.35 +  --{* @{subgoals[display,indent=0,margin=65]} *}
    4.36 +apply (case_tac "n=0")
    4.37 +txt{*subgoals after the case tac
    4.38 +@{subgoals[display,indent=0,margin=65]}
    4.39 +*};
    4.40 +apply (simp_all) 
    4.41 +  --{* @{subgoals[display,indent=0,margin=65]} *}
    4.42 +by (blast dest: dvd_mod_imp_dvd)
    4.43 +
    4.44 +
    4.45 +
    4.46 +text {*
    4.47 +@{thm[display] dvd_mod_imp_dvd}
    4.48 +\rulename{dvd_mod_imp_dvd}
    4.49 +
    4.50 +@{thm[display] dvd_trans}
    4.51 +\rulename{dvd_trans}
    4.52 +*}
    4.53 +
    4.54 +lemmas gcd_dvd1 [iff] = gcd_dvd_both [THEN conjunct1]
    4.55 +lemmas gcd_dvd2 [iff] = gcd_dvd_both [THEN conjunct2];
    4.56 +
    4.57 +
    4.58 +text {*
    4.59 +\begin{quote}
    4.60 +@{thm[display] gcd_dvd1}
    4.61 +\rulename{gcd_dvd1}
    4.62 +
    4.63 +@{thm[display] gcd_dvd2}
    4.64 +\rulename{gcd_dvd2}
    4.65 +\end{quote}
    4.66 +*};
    4.67 +
    4.68 +(*Maximality: for all m,n,k naturals, 
    4.69 +                if k divides m and k divides n then k divides gcd(m,n)*)
    4.70 +lemma gcd_greatest [rule_format]:
    4.71 +      "k dvd m \<longrightarrow> k dvd n \<longrightarrow> k dvd gcd m n"
    4.72 +apply (induct_tac m n rule: gcd.induct)
    4.73 +apply (case_tac "n=0")
    4.74 +txt{*subgoals after the case tac
    4.75 +@{subgoals[display,indent=0,margin=65]}
    4.76 +*};
    4.77 +apply (simp_all add: dvd_mod)
    4.78 +done
    4.79 +
    4.80 +text {*
    4.81 +@{thm[display] dvd_mod}
    4.82 +\rulename{dvd_mod}
    4.83 +*}
    4.84 +
    4.85 +(*just checking the claim that case_tac "n" works too*)
    4.86 +lemma "k dvd m \<longrightarrow> k dvd n \<longrightarrow> k dvd gcd m n"
    4.87 +apply (induct_tac m n rule: gcd.induct)
    4.88 +apply (case_tac "n")
    4.89 +apply (simp_all add: dvd_mod)
    4.90 +done
    4.91 +
    4.92 +
    4.93 +theorem gcd_greatest_iff [iff]: 
    4.94 +        "(k dvd gcd m n) = (k dvd m \<and> k dvd n)"
    4.95 +by (blast intro!: gcd_greatest intro: dvd_trans)
    4.96 +
    4.97 +
    4.98 +(**** The material below was omitted from the book ****)
    4.99 +
   4.100 +definition is_gcd :: "[nat,nat,nat] \<Rightarrow> bool" where        (*gcd as a relation*)
   4.101 +    "is_gcd p m n == p dvd m  \<and>  p dvd n  \<and>
   4.102 +                     (ALL d. d dvd m \<and> d dvd n \<longrightarrow> d dvd p)"
   4.103 +
   4.104 +(*Function gcd yields the Greatest Common Divisor*)
   4.105 +lemma is_gcd: "is_gcd (gcd m n) m n"
   4.106 +apply (simp add: is_gcd_def gcd_greatest);
   4.107 +done
   4.108 +
   4.109 +(*uniqueness of GCDs*)
   4.110 +lemma is_gcd_unique: "\<lbrakk> is_gcd m a b; is_gcd n a b \<rbrakk> \<Longrightarrow> m=n"
   4.111 +apply (simp add: is_gcd_def);
   4.112 +apply (blast intro: dvd_antisym)
   4.113 +done
   4.114 +
   4.115 +
   4.116 +text {*
   4.117 +@{thm[display] dvd_antisym}
   4.118 +\rulename{dvd_antisym}
   4.119 +
   4.120 +\begin{isabelle}
   4.121 +proof\ (prove):\ step\ 1\isanewline
   4.122 +\isanewline
   4.123 +goal\ (lemma\ is_gcd_unique):\isanewline
   4.124 +\isasymlbrakk is_gcd\ m\ a\ b;\ is_gcd\ n\ a\ b\isasymrbrakk \ \isasymLongrightarrow \ m\ =\ n\isanewline
   4.125 +\ 1.\ \isasymlbrakk m\ dvd\ a\ \isasymand \ m\ dvd\ b\ \isasymand \ (\isasymforall d.\ d\ dvd\ a\ \isasymand \ d\ dvd\ b\ \isasymlongrightarrow \ d\ dvd\ m);\isanewline
   4.126 +\ \ \ \ \ \ \ n\ dvd\ a\ \isasymand \ n\ dvd\ b\ \isasymand \ (\isasymforall d.\ d\ dvd\ a\ \isasymand \ d\ dvd\ b\ \isasymlongrightarrow \ d\ dvd\ n)\isasymrbrakk \isanewline
   4.127 +\ \ \ \ \isasymLongrightarrow \ m\ =\ n
   4.128 +\end{isabelle}
   4.129 +*};
   4.130 +
   4.131 +lemma gcd_assoc: "gcd (gcd k m) n = gcd k (gcd m n)"
   4.132 +  apply (rule is_gcd_unique)
   4.133 +  apply (rule is_gcd)
   4.134 +  apply (simp add: is_gcd_def);
   4.135 +  apply (blast intro: dvd_trans);
   4.136 +  done
   4.137 +
   4.138 +text{*
   4.139 +\begin{isabelle}
   4.140 +proof\ (prove):\ step\ 3\isanewline
   4.141 +\isanewline
   4.142 +goal\ (lemma\ gcd_assoc):\isanewline
   4.143 +gcd\ (gcd\ (k,\ m),\ n)\ =\ gcd\ (k,\ gcd\ (m,\ n))\isanewline
   4.144 +\ 1.\ gcd\ (k,\ gcd\ (m,\ n))\ dvd\ k\ \isasymand \isanewline
   4.145 +\ \ \ \ gcd\ (k,\ gcd\ (m,\ n))\ dvd\ m\ \isasymand \ gcd\ (k,\ gcd\ (m,\ n))\ dvd\ n
   4.146 +\end{isabelle}
   4.147 +*}
   4.148 +
   4.149 +
   4.150 +lemma gcd_dvd_gcd_mult: "gcd m n dvd gcd (k*m) n"
   4.151 +  apply (auto intro: dvd_trans [of _ m])
   4.152 +  done
   4.153 +
   4.154 +(*This is half of the proof (by dvd_antisym) of*)
   4.155 +lemma gcd_mult_cancel: "gcd k n = 1 \<Longrightarrow> gcd (k*m) n = gcd m n"
   4.156 +  oops
   4.157 +
   4.158 +end
     5.1 --- a/src/Doc/Tutorial/Sets/Examples.thy	Mon Jan 27 17:13:33 2014 +0000
     5.2 +++ b/src/Doc/Tutorial/Sets/Examples.thy	Wed Jan 29 12:51:37 2014 +0000
     5.3 @@ -1,4 +1,4 @@
     5.4 -theory Examples imports Main "~~/src/HOL/Library/Binomial" begin
     5.5 +theory Examples imports "~~/src/HOL/Number_Theory/Binomial" begin
     5.6  
     5.7  declare [[eta_contract = false]]
     5.8  
     5.9 @@ -44,7 +44,7 @@
    5.10  \rulename{Diff_disjoint}
    5.11  *}
    5.12  
    5.13 -  
    5.14 +
    5.15  
    5.16  lemma "A \<union> -A = UNIV"
    5.17  by blast
    5.18 @@ -142,7 +142,7 @@
    5.19  
    5.20  lemma "{x. x \<in> A} = A"
    5.21  by blast
    5.22 -  
    5.23 +
    5.24  text{*
    5.25  @{thm[display] Collect_mem_eq[no_vars]}
    5.26  \rulename{Collect_mem_eq}
    5.27 @@ -157,7 +157,7 @@
    5.28  definition prime :: "nat set" where
    5.29      "prime == {p. 1<p & (ALL m. m dvd p --> m=1 | m=p)}"
    5.30  
    5.31 -lemma "{p*q | p q. p\<in>prime \<and> q\<in>prime} = 
    5.32 +lemma "{p*q | p q. p\<in>prime \<and> q\<in>prime} =
    5.33         {z. \<exists>p q. z = p*q \<and> p\<in>prime \<and> q\<in>prime}"
    5.34  by (rule refl)
    5.35  
     6.1 --- a/src/HOL/Library/Binomial.thy	Mon Jan 27 17:13:33 2014 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,606 +0,0 @@
     6.4 -(*  Title:      HOL/Library/Binomial.thy
     6.5 -    Author:     Lawrence C Paulson, Amine Chaieb
     6.6 -    Copyright   1997  University of Cambridge
     6.7 -*)
     6.8 -
     6.9 -header {* Binomial Coefficients *}
    6.10 -
    6.11 -theory Binomial
    6.12 -imports Complex_Main
    6.13 -begin
    6.14 -
    6.15 -text {* This development is based on the work of Andy Gordon and
    6.16 -  Florian Kammueller. *}
    6.17 -
    6.18 -subsection {* Basic definitions and lemmas *}
    6.19 -
    6.20 -primrec binomial :: "nat \<Rightarrow> nat \<Rightarrow> nat" (infixl "choose" 65)
    6.21 -where
    6.22 -  "0 choose k = (if k = 0 then 1 else 0)"
    6.23 -| "Suc n choose k = (if k = 0 then 1 else (n choose (k - 1)) + (n choose k))"
    6.24 -
    6.25 -lemma binomial_n_0 [simp]: "(n choose 0) = 1"
    6.26 -  by (cases n) simp_all
    6.27 -
    6.28 -lemma binomial_0_Suc [simp]: "(0 choose Suc k) = 0"
    6.29 -  by simp
    6.30 -
    6.31 -lemma binomial_Suc_Suc [simp]: "(Suc n choose Suc k) = (n choose k) + (n choose Suc k)"
    6.32 -  by simp
    6.33 -
    6.34 -lemma choose_reduce_nat: 
    6.35 -  "0 < (n::nat) \<Longrightarrow> 0 < k \<Longrightarrow>
    6.36 -    (n choose k) = ((n - 1) choose k) + ((n - 1) choose (k - 1))"
    6.37 -  by (metis Suc_diff_1 binomial.simps(2) nat_add_commute neq0_conv)
    6.38 -
    6.39 -lemma binomial_eq_0: "n < k \<Longrightarrow> n choose k = 0"
    6.40 -  by (induct n arbitrary: k) auto
    6.41 -
    6.42 -declare binomial.simps [simp del]
    6.43 -
    6.44 -lemma binomial_n_n [simp]: "n choose n = 1"
    6.45 -  by (induct n) (simp_all add: binomial_eq_0)
    6.46 -
    6.47 -lemma binomial_Suc_n [simp]: "Suc n choose n = Suc n"
    6.48 -  by (induct n) simp_all
    6.49 -
    6.50 -lemma binomial_1 [simp]: "n choose Suc 0 = n"
    6.51 -  by (induct n) simp_all
    6.52 -
    6.53 -lemma zero_less_binomial: "k \<le> n \<Longrightarrow> n choose k > 0"
    6.54 -  by (induct n k rule: diff_induct) simp_all
    6.55 -
    6.56 -lemma binomial_eq_0_iff [simp]: "n choose k = 0 \<longleftrightarrow> n < k"
    6.57 -  by (metis binomial_eq_0 less_numeral_extra(3) not_less zero_less_binomial)
    6.58 -
    6.59 -lemma zero_less_binomial_iff [simp]: "n choose k > 0 \<longleftrightarrow> k \<le> n"
    6.60 -  by (metis binomial_eq_0_iff not_less0 not_less zero_less_binomial)
    6.61 -
    6.62 -(*Might be more useful if re-oriented*)
    6.63 -lemma Suc_times_binomial_eq:
    6.64 -  "k \<le> n \<Longrightarrow> Suc n * (n choose k) = (Suc n choose Suc k) * Suc k"
    6.65 -  apply (induct n arbitrary: k)
    6.66 -   apply (simp add: binomial.simps)
    6.67 -   apply (case_tac k)
    6.68 -  apply (auto simp add: add_mult_distrib add_mult_distrib2 le_Suc_eq binomial_eq_0)
    6.69 -  done
    6.70 -
    6.71 -text{*This is the well-known version, but it's harder to use because of the
    6.72 -  need to reason about division.*}
    6.73 -lemma binomial_Suc_Suc_eq_times:
    6.74 -    "k \<le> n \<Longrightarrow> (Suc n choose Suc k) = (Suc n * (n choose k)) div Suc k"
    6.75 -  by (simp add: Suc_times_binomial_eq del: mult_Suc mult_Suc_right)
    6.76 -
    6.77 -text{*Another version, with -1 instead of Suc.*}
    6.78 -lemma times_binomial_minus1_eq:
    6.79 -  "k \<le> n \<Longrightarrow> 0 < k \<Longrightarrow> (n choose k) * k = n * ((n - 1) choose (k - 1))"
    6.80 -  using Suc_times_binomial_eq [where n = "n - 1" and k = "k - 1"]
    6.81 -  by (auto split add: nat_diff_split)
    6.82 -
    6.83 -
    6.84 -subsection {* Combinatorial theorems involving @{text "choose"} *}
    6.85 -
    6.86 -text {*By Florian Kamm\"uller, tidied by LCP.*}
    6.87 -
    6.88 -lemma card_s_0_eq_empty: "finite A \<Longrightarrow> card {B. B \<subseteq> A & card B = 0} = 1"
    6.89 -  by (simp cong add: conj_cong add: finite_subset [THEN card_0_eq])
    6.90 -
    6.91 -lemma choose_deconstruct: "finite M \<Longrightarrow> x \<notin> M \<Longrightarrow>
    6.92 -    {s. s \<subseteq> insert x M \<and> card s = Suc k} =
    6.93 -    {s. s \<subseteq> M \<and> card s = Suc k} \<union> {s. \<exists>t. t \<subseteq> M \<and> card t = k \<and> s = insert x t}"
    6.94 -  apply safe
    6.95 -     apply (auto intro: finite_subset [THEN card_insert_disjoint])
    6.96 -  by (metis (full_types) Diff_insert_absorb Set.set_insert Zero_neq_Suc card_Diff_singleton_if 
    6.97 -     card_eq_0_iff diff_Suc_1 in_mono subset_insert_iff)
    6.98 -
    6.99 -lemma finite_bex_subset [simp]:
   6.100 -  assumes "finite B"
   6.101 -    and "\<And>A. A \<subseteq> B \<Longrightarrow> finite {x. P x A}"
   6.102 -  shows "finite {x. \<exists>A \<subseteq> B. P x A}"
   6.103 -  by (metis (no_types) assms finite_Collect_bounded_ex finite_Collect_subsets)
   6.104 -
   6.105 -text{*There are as many subsets of @{term A} having cardinality @{term k}
   6.106 - as there are sets obtained from the former by inserting a fixed element
   6.107 - @{term x} into each.*}
   6.108 -lemma constr_bij:
   6.109 -   "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow>
   6.110 -    card {B. \<exists>C. C \<subseteq> A \<and> card C = k \<and> B = insert x C} =
   6.111 -    card {B. B \<subseteq> A & card(B) = k}"
   6.112 -  apply (rule card_bij_eq [where f = "\<lambda>s. s - {x}" and g = "insert x"])
   6.113 -  apply (auto elim!: equalityE simp add: inj_on_def)
   6.114 -  apply (metis card_Diff_singleton_if finite_subset in_mono)
   6.115 -  done
   6.116 -
   6.117 -text {*
   6.118 -  Main theorem: combinatorial statement about number of subsets of a set.
   6.119 -*}
   6.120 -
   6.121 -theorem n_subsets: "finite A \<Longrightarrow> card {B. B \<subseteq> A \<and> card B = k} = (card A choose k)"
   6.122 -proof (induct k arbitrary: A)
   6.123 -  case 0 then show ?case by (simp add: card_s_0_eq_empty)
   6.124 -next
   6.125 -  case (Suc k)
   6.126 -  show ?case using `finite A`
   6.127 -  proof (induct A)
   6.128 -    case empty show ?case by (simp add: card_s_0_eq_empty)
   6.129 -  next
   6.130 -    case (insert x A)
   6.131 -    then show ?case using Suc.hyps
   6.132 -      apply (simp add: card_s_0_eq_empty choose_deconstruct)
   6.133 -      apply (subst card_Un_disjoint)
   6.134 -         prefer 4 apply (force simp add: constr_bij)
   6.135 -        prefer 3 apply force
   6.136 -       prefer 2 apply (blast intro: finite_Pow_iff [THEN iffD2]
   6.137 -         finite_subset [of _ "Pow (insert x F)" for F])
   6.138 -      apply (blast intro: finite_Pow_iff [THEN iffD2, THEN [2] finite_subset])
   6.139 -      done
   6.140 -  qed
   6.141 -qed
   6.142 -
   6.143 -
   6.144 -subsection {* The binomial theorem (courtesy of Tobias Nipkow): *}
   6.145 -
   6.146 -text{* Avigad's version, generalized to any commutative ring *}
   6.147 -theorem binomial_ring: "(a+b::'a::{comm_ring_1,power})^n = 
   6.148 -  (\<Sum>k=0..n. (of_nat (n choose k)) * a^k * b^(n-k))" (is "?P n")
   6.149 -proof (induct n)
   6.150 -  case 0 then show "?P 0" by simp
   6.151 -next
   6.152 -  case (Suc n)
   6.153 -  have decomp: "{0..n+1} = {0} Un {n+1} Un {1..n}"
   6.154 -    by auto
   6.155 -  have decomp2: "{0..n} = {0} Un {1..n}"
   6.156 -    by auto
   6.157 -  have "(a+b)^(n+1) = 
   6.158 -      (a+b) * (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k))"
   6.159 -    using Suc.hyps by simp
   6.160 -  also have "\<dots> = a*(\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k)) +
   6.161 -                   b*(\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k))"
   6.162 -    by (rule distrib)
   6.163 -  also have "\<dots> = (\<Sum>k=0..n. of_nat (n choose k) * a^(k+1) * b^(n-k)) +
   6.164 -                  (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k+1))"
   6.165 -    by (auto simp add: setsum_right_distrib mult_ac)
   6.166 -  also have "\<dots> = (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n+1-k)) +
   6.167 -                  (\<Sum>k=1..n+1. of_nat (n choose (k - 1)) * a^k * b^(n+1-k))"
   6.168 -    by (simp add:setsum_shift_bounds_cl_Suc_ivl Suc_diff_le field_simps  
   6.169 -        del:setsum_cl_ivl_Suc)
   6.170 -  also have "\<dots> = a^(n+1) + b^(n+1) +
   6.171 -                  (\<Sum>k=1..n. of_nat (n choose (k - 1)) * a^k * b^(n+1-k)) +
   6.172 -                  (\<Sum>k=1..n. of_nat (n choose k) * a^k * b^(n+1-k))"
   6.173 -    by (simp add: decomp2)
   6.174 -  also have
   6.175 -      "\<dots> = a^(n+1) + b^(n+1) + 
   6.176 -            (\<Sum>k=1..n. of_nat(n+1 choose k) * a^k * b^(n+1-k))"
   6.177 -    by (auto simp add: field_simps setsum_addf [symmetric] choose_reduce_nat)
   6.178 -  also have "\<dots> = (\<Sum>k=0..n+1. of_nat (n+1 choose k) * a^k * b^(n+1-k))"
   6.179 -    using decomp by (simp add: field_simps)
   6.180 -  finally show "?P (Suc n)" by simp
   6.181 -qed
   6.182 -
   6.183 -text{* Original version for the naturals *}
   6.184 -corollary binomial: "(a+b::nat)^n = (\<Sum>k=0..n. (of_nat (n choose k)) * a^k * b^(n-k))"
   6.185 -    using binomial_ring [of "int a" "int b" n]
   6.186 -  by (simp only: of_nat_add [symmetric] of_nat_mult [symmetric] of_nat_power [symmetric]
   6.187 -           of_nat_setsum [symmetric]
   6.188 -           of_nat_eq_iff of_nat_id)
   6.189 -
   6.190 -subsection{* Pochhammer's symbol : generalized rising factorial *}
   6.191 -
   6.192 -text {* See @{url "http://en.wikipedia.org/wiki/Pochhammer_symbol"} *}
   6.193 -
   6.194 -definition "pochhammer (a::'a::comm_semiring_1) n =
   6.195 -  (if n = 0 then 1 else setprod (\<lambda>n. a + of_nat n) {0 .. n - 1})"
   6.196 -
   6.197 -lemma pochhammer_0 [simp]: "pochhammer a 0 = 1"
   6.198 -  by (simp add: pochhammer_def)
   6.199 -
   6.200 -lemma pochhammer_1 [simp]: "pochhammer a 1 = a"
   6.201 -  by (simp add: pochhammer_def)
   6.202 -
   6.203 -lemma pochhammer_Suc0 [simp]: "pochhammer a (Suc 0) = a"
   6.204 -  by (simp add: pochhammer_def)
   6.205 -
   6.206 -lemma pochhammer_Suc_setprod: "pochhammer a (Suc n) = setprod (\<lambda>n. a + of_nat n) {0 .. n}"
   6.207 -  by (simp add: pochhammer_def)
   6.208 -
   6.209 -lemma setprod_nat_ivl_Suc: "setprod f {0 .. Suc n} = setprod f {0..n} * f (Suc n)"
   6.210 -proof -
   6.211 -  have "{0..Suc n} = {0..n} \<union> {Suc n}" by auto
   6.212 -  then show ?thesis by (simp add: field_simps)
   6.213 -qed
   6.214 -
   6.215 -lemma setprod_nat_ivl_1_Suc: "setprod f {0 .. Suc n} = f 0 * setprod f {1.. Suc n}"
   6.216 -proof -
   6.217 -  have "{0..Suc n} = {0} \<union> {1 .. Suc n}" by auto
   6.218 -  then show ?thesis by simp
   6.219 -qed
   6.220 -
   6.221 -
   6.222 -lemma pochhammer_Suc: "pochhammer a (Suc n) = pochhammer a n * (a + of_nat n)"
   6.223 -proof (cases n)
   6.224 -  case 0
   6.225 -  then show ?thesis by simp
   6.226 -next
   6.227 -  case (Suc n)
   6.228 -  show ?thesis unfolding Suc pochhammer_Suc_setprod setprod_nat_ivl_Suc ..
   6.229 -qed
   6.230 -
   6.231 -lemma pochhammer_rec: "pochhammer a (Suc n) = a * pochhammer (a + 1) n"
   6.232 -proof (cases "n = 0")
   6.233 -  case True
   6.234 -  then show ?thesis by (simp add: pochhammer_Suc_setprod)
   6.235 -next
   6.236 -  case False
   6.237 -  have *: "finite {1 .. n}" "0 \<notin> {1 .. n}" by auto
   6.238 -  have eq: "insert 0 {1 .. n} = {0..n}" by auto
   6.239 -  have **: "(\<Prod>n\<in>{1\<Colon>nat..n}. a + of_nat n) = (\<Prod>n\<in>{0\<Colon>nat..n - 1}. a + 1 + of_nat n)"
   6.240 -    apply (rule setprod_reindex_cong [where f = Suc])
   6.241 -    using False
   6.242 -    apply (auto simp add: fun_eq_iff field_simps)
   6.243 -    done
   6.244 -  show ?thesis
   6.245 -    apply (simp add: pochhammer_def)
   6.246 -    unfolding setprod_insert [OF *, unfolded eq]
   6.247 -    using ** apply (simp add: field_simps)
   6.248 -    done
   6.249 -qed
   6.250 -
   6.251 -lemma pochhammer_fact: "of_nat (fact n) = pochhammer 1 n"
   6.252 -  unfolding fact_altdef_nat
   6.253 -  apply (cases n)
   6.254 -   apply (simp_all add: of_nat_setprod pochhammer_Suc_setprod)
   6.255 -  apply (rule setprod_reindex_cong[where f=Suc])
   6.256 -    apply (auto simp add: fun_eq_iff)
   6.257 -  done
   6.258 -
   6.259 -lemma pochhammer_of_nat_eq_0_lemma:
   6.260 -  assumes "k > n"
   6.261 -  shows "pochhammer (- (of_nat n :: 'a:: idom)) k = 0"
   6.262 -proof (cases "n = 0")
   6.263 -  case True
   6.264 -  then show ?thesis
   6.265 -    using assms by (cases k) (simp_all add: pochhammer_rec)
   6.266 -next
   6.267 -  case False
   6.268 -  from assms obtain h where "k = Suc h" by (cases k) auto
   6.269 -  then show ?thesis
   6.270 -    by (simp add: pochhammer_Suc_setprod)
   6.271 -       (metis Suc_leI Suc_le_mono assms atLeastAtMost_iff less_eq_nat.simps(1))
   6.272 -qed
   6.273 -
   6.274 -lemma pochhammer_of_nat_eq_0_lemma':
   6.275 -  assumes kn: "k \<le> n"
   6.276 -  shows "pochhammer (- (of_nat n :: 'a:: {idom,ring_char_0})) k \<noteq> 0"
   6.277 -proof (cases k)
   6.278 -  case 0
   6.279 -  then show ?thesis by simp
   6.280 -next
   6.281 -  case (Suc h)
   6.282 -  then show ?thesis
   6.283 -    apply (simp add: pochhammer_Suc_setprod)
   6.284 -    using Suc kn apply (auto simp add: algebra_simps)
   6.285 -    done
   6.286 -qed
   6.287 -
   6.288 -lemma pochhammer_of_nat_eq_0_iff:
   6.289 -  shows "pochhammer (- (of_nat n :: 'a:: {idom,ring_char_0})) k = 0 \<longleftrightarrow> k > n"
   6.290 -  (is "?l = ?r")
   6.291 -  using pochhammer_of_nat_eq_0_lemma[of n k, where ?'a='a]
   6.292 -    pochhammer_of_nat_eq_0_lemma'[of k n, where ?'a = 'a]
   6.293 -  by (auto simp add: not_le[symmetric])
   6.294 -
   6.295 -
   6.296 -lemma pochhammer_eq_0_iff: "pochhammer a n = (0::'a::field_char_0) \<longleftrightarrow> (\<exists>k < n. a = - of_nat k)"
   6.297 -  apply (auto simp add: pochhammer_of_nat_eq_0_iff)
   6.298 -  apply (cases n)
   6.299 -   apply (auto simp add: pochhammer_def algebra_simps group_add_class.eq_neg_iff_add_eq_0)
   6.300 -  apply (metis leD not_less_eq)
   6.301 -  done
   6.302 -
   6.303 -
   6.304 -lemma pochhammer_eq_0_mono:
   6.305 -  "pochhammer a n = (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a m = 0"
   6.306 -  unfolding pochhammer_eq_0_iff by auto
   6.307 -
   6.308 -lemma pochhammer_neq_0_mono:
   6.309 -  "pochhammer a m \<noteq> (0::'a::field_char_0) \<Longrightarrow> m \<ge> n \<Longrightarrow> pochhammer a n \<noteq> 0"
   6.310 -  unfolding pochhammer_eq_0_iff by auto
   6.311 -
   6.312 -lemma pochhammer_minus:
   6.313 -  assumes kn: "k \<le> n"
   6.314 -  shows "pochhammer (- b) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (b - of_nat k + 1) k"
   6.315 -proof (cases k)
   6.316 -  case 0
   6.317 -  then show ?thesis by simp
   6.318 -next
   6.319 -  case (Suc h)
   6.320 -  have eq: "((- 1) ^ Suc h :: 'a) = setprod (%i. - 1) {0 .. h}"
   6.321 -    using setprod_constant[where A="{0 .. h}" and y="- 1 :: 'a"]
   6.322 -    by auto
   6.323 -  show ?thesis
   6.324 -    unfolding Suc pochhammer_Suc_setprod eq setprod_timesf[symmetric]
   6.325 -    apply (rule strong_setprod_reindex_cong[where f = "%i. h - i"])
   6.326 -    using Suc
   6.327 -    apply (auto simp add: inj_on_def image_def of_nat_diff)
   6.328 -    apply (metis atLeast0AtMost atMost_iff diff_diff_cancel diff_le_self)
   6.329 -    done
   6.330 -qed
   6.331 -
   6.332 -lemma pochhammer_minus':
   6.333 -  assumes kn: "k \<le> n"
   6.334 -  shows "pochhammer (b - of_nat k + 1) k = ((- 1) ^ k :: 'a::comm_ring_1) * pochhammer (- b) k"
   6.335 -  unfolding pochhammer_minus[OF kn, where b=b]
   6.336 -  unfolding mult_assoc[symmetric]
   6.337 -  unfolding power_add[symmetric]
   6.338 -  by simp
   6.339 -
   6.340 -lemma pochhammer_same: "pochhammer (- of_nat n) n =
   6.341 -    ((- 1) ^ n :: 'a::comm_ring_1) * of_nat (fact n)"
   6.342 -  unfolding pochhammer_minus[OF le_refl[of n]]
   6.343 -  by (simp add: of_nat_diff pochhammer_fact)
   6.344 -
   6.345 -
   6.346 -subsection{* Generalized binomial coefficients *}
   6.347 -
   6.348 -definition gbinomial :: "'a::field_char_0 \<Rightarrow> nat \<Rightarrow> 'a" (infixl "gchoose" 65)
   6.349 -  where "a gchoose n =
   6.350 -    (if n = 0 then 1 else (setprod (\<lambda>i. a - of_nat i) {0 .. n - 1}) / of_nat (fact n))"
   6.351 -
   6.352 -lemma gbinomial_0 [simp]: "a gchoose 0 = 1" "0 gchoose (Suc n) = 0"
   6.353 -  apply (simp_all add: gbinomial_def)
   6.354 -  apply (subgoal_tac "(\<Prod>i\<Colon>nat\<in>{0\<Colon>nat..n}. - of_nat i) = (0::'b)")
   6.355 -   apply (simp del:setprod_zero_iff)
   6.356 -  apply simp
   6.357 -  done
   6.358 -
   6.359 -lemma gbinomial_pochhammer: "a gchoose n = (- 1) ^ n * pochhammer (- a) n / of_nat (fact n)"
   6.360 -proof (cases "n = 0")
   6.361 -  case True
   6.362 -  then show ?thesis by simp
   6.363 -next
   6.364 -  case False
   6.365 -  from this setprod_constant[of "{0 .. n - 1}" "- (1:: 'a)"]
   6.366 -  have eq: "(- (1\<Colon>'a)) ^ n = setprod (\<lambda>i. - 1) {0 .. n - 1}"
   6.367 -    by auto
   6.368 -  from False show ?thesis
   6.369 -    by (simp add: pochhammer_def gbinomial_def field_simps
   6.370 -      eq setprod_timesf[symmetric])
   6.371 -qed
   6.372 -
   6.373 -lemma binomial_fact_lemma: "k \<le> n \<Longrightarrow> fact k * fact (n - k) * (n choose k) = fact n"
   6.374 -proof (induct n arbitrary: k rule: nat_less_induct)
   6.375 -  fix n k assume H: "\<forall>m<n. \<forall>x\<le>m. fact x * fact (m - x) * (m choose x) =
   6.376 -                      fact m" and kn: "k \<le> n"
   6.377 -  let ?ths = "fact k * fact (n - k) * (n choose k) = fact n"
   6.378 -  { assume "n=0" then have ?ths using kn by simp }
   6.379 -  moreover
   6.380 -  { assume "k=0" then have ?ths using kn by simp }
   6.381 -  moreover
   6.382 -  { assume nk: "n=k" then have ?ths by simp }
   6.383 -  moreover
   6.384 -  { fix m h assume n: "n = Suc m" and h: "k = Suc h" and hm: "h < m"
   6.385 -    from n have mn: "m < n" by arith
   6.386 -    from hm have hm': "h \<le> m" by arith
   6.387 -    from hm h n kn have km: "k \<le> m" by arith
   6.388 -    have "m - h = Suc (m - Suc h)" using  h km hm by arith
   6.389 -    with km h have th0: "fact (m - h) = (m - h) * fact (m - k)"
   6.390 -      by simp
   6.391 -    from n h th0
   6.392 -    have "fact k * fact (n - k) * (n choose k) =
   6.393 -        k * (fact h * fact (m - h) * (m choose h)) + 
   6.394 -        (m - h) * (fact k * fact (m - k) * (m choose k))"
   6.395 -      by (simp add: field_simps)
   6.396 -    also have "\<dots> = (k + (m - h)) * fact m"
   6.397 -      using H[rule_format, OF mn hm'] H[rule_format, OF mn km]
   6.398 -      by (simp add: field_simps)
   6.399 -    finally have ?ths using h n km by simp }
   6.400 -  moreover have "n=0 \<or> k = 0 \<or> k = n \<or> (\<exists>m h. n = Suc m \<and> k = Suc h \<and> h < m)"
   6.401 -    using kn by presburger
   6.402 -  ultimately show ?ths by blast
   6.403 -qed
   6.404 -
   6.405 -lemma binomial_fact:
   6.406 -  assumes kn: "k \<le> n"
   6.407 -  shows "(of_nat (n choose k) :: 'a::field_char_0) =
   6.408 -    of_nat (fact n) / (of_nat (fact k) * of_nat (fact (n - k)))"
   6.409 -  using binomial_fact_lemma[OF kn]
   6.410 -  by (simp add: field_simps of_nat_mult [symmetric])
   6.411 -
   6.412 -lemma binomial_gbinomial: "of_nat (n choose k) = of_nat n gchoose k"
   6.413 -proof -
   6.414 -  { assume kn: "k > n"
   6.415 -    then have ?thesis
   6.416 -      by (subst binomial_eq_0[OF kn]) 
   6.417 -         (simp add: gbinomial_pochhammer field_simps  pochhammer_of_nat_eq_0_iff) }
   6.418 -  moreover
   6.419 -  { assume "k=0" then have ?thesis by simp }
   6.420 -  moreover
   6.421 -  { assume kn: "k \<le> n" and k0: "k\<noteq> 0"
   6.422 -    from k0 obtain h where h: "k = Suc h" by (cases k) auto
   6.423 -    from h
   6.424 -    have eq:"(- 1 :: 'a) ^ k = setprod (\<lambda>i. - 1) {0..h}"
   6.425 -      by (subst setprod_constant) auto
   6.426 -    have eq': "(\<Prod>i\<in>{0..h}. of_nat n + - (of_nat i :: 'a)) = (\<Prod>i\<in>{n - h..n}. of_nat i)"
   6.427 -      apply (rule strong_setprod_reindex_cong[where f="op - n"])
   6.428 -        using h kn
   6.429 -        apply (simp_all add: inj_on_def image_iff Bex_def set_eq_iff)
   6.430 -        apply clarsimp
   6.431 -        apply presburger
   6.432 -       apply presburger
   6.433 -      apply (simp add: fun_eq_iff field_simps of_nat_add[symmetric] del: of_nat_add)
   6.434 -      done
   6.435 -    have th0: "finite {1..n - Suc h}" "finite {n - h .. n}"
   6.436 -        "{1..n - Suc h} \<inter> {n - h .. n} = {}" and
   6.437 -        eq3: "{1..n - Suc h} \<union> {n - h .. n} = {1..n}"
   6.438 -      using h kn by auto
   6.439 -    from eq[symmetric]
   6.440 -    have ?thesis using kn
   6.441 -      apply (simp add: binomial_fact[OF kn, where ?'a = 'a]
   6.442 -        gbinomial_pochhammer field_simps pochhammer_Suc_setprod)
   6.443 -      apply (simp add: pochhammer_Suc_setprod fact_altdef_nat h
   6.444 -        of_nat_setprod setprod_timesf[symmetric] eq' del: One_nat_def power_Suc)
   6.445 -      unfolding setprod_Un_disjoint[OF th0, unfolded eq3, of "of_nat:: nat \<Rightarrow> 'a"] eq[unfolded h]
   6.446 -      unfolding mult_assoc[symmetric]
   6.447 -      unfolding setprod_timesf[symmetric]
   6.448 -      apply simp
   6.449 -      apply (rule strong_setprod_reindex_cong[where f= "op - n"])
   6.450 -        apply (auto simp add: inj_on_def image_iff Bex_def)
   6.451 -       apply presburger
   6.452 -      apply (subgoal_tac "(of_nat (n - x) :: 'a) = of_nat n - of_nat x")
   6.453 -       apply simp
   6.454 -      apply (rule of_nat_diff)
   6.455 -      apply simp
   6.456 -      done
   6.457 -  }
   6.458 -  moreover
   6.459 -  have "k > n \<or> k = 0 \<or> (k \<le> n \<and> k \<noteq> 0)" by arith
   6.460 -  ultimately show ?thesis by blast
   6.461 -qed
   6.462 -
   6.463 -lemma gbinomial_1[simp]: "a gchoose 1 = a"
   6.464 -  by (simp add: gbinomial_def)
   6.465 -
   6.466 -lemma gbinomial_Suc0[simp]: "a gchoose (Suc 0) = a"
   6.467 -  by (simp add: gbinomial_def)
   6.468 -
   6.469 -lemma gbinomial_mult_1:
   6.470 -  "a * (a gchoose n) =
   6.471 -    of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))"  (is "?l = ?r")
   6.472 -proof -
   6.473 -  have "?r = ((- 1) ^n * pochhammer (- a) n / of_nat (fact n)) * (of_nat n - (- a + of_nat n))"
   6.474 -    unfolding gbinomial_pochhammer
   6.475 -      pochhammer_Suc fact_Suc of_nat_mult right_diff_distrib power_Suc
   6.476 -    by (simp add:  field_simps del: of_nat_Suc)
   6.477 -  also have "\<dots> = ?l" unfolding gbinomial_pochhammer
   6.478 -    by (simp add: field_simps)
   6.479 -  finally show ?thesis ..
   6.480 -qed
   6.481 -
   6.482 -lemma gbinomial_mult_1':
   6.483 -    "(a gchoose n) * a = of_nat n * (a gchoose n) + of_nat (Suc n) * (a gchoose (Suc n))"
   6.484 -  by (simp add: mult_commute gbinomial_mult_1)
   6.485 -
   6.486 -lemma gbinomial_Suc:
   6.487 -    "a gchoose (Suc k) = (setprod (\<lambda>i. a - of_nat i) {0 .. k}) / of_nat (fact (Suc k))"
   6.488 -  by (simp add: gbinomial_def)
   6.489 -
   6.490 -lemma gbinomial_mult_fact:
   6.491 -  "(of_nat (fact (Suc k)) :: 'a) * ((a::'a::field_char_0) gchoose (Suc k)) =
   6.492 -    (setprod (\<lambda>i. a - of_nat i) {0 .. k})"
   6.493 -  by (simp_all add: gbinomial_Suc field_simps del: fact_Suc)
   6.494 -
   6.495 -lemma gbinomial_mult_fact':
   6.496 -  "((a::'a::field_char_0) gchoose (Suc k)) * (of_nat (fact (Suc k)) :: 'a) =
   6.497 -    (setprod (\<lambda>i. a - of_nat i) {0 .. k})"
   6.498 -  using gbinomial_mult_fact[of k a]
   6.499 -  by (subst mult_commute)
   6.500 -
   6.501 -
   6.502 -lemma gbinomial_Suc_Suc:
   6.503 -  "((a::'a::field_char_0) + 1) gchoose (Suc k) = a gchoose k + (a gchoose (Suc k))"
   6.504 -proof (cases k)
   6.505 -  case 0
   6.506 -  then show ?thesis by simp
   6.507 -next
   6.508 -  case (Suc h)
   6.509 -  have eq0: "(\<Prod>i\<in>{1..k}. (a + 1) - of_nat i) = (\<Prod>i\<in>{0..h}. a - of_nat i)"
   6.510 -    apply (rule strong_setprod_reindex_cong[where f = Suc])
   6.511 -      using Suc
   6.512 -      apply auto
   6.513 -    done
   6.514 -
   6.515 -  have "of_nat (fact (Suc k)) * (a gchoose k + (a gchoose (Suc k))) =
   6.516 -    ((a gchoose Suc h) * of_nat (fact (Suc h)) * of_nat (Suc k)) + (\<Prod>i\<in>{0\<Colon>nat..Suc h}. a - of_nat i)"
   6.517 -    apply (simp add: Suc field_simps del: fact_Suc)
   6.518 -    unfolding gbinomial_mult_fact'
   6.519 -    apply (subst fact_Suc)
   6.520 -    unfolding of_nat_mult
   6.521 -    apply (subst mult_commute)
   6.522 -    unfolding mult_assoc
   6.523 -    unfolding gbinomial_mult_fact
   6.524 -    apply (simp add: field_simps)
   6.525 -    done
   6.526 -  also have "\<dots> = (\<Prod>i\<in>{0..h}. a - of_nat i) * (a + 1)"
   6.527 -    unfolding gbinomial_mult_fact' setprod_nat_ivl_Suc
   6.528 -    by (simp add: field_simps Suc)
   6.529 -  also have "\<dots> = (\<Prod>i\<in>{0..k}. (a + 1) - of_nat i)"
   6.530 -    using eq0
   6.531 -    by (simp add: Suc setprod_nat_ivl_1_Suc)
   6.532 -  also have "\<dots> = of_nat (fact (Suc k)) * ((a + 1) gchoose (Suc k))"
   6.533 -    unfolding gbinomial_mult_fact ..
   6.534 -  finally show ?thesis by (simp del: fact_Suc)
   6.535 -qed
   6.536 -
   6.537 -
   6.538 -lemma binomial_symmetric:
   6.539 -  assumes kn: "k \<le> n"
   6.540 -  shows "n choose k = n choose (n - k)"
   6.541 -proof-
   6.542 -  from kn have kn': "n - k \<le> n" by arith
   6.543 -  from binomial_fact_lemma[OF kn] binomial_fact_lemma[OF kn']
   6.544 -  have "fact k * fact (n - k) * (n choose k) =
   6.545 -    fact (n - k) * fact (n - (n - k)) * (n choose (n - k))" by simp
   6.546 -  then show ?thesis using kn by simp
   6.547 -qed
   6.548 -
   6.549 -(* Contributed by Manuel Eberl *)
   6.550 -(* Alternative definition of the binomial coefficient as \<Prod>i<k. (n - i) / (k - i) *)
   6.551 -lemma binomial_altdef_of_nat:
   6.552 -  fixes n k :: nat
   6.553 -    and x :: "'a :: {field_char_0,field_inverse_zero}"
   6.554 -  assumes "k \<le> n"
   6.555 -  shows "of_nat (n choose k) = (\<Prod>i<k. of_nat (n - i) / of_nat (k - i) :: 'a)"
   6.556 -proof (cases "0 < k")
   6.557 -  case True
   6.558 -  then have "(of_nat (n choose k) :: 'a) = (\<Prod>i<k. of_nat n - of_nat i) / of_nat (fact k)"
   6.559 -    unfolding binomial_gbinomial gbinomial_def
   6.560 -    by (auto simp: gr0_conv_Suc lessThan_Suc_atMost atLeast0AtMost)
   6.561 -  also have "\<dots> = (\<Prod>i<k. of_nat (n - i) / of_nat (k - i) :: 'a)"
   6.562 -    using `k \<le> n` unfolding fact_eq_rev_setprod_nat of_nat_setprod
   6.563 -    by (auto simp add: setprod_dividef intro!: setprod_cong of_nat_diff[symmetric])
   6.564 -  finally show ?thesis .
   6.565 -next
   6.566 -  case False
   6.567 -  then show ?thesis by simp
   6.568 -qed
   6.569 -
   6.570 -lemma binomial_ge_n_over_k_pow_k:
   6.571 -  fixes k n :: nat
   6.572 -    and x :: "'a :: linordered_field_inverse_zero"
   6.573 -  assumes "0 < k"
   6.574 -    and "k \<le> n"
   6.575 -  shows "(of_nat n / of_nat k :: 'a) ^ k \<le> of_nat (n choose k)"
   6.576 -proof -
   6.577 -  have "(of_nat n / of_nat k :: 'a) ^ k = (\<Prod>i<k. of_nat n / of_nat k :: 'a)"
   6.578 -    by (simp add: setprod_constant)
   6.579 -  also have "\<dots> \<le> of_nat (n choose k)"
   6.580 -    unfolding binomial_altdef_of_nat[OF `k\<le>n`]
   6.581 -  proof (safe intro!: setprod_mono)
   6.582 -    fix i :: nat
   6.583 -    assume  "i < k"
   6.584 -    from assms have "n * i \<ge> i * k" by simp
   6.585 -    then have "n * k - n * i \<le> n * k - i * k" by arith
   6.586 -    then have "n * (k - i) \<le> (n - i) * k"
   6.587 -      by (simp add: diff_mult_distrib2 nat_mult_commute)
   6.588 -    then have "of_nat n * of_nat (k - i) \<le> of_nat (n - i) * (of_nat k :: 'a)"
   6.589 -      unfolding of_nat_mult[symmetric] of_nat_le_iff .
   6.590 -    with assms show "of_nat n / of_nat k \<le> of_nat (n - i) / (of_nat (k - i) :: 'a)"
   6.591 -      using `i < k` by (simp add: field_simps)
   6.592 -  qed (simp add: zero_le_divide_iff)
   6.593 -  finally show ?thesis .
   6.594 -qed
   6.595 -
   6.596 -lemma binomial_le_pow:
   6.597 -  assumes "r \<le> n"
   6.598 -  shows "n choose r \<le> n ^ r"
   6.599 -proof -
   6.600 -  have "n choose r \<le> fact n div fact (n - r)"
   6.601 -    using `r \<le> n` by (subst binomial_fact_lemma[symmetric]) auto
   6.602 -  with fact_div_fact_le_pow [OF assms] show ?thesis by auto
   6.603 -qed
   6.604 -
   6.605 -lemma binomial_altdef_nat: "(k::nat) \<le> n \<Longrightarrow>
   6.606 -    n choose k = fact n div (fact k * fact (n - k))"
   6.607 - by (subst binomial_fact_lemma [symmetric]) auto
   6.608 -
   6.609 -end
     7.1 --- a/src/HOL/Library/Formal_Power_Series.thy	Mon Jan 27 17:13:33 2014 +0000
     7.2 +++ b/src/HOL/Library/Formal_Power_Series.thy	Wed Jan 29 12:51:37 2014 +0000
     7.3 @@ -5,7 +5,7 @@
     7.4  header{* A formalization of formal power series *}
     7.5  
     7.6  theory Formal_Power_Series
     7.7 -imports Binomial
     7.8 +imports "~~/src/HOL/Number_Theory/Binomial"
     7.9  begin
    7.10  
    7.11  
     8.1 --- a/src/HOL/Library/Library.thy	Mon Jan 27 17:13:33 2014 +0000
     8.2 +++ b/src/HOL/Library/Library.thy	Wed Jan 29 12:51:37 2014 +0000
     8.3 @@ -3,7 +3,6 @@
     8.4  imports
     8.5    AList
     8.6    BigO
     8.7 -  Binomial
     8.8    Bit
     8.9    BNF_Decl
    8.10    Boolean_Algebra
     9.1 --- a/src/HOL/ROOT	Mon Jan 27 17:13:33 2014 +0000
     9.2 +++ b/src/HOL/ROOT	Wed Jan 29 12:51:37 2014 +0000
     9.3 @@ -258,8 +258,8 @@
     9.4    theories [document = false]
     9.5      (* Preliminaries from set and number theory *)
     9.6      "~~/src/HOL/Library/FuncSet"
     9.7 -    "~~/src/HOL/Old_Number_Theory/Primes"
     9.8 -    "~~/src/HOL/Library/Binomial"
     9.9 +    "~~/src/HOL/Number_Theory/Primes"
    9.10 +    "~~/src/HOL/Number_Theory/Binomial"
    9.11      "~~/src/HOL/Library/Permutation"
    9.12    theories
    9.13      (*** New development, based on explicit structures ***)