1919The term ``special function'' has no formal definition. However, for the purposes of the
2020@racketmodname[math] library, a @deftech{special function} is one that is not @tech{elementary}.
2121
22- The special functions are split into two groups: @secref{real-functions} and
22+ The special functions are split into three groups: @secref{complex-functions}, @secref{real-functions} and
2323@secref{flonum-functions}. Functions that accept real arguments are usually defined
2424in terms of their flonum counterparts, but are different in two crucial ways:
2525@itemlist[
@@ -28,13 +28,13 @@ in terms of their flonum counterparts, but are different in two crucial ways:
2828 @racket[exn:fail:contract] instead of returning @racket[+nan.0 ].}
2929]
3030
31- Currently, @racketmodname[math/special -functions] does not export any functions that accept
32- or return complex numbers. Mathematically, some of them could return complex numbers given
31+ Only functions in @secref{complex -functions} support accepting or returning complex arguments.
32+ Mathematically, some of the other functions could return complex numbers given
3333real numbers, such @racket[hurwitz-zeta] when given a negative second argument. In
3434these cases, they raise an @racket[exn:fail:contract] (for an exact argument) or return
3535@racket[+nan.0 ] (for an inexact argument).
3636
37- Most real functions have more than one type, but they are documented as having only
37+ Most real and complex functions have more than one type, but they are documented as having only
3838one. The documented type is the most general type, which is used to generate a contract for
3939uses in untyped code. Use @racket[:print-type] to see all of a function's types.
4040
@@ -56,11 +56,11 @@ The most general type @racket[Real -> (U Zero Flonum)] is used to generate
5656@racket[lambert]'s contract when it is used in untyped code. Except for this discussion,
5757this the only type documented for @racket[lambert].
5858
59- @section[#:tag "real -functions " ]{Real Functions}
59+ @section[#:tag "complex -functions " ]{Complex Functions}
6060
61- @defproc[(gamma [x Real ]) (U Positive-Integer Flonum) ]{
61+ @defproc[(gamma [x Number ]) Number ]{
6262Computes the @hyperlink["http://en.wikipedia.org/wiki/Gamma_function " ]{gamma function},
63- a generalization of the factorial function to the entire real line , except nonpositive integers.
63+ a generalization of the factorial function to the entire complex plane , except nonpositive exact integers.
6464When @racket[x] is an exact integer, @racket[(gamma x)] is exact.
6565
6666@examples[#:eval untyped-eval
@@ -76,16 +76,17 @@ When @racket[x] is an exact integer, @racket[(gamma x)] is exact.
7676 (gamma -1.0 )
7777 (gamma 0.0 )
7878 (gamma -0.0 )
79+ (gamma 1+i )
7980 (gamma 172.0 )
8081 (eval:alts
8182 (bf (gamma 172 ))
8283 (eval:result @racketresultfont{(bf "1.241018070217667823424840524103103992618e309 " )}))]
8384
84- Error is no more than 10 @tech{ulps} everywhere that has been tested, and is usually no more than 4
85- ulps.
85+ On the real line the error is no more than 10 @tech{ulps} everywhere that has been tested, and is usually no more than 4
86+ ulps. In the rest of the complex plane the relative error is smaller than 1e-13 (@tech{ulps}=450).
8687}
8788
88- @defproc[(log-gamma [x Real ]) (U Zero Flonum) ]{
89+ @defproc[(log-gamma [x Number ]) Number ]{
8990Like @racket[(log (abs (gamma x)))], but more accurate and without unnecessary overflow.
9091The only exact cases are @racket[(log-gamma 1 ) = 0 ] and @racket[(log-gamma 2 ) = 0 ].
9192
@@ -99,25 +100,27 @@ The only exact cases are @racket[(log-gamma 1) = 0] and @racket[(log-gamma 2) =
99100 (log-gamma -1 )
100101 (log-gamma -1.0 )
101102 (log-gamma 0.0 )
103+ (log-gamma 1+i )
102104 (log (abs (gamma 172.0 )))
103105 (log-gamma 172.0 )]
104106
105- Error is no more than 11 @tech{ulps} everywhere that has been tested, and is usually no more than 2
107+ On the real line error is no more than 11 @tech{ulps} everywhere that has been tested, and is usually no more than 2
106108ulps. Error reaches its maximum near negative roots.
107109}
108110
109- @defproc[(psi0 [x Real ]) Flonum ]{
111+ @defproc[(psi0 [x Number ]) Number ]{
110112Computes the @hyperlink["http://en.wikipedia.org/wiki/Digamma_function " ]{digamma function},
111113the logarithmic derivative of the gamma function.
112114
113115@examples[#:eval untyped-eval
114116 (plot (function psi0 -2.5 4.5 ) #:y-min -5 #:y-max 5 )
115117 (psi0 0 )
116118 (psi0 1 )
119+ (psi0 1+i )
117120 (- gamma.0)]
118121
119- Except near negative roots, maximum observed error is 2 @tech{ulps}, but is usually no more
120- than 1.
122+ On the real line, except near negative roots, maximum observed error is 2 @tech{ulps}, but is usually no more
123+ than 1. In the complex plane the relative error is around 1e-13.
121124
122125Near negative roots, which occur singly between each pair of negative integers, @racket[psi0]
123126exhibits @tech{catastrophic cancellation} from using the reflection formula, meaning that
@@ -129,6 +132,8 @@ error.
129132If you need low relative error near negative roots, use @racket[bfpsi0].
130133}
131134
135+ @section[#:tag "real-functions " ]{Real Functions}
136+
132137@defproc[(psi [m Integer] [x Real]) Flonum]{
133138Computes a @hyperlink["http://en.wikipedia.org/wiki/Polygamma_function " ]{polygamma function},
134139or the @racket[m]th logarithmic derivative of the gamma function. The order @racket[m] must be
0 commit comments