Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for new hypergeometric functions #866

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/functions-reference/functions_index.qmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions src/functions-reference/real-valued_basic_functions.qmd
Original file line number Diff line number Diff line change
@@ -1698,3 +1698,69 @@ Implementation of the $W_0$ branch of the Lambert W function, i.e., solution to
`R` **`lambert_wm1`**`(T x)`<br>\newline
Implementation of the $W_{-1}$ branch of the Lambert W function, i.e., solution to the function $W_{-1}(x) \exp^{W_{-1}(x)} = x$
{{< since 2.25 >}}

## Hypergeometric Functions {#hypergeometric-functions}

Hypergeometric functions refer to a power series of the form
\begin{equation*}
_pF_q(a_1,...,a_p;b_1,...,b_q;z) = \sum_{n=0}^\infty \frac{(a_1)_n\cdot\cdot\cdot(a_p)_n}{(b_1)_n\cdot\cdot\cdot(b_q)_n} \frac{x^n}{n!}
\end{equation*}
where $(a)_n$ is the Pochhammer symbol defined as $(a)_n = \frac{\Gamma(a+n)}{\Gamma(a)}$.

The gradients of the hypergeometric function are given by:
\begin{equation*}
\frac{\partial }{\partial a_1} =
\sum_{k=0}^{\infty}{
\frac
{\psi\left(k+a_1\right)\left(\prod_{j=1}^p\left(a_j\right)_k\right)z^k}
{k!\prod_{j=1}^q\left(b_j\right)_k}}
- \psi\left(a_1\right){}_pF_q(a_1,...,a_p;b_1,...,b_q;z)
\end{equation*}
\begin{equation*}
\frac{\partial }{\partial b_1} =
\psi\left(b_1\right){}_pF_q(a_1,...,a_p;b_1,...,b_q;z) -
\sum_{k=0}^{\infty}{
\frac
{\psi\left(k+b_1\right)\left(\prod_{j=1}^p\left(a_j\right)_k\right)z^k}
{k!\prod_{j=1}^q\left(b_j\right)_k}}
\end{equation*}
\begin{equation*}
\frac{\partial }{\partial z} =
\frac{\prod_{j=1}^{p}a_j}{\prod_{j=1}^{q} b_j}{}_pF_q(a_1+1,...,a_p+1;b_1+1,...,b_q+1;z)
\end{equation*}

Stan provides both the generalized hypergeometric function as well as several
special cases for particular values of p and q.

<!-- real; hypergeometric_1F0; (real a, real z); -->
\index{{\tt \bfseries hypergeometric\_1F0 }!{\tt (real a, real z): real}|hyperpage}

`real` **`hypergeometric_1F0`**`(real a, real z)`<br>\newline
Special case of the hypergeometric function with $p=1$ and $q=0$.
{{< since 2.37 >}}

<!-- real; hypergeometric_2F1; (real a1, real a2, real b1, real z); -->
\index{{\tt \bfseries hypergeometric\_2F1 }!{\tt (real a1, real a2, real b1, real z): real}|hyperpage}

`real` **`hypergeometric_2F1`**`(real a1, real a2, real b1, real z)`<br>\newline
Special case of the hypergeometric function with $p=2$ and $q=1$. If the function does not
meet convergence criteria for given inputs, the function will attempt to apply [Euler's transformation](https://mathworld.wolfram.com/EulersHypergeometricTransformations.html)
to improve convergence:
\begin{equation*}
{}_2F_1(a_1,a_2, b_1, z)={}_2F_1(b_1 - a_1,a_2, b_1, \frac{z}{z-1})\cdot(1-z)^{-a_2}
\end{equation*}
{{< since 2.37 >}}

<!-- real; hypergeometric_3F2; (T1 a, T2 b, real z); -->
\index{{\tt \bfseries hypergeometric\_3F2 }!{\tt (T1 a, T2 b, real z): real}|hyperpage}

`real` **`hypergeometric_3F2`**`(T1 a, T2 b, real z)`<br>\newline
Special case of the hypergeometric function with $p=3$ and $q=2$, where a and b are vectors of length 3 and 2, respectively.
{{< since 2.37 >}}

<!-- real; hypergeometric_pFq; (T1 a, T2 b, real z); -->
\index{{\tt \bfseries hypergeometric\_pFq }!{\tt (T1 a, T2 b, real z): real}|hyperpage}

`real` **`hypergeometric_pFq`**`(T1 a, T2 b, real z)`<br>\newline
Generalized hypergeometric function, where a and b are vectors of length p and q, respectively.
{{< since 2.37 >}}