| 1 | ;; Psi (digamma) functions |
|---|
| 2 | ;; Liam Healy, Mon May 1 2006 - 22:11 |
|---|
| 3 | ;; Time-stamp: <2008-02-16 22:43:28EST psi.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | ;;;;**************************************************************************** |
|---|
| 9 | ;;;; Digamma Function |
|---|
| 10 | ;;;;**************************************************************************** |
|---|
| 11 | |
|---|
| 12 | (defgeneric psi (x) |
|---|
| 13 | ;; FDL |
|---|
| 14 | (:documentation "The psi, or digamma, function.")) |
|---|
| 15 | |
|---|
| 16 | (defmfun psi ((n integer)) |
|---|
| 17 | "gsl_sf_psi_int_e" ((n :int) (ret sf-result)) |
|---|
| 18 | :type :method |
|---|
| 19 | :export t |
|---|
| 20 | :documentation ; FDL |
|---|
| 21 | "Domain: n integer, n > 0.") |
|---|
| 22 | |
|---|
| 23 | (defmfun psi ((x float)) |
|---|
| 24 | "gsl_sf_psi_e" ((x :double) (ret sf-result)) |
|---|
| 25 | :type :method |
|---|
| 26 | :documentation ; FDL |
|---|
| 27 | "Domain: x /= 0.0, -1.0, -2.0, ...") |
|---|
| 28 | |
|---|
| 29 | (defmfun psi-1+iy (x) |
|---|
| 30 | "gsl_sf_psi_1piy_e" ((x :double) (ret sf-result)) |
|---|
| 31 | :documentation ; FDL |
|---|
| 32 | "The real part of the digamma function |
|---|
| 33 | on the line 1+i y, Re[psi(1 + i y)].") |
|---|
| 34 | |
|---|
| 35 | ;;;;**************************************************************************** |
|---|
| 36 | ;;;; Trigamma Function |
|---|
| 37 | ;;;;**************************************************************************** |
|---|
| 38 | |
|---|
| 39 | (defgeneric psi-1 (x) |
|---|
| 40 | ;; FDL |
|---|
| 41 | (:documentation "The Trigamma function.")) |
|---|
| 42 | |
|---|
| 43 | (defmfun psi-1 ((n integer)) |
|---|
| 44 | "gsl_sf_psi_1_int_e" ((n :int) (ret sf-result)) |
|---|
| 45 | :type :method |
|---|
| 46 | :documentation ; FDL |
|---|
| 47 | "Domain: n integer, n > 0.") |
|---|
| 48 | |
|---|
| 49 | (defmfun psi-1 ((x float)) |
|---|
| 50 | "gsl_sf_psi_1_e" ((x :double) (ret sf-result)) |
|---|
| 51 | :type :method |
|---|
| 52 | :documentation ; FDL |
|---|
| 53 | "Domain: x /= 0.0, -1.0, -2.0, ...") |
|---|
| 54 | |
|---|
| 55 | ;;;;**************************************************************************** |
|---|
| 56 | ;;;; Polygamma |
|---|
| 57 | ;;;;**************************************************************************** |
|---|
| 58 | |
|---|
| 59 | (defmfun psi-n (m x) |
|---|
| 60 | "gsl_sf_psi_n_e" ((m :int) (x :double) (ret sf-result)) |
|---|
| 61 | :documentation ; FDL |
|---|
| 62 | "The polygamma function psi^{(m)}(x)} for m >= 0, x > 0.") |
|---|
| 63 | |
|---|
| 64 | ;;;;**************************************************************************** |
|---|
| 65 | ;;;; Examples and unit test |
|---|
| 66 | ;;;;**************************************************************************** |
|---|
| 67 | |
|---|
| 68 | #| |
|---|
| 69 | (make-tests psi |
|---|
| 70 | (psi 4) |
|---|
| 71 | (psi 4.0d0) |
|---|
| 72 | (psi-1+iy 2.0d0) |
|---|
| 73 | (psi-1 4) |
|---|
| 74 | (psi-1 4.0d0) |
|---|
| 75 | (psi-n 2 4.0d0)) |
|---|
| 76 | |# |
|---|
| 77 | |
|---|
| 78 | (LISP-UNIT:DEFINE-TEST PSI |
|---|
| 79 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 80 | (LIST 1.2561176684318005d0 2.789141514262906d-16) |
|---|
| 81 | (MULTIPLE-VALUE-LIST (PSI 4))) |
|---|
| 82 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 83 | (LIST 1.2561176684318005d0 2.846229783626858d-16) |
|---|
| 84 | (MULTIPLE-VALUE-LIST (PSI 4.0d0))) |
|---|
| 85 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 86 | (LIST 0.7145915153739806d0 1.925418559790263d-14) |
|---|
| 87 | (MULTIPLE-VALUE-LIST (PSI-1+IY 2.0d0))) |
|---|
| 88 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 89 | (LIST 0.2838229557371153d0 6.302135607530242d-17) |
|---|
| 90 | (MULTIPLE-VALUE-LIST (PSI-1 4))) |
|---|
| 91 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 92 | (LIST 0.28382295573711525d0 1.764597970108467d-15) |
|---|
| 93 | (MULTIPLE-VALUE-LIST (PSI-1 4.0d0))) |
|---|
| 94 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 95 | (LIST -0.0800397322451145d0 5.222647053360405d-16) |
|---|
| 96 | (MULTIPLE-VALUE-LIST (PSI-N 2 4.0d0)))) |
|---|