| 1 | ;; Exponential functions |
|---|
| 2 | ;; Liam Healy, Tue Mar 21 2006 - 17:05 |
|---|
| 3 | ;; Time-stamp: <2008-02-16 21:01:05EST exponential-functions.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | ;;;;**************************************************************************** |
|---|
| 9 | ;;;; Exponential Functions |
|---|
| 10 | ;;;;**************************************************************************** |
|---|
| 11 | |
|---|
| 12 | (defmfun gsl-exp (x) |
|---|
| 13 | "gsl_sf_exp_e" ((x :double) (ret sf-result)) |
|---|
| 14 | :documentation ; FDL |
|---|
| 15 | "The exponential function.") |
|---|
| 16 | |
|---|
| 17 | (defmfun exp-scaled (x) |
|---|
| 18 | "gsl_sf_exp_e10_e" ((x :double) (ret sf-result-e10)) |
|---|
| 19 | :documentation ; FDL |
|---|
| 20 | "The exponential function scaled. This function may be useful if the value |
|---|
| 21 | of exp(x) would overflow the numeric range of double.") |
|---|
| 22 | |
|---|
| 23 | (defmfun exp-mult (x y) |
|---|
| 24 | "gsl_sf_exp_mult_e" ((x :double) (y :double) (ret sf-result)) |
|---|
| 25 | :documentation ; FDL |
|---|
| 26 | "Exponentiate x and multiply by the factor y to |
|---|
| 27 | return the product y \exp(x).") |
|---|
| 28 | |
|---|
| 29 | (defmfun exp-mult-scaled (x y) |
|---|
| 30 | "gsl_sf_exp_mult_e10_e" ((x :double) (y :double) (ret sf-result-e10)) |
|---|
| 31 | :documentation ; FDL |
|---|
| 32 | "The product y \exp(x) with extended numeric range.") |
|---|
| 33 | |
|---|
| 34 | ;;;;**************************************************************************** |
|---|
| 35 | ;;;; Relative Exponential Functions |
|---|
| 36 | ;;;;**************************************************************************** |
|---|
| 37 | |
|---|
| 38 | (defmfun expm1 (x) |
|---|
| 39 | "gsl_sf_expm1_e" ((x :double) (ret sf-result)) |
|---|
| 40 | :documentation ; FDL |
|---|
| 41 | "\exp(x)-1 using an algorithm that is accurate for small x.") |
|---|
| 42 | |
|---|
| 43 | (defmfun exprel (x) |
|---|
| 44 | "gsl_sf_exprel_e" ((x :double) (ret sf-result)) |
|---|
| 45 | :documentation ; FDL |
|---|
| 46 | "(\exp(x)-1)/x using an algorithm that is accurate for small x. |
|---|
| 47 | For small x the algorithm is based on the expansion |
|---|
| 48 | (\exp(x)-1)/x = 1 + x/2 + x^2/(2*3) + x^3/(2*3*4) + ...") |
|---|
| 49 | |
|---|
| 50 | (defmfun exprel-2 (x) |
|---|
| 51 | "gsl_sf_exprel_2_e" ((x :double) (ret sf-result)) |
|---|
| 52 | :documentation ; FDL |
|---|
| 53 | "2(\exp(x)-1-x)/x^2 using an algorithm that is accurate for small |
|---|
| 54 | x. For small x the algorithm is based on the expansion |
|---|
| 55 | 2(\exp(x)-1-x)/x^2 = 1 + x/3 + x^2/(3*4) + x^3/(3*4*5) + ...") |
|---|
| 56 | |
|---|
| 57 | (defmfun exprel-n (n x) |
|---|
| 58 | "gsl_sf_exprel_n_e" ((n :int) (x :double) (ret sf-result)) |
|---|
| 59 | :documentation ; FDL |
|---|
| 60 | "N-relative exponential, which is the n-th generalization |
|---|
| 61 | of the functions #'exprel and #'exprel-2.") |
|---|
| 62 | |
|---|
| 63 | ;;;;**************************************************************************** |
|---|
| 64 | ;;;; Exponentiation With Error Estimate |
|---|
| 65 | ;;;;**************************************************************************** |
|---|
| 66 | |
|---|
| 67 | (defmfun exp-err (x dx) |
|---|
| 68 | "gsl_sf_exp_err_e" ((x :double) (dx :double) (ret sf-result)) |
|---|
| 69 | :documentation ; FDL |
|---|
| 70 | "Exponentiate x with an associated absolute error dx.") |
|---|
| 71 | |
|---|
| 72 | (defmfun exp-err-scaled (x dx) |
|---|
| 73 | "gsl_sf_exp_err_e10_e" |
|---|
| 74 | ((x :double) (dx :double) (ret sf-result)) |
|---|
| 75 | :documentation ; FDL |
|---|
| 76 | "Exponentiate x with an associated absolute error dx |
|---|
| 77 | and with extended numeric range.") |
|---|
| 78 | |
|---|
| 79 | (defmfun exp-mult-err (x dx y dy) |
|---|
| 80 | "gsl_sf_exp_mult_err_e" |
|---|
| 81 | ((x :double) (dx :double) (y :double) (dy :double) (ret sf-result)) |
|---|
| 82 | :documentation ; FDL |
|---|
| 83 | "The product y \exp(x) for the quantities x, y |
|---|
| 84 | with associated absolute errors dx, dy.") |
|---|
| 85 | |
|---|
| 86 | (defmfun exp-mult-err-scaled (x y) |
|---|
| 87 | "gsl_sf_exp_mult_err_e10_e" ((x :double) (y :double) (ret sf-result-e10)) |
|---|
| 88 | :documentation ; FDL |
|---|
| 89 | "The product y \exp(x) for the quantities x, y |
|---|
| 90 | with associated absolute errors dx, dy and with |
|---|
| 91 | extended numeric range.") |
|---|
| 92 | |
|---|
| 93 | ;;;;**************************************************************************** |
|---|
| 94 | ;;;; Examples and unit test |
|---|
| 95 | ;;;;**************************************************************************** |
|---|
| 96 | |
|---|
| 97 | #| |
|---|
| 98 | (make-tests exponential-functions |
|---|
| 99 | (gsl-exp 3.0d0) |
|---|
| 100 | (exp-scaled 555.0d0) |
|---|
| 101 | (exp-mult 101.0d0 5.0d0) |
|---|
| 102 | (exp-mult-scaled 555.0d0 101.0d0) |
|---|
| 103 | (expm1 0.0001d0) |
|---|
| 104 | (exprel 0.0001d0) |
|---|
| 105 | (exprel-2 0.001d0) |
|---|
| 106 | (exprel-n 3 0.001d0) |
|---|
| 107 | (exp-err 3.0d0 0.001d0) |
|---|
| 108 | (exp-mult-err 3.0d0 0.001d0 23.0d0 0.001d0)) |
|---|
| 109 | |# |
|---|
| 110 | |
|---|
| 111 | (LISP-UNIT:DEFINE-TEST EXPONENTIAL-FUNCTIONS |
|---|
| 112 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 113 | (LIST 20.085536923187668d0 8.91977022163267d-15) |
|---|
| 114 | (MULTIPLE-VALUE-LIST (GSL-EXP 3.0d0))) |
|---|
| 115 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 116 | (LIST 1.0800340716201098d0 241 2.666751014771678d-13) |
|---|
| 117 | (MULTIPLE-VALUE-LIST (EXP-SCALED 555.0d0))) |
|---|
| 118 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 119 | (LIST 3.6535299896840335d44 8.355840218353793d30) |
|---|
| 120 | (MULTIPLE-VALUE-LIST (EXP-MULT 101.0d0 5.0d0))) |
|---|
| 121 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 122 | (LIST 1.0908344123363103d0 243 2.7201204352005766d-15) |
|---|
| 123 | (MULTIPLE-VALUE-LIST |
|---|
| 124 | (EXP-MULT-SCALED 555.0d0 101.0d0))) |
|---|
| 125 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 126 | (LIST 1.0000500016667085d-4 4.441114150507224d-20) |
|---|
| 127 | (MULTIPLE-VALUE-LIST (EXPM1 1.d-4))) |
|---|
| 128 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 129 | (LIST 1.0000500016667084d0 4.4411141505072235d-16) |
|---|
| 130 | (MULTIPLE-VALUE-LIST (EXPREL 1.d-4))) |
|---|
| 131 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 132 | (LIST 1.0003334166833362d0 4.442372766015162d-16) |
|---|
| 133 | (MULTIPLE-VALUE-LIST (EXPREL-2 0.001d0))) |
|---|
| 134 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 135 | (LIST 1.0002500500083344d0 2.665201526164121d-15) |
|---|
| 136 | (MULTIPLE-VALUE-LIST (EXPREL-N 3 0.001d0))) |
|---|
| 137 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 138 | (LIST 20.085536923187668d0 0.04017108054156605d0) |
|---|
| 139 | (MULTIPLE-VALUE-LIST (EXP-ERR 3.0d0 0.001d0))) |
|---|
| 140 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 141 | (LIST 461.9673492333164d0 0.4820528861567092d0) |
|---|
| 142 | (MULTIPLE-VALUE-LIST |
|---|
| 143 | (EXP-MULT-ERR 3.0d0 0.001d0 23.0d0 0.001d0)))) |
|---|
| 144 | |
|---|