Mercurial > emacs
annotate lisp/calc/calc-funcs.el @ 81918:06e5dde16893
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Mon, 16 Jul 2007 22:37:26 +0000 |
parents | 886906acf1e7 |
children | b98604865ea0 988f1edc9674 |
rev | line source |
---|---|
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1 ;;; calc-funcs.el --- well-known functions for Calc |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
2 |
64325
1db49616ce05
Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62442
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, |
75346 | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
5 |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
6 ;; Author: David Gillespie <daveg@synaptics.com> |
77465
1154f082efd9
Update maintainer's address.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
76595
diff
changeset
|
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com> |
40785 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
76595
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
14 ;; any later version. |
40785 | 15 |
76595
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
19 ;; GNU General Public License for more details. |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
20 |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
24 ;; Boston, MA 02110-1301, USA. |
40785 | 25 |
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
26 ;;; Commentary: |
40785 | 27 |
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
28 ;;; Code: |
40785 | 29 |
30 ;; This file is autoloaded from calc-ext.el. | |
58656
c60e5eef3cde
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
31 |
40785 | 32 (require 'calc-ext) |
33 (require 'calc-macs) | |
34 | |
35 (defun calc-inc-gamma (arg) | |
36 (interactive "P") | |
37 (calc-slow-wrapper | |
38 (if (calc-is-inverse) | |
39 (if (calc-is-hyperbolic) | |
40 (calc-binary-op "gamG" 'calcFunc-gammaG arg) | |
41 (calc-binary-op "gamQ" 'calcFunc-gammaQ arg)) | |
42 (if (calc-is-hyperbolic) | |
43 (calc-binary-op "gamg" 'calcFunc-gammag arg) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
44 (calc-binary-op "gamP" 'calcFunc-gammaP arg))))) |
40785 | 45 |
46 (defun calc-erf (arg) | |
47 (interactive "P") | |
48 (calc-slow-wrapper | |
49 (if (calc-is-inverse) | |
50 (calc-unary-op "erfc" 'calcFunc-erfc arg) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
51 (calc-unary-op "erf" 'calcFunc-erf arg)))) |
40785 | 52 |
53 (defun calc-erfc (arg) | |
54 (interactive "P") | |
55 (calc-invert-func) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
56 (calc-erf arg)) |
40785 | 57 |
58 (defun calc-beta (arg) | |
59 (interactive "P") | |
60 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
61 (calc-binary-op "beta" 'calcFunc-beta arg))) |
40785 | 62 |
63 (defun calc-inc-beta () | |
64 (interactive) | |
65 (calc-slow-wrapper | |
66 (if (calc-is-hyperbolic) | |
67 (calc-enter-result 3 "betB" (cons 'calcFunc-betaB (calc-top-list-n 3))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
68 (calc-enter-result 3 "betI" (cons 'calcFunc-betaI (calc-top-list-n 3)))))) |
40785 | 69 |
70 (defun calc-bessel-J (arg) | |
71 (interactive "P") | |
72 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
73 (calc-binary-op "besJ" 'calcFunc-besJ arg))) |
40785 | 74 |
75 (defun calc-bessel-Y (arg) | |
76 (interactive "P") | |
77 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
78 (calc-binary-op "besY" 'calcFunc-besY arg))) |
40785 | 79 |
80 (defun calc-bernoulli-number (arg) | |
81 (interactive "P") | |
82 (calc-slow-wrapper | |
83 (if (calc-is-hyperbolic) | |
84 (calc-binary-op "bern" 'calcFunc-bern arg) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
85 (calc-unary-op "bern" 'calcFunc-bern arg)))) |
40785 | 86 |
87 (defun calc-euler-number (arg) | |
88 (interactive "P") | |
89 (calc-slow-wrapper | |
90 (if (calc-is-hyperbolic) | |
91 (calc-binary-op "eulr" 'calcFunc-euler arg) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
92 (calc-unary-op "eulr" 'calcFunc-euler arg)))) |
40785 | 93 |
94 (defun calc-stirling-number (arg) | |
95 (interactive "P") | |
96 (calc-slow-wrapper | |
97 (if (calc-is-hyperbolic) | |
98 (calc-binary-op "str2" 'calcFunc-stir2 arg) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
99 (calc-binary-op "str1" 'calcFunc-stir1 arg)))) |
40785 | 100 |
101 (defun calc-utpb () | |
102 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
103 (calc-prob-dist "b" 3)) |
40785 | 104 |
105 (defun calc-utpc () | |
106 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
107 (calc-prob-dist "c" 2)) |
40785 | 108 |
109 (defun calc-utpf () | |
110 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
111 (calc-prob-dist "f" 3)) |
40785 | 112 |
113 (defun calc-utpn () | |
114 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
115 (calc-prob-dist "n" 3)) |
40785 | 116 |
117 (defun calc-utpp () | |
118 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
119 (calc-prob-dist "p" 2)) |
40785 | 120 |
121 (defun calc-utpt () | |
122 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
123 (calc-prob-dist "t" 2)) |
40785 | 124 |
125 (defun calc-prob-dist (letter nargs) | |
126 (calc-slow-wrapper | |
127 (if (calc-is-inverse) | |
128 (calc-enter-result nargs (concat "ltp" letter) | |
129 (append (list (intern (concat "calcFunc-ltp" letter)) | |
130 (calc-top-n 1)) | |
131 (calc-top-list-n (1- nargs) 2))) | |
132 (calc-enter-result nargs (concat "utp" letter) | |
133 (append (list (intern (concat "calcFunc-utp" letter)) | |
134 (calc-top-n 1)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
135 (calc-top-list-n (1- nargs) 2)))))) |
40785 | 136 |
137 | |
138 | |
139 | |
140 ;;; Sources: Numerical Recipes, Press et al; | |
141 ;;; Handbook of Mathematical Functions, Abramowitz & Stegun. | |
142 | |
143 | |
144 ;;; Gamma function. | |
145 | |
146 (defun calcFunc-gamma (x) | |
147 (or (math-numberp x) (math-reject-arg x 'numberp)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
148 (calcFunc-fact (math-add x -1))) |
40785 | 149 |
81745
886906acf1e7
(math-gammap1-raw): Add docstring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81548
diff
changeset
|
150 (defun math-gammap1-raw (x &optional fprec nfprec) |
886906acf1e7
(math-gammap1-raw): Add docstring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81548
diff
changeset
|
151 "Compute gamma(1+X) to the appropriate precision." |
40785 | 152 (or fprec |
153 (setq fprec (math-float calc-internal-prec) | |
154 nfprec (math-float (- calc-internal-prec)))) | |
155 (cond ((math-lessp-float (calcFunc-re x) fprec) | |
156 (if (math-lessp-float (calcFunc-re x) nfprec) | |
157 (math-neg (math-div | |
158 (math-pi) | |
159 (math-mul (math-gammap1-raw | |
160 (math-add (math-neg x) | |
161 '(float -1 0)) | |
162 fprec nfprec) | |
163 (math-sin-raw | |
164 (math-mul (math-pi) x))))) | |
165 (let ((xplus1 (math-add x '(float 1 0)))) | |
166 (math-div (math-gammap1-raw xplus1 fprec nfprec) xplus1)))) | |
167 ((and (math-realp x) | |
168 (math-lessp-float '(float 736276 0) x)) | |
169 (math-overflow)) | |
170 (t ; re(x) now >= 10.0 | |
171 (let ((xinv (math-div 1 x)) | |
172 (lnx (math-ln-raw x))) | |
173 (math-mul (math-sqrt-two-pi) | |
174 (math-exp-raw | |
175 (math-gamma-series | |
176 (math-sub (math-mul (math-add x '(float 5 -1)) | |
177 lnx) | |
178 x) | |
179 xinv | |
180 (math-sqr xinv) | |
181 '(float 0 0) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
182 2))))))) |
40785 | 183 |
184 (defun math-gamma-series (sum x xinvsqr oterm n) | |
185 (math-working "gamma" sum) | |
186 (let* ((bn (math-bernoulli-number n)) | |
187 (term (math-mul (math-div-float (math-float (nth 1 bn)) | |
188 (math-float (* (nth 2 bn) | |
189 (* n (1- n))))) | |
190 x)) | |
191 (next (math-add sum term))) | |
192 (if (math-nearly-equal sum next) | |
193 next | |
194 (if (> n (* 2 calc-internal-prec)) | |
195 (progn | |
196 ;; Need this because series eventually diverges for large enough n. | |
197 (calc-record-why | |
198 "*Gamma computation stopped early, not all digits may be valid") | |
199 next) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
200 (math-gamma-series next (math-mul x xinvsqr) xinvsqr term (+ n 2)))))) |
40785 | 201 |
202 | |
203 ;;; Incomplete gamma function. | |
204 | |
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
205 (defvar math-current-gamma-value nil) |
40785 | 206 (defun calcFunc-gammaP (a x) |
207 (if (equal x '(var inf var-inf)) | |
208 '(float 1 0) | |
209 (math-inexact-result) | |
210 (or (Math-numberp a) (math-reject-arg a 'numberp)) | |
211 (or (math-numberp x) (math-reject-arg x 'numberp)) | |
212 (if (and (math-num-integerp a) | |
213 (integerp (setq a (math-trunc a))) | |
214 (> a 0) (< a 20)) | |
215 (math-sub 1 (calcFunc-gammaQ a x)) | |
216 (let ((math-current-gamma-value (calcFunc-gamma a))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
217 (math-div (calcFunc-gammag a x) math-current-gamma-value))))) |
40785 | 218 |
219 (defun calcFunc-gammaQ (a x) | |
220 (if (equal x '(var inf var-inf)) | |
221 '(float 0 0) | |
222 (math-inexact-result) | |
223 (or (Math-numberp a) (math-reject-arg a 'numberp)) | |
224 (or (math-numberp x) (math-reject-arg x 'numberp)) | |
225 (if (and (math-num-integerp a) | |
226 (integerp (setq a (math-trunc a))) | |
227 (> a 0) (< a 20)) | |
228 (let ((n 0) | |
229 (sum '(float 1 0)) | |
230 (term '(float 1 0))) | |
231 (math-with-extra-prec 1 | |
232 (while (< (setq n (1+ n)) a) | |
233 (setq term (math-div (math-mul term x) n) | |
234 sum (math-add sum term)) | |
235 (math-working "gamma" sum)) | |
236 (math-mul sum (calcFunc-exp (math-neg x))))) | |
237 (let ((math-current-gamma-value (calcFunc-gamma a))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
238 (math-div (calcFunc-gammaG a x) math-current-gamma-value))))) |
40785 | 239 |
240 (defun calcFunc-gammag (a x) | |
241 (if (equal x '(var inf var-inf)) | |
242 (calcFunc-gamma a) | |
243 (math-inexact-result) | |
244 (or (Math-numberp a) (math-reject-arg a 'numberp)) | |
245 (or (Math-numberp x) (math-reject-arg x 'numberp)) | |
246 (math-with-extra-prec 2 | |
247 (setq a (math-float a)) | |
248 (setq x (math-float x)) | |
249 (if (or (math-negp (calcFunc-re a)) | |
250 (math-lessp-float (calcFunc-re x) | |
251 (math-add-float (calcFunc-re a) | |
252 '(float 1 0)))) | |
253 (math-inc-gamma-series a x) | |
254 (math-sub (or math-current-gamma-value (calcFunc-gamma a)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
255 (math-inc-gamma-cfrac a x)))))) |
40785 | 256 |
257 (defun calcFunc-gammaG (a x) | |
258 (if (equal x '(var inf var-inf)) | |
259 '(float 0 0) | |
260 (math-inexact-result) | |
261 (or (Math-numberp a) (math-reject-arg a 'numberp)) | |
262 (or (Math-numberp x) (math-reject-arg x 'numberp)) | |
263 (math-with-extra-prec 2 | |
264 (setq a (math-float a)) | |
265 (setq x (math-float x)) | |
266 (if (or (math-negp (calcFunc-re a)) | |
267 (math-lessp-float (calcFunc-re x) | |
268 (math-add-float (math-abs-approx a) | |
269 '(float 1 0)))) | |
270 (math-sub (or math-current-gamma-value (calcFunc-gamma a)) | |
271 (math-inc-gamma-series a x)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
272 (math-inc-gamma-cfrac a x))))) |
40785 | 273 |
274 (defun math-inc-gamma-series (a x) | |
275 (if (Math-zerop x) | |
276 '(float 0 0) | |
277 (math-mul (math-exp-raw (math-sub (math-mul a (math-ln-raw x)) x)) | |
278 (math-with-extra-prec 2 | |
279 (let ((start (math-div '(float 1 0) a))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
280 (math-inc-gamma-series-step start start a x)))))) |
40785 | 281 |
282 (defun math-inc-gamma-series-step (sum term a x) | |
283 (math-working "gamma" sum) | |
284 (setq a (math-add a '(float 1 0)) | |
285 term (math-div (math-mul term x) a)) | |
286 (let ((next (math-add sum term))) | |
287 (if (math-nearly-equal sum next) | |
288 next | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
289 (math-inc-gamma-series-step next term a x)))) |
40785 | 290 |
291 (defun math-inc-gamma-cfrac (a x) | |
292 (if (Math-zerop x) | |
293 (or math-current-gamma-value (calcFunc-gamma a)) | |
294 (math-mul (math-exp-raw (math-sub (math-mul a (math-ln-raw x)) x)) | |
295 (math-inc-gamma-cfrac-step '(float 1 0) x | |
296 '(float 0 0) '(float 1 0) | |
297 '(float 1 0) '(float 1 0) '(float 0 0) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
298 a x)))) |
40785 | 299 |
300 (defun math-inc-gamma-cfrac-step (a0 a1 b0 b1 n fac g a x) | |
301 (let ((ana (math-sub n a)) | |
302 (anf (math-mul n fac))) | |
303 (setq n (math-add n '(float 1 0)) | |
304 a0 (math-mul (math-add a1 (math-mul a0 ana)) fac) | |
305 b0 (math-mul (math-add b1 (math-mul b0 ana)) fac) | |
306 a1 (math-add (math-mul x a0) (math-mul anf a1)) | |
307 b1 (math-add (math-mul x b0) (math-mul anf b1))) | |
308 (if (math-zerop a1) | |
309 (math-inc-gamma-cfrac-step a0 a1 b0 b1 n fac g a x) | |
310 (setq fac (math-div '(float 1 0) a1)) | |
311 (let ((next (math-mul b1 fac))) | |
312 (math-working "gamma" next) | |
313 (if (math-nearly-equal next g) | |
314 next | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
315 (math-inc-gamma-cfrac-step a0 a1 b0 b1 n fac next a x)))))) |
40785 | 316 |
317 | |
318 ;;; Error function. | |
319 | |
320 (defun calcFunc-erf (x) | |
321 (if (equal x '(var inf var-inf)) | |
322 '(float 1 0) | |
323 (if (equal x '(neg (var inf var-inf))) | |
324 '(float -1 0) | |
325 (if (Math-zerop x) | |
326 x | |
327 (let ((math-current-gamma-value (math-sqrt-pi))) | |
328 (math-to-same-complex-quad | |
329 (math-div (calcFunc-gammag '(float 5 -1) | |
330 (math-sqr (math-to-complex-quad-one x))) | |
331 math-current-gamma-value) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
332 x)))))) |
40785 | 333 |
334 (defun calcFunc-erfc (x) | |
335 (if (equal x '(var inf var-inf)) | |
336 '(float 0 0) | |
337 (if (math-posp x) | |
338 (let ((math-current-gamma-value (math-sqrt-pi))) | |
339 (math-div (calcFunc-gammaG '(float 5 -1) (math-sqr x)) | |
340 math-current-gamma-value)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
341 (math-sub 1 (calcFunc-erf x))))) |
40785 | 342 |
343 (defun math-to-complex-quad-one (x) | |
344 (if (eq (car-safe x) 'polar) (setq x (math-complex x))) | |
345 (if (eq (car-safe x) 'cplx) | |
346 (list 'cplx (math-abs (nth 1 x)) (math-abs (nth 2 x))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
347 x)) |
40785 | 348 |
349 (defun math-to-same-complex-quad (x y) | |
350 (if (eq (car-safe y) 'cplx) | |
351 (if (eq (car-safe x) 'cplx) | |
352 (list 'cplx | |
353 (if (math-negp (nth 1 y)) (math-neg (nth 1 x)) (nth 1 x)) | |
354 (if (math-negp (nth 2 y)) (math-neg (nth 2 x)) (nth 2 x))) | |
355 (if (math-negp (nth 1 y)) (math-neg x) x)) | |
356 (if (math-negp y) | |
357 (if (eq (car-safe x) 'cplx) | |
358 (list 'cplx (math-neg (nth 1 x)) (nth 2 x)) | |
359 (math-neg x)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
360 x))) |
40785 | 361 |
362 | |
363 ;;; Beta function. | |
364 | |
365 (defun calcFunc-beta (a b) | |
366 (if (math-num-integerp a) | |
367 (let ((am (math-add a -1))) | |
368 (or (math-numberp b) (math-reject-arg b 'numberp)) | |
369 (math-div 1 (math-mul b (calcFunc-choose (math-add b am) am)))) | |
370 (if (math-num-integerp b) | |
371 (calcFunc-beta b a) | |
372 (math-div (math-mul (calcFunc-gamma a) (calcFunc-gamma b)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
373 (calcFunc-gamma (math-add a b)))))) |
40785 | 374 |
375 | |
376 ;;; Incomplete beta function. | |
377 | |
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
378 (defvar math-current-beta-value nil) |
40785 | 379 (defun calcFunc-betaI (x a b) |
380 (cond ((math-zerop x) | |
381 '(float 0 0)) | |
382 ((math-equal-int x 1) | |
383 '(float 1 0)) | |
384 ((or (math-zerop a) | |
385 (and (math-num-integerp a) | |
386 (math-negp a))) | |
387 (if (or (math-zerop b) | |
388 (and (math-num-integerp b) | |
389 (math-negp b))) | |
390 (math-reject-arg b 'range) | |
391 '(float 1 0))) | |
392 ((or (math-zerop b) | |
393 (and (math-num-integerp b) | |
394 (math-negp b))) | |
395 '(float 0 0)) | |
396 ((not (math-numberp a)) (math-reject-arg a 'numberp)) | |
397 ((not (math-numberp b)) (math-reject-arg b 'numberp)) | |
398 ((math-inexact-result)) | |
399 (t (let ((math-current-beta-value (calcFunc-beta a b))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
400 (math-div (calcFunc-betaB x a b) math-current-beta-value))))) |
40785 | 401 |
402 (defun calcFunc-betaB (x a b) | |
403 (cond | |
404 ((math-zerop x) | |
405 '(float 0 0)) | |
406 ((math-equal-int x 1) | |
407 (calcFunc-beta a b)) | |
408 ((not (math-numberp x)) (math-reject-arg x 'numberp)) | |
409 ((not (math-numberp a)) (math-reject-arg a 'numberp)) | |
410 ((not (math-numberp b)) (math-reject-arg b 'numberp)) | |
411 ((math-zerop a) (math-reject-arg a 'nonzerop)) | |
412 ((math-zerop b) (math-reject-arg b 'nonzerop)) | |
413 ((and (math-num-integerp b) | |
414 (if (math-negp b) | |
415 (math-reject-arg b 'range) | |
416 (Math-natnum-lessp (setq b (math-trunc b)) 20))) | |
417 (and calc-symbolic-mode (or (math-floatp a) (math-floatp b)) | |
418 (math-inexact-result)) | |
419 (math-mul | |
420 (math-with-extra-prec 2 | |
421 (let* ((i 0) | |
422 (term 1) | |
423 (sum (math-div term a))) | |
424 (while (< (setq i (1+ i)) b) | |
425 (setq term (math-mul (math-div (math-mul term (- i b)) i) x) | |
426 sum (math-add sum (math-div term (math-add a i)))) | |
427 (math-working "beta" sum)) | |
428 sum)) | |
429 (math-pow x a))) | |
430 ((and (math-num-integerp a) | |
431 (if (math-negp a) | |
432 (math-reject-arg a 'range) | |
433 (Math-natnum-lessp (setq a (math-trunc a)) 20))) | |
434 (math-sub (or math-current-beta-value (calcFunc-beta a b)) | |
435 (calcFunc-betaB (math-sub 1 x) b a))) | |
436 (t | |
437 (math-inexact-result) | |
438 (math-with-extra-prec 2 | |
439 (setq x (math-float x)) | |
440 (setq a (math-float a)) | |
441 (setq b (math-float b)) | |
442 (let ((bt (math-exp-raw (math-add (math-mul a (math-ln-raw x)) | |
443 (math-mul b (math-ln-raw | |
444 (math-sub '(float 1 0) | |
445 x))))))) | |
446 (if (Math-lessp x (math-div (math-add a '(float 1 0)) | |
447 (math-add (math-add a b) '(float 2 0)))) | |
448 (math-div (math-mul bt (math-beta-cfrac a b x)) a) | |
449 (math-sub (or math-current-beta-value (calcFunc-beta a b)) | |
450 (math-div (math-mul bt | |
451 (math-beta-cfrac b a (math-sub 1 x))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
452 b)))))))) |
40785 | 453 |
454 (defun math-beta-cfrac (a b x) | |
455 (let ((qab (math-add a b)) | |
456 (qap (math-add a '(float 1 0))) | |
457 (qam (math-add a '(float -1 0)))) | |
458 (math-beta-cfrac-step '(float 1 0) | |
459 (math-sub '(float 1 0) | |
460 (math-div (math-mul qab x) qap)) | |
461 '(float 1 0) '(float 1 0) | |
462 '(float 1 0) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
463 qab qap qam a b x))) |
40785 | 464 |
465 (defun math-beta-cfrac-step (az bz am bm m qab qap qam a b x) | |
466 (let* ((two-m (math-mul m '(float 2 0))) | |
467 (d (math-div (math-mul (math-mul (math-sub b m) m) x) | |
468 (math-mul (math-add qam two-m) (math-add a two-m)))) | |
469 (ap (math-add az (math-mul d am))) | |
470 (bp (math-add bz (math-mul d bm))) | |
471 (d2 (math-neg | |
472 (math-div (math-mul (math-mul (math-add a m) (math-add qab m)) x) | |
473 (math-mul (math-add qap two-m) (math-add a two-m))))) | |
474 (app (math-add ap (math-mul d2 az))) | |
475 (bpp (math-add bp (math-mul d2 bz))) | |
476 (next (math-div app bpp))) | |
477 (math-working "beta" next) | |
478 (if (math-nearly-equal next az) | |
479 next | |
480 (math-beta-cfrac-step next '(float 1 0) | |
481 (math-div ap bpp) (math-div bp bpp) | |
482 (math-add m '(float 1 0)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
483 qab qap qam a b x)))) |
40785 | 484 |
485 | |
486 ;;; Bessel functions. | |
487 | |
488 ;;; Should generalize this to handle arbitrary precision! | |
489 | |
490 (defun calcFunc-besJ (v x) | |
491 (or (math-numberp v) (math-reject-arg v 'numberp)) | |
492 (or (math-numberp x) (math-reject-arg x 'numberp)) | |
493 (let ((calc-internal-prec (min 8 calc-internal-prec))) | |
494 (math-with-extra-prec 3 | |
495 (setq x (math-float (math-normalize x))) | |
496 (setq v (math-float (math-normalize v))) | |
497 (cond ((math-zerop x) | |
498 (if (math-zerop v) | |
499 '(float 1 0) | |
500 '(float 0 0))) | |
501 ((math-inexact-result)) | |
502 ((not (math-num-integerp v)) | |
503 (let ((start (math-div 1 (calcFunc-fact v)))) | |
504 (math-mul (math-besJ-series start start | |
505 0 | |
506 (math-mul '(float -25 -2) | |
507 (math-sqr x)) | |
508 v) | |
509 (math-pow (math-div x 2) v)))) | |
510 ((math-negp (setq v (math-trunc v))) | |
511 (if (math-oddp v) | |
512 (math-neg (calcFunc-besJ (math-neg v) x)) | |
513 (calcFunc-besJ (math-neg v) x))) | |
514 ((eq v 0) | |
515 (math-besJ0 x)) | |
516 ((eq v 1) | |
517 (math-besJ1 x)) | |
518 ((Math-lessp v (math-abs-approx x)) | |
519 (let ((j 0) | |
520 (bjm (math-besJ0 x)) | |
521 (bj (math-besJ1 x)) | |
522 (two-over-x (math-div 2 x)) | |
523 bjp) | |
524 (while (< (setq j (1+ j)) v) | |
525 (setq bjp (math-sub (math-mul (math-mul j two-over-x) bj) | |
526 bjm) | |
527 bjm bj | |
528 bj bjp)) | |
529 bj)) | |
530 (t | |
531 (if (Math-lessp 100 v) (math-reject-arg v 'range)) | |
532 (let* ((j (logior (+ v (math-isqrt-small (* 40 v))) 1)) | |
533 (two-over-x (math-div 2 x)) | |
534 (jsum nil) | |
535 (bjp '(float 0 0)) | |
536 (sum '(float 0 0)) | |
537 (bj '(float 1 0)) | |
538 bjm ans) | |
539 (while (> (setq j (1- j)) 0) | |
540 (setq bjm (math-sub (math-mul (math-mul j two-over-x) bj) | |
541 bjp) | |
542 bjp bj | |
543 bj bjm) | |
544 (if (> (nth 2 (math-abs-approx bj)) 10) | |
545 (setq bj (math-mul bj '(float 1 -10)) | |
546 bjp (math-mul bjp '(float 1 -10)) | |
547 ans (and ans (math-mul ans '(float 1 -10))) | |
548 sum (math-mul sum '(float 1 -10)))) | |
549 (or (setq jsum (not jsum)) | |
550 (setq sum (math-add sum bj))) | |
551 (if (= j v) | |
552 (setq ans bjp))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
553 (math-div ans (math-sub (math-mul 2 sum) bj)))))))) |
40785 | 554 |
555 (defun math-besJ-series (sum term k zz vk) | |
556 (math-working "besJ" sum) | |
557 (setq k (1+ k) | |
558 vk (math-add 1 vk) | |
559 term (math-div (math-mul term zz) (math-mul k vk))) | |
560 (let ((next (math-add sum term))) | |
561 (if (math-nearly-equal next sum) | |
562 next | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
563 (math-besJ-series next term k zz vk)))) |
40785 | 564 |
565 (defun math-besJ0 (x &optional yflag) | |
566 (cond ((and (not yflag) (math-negp (calcFunc-re x))) | |
567 (math-besJ0 (math-neg x))) | |
568 ((Math-lessp '(float 8 0) (math-abs-approx x)) | |
569 (let* ((z (math-div '(float 8 0) x)) | |
570 (y (math-sqr z)) | |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
571 (xx (math-add x |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
572 (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
573 (math-read-number-simple "-0.785398164")))) |
40785 | 574 (a1 (math-poly-eval y |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
575 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
576 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
577 (math-read-number-simple "0.0000002093887211") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
578 (math-read-number-simple "-0.000002073370639") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
579 (math-read-number-simple "0.00002734510407") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
580 (math-read-number-simple "-0.001098628627") |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
581 '(float 1 0))))) |
40785 | 582 (a2 (math-poly-eval y |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
583 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
584 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
585 (math-read-number-simple "-0.0000000934935152") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
586 (math-read-number-simple "0.0000007621095161") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
587 (math-read-number-simple "-0.000006911147651") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
588 (math-read-number-simple "0.0001430488765") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
589 (math-read-number-simple "-0.01562499995"))))) |
40785 | 590 (sc (math-sin-cos-raw xx))) |
591 (if yflag | |
592 (setq sc (cons (math-neg (cdr sc)) (car sc)))) | |
593 (math-mul (math-sqrt | |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
594 (math-div (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
595 (math-read-number-simple "0.636619722")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
596 x)) |
40785 | 597 (math-sub (math-mul (cdr sc) a1) |
598 (math-mul (car sc) (math-mul z a2)))))) | |
599 (t | |
600 (let ((y (math-sqr x))) | |
601 (math-div (math-poly-eval y | |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
602 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
603 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
604 (math-read-number-simple "-184.9052456") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
605 (math-read-number-simple "77392.33017") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
606 (math-read-number-simple "-11214424.18") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
607 (math-read-number-simple "651619640.7") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
608 (math-read-number-simple "-13362590354.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
609 (math-read-number-simple "57568490574.0")))) |
40785 | 610 (math-poly-eval y |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
611 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
612 (list |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
613 '(float 1 0) |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
614 (math-read-number-simple "267.8532712") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
615 (math-read-number-simple "59272.64853") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
616 (math-read-number-simple "9494680.718") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
617 (math-read-number-simple "1029532985.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
618 (math-read-number-simple "57568490411.0"))))))))) |
40785 | 619 |
620 (defun math-besJ1 (x &optional yflag) | |
621 (cond ((and (math-negp (calcFunc-re x)) (not yflag)) | |
622 (math-neg (math-besJ1 (math-neg x)))) | |
623 ((Math-lessp '(float 8 0) (math-abs-approx x)) | |
624 (let* ((z (math-div '(float 8 0) x)) | |
625 (y (math-sqr z)) | |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
626 (xx (math-add x (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
627 (math-read-number-simple "-2.356194491")))) |
40785 | 628 (a1 (math-poly-eval y |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
629 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
630 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
631 (math-read-number-simple "-0.000000240337019") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
632 (math-read-number-simple "0.000002457520174") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
633 (math-read-number-simple "-0.00003516396496") |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
634 '(float 183105 -8) |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
635 '(float 1 0))))) |
40785 | 636 (a2 (math-poly-eval y |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
637 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
638 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
639 (math-read-number-simple "0.000000105787412") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
640 (math-read-number-simple "-0.00000088228987") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
641 (math-read-number-simple "0.000008449199096") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
642 (math-read-number-simple "-0.0002002690873") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
643 (math-read-number-simple "0.04687499995"))))) |
40785 | 644 (sc (math-sin-cos-raw xx))) |
645 (if yflag | |
646 (setq sc (cons (math-neg (cdr sc)) (car sc))) | |
647 (if (math-negp x) | |
648 (setq sc (cons (math-neg (car sc)) (math-neg (cdr sc)))))) | |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
649 (math-mul (math-sqrt (math-div |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
650 (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
651 (math-read-number-simple "0.636619722")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
652 x)) |
40785 | 653 (math-sub (math-mul (cdr sc) a1) |
654 (math-mul (car sc) (math-mul z a2)))))) | |
655 (t | |
656 (let ((y (math-sqr x))) | |
657 (math-mul | |
658 x | |
659 (math-div (math-poly-eval y | |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
660 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
661 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
662 (math-read-number-simple "-30.16036606") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
663 (math-read-number-simple "15704.4826") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
664 (math-read-number-simple "-2972611.439") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
665 (math-read-number-simple "242396853.1") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
666 (math-read-number-simple "-7895059235.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
667 (math-read-number-simple "72362614232.0")))) |
40785 | 668 (math-poly-eval y |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
669 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
670 (list |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
671 '(float 1 0) |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
672 (math-read-number-simple "376.9991397") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
673 (math-read-number-simple "99447.43394") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
674 (math-read-number-simple "18583304.74") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
675 (math-read-number-simple "2300535178.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
676 (math-read-number-simple "144725228442.0")))))))))) |
40785 | 677 |
678 (defun calcFunc-besY (v x) | |
679 (math-inexact-result) | |
680 (or (math-numberp v) (math-reject-arg v 'numberp)) | |
681 (or (math-numberp x) (math-reject-arg x 'numberp)) | |
682 (let ((calc-internal-prec (min 8 calc-internal-prec))) | |
683 (math-with-extra-prec 3 | |
684 (setq x (math-float (math-normalize x))) | |
685 (setq v (math-float (math-normalize v))) | |
686 (cond ((not (math-num-integerp v)) | |
687 (let ((sc (math-sin-cos-raw (math-mul v (math-pi))))) | |
688 (math-div (math-sub (math-mul (calcFunc-besJ v x) (cdr sc)) | |
689 (calcFunc-besJ (math-neg v) x)) | |
690 (car sc)))) | |
691 ((math-negp (setq v (math-trunc v))) | |
692 (if (math-oddp v) | |
693 (math-neg (calcFunc-besY (math-neg v) x)) | |
694 (calcFunc-besY (math-neg v) x))) | |
695 ((eq v 0) | |
696 (math-besY0 x)) | |
697 ((eq v 1) | |
698 (math-besY1 x)) | |
699 (t | |
700 (let ((j 0) | |
701 (bym (math-besY0 x)) | |
702 (by (math-besY1 x)) | |
703 (two-over-x (math-div 2 x)) | |
704 byp) | |
705 (while (< (setq j (1+ j)) v) | |
706 (setq byp (math-sub (math-mul (math-mul j two-over-x) by) | |
707 bym) | |
708 bym by | |
709 by byp)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
710 by)))))) |
40785 | 711 |
712 (defun math-besY0 (x) | |
713 (cond ((Math-lessp (math-abs-approx x) '(float 8 0)) | |
714 (let ((y (math-sqr x))) | |
715 (math-add | |
716 (math-div (math-poly-eval y | |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
717 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
718 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
719 (math-read-number-simple "228.4622733") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
720 (math-read-number-simple "-86327.92757") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
721 (math-read-number-simple "10879881.29") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
722 (math-read-number-simple "-512359803.6") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
723 (math-read-number-simple "7062834065.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
724 (math-read-number-simple "-2957821389.0")))) |
40785 | 725 (math-poly-eval y |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
726 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
727 (list |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
728 '(float 1 0) |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
729 (math-read-number-simple "226.1030244") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
730 (math-read-number-simple "47447.2647") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
731 (math-read-number-simple "7189466.438") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
732 (math-read-number-simple "745249964.8") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
733 (math-read-number-simple "40076544269.0"))))) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
734 (math-mul (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
735 (math-read-number-simple "0.636619772")) |
40785 | 736 (math-mul (math-besJ0 x) (math-ln-raw x)))))) |
737 ((math-negp (calcFunc-re x)) | |
738 (math-add (math-besJ0 (math-neg x) t) | |
739 (math-mul '(cplx 0 2) | |
740 (math-besJ0 (math-neg x))))) | |
741 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
742 (math-besJ0 x t)))) |
40785 | 743 |
744 (defun math-besY1 (x) | |
745 (cond ((Math-lessp (math-abs-approx x) '(float 8 0)) | |
746 (let ((y (math-sqr x))) | |
747 (math-add | |
748 (math-mul | |
749 x | |
750 (math-div (math-poly-eval y | |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
751 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
752 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
753 (math-read-number-simple "8511.937935") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
754 (math-read-number-simple "-4237922.726") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
755 (math-read-number-simple "734926455.1") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
756 (math-read-number-simple "-51534381390.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
757 (math-read-number-simple "1275274390000.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
758 (math-read-number-simple "-4900604943000.0")))) |
40785 | 759 (math-poly-eval y |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
760 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
761 (list |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
762 '(float 1 0) |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
763 (math-read-number-simple "354.9632885") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
764 (math-read-number-simple "102042.605") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
765 (math-read-number-simple "22459040.02") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
766 (math-read-number-simple "3733650367.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
767 (math-read-number-simple "424441966400.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
768 (math-read-number-simple "24995805700000.0")))))) |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
769 (math-mul (eval-when-compile (math-read-number-simple "0.636619772")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
770 (math-sub (math-mul (math-besJ1 x) (math-ln-raw x)) |
40785 | 771 (math-div 1 x)))))) |
772 ((math-negp (calcFunc-re x)) | |
773 (math-neg | |
774 (math-add (math-besJ1 (math-neg x) t) | |
775 (math-mul '(cplx 0 2) | |
776 (math-besJ1 (math-neg x)))))) | |
777 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
778 (math-besJ1 x t)))) |
40785 | 779 |
780 (defun math-poly-eval (x coefs) | |
781 (let ((accum (car coefs))) | |
782 (while (setq coefs (cdr coefs)) | |
783 (setq accum (math-add (car coefs) (math-mul accum x)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
784 accum)) |
40785 | 785 |
786 | |
787 ;;;; Bernoulli and Euler polynomials and numbers. | |
788 | |
789 (defun calcFunc-bern (n &optional x) | |
790 (if (and x (not (math-zerop x))) | |
791 (if (and calc-symbolic-mode (math-floatp x)) | |
792 (math-inexact-result) | |
793 (math-build-polynomial-expr (math-bernoulli-coefs n) x)) | |
794 (or (math-num-natnump n) (math-reject-arg n 'natnump)) | |
795 (if (consp n) | |
796 (progn | |
797 (math-inexact-result) | |
798 (math-float (math-bernoulli-number (math-trunc n)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
799 (math-bernoulli-number n)))) |
40785 | 800 |
801 (defun calcFunc-euler (n &optional x) | |
802 (or (math-num-natnump n) (math-reject-arg n 'natnump)) | |
803 (if x | |
804 (let* ((n1 (math-add n 1)) | |
805 (coefs (math-bernoulli-coefs n1)) | |
806 (fac (math-div (math-pow 2 n1) n1)) | |
807 (k -1) | |
808 (x1 (math-div (math-add x 1) 2)) | |
809 (x2 (math-div x 2))) | |
810 (if (math-numberp x) | |
811 (if (and calc-symbolic-mode (math-floatp x)) | |
812 (math-inexact-result) | |
813 (math-mul fac | |
814 (math-sub (math-build-polynomial-expr coefs x1) | |
815 (math-build-polynomial-expr coefs x2)))) | |
816 (calcFunc-collect | |
817 (math-reduce-vec | |
818 'math-add | |
819 (cons 'vec | |
820 (mapcar (function | |
821 (lambda (c) | |
822 (setq k (1+ k)) | |
823 (math-mul (math-mul fac c) | |
824 (math-sub (math-pow x1 k) | |
825 (math-pow x2 k))))) | |
826 coefs))) | |
827 x))) | |
828 (math-mul (math-pow 2 n) | |
829 (if (consp n) | |
830 (progn | |
831 (math-inexact-result) | |
832 (calcFunc-euler n '(float 5 -1))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
833 (calcFunc-euler n '(frac 1 2)))))) |
40785 | 834 |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
835 (defvar math-bernoulli-b-cache |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
836 (eval-when-compile |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
837 (list |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
838 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
839 -174611 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
840 (math-read-number-simple "802857662698291200000")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
841 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
842 43867 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
843 (math-read-number-simple "5109094217170944000")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
844 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
845 -3617 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
846 (math-read-number-simple "10670622842880000")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
847 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
848 1 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
849 (math-read-number-simple "74724249600")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
850 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
851 -691 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
852 (math-read-number-simple "1307674368000")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
853 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
854 1 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
855 (math-read-number-simple "47900160")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
856 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
857 -1 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
858 (math-read-number-simple "1209600")) |
81542
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
859 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
860 1 |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
861 30240) |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
862 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
863 -1 |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
864 720) |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
865 (list 'frac |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
866 1 |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
867 12) |
1c7ac4170c9d
(math-besJ0,math-besJ1,math-besY0,math-besY1,math-bernoulli-b-cache):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
868 1 ))) |
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
869 |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
870 (defvar math-bernoulli-B-cache '((frac -174611 330) (frac 43867 798) |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
871 (frac -3617 510) (frac 7 6) (frac -691 2730) |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
872 (frac 5 66) (frac -1 30) (frac 1 42) |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
873 (frac -1 30) (frac 1 6) 1 )) |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
874 |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
875 (defvar math-bernoulli-cache-size 11) |
40785 | 876 (defun math-bernoulli-coefs (n) |
877 (let* ((coefs (list (calcFunc-bern n))) | |
878 (nn (math-trunc n)) | |
879 (k nn) | |
880 (term nn) | |
881 coef | |
882 (calc-prefer-frac (or (integerp n) calc-prefer-frac))) | |
883 (while (>= (setq k (1- k)) 0) | |
884 (setq term (math-div term (- nn k)) | |
885 coef (math-mul term (math-bernoulli-number k)) | |
886 coefs (cons (if (consp n) (math-float coef) coef) coefs) | |
887 term (math-mul term k))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
888 (nreverse coefs))) |
40785 | 889 |
890 (defun math-bernoulli-number (n) | |
891 (if (= (% n 2) 1) | |
892 (if (= n 1) | |
893 '(frac -1 2) | |
894 0) | |
895 (setq n (/ n 2)) | |
896 (while (>= n math-bernoulli-cache-size) | |
897 (let* ((sum 0) | |
898 (nk 1) ; nk = n-k+1 | |
899 (fact 1) ; fact = (n-k+1)! | |
900 ofact | |
901 (p math-bernoulli-b-cache) | |
902 (calc-prefer-frac t)) | |
903 (math-working "bernoulli B" (* 2 math-bernoulli-cache-size)) | |
904 (while p | |
905 (setq nk (+ nk 2) | |
906 ofact fact | |
907 fact (math-mul fact (* nk (1- nk))) | |
908 sum (math-add sum (math-div (car p) fact)) | |
909 p (cdr p))) | |
910 (setq ofact (math-mul ofact (1- nk)) | |
911 sum (math-sub (math-div '(frac 1 2) ofact) sum) | |
912 math-bernoulli-b-cache (cons sum math-bernoulli-b-cache) | |
913 math-bernoulli-B-cache (cons (math-mul sum ofact) | |
914 math-bernoulli-B-cache) | |
915 math-bernoulli-cache-size (1+ math-bernoulli-cache-size)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
916 (nth (- math-bernoulli-cache-size n 1) math-bernoulli-B-cache))) |
40785 | 917 |
918 ;;; Bn = n! bn | |
919 ;;; bn = - sum_k=0^n-1 bk / (n-k+1)! | |
920 | |
921 ;;; A faster method would be to use "tangent numbers", c.f., Concrete | |
922 ;;; Mathematics pg. 273. | |
923 | |
924 | |
925 ;;; Probability distributions. | |
926 | |
927 ;;; Binomial. | |
928 (defun calcFunc-utpb (x n p) | |
929 (if math-expand-formulas | |
930 (math-normalize (list 'calcFunc-betaI p x (list '+ (list '- n x) 1))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
931 (calcFunc-betaI p x (math-add (math-sub n x) 1)))) |
40785 | 932 (put 'calcFunc-utpb 'math-expandable t) |
933 | |
934 (defun calcFunc-ltpb (x n p) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
935 (math-sub 1 (calcFunc-utpb x n p))) |
40785 | 936 (put 'calcFunc-ltpb 'math-expandable t) |
937 | |
938 ;;; Chi-square. | |
939 (defun calcFunc-utpc (chisq v) | |
940 (if math-expand-formulas | |
941 (math-normalize (list 'calcFunc-gammaQ (list '/ v 2) (list '/ chisq 2))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
942 (calcFunc-gammaQ (math-div v 2) (math-div chisq 2)))) |
40785 | 943 (put 'calcFunc-utpc 'math-expandable t) |
944 | |
945 (defun calcFunc-ltpc (chisq v) | |
946 (if math-expand-formulas | |
947 (math-normalize (list 'calcFunc-gammaP (list '/ v 2) (list '/ chisq 2))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
948 (calcFunc-gammaP (math-div v 2) (math-div chisq 2)))) |
40785 | 949 (put 'calcFunc-ltpc 'math-expandable t) |
950 | |
951 ;;; F-distribution. | |
952 (defun calcFunc-utpf (f v1 v2) | |
953 (if math-expand-formulas | |
954 (math-normalize (list 'calcFunc-betaI | |
955 (list '/ v2 (list '+ v2 (list '* v1 f))) | |
956 (list '/ v2 2) | |
957 (list '/ v1 2))) | |
958 (calcFunc-betaI (math-div v2 (math-add v2 (math-mul v1 f))) | |
959 (math-div v2 2) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
960 (math-div v1 2)))) |
40785 | 961 (put 'calcFunc-utpf 'math-expandable t) |
962 | |
963 (defun calcFunc-ltpf (f v1 v2) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
964 (math-sub 1 (calcFunc-utpf f v1 v2))) |
40785 | 965 (put 'calcFunc-ltpf 'math-expandable t) |
966 | |
967 ;;; Normal. | |
968 (defun calcFunc-utpn (x mean sdev) | |
969 (if math-expand-formulas | |
970 (math-normalize | |
971 (list '/ | |
972 (list '+ 1 | |
973 (list 'calcFunc-erf | |
974 (list '/ (list '- mean x) | |
975 (list '* sdev (list 'calcFunc-sqrt 2))))) | |
976 2)) | |
977 (math-mul (math-add '(float 1 0) | |
978 (calcFunc-erf | |
979 (math-div (math-sub mean x) | |
980 (math-mul sdev (math-sqrt-2))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
981 '(float 5 -1)))) |
40785 | 982 (put 'calcFunc-utpn 'math-expandable t) |
983 | |
984 (defun calcFunc-ltpn (x mean sdev) | |
985 (if math-expand-formulas | |
986 (math-normalize | |
987 (list '/ | |
988 (list '+ 1 | |
989 (list 'calcFunc-erf | |
990 (list '/ (list '- x mean) | |
991 (list '* sdev (list 'calcFunc-sqrt 2))))) | |
992 2)) | |
993 (math-mul (math-add '(float 1 0) | |
994 (calcFunc-erf | |
995 (math-div (math-sub x mean) | |
996 (math-mul sdev (math-sqrt-2))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
997 '(float 5 -1)))) |
40785 | 998 (put 'calcFunc-ltpn 'math-expandable t) |
999 | |
1000 ;;; Poisson. | |
1001 (defun calcFunc-utpp (n x) | |
1002 (if math-expand-formulas | |
1003 (math-normalize (list 'calcFunc-gammaP x n)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1004 (calcFunc-gammaP x n))) |
40785 | 1005 (put 'calcFunc-utpp 'math-expandable t) |
1006 | |
1007 (defun calcFunc-ltpp (n x) | |
1008 (if math-expand-formulas | |
1009 (math-normalize (list 'calcFunc-gammaQ x n)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1010 (calcFunc-gammaQ x n))) |
40785 | 1011 (put 'calcFunc-ltpp 'math-expandable t) |
1012 | |
1013 ;;; Student's t. (As defined in Abramowitz & Stegun and Numerical Recipes.) | |
1014 (defun calcFunc-utpt (tt v) | |
1015 (if math-expand-formulas | |
1016 (math-normalize (list 'calcFunc-betaI | |
1017 (list '/ v (list '+ v (list '^ tt 2))) | |
1018 (list '/ v 2) | |
1019 '(float 5 -1))) | |
1020 (calcFunc-betaI (math-div v (math-add v (math-sqr tt))) | |
1021 (math-div v 2) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1022 '(float 5 -1)))) |
40785 | 1023 (put 'calcFunc-utpt 'math-expandable t) |
1024 | |
1025 (defun calcFunc-ltpt (tt v) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1026 (math-sub 1 (calcFunc-utpt tt v))) |
40785 | 1027 (put 'calcFunc-ltpt 'math-expandable t) |
1028 | |
58656
c60e5eef3cde
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1029 (provide 'calc-funcs) |
40785 | 1030 |
52401 | 1031 ;;; arch-tag: 421ddb7a-550f-4dda-a31c-06638ebfc43a |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1032 ;;; calc-funcs.el ends here |