Mercurial > emacs
annotate lisp/calc/calc-funcs.el @ 81668:5cba81c25d1d
*** empty log message ***
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Fri, 29 Jun 2007 07:32:59 +0000 |
parents | 334bfc4cc092 |
children | 886906acf1e7 |
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 |
150 (defun math-gammap1-raw (x &optional fprec nfprec) ; compute gamma(1 + x) | |
151 (or fprec | |
152 (setq fprec (math-float calc-internal-prec) | |
153 nfprec (math-float (- calc-internal-prec)))) | |
154 (cond ((math-lessp-float (calcFunc-re x) fprec) | |
155 (if (math-lessp-float (calcFunc-re x) nfprec) | |
156 (math-neg (math-div | |
157 (math-pi) | |
158 (math-mul (math-gammap1-raw | |
159 (math-add (math-neg x) | |
160 '(float -1 0)) | |
161 fprec nfprec) | |
162 (math-sin-raw | |
163 (math-mul (math-pi) x))))) | |
164 (let ((xplus1 (math-add x '(float 1 0)))) | |
165 (math-div (math-gammap1-raw xplus1 fprec nfprec) xplus1)))) | |
166 ((and (math-realp x) | |
167 (math-lessp-float '(float 736276 0) x)) | |
168 (math-overflow)) | |
169 (t ; re(x) now >= 10.0 | |
170 (let ((xinv (math-div 1 x)) | |
171 (lnx (math-ln-raw x))) | |
172 (math-mul (math-sqrt-two-pi) | |
173 (math-exp-raw | |
174 (math-gamma-series | |
175 (math-sub (math-mul (math-add x '(float 5 -1)) | |
176 lnx) | |
177 x) | |
178 xinv | |
179 (math-sqr xinv) | |
180 '(float 0 0) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
181 2))))))) |
40785 | 182 |
183 (defun math-gamma-series (sum x xinvsqr oterm n) | |
184 (math-working "gamma" sum) | |
185 (let* ((bn (math-bernoulli-number n)) | |
186 (term (math-mul (math-div-float (math-float (nth 1 bn)) | |
187 (math-float (* (nth 2 bn) | |
188 (* n (1- n))))) | |
189 x)) | |
190 (next (math-add sum term))) | |
191 (if (math-nearly-equal sum next) | |
192 next | |
193 (if (> n (* 2 calc-internal-prec)) | |
194 (progn | |
195 ;; Need this because series eventually diverges for large enough n. | |
196 (calc-record-why | |
197 "*Gamma computation stopped early, not all digits may be valid") | |
198 next) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
199 (math-gamma-series next (math-mul x xinvsqr) xinvsqr term (+ n 2)))))) |
40785 | 200 |
201 | |
202 ;;; Incomplete gamma function. | |
203 | |
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
204 (defvar math-current-gamma-value nil) |
40785 | 205 (defun calcFunc-gammaP (a x) |
206 (if (equal x '(var inf var-inf)) | |
207 '(float 1 0) | |
208 (math-inexact-result) | |
209 (or (Math-numberp a) (math-reject-arg a 'numberp)) | |
210 (or (math-numberp x) (math-reject-arg x 'numberp)) | |
211 (if (and (math-num-integerp a) | |
212 (integerp (setq a (math-trunc a))) | |
213 (> a 0) (< a 20)) | |
214 (math-sub 1 (calcFunc-gammaQ a x)) | |
215 (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
|
216 (math-div (calcFunc-gammag a x) math-current-gamma-value))))) |
40785 | 217 |
218 (defun calcFunc-gammaQ (a x) | |
219 (if (equal x '(var inf var-inf)) | |
220 '(float 0 0) | |
221 (math-inexact-result) | |
222 (or (Math-numberp a) (math-reject-arg a 'numberp)) | |
223 (or (math-numberp x) (math-reject-arg x 'numberp)) | |
224 (if (and (math-num-integerp a) | |
225 (integerp (setq a (math-trunc a))) | |
226 (> a 0) (< a 20)) | |
227 (let ((n 0) | |
228 (sum '(float 1 0)) | |
229 (term '(float 1 0))) | |
230 (math-with-extra-prec 1 | |
231 (while (< (setq n (1+ n)) a) | |
232 (setq term (math-div (math-mul term x) n) | |
233 sum (math-add sum term)) | |
234 (math-working "gamma" sum)) | |
235 (math-mul sum (calcFunc-exp (math-neg x))))) | |
236 (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
|
237 (math-div (calcFunc-gammaG a x) math-current-gamma-value))))) |
40785 | 238 |
239 (defun calcFunc-gammag (a x) | |
240 (if (equal x '(var inf var-inf)) | |
241 (calcFunc-gamma a) | |
242 (math-inexact-result) | |
243 (or (Math-numberp a) (math-reject-arg a 'numberp)) | |
244 (or (Math-numberp x) (math-reject-arg x 'numberp)) | |
245 (math-with-extra-prec 2 | |
246 (setq a (math-float a)) | |
247 (setq x (math-float x)) | |
248 (if (or (math-negp (calcFunc-re a)) | |
249 (math-lessp-float (calcFunc-re x) | |
250 (math-add-float (calcFunc-re a) | |
251 '(float 1 0)))) | |
252 (math-inc-gamma-series a x) | |
253 (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
|
254 (math-inc-gamma-cfrac a x)))))) |
40785 | 255 |
256 (defun calcFunc-gammaG (a x) | |
257 (if (equal x '(var inf var-inf)) | |
258 '(float 0 0) | |
259 (math-inexact-result) | |
260 (or (Math-numberp a) (math-reject-arg a 'numberp)) | |
261 (or (Math-numberp x) (math-reject-arg x 'numberp)) | |
262 (math-with-extra-prec 2 | |
263 (setq a (math-float a)) | |
264 (setq x (math-float x)) | |
265 (if (or (math-negp (calcFunc-re a)) | |
266 (math-lessp-float (calcFunc-re x) | |
267 (math-add-float (math-abs-approx a) | |
268 '(float 1 0)))) | |
269 (math-sub (or math-current-gamma-value (calcFunc-gamma a)) | |
270 (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
|
271 (math-inc-gamma-cfrac a x))))) |
40785 | 272 |
273 (defun math-inc-gamma-series (a x) | |
274 (if (Math-zerop x) | |
275 '(float 0 0) | |
276 (math-mul (math-exp-raw (math-sub (math-mul a (math-ln-raw x)) x)) | |
277 (math-with-extra-prec 2 | |
278 (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
|
279 (math-inc-gamma-series-step start start a x)))))) |
40785 | 280 |
281 (defun math-inc-gamma-series-step (sum term a x) | |
282 (math-working "gamma" sum) | |
283 (setq a (math-add a '(float 1 0)) | |
284 term (math-div (math-mul term x) a)) | |
285 (let ((next (math-add sum term))) | |
286 (if (math-nearly-equal sum next) | |
287 next | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
288 (math-inc-gamma-series-step next term a x)))) |
40785 | 289 |
290 (defun math-inc-gamma-cfrac (a x) | |
291 (if (Math-zerop x) | |
292 (or math-current-gamma-value (calcFunc-gamma a)) | |
293 (math-mul (math-exp-raw (math-sub (math-mul a (math-ln-raw x)) x)) | |
294 (math-inc-gamma-cfrac-step '(float 1 0) x | |
295 '(float 0 0) '(float 1 0) | |
296 '(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
|
297 a x)))) |
40785 | 298 |
299 (defun math-inc-gamma-cfrac-step (a0 a1 b0 b1 n fac g a x) | |
300 (let ((ana (math-sub n a)) | |
301 (anf (math-mul n fac))) | |
302 (setq n (math-add n '(float 1 0)) | |
303 a0 (math-mul (math-add a1 (math-mul a0 ana)) fac) | |
304 b0 (math-mul (math-add b1 (math-mul b0 ana)) fac) | |
305 a1 (math-add (math-mul x a0) (math-mul anf a1)) | |
306 b1 (math-add (math-mul x b0) (math-mul anf b1))) | |
307 (if (math-zerop a1) | |
308 (math-inc-gamma-cfrac-step a0 a1 b0 b1 n fac g a x) | |
309 (setq fac (math-div '(float 1 0) a1)) | |
310 (let ((next (math-mul b1 fac))) | |
311 (math-working "gamma" next) | |
312 (if (math-nearly-equal next g) | |
313 next | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
314 (math-inc-gamma-cfrac-step a0 a1 b0 b1 n fac next a x)))))) |
40785 | 315 |
316 | |
317 ;;; Error function. | |
318 | |
319 (defun calcFunc-erf (x) | |
320 (if (equal x '(var inf var-inf)) | |
321 '(float 1 0) | |
322 (if (equal x '(neg (var inf var-inf))) | |
323 '(float -1 0) | |
324 (if (Math-zerop x) | |
325 x | |
326 (let ((math-current-gamma-value (math-sqrt-pi))) | |
327 (math-to-same-complex-quad | |
328 (math-div (calcFunc-gammag '(float 5 -1) | |
329 (math-sqr (math-to-complex-quad-one x))) | |
330 math-current-gamma-value) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
331 x)))))) |
40785 | 332 |
333 (defun calcFunc-erfc (x) | |
334 (if (equal x '(var inf var-inf)) | |
335 '(float 0 0) | |
336 (if (math-posp x) | |
337 (let ((math-current-gamma-value (math-sqrt-pi))) | |
338 (math-div (calcFunc-gammaG '(float 5 -1) (math-sqr x)) | |
339 math-current-gamma-value)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
340 (math-sub 1 (calcFunc-erf x))))) |
40785 | 341 |
342 (defun math-to-complex-quad-one (x) | |
343 (if (eq (car-safe x) 'polar) (setq x (math-complex x))) | |
344 (if (eq (car-safe x) 'cplx) | |
345 (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
|
346 x)) |
40785 | 347 |
348 (defun math-to-same-complex-quad (x y) | |
349 (if (eq (car-safe y) 'cplx) | |
350 (if (eq (car-safe x) 'cplx) | |
351 (list 'cplx | |
352 (if (math-negp (nth 1 y)) (math-neg (nth 1 x)) (nth 1 x)) | |
353 (if (math-negp (nth 2 y)) (math-neg (nth 2 x)) (nth 2 x))) | |
354 (if (math-negp (nth 1 y)) (math-neg x) x)) | |
355 (if (math-negp y) | |
356 (if (eq (car-safe x) 'cplx) | |
357 (list 'cplx (math-neg (nth 1 x)) (nth 2 x)) | |
358 (math-neg x)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
359 x))) |
40785 | 360 |
361 | |
362 ;;; Beta function. | |
363 | |
364 (defun calcFunc-beta (a b) | |
365 (if (math-num-integerp a) | |
366 (let ((am (math-add a -1))) | |
367 (or (math-numberp b) (math-reject-arg b 'numberp)) | |
368 (math-div 1 (math-mul b (calcFunc-choose (math-add b am) am)))) | |
369 (if (math-num-integerp b) | |
370 (calcFunc-beta b a) | |
371 (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
|
372 (calcFunc-gamma (math-add a b)))))) |
40785 | 373 |
374 | |
375 ;;; Incomplete beta function. | |
376 | |
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
377 (defvar math-current-beta-value nil) |
40785 | 378 (defun calcFunc-betaI (x a b) |
379 (cond ((math-zerop x) | |
380 '(float 0 0)) | |
381 ((math-equal-int x 1) | |
382 '(float 1 0)) | |
383 ((or (math-zerop a) | |
384 (and (math-num-integerp a) | |
385 (math-negp a))) | |
386 (if (or (math-zerop b) | |
387 (and (math-num-integerp b) | |
388 (math-negp b))) | |
389 (math-reject-arg b 'range) | |
390 '(float 1 0))) | |
391 ((or (math-zerop b) | |
392 (and (math-num-integerp b) | |
393 (math-negp b))) | |
394 '(float 0 0)) | |
395 ((not (math-numberp a)) (math-reject-arg a 'numberp)) | |
396 ((not (math-numberp b)) (math-reject-arg b 'numberp)) | |
397 ((math-inexact-result)) | |
398 (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
|
399 (math-div (calcFunc-betaB x a b) math-current-beta-value))))) |
40785 | 400 |
401 (defun calcFunc-betaB (x a b) | |
402 (cond | |
403 ((math-zerop x) | |
404 '(float 0 0)) | |
405 ((math-equal-int x 1) | |
406 (calcFunc-beta a b)) | |
407 ((not (math-numberp x)) (math-reject-arg x 'numberp)) | |
408 ((not (math-numberp a)) (math-reject-arg a 'numberp)) | |
409 ((not (math-numberp b)) (math-reject-arg b 'numberp)) | |
410 ((math-zerop a) (math-reject-arg a 'nonzerop)) | |
411 ((math-zerop b) (math-reject-arg b 'nonzerop)) | |
412 ((and (math-num-integerp b) | |
413 (if (math-negp b) | |
414 (math-reject-arg b 'range) | |
415 (Math-natnum-lessp (setq b (math-trunc b)) 20))) | |
416 (and calc-symbolic-mode (or (math-floatp a) (math-floatp b)) | |
417 (math-inexact-result)) | |
418 (math-mul | |
419 (math-with-extra-prec 2 | |
420 (let* ((i 0) | |
421 (term 1) | |
422 (sum (math-div term a))) | |
423 (while (< (setq i (1+ i)) b) | |
424 (setq term (math-mul (math-div (math-mul term (- i b)) i) x) | |
425 sum (math-add sum (math-div term (math-add a i)))) | |
426 (math-working "beta" sum)) | |
427 sum)) | |
428 (math-pow x a))) | |
429 ((and (math-num-integerp a) | |
430 (if (math-negp a) | |
431 (math-reject-arg a 'range) | |
432 (Math-natnum-lessp (setq a (math-trunc a)) 20))) | |
433 (math-sub (or math-current-beta-value (calcFunc-beta a b)) | |
434 (calcFunc-betaB (math-sub 1 x) b a))) | |
435 (t | |
436 (math-inexact-result) | |
437 (math-with-extra-prec 2 | |
438 (setq x (math-float x)) | |
439 (setq a (math-float a)) | |
440 (setq b (math-float b)) | |
441 (let ((bt (math-exp-raw (math-add (math-mul a (math-ln-raw x)) | |
442 (math-mul b (math-ln-raw | |
443 (math-sub '(float 1 0) | |
444 x))))))) | |
445 (if (Math-lessp x (math-div (math-add a '(float 1 0)) | |
446 (math-add (math-add a b) '(float 2 0)))) | |
447 (math-div (math-mul bt (math-beta-cfrac a b x)) a) | |
448 (math-sub (or math-current-beta-value (calcFunc-beta a b)) | |
449 (math-div (math-mul bt | |
450 (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
|
451 b)))))))) |
40785 | 452 |
453 (defun math-beta-cfrac (a b x) | |
454 (let ((qab (math-add a b)) | |
455 (qap (math-add a '(float 1 0))) | |
456 (qam (math-add a '(float -1 0)))) | |
457 (math-beta-cfrac-step '(float 1 0) | |
458 (math-sub '(float 1 0) | |
459 (math-div (math-mul qab x) qap)) | |
460 '(float 1 0) '(float 1 0) | |
461 '(float 1 0) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
462 qab qap qam a b x))) |
40785 | 463 |
464 (defun math-beta-cfrac-step (az bz am bm m qab qap qam a b x) | |
465 (let* ((two-m (math-mul m '(float 2 0))) | |
466 (d (math-div (math-mul (math-mul (math-sub b m) m) x) | |
467 (math-mul (math-add qam two-m) (math-add a two-m)))) | |
468 (ap (math-add az (math-mul d am))) | |
469 (bp (math-add bz (math-mul d bm))) | |
470 (d2 (math-neg | |
471 (math-div (math-mul (math-mul (math-add a m) (math-add qab m)) x) | |
472 (math-mul (math-add qap two-m) (math-add a two-m))))) | |
473 (app (math-add ap (math-mul d2 az))) | |
474 (bpp (math-add bp (math-mul d2 bz))) | |
475 (next (math-div app bpp))) | |
476 (math-working "beta" next) | |
477 (if (math-nearly-equal next az) | |
478 next | |
479 (math-beta-cfrac-step next '(float 1 0) | |
480 (math-div ap bpp) (math-div bp bpp) | |
481 (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
|
482 qab qap qam a b x)))) |
40785 | 483 |
484 | |
485 ;;; Bessel functions. | |
486 | |
487 ;;; Should generalize this to handle arbitrary precision! | |
488 | |
489 (defun calcFunc-besJ (v x) | |
490 (or (math-numberp v) (math-reject-arg v 'numberp)) | |
491 (or (math-numberp x) (math-reject-arg x 'numberp)) | |
492 (let ((calc-internal-prec (min 8 calc-internal-prec))) | |
493 (math-with-extra-prec 3 | |
494 (setq x (math-float (math-normalize x))) | |
495 (setq v (math-float (math-normalize v))) | |
496 (cond ((math-zerop x) | |
497 (if (math-zerop v) | |
498 '(float 1 0) | |
499 '(float 0 0))) | |
500 ((math-inexact-result)) | |
501 ((not (math-num-integerp v)) | |
502 (let ((start (math-div 1 (calcFunc-fact v)))) | |
503 (math-mul (math-besJ-series start start | |
504 0 | |
505 (math-mul '(float -25 -2) | |
506 (math-sqr x)) | |
507 v) | |
508 (math-pow (math-div x 2) v)))) | |
509 ((math-negp (setq v (math-trunc v))) | |
510 (if (math-oddp v) | |
511 (math-neg (calcFunc-besJ (math-neg v) x)) | |
512 (calcFunc-besJ (math-neg v) x))) | |
513 ((eq v 0) | |
514 (math-besJ0 x)) | |
515 ((eq v 1) | |
516 (math-besJ1 x)) | |
517 ((Math-lessp v (math-abs-approx x)) | |
518 (let ((j 0) | |
519 (bjm (math-besJ0 x)) | |
520 (bj (math-besJ1 x)) | |
521 (two-over-x (math-div 2 x)) | |
522 bjp) | |
523 (while (< (setq j (1+ j)) v) | |
524 (setq bjp (math-sub (math-mul (math-mul j two-over-x) bj) | |
525 bjm) | |
526 bjm bj | |
527 bj bjp)) | |
528 bj)) | |
529 (t | |
530 (if (Math-lessp 100 v) (math-reject-arg v 'range)) | |
531 (let* ((j (logior (+ v (math-isqrt-small (* 40 v))) 1)) | |
532 (two-over-x (math-div 2 x)) | |
533 (jsum nil) | |
534 (bjp '(float 0 0)) | |
535 (sum '(float 0 0)) | |
536 (bj '(float 1 0)) | |
537 bjm ans) | |
538 (while (> (setq j (1- j)) 0) | |
539 (setq bjm (math-sub (math-mul (math-mul j two-over-x) bj) | |
540 bjp) | |
541 bjp bj | |
542 bj bjm) | |
543 (if (> (nth 2 (math-abs-approx bj)) 10) | |
544 (setq bj (math-mul bj '(float 1 -10)) | |
545 bjp (math-mul bjp '(float 1 -10)) | |
546 ans (and ans (math-mul ans '(float 1 -10))) | |
547 sum (math-mul sum '(float 1 -10)))) | |
548 (or (setq jsum (not jsum)) | |
549 (setq sum (math-add sum bj))) | |
550 (if (= j v) | |
551 (setq ans bjp))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
552 (math-div ans (math-sub (math-mul 2 sum) bj)))))))) |
40785 | 553 |
554 (defun math-besJ-series (sum term k zz vk) | |
555 (math-working "besJ" sum) | |
556 (setq k (1+ k) | |
557 vk (math-add 1 vk) | |
558 term (math-div (math-mul term zz) (math-mul k vk))) | |
559 (let ((next (math-add sum term))) | |
560 (if (math-nearly-equal next sum) | |
561 next | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
562 (math-besJ-series next term k zz vk)))) |
40785 | 563 |
564 (defun math-besJ0 (x &optional yflag) | |
565 (cond ((and (not yflag) (math-negp (calcFunc-re x))) | |
566 (math-besJ0 (math-neg x))) | |
567 ((Math-lessp '(float 8 0) (math-abs-approx x)) | |
568 (let* ((z (math-div '(float 8 0) x)) | |
569 (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
|
570 (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
|
571 (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
572 (math-read-number-simple "-0.785398164")))) |
40785 | 573 (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
|
574 (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
|
575 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
576 (math-read-number-simple "0.0000002093887211") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
577 (math-read-number-simple "-0.000002073370639") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
578 (math-read-number-simple "0.00002734510407") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
579 (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
|
580 '(float 1 0))))) |
40785 | 581 (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
|
582 (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
|
583 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
584 (math-read-number-simple "-0.0000000934935152") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
585 (math-read-number-simple "0.0000007621095161") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
586 (math-read-number-simple "-0.000006911147651") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
587 (math-read-number-simple "0.0001430488765") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
588 (math-read-number-simple "-0.01562499995"))))) |
40785 | 589 (sc (math-sin-cos-raw xx))) |
590 (if yflag | |
591 (setq sc (cons (math-neg (cdr sc)) (car sc)))) | |
592 (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
|
593 (math-div (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
594 (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
|
595 x)) |
40785 | 596 (math-sub (math-mul (cdr sc) a1) |
597 (math-mul (car sc) (math-mul z a2)))))) | |
598 (t | |
599 (let ((y (math-sqr x))) | |
600 (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
|
601 (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
|
602 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
603 (math-read-number-simple "-184.9052456") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
604 (math-read-number-simple "77392.33017") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
605 (math-read-number-simple "-11214424.18") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
606 (math-read-number-simple "651619640.7") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
607 (math-read-number-simple "-13362590354.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
608 (math-read-number-simple "57568490574.0")))) |
40785 | 609 (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
|
610 (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
|
611 (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
|
612 '(float 1 0) |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
613 (math-read-number-simple "267.8532712") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
614 (math-read-number-simple "59272.64853") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
615 (math-read-number-simple "9494680.718") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
616 (math-read-number-simple "1029532985.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
617 (math-read-number-simple "57568490411.0"))))))))) |
40785 | 618 |
619 (defun math-besJ1 (x &optional yflag) | |
620 (cond ((and (math-negp (calcFunc-re x)) (not yflag)) | |
621 (math-neg (math-besJ1 (math-neg x)))) | |
622 ((Math-lessp '(float 8 0) (math-abs-approx x)) | |
623 (let* ((z (math-div '(float 8 0) x)) | |
624 (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
|
625 (xx (math-add x (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
626 (math-read-number-simple "-2.356194491")))) |
40785 | 627 (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
|
628 (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
|
629 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
630 (math-read-number-simple "-0.000000240337019") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
631 (math-read-number-simple "0.000002457520174") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
632 (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
|
633 '(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
|
634 '(float 1 0))))) |
40785 | 635 (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
|
636 (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
|
637 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
638 (math-read-number-simple "0.000000105787412") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
639 (math-read-number-simple "-0.00000088228987") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
640 (math-read-number-simple "0.000008449199096") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
641 (math-read-number-simple "-0.0002002690873") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
642 (math-read-number-simple "0.04687499995"))))) |
40785 | 643 (sc (math-sin-cos-raw xx))) |
644 (if yflag | |
645 (setq sc (cons (math-neg (cdr sc)) (car sc))) | |
646 (if (math-negp x) | |
647 (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
|
648 (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
|
649 (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
650 (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
|
651 x)) |
40785 | 652 (math-sub (math-mul (cdr sc) a1) |
653 (math-mul (car sc) (math-mul z a2)))))) | |
654 (t | |
655 (let ((y (math-sqr x))) | |
656 (math-mul | |
657 x | |
658 (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
|
659 (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
|
660 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
661 (math-read-number-simple "-30.16036606") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
662 (math-read-number-simple "15704.4826") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
663 (math-read-number-simple "-2972611.439") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
664 (math-read-number-simple "242396853.1") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
665 (math-read-number-simple "-7895059235.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
666 (math-read-number-simple "72362614232.0")))) |
40785 | 667 (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
|
668 (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
|
669 (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
|
670 '(float 1 0) |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
671 (math-read-number-simple "376.9991397") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
672 (math-read-number-simple "99447.43394") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
673 (math-read-number-simple "18583304.74") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
674 (math-read-number-simple "2300535178.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
675 (math-read-number-simple "144725228442.0")))))))))) |
40785 | 676 |
677 (defun calcFunc-besY (v x) | |
678 (math-inexact-result) | |
679 (or (math-numberp v) (math-reject-arg v 'numberp)) | |
680 (or (math-numberp x) (math-reject-arg x 'numberp)) | |
681 (let ((calc-internal-prec (min 8 calc-internal-prec))) | |
682 (math-with-extra-prec 3 | |
683 (setq x (math-float (math-normalize x))) | |
684 (setq v (math-float (math-normalize v))) | |
685 (cond ((not (math-num-integerp v)) | |
686 (let ((sc (math-sin-cos-raw (math-mul v (math-pi))))) | |
687 (math-div (math-sub (math-mul (calcFunc-besJ v x) (cdr sc)) | |
688 (calcFunc-besJ (math-neg v) x)) | |
689 (car sc)))) | |
690 ((math-negp (setq v (math-trunc v))) | |
691 (if (math-oddp v) | |
692 (math-neg (calcFunc-besY (math-neg v) x)) | |
693 (calcFunc-besY (math-neg v) x))) | |
694 ((eq v 0) | |
695 (math-besY0 x)) | |
696 ((eq v 1) | |
697 (math-besY1 x)) | |
698 (t | |
699 (let ((j 0) | |
700 (bym (math-besY0 x)) | |
701 (by (math-besY1 x)) | |
702 (two-over-x (math-div 2 x)) | |
703 byp) | |
704 (while (< (setq j (1+ j)) v) | |
705 (setq byp (math-sub (math-mul (math-mul j two-over-x) by) | |
706 bym) | |
707 bym by | |
708 by byp)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
709 by)))))) |
40785 | 710 |
711 (defun math-besY0 (x) | |
712 (cond ((Math-lessp (math-abs-approx x) '(float 8 0)) | |
713 (let ((y (math-sqr x))) | |
714 (math-add | |
715 (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
|
716 (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
|
717 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
718 (math-read-number-simple "228.4622733") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
719 (math-read-number-simple "-86327.92757") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
720 (math-read-number-simple "10879881.29") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
721 (math-read-number-simple "-512359803.6") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
722 (math-read-number-simple "7062834065.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
723 (math-read-number-simple "-2957821389.0")))) |
40785 | 724 (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
|
725 (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
|
726 (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
|
727 '(float 1 0) |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
728 (math-read-number-simple "226.1030244") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
729 (math-read-number-simple "47447.2647") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
730 (math-read-number-simple "7189466.438") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
731 (math-read-number-simple "745249964.8") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
732 (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
|
733 (math-mul (eval-when-compile |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
734 (math-read-number-simple "0.636619772")) |
40785 | 735 (math-mul (math-besJ0 x) (math-ln-raw x)))))) |
736 ((math-negp (calcFunc-re x)) | |
737 (math-add (math-besJ0 (math-neg x) t) | |
738 (math-mul '(cplx 0 2) | |
739 (math-besJ0 (math-neg x))))) | |
740 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
741 (math-besJ0 x t)))) |
40785 | 742 |
743 (defun math-besY1 (x) | |
744 (cond ((Math-lessp (math-abs-approx x) '(float 8 0)) | |
745 (let ((y (math-sqr x))) | |
746 (math-add | |
747 (math-mul | |
748 x | |
749 (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
|
750 (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
|
751 (list |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
752 (math-read-number-simple "8511.937935") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
753 (math-read-number-simple "-4237922.726") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
754 (math-read-number-simple "734926455.1") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
755 (math-read-number-simple "-51534381390.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
756 (math-read-number-simple "1275274390000.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
757 (math-read-number-simple "-4900604943000.0")))) |
40785 | 758 (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
|
759 (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
|
760 (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
|
761 '(float 1 0) |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
762 (math-read-number-simple "354.9632885") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
763 (math-read-number-simple "102042.605") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
764 (math-read-number-simple "22459040.02") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
765 (math-read-number-simple "3733650367.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
766 (math-read-number-simple "424441966400.0") |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
767 (math-read-number-simple "24995805700000.0")))))) |
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
768 (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
|
769 (math-sub (math-mul (math-besJ1 x) (math-ln-raw x)) |
40785 | 770 (math-div 1 x)))))) |
771 ((math-negp (calcFunc-re x)) | |
772 (math-neg | |
773 (math-add (math-besJ1 (math-neg x) t) | |
774 (math-mul '(cplx 0 2) | |
775 (math-besJ1 (math-neg x)))))) | |
776 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
777 (math-besJ1 x t)))) |
40785 | 778 |
779 (defun math-poly-eval (x coefs) | |
780 (let ((accum (car coefs))) | |
781 (while (setq coefs (cdr coefs)) | |
782 (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
|
783 accum)) |
40785 | 784 |
785 | |
786 ;;;; Bernoulli and Euler polynomials and numbers. | |
787 | |
788 (defun calcFunc-bern (n &optional x) | |
789 (if (and x (not (math-zerop x))) | |
790 (if (and calc-symbolic-mode (math-floatp x)) | |
791 (math-inexact-result) | |
792 (math-build-polynomial-expr (math-bernoulli-coefs n) x)) | |
793 (or (math-num-natnump n) (math-reject-arg n 'natnump)) | |
794 (if (consp n) | |
795 (progn | |
796 (math-inexact-result) | |
797 (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
|
798 (math-bernoulli-number n)))) |
40785 | 799 |
800 (defun calcFunc-euler (n &optional x) | |
801 (or (math-num-natnump n) (math-reject-arg n 'natnump)) | |
802 (if x | |
803 (let* ((n1 (math-add n 1)) | |
804 (coefs (math-bernoulli-coefs n1)) | |
805 (fac (math-div (math-pow 2 n1) n1)) | |
806 (k -1) | |
807 (x1 (math-div (math-add x 1) 2)) | |
808 (x2 (math-div x 2))) | |
809 (if (math-numberp x) | |
810 (if (and calc-symbolic-mode (math-floatp x)) | |
811 (math-inexact-result) | |
812 (math-mul fac | |
813 (math-sub (math-build-polynomial-expr coefs x1) | |
814 (math-build-polynomial-expr coefs x2)))) | |
815 (calcFunc-collect | |
816 (math-reduce-vec | |
817 'math-add | |
818 (cons 'vec | |
819 (mapcar (function | |
820 (lambda (c) | |
821 (setq k (1+ k)) | |
822 (math-mul (math-mul fac c) | |
823 (math-sub (math-pow x1 k) | |
824 (math-pow x2 k))))) | |
825 coefs))) | |
826 x))) | |
827 (math-mul (math-pow 2 n) | |
828 (if (consp n) | |
829 (progn | |
830 (math-inexact-result) | |
831 (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
|
832 (calcFunc-euler n '(frac 1 2)))))) |
40785 | 833 |
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
|
834 (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
|
835 (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
|
836 (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
|
837 (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
|
838 -174611 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
839 (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
|
840 (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
|
841 43867 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
842 (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
|
843 (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
|
844 -3617 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
845 (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
|
846 (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
|
847 1 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
848 (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
|
849 (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
|
850 -691 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
851 (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
|
852 (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
|
853 1 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
854 (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
|
855 (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
|
856 -1 |
81548
334bfc4cc092
*** empty log message ***
Jay Belanger <jay.p.belanger@gmail.com>
parents:
81543
diff
changeset
|
857 (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
|
858 (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
|
859 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
|
860 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
|
861 (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
|
862 -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
|
863 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
|
864 (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
|
865 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
|
866 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
|
867 1 ))) |
41264
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
868 |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
869 (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
|
870 (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
|
871 (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
|
872 (frac -1 30) (frac 1 6) 1 )) |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
873 |
0759b2de09c1
(calc-over-notation): Use `completing-read'.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
874 (defvar math-bernoulli-cache-size 11) |
40785 | 875 (defun math-bernoulli-coefs (n) |
876 (let* ((coefs (list (calcFunc-bern n))) | |
877 (nn (math-trunc n)) | |
878 (k nn) | |
879 (term nn) | |
880 coef | |
881 (calc-prefer-frac (or (integerp n) calc-prefer-frac))) | |
882 (while (>= (setq k (1- k)) 0) | |
883 (setq term (math-div term (- nn k)) | |
884 coef (math-mul term (math-bernoulli-number k)) | |
885 coefs (cons (if (consp n) (math-float coef) coef) coefs) | |
886 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
|
887 (nreverse coefs))) |
40785 | 888 |
889 (defun math-bernoulli-number (n) | |
890 (if (= (% n 2) 1) | |
891 (if (= n 1) | |
892 '(frac -1 2) | |
893 0) | |
894 (setq n (/ n 2)) | |
895 (while (>= n math-bernoulli-cache-size) | |
896 (let* ((sum 0) | |
897 (nk 1) ; nk = n-k+1 | |
898 (fact 1) ; fact = (n-k+1)! | |
899 ofact | |
900 (p math-bernoulli-b-cache) | |
901 (calc-prefer-frac t)) | |
902 (math-working "bernoulli B" (* 2 math-bernoulli-cache-size)) | |
903 (while p | |
904 (setq nk (+ nk 2) | |
905 ofact fact | |
906 fact (math-mul fact (* nk (1- nk))) | |
907 sum (math-add sum (math-div (car p) fact)) | |
908 p (cdr p))) | |
909 (setq ofact (math-mul ofact (1- nk)) | |
910 sum (math-sub (math-div '(frac 1 2) ofact) sum) | |
911 math-bernoulli-b-cache (cons sum math-bernoulli-b-cache) | |
912 math-bernoulli-B-cache (cons (math-mul sum ofact) | |
913 math-bernoulli-B-cache) | |
914 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
|
915 (nth (- math-bernoulli-cache-size n 1) math-bernoulli-B-cache))) |
40785 | 916 |
917 ;;; Bn = n! bn | |
918 ;;; bn = - sum_k=0^n-1 bk / (n-k+1)! | |
919 | |
920 ;;; A faster method would be to use "tangent numbers", c.f., Concrete | |
921 ;;; Mathematics pg. 273. | |
922 | |
923 | |
924 ;;; Probability distributions. | |
925 | |
926 ;;; Binomial. | |
927 (defun calcFunc-utpb (x n p) | |
928 (if math-expand-formulas | |
929 (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
|
930 (calcFunc-betaI p x (math-add (math-sub n x) 1)))) |
40785 | 931 (put 'calcFunc-utpb 'math-expandable t) |
932 | |
933 (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
|
934 (math-sub 1 (calcFunc-utpb x n p))) |
40785 | 935 (put 'calcFunc-ltpb 'math-expandable t) |
936 | |
937 ;;; Chi-square. | |
938 (defun calcFunc-utpc (chisq v) | |
939 (if math-expand-formulas | |
940 (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
|
941 (calcFunc-gammaQ (math-div v 2) (math-div chisq 2)))) |
40785 | 942 (put 'calcFunc-utpc 'math-expandable t) |
943 | |
944 (defun calcFunc-ltpc (chisq v) | |
945 (if math-expand-formulas | |
946 (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
|
947 (calcFunc-gammaP (math-div v 2) (math-div chisq 2)))) |
40785 | 948 (put 'calcFunc-ltpc 'math-expandable t) |
949 | |
950 ;;; F-distribution. | |
951 (defun calcFunc-utpf (f v1 v2) | |
952 (if math-expand-formulas | |
953 (math-normalize (list 'calcFunc-betaI | |
954 (list '/ v2 (list '+ v2 (list '* v1 f))) | |
955 (list '/ v2 2) | |
956 (list '/ v1 2))) | |
957 (calcFunc-betaI (math-div v2 (math-add v2 (math-mul v1 f))) | |
958 (math-div v2 2) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
959 (math-div v1 2)))) |
40785 | 960 (put 'calcFunc-utpf 'math-expandable t) |
961 | |
962 (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
|
963 (math-sub 1 (calcFunc-utpf f v1 v2))) |
40785 | 964 (put 'calcFunc-ltpf 'math-expandable t) |
965 | |
966 ;;; Normal. | |
967 (defun calcFunc-utpn (x mean sdev) | |
968 (if math-expand-formulas | |
969 (math-normalize | |
970 (list '/ | |
971 (list '+ 1 | |
972 (list 'calcFunc-erf | |
973 (list '/ (list '- mean x) | |
974 (list '* sdev (list 'calcFunc-sqrt 2))))) | |
975 2)) | |
976 (math-mul (math-add '(float 1 0) | |
977 (calcFunc-erf | |
978 (math-div (math-sub mean x) | |
979 (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
|
980 '(float 5 -1)))) |
40785 | 981 (put 'calcFunc-utpn 'math-expandable t) |
982 | |
983 (defun calcFunc-ltpn (x mean sdev) | |
984 (if math-expand-formulas | |
985 (math-normalize | |
986 (list '/ | |
987 (list '+ 1 | |
988 (list 'calcFunc-erf | |
989 (list '/ (list '- x mean) | |
990 (list '* sdev (list 'calcFunc-sqrt 2))))) | |
991 2)) | |
992 (math-mul (math-add '(float 1 0) | |
993 (calcFunc-erf | |
994 (math-div (math-sub x mean) | |
995 (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
|
996 '(float 5 -1)))) |
40785 | 997 (put 'calcFunc-ltpn 'math-expandable t) |
998 | |
999 ;;; Poisson. | |
1000 (defun calcFunc-utpp (n x) | |
1001 (if math-expand-formulas | |
1002 (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
|
1003 (calcFunc-gammaP x n))) |
40785 | 1004 (put 'calcFunc-utpp 'math-expandable t) |
1005 | |
1006 (defun calcFunc-ltpp (n x) | |
1007 (if math-expand-formulas | |
1008 (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
|
1009 (calcFunc-gammaQ x n))) |
40785 | 1010 (put 'calcFunc-ltpp 'math-expandable t) |
1011 | |
1012 ;;; Student's t. (As defined in Abramowitz & Stegun and Numerical Recipes.) | |
1013 (defun calcFunc-utpt (tt v) | |
1014 (if math-expand-formulas | |
1015 (math-normalize (list 'calcFunc-betaI | |
1016 (list '/ v (list '+ v (list '^ tt 2))) | |
1017 (list '/ v 2) | |
1018 '(float 5 -1))) | |
1019 (calcFunc-betaI (math-div v (math-add v (math-sqr tt))) | |
1020 (math-div v 2) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1021 '(float 5 -1)))) |
40785 | 1022 (put 'calcFunc-utpt 'math-expandable t) |
1023 | |
1024 (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
|
1025 (math-sub 1 (calcFunc-utpt tt v))) |
40785 | 1026 (put 'calcFunc-ltpt 'math-expandable t) |
1027 | |
58656
c60e5eef3cde
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1028 (provide 'calc-funcs) |
40785 | 1029 |
52401 | 1030 ;;; 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
|
1031 ;;; calc-funcs.el ends here |