src/HOL/Analysis/Gamma_Function.thy
changeset 70136 f03a01a18c6e
parent 70113 c8deb8ba6d05
child 70196 b7ef9090feed
equal deleted inserted replaced
70135:ad6d4a14adb5 70136:f03a01a18c6e
   243   that it is a relatively simple limit that converges everywhere. The limit at the poles is 0
   243   that it is a relatively simple limit that converges everywhere. The limit at the poles is 0
   244   (due to division by 0). The functional equation \<open>Gamma (z + 1) = z * Gamma z\<close> follows
   244   (due to division by 0). The functional equation \<open>Gamma (z + 1) = z * Gamma z\<close> follows
   245   immediately from the definition.
   245   immediately from the definition.
   246 \<close>
   246 \<close>
   247 
   247 
   248 definition%important Gamma_series :: "('a :: {banach,real_normed_field}) \<Rightarrow> nat \<Rightarrow> 'a" where
   248 definition\<^marker>\<open>tag important\<close> Gamma_series :: "('a :: {banach,real_normed_field}) \<Rightarrow> nat \<Rightarrow> 'a" where
   249   "Gamma_series z n = fact n * exp (z * of_real (ln (of_nat n))) / pochhammer z (n+1)"
   249   "Gamma_series z n = fact n * exp (z * of_real (ln (of_nat n))) / pochhammer z (n+1)"
   250 
   250 
   251 definition Gamma_series' :: "('a :: {banach,real_normed_field}) \<Rightarrow> nat \<Rightarrow> 'a" where
   251 definition Gamma_series' :: "('a :: {banach,real_normed_field}) \<Rightarrow> nat \<Rightarrow> 'a" where
   252   "Gamma_series' z n = fact (n - 1) * exp (z * of_real (ln (of_nat n))) / pochhammer z n"
   252   "Gamma_series' z n = fact (n - 1) * exp (z * of_real (ln (of_nat n))) / pochhammer z n"
   253 
   253 
   315 
   315 
   316   This will later allow us to lift holomorphicity and continuity from the log-Gamma
   316   This will later allow us to lift holomorphicity and continuity from the log-Gamma
   317   function to the inverse of the Gamma function, and from that to the Gamma function itself.
   317   function to the inverse of the Gamma function, and from that to the Gamma function itself.
   318 \<close>
   318 \<close>
   319 
   319 
   320 definition%important ln_Gamma_series :: "('a :: {banach,real_normed_field,ln}) \<Rightarrow> nat \<Rightarrow> 'a" where
   320 definition\<^marker>\<open>tag important\<close> ln_Gamma_series :: "('a :: {banach,real_normed_field,ln}) \<Rightarrow> nat \<Rightarrow> 'a" where
   321   "ln_Gamma_series z n = z * ln (of_nat n) - ln z - (\<Sum>k=1..n. ln (z / of_nat k + 1))"
   321   "ln_Gamma_series z n = z * ln (of_nat n) - ln z - (\<Sum>k=1..n. ln (z / of_nat k + 1))"
   322 
   322 
   323 definition%unimportant ln_Gamma_series' :: "('a :: {banach,real_normed_field,ln}) \<Rightarrow> nat \<Rightarrow> 'a" where
   323 definition\<^marker>\<open>tag unimportant\<close> ln_Gamma_series' :: "('a :: {banach,real_normed_field,ln}) \<Rightarrow> nat \<Rightarrow> 'a" where
   324   "ln_Gamma_series' z n =
   324   "ln_Gamma_series' z n =
   325      - euler_mascheroni*z - ln z + (\<Sum>k=1..n. z / of_nat n - ln (z / of_nat k + 1))"
   325      - euler_mascheroni*z - ln z + (\<Sum>k=1..n. z / of_nat n - ln (z / of_nat k + 1))"
   326 
   326 
   327 definition ln_Gamma :: "('a :: {banach,real_normed_field,ln}) \<Rightarrow> 'a" where
   327 definition ln_Gamma :: "('a :: {banach,real_normed_field,ln}) \<Rightarrow> 'a" where
   328   "ln_Gamma z = lim (ln_Gamma_series z)"
   328   "ln_Gamma z = lim (ln_Gamma_series z)"
   612      summable (\<lambda>n. inverse (of_nat (Suc n)) - inverse (z + of_nat (Suc n)))"
   612      summable (\<lambda>n. inverse (of_nat (Suc n)) - inverse (z + of_nat (Suc n)))"
   613   unfolding summable_iff_convergent
   613   unfolding summable_iff_convergent
   614   by (rule uniformly_convergent_imp_convergent,
   614   by (rule uniformly_convergent_imp_convergent,
   615       rule uniformly_summable_deriv_ln_Gamma[of z "norm z/2"]) simp_all
   615       rule uniformly_summable_deriv_ln_Gamma[of z "norm z/2"]) simp_all
   616 
   616 
   617 definition%important Polygamma :: "nat \<Rightarrow> ('a :: {real_normed_field,banach}) \<Rightarrow> 'a" where
   617 definition\<^marker>\<open>tag important\<close> Polygamma :: "nat \<Rightarrow> ('a :: {real_normed_field,banach}) \<Rightarrow> 'a" where
   618   "Polygamma n z = (if n = 0 then
   618   "Polygamma n z = (if n = 0 then
   619       (\<Sum>k. inverse (of_nat (Suc k)) - inverse (z + of_nat k)) - euler_mascheroni else
   619       (\<Sum>k. inverse (of_nat (Suc k)) - inverse (z + of_nat k)) - euler_mascheroni else
   620       (-1)^Suc n * fact n * (\<Sum>k. inverse ((z + of_nat k)^Suc n)))"
   620       (-1)^Suc n * fact n * (\<Sum>k. inverse ((z + of_nat k)^Suc n)))"
   621 
   621 
   622 abbreviation%important Digamma :: "('a :: {real_normed_field,banach}) \<Rightarrow> 'a" where
   622 abbreviation\<^marker>\<open>tag important\<close> Digamma :: "('a :: {real_normed_field,banach}) \<Rightarrow> 'a" where
   623   "Digamma \<equiv> Polygamma 0"
   623   "Digamma \<equiv> Polygamma 0"
   624 
   624 
   625 lemma Digamma_def:
   625 lemma Digamma_def:
   626   "Digamma z = (\<Sum>k. inverse (of_nat (Suc k)) - inverse (z + of_nat k)) - euler_mascheroni"
   626   "Digamma z = (\<Sum>k. inverse (of_nat (Suc k)) - inverse (z + of_nat k)) - euler_mascheroni"
   627   by (simp add: Polygamma_def)
   627   by (simp add: Polygamma_def)
  1019   We define a type class that captures all the fundamental properties of the inverse of the Gamma function
  1019   We define a type class that captures all the fundamental properties of the inverse of the Gamma function
  1020   and defines the Gamma function upon that. This allows us to instantiate the type class both for
  1020   and defines the Gamma function upon that. This allows us to instantiate the type class both for
  1021   the reals and for the complex numbers with a minimal amount of proof duplication.
  1021   the reals and for the complex numbers with a minimal amount of proof duplication.
  1022 \<close>
  1022 \<close>
  1023 
  1023 
  1024 class%unimportant Gamma = real_normed_field + complete_space +
  1024 class\<^marker>\<open>tag unimportant\<close> Gamma = real_normed_field + complete_space +
  1025   fixes rGamma :: "'a \<Rightarrow> 'a"
  1025   fixes rGamma :: "'a \<Rightarrow> 'a"
  1026   assumes rGamma_eq_zero_iff_aux: "rGamma z = 0 \<longleftrightarrow> (\<exists>n. z = - of_nat n)"
  1026   assumes rGamma_eq_zero_iff_aux: "rGamma z = 0 \<longleftrightarrow> (\<exists>n. z = - of_nat n)"
  1027   assumes differentiable_rGamma_aux1:
  1027   assumes differentiable_rGamma_aux1:
  1028     "(\<And>n. z \<noteq> - of_nat n) \<Longrightarrow>
  1028     "(\<And>n. z \<noteq> - of_nat n) \<Longrightarrow>
  1029      let d = (THE d. (\<lambda>n. \<Sum>k<n. inverse (of_nat (Suc k)) - inverse (z + of_nat k))
  1029      let d = (THE d. (\<lambda>n. \<Sum>k<n. inverse (of_nat (Suc k)) - inverse (z + of_nat k))
  1257 
  1257 
  1258 lemma isCont_Gamma [continuous_intros]:
  1258 lemma isCont_Gamma [continuous_intros]:
  1259   "isCont f z \<Longrightarrow> f z \<notin> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> isCont (\<lambda>x. Gamma (f x)) z"
  1259   "isCont f z \<Longrightarrow> f z \<notin> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> isCont (\<lambda>x. Gamma (f x)) z"
  1260   by (rule isCont_o2[OF _  DERIV_isCont[OF has_field_derivative_Gamma]])
  1260   by (rule isCont_o2[OF _  DERIV_isCont[OF has_field_derivative_Gamma]])
  1261 
  1261 
  1262 subsection%unimportant \<open>The complex Gamma function\<close>
  1262 subsection\<^marker>\<open>tag unimportant\<close> \<open>The complex Gamma function\<close>
  1263 
  1263 
  1264 instantiation%unimportant complex :: Gamma
  1264 instantiation\<^marker>\<open>tag unimportant\<close> complex :: Gamma
  1265 begin
  1265 begin
  1266 
  1266 
  1267 definition%unimportant rGamma_complex :: "complex \<Rightarrow> complex" where
  1267 definition\<^marker>\<open>tag unimportant\<close> rGamma_complex :: "complex \<Rightarrow> complex" where
  1268   "rGamma_complex z = lim (rGamma_series z)"
  1268   "rGamma_complex z = lim (rGamma_series z)"
  1269 
  1269 
  1270 lemma rGamma_series_complex_converges:
  1270 lemma rGamma_series_complex_converges:
  1271         "convergent (rGamma_series (z :: complex))" (is "?thesis1")
  1271         "convergent (rGamma_series (z :: complex))" (is "?thesis1")
  1272   and rGamma_complex_altdef:
  1272   and rGamma_complex_altdef:
  1297       by (auto simp: rGamma_complex_def convergent_def intro!: limI)
  1297       by (auto simp: rGamma_complex_def convergent_def intro!: limI)
  1298   qed
  1298   qed
  1299   thus "?thesis1" "?thesis2" by blast+
  1299   thus "?thesis1" "?thesis2" by blast+
  1300 qed
  1300 qed
  1301 
  1301 
  1302 context%unimportant
  1302 context\<^marker>\<open>tag unimportant\<close>
  1303 begin
  1303 begin
  1304 
  1304 
  1305 (* TODO: duplication *)
  1305 (* TODO: duplication *)
  1306 private lemma rGamma_complex_plus1: "z * rGamma (z + 1) = rGamma (z :: complex)"
  1306 private lemma rGamma_complex_plus1: "z * rGamma (z + 1) = rGamma (z :: complex)"
  1307 proof -
  1307 proof -
  1524   by (rule analytic_on_subset[of _ "UNIV - \<int>\<^sub>\<le>\<^sub>0"], subst analytic_on_open)
  1524   by (rule analytic_on_subset[of _ "UNIV - \<int>\<^sub>\<le>\<^sub>0"], subst analytic_on_open)
  1525      (auto intro!: holomorphic_on_Polygamma)
  1525      (auto intro!: holomorphic_on_Polygamma)
  1526 
  1526 
  1527 
  1527 
  1528 
  1528 
  1529 subsection%unimportant \<open>The real Gamma function\<close>
  1529 subsection\<^marker>\<open>tag unimportant\<close> \<open>The real Gamma function\<close>
  1530 
  1530 
  1531 lemma rGamma_series_real:
  1531 lemma rGamma_series_real:
  1532   "eventually (\<lambda>n. rGamma_series x n = Re (rGamma_series (of_real x) n)) sequentially"
  1532   "eventually (\<lambda>n. rGamma_series x n = Re (rGamma_series (of_real x) n)) sequentially"
  1533   using eventually_gt_at_top[of "0 :: nat"]
  1533   using eventually_gt_at_top[of "0 :: nat"]
  1534 proof eventually_elim
  1534 proof eventually_elim
  1542   also from n have "\<dots> = rGamma_series x n"
  1542   also from n have "\<dots> = rGamma_series x n"
  1543     by (subst Re_complex_of_real) (simp add: rGamma_series_def powr_def)
  1543     by (subst Re_complex_of_real) (simp add: rGamma_series_def powr_def)
  1544   finally show "rGamma_series x n = Re (rGamma_series (of_real x) n)" ..
  1544   finally show "rGamma_series x n = Re (rGamma_series (of_real x) n)" ..
  1545 qed
  1545 qed
  1546 
  1546 
  1547 instantiation%unimportant real :: Gamma
  1547 instantiation\<^marker>\<open>tag unimportant\<close> real :: Gamma
  1548 begin
  1548 begin
  1549 
  1549 
  1550 definition "rGamma_real x = Re (rGamma (of_real x :: complex))"
  1550 definition "rGamma_real x = Re (rGamma (of_real x :: complex))"
  1551 
  1551 
  1552 instance proof
  1552 instance proof
  1805   In principle, if \<open>G\<close> is a holomorphic complex function, one could then extend
  1805   In principle, if \<open>G\<close> is a holomorphic complex function, one could then extend
  1806   this from the positive reals to the entire complex plane (minus the non-positive
  1806   this from the positive reals to the entire complex plane (minus the non-positive
  1807   integers, where the Gamma function is not defined).
  1807   integers, where the Gamma function is not defined).
  1808 \<close>
  1808 \<close>
  1809 
  1809 
  1810 context%unimportant
  1810 context\<^marker>\<open>tag unimportant\<close>
  1811   fixes G :: "real \<Rightarrow> real"
  1811   fixes G :: "real \<Rightarrow> real"
  1812   assumes G_1: "G 1 = 1"
  1812   assumes G_1: "G 1 = 1"
  1813   assumes G_plus1: "x > 0 \<Longrightarrow> G (x + 1) = x * G x"
  1813   assumes G_plus1: "x > 0 \<Longrightarrow> G (x + 1) = x * G x"
  1814   assumes G_pos: "x > 0 \<Longrightarrow> G x > 0"
  1814   assumes G_pos: "x > 0 \<Longrightarrow> G x > 0"
  1815   assumes log_convex_G: "convex_on {0<..} (ln \<circ> G)"
  1815   assumes log_convex_G: "convex_on {0<..} (ln \<circ> G)"
  2387   using Gamma_legendre_duplication_aux[OF assms] by (simp add: Gamma_one_half_complex)
  2387   using Gamma_legendre_duplication_aux[OF assms] by (simp add: Gamma_one_half_complex)
  2388 
  2388 
  2389 end
  2389 end
  2390 
  2390 
  2391 
  2391 
  2392 subsection%unimportant \<open>Limits and residues\<close>
  2392 subsection\<^marker>\<open>tag unimportant\<close> \<open>Limits and residues\<close>
  2393 
  2393 
  2394 text \<open>
  2394 text \<open>
  2395   The inverse of the Gamma function has simple zeros:
  2395   The inverse of the Gamma function has simple zeros:
  2396 \<close>
  2396 \<close>
  2397 
  2397 
  2535 
  2535 
  2536 definition Gamma_series_Weierstrass :: "'a :: {banach,real_normed_field} \<Rightarrow> nat \<Rightarrow> 'a" where
  2536 definition Gamma_series_Weierstrass :: "'a :: {banach,real_normed_field} \<Rightarrow> nat \<Rightarrow> 'a" where
  2537   "Gamma_series_Weierstrass z n =
  2537   "Gamma_series_Weierstrass z n =
  2538      exp (-euler_mascheroni * z) / z * (\<Prod>k=1..n. exp (z / of_nat k) / (1 + z / of_nat k))"
  2538      exp (-euler_mascheroni * z) / z * (\<Prod>k=1..n. exp (z / of_nat k) / (1 + z / of_nat k))"
  2539 
  2539 
  2540 definition%unimportant
  2540 definition\<^marker>\<open>tag unimportant\<close>
  2541   rGamma_series_Weierstrass :: "'a :: {banach,real_normed_field} \<Rightarrow> nat \<Rightarrow> 'a" where
  2541   rGamma_series_Weierstrass :: "'a :: {banach,real_normed_field} \<Rightarrow> nat \<Rightarrow> 'a" where
  2542   "rGamma_series_Weierstrass z n =
  2542   "rGamma_series_Weierstrass z n =
  2543      exp (euler_mascheroni * z) * z * (\<Prod>k=1..n. (1 + z / of_nat k) * exp (-z / of_nat k))"
  2543      exp (euler_mascheroni * z) * z * (\<Prod>k=1..n. (1 + z / of_nat k) * exp (-z / of_nat k))"
  2544 
  2544 
  2545 lemma Gamma_series_Weierstrass_nonpos_Ints:
  2545 lemma Gamma_series_Weierstrass_nonpos_Ints: