src/HOL/Analysis/Gamma_Function.thy
changeset 69529 4ab9657b3257
parent 69260 0a9688695a1b
child 69566 c41954ee87cf
equal deleted inserted replaced
69526:5574d504cf36 69529:4ab9657b3257
   550 lemma uniformly_summable_deriv_ln_Gamma:
   550 lemma uniformly_summable_deriv_ln_Gamma:
   551   assumes z: "(z :: 'a :: {real_normed_field,banach}) \<noteq> 0" and d: "d > 0" "d \<le> norm z/2"
   551   assumes z: "(z :: 'a :: {real_normed_field,banach}) \<noteq> 0" and d: "d > 0" "d \<le> norm z/2"
   552   shows "uniformly_convergent_on (ball z d)
   552   shows "uniformly_convergent_on (ball z d)
   553             (\<lambda>k z. \<Sum>i<k. inverse (of_nat (Suc i)) - inverse (z + of_nat (Suc i)))"
   553             (\<lambda>k z. \<Sum>i<k. inverse (of_nat (Suc i)) - inverse (z + of_nat (Suc i)))"
   554            (is "uniformly_convergent_on _ (\<lambda>k z. \<Sum>i<k. ?f i z)")
   554            (is "uniformly_convergent_on _ (\<lambda>k z. \<Sum>i<k. ?f i z)")
   555 proof (rule weierstrass_m_test'_ev)
   555 proof (rule Weierstrass_m_test'_ev)
   556   {
   556   {
   557     fix t assume t: "t \<in> ball z d"
   557     fix t assume t: "t \<in> ball z d"
   558     have "norm z = norm (t + (z - t))" by simp
   558     have "norm z = norm (t + (z - t))" by simp
   559     have "norm (t + (z - t)) \<le> norm t + norm (z - t)" by (rule norm_triangle_ineq)
   559     have "norm (t + (z - t)) \<le> norm t + norm (z - t)" by (rule norm_triangle_ineq)
   560     also from t d have "norm (z - t) < norm z / 2" by (simp add: dist_norm)
   560     also from t d have "norm (z - t) < norm z / 2" by (simp add: dist_norm)
   663 
   663 
   664 lemma Polygamma_converges:
   664 lemma Polygamma_converges:
   665   fixes z :: "'a :: {real_normed_field,banach}"
   665   fixes z :: "'a :: {real_normed_field,banach}"
   666   assumes z: "z \<noteq> 0" and n: "n \<ge> 2"
   666   assumes z: "z \<noteq> 0" and n: "n \<ge> 2"
   667   shows "uniformly_convergent_on (ball z d) (\<lambda>k z. \<Sum>i<k. inverse ((z + of_nat i)^n))"
   667   shows "uniformly_convergent_on (ball z d) (\<lambda>k z. \<Sum>i<k. inverse ((z + of_nat i)^n))"
   668 proof (rule weierstrass_m_test'_ev)
   668 proof (rule Weierstrass_m_test'_ev)
   669   define e where "e = (1 + d / norm z)"
   669   define e where "e = (1 + d / norm z)"
   670   define m where "m = nat \<lceil>norm z * e\<rceil>"
   670   define m where "m = nat \<lceil>norm z * e\<rceil>"
   671   {
   671   {
   672     fix t assume t: "t \<in> ball z d"
   672     fix t assume t: "t \<in> ball z d"
   673     have "norm t = norm (z + (t - z))" by simp
   673     have "norm t = norm (z + (t - z))" by simp
  2526 
  2526 
  2527 
  2527 
  2528 
  2528 
  2529 subsubsection \<open>Weierstrass form\<close>
  2529 subsubsection \<open>Weierstrass form\<close>
  2530 
  2530 
  2531 definition Gamma_series_weierstrass :: "'a :: {banach,real_normed_field} \<Rightarrow> nat \<Rightarrow> 'a" where
  2531 definition Gamma_series_Weierstrass :: "'a :: {banach,real_normed_field} \<Rightarrow> nat \<Rightarrow> 'a" where
  2532   "Gamma_series_weierstrass z n =
  2532   "Gamma_series_Weierstrass z n =
  2533      exp (-euler_mascheroni * z) / z * (\<Prod>k=1..n. exp (z / of_nat k) / (1 + z / of_nat k))"
  2533      exp (-euler_mascheroni * z) / z * (\<Prod>k=1..n. exp (z / of_nat k) / (1 + z / of_nat k))"
  2534 
  2534 
  2535 definition%unimportant
  2535 definition%unimportant
  2536   rGamma_series_weierstrass :: "'a :: {banach,real_normed_field} \<Rightarrow> nat \<Rightarrow> 'a" where
  2536   rGamma_series_Weierstrass :: "'a :: {banach,real_normed_field} \<Rightarrow> nat \<Rightarrow> 'a" where
  2537   "rGamma_series_weierstrass z n =
  2537   "rGamma_series_Weierstrass z n =
  2538      exp (euler_mascheroni * z) * z * (\<Prod>k=1..n. (1 + z / of_nat k) * exp (-z / of_nat k))"
  2538      exp (euler_mascheroni * z) * z * (\<Prod>k=1..n. (1 + z / of_nat k) * exp (-z / of_nat k))"
  2539 
  2539 
  2540 lemma Gamma_series_weierstrass_nonpos_Ints:
  2540 lemma Gamma_series_Weierstrass_nonpos_Ints:
  2541   "eventually (\<lambda>k. Gamma_series_weierstrass (- of_nat n) k = 0) sequentially"
  2541   "eventually (\<lambda>k. Gamma_series_Weierstrass (- of_nat n) k = 0) sequentially"
  2542   using eventually_ge_at_top[of n] by eventually_elim (auto simp: Gamma_series_weierstrass_def)
  2542   using eventually_ge_at_top[of n] by eventually_elim (auto simp: Gamma_series_Weierstrass_def)
  2543 
  2543 
  2544 lemma rGamma_series_weierstrass_nonpos_Ints:
  2544 lemma rGamma_series_Weierstrass_nonpos_Ints:
  2545   "eventually (\<lambda>k. rGamma_series_weierstrass (- of_nat n) k = 0) sequentially"
  2545   "eventually (\<lambda>k. rGamma_series_Weierstrass (- of_nat n) k = 0) sequentially"
  2546   using eventually_ge_at_top[of n] by eventually_elim (auto simp: rGamma_series_weierstrass_def)
  2546   using eventually_ge_at_top[of n] by eventually_elim (auto simp: rGamma_series_Weierstrass_def)
  2547 
  2547 
  2548 theorem Gamma_weierstrass_complex: "Gamma_series_weierstrass z \<longlonglongrightarrow> Gamma (z :: complex)"
  2548 theorem Gamma_Weierstrass_complex: "Gamma_series_Weierstrass z \<longlonglongrightarrow> Gamma (z :: complex)"
  2549 proof (cases "z \<in> \<int>\<^sub>\<le>\<^sub>0")
  2549 proof (cases "z \<in> \<int>\<^sub>\<le>\<^sub>0")
  2550   case True
  2550   case True
  2551   then obtain n where "z = - of_nat n" by (elim nonpos_Ints_cases')
  2551   then obtain n where "z = - of_nat n" by (elim nonpos_Ints_cases')
  2552   also from True have "Gamma_series_weierstrass \<dots> \<longlonglongrightarrow> Gamma z"
  2552   also from True have "Gamma_series_Weierstrass \<dots> \<longlonglongrightarrow> Gamma z"
  2553     by (simp add: tendsto_cong[OF Gamma_series_weierstrass_nonpos_Ints] Gamma_nonpos_Int)
  2553     by (simp add: tendsto_cong[OF Gamma_series_Weierstrass_nonpos_Ints] Gamma_nonpos_Int)
  2554   finally show ?thesis .
  2554   finally show ?thesis .
  2555 next
  2555 next
  2556   case False
  2556   case False
  2557   hence z: "z \<noteq> 0" by auto
  2557   hence z: "z \<noteq> 0" by auto
  2558   let ?f = "(\<lambda>x. \<Prod>x = Suc 0..x. exp (z / of_nat x) / (1 + z / of_nat x))"
  2558   let ?f = "(\<lambda>x. \<Prod>x = Suc 0..x. exp (z / of_nat x) / (1 + z / of_nat x))"
  2563     by (simp only: atLeastLessThanSuc_atLeastAtMost [symmetric] One_nat_def
  2563     by (simp only: atLeastLessThanSuc_atLeastAtMost [symmetric] One_nat_def
  2564                    sum_shift_bounds_Suc_ivl sums_def atLeast0LessThan)
  2564                    sum_shift_bounds_Suc_ivl sums_def atLeast0LessThan)
  2565   from tendsto_exp[OF this] False z have "?f \<longlonglongrightarrow> z * exp (euler_mascheroni * z) * Gamma z"
  2565   from tendsto_exp[OF this] False z have "?f \<longlonglongrightarrow> z * exp (euler_mascheroni * z) * Gamma z"
  2566     by (simp add: exp_add exp_sum exp_diff mult_ac Gamma_complex_altdef A)
  2566     by (simp add: exp_add exp_sum exp_diff mult_ac Gamma_complex_altdef A)
  2567   from tendsto_mult[OF tendsto_const[of "exp (-euler_mascheroni * z) / z"] this] z
  2567   from tendsto_mult[OF tendsto_const[of "exp (-euler_mascheroni * z) / z"] this] z
  2568     show "Gamma_series_weierstrass z \<longlonglongrightarrow> Gamma z"
  2568     show "Gamma_series_Weierstrass z \<longlonglongrightarrow> Gamma z"
  2569     by (simp add: exp_minus divide_simps Gamma_series_weierstrass_def [abs_def])
  2569     by (simp add: exp_minus divide_simps Gamma_series_Weierstrass_def [abs_def])
  2570 qed
  2570 qed
  2571 
  2571 
  2572 lemma tendsto_complex_of_real_iff: "((\<lambda>x. complex_of_real (f x)) \<longlongrightarrow> of_real c) F = (f \<longlongrightarrow> c) F"
  2572 lemma tendsto_complex_of_real_iff: "((\<lambda>x. complex_of_real (f x)) \<longlongrightarrow> of_real c) F = (f \<longlongrightarrow> c) F"
  2573   by (rule tendsto_of_real_iff)
  2573   by (rule tendsto_of_real_iff)
  2574 
  2574 
  2575 lemma Gamma_weierstrass_real: "Gamma_series_weierstrass x \<longlonglongrightarrow> Gamma (x :: real)"
  2575 lemma Gamma_Weierstrass_real: "Gamma_series_Weierstrass x \<longlonglongrightarrow> Gamma (x :: real)"
  2576   using Gamma_weierstrass_complex[of "of_real x"] unfolding Gamma_series_weierstrass_def[abs_def]
  2576   using Gamma_Weierstrass_complex[of "of_real x"] unfolding Gamma_series_Weierstrass_def[abs_def]
  2577   by (subst tendsto_complex_of_real_iff [symmetric])
  2577   by (subst tendsto_complex_of_real_iff [symmetric])
  2578      (simp_all add: exp_of_real[symmetric] Gamma_complex_of_real)
  2578      (simp_all add: exp_of_real[symmetric] Gamma_complex_of_real)
  2579 
  2579 
  2580 lemma rGamma_weierstrass_complex: "rGamma_series_weierstrass z \<longlonglongrightarrow> rGamma (z :: complex)"
  2580 lemma rGamma_Weierstrass_complex: "rGamma_series_Weierstrass z \<longlonglongrightarrow> rGamma (z :: complex)"
  2581 proof (cases "z \<in> \<int>\<^sub>\<le>\<^sub>0")
  2581 proof (cases "z \<in> \<int>\<^sub>\<le>\<^sub>0")
  2582   case True
  2582   case True
  2583   then obtain n where "z = - of_nat n" by (elim nonpos_Ints_cases')
  2583   then obtain n where "z = - of_nat n" by (elim nonpos_Ints_cases')
  2584   also from True have "rGamma_series_weierstrass \<dots> \<longlonglongrightarrow> rGamma z"
  2584   also from True have "rGamma_series_Weierstrass \<dots> \<longlonglongrightarrow> rGamma z"
  2585     by (simp add: tendsto_cong[OF rGamma_series_weierstrass_nonpos_Ints] rGamma_nonpos_Int)
  2585     by (simp add: tendsto_cong[OF rGamma_series_Weierstrass_nonpos_Ints] rGamma_nonpos_Int)
  2586   finally show ?thesis .
  2586   finally show ?thesis .
  2587 next
  2587 next
  2588   case False
  2588   case False
  2589   have "rGamma_series_weierstrass z = (\<lambda>n. inverse (Gamma_series_weierstrass z n))"
  2589   have "rGamma_series_Weierstrass z = (\<lambda>n. inverse (Gamma_series_Weierstrass z n))"
  2590     by (simp add: rGamma_series_weierstrass_def[abs_def] Gamma_series_weierstrass_def
  2590     by (simp add: rGamma_series_Weierstrass_def[abs_def] Gamma_series_Weierstrass_def
  2591                   exp_minus divide_inverse prod_inversef[symmetric] mult_ac)
  2591                   exp_minus divide_inverse prod_inversef[symmetric] mult_ac)
  2592   also from False have "\<dots> \<longlonglongrightarrow> inverse (Gamma z)"
  2592   also from False have "\<dots> \<longlonglongrightarrow> inverse (Gamma z)"
  2593     by (intro tendsto_intros Gamma_weierstrass_complex) (simp add: Gamma_eq_zero_iff)
  2593     by (intro tendsto_intros Gamma_Weierstrass_complex) (simp add: Gamma_eq_zero_iff)
  2594   finally show ?thesis by (simp add: Gamma_def)
  2594   finally show ?thesis by (simp add: Gamma_def)
  2595 qed
  2595 qed
  2596 
  2596 
  2597 subsubsection \<open>Binomial coefficient form\<close>
  2597 subsubsection \<open>Binomial coefficient form\<close>
  2598 
  2598 
  3173 
  3173 
  3174 theorem sin_product_formula_complex:
  3174 theorem sin_product_formula_complex:
  3175   fixes z :: complex
  3175   fixes z :: complex
  3176   shows "(\<lambda>n. of_real pi * z * (\<Prod>k=1..n. 1 - z^2 / of_nat k^2)) \<longlonglongrightarrow> sin (of_real pi * z)"
  3176   shows "(\<lambda>n. of_real pi * z * (\<Prod>k=1..n. 1 - z^2 / of_nat k^2)) \<longlonglongrightarrow> sin (of_real pi * z)"
  3177 proof -
  3177 proof -
  3178   let ?f = "rGamma_series_weierstrass"
  3178   let ?f = "rGamma_series_Weierstrass"
  3179   have "(\<lambda>n. (- of_real pi * inverse z) * (?f z n * ?f (- z) n))
  3179   have "(\<lambda>n. (- of_real pi * inverse z) * (?f z n * ?f (- z) n))
  3180             \<longlonglongrightarrow> (- of_real pi * inverse z) * (rGamma z * rGamma (- z))"
  3180             \<longlonglongrightarrow> (- of_real pi * inverse z) * (rGamma z * rGamma (- z))"
  3181     by (intro tendsto_intros rGamma_weierstrass_complex)
  3181     by (intro tendsto_intros rGamma_Weierstrass_complex)
  3182   also have "(\<lambda>n. (- of_real pi * inverse z) * (?f z n * ?f (-z) n)) =
  3182   also have "(\<lambda>n. (- of_real pi * inverse z) * (?f z n * ?f (-z) n)) =
  3183                     (\<lambda>n. of_real pi * z * (\<Prod>k=1..n. 1 - z^2 / of_nat k ^ 2))"
  3183                     (\<lambda>n. of_real pi * z * (\<Prod>k=1..n. 1 - z^2 / of_nat k ^ 2))"
  3184   proof
  3184   proof
  3185     fix n :: nat
  3185     fix n :: nat
  3186     have "(- of_real pi * inverse z) * (?f z n * ?f (-z) n) =
  3186     have "(- of_real pi * inverse z) * (?f z n * ?f (-z) n) =
  3187               of_real pi * z * (\<Prod>k=1..n. (of_nat k - z) * (of_nat k + z) / of_nat k ^ 2)"
  3187               of_real pi * z * (\<Prod>k=1..n. (of_nat k - z) * (of_nat k + z) / of_nat k ^ 2)"
  3188       by (simp add: rGamma_series_weierstrass_def mult_ac exp_minus
  3188       by (simp add: rGamma_series_Weierstrass_def mult_ac exp_minus
  3189                     divide_simps prod.distrib[symmetric] power2_eq_square)
  3189                     divide_simps prod.distrib[symmetric] power2_eq_square)
  3190     also have "(\<Prod>k=1..n. (of_nat k - z) * (of_nat k + z) / of_nat k ^ 2) =
  3190     also have "(\<Prod>k=1..n. (of_nat k - z) * (of_nat k + z) / of_nat k ^ 2) =
  3191                  (\<Prod>k=1..n. 1 - z^2 / of_nat k ^ 2)"
  3191                  (\<Prod>k=1..n. 1 - z^2 / of_nat k ^ 2)"
  3192       by (intro prod.cong) (simp_all add: power2_eq_square field_simps)
  3192       by (intro prod.cong) (simp_all add: power2_eq_square field_simps)
  3193     finally show "(- of_real pi * inverse z) * (?f z n * ?f (-z) n) = of_real pi * z * \<dots>"
  3193     finally show "(- of_real pi * inverse z) * (?f z n * ?f (-z) n) = of_real pi * z * \<dots>"
  3255   qed
  3255   qed
  3256 
  3256 
  3257   have "continuous_on (ball 0 1) f"
  3257   have "continuous_on (ball 0 1) f"
  3258   proof (rule uniform_limit_theorem; (intro always_eventually allI)?)
  3258   proof (rule uniform_limit_theorem; (intro always_eventually allI)?)
  3259     show "uniform_limit (ball 0 1) (\<lambda>n x. \<Sum>k<n. P x k / of_nat (Suc k)^2) f sequentially"
  3259     show "uniform_limit (ball 0 1) (\<lambda>n x. \<Sum>k<n. P x k / of_nat (Suc k)^2) f sequentially"
  3260     proof (unfold f_def, rule weierstrass_m_test)
  3260     proof (unfold f_def, rule Weierstrass_m_test)
  3261       fix n :: nat and x :: real assume x: "x \<in> ball 0 1"
  3261       fix n :: nat and x :: real assume x: "x \<in> ball 0 1"
  3262       {
  3262       {
  3263         fix k :: nat assume k: "k \<ge> 1"
  3263         fix k :: nat assume k: "k \<ge> 1"
  3264         from x have "x^2 < 1" by (auto simp: dist_0_norm abs_square_less_1)
  3264         from x have "x^2 < 1" by (auto simp: dist_0_norm abs_square_less_1)
  3265         also from k have "\<dots> \<le> of_nat k^2" by simp
  3265         also from k have "\<dots> \<le> of_nat k^2" by simp