ellint_legendre.qbk 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. [/
  2. Copyright (c) 2006 Xiaogang Zhang
  3. Copyright (c) 2006 John Maddock
  4. Use, modification and distribution are subject to the
  5. Boost Software License, Version 1.0. (See accompanying file
  6. LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ]
  8. [section:ellint_1 Elliptic Integrals of the First Kind - Legendre Form]
  9. [heading Synopsis]
  10. ``
  11. #include <boost/math/special_functions/ellint_1.hpp>
  12. ``
  13. namespace boost { namespace math {
  14. template <class T1, class T2>
  15. ``__sf_result`` ellint_1(T1 k, T2 phi);
  16. template <class T1, class T2, class ``__Policy``>
  17. ``__sf_result`` ellint_1(T1 k, T2 phi, const ``__Policy``&);
  18. template <class T>
  19. ``__sf_result`` ellint_1(T k);
  20. template <class T, class ``__Policy``>
  21. ``__sf_result`` ellint_1(T k, const ``__Policy``&);
  22. }} // namespaces
  23. [heading Description]
  24. These two functions evaluate the incomplete elliptic integral of the first kind
  25. ['F([phi], k)] and its complete counterpart ['K(k) = F([pi]/2, k)].
  26. [graph ellint_1]
  27. The return type of these functions is computed using the __arg_promotion_rules
  28. when T1 and T2 are different types: when they are the same type then the result
  29. is the same type as the arguments.
  30. template <class T1, class T2>
  31. ``__sf_result`` ellint_1(T1 k, T2 phi);
  32. template <class T1, class T2, class ``__Policy``>
  33. ``__sf_result`` ellint_1(T1 k, T2 phi, const ``__Policy``&);
  34. Returns the incomplete elliptic integral of the first kind ['F([phi], k)]:
  35. [equation ellint2]
  36. Requires k[super 2]sin[super 2](phi) < 1, otherwise returns the result of __domain_error.
  37. [optional_policy]
  38. template <class T>
  39. ``__sf_result`` ellint_1(T k);
  40. template <class T>
  41. ``__sf_result`` ellint_1(T k, const ``__Policy``&);
  42. Returns the complete elliptic integral of the first kind ['K(k)]:
  43. [equation ellint6]
  44. Requires |k| < 1, otherwise returns the result of __domain_error.
  45. [optional_policy]
  46. [heading Accuracy]
  47. These functions are computed using only basic arithmetic operations, so
  48. there isn't much variation in accuracy over differing platforms.
  49. Note that only results for the widest floating point type on the
  50. system are given as narrower types have __zero_error. All values
  51. are relative errors in units of epsilon.
  52. [table_ellint_1]
  53. The following error plot are based on an exhaustive search of the functions domain, MSVC-15.5 at `double` precision,
  54. and GCC-7.1/Ubuntu for `long double` and `__float128`.
  55. [graph elliptic_integral_k__double]
  56. [graph elliptic_integral_k__80_bit_long_double]
  57. [graph elliptic_integral_k____float128]
  58. [heading Testing]
  59. The tests use a mixture of spot test values calculated using the online
  60. calculator at [@http://functions.wolfram.com/ functions.wolfram.com],
  61. and random test data generated using
  62. NTL::RR at 1000-bit precision and this implementation.
  63. [heading Implementation]
  64. These functions are implemented in terms of Carlson's integrals using the relations:
  65. [equation ellint19]
  66. and
  67. [equation ellint20]
  68. [endsect] [/section:ellint_1 Elliptic Integrals of the First Kind - Legendre Form]
  69. [section:ellint_2 Elliptic Integrals of the Second Kind - Legendre Form]
  70. [heading Synopsis]
  71. ``
  72. #include <boost/math/special_functions/ellint_2.hpp>
  73. ``
  74. namespace boost { namespace math {
  75. template <class T1, class T2>
  76. ``__sf_result`` ellint_2(T1 k, T2 phi);
  77. template <class T1, class T2, class ``__Policy``>
  78. ``__sf_result`` ellint_2(T1 k, T2 phi, const ``__Policy``&);
  79. template <class T>
  80. ``__sf_result`` ellint_2(T k);
  81. template <class T, class ``__Policy``>
  82. ``__sf_result`` ellint_2(T k, const ``__Policy``&);
  83. }} // namespaces
  84. [heading Description]
  85. These two functions evaluate the incomplete elliptic integral of the second kind
  86. ['E([phi], k)] and its complete counterpart ['E(k) = E([pi]/2, k)].
  87. [graph ellint_2]
  88. The return type of these functions is computed using the __arg_promotion_rules
  89. when T1 and T2 are different types: when they are the same type then the result
  90. is the same type as the arguments.
  91. template <class T1, class T2>
  92. ``__sf_result`` ellint_2(T1 k, T2 phi);
  93. template <class T1, class T2, class ``__Policy``>
  94. ``__sf_result`` ellint_2(T1 k, T2 phi, const ``__Policy``&);
  95. Returns the incomplete elliptic integral of the second kind ['E([phi], k)]:
  96. [equation ellint3]
  97. Requires k[super 2]sin[super 2](phi) < 1, otherwise returns the result of __domain_error.
  98. [optional_policy]
  99. template <class T>
  100. ``__sf_result`` ellint_2(T k);
  101. template <class T>
  102. ``__sf_result`` ellint_2(T k, const ``__Policy``&);
  103. Returns the complete elliptic integral of the second kind ['E(k)]:
  104. [equation ellint7]
  105. Requires |k| < 1, otherwise returns the result of __domain_error.
  106. [optional_policy]
  107. [heading Accuracy]
  108. These functions are computed using only basic arithmetic operations, so
  109. there isn't much variation in accuracy over differing platforms.
  110. Note that only results for the widest floating point type on the
  111. system are given as narrower types have __zero_error. All values
  112. are relative errors in units of epsilon.
  113. [table_ellint_2]
  114. The following error plot are based on an exhaustive search of the functions domain, MSVC-15.5 at `double` precision,
  115. and GCC-7.1/Ubuntu for `long double` and `__float128`.
  116. [graph elliptic_integral_e__double]
  117. [graph elliptic_integral_e__80_bit_long_double]
  118. [graph elliptic_integral_e____float128]
  119. [heading Testing]
  120. The tests use a mixture of spot test values calculated using the online
  121. calculator at [@http://functions.wolfram.com
  122. functions.wolfram.com], and random test data generated using
  123. NTL::RR at 1000-bit precision and this implementation.
  124. [heading Implementation]
  125. These functions are implemented in terms of Carlson's integrals
  126. using the relations:
  127. [equation ellint21]
  128. and
  129. [equation ellint22]
  130. [endsect] [/section:ellint_2 Elliptic Integrals of the Second Kind - Legendre Form]
  131. [section:ellint_3 Elliptic Integrals of the Third Kind - Legendre Form]
  132. [heading Synopsis]
  133. ``
  134. #include <boost/math/special_functions/ellint_3.hpp>
  135. ``
  136. namespace boost { namespace math {
  137. template <class T1, class T2, class T3>
  138. ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi);
  139. template <class T1, class T2, class T3, class ``__Policy``>
  140. ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi, const ``__Policy``&);
  141. template <class T1, class T2>
  142. ``__sf_result`` ellint_3(T1 k, T2 n);
  143. template <class T1, class T2, class ``__Policy``>
  144. ``__sf_result`` ellint_3(T1 k, T2 n, const ``__Policy``&);
  145. }} // namespaces
  146. [heading Description]
  147. These two functions evaluate the incomplete elliptic integral of the third kind
  148. ['[Pi](n, [phi], k)] and its complete counterpart ['[Pi](n, k) = E(n, [pi]/2, k)].
  149. [graph ellint_3]
  150. The return type of these functions is computed using the __arg_promotion_rules
  151. when the arguments are of different types: when they are the same type then the result
  152. is the same type as the arguments.
  153. template <class T1, class T2, class T3>
  154. ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi);
  155. template <class T1, class T2, class T3, class ``__Policy``>
  156. ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi, const ``__Policy``&);
  157. Returns the incomplete elliptic integral of the third kind ['[Pi](n, [phi], k)]:
  158. [equation ellint4]
  159. Requires ['k[super 2]sin[super 2](phi) < 1] and ['n < 1/sin[super 2]([phi])], otherwise
  160. returns the result of __domain_error (outside this range the result
  161. would be complex).
  162. [optional_policy]
  163. template <class T1, class T2>
  164. ``__sf_result`` ellint_3(T1 k, T2 n);
  165. template <class T1, class T2, class ``__Policy``>
  166. ``__sf_result`` ellint_3(T1 k, T2 n, const ``__Policy``&);
  167. Returns the complete elliptic integral of the first kind ['[Pi](n, k)]:
  168. [equation ellint8]
  169. Requires ['|k| < 1] and ['n < 1], otherwise returns the
  170. result of __domain_error (outside this range the result would be complex).
  171. [optional_policy]
  172. [heading Accuracy]
  173. These functions are computed using only basic arithmetic operations, so
  174. there isn't much variation in accuracy over differing platforms.
  175. Note that only results for the widest floating point type on the
  176. system are given as narrower types have __zero_error. All values
  177. are relative errors in units of epsilon.
  178. [table_ellint_3]
  179. [heading Testing]
  180. The tests use a mixture of spot test values calculated using the online
  181. calculator at [@http://functions.wolfram.com
  182. functions.wolfram.com], and random test data generated using
  183. NTL::RR at 1000-bit precision and this implementation.
  184. [heading Implementation]
  185. The implementation for [Pi](n, [phi], k) first siphons off the special cases:
  186. [expression ['[Pi](0, [phi], k) = F([phi], k)]]
  187. [expression ['[Pi](n, [pi]/2, k) = [Pi](n, k)]]
  188. and
  189. [equation ellint23]
  190. Then if n < 0 the relations (A&S 17.7.15/16):
  191. [equation ellint24]
  192. are used to shift /n/ to the range \[0, 1\].
  193. Then the relations:
  194. [expression ['[Pi](n, -[phi], k) = -[Pi](n, [phi], k)]]
  195. [expression ['[Pi](n, [phi]+m[pi], k) = [Pi](n, [phi], k) + 2m[Pi](n, k) ; n <= 1]]
  196. [expression ['[Pi](n, [phi]+m[pi], k) = [Pi](n, [phi], k) ; n > 1] [indent] [indent]
  197. [footnote I haven't been able to find a literature reference for this
  198. relation, but it appears to be the convention used by Mathematica.
  199. Intuitively the first ['2 * m * [Pi](n, k)] terms cancel out as the
  200. derivative alternates between +[infin] and -[infin].]]
  201. are used to move [phi] to the range \[0, [pi]\/2\].
  202. The functions are then implemented in terms of Carlson's integrals using the relations:
  203. [equation ellint25]
  204. and
  205. [equation ellint26]
  206. [endsect] [/section:ellint_3 Elliptic Integrals of the Third Kind - Legendre Form]
  207. [section:ellint_d Elliptic Integral D - Legendre Form]
  208. [heading Synopsis]
  209. ``
  210. #include <boost/math/special_functions/ellint_d.hpp>
  211. ``
  212. namespace boost { namespace math {
  213. template <class T1, class T2>
  214. ``__sf_result`` ellint_d(T1 k, T2 phi);
  215. template <class T1, class T2, class ``__Policy``>
  216. ``__sf_result`` ellint_d(T1 k, T2 phi, const ``__Policy``&);
  217. template <class T1>
  218. ``__sf_result`` ellint_d(T1 k);
  219. template <class T1, class ``__Policy``>
  220. ``__sf_result`` ellint_d(T1 k, const ``__Policy``&);
  221. }} // namespaces
  222. [heading Description]
  223. These two functions evaluate the incomplete elliptic integral
  224. ['D([phi], k)] and its complete counterpart ['D(k) = D([pi]/2, k)].
  225. The return type of these functions is computed using the __arg_promotion_rules
  226. when the arguments are of different types: when they are the same type then the result
  227. is the same type as the arguments.
  228. template <class T1, class T2>
  229. ``__sf_result`` ellint_d(T1 k, T2 phi);
  230. template <class T1, class T2, class ``__Policy``>
  231. ``__sf_result`` ellint_3(T1 k, T2 phi, const ``__Policy``&);
  232. Returns the incomplete elliptic integral:
  233. [equation ellint_d]
  234. Requires ['k[super 2]sin[super 2](phi) < 1], otherwise
  235. returns the result of __domain_error (outside this range the result
  236. would be complex).
  237. [optional_policy]
  238. template <class T1>
  239. ``__sf_result`` ellint_d(T1 k);
  240. template <class T1, class ``__Policy``>
  241. ``__sf_result`` ellint_d(T1 k, const ``__Policy``&);
  242. Returns the complete elliptic integral ['D(k) = D([pi]/2, k)]
  243. Requires ['-1 <= k <= 1] otherwise returns the
  244. result of __domain_error (outside this range the result would be complex).
  245. [optional_policy]
  246. [heading Accuracy]
  247. These functions are trivially computed in terms of other elliptic integrals
  248. and generally have very low error rates (a few epsilon) unless parameter [phi]
  249. is very large, in which case the usual trigonometric function argument-reduction issues apply.
  250. [table_ellint_d_complete_]
  251. [table_ellint_d]
  252. The following error plot are based on an exhaustive search of the functions domain, MSVC-15.5 at `double` precision,
  253. and GCC-7.1/Ubuntu for `long double` and `__float128`.
  254. [graph elliptic_integral_d__double]
  255. [graph elliptic_integral_d__80_bit_long_double]
  256. [graph elliptic_integral_d____float128]
  257. [heading Testing]
  258. The tests use a mixture of spot test values calculated using
  259. values calculated at __WolframAlpha, and random test data generated using
  260. MPFR at 1000-bit precision and a deliberately naive implementation in terms of
  261. the Legendre integrals.
  262. [heading Implementation]
  263. The implementation for D([phi], k) first performs argument reduction using the relations:
  264. [expression ['D(-[phi], k) = -D([phi], k)]]
  265. and
  266. [expression ['D(n[pi]+[phi], k) = 2nD(k) + D([phi], k)]]
  267. to move [phi] to the range \[0, [pi]\/2\].
  268. The functions are then implemented in terms of Carlson's integral R[sub D]
  269. using the relation:
  270. [equation ellint_d]
  271. [endsect] [/section:ellint_d Elliptic Integral D - Legendre Form]
  272. [section:jacobi_zeta Jacobi Zeta Function]
  273. [heading Synopsis]
  274. ``
  275. #include <boost/math/special_functions/jacobi_zeta.hpp>
  276. ``
  277. namespace boost { namespace math {
  278. template <class T1, class T2>
  279. ``__sf_result`` jacobi_zeta(T1 k, T2 phi);
  280. template <class T1, class T2, class ``__Policy``>
  281. ``__sf_result`` jacobi_zeta(T1 k, T2 phi, const ``__Policy``&);
  282. }} // namespaces
  283. [heading Description]
  284. This function evaluates the Jacobi Zeta Function ['Z([phi], k)]
  285. [equation jacobi_zeta]
  286. Please note the use of [phi], and /k/ as the parameters, the function is often defined as ['Z([phi], m)]
  287. with ['m = k[super 2]], see for example [@http://mathworld.wolfram.com/JacobiZetaFunction.html Weisstein, Eric W. "Jacobi Zeta Function." From MathWorld--A Wolfram Web Resource.]
  288. Or else as [@https://dlmf.nist.gov/22.16#E32 ['Z(x, k)]] with ['[phi] = am(x, k)],
  289. where ['am] is the [@https://dlmf.nist.gov/22.16#E1 Jacobi amplitude function]
  290. which is equivalent to ['asin(jacobi_elliptic(k, x))].
  291. The return type of this function is computed using the __arg_promotion_rules
  292. when the arguments are of different types: when they are the same type then the result
  293. is the same type as the arguments.
  294. Requires ['-1 <= k <= 1], otherwise
  295. returns the result of __domain_error (outside this range the result would be complex).
  296. [optional_policy]
  297. Note that there is no complete analogue of this function (where [phi] = [pi] / 2)
  298. as this takes the value 0 for all ['k].
  299. [heading Accuracy]
  300. These functions are trivially computed in terms of other elliptic integrals
  301. and generally have very low error rates (a few epsilon) unless parameter [phi]
  302. is very large, in which case the usual trigonometric function argument-reduction issues apply.
  303. [table_jacobi_zeta]
  304. [heading Testing]
  305. The tests use a mixture of spot test values calculated using
  306. values calculated at __WolframAlpha, and random test data generated using
  307. MPFR at 1000-bit precision and a deliberately naive implementation in terms of
  308. the Legendre integrals.
  309. [heading Implementation]
  310. The implementation for Z([phi], k) first makes the argument [phi] positive using:
  311. [expression ['Z(-[phi], k) = -Z([phi], k)]]
  312. The function is then implemented in terms of Carlson's integral R[sub J]
  313. using the relation:
  314. [equation jacobi_zeta]
  315. There is one special case where the above relation fails: when ['k = 1], in that case
  316. the function simplifies to
  317. [expression ['Z([phi], 1) = sign(cos([phi])) sin([phi])]]
  318. [h5:jacobi_zeta_example Example]
  319. A simple example comparing use of __WolframAlpha with Boost.Math (including much higher precision using Boost.Multiprecision)
  320. is [@../../example/jacobi_zeta_example.cpp jacobi_zeta_example.cpp].
  321. [endsect] [/section:jacobi_zeta Jacobi Zeta Function]
  322. [section:heuman_lambda Heuman Lambda Function]
  323. [heading Synopsis]
  324. ``
  325. #include <boost/math/special_functions/heuman_lambda.hpp>
  326. ``
  327. namespace boost { namespace math {
  328. template <class T1, class T2>
  329. ``__sf_result`` heuman_lambda(T1 k, T2 phi);
  330. template <class T1, class T2, class ``__Policy``>
  331. ``__sf_result`` heuman_lambda(T1 k, T2 phi, const ``__Policy``&);
  332. }} // namespaces
  333. [heading Description]
  334. This function evaluates the Heuman Lambda Function ['[Lambda][sub 0]([phi], k)]
  335. [equation heuman_lambda]
  336. The return type of this function is computed using the __arg_promotion_rules
  337. when the arguments are of different types: when they are the same type then the result
  338. is the same type as the arguments.
  339. Requires ['-1 <= k <= 1], otherwise
  340. returns the result of __domain_error (outside this range the result would be complex).
  341. [optional_policy]
  342. Note that there is no complete analogue of this function (where [phi] = [pi] / 2)
  343. as this takes the value 1 for all ['k].
  344. [heading Accuracy]
  345. These functions are trivially computed in terms of other elliptic integrals
  346. and generally have very low error rates (a few epsilon) unless parameter [phi]
  347. is very large, in which case the usual trigonometric function argument-reduction issues apply.
  348. [table_heuman_lambda]
  349. [heading Testing]
  350. The tests use a mixture of spot test values calculated using
  351. values calculated at __WolframAlpha, and random test data generated using
  352. MPFR at 1000-bit precision and a deliberately naive implementation in terms of
  353. the Legendre integrals.
  354. [heading Implementation]
  355. The function is then implemented in terms of Carlson's integrals R[sub J] and R[sub F]
  356. using the relation:
  357. [equation heuman_lambda]
  358. This relation fails for ['|[phi]| >= [pi]/2] in which case the definition in terms of the
  359. Jacobi Zeta is used.
  360. [endsect] [/section:heuman_lambda Heuman Lambda Function]