3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Hypergeometric 1F1</title>
5 <link rel="stylesheet" href="../../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Math Toolkit 2.11.0">
8 <link rel="up" href="../hypergeometric.html" title="Hypergeometric Functions">
9 <link rel="prev" href="hypergeometric_2f0.html" title="Hypergeometric 2F0">
10 <link rel="next" href="hypergeometric_pfq.html" title="Hypergeometric pFq">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="hypergeometric_2f0.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hypergeometric.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="hypergeometric_pfq.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="math_toolkit.hypergeometric.hypergeometric_1f1"></a><a class="link" href="hypergeometric_1f1.html" title="Hypergeometric 1F1">Hypergeometric
28 <sub>1</sub><span class="emphasis"><em>F</em></span><sub>1</sub></a>
29 </h3></div></div></div>
30 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">hypergeometric_1F1</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
32 <span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span> <span class="special">{</span>
34 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">></span>
35 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">hypergeometric_1F1</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">z</span><span class="special">);</span>
37 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
38 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">hypergeometric_1F1</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
40 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">></span>
41 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">hypergeometric_1F1_regularized</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">z</span><span class="special">);</span>
43 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
44 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">hypergeometric_1F1_regularized</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
46 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">></span>
47 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">log_hypergeometric_1F1</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">z</span><span class="special">);</span>
49 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
50 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">log_hypergeometric_1F1</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
52 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">></span>
53 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">log_hypergeometric_1F1</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">int</span><span class="special">*</span> <span class="identifier">sign</span><span class="special">);</span>
55 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
56 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">log_hypergeometric_1F1</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">int</span><span class="special">*</span> <span class="identifier">sign</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
58 <span class="special">}}</span> <span class="comment">// namespaces</span>
61 <a name="math_toolkit.hypergeometric.hypergeometric_1f1.h0"></a>
62 <span class="phrase"><a name="math_toolkit.hypergeometric.hypergeometric_1f1.description"></a></span><a class="link" href="hypergeometric_1f1.html#math_toolkit.hypergeometric.hypergeometric_1f1.description">Description</a>
67 <script type="text/javascript" src="../../../graphs/hypergeometric_1f1/plotlyjs-bundle.js"></script>
72 The function <code class="computeroutput"><span class="identifier">hypergeometric_1F1</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span>
73 <span class="identifier">b</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)</span></code> returns
74 the non-singular solution to <a href="https://en.wikipedia.org/wiki/Confluent_hypergeometric_function" target="_top">Kummer's
77 <div class="blockquote"><blockquote class="blockquote"><p>
78 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_2.svg" width="181" height="34"></object></span>
79 </p></blockquote></div>
81 which for |<span class="emphasis"><em>z</em></span>| < 1 has the hypergeometric series expansion
83 <div class="blockquote"><blockquote class="blockquote"><p>
84 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_1.svg" width="234" height="38"></object></span>
85 </p></blockquote></div>
87 where (<span class="emphasis"><em>a</em></span>)<sub><span class="emphasis"><em>n</em></span></sub> denotes rising factorial.
88 This function has the same definition as Mathematica's <code class="computeroutput"><span class="identifier">Hypergeometric1F1</span><span class="special">[</span><span class="identifier">a</span><span class="special">,</span>
89 <span class="identifier">b</span><span class="special">,</span> <span class="identifier">z</span><span class="special">]</span></code> and
90 Maple's <code class="computeroutput"><span class="identifier">KummerM</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)</span></code>.
93 The "regularized" versions of the function return:
95 <div class="blockquote"><blockquote class="blockquote"><p>
96 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_17.svg" width="313" height="44"></object></span>
97 </p></blockquote></div>
99 The "log" versions of the function return:
101 <div class="blockquote"><blockquote class="blockquote"><p>
102 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_18.svg" width="119" height="20"></object></span>
103 </p></blockquote></div>
105 When the optional <code class="computeroutput"><span class="identifier">sign</span></code> argument
106 is supplied it is set on exit to either +1 or -1 depending on the sign of
107 <sub>1</sub><span class="emphasis"><em>F</em></span><sub>1</sub>(<span class="emphasis"><em>a</em></span>, <span class="emphasis"><em>b</em></span>,
108 <span class="emphasis"><em>z</em></span>).
111 Both the regularized and the logarithmic versions of these functions return
112 results without the spurious under/overflow that plague naive implementations.
115 <a name="math_toolkit.hypergeometric.hypergeometric_1f1.h1"></a>
116 <span class="phrase"><a name="math_toolkit.hypergeometric.hypergeometric_1f1.known_issues"></a></span><a class="link" href="hypergeometric_1f1.html#math_toolkit.hypergeometric.hypergeometric_1f1.known_issues">Known
120 This function is still very much the subject of active research, and a full
121 range of methods capable of calculating the function over its entire domain
122 are not yet available. We have worked extremely hard to ensure that problem
123 domains result in an exception being thrown (an <a class="link" href="../error_handling.html#math_toolkit.error_handling.evaluation_error">evaluation_error</a>)
124 rather than return a garbage result. Domains that are still unsolved include:
126 <div class="informaltable"><table class="table">
153 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_13.svg" width="101" height="16"></object></span>
158 <span class="emphasis"><em>a, b</em></span> and <span class="emphasis"><em>z</em></span> all large.
163 <sub>1</sub>F<sub>1</sub>(-814723.75, -13586.87890625, -15.87335205078125)
170 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_14.svg" width="89" height="16"></object></span>
175 <span class="emphasis"><em>a < b</em></span>, <span class="emphasis"><em>b > z</em></span>, this
176 is really the same domain as above.
185 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_15.svg" width="78" height="16"></object></span>
190 There is a gap in between methods where no reliable implementation
191 is possible, the issue becomes much worse for <span class="emphasis"><em>a</em></span>,
192 <span class="emphasis"><em>b</em></span> and <span class="emphasis"><em>z</em></span> all large.
197 <sub>1</sub>F<sub>1</sub>(9057.91796875, -1252.51318359375, 15.87335205078125)
204 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_16.svg" width="98" height="18"></object></span>
209 This domain is mostly handled by A&S 13.3.6 (see implementation
210 notes below), but there are some values where either that series
211 is non-convergent (most particularly for <span class="emphasis"><em>b</em></span>
212 < 0) or where the series becomes divergent after a few terms
213 limiting the precision that can be achieved.
218 <sub>1</sub>F<sub>1</sub>(-5.9981750131794866e-15, 0.499999999999994, -240.42092034220695)
225 The following graph illustrates the problem area for <span class="emphasis"><em>b < 0</em></span>
226 and <span class="emphasis"><em>a,z > 0</em></span>:
231 <script type="text/javascript" src="../../../graphs/hypergeometric_1f1/negative_b_incalculable.js"></script>
233 <div id="fce5fa05-942c-4973-941f-2f3d25bcecb3" style="width: 800px; height: 600px;" class="plotly-graph-div"></div>
234 <script type="text/javascript">
236 window.PLOTLYENV={'BASE_URL': 'https://plot.ly'};
238 var gd = document.getElementById('fce5fa05-942c-4973-941f-2f3d25bcecb3')
239 var resizeDebounce = null;
241 function resizePlot() {
242 var bb = gd.getBoundingClientRect();
243 Plotly.relayout(gd, {
250 window.addEventListener('resize', function() {
251 if (resizeDebounce) {
252 window.clearTimeout(resizeDebounce);
254 resizeDebounce = window.setTimeout(resizePlot, 100);
260 data: negative_b_incalculable.data,
261 layout: negative_b_incalculable.layout,
262 frames: negative_b_incalculable.frames,
263 config: {"showLink": true, "linkText": "Export to plot.ly", "mapboxAccessToken": "pk.eyJ1IjoiY2hyaWRkeXAiLCJhIjoiY2lxMnVvdm5iMDA4dnhsbTQ5aHJzcGs0MyJ9.X9o_rzNLNesDxdra4neC_A"}
273 <a name="math_toolkit.hypergeometric.hypergeometric_1f1.h2"></a>
274 <span class="phrase"><a name="math_toolkit.hypergeometric.hypergeometric_1f1.testing"></a></span><a class="link" href="hypergeometric_1f1.html#math_toolkit.hypergeometric.hypergeometric_1f1.testing">Testing</a>
277 There are 3 main groups of tests:
279 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
280 <li class="listitem">
281 Spot tests for special inputs with known values.
283 <li class="listitem">
284 Sanity checks which use integrals of hypergeometric functions of known
285 value. These are particularly useful since for fixed <span class="emphasis"><em>a</em></span>
286 and <span class="emphasis"><em>b</em></span> they evaluate <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(a,b,z)</em></span>
287 for all <span class="emphasis"><em>z</em></span>.
289 <li class="listitem">
290 Testing against values precomputed using arbitrary precision arithmetic
291 and the <span class="emphasis"><em>pFq</em></span> series.
295 We also have a <a href="../../../../tools/hypergeometric_1F1_error_plot.cpp" target="_top">small
296 program</a> for testing random values over a user-specified domain of
297 <span class="emphasis"><em>a</em></span>, <span class="emphasis"><em>b</em></span> and <span class="emphasis"><em>z</em></span>,
298 this program is also used for the error rate plots below and has been extremely
299 useful in fine-tuning the implementation.
302 It should be noted however, that there are some domains for large negative
303 <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> that have poor test coverage
304 as we were simply unable to compute test values in reasonable time: it is
305 not uncommon for the <span class="emphasis"><em>pFq</em></span> series to cancel many hundreds
306 of digits and sometimes into the thousands of digits.
309 <a name="math_toolkit.hypergeometric.hypergeometric_1f1.h3"></a>
310 <span class="phrase"><a name="math_toolkit.hypergeometric.hypergeometric_1f1.errors"></a></span><a class="link" href="hypergeometric_1f1.html#math_toolkit.hypergeometric.hypergeometric_1f1.errors">Errors</a>
313 We divide the domain of <sub>1</sub><span class="emphasis"><em>F</em></span><sub>1</sub> up into several domains to
314 explain the error rates.
317 In the following graphs we ran 100000 random test cases over each domain,
318 note that the scatter plots show only the very worst errors as otherwise
319 the graphs are both incomprehensible and virtually unplottable (as in sudden
323 For 0 < a,b,z the error rates are trivially small unless we are forced
324 to take steps to avoid very-slow convergence and use a method other than
325 direct evaluation of the series for performance reasons. Even so the errors
326 rates are broadly acceptable, while the scatter graph shows where the worst
330 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/hypergeometric_1f1/positive_abz_bins.svg" width="567" height="320"></object></span>
333 <script type="text/javascript" src="../../../graphs/hypergeometric_1f1/positive_abz.js"></script>
335 <div id="87d8c26d-c743-4b69-8576-64f861bb7262" style="width: 800px; height: 600px;" class="plotly-graph-div"></div>
336 <script type="text/javascript">
338 window.PLOTLYENV = { 'BASE_URL': 'https://plot.ly' };
340 var gd = document.getElementById('87d8c26d-c743-4b69-8576-64f861bb7262')
341 var resizeDebounce = null;
343 function resizePlot() {
344 var bb = gd.getBoundingClientRect();
345 Plotly.relayout(gd, {
352 window.addEventListener('resize', function () {
353 if (resizeDebounce) {
354 window.clearTimeout(resizeDebounce);
356 resizeDebounce = window.setTimeout(resizePlot, 100);
362 data: positive_abz.data,
363 layout: positive_abz.layout,
364 frames: positive_abz.frames,
365 config: { "showLink": true, "linkText": "Export to plot.ly", "mapboxAccessToken": "pk.eyJ1IjoiY2hyaWRkeXAiLCJhIjoiY2lxMnVvdm5iMDA4dnhsbTQ5aHJzcGs0MyJ9.X9o_rzNLNesDxdra4neC_A" }
375 For -1000 < a < 0 and 0 < b,z < 1000 the maximum error rates
376 are higher, but most are still low, and the worst errors are fairly evenly
380 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/hypergeometric_1f1/negative_a_bins.svg" width="567" height="331"></object></span>
383 <script type="text/javascript" src="../../../graphs/hypergeometric_1f1/negative_a.js"></script>
385 <div id="cc677464-acba-4deb-b026-ef0ea03f1259" style="width: 800px; height: 600px;" class="plotly-graph-div"></div>
386 <script type="text/javascript">
388 window.PLOTLYENV = { 'BASE_URL': 'https://plot.ly' };
390 var gd = document.getElementById('cc677464-acba-4deb-b026-ef0ea03f1259')
391 var resizeDebounce = null;
393 function resizePlot() {
394 var bb = gd.getBoundingClientRect();
395 Plotly.relayout(gd, {
402 window.addEventListener('resize', function () {
403 if (resizeDebounce) {
404 window.clearTimeout(resizeDebounce);
406 resizeDebounce = window.setTimeout(resizePlot, 100);
412 data: negative_a.data,
413 layout: negative_a.layout,
414 frames: negative_a.frames,
415 config: { "showLink": true, "linkText": "Export to plot.ly", "mapboxAccessToken": "pk.eyJ1IjoiY2hyaWRkeXAiLCJhIjoiY2lxMnVvdm5iMDA4dnhsbTQ5aHJzcGs0MyJ9.X9o_rzNLNesDxdra4neC_A" }
425 For -1000 < <span class="emphasis"><em>b</em></span> < 0 and <span class="emphasis"><em>a</em></span>,<span class="emphasis"><em>z</em></span>
426 > 0 the errors are mostly low at double precision except near the "unimplementable
427 zone". Note however, that the some of the methods used here fail to
428 converge to much better than double precision.
431 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/hypergeometric_1f1/negative_b_bins.svg" width="567" height="319"></object></span>
435 <script type="text/javascript" src="../../../graphs/hypergeometric_1f1/negative_b.js"></script>
437 <div id="49ba2424-47a3-454d-ba72-b46ded00693f" style="width: 800px; height: 600px;" class="plotly-graph-div"></div>
438 <script type="text/javascript">
440 window.PLOTLYENV={'BASE_URL': 'https://plot.ly'};
442 var gd = document.getElementById('49ba2424-47a3-454d-ba72-b46ded00693f')
443 var resizeDebounce = null;
445 function resizePlot() {
446 var bb = gd.getBoundingClientRect();
447 Plotly.relayout(gd, {
454 window.addEventListener('resize', function() {
455 if (resizeDebounce) {
456 window.clearTimeout(resizeDebounce);
458 resizeDebounce = window.setTimeout(resizePlot, 100);
464 data: negative_b.data,
465 layout: negative_b.layout,
466 frames: negative_b.frames,
467 config: {"showLink": true, "linkText": "Export to plot.ly", "mapboxAccessToken": "pk.eyJ1IjoiY2hyaWRkeXAiLCJhIjoiY2lxMnVvdm5iMDA4dnhsbTQ5aHJzcGs0MyJ9.X9o_rzNLNesDxdra4neC_A"}
477 For both <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> less than zero,
478 the errors the worst errors are clustered in a "difficult zone"
479 with <span class="emphasis"><em>b < a</em></span> and <span class="emphasis"><em>z</em></span> ≈ <span class="emphasis"><em>a</em></span>:
482 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/hypergeometric_1f1/negative_ab_bins.svg" width="461" height="280"></object></span>
484 <script type="text/javascript" src="../../../graphs/hypergeometric_1f1/negative_ab.js"></script>
486 <div id="2867e84a-7d1d-4110-b28a-fb718dbd65ca" style="width: 800px; height: 600px;" class="plotly-graph-div"></div>
487 <script type="text/javascript">
489 window.PLOTLYENV={'BASE_URL': 'https://plot.ly'};
491 var gd = document.getElementById('2867e84a-7d1d-4110-b28a-fb718dbd65ca')
492 var resizeDebounce = null;
494 function resizePlot() {
495 var bb = gd.getBoundingClientRect();
496 Plotly.relayout(gd, {
503 window.addEventListener('resize', function() {
504 if (resizeDebounce) {
505 window.clearTimeout(resizeDebounce);
507 resizeDebounce = window.setTimeout(resizePlot, 100);
513 data: negative_ab.data,
514 layout: negative_ab.layout,
515 frames: negative_ab.frames,
516 config: {"showLink": true, "linkText": "Export to plot.ly", "mapboxAccessToken": "pk.eyJ1IjoiY2hyaWRkeXAiLCJhIjoiY2lxMnVvdm5iMDA4dnhsbTQ5aHJzcGs0MyJ9.X9o_rzNLNesDxdra4neC_A"}
525 <a name="math_toolkit.hypergeometric.hypergeometric_1f1.h4"></a>
526 <span class="phrase"><a name="math_toolkit.hypergeometric.hypergeometric_1f1.implementation"></a></span><a class="link" href="hypergeometric_1f1.html#math_toolkit.hypergeometric.hypergeometric_1f1.implementation">Implementation</a>
529 The implementation for this function is remarkably complex; readers will
530 have to refer to the code for the transitions between methods, as we can
531 only give an overview here.
534 In almost all cases where <span class="emphasis"><em>z < 0</em></span> we use <a href="https://en.wikipedia.org/wiki/Confluent_hypergeometric_function" target="_top">Kummer's
535 relation</a> to make <span class="emphasis"><em>z</em></span> positive:
537 <div class="blockquote"><blockquote class="blockquote"><p>
538 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_12.svg" width="189" height="16"></object></span>
539 </p></blockquote></div>
541 The main series representation
543 <div class="blockquote"><blockquote class="blockquote"><p>
544 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_1.svg" width="234" height="38"></object></span>
545 </p></blockquote></div>
549 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
550 <li class="listitem">
551 we are sure that it is convergent and not subject to excessive cancellation,
554 <li class="listitem">
555 there is no other better method available.
559 The implementation of this series is complicated by the fact that for <span class="emphasis"><em>b</em></span>
560 < 0 then what appears to be a fully converged series can in fact suddenly
561 jump back to life again as <span class="emphasis"><em>b</em></span> crosses the origin.
566 <div class="blockquote"><blockquote class="blockquote"><p>
567 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_3.svg" width="614" height="39"></object></span>
568 </p></blockquote></div>
570 which is particularly useful for <span class="emphasis"><em>a ≅ b</em></span> and <span class="emphasis"><em>z
571 > 0</em></span>, or <span class="emphasis"><em>a</em></span> ≪ 1, and <span class="emphasis"><em>z
575 Then we have Tricomi's approximation (given in simplified form in A&S
576 13.3.7) <a class="link" href="hypergeometric_refs.html" title="Hypergeometric References">(7)</a>
578 <div class="blockquote"><blockquote class="blockquote"><p>
579 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_4.svg" width="356" height="38"></object></span>
580 </p></blockquote></div>
584 <div class="blockquote"><blockquote class="blockquote"><p>
585 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_5.svg" width="390" height="33"></object></span>
586 </p></blockquote></div>
590 <div class="blockquote"><blockquote class="blockquote"><p>
591 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_6.svg" width="370" height="16"></object></span>
592 </p></blockquote></div>
594 With <span class="emphasis"><em>E<sub>v</sub></em></span> defined as:
596 <div class="blockquote"><blockquote class="blockquote"><p>
597 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_7.svg" width="149" height="86"></object></span>
598 </p></blockquote></div>
600 This approximation is especially effective when <span class="emphasis"><em>a < 0</em></span>.
603 For <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> both large and positive
604 and somewhat similar in size then an expansion in terms of gamma functions
605 can be used <a class="link" href="hypergeometric_refs.html" title="Hypergeometric References">(6)</a>:
607 <div class="blockquote"><blockquote class="blockquote"><p>
608 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_8.svg" width="349" height="43"></object></span>
609 </p></blockquote></div>
611 For <span class="emphasis"><em>z</em></span> large we have the asymptotic expansion:
613 <div class="blockquote"><blockquote class="blockquote"><p>
614 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_9.svg" width="261" height="43"></object></span>
615 </p></blockquote></div>
617 which is a special case of the gamma function expansion above.
620 In the situation where <code class="computeroutput"><span class="identifier">ab</span><span class="special">/</span><span class="identifier">z</span></code> is reasonably
621 small then Luke's rational approximation is used - this is too complex to
622 document here, refer either to the code or the original paper <a class="link" href="hypergeometric_refs.html" title="Hypergeometric References">(3)</a>.
625 The special case <sub>1</sub><span class="emphasis"><em>F</em></span><sub>1</sub>(1, <span class="emphasis"><em>b</em></span>, -<span class="emphasis"><em>z</em></span>)
626 is treated via Luke's Pade approximation <a class="link" href="hypergeometric_refs.html" title="Hypergeometric References">(3)</a>.
629 That effectively completes the "direct" methods used, the remaining
630 areas are treated indirectly via recurrence relations. These require extreme
631 care in their use, as they often change the direction of stability, or else
632 are not stable at all. Sometimes this is a well defined and characterized
633 change in direction: for example with <span class="emphasis"><em>a,b</em></span> and <span class="emphasis"><em>z</em></span>
634 all positive recurrence on <span class="emphasis"><em>a</em></span> via
636 <div class="blockquote"><blockquote class="blockquote"><p>
637 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_10.svg" width="429" height="16"></object></span>
638 </p></blockquote></div>
640 abruptly changes from stable forwards recursion to stable backwards if <span class="emphasis"><em>2a-b+z</em></span>
641 changes sign. Thus recurrence on <span class="emphasis"><em>a</em></span>, even when <sub>1</sub><span class="emphasis"><em>F</em></span><sub>1</sub>(<span class="emphasis"><em>a</em></span>+<span class="emphasis"><em>N</em></span>,
642 <span class="emphasis"><em>b</em></span>, <span class="emphasis"><em>z</em></span>) is strictly increasing, needs
643 careful handling as <span class="emphasis"><em>a</em></span> → 0.
646 The transitory nature of the stable recurrence relations is well documented
647 in the literature, for example <a class="link" href="hypergeometric_refs.html" title="Hypergeometric References">(10)</a>
648 gives many examples, including the anomalous behaviour of recurrence on
649 <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> for large <span class="emphasis"><em>z</em></span>
650 as first documented by Gauchi <a class="link" href="hypergeometric_refs.html" title="Hypergeometric References">(12)</a>.
651 Gauchi also provides the definitive reference on 3-term recurrence relations
652 in general in <a class="link" href="hypergeometric_refs.html" title="Hypergeometric References">(11)</a>.
655 Unfortunately, not all recurrence stabilities are so well defined. For example,
656 when considering <sub>1</sub>F<sub>1</sub>(<span class="emphasis"><em>a</em></span>, -<span class="emphasis"><em>b</em></span>, <span class="emphasis"><em>z</em></span>)
657 it would be convenient to use the continued fractions associated with the
658 recurrence relations to calculate <sub>1</sub>F<sub>1</sub>(<span class="emphasis"><em>a</em></span>, -<span class="emphasis"><em>b</em></span>,
659 <span class="emphasis"><em>z</em></span>) / <sub>1</sub>F<sub>1</sub>(<span class="emphasis"><em>a</em></span>, 1-<span class="emphasis"><em>b</em></span>,
660 <span class="emphasis"><em>z</em></span>) and then normalize either by iterating forwards on
661 <span class="emphasis"><em>b</em></span> until <span class="emphasis"><em>b > 0</em></span> and comparison
662 with a reference value, or by using the Wronskian
664 <div class="blockquote"><blockquote class="blockquote"><p>
665 <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/hypergeometric_1f1_11.svg" width="564" height="33"></object></span>
666 </p></blockquote></div>
668 which is of course the well known Miller's method <a class="link" href="hypergeometric_refs.html" title="Hypergeometric References">(12)</a>.
671 Unfortunately, stable forwards recursion on <span class="emphasis"><em>b</em></span> is stable
672 only for <span class="emphasis"><em>|b| << |z|</em></span>, as <span class="emphasis"><em>|b|</em></span>
673 increases in magnitude it passes through a region where recursion is unstable
674 in both directions before eventually becoming stable in the backwards direction
675 (at least for a while!). This transition is moderated not by a change of
676 sign in the recurrence coefficients themselves, but by a change in the behaviour
677 of the <span class="emphasis"><em>values</em></span> of <sub>1</sub>F<sub>1</sub> - from alternating in sign when
678 <span class="emphasis"><em>|b|</em></span> is small to having the same sign when <span class="emphasis"><em>b</em></span>
679 is larger. During the actual transition, <sub>1</sub>F<sub>1</sub> will either pass through a zero
680 or a minima depending on whether b is even or odd (if there is a minima at
681 <sub>1</sub>F<sub>1</sub>(a, b, z) then there is necessarily a zero at <sub>1</sub>F<sub>1</sub>(a+1, b+1, z) as per
682 the <a href="https://dlmf.nist.gov/13.3#E15" target="_top">derivative of the function</a>).
683 As a result the behaviour of the recurrence relations is almost impossible
684 to reason about in this area, and we are left to using heuristic based approaches
685 to "guess" which region we are in.
688 In this implementation we use recurrence relations as follows:
691 For <span class="emphasis"><em>a,b,z > 0</em></span> and large we can either:
693 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
694 <li class="listitem">
695 Make <span class="emphasis"><em>0 < a < 1</em></span> and <span class="emphasis"><em>b > z</em></span>
696 and evaluate the defining series directly, or
698 <li class="listitem">
699 The gamma function approximation has decent convergence and accuracy
700 for <span class="emphasis"><em>2b - 1 < a < 2b < z</em></span>, so we can move
701 <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> into this region, or
703 <li class="listitem">
704 We can recurse on <span class="emphasis"><em>b</em></span> alone so that <span class="emphasis"><em>b-1
705 < a < b</em></span> and use A&S 13.3.6 as long as <span class="emphasis"><em>z</em></span>
710 For <span class="emphasis"><em>b < 0</em></span> and <span class="emphasis"><em>a</em></span> tiny we would
711 normally use A&S 13.3.6, but when that is non-convergent for some inputs
712 we can use the forward recurrence relation on <span class="emphasis"><em>b</em></span> to calculate
713 the ratio <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(a, -b, z)/<sub>1</sub>F<sub>1</sub>(a, 1-b, z)</em></span> and then iterate
714 forwards until <span class="emphasis"><em>b > 0</em></span> and compute a reference value
715 and normalize (Millers Method). In the same domain when <span class="emphasis"><em>b</em></span>
716 is near -1 we can use a single backwards recursion on <span class="emphasis"><em>b</em></span>
717 to compute <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(a, -b, z)</em></span> from <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(a, 2-b,
718 z)</em></span> and <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(<span class="emphasis"><em>a</em></span>, 1-<span class="emphasis"><em>b</em></span>,
719 <span class="emphasis"><em>z</em></span>)</em></span> even though technically we are recursing
720 in the unstable direction.
723 For <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(-N, b, z)</em></span> and integer <span class="emphasis"><em>N</em></span>
724 then backwards recursion from <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(0, b, z)</em></span> and <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(-1,
725 b, z)</em></span> works well.
728 For <span class="emphasis"><em>a</em></span> or <span class="emphasis"><em>b</em></span> < 0 and if all the
729 direct methods have failed, then we use various fallbacks:
732 For <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(-a, b, z)</em></span> we can use backwards recursion on
733 <span class="emphasis"><em>a</em></span> as long as <span class="emphasis"><em>b > z</em></span>, otherwise
734 a more complex scheme is required which starts from <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(-a + N,
735 b + M, z)</em></span>, and recurses backwards in up to 3 stages: first on
736 <span class="emphasis"><em>a</em></span>, then on <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span>
737 together, and finally on <span class="emphasis"><em>b</em></span> alone.
740 For <span class="emphasis"><em>b < 0</em></span> we have no good methods in some domains
741 (see the unsolved issues above). However in some circumstances we can either
744 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
745 <li class="listitem">
746 3-stage backwards recursion on both <span class="emphasis"><em>a</em></span>, <span class="emphasis"><em>a</em></span>
747 and <span class="emphasis"><em>b</em></span> and then <span class="emphasis"><em>b</em></span> as above.
749 <li class="listitem">
750 Calculate the ratio <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(a, b, z) / <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(a-1, b-1,
751 z)</em></span></em></span> via backwards recurrence when z is small, and
752 then normalize via the Wronskian above (Miller's method).
754 <li class="listitem">
755 Calculate the ratio <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(a, b, z) / <span class="emphasis"><em><sub>1</sub>F<sub>1</sub>(a+1, b+1,
756 z)</em></span></em></span> via forwards recurrence when z is large, and
757 then normalize by iterating until b > 1 and comparing to a reference
762 The latter two methods use a lookup table to determine whether inputs are
763 in either of the domains or neither. Unfortunately the methods are basically
764 limited to double precision: calculation of the ratios require iteration
765 <span class="emphasis"><em>towards</em></span> the no-mans-land between the two methods where
766 iteration is unstable in both directions. As a result, only low-precision
767 results which require few iterations to calculate the ratio are available.
770 If all else fails, then we use a checked series summation which will raise
771 an <a class="link" href="../error_handling.html#math_toolkit.error_handling.evaluation_error">evaluation_error</a>
772 if more than half the digits are destroyed by cancellation.
775 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
776 <td align="left"></td>
777 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
778 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
779 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
780 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
781 Daryle Walker and Xiaogang Zhang<p>
782 Distributed under the Boost Software License, Version 1.0. (See accompanying
783 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
788 <div class="spirit-nav">
789 <a accesskey="p" href="hypergeometric_2f0.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../hypergeometric.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="hypergeometric_pfq.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>