1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10-*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancements. ;;;;;
5 ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
6 ;;; All rights reserved ;;;;;
8 ;;; Copyright (c) 2001 by Raymond Toy. Replaced everything and added ;;;;;
9 ;;; support for symbolic manipulation of all 12 Jacobian elliptic ;;;;;
10 ;;; functions and the complete and incomplete elliptic integral ;;;;;
11 ;;; of the first, second and third kinds. ;;;;;
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15 ;;(macsyma-module ellipt)
18 ;;; Jacobian elliptic functions and elliptic integrals.
22 ;;; [1] Abramowitz and Stegun
23 ;;; [2] Lawden, Elliptic Functions and Applications, Springer-Verlag, 1989
24 ;;; [3] Whittaker & Watson, A Course of Modern Analysis
26 ;;; We use the definitions from Abramowitz and Stegun where our
27 ;;; sn(u,m) is sn(u|m). That is, the second arg is the parameter,
28 ;;; instead of the modulus k or modular angle alpha.
30 ;;; Note that m = k^2 and k = sin(alpha).
34 ;;; Routines for computing the basic elliptic functions sn, cn, and dn.
37 ;;; A&S gives several methods for computing elliptic functions
38 ;;; including the AGM method (16.4) and ascending and descending Landen
39 ;;; transformations (16.12 and 16.14). The latter are actually quite
40 ;;; fast, only requiring simple arithmetic and square roots for the
41 ;;; transformation until the last step. The AGM requires evaluation of
42 ;;; several trigonometric functions at each stage.
44 ;;; However, the Landen transformations appear to have some round-off
45 ;;; issues. For example, using the ascending transform to compute cn,
46 ;;; cn(100,.7) > 1e10. This is clearly not right since |cn| <= 1.
49 ;;; All the routines in the BIGFLOAT package are collected here.
50 ;;; These functions compute numerical results for the elliptic
51 ;;; functions and integrals.
52 (in-package #:bigfloat
)
54 (declaim (inline descending-transform ascending-transform
))
56 (defun ascending-transform (u m
)
59 ;; Take care in computing this transform. For the case where
60 ;; m is complex, we should compute sqrt(mu1) first as
61 ;; (1-sqrt(m))/(1+sqrt(m)), and then square this to get mu1.
62 ;; If not, we may choose the wrong branch when computing
64 (let* ((root-m (sqrt m
))
66 (expt (1+ root-m
) 2)))
67 (root-mu1 (/ (- 1 root-m
) (+ 1 root-m
)))
68 (v (/ u
(1+ root-mu1
))))
69 (values v mu root-mu1
)))
71 (defun descending-transform (u m
)
72 ;; Note: Don't calculate mu first, as given in 16.12.1. We
73 ;; should calculate sqrt(mu) = (1-sqrt(m1)/(1+sqrt(m1)), and
74 ;; then compute mu = sqrt(mu)^2. If we calculate mu first,
75 ;; sqrt(mu) loses information when m or m1 is complex.
76 (let* ((root-m1 (sqrt (- 1 m
)))
77 (root-mu (/ (- 1 root-m1
) (+ 1 root-m1
)))
78 (mu (* root-mu root-mu
))
79 (v (/ u
(1+ root-mu
))))
80 (values v mu root-mu
)))
83 ;; This appears to work quite well for both real and complex values
85 (defun elliptic-sn-descending (u m
)
89 ((< (abs m
) (epsilon u
))
93 (multiple-value-bind (v mu root-mu
)
94 (descending-transform u m
)
95 (let* ((new-sn (elliptic-sn-descending v mu
)))
96 (/ (* (1+ root-mu
) new-sn
)
97 (1+ (* root-mu new-sn new-sn
))))))))
101 ;; jacobi_sn(u,0) = sin(u). Should we use A&S 16.13.1 if m
104 ;; sn(u,m) = sin(u) - 1/4*m(u-sin(u)*cos(u))*cos(u)
107 ;; jacobi_sn(u,1) = tanh(u). Should we use A&S 16.15.1 if m
108 ;; is close enough to 1?
110 ;; sn(u,m) = tanh(u) + 1/4*(1-m)*(sinh(u)*cosh(u)-u)*sech(u)^2
113 ;; Use the ascending Landen transformation to compute sn.
114 (let ((s (elliptic-sn-descending u m
)))
115 (if (and (realp u
) (realp m
))
121 ;; jacobi_dn(u,0) = 1. Should we use A&S 16.13.3 for small m?
123 ;; dn(u,m) = 1 - 1/2*m*sin(u)^2
126 ;; jacobi_dn(u,1) = sech(u). Should we use A&S 16.15.3 if m
127 ;; is close enough to 1?
129 ;; dn(u,m) = sech(u) + 1/4*(1-m)*(sinh(u)*cosh(u)+u)*tanh(u)*sech(u)
132 ;; Use the Gauss transformation from
133 ;; http://functions.wolfram.com/09.29.16.0013.01:
136 ;; dn((1+sqrt(m))*z, 4*sqrt(m)/(1+sqrt(m))^2)
137 ;; = (1-sqrt(m)*sn(z, m)^2)/(1+sqrt(m)*sn(z,m)^2)
141 ;; dn(y, mu) = (1-sqrt(m)*sn(z, m)^2)/(1+sqrt(m)*sn(z,m)^2)
143 ;; where z = y/(1+sqrt(m)) and mu=4*sqrt(m)/(1+sqrt(m))^2.
145 ;; Solve for m, and we get
147 ;; sqrt(m) = -(mu+2*sqrt(1-mu)-2)/mu or (-mu+2*sqrt(1-mu)+2)/mu.
149 ;; I don't think it matters which sqrt we use, so I (rtoy)
150 ;; arbitrarily choose the first one above.
152 ;; Note that (1-sqrt(1-mu))/(1+sqrt(1-mu)) is the same as
153 ;; -(mu+2*sqrt(1-mu)-2)/mu. Also, the former is more
154 ;; accurate for small mu.
155 (let* ((root (let ((root-1-m (sqrt (- 1 m
))))
159 (s (elliptic-sn-descending z
(* root root
)))
166 ;; jacobi_cn(u,0) = cos(u). Should we use A&S 16.13.2 for
169 ;; cn(u,m) = cos(u) + 1/4*m*(u-sin(u)*cos(u))*sin(u)
172 ;; jacobi_cn(u,1) = sech(u). Should we use A&S 16.15.3 if m
173 ;; is close enough to 1?
175 ;; cn(u,m) = sech(u) - 1/4*(1-m)*(sinh(u)*cosh(u)-u)*tanh(u)*sech(u)
178 ;; Use the ascending Landen transformation, A&S 16.14.3.
179 (multiple-value-bind (v mu root-mu1
)
180 (ascending-transform u m
)
182 (* (/ (+ 1 root-mu1
) mu
)
183 (/ (- (* d d
) root-mu1
)
186 ;; Arithmetic-Geometric Mean algorithm for real or complex numbers.
187 ;; See https://dlmf.nist.gov/22.20.ii.
189 ;; Do not use this for computing jacobi sn. It loses some 7 digits of
190 ;; accuracy for sn(1+%i,0.7).
191 (let ((an (make-array 100 :fill-pointer
0))
192 (bn (make-array 100 :fill-pointer
0))
193 (cn (make-array 100 :fill-pointer
0)))
194 ;; Instead of allocating these array anew each time, we'll reuse
195 ;; them and allow them to grow as needed.
196 (defun agm (a0 b0 c0 tol
)
197 "Arithmetic-Geometric Mean algorithm for real or complex a0, b0, c0.
198 Algorithm continues until |c[n]| <= tol."
200 ;; DLMF (https://dlmf.nist.gov/22.20.ii) says for any real or
201 ;; complex a0 and b0, b0/a0 must not be real and negative. Let's
204 (when (and (= (imagpart q
) 0)
205 (minusp (realpart q
)))
206 (error "Invalid arguments for AGM: ~A ~A~%" a0 b0
)))
207 (let ((nd (max (* 2 (ceiling (log (- (log tol
2))))) 8)))
208 ;; DLMF (https://dlmf.nist.gov/22.20.ii) says that |c[n]| <=
209 ;; C*2^(-2^n), for some constant C. Solve C*2^(-2^n) = tol to
210 ;; get n = log(log(C/tol)/log(2))/log(2). Arbitrarily assume C
211 ;; is one to get n = log(-(log(tol)/log(2)))/log(2). Thus, the
212 ;; approximate number of term needed is n =
213 ;; 1.44*log(-(1.44*log(tol))). Round to 2*log(-log2(tol)).
214 (setf (fill-pointer an
) 0
217 (vector-push-extend a0 an
)
218 (vector-push-extend b0 bn
)
219 (vector-push-extend c0 cn
)
222 ((or (<= (abs (aref cn k
)) tol
)
225 (error "Failed to converge")
226 (values k an bn cn
)))
227 (vector-push-extend (/ (+ (aref an k
) (aref bn k
)) 2) an
)
228 ;; DLMF (https://dlmf.nist.gov/22.20.ii) has conditions on how
229 ;; to choose the square root depending on the phase of a[n-1]
230 ;; and b[n-1]. We don't check for that here.
231 (vector-push-extend (sqrt (* (aref an k
) (aref bn k
))) bn
)
232 (vector-push-extend (/ (- (aref an k
) (aref bn k
)) 2) cn
)))))
234 (defun jacobi-am-agm (u m tol
)
235 "Evaluate the jacobi_am function from real u and m with |m| <= 1. This
236 uses the AGM method until a tolerance of TOL is reached for the
238 (multiple-value-bind (n an bn cn
)
239 (agm 1 (sqrt (- 1 m
)) (sqrt m
) tol
)
240 (declare (ignore bn
))
241 ;; See DLMF (https://dlmf.nist.gov/22.20.ii) for the algorithm.
242 (let ((phi (* u
(aref an n
) (expt 2 n
))))
243 (loop for k from n downto
1
245 (setf phi
(/ (+ phi
(asin (* (/ (aref cn k
)
251 ;; Compute Jacobi am for real or complex values of U and M. The args
252 ;; must be floats or bigfloat::bigfloats. TOL is the tolerance used
253 ;; by the AGM algorithm. It is ignored if the AGM algorithm is not
255 (defun bf-jacobi-am (u m tol
)
256 (cond ((and (realp u
) (realp m
) (<= (abs m
) 1))
257 ;; The case of real u and m with |m| <= 1. We can use AGM to
258 ;; compute the result.
259 (jacobi-am-agm (to u
)
263 ;; Otherwise, use the formula am(u,m) = asin(jacobi_sn(u,m)).
264 ;; (See DLMF https://dlmf.nist.gov/22.16.E1). This appears
265 ;; to be what functions.wolfram.com is using in this case.
266 (asin (sn (to u
) (to m
))))))
268 ;; Translation of Jim FitzSimons' bigfloat implementation of elliptic
269 ;; integrals from http://www.getnet.com/~cherry/elliptbf3.mac.
271 ;; The algorithms are based on B.C. Carlson's "Numerical Computation
272 ;; of Real or Complex Elliptic Integrals". These are updated to the
273 ;; algorithms in Journal of Computational and Applied Mathematics 118
274 ;; (2000) 71-85 "Reduction Theorems for Elliptic Integrands with the
275 ;; Square Root of two quadritic factors"
278 ;; NOTE: Despite the names indicating these are for bigfloat numbers,
279 ;; the algorithms and routines are generic and will work with floats
282 (defun bferrtol (&rest args
)
283 ;; Compute error tolerance as sqrt(2^(-fpprec)). Not sure this is
284 ;; quite right, but it makes the routines more accurate as fpprec
286 (sqrt (reduce #'min
(mapcar #'(lambda (x)
287 (if (rationalp (realpart x
))
288 maxima
::+flonum-epsilon
+
292 ;; rc(x,y) = integrate(1/2*(t+x)^(-1/2)/(t+y), t, 0, inf)
294 ;; log(x) = (x-1)*rc(((1+x)/2)^2, x), x > 0
295 ;; asin(x) = x * rc(1-x^2, 1), |x|<= 1
296 ;; acos(x) = sqrt(1-x^2)*rc(x^2,1), 0 <= x <=1
297 ;; atan(x) = x * rc(1,1+x^2)
298 ;; asinh(x) = x * rc(1+x^2,1)
299 ;; acosh(x) = sqrt(x^2-1) * rc(x^2,1), x >= 1
300 ;; atanh(x) = x * rc(1,1-x^2), |x|<=1
304 xn z w a an pwr4 n epslon lambda sn s
)
305 (cond ((and (zerop (imagpart yn
))
306 (minusp (realpart yn
)))
310 (setf w
(sqrt (/ x xn
))))
315 (setf a
(/ (+ xn yn yn
) 3))
316 (setf epslon
(/ (abs (- a xn
)) (bferrtol x y
)))
320 (loop while
(> (* epslon pwr4
) (abs an
))
322 (setf pwr4
(/ pwr4
4))
323 (setf lambda
(+ (* 2 (sqrt xn
) (sqrt yn
)) yn
))
324 (setf an
(/ (+ an lambda
) 4))
325 (setf xn
(/ (+ xn lambda
) 4))
326 (setf yn
(/ (+ yn lambda
) 4))
328 ;; c2=3/10,c3=1/7,c4=3/8,c5=9/22,c6=159/208,c7=9/8
329 (setf sn
(/ (* pwr4
(- z a
)) an
))
330 (setf s
(* sn sn
(+ 3/10
335 (* sn
9/8))))))))))))
341 ;; See https://dlmf.nist.gov/19.16.E5:
343 ;; rd(x,y,z) = integrate(3/2/sqrt(t+x)/sqrt(t+y)/sqrt(t+z)/(t+z), t, 0, inf)
346 ;; E(K) = rf(0, 1-K^2, 1) - (K^2/3)*rd(0,1-K^2,1)
348 ;; B = integrate(s^2/sqrt(1-s^4), s, 0 ,1)
350 ;; = sqrt(%pi)*gamma(3/4)/gamma(1/4)
357 (a (/ (+ xn yn
(* 3 zn
)) 5))
358 (epslon (/ (max (abs (- a xn
))
366 xnroot ynroot znroot lam
)
367 (loop while
(> (* power4 epslon
) (abs an
))
369 (setf xnroot
(sqrt xn
))
370 (setf ynroot
(sqrt yn
))
371 (setf znroot
(sqrt zn
))
372 (setf lam
(+ (* xnroot ynroot
)
375 (setf sigma
(+ sigma
(/ power4
376 (* znroot
(+ zn lam
)))))
377 (setf power4
(* power4
1/4))
378 (setf xn
(* (+ xn lam
) 1/4))
379 (setf yn
(* (+ yn lam
) 1/4))
380 (setf zn
(* (+ zn lam
) 1/4))
381 (setf an
(* (+ an lam
) 1/4))
383 ;; c1=-3/14,c2=1/6,c3=9/88,c4=9/22,c5=-3/22,c6=-9/52,c7=3/26
384 (let* ((xndev (/ (* (- a x
) power4
) an
))
385 (yndev (/ (* (- a y
) power4
) an
))
386 (zndev (- (* (+ xndev yndev
) 1/3)))
387 (ee2 (- (* xndev yndev
) (* 6 zndev zndev
)))
388 (ee3 (* (- (* 3 xndev yndev
)
391 (ee4 (* 3 (- (* xndev yndev
) (* zndev zndev
)) zndev zndev
))
392 (ee5 (* xndev yndev zndev zndev zndev
))
400 (* -
1/16 ee2 ee2 ee2
)
403 (* 45/272 ee2 ee2 ee3
)
404 (* -
9/68 (+ (* ee2 ee5
) (* ee3 ee4
))))))
409 ;; See https://dlmf.nist.gov/19.16.E1
411 ;; rf(x,y,z) = 1/2*integrate(1/(sqrt(t+x)*sqrt(t+y)*sqrt(t+z)), t, 0, inf);
418 (a (/ (+ xn yn zn
) 3))
419 (epslon (/ (max (abs (- a xn
))
426 xnroot ynroot znroot lam
)
427 (loop while
(> (* power4 epslon
) (abs an
))
429 (setf xnroot
(sqrt xn
))
430 (setf ynroot
(sqrt yn
))
431 (setf znroot
(sqrt zn
))
432 (setf lam
(+ (* xnroot ynroot
)
435 (setf power4
(* power4
1/4))
436 (setf xn
(* (+ xn lam
) 1/4))
437 (setf yn
(* (+ yn lam
) 1/4))
438 (setf zn
(* (+ zn lam
) 1/4))
439 (setf an
(* (+ an lam
) 1/4))
441 ;; c1=-3/14,c2=1/6,c3=9/88,c4=9/22,c5=-3/22,c6=-9/52,c7=3/26
442 (let* ((xndev (/ (* (- a x
) power4
) an
))
443 (yndev (/ (* (- a y
) power4
) an
))
444 (zndev (- (+ xndev yndev
)))
445 (ee2 (- (* xndev yndev
) (* 6 zndev zndev
)))
446 (ee3 (* xndev yndev zndev
))
454 (defun bf-rj1 (x y z p
)
465 (a (/ (+ xn yn zn pn pn
) 5))
466 (epslon (/ (max (abs (- a xn
))
472 xnroot ynroot znroot pnroot lam dn
)
473 (loop while
(> (* power4 epslon
) (abs an
))
475 (setf xnroot
(sqrt xn
))
476 (setf ynroot
(sqrt yn
))
477 (setf znroot
(sqrt zn
))
478 (setf pnroot
(sqrt pn
))
479 (setf lam
(+ (* xnroot ynroot
)
482 (setf dn
(* (+ pnroot xnroot
)
487 (bf-rc 1 (+ 1 (/ en
(* dn dn
)))))
489 (setf power4
(* power4
1/4))
491 (setf xn
(* (+ xn lam
) 1/4))
492 (setf yn
(* (+ yn lam
) 1/4))
493 (setf zn
(* (+ zn lam
) 1/4))
494 (setf pn
(* (+ pn lam
) 1/4))
495 (setf an
(* (+ an lam
) 1/4))
497 (let* ((xndev (/ (* (- a x
) power4
) an
))
498 (yndev (/ (* (- a y
) power4
) an
))
499 (zndev (/ (* (- a z
) power4
) an
))
500 (pndev (* -
0.5 (+ xndev yndev zndev
)))
501 (ee2 (+ (* xndev yndev
)
505 (ee3 (+ (* xndev yndev zndev
)
507 (* 4 pndev pndev pndev
)))
508 (ee4 (* (+ (* 2 xndev yndev zndev
)
510 (* 3 pndev pndev pndev
))
512 (ee5 (* xndev yndev zndev pndev pndev
))
520 (* -
1/16 ee2 ee2 ee2
)
523 (* 45/272 ee2 ee2 ee3
)
524 (* -
9/68 (+ (* ee2 ee5
) (* ee3 ee4
))))))
527 (sqrt (* an an an
)))))))
529 (defun bf-rj (x y z p
)
534 (cond ((and (and (zerop (imagpart xn
)) (>= (realpart xn
) 0))
535 (and (zerop (imagpart yn
)) (>= (realpart yn
) 0))
536 (and (zerop (imagpart zn
)) (>= (realpart zn
) 0))
537 (and (zerop (imagpart qn
)) (> (realpart qn
) 0)))
538 (destructuring-bind (xn yn zn
)
539 (sort (list xn yn zn
) #'<)
540 (let* ((pn (+ yn
(* (- zn yn
) (/ (- yn xn
) (+ yn qn
)))))
541 (s (- (* (- pn yn
) (bf-rj1 xn yn zn pn
))
542 (* 3 (bf-rf xn yn zn
)))))
543 (setf s
(+ s
(* 3 (sqrt (/ (* xn yn zn
)
544 (+ (* xn zn
) (* pn qn
))))
545 (bf-rc (+ (* xn zn
) (* pn qn
)) (* pn qn
)))))
552 (+ (* z
(bf-rf x y z
))
557 (sqrt (/ (* x y
) z
)))))
559 ;; elliptic_f(phi,m) = sin(phi)*rf(cos(phi)^2, 1-m*sin(phi)^2,1)
560 (defun bf-elliptic-f (phi m
)
563 ;; F(z|1) = log(tan(z/2+%pi/4))
564 (log (tan (+ (/ phi
2) (/ (%pi phi
) 4)))))
568 (* s
(bf-rf (* c c
) (- 1 (* m s s
)) 1)))))))
569 ;; Handle periodicity (see elliptic-f)
570 (let* ((bfpi (%pi phi
))
571 (period (round (realpart phi
) bfpi
)))
572 (+ (base (- phi
(* bfpi period
)) m
)
575 (* 2 period
(bf-elliptic-k m
)))))))
577 ;; elliptic_kc(k) = rf(0, 1-k^2,1)
580 ;; elliptic_kc(m) = rf(0, 1-m,1)
582 (defun bf-elliptic-k (m)
584 (if (maxima::$bfloatp m
)
585 (maxima::$bfloat
(maxima::div
'maxima
::$%pi
2))
586 (float (/ pi
2) 1e0
)))
589 (intl:gettext
"elliptic_kc: elliptic_kc(1) is undefined.")))
591 (bf-rf 0 (- 1 m
) 1))))
593 ;; elliptic_e(phi, k) = sin(phi)*rf(cos(phi)^2,1-k^2*sin(phi)^2,1)
594 ;; - (k^2/3)*sin(phi)^3*rd(cos(phi)^2, 1-k^2*sin(phi)^2,1)
598 ;; elliptic_e(phi, m) = sin(phi)*rf(cos(phi)^2,1-m*sin(phi)^2,1)
599 ;; - (m/3)*sin(phi)^3*rd(cos(phi)^2, 1-m*sin(phi)^2,1)
601 (defun bf-elliptic-e (phi m
)
606 (s2 (- 1 (* m s s
))))
607 (- (* s
(bf-rf c2 s2
1))
608 (* (/ m
3) (* s s s
) (bf-rd c2 s2
1))))))
609 ;; Elliptic E is quasi-periodic wrt to phi:
611 ;; E(z|m) = E(z - %pi*round(Re(z)/%pi)|m) + 2*round(Re(z)/%pi)*E(m)
612 (let* ((bfpi (%pi phi
))
613 (period (round (realpart phi
) bfpi
)))
614 (+ (base (- phi
(* bfpi period
)) m
)
615 (* 2 period
(bf-elliptic-ec m
))))))
618 ;; elliptic_ec(k) = rf(0,1-k^2,1) - (k^2/3)*rd(0,1-k^2,1);
621 ;; elliptic_ec(m) = rf(0,1-m,1) - (m/3)*rd(0,1-m,1);
623 (defun bf-elliptic-ec (m)
625 (if (typep m
'bigfloat
)
626 (bigfloat (maxima::$bfloat
(maxima::div
'maxima
::$%pi
2)))
627 (float (/ pi
2) 1e0
)))
629 (if (typep m
'bigfloat
)
635 (* m
1/3 (bf-rd 0 m1
1)))))))
637 (defun bf-elliptic-pi-complete (n m
)
638 (+ (bf-rf 0 (- 1 m
) 1)
639 (* 1/3 n
(bf-rj 0 (- 1 m
) 1 (- 1 n
)))))
641 (defun bf-elliptic-pi (n phi m
)
642 ;; Note: Carlson's DRJ has n defined as the negative of the n given
644 (flet ((base (n phi m
)
649 (k2sin (* (- 1 (* k sin-phi
))
650 (+ 1 (* k sin-phi
)))))
651 (- (* sin-phi
(bf-rf (expt cos-phi
2) k2sin
1.0))
652 (* (/ nn
3) (expt sin-phi
3)
653 (bf-rj (expt cos-phi
2) k2sin
1.0
654 (- 1 (* n
(expt sin-phi
2)))))))))
655 ;; FIXME: Reducing the arg by pi has significant round-off.
656 ;; Consider doing something better.
657 (let* ((bf-pi (%pi
(realpart phi
)))
658 (cycles (round (realpart phi
) bf-pi
))
659 (rem (- phi
(* cycles bf-pi
))))
660 (let ((complete (bf-elliptic-pi-complete n m
)))
661 (+ (* 2 cycles complete
)
664 ;; Compute inverse_jacobi_sn, for float or bigfloat args.
665 (defun bf-inverse-jacobi-sn (u m
)
666 (* u
(bf-rf (- 1 (* u u
))
670 ;; Compute inverse_jacobi_dn. We use the following identity
671 ;; from Gradshteyn & Ryzhik, 8.153.6
673 ;; w = dn(z|m) = cn(sqrt(m)*z, 1/m)
675 ;; Solve for z to get
677 ;; z = inverse_jacobi_dn(w,m)
678 ;; = 1/sqrt(m) * inverse_jacobi_cn(w, 1/m)
679 (defun bf-inverse-jacobi-dn (w m
)
683 ;; jacobi_dn(x,1) = sech(x) so the inverse is asech(x)
684 (maxima::take
'(maxima::%asech
) (maxima::to w
)))
686 ;; We should do something better to make sure that things
687 ;; that should be real are real.
688 (/ (to (maxima::take
'(maxima::%inverse_jacobi_cn
)
695 ;; Tell maxima what the derivatives are.
697 ;; Lawden says the derivative wrt to k but that's not what we want.
699 ;; Here's the derivation we used, based on how Lawden gets his results.
703 ;; diff(sn(u,m),m) = s
704 ;; diff(cn(u,m),m) = p
705 ;; diff(dn(u,m),m) = q
707 ;; From the derivatives of sn, cn, dn wrt to u, we have
709 ;; diff(sn(u,m),u) = cn(u)*dn(u)
710 ;; diff(cn(u,m),u) = -cn(u)*dn(u)
711 ;; diff(dn(u,m),u) = -m*sn(u)*cn(u)
714 ;; Differentiate these wrt to m:
716 ;; diff(s,u) = p*dn + cn*q
717 ;; diff(p,u) = -p*dn - q*dn
718 ;; diff(q,u) = -sn*cn - m*s*cn - m*sn*q
722 ;; sn(u)^2 + cn(u)^2 = 1
723 ;; dn(u)^2 + m*sn(u)^2 = 1
725 ;; Differentiate these wrt to m:
728 ;; 2*dn*q + sn^2 + 2*m*sn*s = 0
733 ;; q = -m*s*sn/dn - sn^2/dn/2
736 ;; diff(s,u) = -s*sn*dn/cn - m*s*sn*cn/dn - sn^2*cn/dn/2
740 ;; diff(s,u) + s*(sn*dn/cn + m*sn*cn/dn) = -1/2*sn^2*cn/dn
742 ;; diff(s,u) + s*sn/cn/dn*(dn^2 + m*cn^2) = -1/2*sn^2*cn/dn
744 ;; Multiply through by the integrating factor 1/cn/dn:
746 ;; diff(s/cn/dn, u) = -1/2*sn^2/dn^2 = -1/2*sd^2.
748 ;; Integrate this to get
750 ;; s/cn/dn = C + -1/2*int sd^2
752 ;; It can be shown that C is zero.
754 ;; We know that (by differentiating this expression)
756 ;; int dn^2 = (1-m)*u+m*sn*cd + m*(1-m)*int sd^2
760 ;; int sd^2 = 1/m/(1-m)*int dn^2 - u/m - sn*cd/(1-m)
764 ;; s/cn/dn = u/(2*m) + sn*cd/(2*(1-m)) - 1/2/m/(1-m)*int dn^2
768 ;; s = 1/(2*m)*u*cn*dn + 1/(2*(1-m))*sn*cn^2 - 1/2/(m*(1-m))*cn*dn*E(u)
770 ;; where E(u) = int dn^2 = elliptic_e(am(u)) = elliptic_e(asin(sn(u)))
772 ;; This is our desired result:
774 ;; s = 1/(2*m)*cn*dn*[u - elliptic_e(asin(sn(u)),m)/(1-m)] + sn*cn^2/2/(1-m)
777 ;; Since diff(cn(u,m),m) = p = -s*sn/cn, we have
779 ;; p = -1/(2*m)*sn*dn[u - elliptic_e(asin(sn(u)),m)/(1-m)] - sn^2*cn/2/(1-m)
781 ;; diff(dn(u,m),m) = q = -m*s*sn/dn - sn^2/dn/2
783 ;; q = -1/2*sn*cn*[u-elliptic_e(asin(sn),m)/(1-m)] - m*sn^2*cn^2/dn/2/(1-m)
787 ;; = -1/2*sn*cn*[u-elliptic_e(asin(sn),m)/(1-m)] + dn*sn^2/2/(m-1)
791 ((mtimes) ((%jacobi_cn
) u m
) ((%jacobi_dn
) u m
))
793 ((mtimes simp
) ((rat simp
) 1 2)
794 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
795 ((mexpt simp
) ((%jacobi_cn simp
) u m
) 2) ((%jacobi_sn simp
) u m
))
796 ((mtimes simp
) ((rat simp
) 1 2) ((mexpt simp
) m -
1)
797 ((%jacobi_cn simp
) u m
) ((%jacobi_dn simp
) u m
)
799 ((mtimes simp
) -
1 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
800 ((%elliptic_e simp
) ((%asin simp
) ((%jacobi_sn simp
) u m
)) m
))))))
805 ((mtimes simp
) -
1 ((%jacobi_sn simp
) u m
) ((%jacobi_dn simp
) u m
))
807 ((mtimes simp
) ((rat simp
) -
1 2)
808 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
809 ((%jacobi_cn simp
) u m
) ((mexpt simp
) ((%jacobi_sn simp
) u m
) 2))
810 ((mtimes simp
) ((rat simp
) -
1 2) ((mexpt simp
) m -
1)
811 ((%jacobi_dn simp
) u m
) ((%jacobi_sn simp
) u m
)
813 ((mtimes simp
) -
1 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
814 ((%elliptic_e simp
) ((%asin simp
) ((%jacobi_sn simp
) u m
)) m
))))))
819 ((mtimes) -
1 m
((%jacobi_sn
) u m
) ((%jacobi_cn
) u m
))
821 ((mtimes simp
) ((rat simp
) -
1 2)
822 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
823 ((%jacobi_dn simp
) u m
) ((mexpt simp
) ((%jacobi_sn simp
) u m
) 2))
824 ((mtimes simp
) ((rat simp
) -
1 2) ((%jacobi_cn simp
) u m
)
825 ((%jacobi_sn simp
) u m
)
828 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
829 ((%elliptic_e simp
) ((%asin simp
) ((%jacobi_sn simp
) u m
)) m
))))))
832 ;; The inverse elliptic functions.
834 ;; F(phi|m) = asn(sin(phi),m)
836 ;; so asn(u,m) = F(asin(u)|m)
837 (defprop %inverse_jacobi_sn
840 ;; inverse_jacobi_sn(x) = integrate(1/sqrt(1-t^2)/sqrt(1-m*t^2),t,0,x)
841 ;; -> 1/sqrt(1-x^2)/sqrt(1-m*x^2)
843 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))
845 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
((mexpt simp
) x
2)))
847 ;; diff(F(asin(u)|m),m)
848 ((mtimes simp
) ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
851 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))
853 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
((mexpt simp
) x
2)))
855 ((mtimes simp
) ((mexpt simp
) m -
1)
856 ((mplus simp
) ((%elliptic_e simp
) ((%asin simp
) x
) m
)
857 ((mtimes simp
) -
1 ((mplus simp
) 1 ((mtimes simp
) -
1 m
))
858 ((%elliptic_f simp
) ((%asin simp
) x
) m
)))))))
861 ;; Let u = inverse_jacobi_cn(x). Then jacobi_cn(u) = x or
862 ;; sqrt(1-jacobi_sn(u)^2) = x. Or
864 ;; jacobi_sn(u) = sqrt(1-x^2)
866 ;; So u = inverse_jacobi_sn(sqrt(1-x^2),m) = inverse_jacob_cn(x,m)
868 (defprop %inverse_jacobi_cn
870 ;; Whittaker and Watson, 22.121
871 ;; inverse_jacobi_cn(u,m) = integrate(1/sqrt(1-t^2)/sqrt(1-m+m*t^2), t, u, 1)
872 ;; -> -1/sqrt(1-x^2)/sqrt(1-m+m*x^2)
874 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))
877 ((mplus simp
) 1 ((mtimes simp
) -
1 m
)
878 ((mtimes simp
) m
((mexpt simp
) x
2)))
880 ((mtimes simp
) ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
885 ((mtimes simp
) -
1 m
((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))))
887 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2))) ((rat simp
) 1 2))
889 ((mtimes simp
) ((mexpt simp
) m -
1)
893 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2))) ((rat simp
) 1 2)))
895 ((mtimes simp
) -
1 ((mplus simp
) 1 ((mtimes simp
) -
1 m
))
898 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2))) ((rat simp
) 1 2)))
902 ;; Let u = inverse_jacobi_dn(x). Then
904 ;; jacobi_dn(u) = x or
906 ;; x^2 = jacobi_dn(u)^2 = 1 - m*jacobi_sn(u)^2
908 ;; so jacobi_sn(u) = sqrt(1-x^2)/sqrt(m)
910 ;; or u = inverse_jacobi_sn(sqrt(1-x^2)/sqrt(m))
911 (defprop %inverse_jacobi_dn
913 ;; Whittaker and Watson, 22.121
914 ;; inverse_jacobi_dn(u,m) = integrate(1/sqrt(1-t^2)/sqrt(t^2-(1-m)), t, u, 1)
915 ;; -> -1/sqrt(1-x^2)/sqrt(x^2+m-1)
917 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))
919 ((mexpt simp
) ((mplus simp
) -
1 m
((mexpt simp
) x
2)) ((rat simp
) -
1 2)))
921 ((mtimes simp
) ((rat simp
) -
1 2) ((mexpt simp
) m
((rat simp
) -
3 2))
924 ((mtimes simp
) -
1 ((mexpt simp
) m -
1)
925 ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))))
927 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))
929 ((mexpt simp
) ((mabs simp
) x
) -
1))
930 ((mtimes simp
) ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
932 ((mtimes simp
) -
1 ((mexpt simp
) m
((rat simp
) -
1 2))
935 ((mtimes simp
) -
1 ((mexpt simp
) m -
1)
936 ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))))
938 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))
940 ((mexpt simp
) ((mabs simp
) x
) -
1))
941 ((mtimes simp
) ((mexpt simp
) m -
1)
945 ((mtimes simp
) ((mexpt simp
) m
((rat simp
) -
1 2))
946 ((mexpt simp
) ((mplus simp
) 1
947 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))
950 ((mtimes simp
) -
1 ((mplus simp
) 1 ((mtimes simp
) -
1 m
))
953 ((mtimes simp
) ((mexpt simp
) m
((rat simp
) -
1 2))
954 ((mexpt simp
) ((mplus simp
) 1
955 ((mtimes simp
) -
1 ((mexpt simp
) x
2)))
961 ;; Possible forms of a complex number:
965 ;; ((mplus simp) 2.3 ((mtimes simp) 2.3 $%i))
966 ;; ((mplus simp) 2.3 $%i))
967 ;; ((mtimes simp) 2.3 $%i)
971 ;; Is argument u a complex number with real and imagpart satisfying predicate ntypep?
972 (defun complex-number-p (u &optional
(ntypep 'numberp
))
974 (labels ((a1 (x) (cadr x
))
977 (N (x) (funcall ntypep x
)) ; N
978 (i (x) (and (eq x
'$%i
) (N 1))) ; %i
979 (N+i
(x) (and (null (a3+ x
)) ; mplus test is precondition
981 (or (and (i (a2 x
)) (setq I
1) t
)
982 (and (mtimesp (a2 x
)) (N*i
(a2 x
))))))
983 (N*i
(x) (and (null (a3+ x
)) ; mtimes test is precondition
986 (declare (inline a1 a2 a3
+ N i N
+i N
*i
))
987 (cond ((N u
) (values t u
0)) ;2.3
988 ((atom u
) (if (i u
) (values t
0 1))) ;%i
989 ((mplusp u
) (if (N+i u
) (values t R I
))) ;N+%i, N+N*%i
990 ((mtimesp u
) (if (N*i u
) (values t R I
))) ;N*%i
993 (defun complexify (x)
994 ;; Convert a Lisp number to a maxima number
996 ((complexp x
) (add (realpart x
) (mul '$%i
(imagpart x
))))
997 (t (merror (intl:gettext
"COMPLEXIFY: argument must be a Lisp real or complex number.~%COMPLEXIFY: found: ~:M") x
))))
999 (defun kc-arg (exp m
)
1000 ;; Replace elliptic_kc(m) in the expression with sym. Check to see
1001 ;; if the resulting expression is linear in sym and the constant
1002 ;; term is zero. If so, return the coefficient of sym, i.e, the
1003 ;; coefficient of elliptic_kc(m).
1004 (let* ((sym (gensym))
1005 (arg (maxima-substitute sym
`((%elliptic_kc
) ,m
) exp
)))
1006 (if (and (not (equalp arg exp
))
1008 (zerop1 (coefficient arg sym
0)))
1009 (coefficient arg sym
1)
1012 (defun kc-arg2 (exp m
)
1013 ;; Replace elliptic_kc(m) in the expression with sym. Check to see
1014 ;; if the resulting expression is linear in sym and the constant
1015 ;; term is zero. If so, return the coefficient of sym, i.e, the
1016 ;; coefficient of elliptic_kc(m), and the constant term. Otherwise,
1018 (let* ((sym (gensym))
1019 (arg (maxima-substitute sym
`((%elliptic_kc
) ,m
) exp
)))
1020 (if (and (not (equalp arg exp
))
1022 (list (coefficient arg sym
1)
1023 (coefficient arg sym
0))
1026 ;; Tell maxima how to simplify the functions
1028 (def-simplifier jacobi_sn
(u m
)
1031 ((float-numerical-eval-p u m
)
1032 (to (bigfloat::sn
(bigfloat:to
($float u
)) (bigfloat:to
($float m
)))))
1033 ((setf args
(complex-float-numerical-eval-p u m
))
1034 (destructuring-bind (u m
)
1036 (to (bigfloat::sn
(bigfloat:to
($float u
)) (bigfloat:to
($float m
))))))
1037 ((bigfloat-numerical-eval-p u m
)
1038 (to (bigfloat::sn
(bigfloat:to
($bfloat u
)) (bigfloat:to
($bfloat m
)))))
1039 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
1040 (destructuring-bind (u m
)
1042 (to (bigfloat::sn
(bigfloat:to
($bfloat u
)) (bigfloat:to
($bfloat m
))))))
1052 ((and $trigsign
(mminusp* u
))
1053 (neg (ftake* '%jacobi_sn
(neg u
) m
)))
1056 (member (caar u
) '(%inverse_jacobi_sn
1067 %inverse_jacobi_dc
))
1068 (alike1 (third u
) m
))
1069 (let ((inv-arg (second u
)))
1072 ;; jacobi_sn(inverse_jacobi_sn(u,m), m) = u
1075 ;; inverse_jacobi_ns(u,m) = inverse_jacobi_sn(1/u,m)
1078 ;; sn(x)^2 + cn(x)^2 = 1 so sn(x) = sqrt(1-cn(x)^2)
1079 (power (sub 1 (mul inv-arg inv-arg
)) 1//2))
1081 ;; inverse_jacobi_nc(u) = inverse_jacobi_cn(1/u)
1082 (ftake '%jacobi_sn
(ftake '%inverse_jacobi_cn
(div 1 inv-arg
) m
)
1085 ;; dn(x)^2 + m*sn(x)^2 = 1 so
1086 ;; sn(x) = 1/sqrt(m)*sqrt(1-dn(x)^2)
1087 (mul (div 1 (power m
1//2))
1088 (power (sub 1 (mul inv-arg inv-arg
)) 1//2)))
1090 ;; inverse_jacobi_nd(u) = inverse_jacobi_dn(1/u)
1091 (ftake '%jacobi_sn
(ftake '%inverse_jacobi_dn
(div 1 inv-arg
) m
)
1094 ;; See below for inverse_jacobi_sc.
1095 (div inv-arg
(power (add 1 (mul inv-arg inv-arg
)) 1//2)))
1097 ;; inverse_jacobi_cs(u) = inverse_jacobi_sc(1/u)
1098 (ftake '%jacobi_sn
(ftake '%inverse_jacobi_sc
(div 1 inv-arg
) m
)
1101 ;; See below for inverse_jacobi_sd
1102 (div inv-arg
(power (add 1 (mul m
(mul inv-arg inv-arg
))) 1//2)))
1104 ;; inverse_jacobi_ds(u) = inverse_jacobi_sd(1/u)
1105 (ftake '%jacobi_sn
(ftake '%inverse_jacobi_sd
(div 1 inv-arg
) m
)
1109 (div (power (sub 1 (mul inv-arg inv-arg
)) 1//2)
1110 (power (sub 1 (mul m
(mul inv-arg inv-arg
))) 1//2)))
1112 (ftake '%jacobi_sn
(ftake '%inverse_jacobi_cd
(div 1 inv-arg
) m
) m
)))))
1113 ;; A&S 16.20.1 (Jacobi's Imaginary transformation)
1114 ((and $%iargs
(multiplep u
'$%i
))
1116 (ftake* '%jacobi_sc
(coeff u
'$%i
1) (add 1 (neg m
)))))
1117 ((setq coef
(kc-arg2 u m
))
1121 (destructuring-bind (lin const
)
1123 (cond ((integerp lin
)
1126 ;; sn(4*m*K + u) = sn(u), sn(0) = 0
1129 (ftake '%jacobi_sn const m
)))
1131 ;; sn(4*m*K + K + u) = sn(K+u) = cd(u)
1135 (ftake '%jacobi_cd const m
)))
1137 ;; sn(4*m*K+2*K + u) = sn(2*K+u) = -sn(u)
1141 (neg (ftake '%jacobi_sn const m
))))
1143 ;; sn(4*m*K+3*K+u) = sn(2*K + K + u) = -sn(K+u) = -cd(u)
1147 (neg (ftake '%jacobi_cd const m
))))))
1148 ((and (alike1 lin
1//2)
1152 ;; sn(1/2*K) = 1/sqrt(1+sqrt(1-m))
1154 (power (add 1 (power (sub 1 m
) 1//2))
1156 ((and (alike1 lin
3//2)
1160 ;; sn(1/2*K + K) = cd(1/2*K,m)
1161 (ftake '%jacobi_cd
(mul 1//2
1162 (ftake '%elliptic_kc m
))
1170 (def-simplifier jacobi_cn
(u m
)
1173 ((float-numerical-eval-p u m
)
1174 (to (bigfloat::cn
(bigfloat:to
($float u
)) (bigfloat:to
($float m
)))))
1175 ((setf args
(complex-float-numerical-eval-p u m
))
1176 (destructuring-bind (u m
)
1178 (to (bigfloat::cn
(bigfloat:to
($float u
)) (bigfloat:to
($float m
))))))
1179 ((bigfloat-numerical-eval-p u m
)
1180 (to (bigfloat::cn
(bigfloat:to
($bfloat u
)) (bigfloat:to
($bfloat m
)))))
1181 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
1182 (destructuring-bind (u m
)
1184 (to (bigfloat::cn
(bigfloat:to
($bfloat u
)) (bigfloat:to
($bfloat m
))))))
1194 ((and $trigsign
(mminusp* u
))
1195 (ftake* '%jacobi_cn
(neg u
) m
))
1198 (member (caar u
) '(%inverse_jacobi_sn
1209 %inverse_jacobi_dc
))
1210 (alike1 (third u
) m
))
1211 (cond ((eq (caar u
) '%inverse_jacobi_cn
)
1214 ;; I'm lazy. Use cn(x) = sqrt(1-sn(x)^2). Hope
1216 (power (sub 1 (power (ftake '%jacobi_sn u
(third u
)) 2))
1218 ;; A&S 16.20.2 (Jacobi's Imaginary transformation)
1219 ((and $%iargs
(multiplep u
'$%i
))
1220 (ftake* '%jacobi_nc
(coeff u
'$%i
1) (add 1 (neg m
))))
1221 ((setq coef
(kc-arg2 u m
))
1225 (destructuring-bind (lin const
)
1227 (cond ((integerp lin
)
1230 ;; cn(4*m*K + u) = cn(u),
1234 (ftake '%jacobi_cn const m
)))
1236 ;; cn(4*m*K + K + u) = cn(K+u) = -sqrt(m1)*sd(u)
1240 (neg (mul (power (sub 1 m
) 1//2)
1241 (ftake '%jacobi_sd const m
)))))
1243 ;; cn(4*m*K + 2*K + u) = cn(2*K+u) = -cn(u)
1247 (neg (ftake '%jacobi_cn const m
))))
1249 ;; cn(4*m*K + 3*K + u) = cn(2*K + K + u) =
1250 ;; -cn(K+u) = sqrt(m1)*sd(u)
1255 (mul (power (sub 1 m
) 1//2)
1256 (ftake '%jacobi_sd const m
))))))
1257 ((and (alike1 lin
1//2)
1260 ;; cn(1/2*K) = (1-m)^(1/4)/sqrt(1+sqrt(1-m))
1261 (mul (power (sub 1 m
) (div 1 4))
1271 (def-simplifier jacobi_dn
(u m
)
1274 ((float-numerical-eval-p u m
)
1275 (to (bigfloat::dn
(bigfloat:to
($float u
)) (bigfloat:to
($float m
)))))
1276 ((setf args
(complex-float-numerical-eval-p u m
))
1277 (destructuring-bind (u m
)
1279 (to (bigfloat::dn
(bigfloat:to
($float u
)) (bigfloat:to
($float m
))))))
1280 ((bigfloat-numerical-eval-p u m
)
1281 (to (bigfloat::dn
(bigfloat:to
($bfloat u
)) (bigfloat:to
($bfloat m
)))))
1282 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
1283 (destructuring-bind (u m
)
1285 (to (bigfloat::dn
(bigfloat:to
($bfloat u
)) (bigfloat:to
($bfloat m
))))))
1295 ((and $trigsign
(mminusp* u
))
1296 (ftake* '%jacobi_dn
(neg u
) m
))
1299 (member (caar u
) '(%inverse_jacobi_sn
1310 %inverse_jacobi_dc
))
1311 (alike1 (third u
) m
))
1312 (cond ((eq (caar u
) '%inverse_jacobi_dn
)
1313 ;; jacobi_dn(inverse_jacobi_dn(u,m), m) = u
1316 ;; Express in terms of sn:
1317 ;; dn(x) = sqrt(1-m*sn(x)^2)
1318 (power (sub 1 (mul m
1319 (power (ftake '%jacobi_sn u m
) 2)))
1321 ((zerop1 ($ratsimp
(sub u
(power (sub 1 m
) 1//2))))
1323 ;; dn(sqrt(1-m),m) = K(m)
1324 (ftake '%elliptic_kc m
))
1325 ;; A&S 16.20.2 (Jacobi's Imaginary transformation)
1326 ((and $%iargs
(multiplep u
'$%i
))
1327 (ftake* '%jacobi_dc
(coeff u
'$%i
1)
1329 ((setq coef
(kc-arg2 u m
))
1332 ;; dn(m*K+u) has period 2K
1334 (destructuring-bind (lin const
)
1336 (cond ((integerp lin
)
1339 ;; dn(2*m*K + u) = dn(u)
1343 ;; dn(4*m*K+2*K + u) = dn(2*K+u) = dn(u)
1344 (ftake '%jacobi_dn const m
)))
1346 ;; dn(2*m*K + K + u) = dn(K + u) = sqrt(1-m)*nd(u)
1347 ;; dn(K) = sqrt(1-m)
1349 (power (sub 1 m
) 1//2)
1350 (mul (power (sub 1 m
) 1//2)
1351 (ftake '%jacobi_nd const m
))))))
1352 ((and (alike1 lin
1//2)
1355 ;; dn(1/2*K) = (1-m)^(1/4)
1362 ;; Should we simplify the inverse elliptic functions into the
1363 ;; appropriate incomplete elliptic integral? I think we should leave
1364 ;; it, but perhaps allow some way to do that transformation if
1367 (def-simplifier inverse_jacobi_sn
(u m
)
1369 ;; To numerically evaluate inverse_jacobi_sn (asn), use
1371 ;; asn(x,m) = F(asin(x),m)
1373 ;; But F(phi,m) = sin(phi)*rf(cos(phi)^2, 1-m*sin(phi)^2,1). Thus
1375 ;; asn(x,m) = F(asin(x),m)
1376 ;; = x*rf(1-x^2,1-m*x^2,1)
1378 ;; I (rtoy) am not 100% about the first identity above for all
1379 ;; complex values of x and m, but tests seem to indicate that it
1380 ;; produces the correct value as verified by verifying
1381 ;; jacobi_sn(inverse_jacobi_sn(x,m),m) = x.
1382 (cond ((float-numerical-eval-p u m
)
1383 (let ((uu (bigfloat:to
($float u
)))
1384 (mm (bigfloat:to
($float m
))))
1387 (bigfloat::bf-rf
(bigfloat:to
(- 1 (* uu uu
)))
1388 (bigfloat:to
(- 1 (* mm uu uu
)))
1390 ((setf args
(complex-float-numerical-eval-p u m
))
1391 (destructuring-bind (u m
)
1393 (let ((uu (bigfloat:to
($float u
)))
1394 (mm (bigfloat:to
($float m
))))
1395 (complexify (* uu
(bigfloat::bf-rf
(- 1 (* uu uu
))
1398 ((bigfloat-numerical-eval-p u m
)
1399 (let ((uu (bigfloat:to u
))
1400 (mm (bigfloat:to m
)))
1402 (bigfloat::bf-rf
(bigfloat:-
1 (bigfloat:* uu uu
))
1403 (bigfloat:-
1 (bigfloat:* mm uu uu
))
1405 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
1406 (destructuring-bind (u m
)
1408 (let ((uu (bigfloat:to u
))
1409 (mm (bigfloat:to m
)))
1411 (bigfloat::bf-rf
(bigfloat:-
1 (bigfloat:* uu uu
))
1412 (bigfloat:-
1 (bigfloat:* mm uu uu
))
1418 ;; asn(1,m) = elliptic_kc(m)
1419 (ftake '%elliptic_kc m
))
1420 ((and (numberp u
) (onep1 (- u
)))
1421 ;; asn(-1,m) = -elliptic_kc(m)
1422 (mul -
1 (ftake '%elliptic_kc m
)))
1424 ;; asn(x,0) = F(asin(x),0) = asin(x)
1427 ;; asn(x,1) = F(asin(x),1) = log(tan(pi/4+asin(x)/2))
1428 (ftake '%elliptic_f
(ftake '%asin u
) 1))
1429 ((and (eq $triginverses
'$all
)
1431 (eq (caar u
) '%jacobi_sn
)
1432 (alike1 (third u
) m
))
1433 ;; inverse_jacobi_sn(sn(u)) = u
1439 (def-simplifier inverse_jacobi_cn
(u m
)
1441 (cond ((float-numerical-eval-p u m
)
1442 ;; Numerically evaluate acn
1444 ;; acn(x,m) = F(acos(x),m)
1445 (to (elliptic-f (cl:acos
($float u
)) ($float m
))))
1446 ((setf args
(complex-float-numerical-eval-p u m
))
1447 (destructuring-bind (u m
)
1449 (to (elliptic-f (cl:acos
(bigfloat:to
($float u
)))
1450 (bigfloat:to
($float m
))))))
1451 ((bigfloat-numerical-eval-p u m
)
1452 (to (bigfloat::bf-elliptic-f
(bigfloat:acos
(bigfloat:to u
))
1454 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
1455 (destructuring-bind (u m
)
1457 (to (bigfloat::bf-elliptic-f
(bigfloat:acos
(bigfloat:to u
))
1460 ;; asn(x,0) = F(acos(x),0) = acos(x)
1461 (ftake '%elliptic_f
(ftake '%acos u
) 0))
1463 ;; asn(x,1) = F(asin(x),1) = log(tan(pi/2+asin(x)/2))
1464 (ftake '%elliptic_f
(ftake '%acos u
) 1))
1466 (ftake '%elliptic_kc m
))
1469 ((and (eq $triginverses
'$all
)
1471 (eq (caar u
) '%jacobi_cn
)
1472 (alike1 (third u
) m
))
1473 ;; inverse_jacobi_cn(cn(u)) = u
1479 (def-simplifier inverse_jacobi_dn
(u m
)
1481 (cond ((float-numerical-eval-p u m
)
1482 (to (bigfloat::bf-inverse-jacobi-dn
(bigfloat:to
(float u
))
1483 (bigfloat:to
(float m
)))))
1484 ((setf args
(complex-float-numerical-eval-p u m
))
1485 (destructuring-bind (u m
)
1487 (let ((uu (bigfloat:to
($float u
)))
1488 (mm (bigfloat:to
($float m
))))
1489 (to (bigfloat::bf-inverse-jacobi-dn uu mm
)))))
1490 ((bigfloat-numerical-eval-p u m
)
1491 (let ((uu (bigfloat:to u
))
1492 (mm (bigfloat:to m
)))
1493 (to (bigfloat::bf-inverse-jacobi-dn uu mm
))))
1494 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
1495 (destructuring-bind (u m
)
1497 (to (bigfloat::bf-inverse-jacobi-dn
(bigfloat:to u
) (bigfloat:to m
)))))
1499 ;; x = dn(u,1) = sech(u). so u = asech(x)
1502 ;; jacobi_dn(0,m) = 1
1504 ((zerop1 ($ratsimp
(sub u
(power (sub 1 m
) 1//2))))
1505 ;; jacobi_dn(K(m),m) = sqrt(1-m) so
1506 ;; inverse_jacobi_dn(sqrt(1-m),m) = K(m)
1507 (ftake '%elliptic_kc m
))
1508 ((and (eq $triginverses
'$all
)
1510 (eq (caar u
) '%jacobi_dn
)
1511 (alike1 (third u
) m
))
1512 ;; inverse_jacobi_dn(dn(u)) = u
1518 ;;;; Elliptic integrals
1520 (let ((errtol (expt (* 4 +flonum-epsilon
+) 1/6))
1524 (declare (type flonum errtol c1 c2 c3
))
1526 "Compute Carlson's incomplete or complete elliptic integral of the
1532 RF(x, y, z) = I ----------------------------------- dt
1533 ] SQRT(x + t) SQRT(y + t) SQRT(z + t)
1537 x, y, and z may be complex.
1539 (declare (number x y z
))
1540 (let ((x (coerce x
'(complex flonum
)))
1541 (y (coerce y
'(complex flonum
)))
1542 (z (coerce z
'(complex flonum
))))
1543 (declare (type (complex flonum
) x y z
))
1545 (let* ((mu (/ (+ x y z
) 3))
1546 (x-dev (- 2 (/ (+ mu x
) mu
)))
1547 (y-dev (- 2 (/ (+ mu y
) mu
)))
1548 (z-dev (- 2 (/ (+ mu z
) mu
))))
1549 (when (< (max (abs x-dev
) (abs y-dev
) (abs z-dev
)) errtol
)
1550 (let ((e2 (- (* x-dev y-dev
) (* z-dev z-dev
)))
1551 (e3 (* x-dev y-dev z-dev
)))
1558 (let* ((x-root (sqrt x
))
1561 (lam (+ (* x-root
(+ y-root z-root
)) (* y-root z-root
))))
1562 (setf x
(* (+ x lam
) 1/4))
1563 (setf y
(* (+ y lam
) 1/4))
1564 (setf z
(* (+ z lam
) 1/4))))))))
1566 ;; Elliptic integral of the first kind (Legendre's form):
1572 ;; I ------------------- ds
1574 ;; / SQRT(1 - m SIN (s))
1577 (defun elliptic-f (phi-arg m-arg
)
1578 (flet ((base (phi-arg m-arg
)
1579 (cond ((and (realp m-arg
) (realp phi-arg
))
1580 (let ((phi (float phi-arg
))
1585 ;; F(phi|m) = 1/sqrt(m)*F(theta|1/m)
1587 ;; with sin(theta) = sqrt(m)*sin(phi)
1588 (/ (elliptic-f (cl:asin
(* (sqrt m
) (sin phi
))) (/ m
))
1596 (- (/ (elliptic-f (float (/ pi
2)) m
/m
+1)
1598 (/ (elliptic-f (- (float (/ pi
2)) phi
) m
/m
+1)
1606 1 ;; F(phi,1) = log(sec(phi)+tan(phi))
1607 ;; = log(tan(pi/4+pi/2))
1608 (log (cl:tan
(+ (/ phi
2) (float (/ pi
4))))))
1610 (- (elliptic-f (- phi
) m
)))
1613 (multiple-value-bind (s phi-rem
)
1614 (truncate phi
(float pi
))
1615 (+ (* 2 s
(elliptic-k m
))
1616 (elliptic-f phi-rem m
))))
1618 (let ((sin-phi (sin phi
))
1622 (bigfloat::bf-rf
(* cos-phi cos-phi
)
1623 (* (- 1 (* k sin-phi
))
1624 (+ 1 (* k sin-phi
)))
1627 (+ (* 2 (elliptic-k m
))
1628 (elliptic-f (- phi
(float pi
)) m
)))
1630 (error "Shouldn't happen! Unhandled case in elliptic-f: ~S ~S~%"
1633 (let ((phi (coerce phi-arg
'(complex flonum
)))
1634 (m (coerce m-arg
'(complex flonum
))))
1635 (let ((sin-phi (sin phi
))
1639 (crf (* cos-phi cos-phi
)
1640 (* (- 1 (* k sin-phi
))
1641 (+ 1 (* k sin-phi
)))
1643 ;; Elliptic F is quasi-periodic wrt to z:
1645 ;; F(z|m) = F(z - pi*round(Re(z)/pi)|m) + 2*round(Re(z)/pi)*K(m)
1646 (let ((period (round (realpart phi-arg
) pi
)))
1647 (+ (base (- phi-arg
(* pi period
)) m-arg
)
1651 (bigfloat:to
(elliptic-k m-arg
))))))))
1653 ;; Complete elliptic integral of the first kind
1654 (defun elliptic-k (m)
1662 (- (/ (elliptic-k m
/m
+1)
1664 (/ (elliptic-f 0.0 m
/m
+1)
1671 (intl:gettext
"elliptic_kc: elliptic_kc(1) is undefined.")))
1673 (bigfloat::bf-rf
0.0 (- 1 m
)
1676 (bigfloat::bf-rf
0.0 (- 1 m
)
1679 ;; Elliptic integral of the second kind (Legendre's form):
1685 ;; I SQRT(1 - m SIN (s)) ds
1690 (defun elliptic-e (phi m
)
1691 (declare (type flonum phi m
))
1692 (flet ((base (phi m
)
1700 (let* ((sin-phi (sin phi
))
1703 (y (* (- 1 (* k sin-phi
))
1704 (+ 1 (* k sin-phi
)))))
1706 (bigfloat::bf-rf
(* cos-phi cos-phi
) y
1.0))
1709 (bigfloat::bf-rd
(* cos-phi cos-phi
) y
1.0))))))))
1710 ;; Elliptic E is quasi-periodic wrt to phi:
1712 ;; E(z|m) = E(z - %pi*round(Re(z)/%pi)|m) + 2*round(Re(z)/%pi)*E(m)
1713 (let ((period (round (realpart phi
) pi
)))
1714 (+ (base (- phi
(* pi period
)) m
)
1715 (* 2 period
(elliptic-ec m
))))))
1718 (defun elliptic-ec (m)
1719 (declare (type flonum m
))
1728 (- (bigfloat::bf-rf
0.0 y
1.0)
1730 (bigfloat::bf-rd
0.0 y
1.0)))))))
1733 ;; Define the elliptic integrals for maxima
1735 ;; We use the definitions given in A&S 17.2.6 and 17.2.8. In particular:
1740 ;; F(phi|m) = I ------------------- ds
1742 ;; / SQRT(1 - m SIN (s))
1750 ;; E(phi|m) = I SQRT(1 - m SIN (s)) ds
1755 ;; That is, we do not use the modular angle, alpha, as the second arg;
1756 ;; the parameter m = sin(alpha)^2 is used.
1760 ;; The derivative of F(phi|m) wrt to phi is easy. The derivative wrt
1761 ;; to m is harder. Here is a derivation. Hope I got it right.
1763 ;; diff(integrate(1/sqrt(1-m*sin(x)^2),x,0,phi), m);
1768 ;; I ------------------ dx
1770 ;; / (1 - m SIN (x))
1772 ;; --------------------------
1776 ;; Now use the following relationship that is easily verified:
1779 ;; (1 - m) SIN (x) COS (x) COS(x) SIN(x)
1780 ;; ------------------- = ------------------- - DIFF(-------------------, x)
1782 ;; SQRT(1 - m SIN (x)) SQRT(1 - m SIN (x)) SQRT(1 - m SIN (x))
1785 ;; Now integrate this to get:
1791 ;; (1 - m) I ------------------- dx =
1793 ;; / SQRT(1 - m SIN (x))
1800 ;; + I ------------------- dx
1802 ;; / SQRT(1 - m SIN (x))
1804 ;; COS(PHI) SIN(PHI)
1805 ;; - ---------------------
1807 ;; SQRT(1 - m SIN (PHI))
1809 ;; Use the fact that cos(x)^2 = 1 - sin(x)^2 to show that this
1810 ;; integral on the RHS is:
1813 ;; (1 - m) elliptic_F(PHI, m) + elliptic_E(PHI, m)
1814 ;; -------------------------------------------
1816 ;; So, finally, we have
1821 ;; 2 -- (elliptic_F(PHI, m)) =
1824 ;; elliptic_E(PHI, m) - (1 - m) elliptic_F(PHI, m) COS(PHI) SIN(PHI)
1825 ;; ---------------------------------------------- - ---------------------
1827 ;; SQRT(1 - m SIN (PHI))
1828 ;; ----------------------------------------------------------------------
1831 (defprop %elliptic_f
1834 ;; 1/sqrt(1-m*sin(phi)^2)
1836 ((mplus simp
) 1 ((mtimes simp
) -
1 m
((mexpt simp
) ((%sin simp
) phi
) 2)))
1839 ((mtimes simp
) ((rat simp
) 1 2)
1840 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
1842 ((mtimes simp
) ((mexpt simp
) m -
1)
1843 ((mplus simp
) ((%elliptic_e simp
) phi m
)
1844 ((mtimes simp
) -
1 ((mplus simp
) 1 ((mtimes simp
) -
1 m
))
1845 ((%elliptic_f simp
) phi m
))))
1846 ((mtimes simp
) -
1 ((%cos simp
) phi
) ((%sin simp
) phi
)
1849 ((mtimes simp
) -
1 m
((mexpt simp
) ((%sin simp
) phi
) 2)))
1850 ((rat simp
) -
1 2))))))
1854 ;; The derivative of E(phi|m) wrt to m is much simpler to derive than F(phi|m).
1856 ;; Take the derivative of the definition to get
1861 ;; I ------------------- dx
1863 ;; / SQRT(1 - m SIN (x))
1865 ;; - ---------------------------
1868 ;; It is easy to see that
1873 ;; elliptic_F(PHI, m) - m I ------------------- dx = elliptic_E(PHI, m)
1875 ;; / SQRT(1 - m SIN (x))
1878 ;; So we finally have
1880 ;; d elliptic_E(PHI, m) - elliptic_F(PHI, m)
1881 ;; -- (elliptic_E(PHI, m)) = ---------------------------------------
1884 (defprop %elliptic_e
1886 ;; sqrt(1-m*sin(phi)^2)
1888 ((mplus simp
) 1 ((mtimes simp
) -
1 m
((mexpt simp
) ((%sin simp
) phi
) 2)))
1891 ((mtimes simp
) ((rat simp
) 1 2) ((mexpt simp
) m -
1)
1892 ((mplus simp
) ((%elliptic_e simp
) phi m
)
1893 ((mtimes simp
) -
1 ((%elliptic_f simp
) phi m
)))))
1896 (def-simplifier elliptic_f
(phi m
)
1898 (cond ((float-numerical-eval-p phi m
)
1899 ;; Numerically evaluate it
1900 (to (elliptic-f ($float phi
) ($float m
))))
1901 ((setf args
(complex-float-numerical-eval-p phi m
))
1902 (destructuring-bind (phi m
)
1904 (to (elliptic-f (bigfloat:to
($float phi
))
1905 (bigfloat:to
($float m
))))))
1906 ((bigfloat-numerical-eval-p phi m
)
1907 (to (bigfloat::bf-elliptic-f
(bigfloat:to
($bfloat phi
))
1908 (bigfloat:to
($bfloat m
)))))
1909 ((setf args
(complex-bigfloat-numerical-eval-p phi m
))
1910 (destructuring-bind (phi m
)
1912 (to (bigfloat::bf-elliptic-f
(bigfloat:to
($bfloat phi
))
1913 (bigfloat:to
($bfloat m
))))))
1920 ;; A&S 17.4.21. Let's pick the log tan form. But this
1921 ;; isn't right if we know that abs(phi) > %pi/2, where
1922 ;; elliptic_f is undefined (or infinity).
1923 (cond ((not (eq '$pos
(csign (sub ($abs phi
) (div '$%pi
2)))))
1926 (add (mul '$%pi
(div 1 4))
1929 (merror (intl:gettext
"elliptic_f: elliptic_f(~:M, ~:M) is undefined.")
1931 ((alike1 phi
(div '$%pi
2))
1932 ;; Complete elliptic integral
1933 (ftake '%elliptic_kc m
))
1938 (def-simplifier elliptic_e
(phi m
)
1940 (cond ((float-numerical-eval-p phi m
)
1941 ;; Numerically evaluate it
1942 (complexify (elliptic-e ($float phi
) ($float m
))))
1943 ((complex-float-numerical-eval-p phi m
)
1944 (complexify (bigfloat::bf-elliptic-e
(complex ($float
($realpart phi
)) ($float
($imagpart phi
)))
1945 (complex ($float
($realpart m
)) ($float
($imagpart m
))))))
1946 ((bigfloat-numerical-eval-p phi m
)
1947 (to (bigfloat::bf-elliptic-e
(bigfloat:to
($bfloat phi
))
1948 (bigfloat:to
($bfloat m
)))))
1949 ((setf args
(complex-bigfloat-numerical-eval-p phi m
))
1950 (destructuring-bind (phi m
)
1952 (to (bigfloat::bf-elliptic-e
(bigfloat:to
($bfloat phi
))
1953 (bigfloat:to
($bfloat m
))))))
1960 ;; A&S 17.4.25, but handle periodicity:
1961 ;; elliptic_e(x,m) = elliptic_e(x-%pi*round(x/%pi), m)
1962 ;; + 2*round(x/%pi)*elliptic_ec(m)
1966 ;; elliptic_e(x,1) = sin(x-%pi*round(x/%pi)) + 2*round(x/%pi)*elliptic_ec(m)
1968 (let ((mult-pi (ftake '%round
(div phi
'$%pi
))))
1969 (add (ftake '%sin
(sub phi
1974 (ftake '%elliptic_ec m
))))))
1975 ((alike1 phi
(div '$%pi
2))
1976 ;; Complete elliptic integral
1977 (ftake '%elliptic_ec m
))
1978 ((and ($numberp phi
)
1979 (let ((r ($round
(div phi
'$%pi
))))
1982 ;; Handle the case where phi is a number where we can apply
1983 ;; the periodicity property without blowing up the
1985 (add (ftake '%elliptic_e
1988 (ftake '%round
(div phi
'$%pi
))))
1991 (mul (ftake '%round
(div phi
'$%pi
))
1992 (ftake '%elliptic_ec m
)))))
1997 ;; Complete elliptic integrals
1999 ;; elliptic_kc(m) = elliptic_f(%pi/2, m)
2001 ;; elliptic_ec(m) = elliptic_e(%pi/2, m)
2004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2006 ;;; We support a simplim%function. The function is looked up in simplimit and
2007 ;;; handles specific values of the function.
2009 (defprop %elliptic_kc simplim%elliptic_kc simplim%function
)
2011 (defun simplim%elliptic_kc
(expr var val
)
2012 ;; Look for the limit of the argument
2013 (let ((m (limit (cadr expr
) var val
'think
)))
2015 ;; For an argument 1 return $infinity.
2018 ;; All other cases are handled by the simplifier of the function.
2019 (simplify (list '(%elliptic_kc
) m
))))))
2021 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2023 (def-simplifier elliptic_kc
(m)
2026 ;; elliptic_kc(1) is complex infinity. Maxima can not handle
2027 ;; infinities correctly, throw a Maxima error.
2029 (intl:gettext
"elliptic_kc: elliptic_kc(~:M) is undefined.")
2031 ((float-numerical-eval-p m
)
2032 ;; Numerically evaluate it
2033 (to (elliptic-k ($float m
))))
2034 ((complex-float-numerical-eval-p m
)
2035 (complexify (bigfloat::bf-elliptic-k
(complex ($float
($realpart m
)) ($float
($imagpart m
))))))
2036 ((setf args
(complex-bigfloat-numerical-eval-p m
))
2037 (destructuring-bind (m)
2039 (to (bigfloat::bf-elliptic-k
(bigfloat:to
($bfloat m
))))))
2043 ;; http://functions.wolfram.com/EllipticIntegrals/EllipticK/03/01/
2045 ;; elliptic_kc(1/2) = 8*%pi^(3/2)/gamma(-1/4)^2
2046 (div (mul 8 (power '$%pi
(div 3 2)))
2047 (power (gm (div -
1 4)) 2)))
2049 ;; elliptic_kc(-1) = gamma(1/4)^2/(4*sqrt(2*%pi))
2050 (div (power (gm (div 1 4)) 2)
2051 (mul 4 (power (mul 2 '$%pi
) 1//2))))
2052 ((alike1 m
(add 17 (mul -
12 (power 2 1//2))))
2053 ;; elliptic_kc(17-12*sqrt(2)) = 2*(2+sqrt(2))*%pi^(3/2)/gamma(-1/4)^2
2054 (div (mul 2 (mul (add 2 (power 2 1//2))
2055 (power '$%pi
(div 3 2))))
2056 (power (gm (div -
1 4)) 2)))
2057 ((or (alike1 m
(div (add 2 (power 3 1//2))
2059 (alike1 m
(add (div (power 3 1//2)
2062 ;; elliptic_kc((sqrt(3)+2)/4) = sqrt(%pi)*gamma(1/3)/gamma(5/6).
2064 ;; First evaluate this integral, where y = sqrt(1+t^3).
2066 ;; integrate(1/y,t,-1,inf) = integrate(1/y,t,-1,0) + integrate(1/y,t,0,inf).
2068 ;; The second integral, maxima gives beta(1/6,1/3)/3.
2070 ;; For the first, we can use the change of variable x=-u^(1/3) to get
2072 ;; integrate(1/sqrt(1-u)/u^(2/3),u,0,1)
2074 ;; which is a beta integral that maxima can evaluate to
2075 ;; beta(1/3,1/2)/3. Then we see the value of the initial
2078 ;; beta(1/6,1/3)/3 + beta(1/3,1/2)/3
2080 ;; (Thanks to Guilherme Namen for this derivation on the mailing list, 2023-03-09.)
2082 ;; We can simplify this expression by converting to gamma functions:
2084 ;; beta(1/6,1/3)/3 + beta(1/3,1/2)/3 =
2085 ;; (gamma(1/3)*(gamma(1/6)*gamma(5/6)+%pi))/(3*sqrt(%pi)*gamma(5/6));
2087 ;; Using the reflection formula gamma(1-z)*gamma(z) =
2088 ;; %pi/sin(%pi*z), we can write gamma(1/6)*gamma(5/6) =
2089 ;; %pi/sin(%pi*1/6) = 2*%pi. Finally, we have
2091 ;; sqrt(%pi)*gamma(1/3)/gamma(5/6);
2093 ;; All that remains is to show that integrate(1/y,t) can be
2094 ;; written as an inverse_jacobi_cn function with modulus
2097 ;; First apply the substitution
2099 ;; s = (t+sqrt(3)+1)/(t-sqrt(3)+1). We then have the integral
2101 ;; C*integrate(1/sqrt(s^2-1)/sqrt(s^2+4*sqrt(3)+7),s)
2103 ;; where C is some constant. From A&S 14.4.49, we can see
2104 ;; this integral is the inverse_jacobi_nc function with
2105 ;; modulus of (4*sqrt(3)+7)/(4*sqrt(3)+7+1) =
2107 (div (mul (power '$%pi
1//2)
2108 (ftake '%gamma
(div 1 3)))
2109 (ftake '%gamma
(div 5 6))))
2110 ($hypergeometric_representation
2111 ;; See http://functions.wolfram.com/08.02.26.0001.01
2113 ;; elliptic_kc(z) = %pi/2*%f[2,1]([1/2,1/2],[1], z)
2116 (ftake '%hypergeometric
2117 (make-mlist 1//2 1//2)
2124 (defprop %elliptic_kc
2129 ((mplus) ((%elliptic_ec
) m
)
2132 ((mplus) 1 ((mtimes) -
1 m
))))
2133 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
2137 (def-simplifier elliptic_ec
(m)
2139 (cond ((float-numerical-eval-p m
)
2140 ;; Numerically evaluate it
2141 (complexify (elliptic-ec ($float m
))))
2142 ((setf args
(complex-float-numerical-eval-p m
))
2143 (destructuring-bind (m)
2145 (complexify (bigfloat::bf-elliptic-ec
(bigfloat:to
($float m
))))))
2146 ((setf args
(complex-bigfloat-numerical-eval-p m
))
2147 (destructuring-bind (m)
2149 (to (bigfloat::bf-elliptic-ec
(bigfloat:to
($bfloat m
))))))
2150 ;; Some special cases we know about.
2156 ;; elliptic_ec(1/2). Use the identity
2158 ;; elliptic_ec(z)*elliptic_kc(1-z) - elliptic_kc(z)*elliptic_kc(1-z)
2159 ;; + elliptic_ec(1-z)*elliptic_kc(z) = %pi/2;
2161 ;; Let z = 1/2 to get
2163 ;; %pi^(3/2)*'elliptic_ec(1/2)/gamma(3/4)^2-%pi^3/(4*gamma(3/4)^4) = %pi/2
2165 ;; since we know that elliptic_kc(1/2) = %pi^(3/2)/(2*gamma(3/4)^2). Hence
2168 ;; = (2*%pi*gamma(3/4)^4+%pi^3)/(4*%pi^(3/2)*gamma(3/4)^2)
2169 ;; = gamma(3/4)^2/(2*sqrt(%pi))+%pi^(3/2)/(4*gamma(3/4)^2)
2171 (add (div (power (ftake '%gamma
(div 3 4)) 2)
2172 (mul 2 (power '$%pi
1//2)))
2173 (div (power '$%pi
(div 3 2))
2174 (mul 4 (power (ftake '%gamma
(div 3 4)) 2)))))
2176 ;; elliptic_ec(-1). Use the identity
2177 ;; http://functions.wolfram.com/08.01.17.0002.01
2180 ;; elliptic_ec(z) = sqrt(1 - z)*elliptic_ec(z/(z-1))
2182 ;; Let z = -1 to get
2184 ;; elliptic_ec(-1) = sqrt(2)*elliptic_ec(1/2)
2186 ;; Should we expand out elliptic_ec(1/2) using the above result?
2188 (ftake '%elliptic_ec
1//2)))
2189 ($hypergeometric_representation
2190 ;; See http://functions.wolfram.com/08.01.26.0001.01
2192 ;; elliptic_ec(z) = %pi/2*%f[2,1]([-1/2,1/2],[1], z)
2195 (ftake '%hypergeometric
2196 (make-mlist -
1//2 1//2)
2203 (defprop %elliptic_ec
2205 ((mtimes) ((rat) 1 2)
2206 ((mplus) ((%elliptic_ec
) m
)
2207 ((mtimes) -
1 ((%elliptic_kc
)
2213 ;; Elliptic integral of the third kind:
2220 ;; PI(n;phi|m) = I ----------------------------------- ds
2222 ;; / SQRT(1 - m SIN (s)) (1 - n SIN (s))
2225 ;; As with E and F, we do not use the modular angle alpha but the
2226 ;; parameter m = sin(alpha)^2.
2228 (def-simplifier elliptic_pi
(n phi m
)
2231 ((float-numerical-eval-p n phi m
)
2232 ;; Numerically evaluate it
2233 (elliptic-pi ($float n
) ($float phi
) ($float m
)))
2234 ((setf args
(complex-float-numerical-eval-p n phi m
))
2235 (destructuring-bind (n phi m
)
2237 (elliptic-pi (bigfloat:to
($float n
))
2238 (bigfloat:to
($float phi
))
2239 (bigfloat:to
($float m
)))))
2240 ((bigfloat-numerical-eval-p n phi m
)
2241 (to (bigfloat::bf-elliptic-pi
(bigfloat:to n
)
2244 ((setq args
(complex-bigfloat-numerical-eval-p n phi m
))
2245 (destructuring-bind (n phi m
)
2247 (to (bigfloat::bf-elliptic-pi
(bigfloat:to n
)
2251 (ftake '%elliptic_f phi m
))
2253 ;; 3 cases depending on n < 1, n > 1, or n = 1.
2254 (let ((s (asksign (add -
1 n
))))
2257 (div (ftake '%atanh
(mul (power (add n -
1) 1//2)
2259 (power (add n -
1) 1//2)))
2261 (div (ftake '%atan
(mul (power (sub 1 n
) 1//2)
2263 (power (sub 1 n
) 1//2)))
2265 (ftake '%tan phi
)))))
2270 ;; Complete elliptic-pi. That is phi = %pi/2. Then
2272 ;; = Rf(0, 1-m,1) + Rj(0,1-m,1-n)*n/3;
2273 (defun elliptic-pi-complete (n m
)
2274 (to (bigfloat:+ (bigfloat::bf-rf
0 (- 1 m
) 1)
2275 (bigfloat:* 1/3 n
(bigfloat::bf-rj
0 (- 1 m
) 1 (- 1 n
))))))
2277 ;; To compute elliptic_pi for all z, we use the property
2278 ;; (http://functions.wolfram.com/08.06.16.0002.01)
2280 ;; elliptic_pi(n, z + %pi*k, m)
2281 ;; = 2*k*elliptic_pi(n, %pi/2, m) + elliptic_pi(n, z, m)
2283 ;; So we are left with computing the integral for 0 <= z < %pi. Using
2284 ;; Carlson's formulation produces the wrong values for %pi/2 < z <
2285 ;; %pi. How to do that?
2289 ;; I(a,b) = integrate(1/(1-n*sin(x)^2)/sqrt(1 - m*sin(x)^2), x, a, b)
2291 ;; That is, I(a,b) is the integral for the elliptic_pi function but
2292 ;; with a lower limit of a and an upper limit of b.
2294 ;; Then, we want to compute I(0, z), with %pi <= z < %pi. Let w = z +
2295 ;; %pi/2, 0 <= w < %pi/2. Then
2297 ;; I(0, w+%pi/2) = I(0, %pi/2) + I(%pi/2, w+%pi/2)
2299 ;; To evaluate I(%pi/2, w+%pi/2), use a change of variables:
2301 ;; changevar('integrate(1/(1-n*sin(x)^2)/sqrt(1 - m*sin(x)^2), x, %pi/2, w + %pi/2),
2304 ;; = integrate(-1/(sqrt(1-m*sin(u)^2)*(1-n*sin(u)^2)),u,%pi/2-w,%pi/2)
2305 ;; = I(%pi/2-w,%pi/2)
2306 ;; = I(0,%pi/2) - I(0,%pi/2-w)
2310 ;; I(0,%pi/2+w) = 2*I(0,%pi/2) - I(0,%pi/2-w)
2312 ;; This allows us to compute the general result with 0 <= z < %pi
2314 ;; I(0, k*%pi + z) = 2*k*I(0,%pi/2) + I(0,z);
2316 ;; If 0 <= z < %pi/2, then the we are done. If %pi/2 <= z < %pi, let
2317 ;; z = w+%pi/2. Then
2319 ;; I(0,z) = 2*I(0,%pi/2) - I(0,%pi/2-w)
2321 ;; Or, since w = z-%pi/2:
2323 ;; I(0,z) = 2*I(0,%pi/2) - I(0,%pi-z)
2325 (defun elliptic-pi (n phi m
)
2326 ;; elliptic_pi(n, -phi, m) = -elliptic_pi(n, phi, m). That is, it
2327 ;; is an odd function of phi.
2328 (when (minusp (realpart phi
))
2329 (return-from elliptic-pi
(- (elliptic-pi n
(- phi
) m
))))
2331 ;; Note: Carlson's DRJ has n defined as the negative of the n given
2333 (flet ((base (n phi m
)
2334 ;; elliptic_pi(n,phi,m) =
2335 ;; sin(phi)*Rf(cos(phi)^2, 1-m*sin(phi)^2, 1)
2336 ;; - (-n / 3) * sin(phi)^3
2337 ;; * Rj(cos(phi)^2, 1-m*sin(phi)^2, 1, 1-n*sin(phi)^2)
2342 (k2sin (* (- 1 (* k sin-phi
))
2343 (+ 1 (* k sin-phi
)))))
2344 (- (* sin-phi
(bigfloat::bf-rf
(expt cos-phi
2) k2sin
1.0))
2345 (* (/ nn
3) (expt sin-phi
3)
2346 (bigfloat::bf-rj
(expt cos-phi
2) k2sin
1.0
2347 (- 1 (* n
(expt sin-phi
2)))))))))
2348 ;; FIXME: Reducing the arg by pi has significant round-off.
2349 ;; Consider doing something better.
2350 (let* ((cycles (round (realpart phi
) pi
))
2351 (rem (- phi
(* cycles pi
))))
2352 (let ((complete (elliptic-pi-complete n m
)))
2353 (to (+ (* 2 cycles complete
)
2354 (base n rem m
)))))))
2356 ;;; Deriviatives from functions.wolfram.com
2357 ;;; http://functions.wolfram.com/EllipticIntegrals/EllipticPi3/20/
2358 (defprop %elliptic_pi
2360 ;Derivative wrt first argument
2361 ((mtimes) ((rat) 1 2)
2362 ((mexpt) ((mplus) m
((mtimes) -
1 n
)) -
1)
2363 ((mexpt) ((mplus) -
1 n
) -
1)
2365 ((mtimes) ((mexpt) n -
1)
2366 ((mplus) ((mtimes) -
1 m
) ((mexpt) n
2))
2367 ((%elliptic_pi
) n z m
))
2369 ((mtimes) ((mplus) m
((mtimes) -
1 n
)) ((mexpt) n -
1)
2370 ((%elliptic_f
) z m
))
2371 ((mtimes) ((rat) -
1 2) n
2373 ((mplus) 1 ((mtimes) -
1 m
((mexpt) ((%sin
) z
) 2)))
2376 ((mplus) 1 ((mtimes) -
1 n
((mexpt) ((%sin
) z
) 2)))
2378 ((%sin
) ((mtimes) 2 z
)))))
2379 ;derivative wrt second argument
2382 ((mplus) 1 ((mtimes) -
1 m
((mexpt) ((%sin
) z
) 2)))
2385 ((mplus) 1 ((mtimes) -
1 n
((mexpt) ((%sin
) z
) 2))) -
1))
2386 ;Derivative wrt third argument
2387 ((mtimes) ((rat) 1 2)
2388 ((mexpt) ((mplus) ((mtimes) -
1 m
) n
) -
1)
2389 ((mplus) ((%elliptic_pi
) n z m
)
2390 ((mtimes) ((mexpt) ((mplus) -
1 m
) -
1)
2391 ((%elliptic_e
) z m
))
2392 ((mtimes) ((rat) -
1 2) ((mexpt) ((mplus) -
1 m
) -
1) m
2394 ((mplus) 1 ((mtimes) -
1 m
((mexpt) ((%sin
) z
) 2)))
2396 ((%sin
) ((mtimes) 2 z
))))))
2399 ;; Define Carlson's elliptic integrals.
2401 (def-simplifier carlson_rc
(x y
)
2404 (flet ((floatify (z)
2405 ;; If z is a complex rational, convert to a
2406 ;; complex double-float. Otherwise, leave it as
2407 ;; is. If we don't do this, %i is handled as
2408 ;; #c(0 1), which makes bf-rc use single-float
2409 ;; arithmetic instead of the desired
2411 (if (and (complexp z
) (rationalp (realpart z
)))
2412 (complex (float (realpart z
))
2413 (float (imagpart z
)))
2415 (to (bigfloat::bf-rc
(floatify (bigfloat:to x
))
2416 (floatify (bigfloat:to y
)))))))
2417 ;; See comments from bf-rc
2418 (cond ((float-numerical-eval-p x y
)
2419 (calc ($float x
) ($float y
)))
2420 ((bigfloat-numerical-eval-p x y
)
2421 (calc ($bfloat x
) ($bfloat y
)))
2422 ((setf args
(complex-float-numerical-eval-p x y
))
2423 (destructuring-bind (x y
)
2425 (calc ($float x
) ($float y
))))
2426 ((setf args
(complex-bigfloat-numerical-eval-p x y
))
2427 (destructuring-bind (x y
)
2429 (calc ($bfloat x
) ($bfloat y
))))
2435 (alike1 y
(div 1 4)))
2440 ;; rc(2,1) = 1/2*integrate(1/sqrt(t+2)/(t+1), t, 0, inf)
2441 ;; = (log(sqrt(2)+1)-log(sqrt(2)-1))/2
2442 ;; ratsimp(logcontract(%)),algebraic:
2443 ;; = -log(3-2^(3/2))/2
2444 ;; = -log(sqrt(3-2^(3/2)))
2445 ;; = -log(sqrt(2)-1)
2446 ;; = log(1/(sqrt(2)-1))
2447 ;; ratsimp(%),algebraic;
2449 (ftake '%log
(add 1 (power 2 1//2))))
2450 ((and (alike x
'$%i
)
2451 (alike y
(add 1 '$%i
)))
2452 ;; rc(%i, %i+1) = 1/2*integrate(1/sqrt(t+%i)/(t+%i+1), t, 0, inf)
2453 ;; = %pi/2-atan((-1)^(1/4))
2454 ;; ratsimp(logcontract(ratsimp(rectform(%o42)))),algebraic;
2455 ;; = (%i*log(3-2^(3/2))+%pi)/4
2456 ;; = (%i*log(3-2^(3/2)))/4+%pi/4
2457 ;; = %i*log(sqrt(3-2^(3/2)))/2+%pi/4
2459 ;; = %pi/4 + %i*log(sqrt(2)-1)/2
2463 (ftake '%log
(sub (power 2 1//2) 1)))))
2466 ;; rc(0,%i) = 1/2*integrate(1/(sqrt(t)*(t+%i)), t, 0, inf)
2467 ;; = -((sqrt(2)*%i-sqrt(2))*%pi)/4
2468 ;; = ((1-%i)*%pi)/2^(3/2)
2469 (div (mul (sub 1 '$%i
)
2473 (eq ($sign
($realpart x
)) '$pos
))
2474 ;; carlson_rc(x,x) = 1/2*integrate(1/sqrt(t+x)/(t+x), t, 0, inf)
2477 ((and (alike1 x
(power (div (add 1 y
) 2) 2))
2478 (eq ($sign
($realpart y
)) '$pos
))
2479 ;; Rc(((1+x)/2)^2,x) = log(x)/(x-1) for x > 0.
2481 ;; This is done by looking at Rc(x,y) and seeing if
2482 ;; ((1+y)/2)^2 is the same as x.
2483 (div (ftake '%log y
)
2488 (def-simplifier carlson_rd
(x y z
)
2490 (flet ((calc (x y z
)
2491 (to (bigfloat::bf-rd
(bigfloat:to x
)
2494 ;; See https://dlmf.nist.gov/19.20.E18
2495 (cond ((and (eql x
1)
2502 ;; Rd(x,x,x) = x^(-3/2)
2503 (power x
(div -
3 2)))
2506 ;; Rd(0,y,y) = 3/4*%pi*y^(-3/2)
2509 (power y
(div -
3 2))))
2511 ;; Rd(x,y,y) = 3/(2*(y-x))*(Rc(x, y) - sqrt(x)/y)
2512 (mul (div 3 (mul 2 (sub y x
)))
2513 (sub (ftake '%carlson_rc x y
)
2517 ;; Rd(x,x,z) = 3/(z-x)*(Rc(z,x) - 1/sqrt(z))
2518 (mul (div 3 (sub z x
))
2519 (sub (ftake '%carlson_rc z x
)
2520 (div 1 (power z
1//2)))))
2526 ;; Rd(0,2,1) = 3*(gamma(3/4)^2)/sqrt(2*%pi)
2527 ;; See https://dlmf.nist.gov/19.20.E22.
2529 ;; But that's the same as
2530 ;; 3*sqrt(%pi)*gamma(3/4)/gamma(1/4). We can see this by
2531 ;; taking the ratio to get
2532 ;; gamma(1/4)*gamma(3/4)/sqrt(2)*%pi. But
2533 ;; gamma(1/4)*gamma(3/4) = beta(1/4,3/4) = sqrt(2)*%pi.
2534 ;; Hence, the ratio is 1.
2536 ;; Note also that Rd(x,y,z) = Rd(y,x,z)
2539 (div (ftake '%gamma
(div 3 4))
2540 (ftake '%gamma
(div 1 4)))))
2541 ((and (or (eql x
0) (eql y
0))
2543 ;; 1/3*m*Rd(0,1-m,1) = K(m) - E(m).
2544 ;; See https://dlmf.nist.gov/19.25.E1
2546 ;; Thus, Rd(0,y,1) = 3/(1-y)*(K(1-y) - E(1-y))
2548 ;; Note that Rd(x,y,z) = Rd(y,x,z).
2549 (let ((m (sub 1 y
)))
2551 (sub (ftake '%elliptic_kc m
)
2552 (ftake '%elliptic_ec m
)))))
2557 ;; 1/3*m*(1-m)*Rd(0,1,1-m) = E(m) - (1-m)*K(m)
2558 ;; See https://dlmf.nist.gov/19.25.E1
2561 ;; Rd(0,1,z) = 3/(z*(1-z))*(E(1-z) - z*K(1-z))
2562 ;; Recall that Rd(x,y,z) = Rd(y,x,z).
2563 (mul (div 3 (mul z
(sub 1 z
)))
2564 (sub (ftake '%elliptic_ec
(sub 1 z
))
2566 (ftake '%elliptic_kc
(sub 1 z
))))))
2567 ((float-numerical-eval-p x y z
)
2568 (calc ($float x
) ($float y
) ($float z
)))
2569 ((bigfloat-numerical-eval-p x y z
)
2570 (calc ($bfloat x
) ($bfloat y
) ($bfloat z
)))
2571 ((setf args
(complex-float-numerical-eval-p x y z
))
2572 (destructuring-bind (x y z
)
2574 (calc ($float x
) ($float y
) ($float z
))))
2575 ((setf args
(complex-bigfloat-numerical-eval-p x y z
))
2576 (destructuring-bind (x y z
)
2578 (calc ($bfloat x
) ($bfloat y
) ($bfloat z
))))
2582 (def-simplifier carlson_rf
(x y z
)
2584 (flet ((calc (x y z
)
2585 (to (bigfloat::bf-rf
(bigfloat:to x
)
2588 ;; See https://dlmf.nist.gov/19.20.i
2589 (cond ((and (alike1 x y
)
2591 ;; Rf(x,x,x) = x^(-1/2)
2595 ;; Rf(0,y,y) = 1/2*%pi*y^(-1/2)
2599 (ftake '%carlson_rc x y
))
2600 ((some #'(lambda (args)
2601 (destructuring-bind (x y z
)
2612 ;; Rf(0,1,2) = (gamma(1/4))^2/(4*sqrt(2*%pi))
2614 ;; And Rf is symmetric in all the args, so check every
2615 ;; permutation too. This could probably be simplified
2616 ;; without consing all the lists, but I'm lazy.
2617 (div (power (ftake '%gamma
(div 1 4)) 2)
2618 (mul 4 (power (mul 2 '$%pi
) 1//2))))
2619 ((some #'(lambda (args)
2620 (destructuring-bind (x y z
)
2622 (and (alike1 x
'$%i
)
2623 (alike1 y
(mul -
1 '$%i
))
2632 ;; = 1/2*integrate(1/sqrt(t^2+1)/sqrt(t),t,0,inf)
2633 ;; = beta(1/4,1/4)/4;
2635 ;; = gamma(1/4)^2/(4*sqrt(%pi))
2637 ;; Rf is symmetric, so check all the permutations too.
2638 (div (power (ftake '%gamma
(div 1 4)) 2)
2639 (mul 4 (power '$%pi
1//2))))
2641 (some #'(lambda (args)
2642 (destructuring-bind (x y z
)
2644 ;; Check that x = 0 and z = 1, and
2655 ;; Rf(0,1-m,1) = elliptic_kc(m).
2656 ;; See https://dlmf.nist.gov/19.25.E1
2657 (ftake '%elliptic_kc
(sub 1 args
)))
2658 ((some #'(lambda (args)
2659 (destructuring-bind (x y z
)
2661 (and (alike1 x
'$%i
)
2662 (alike1 y
(mul -
1 '$%i
))
2671 ;; = 1/2*integrate(1/sqrt(t^2+1)/sqrt(t),t,0,inf)
2672 ;; = beta(1/4,1/4)/4;
2674 ;; = gamma(1/4)^2/(4*sqrt(%pi))
2676 ;; Rf is symmetric, so check all the permutations too.
2677 (div (power (ftake '%gamma
(div 1 4)) 2)
2678 (mul 4 (power '$%pi
1//2))))
2679 ((float-numerical-eval-p x y z
)
2680 (calc ($float x
) ($float y
) ($float z
)))
2681 ((bigfloat-numerical-eval-p x y z
)
2682 (calc ($bfloat x
) ($bfloat y
) ($bfloat z
)))
2683 ((setf args
(complex-float-numerical-eval-p x y z
))
2684 (destructuring-bind (x y z
)
2686 (calc ($float x
) ($float y
) ($float z
))))
2687 ((setf args
(complex-bigfloat-numerical-eval-p x y z
))
2688 (destructuring-bind (x y z
)
2690 (calc ($bfloat x
) ($bfloat y
) ($bfloat z
))))
2694 (def-simplifier carlson_rj
(x y z p
)
2696 (flet ((calc (x y z p
)
2697 (to (bigfloat::bf-rj
(bigfloat:to x
)
2701 ;; See https://dlmf.nist.gov/19.20.iii
2702 (cond ((and (alike1 x y
)
2705 ;; Rj(x,x,x,x) = x^(-3/2)
2706 (power x
(div -
3 2)))
2708 ;; Rj(x,y,z,z) = Rd(x,y,z)
2709 (ftake '%carlson_rd x y z
))
2712 ;; Rj(0,y,y,p) = 3*%pi/(2*(y*sqrt(p)+p*sqrt(y)))
2715 (add (mul y
(power p
1//2))
2716 (mul p
(power y
1//2))))))
2718 ;; Rj(x,y,y,p) = 3/(p-y)*(Rc(x,y) - Rc(x,p))
2719 (mul (div 3 (sub p y
))
2720 (sub (ftake '%carlson_rc x y
)
2721 (ftake '%carlson_rc x p
))))
2724 ;; Rj(x,y,y,y) = Rd(x,y,y)
2725 (ftake '%carlson_rd x y y
))
2726 ((float-numerical-eval-p x y z p
)
2727 (calc ($float x
) ($float y
) ($float z
) ($float p
)))
2728 ((bigfloat-numerical-eval-p x y z p
)
2729 (calc ($bfloat x
) ($bfloat y
) ($bfloat z
) ($bfloat p
)))
2730 ((setf args
(complex-float-numerical-eval-p x y z p
))
2731 (destructuring-bind (x y z p
)
2733 (calc ($float x
) ($float y
) ($float z
) ($float p
))))
2734 ((setf args
(complex-bigfloat-numerical-eval-p x y z p
))
2735 (destructuring-bind (x y z p
)
2737 (calc ($bfloat x
) ($bfloat y
) ($bfloat z
) ($bfloat p
))))
2741 ;;; Other Jacobian elliptic functions
2743 ;; jacobi_ns(u,m) = 1/jacobi_sn(u,m)
2747 ((mtimes) -
1 ((%jacobi_cn
) u m
) ((%jacobi_dn
) u m
)
2748 ((mexpt) ((%jacobi_sn
) u m
) -
2))
2750 ((mtimes) -
1 ((mexpt) ((%jacobi_sn
) u m
) -
2)
2752 ((mtimes) ((rat) 1 2)
2753 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
2754 ((mexpt) ((%jacobi_cn
) u m
) 2)
2756 ((mtimes) ((rat) 1 2) ((mexpt) m -
1)
2757 ((%jacobi_cn
) u m
) ((%jacobi_dn
) u m
)
2760 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
2761 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
2765 (def-simplifier jacobi_ns
(u m
)
2768 ((float-numerical-eval-p u m
)
2769 (to (bigfloat:/ (bigfloat::sn
(bigfloat:to
($float u
))
2770 (bigfloat:to
($float m
))))))
2771 ((setf args
(complex-float-numerical-eval-p u m
))
2772 (destructuring-bind (u m
)
2774 (to (bigfloat:/ (bigfloat::sn
(bigfloat:to
($float u
))
2775 (bigfloat:to
($float m
)))))))
2776 ((bigfloat-numerical-eval-p u m
)
2777 (let ((uu (bigfloat:to
($bfloat u
)))
2778 (mm (bigfloat:to
($bfloat m
))))
2779 (to (bigfloat:/ (bigfloat::sn uu mm
)))))
2780 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
2781 (destructuring-bind (u m
)
2783 (let ((uu (bigfloat:to
($bfloat u
)))
2784 (mm (bigfloat:to
($bfloat m
))))
2785 (to (bigfloat:/ (bigfloat::sn uu mm
))))))
2793 (dbz-err1 'jacobi_ns
))
2794 ((and $trigsign
(mminusp* u
))
2796 (neg (ftake* '%jacobi_ns
(neg u
) m
)))
2799 (member (caar u
) '(%inverse_jacobi_sn
2810 %inverse_jacobi_dc
))
2811 (alike1 (third u
) m
))
2812 (cond ((eq (caar u
) '%inverse_jacobi_ns
)
2815 ;; Express in terms of sn:
2817 (div 1 (ftake '%jacobi_sn u m
)))))
2818 ;; A&S 16.20 (Jacobi's Imaginary transformation)
2819 ((and $%iargs
(multiplep u
'$%i
))
2820 ;; ns(i*u) = 1/sn(i*u) = -i/sc(u,m1) = -i*cs(u,m1)
2822 (ftake* '%jacobi_cs
(coeff u
'$%i
1) (add 1 (neg m
))))))
2823 ((setq coef
(kc-arg2 u m
))
2826 ;; ns(m*K+u) = 1/sn(m*K+u)
2828 (destructuring-bind (lin const
)
2830 (cond ((integerp lin
)
2833 ;; ns(4*m*K+u) = ns(u)
2836 (dbz-err1 'jacobi_ns
)
2837 (ftake '%jacobi_ns const m
)))
2839 ;; ns(4*m*K + K + u) = ns(K+u) = dc(u)
2843 (ftake '%jacobi_dc const m
)))
2845 ;; ns(4*m*K+2*K + u) = ns(2*K+u) = -ns(u)
2846 ;; ns(2*K) = infinity
2848 (dbz-err1 'jacobi_ns
)
2849 (neg (ftake '%jacobi_ns const m
))))
2851 ;; ns(4*m*K+3*K+u) = ns(2*K + K + u) = -ns(K+u) = -dc(u)
2855 (neg (ftake '%jacobi_dc const m
))))))
2856 ((and (alike1 lin
1//2)
2858 (div 1 (ftake '%jacobi_sn u m
)))
2865 ;; jacobi_nc(u,m) = 1/jacobi_cn(u,m)
2869 ((mtimes) ((mexpt) ((%jacobi_cn
) u m
) -
2)
2870 ((%jacobi_dn
) u m
) ((%jacobi_sn
) u m
))
2872 ((mtimes) -
1 ((mexpt) ((%jacobi_cn
) u m
) -
2)
2874 ((mtimes) ((rat) -
1 2)
2875 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
2876 ((%jacobi_cn
) u m
) ((mexpt) ((%jacobi_sn
) u m
) 2))
2877 ((mtimes) ((rat) -
1 2) ((mexpt) m -
1)
2878 ((%jacobi_dn
) u m
) ((%jacobi_sn
) u m
)
2880 ((mtimes) -
1 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
2881 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
)) m
)))))))
2884 (def-simplifier jacobi_nc
(u m
)
2887 ((float-numerical-eval-p u m
)
2888 (to (bigfloat:/ (bigfloat::cn
(bigfloat:to
($float u
))
2889 (bigfloat:to
($float m
))))))
2890 ((setf args
(complex-float-numerical-eval-p u m
))
2891 (destructuring-bind (u m
)
2893 (to (bigfloat:/ (bigfloat::cn
(bigfloat:to
($float u
))
2894 (bigfloat:to
($float m
)))))))
2895 ((bigfloat-numerical-eval-p u m
)
2896 (let ((uu (bigfloat:to
($bfloat u
)))
2897 (mm (bigfloat:to
($bfloat m
))))
2898 (to (bigfloat:/ (bigfloat::cn uu mm
)))))
2899 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
2900 (destructuring-bind (u m
)
2902 (let ((uu (bigfloat:to
($bfloat u
)))
2903 (mm (bigfloat:to
($bfloat m
))))
2904 (to (bigfloat:/ (bigfloat::cn uu mm
))))))
2913 ((and $trigsign
(mminusp* u
))
2915 (ftake* '%jacobi_nc
(neg u
) m
))
2918 (member (caar u
) '(%inverse_jacobi_sn
2929 %inverse_jacobi_dc
))
2930 (alike1 (third u
) m
))
2931 (cond ((eq (caar u
) '%inverse_jacobi_nc
)
2934 ;; Express in terms of cn:
2936 (div 1 (ftake '%jacobi_cn u m
)))))
2937 ;; A&S 16.20 (Jacobi's Imaginary transformation)
2938 ((and $%iargs
(multiplep u
'$%i
))
2939 ;; nc(i*u) = 1/cn(i*u) = 1/nc(u,1-m) = cn(u,1-m)
2940 (ftake* '%jacobi_cn
(coeff u
'$%i
1) (add 1 (neg m
))))
2941 ((setq coef
(kc-arg2 u m
))
2946 (destructuring-bind (lin const
)
2948 (cond ((integerp lin
)
2951 ;; nc(4*m*K+u) = nc(u)
2955 (ftake '%jacobi_nc const m
)))
2957 ;; nc(4*m*K+K+u) = nc(K+u) = -ds(u)/sqrt(1-m)
2960 (dbz-err1 'jacobi_nc
)
2961 (neg (div (ftake '%jacobi_ds const m
)
2962 (power (sub 1 m
) 1//2)))))
2964 ;; nc(4*m*K+2*K+u) = nc(2*K+u) = -nc(u)
2968 (neg (ftake '%jacobi_nc const m
))))
2970 ;; nc(4*m*K+3*K+u) = nc(3*K+u) = nc(2*K+K+u) =
2971 ;; -nc(K+u) = ds(u)/sqrt(1-m)
2973 ;; nc(3*K) = infinity
2975 (dbz-err1 'jacobi_nc
)
2976 (div (ftake '%jacobi_ds const m
)
2977 (power (sub 1 m
) 1//2))))))
2978 ((and (alike1 1//2 lin
)
2980 (div 1 (ftake '%jacobi_cn u m
)))
2987 ;; jacobi_nd(u,m) = 1/jacobi_dn(u,m)
2991 ((mtimes) m
((%jacobi_cn
) u m
)
2992 ((mexpt) ((%jacobi_dn
) u m
) -
2) ((%jacobi_sn
) u m
))
2994 ((mtimes) -
1 ((mexpt) ((%jacobi_dn
) u m
) -
2)
2996 ((mtimes) ((rat) -
1 2)
2997 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
2999 ((mexpt) ((%jacobi_sn
) u m
) 2))
3000 ((mtimes) ((rat) -
1 2) ((%jacobi_cn
) u m
)
3004 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3005 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3009 (def-simplifier jacobi_nd
(u m
)
3012 ((float-numerical-eval-p u m
)
3013 (to (bigfloat:/ (bigfloat::dn
(bigfloat:to
($float u
))
3014 (bigfloat:to
($float m
))))))
3015 ((setf args
(complex-float-numerical-eval-p u m
))
3016 (destructuring-bind (u m
)
3018 (to (bigfloat:/ (bigfloat::dn
(bigfloat:to
($float u
))
3019 (bigfloat:to
($float m
)))))))
3020 ((bigfloat-numerical-eval-p u m
)
3021 (let ((uu (bigfloat:to
($bfloat u
)))
3022 (mm (bigfloat:to
($bfloat m
))))
3023 (to (bigfloat:/ (bigfloat::dn uu mm
)))))
3024 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
3025 (destructuring-bind (u m
)
3027 (let ((uu (bigfloat:to
($bfloat u
)))
3028 (mm (bigfloat:to
($bfloat m
))))
3029 (to (bigfloat:/ (bigfloat::dn uu mm
))))))
3038 ((and $trigsign
(mminusp* u
))
3040 (ftake* '%jacobi_nd
(neg u
) m
))
3043 (member (caar u
) '(%inverse_jacobi_sn
3054 %inverse_jacobi_dc
))
3055 (alike1 (third u
) m
))
3056 (cond ((eq (caar u
) '%inverse_jacobi_nd
)
3059 ;; Express in terms of dn:
3061 (div 1 (ftake '%jacobi_dn u m
)))))
3062 ;; A&S 16.20 (Jacobi's Imaginary transformation)
3063 ((and $%iargs
(multiplep u
'$%i
))
3064 ;; nd(i*u) = 1/dn(i*u) = 1/dc(u,1-m) = cd(u,1-m)
3065 (ftake* '%jacobi_cd
(coeff u
'$%i
1) (add 1 (neg m
))))
3066 ((setq coef
(kc-arg2 u m
))
3069 (destructuring-bind (lin const
)
3071 (cond ((integerp lin
)
3075 ;; nd(2*m*K+u) = nd(u)
3079 (ftake '%jacobi_nd const m
)))
3081 ;; nd(2*m*K+K+u) = nd(K+u) = dn(u)/sqrt(1-m)
3082 ;; nd(K) = 1/sqrt(1-m)
3084 (power (sub 1 m
) -
1//2)
3085 (div (ftake '%jacobi_nd const m
)
3086 (power (sub 1 m
) 1//2))))))
3093 ;; jacobi_sc(u,m) = jacobi_sn/jacobi_cn
3097 ((mtimes) ((mexpt) ((%jacobi_cn
) u m
) -
2)
3101 ((mtimes) ((mexpt) ((%jacobi_cn
) u m
) -
1)
3103 ((mtimes) ((rat) 1 2)
3104 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3105 ((mexpt) ((%jacobi_cn
) u m
) 2)
3107 ((mtimes) ((rat) 1 2) ((mexpt) m -
1)
3108 ((%jacobi_cn
) u m
) ((%jacobi_dn
) u m
)
3111 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3112 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3114 ((mtimes) -
1 ((mexpt) ((%jacobi_cn
) u m
) -
2)
3117 ((mtimes) ((rat) -
1 2)
3118 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3120 ((mexpt) ((%jacobi_sn
) u m
) 2))
3121 ((mtimes) ((rat) -
1 2) ((mexpt) m -
1)
3122 ((%jacobi_dn
) u m
) ((%jacobi_sn
) u m
)
3125 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3126 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3130 (def-simplifier jacobi_sc
(u m
)
3133 ((float-numerical-eval-p u m
)
3134 (let ((fu (bigfloat:to
($float u
)))
3135 (fm (bigfloat:to
($float m
))))
3136 (to (bigfloat:/ (bigfloat::sn fu fm
) (bigfloat::cn fu fm
)))))
3137 ((setf args
(complex-float-numerical-eval-p u m
))
3138 (destructuring-bind (u m
)
3140 (let ((fu (bigfloat:to
($float u
)))
3141 (fm (bigfloat:to
($float m
))))
3142 (to (bigfloat:/ (bigfloat::sn fu fm
) (bigfloat::cn fu fm
))))))
3143 ((bigfloat-numerical-eval-p u m
)
3144 (let ((uu (bigfloat:to
($bfloat u
)))
3145 (mm (bigfloat:to
($bfloat m
))))
3146 (to (bigfloat:/ (bigfloat::sn uu mm
)
3147 (bigfloat::cn uu mm
)))))
3148 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
3149 (destructuring-bind (u m
)
3151 (let ((uu (bigfloat:to
($bfloat u
)))
3152 (mm (bigfloat:to
($bfloat m
))))
3153 (to (bigfloat:/ (bigfloat::sn uu mm
)
3154 (bigfloat::cn uu mm
))))))
3163 ((and $trigsign
(mminusp* u
))
3165 (neg (ftake* '%jacobi_sc
(neg u
) m
)))
3168 (member (caar u
) '(%inverse_jacobi_sn
3179 %inverse_jacobi_dc
))
3180 (alike1 (third u
) m
))
3181 (cond ((eq (caar u
) '%inverse_jacobi_sc
)
3184 ;; Express in terms of sn and cn
3185 ;; sc(x) = sn(x)/cn(x)
3186 (div (ftake '%jacobi_sn u m
)
3187 (ftake '%jacobi_cn u m
)))))
3188 ;; A&S 16.20 (Jacobi's Imaginary transformation)
3189 ((and $%iargs
(multiplep u
'$%i
))
3190 ;; sc(i*u) = sn(i*u)/cn(i*u) = i*sc(u,m1)/nc(u,m1) = i*sn(u,m1)
3192 (ftake* '%jacobi_sn
(coeff u
'$%i
1) (add 1 (neg m
)))))
3193 ((setq coef
(kc-arg2 u m
))
3195 ;; sc(2*m*K+u) = sc(u)
3196 (destructuring-bind (lin const
)
3198 (cond ((integerp lin
)
3201 ;; sc(2*m*K+ u) = sc(u)
3205 (ftake '%jacobi_sc const m
)))
3207 ;; sc(2*m*K + K + u) = sc(K+u)= - cs(u)/sqrt(1-m)
3210 (dbz-err1 'jacobi_sc
)
3212 (div (ftake* '%jacobi_cs const m
)
3213 (power (sub 1 m
) 1//2)))))))
3214 ((and (alike1 lin
1//2)
3216 ;; From A&S 16.3.3 and 16.5.2:
3217 ;; sc(1/2*K) = 1/(1-m)^(1/4)
3218 (power (sub 1 m
) (div -
1 4)))
3225 ;; jacobi_sd(u,m) = jacobi_sn/jacobi_dn
3229 ((mtimes) ((%jacobi_cn
) u m
)
3230 ((mexpt) ((%jacobi_dn
) u m
) -
2))
3233 ((mtimes) ((mexpt) ((%jacobi_dn
) u m
) -
1)
3235 ((mtimes) ((rat) 1 2)
3236 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3237 ((mexpt) ((%jacobi_cn
) u m
) 2)
3239 ((mtimes) ((rat) 1 2) ((mexpt) m -
1)
3240 ((%jacobi_cn
) u m
) ((%jacobi_dn
) u m
)
3243 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3244 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3246 ((mtimes) -
1 ((mexpt) ((%jacobi_dn
) u m
) -
2)
3249 ((mtimes) ((rat) -
1 2)
3250 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3252 ((mexpt) ((%jacobi_sn
) u m
) 2))
3253 ((mtimes) ((rat) -
1 2) ((%jacobi_cn
) u m
)
3257 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3258 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3262 (def-simplifier jacobi_sd
(u m
)
3265 ((float-numerical-eval-p u m
)
3266 (let ((fu (bigfloat:to
($float u
)))
3267 (fm (bigfloat:to
($float m
))))
3268 (to (bigfloat:/ (bigfloat::sn fu fm
) (bigfloat::dn fu fm
)))))
3269 ((setf args
(complex-float-numerical-eval-p u m
))
3270 (destructuring-bind (u m
)
3272 (let ((fu (bigfloat:to
($float u
)))
3273 (fm (bigfloat:to
($float m
))))
3274 (to (bigfloat:/ (bigfloat::sn fu fm
) (bigfloat::dn fu fm
))))))
3275 ((bigfloat-numerical-eval-p u m
)
3276 (let ((uu (bigfloat:to
($bfloat u
)))
3277 (mm (bigfloat:to
($bfloat m
))))
3278 (to (bigfloat:/ (bigfloat::sn uu mm
)
3279 (bigfloat::dn uu mm
)))))
3280 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
3281 (destructuring-bind (u m
)
3283 (let ((uu (bigfloat:to
($bfloat u
)))
3284 (mm (bigfloat:to
($bfloat m
))))
3285 (to (bigfloat:/ (bigfloat::sn uu mm
)
3286 (bigfloat::dn uu mm
))))))
3295 ((and $trigsign
(mminusp* u
))
3297 (neg (ftake* '%jacobi_sd
(neg u
) m
)))
3300 (member (caar u
) '(%inverse_jacobi_sn
3311 %inverse_jacobi_dc
))
3312 (alike1 (third u
) m
))
3313 (cond ((eq (caar u
) '%inverse_jacobi_sd
)
3316 ;; Express in terms of sn and dn
3317 (div (ftake '%jacobi_sn u m
)
3318 (ftake '%jacobi_dn u m
)))))
3319 ;; A&S 16.20 (Jacobi's Imaginary transformation)
3320 ((and $%iargs
(multiplep u
'$%i
))
3321 ;; sd(i*u) = sn(i*u)/dn(i*u) = i*sc(u,m1)/dc(u,m1) = i*sd(u,m1)
3323 (ftake* '%jacobi_sd
(coeff u
'$%i
1) (add 1 (neg m
)))))
3324 ((setq coef
(kc-arg2 u m
))
3326 ;; sd(4*m*K+u) = sd(u)
3327 (destructuring-bind (lin const
)
3329 (cond ((integerp lin
)
3332 ;; sd(4*m*K+u) = sd(u)
3336 (ftake '%jacobi_sd const m
)))
3338 ;; sd(4*m*K+K+u) = sd(K+u) = cn(u)/sqrt(1-m)
3339 ;; sd(K) = 1/sqrt(m1)
3341 (power (sub 1 m
) 1//2)
3342 (div (ftake '%jacobi_cn const m
)
3343 (power (sub 1 m
) 1//2))))
3345 ;; sd(4*m*K+2*K+u) = sd(2*K+u) = -sd(u)
3349 (neg (ftake '%jacobi_sd const m
))))
3351 ;; sd(4*m*K+3*K+u) = sd(3*K+u) = sd(2*K+K+u) =
3352 ;; -sd(K+u) = -cn(u)/sqrt(1-m)
3353 ;; sd(3*K) = -1/sqrt(m1)
3355 (neg (power (sub 1 m
) -
1//2))
3356 (neg (div (ftake '%jacobi_cn const m
)
3357 (power (sub 1 m
) 1//2)))))))
3358 ((and (alike1 lin
1//2)
3360 ;; jacobi_sn/jacobi_dn
3361 (div (ftake '%jacobi_sn
3363 (ftake '%elliptic_kc m
))
3367 (ftake '%elliptic_kc m
))
3375 ;; jacobi_cs(u,m) = jacobi_cn/jacobi_sn
3379 ((mtimes) -
1 ((%jacobi_dn
) u m
)
3380 ((mexpt) ((%jacobi_sn
) u m
) -
2))
3383 ((mtimes) -
1 ((%jacobi_cn
) u m
)
3384 ((mexpt) ((%jacobi_sn
) u m
) -
2)
3386 ((mtimes) ((rat) 1 2)
3387 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3388 ((mexpt) ((%jacobi_cn
) u m
) 2)
3390 ((mtimes) ((rat) 1 2) ((mexpt) m -
1)
3391 ((%jacobi_cn
) u m
) ((%jacobi_dn
) u m
)
3394 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3395 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3397 ((mtimes) ((mexpt) ((%jacobi_sn
) u m
) -
1)
3399 ((mtimes) ((rat) -
1 2)
3400 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3402 ((mexpt) ((%jacobi_sn
) u m
) 2))
3403 ((mtimes) ((rat) -
1 2) ((mexpt) m -
1)
3404 ((%jacobi_dn
) u m
) ((%jacobi_sn
) u m
)
3407 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3408 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3412 (def-simplifier jacobi_cs
(u m
)
3415 ((float-numerical-eval-p u m
)
3416 (let ((fu (bigfloat:to
($float u
)))
3417 (fm (bigfloat:to
($float m
))))
3418 (to (bigfloat:/ (bigfloat::cn fu fm
) (bigfloat::sn fu fm
)))))
3419 ((setf args
(complex-float-numerical-eval-p u m
))
3420 (destructuring-bind (u m
)
3422 (let ((fu (bigfloat:to
($float u
)))
3423 (fm (bigfloat:to
($float m
))))
3424 (to (bigfloat:/ (bigfloat::cn fu fm
) (bigfloat::sn fu fm
))))))
3425 ((bigfloat-numerical-eval-p u m
)
3426 (let ((uu (bigfloat:to
($bfloat u
)))
3427 (mm (bigfloat:to
($bfloat m
))))
3428 (to (bigfloat:/ (bigfloat::cn uu mm
)
3429 (bigfloat::sn uu mm
)))))
3430 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
3431 (destructuring-bind (u m
)
3433 (let ((uu (bigfloat:to
($bfloat u
)))
3434 (mm (bigfloat:to
($bfloat m
))))
3435 (to (bigfloat:/ (bigfloat::cn uu mm
)
3436 (bigfloat::sn uu mm
))))))
3444 (dbz-err1 'jacobi_cs
))
3445 ((and $trigsign
(mminusp* u
))
3447 (neg (ftake* '%jacobi_cs
(neg u
) m
)))
3450 (member (caar u
) '(%inverse_jacobi_sn
3461 %inverse_jacobi_dc
))
3462 (alike1 (third u
) m
))
3463 (cond ((eq (caar u
) '%inverse_jacobi_cs
)
3466 ;; Express in terms of cn an sn
3467 (div (ftake '%jacobi_cn u m
)
3468 (ftake '%jacobi_sn u m
)))))
3469 ;; A&S 16.20 (Jacobi's Imaginary transformation)
3470 ((and $%iargs
(multiplep u
'$%i
))
3471 ;; cs(i*u) = cn(i*u)/sn(i*u) = -i*nc(u,m1)/sc(u,m1) = -i*ns(u,m1)
3473 (ftake* '%jacobi_ns
(coeff u
'$%i
1) (add 1 (neg m
))))))
3474 ((setq coef
(kc-arg2 u m
))
3477 ;; cs(2*m*K + u) = cs(u)
3478 (destructuring-bind (lin const
)
3480 (cond ((integerp lin
)
3483 ;; cs(2*m*K + u) = cs(u)
3486 (dbz-err1 'jacobi_cs
)
3487 (ftake '%jacobi_cs const m
)))
3489 ;; cs(K+u) = -sqrt(1-m)*sc(u)
3493 (neg (mul (power (sub 1 m
) 1//2)
3494 (ftake '%jacobi_sc const m
)))))))
3495 ((and (alike1 lin
1//2)
3499 (ftake '%jacobi_sc
(mul 1//2
3500 (ftake '%elliptic_kc m
))
3508 ;; jacobi_cd(u,m) = jacobi_cn/jacobi_dn
3512 ((mtimes) ((mplus) -
1 m
)
3513 ((mexpt) ((%jacobi_dn
) u m
) -
2)
3517 ((mtimes) -
1 ((%jacobi_cn
) u m
)
3518 ((mexpt) ((%jacobi_dn
) u m
) -
2)
3520 ((mtimes) ((rat) -
1 2)
3521 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3523 ((mexpt) ((%jacobi_sn
) u m
) 2))
3524 ((mtimes) ((rat) -
1 2) ((%jacobi_cn
) u m
)
3528 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3529 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3531 ((mtimes) ((mexpt) ((%jacobi_dn
) u m
) -
1)
3533 ((mtimes) ((rat) -
1 2)
3534 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3536 ((mexpt) ((%jacobi_sn
) u m
) 2))
3537 ((mtimes) ((rat) -
1 2) ((mexpt) m -
1)
3538 ((%jacobi_dn
) u m
) ((%jacobi_sn
) u m
)
3541 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3542 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3546 (def-simplifier jacobi_cd
(u m
)
3549 ((float-numerical-eval-p u m
)
3550 (let ((fu (bigfloat:to
($float u
)))
3551 (fm (bigfloat:to
($float m
))))
3552 (to (bigfloat:/ (bigfloat::cn fu fm
) (bigfloat::dn fu fm
)))))
3553 ((setf args
(complex-float-numerical-eval-p u m
))
3554 (destructuring-bind (u m
)
3556 (let ((fu (bigfloat:to
($float u
)))
3557 (fm (bigfloat:to
($float m
))))
3558 (to (bigfloat:/ (bigfloat::cn fu fm
) (bigfloat::dn fu fm
))))))
3559 ((bigfloat-numerical-eval-p u m
)
3560 (let ((uu (bigfloat:to
($bfloat u
)))
3561 (mm (bigfloat:to
($bfloat m
))))
3562 (to (bigfloat:/ (bigfloat::cn uu mm
) (bigfloat::dn uu mm
)))))
3563 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
3564 (destructuring-bind (u m
)
3566 (let ((uu (bigfloat:to
($bfloat u
)))
3567 (mm (bigfloat:to
($bfloat m
))))
3568 (to (bigfloat:/ (bigfloat::cn uu mm
) (bigfloat::dn uu mm
))))))
3577 ((and $trigsign
(mminusp* u
))
3579 (ftake* '%jacobi_cd
(neg u
) m
))
3582 (member (caar u
) '(%inverse_jacobi_sn
3593 %inverse_jacobi_dc
))
3594 (alike1 (third u
) m
))
3595 (cond ((eq (caar u
) '%inverse_jacobi_cd
)
3598 ;; Express in terms of cn and dn
3599 (div (ftake '%jacobi_cn u m
)
3600 (ftake '%jacobi_dn u m
)))))
3601 ;; A&S 16.20 (Jacobi's Imaginary transformation)
3602 ((and $%iargs
(multiplep u
'$%i
))
3603 ;; cd(i*u) = cn(i*u)/dn(i*u) = nc(u,m1)/dc(u,m1) = nd(u,m1)
3604 (ftake* '%jacobi_nd
(coeff u
'$%i
1) (add 1 (neg m
))))
3605 ((setf coef
(kc-arg2 u m
))
3608 (destructuring-bind (lin const
)
3610 (cond ((integerp lin
)
3613 ;; cd(4*m*K + u) = cd(u)
3617 (ftake '%jacobi_cd const m
)))
3619 ;; cd(4*m*K + K + u) = cd(K+u) = -sn(u)
3623 (neg (ftake '%jacobi_sn const m
))))
3625 ;; cd(4*m*K + 2*K + u) = cd(2*K+u) = -cd(u)
3629 (neg (ftake '%jacobi_cd const m
))))
3631 ;; cd(4*m*K + 3*K + u) = cd(2*K + K + u) =
3636 (ftake '%jacobi_sn const m
)))))
3637 ((and (alike1 lin
1//2)
3639 ;; jacobi_cn/jacobi_dn
3640 (div (ftake '%jacobi_cn
3642 (ftake '%elliptic_kc m
))
3646 (ftake '%elliptic_kc m
))
3655 ;; jacobi_ds(u,m) = jacobi_dn/jacobi_sn
3659 ((mtimes) -
1 ((%jacobi_cn
) u m
)
3660 ((mexpt) ((%jacobi_sn
) u m
) -
2))
3663 ((mtimes) -
1 ((%jacobi_dn
) u m
)
3664 ((mexpt) ((%jacobi_sn
) u m
) -
2)
3666 ((mtimes) ((rat) 1 2)
3667 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3668 ((mexpt) ((%jacobi_cn
) u m
) 2)
3670 ((mtimes) ((rat) 1 2) ((mexpt) m -
1)
3671 ((%jacobi_cn
) u m
) ((%jacobi_dn
) u m
)
3674 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3675 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3677 ((mtimes) ((mexpt) ((%jacobi_sn
) u m
) -
1)
3679 ((mtimes) ((rat) -
1 2)
3680 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3682 ((mexpt) ((%jacobi_sn
) u m
) 2))
3683 ((mtimes) ((rat) -
1 2) ((%jacobi_cn
) u m
)
3687 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3688 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3692 (def-simplifier jacobi_ds
(u m
)
3695 ((float-numerical-eval-p u m
)
3696 (let ((fu (bigfloat:to
($float u
)))
3697 (fm (bigfloat:to
($float m
))))
3698 (to (bigfloat:/ (bigfloat::dn fu fm
) (bigfloat::sn fu fm
)))))
3699 ((setf args
(complex-float-numerical-eval-p u m
))
3700 (destructuring-bind (u m
)
3702 (let ((fu (bigfloat:to
($float u
)))
3703 (fm (bigfloat:to
($float m
))))
3704 (to (bigfloat:/ (bigfloat::dn fu fm
) (bigfloat::sn fu fm
))))))
3705 ((bigfloat-numerical-eval-p u m
)
3706 (let ((uu (bigfloat:to
($bfloat u
)))
3707 (mm (bigfloat:to
($bfloat m
))))
3708 (to (bigfloat:/ (bigfloat::dn uu mm
)
3709 (bigfloat::sn uu mm
)))))
3710 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
3711 (destructuring-bind (u m
)
3713 (let ((uu (bigfloat:to
($bfloat u
)))
3714 (mm (bigfloat:to
($bfloat m
))))
3715 (to (bigfloat:/ (bigfloat::dn uu mm
)
3716 (bigfloat::sn uu mm
))))))
3724 (dbz-err1 'jacobi_ds
))
3725 ((and $trigsign
(mminusp* u
))
3726 (neg (ftake* '%jacobi_ds
(neg u
) m
)))
3729 (member (caar u
) '(%inverse_jacobi_sn
3740 %inverse_jacobi_dc
))
3741 (alike1 (third u
) m
))
3742 (cond ((eq (caar u
) '%inverse_jacobi_ds
)
3745 ;; Express in terms of dn and sn
3746 (div (ftake '%jacobi_dn u m
)
3747 (ftake '%jacobi_sn u m
)))))
3748 ;; A&S 16.20 (Jacobi's Imaginary transformation)
3749 ((and $%iargs
(multiplep u
'$%i
))
3750 ;; ds(i*u) = dn(i*u)/sn(i*u) = -i*dc(u,m1)/sc(u,m1) = -i*ds(u,m1)
3752 (ftake* '%jacobi_ds
(coeff u
'$%i
1) (add 1 (neg m
))))))
3753 ((setf coef
(kc-arg2 u m
))
3755 (destructuring-bind (lin const
)
3757 (cond ((integerp lin
)
3760 ;; ds(4*m*K + u) = ds(u)
3763 (dbz-err1 'jacobi_ds
)
3764 (ftake '%jacobi_ds const m
)))
3766 ;; ds(4*m*K + K + u) = ds(K+u) = sqrt(1-m)*nc(u)
3767 ;; ds(K) = sqrt(1-m)
3769 (power (sub 1 m
) 1//2)
3770 (mul (power (sub 1 m
) 1//2)
3771 (ftake '%jacobi_nc const m
))))
3773 ;; ds(4*m*K + 2*K + u) = ds(2*K+u) = -ds(u)
3776 (dbz-err1 'jacobi_ds
)
3777 (neg (ftake '%jacobi_ds const m
))))
3779 ;; ds(4*m*K + 3*K + u) = ds(2*K + K + u) =
3780 ;; -ds(K+u) = -sqrt(1-m)*nc(u)
3781 ;; ds(3*K) = -sqrt(1-m)
3783 (neg (power (sub 1 m
) 1//2))
3784 (neg (mul (power (sub 1 m
) 1//2)
3785 (ftake '%jacobi_nc u m
)))))))
3786 ((and (alike1 lin
1//2)
3788 ;; jacobi_dn/jacobi_sn
3791 (mul 1//2 (ftake '%elliptic_kc m
))
3794 (mul 1//2 (ftake '%elliptic_kc m
))
3803 ;; jacobi_dc(u,m) = jacobi_dn/jacobi_cn
3807 ((mtimes) ((mplus) 1 ((mtimes) -
1 m
))
3808 ((mexpt) ((%jacobi_cn
) u m
) -
2)
3812 ((mtimes) ((mexpt) ((%jacobi_cn
) u m
) -
1)
3814 ((mtimes) ((rat) -
1 2)
3815 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3817 ((mexpt) ((%jacobi_sn
) u m
) 2))
3818 ((mtimes) ((rat) -
1 2) ((%jacobi_cn
) u m
)
3822 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3823 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3825 ((mtimes) -
1 ((mexpt) ((%jacobi_cn
) u m
) -
2)
3828 ((mtimes) ((rat) -
1 2)
3829 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3831 ((mexpt) ((%jacobi_sn
) u m
) 2))
3832 ((mtimes) ((rat) -
1 2) ((mexpt) m -
1)
3833 ((%jacobi_dn
) u m
) ((%jacobi_sn
) u m
)
3836 ((mexpt) ((mplus) 1 ((mtimes) -
1 m
)) -
1)
3837 ((%elliptic_e
) ((%asin
) ((%jacobi_sn
) u m
))
3841 (def-simplifier jacobi_dc
(u m
)
3844 ((float-numerical-eval-p u m
)
3845 (let ((fu (bigfloat:to
($float u
)))
3846 (fm (bigfloat:to
($float m
))))
3847 (to (bigfloat:/ (bigfloat::dn fu fm
) (bigfloat::cn fu fm
)))))
3848 ((setf args
(complex-float-numerical-eval-p u m
))
3849 (destructuring-bind (u m
)
3851 (let ((fu (bigfloat:to
($float u
)))
3852 (fm (bigfloat:to
($float m
))))
3853 (to (bigfloat:/ (bigfloat::dn fu fm
) (bigfloat::cn fu fm
))))))
3854 ((bigfloat-numerical-eval-p u m
)
3855 (let ((uu (bigfloat:to
($bfloat u
)))
3856 (mm (bigfloat:to
($bfloat m
))))
3857 (to (bigfloat:/ (bigfloat::dn uu mm
)
3858 (bigfloat::cn uu mm
)))))
3859 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
3860 (destructuring-bind (u m
)
3862 (let ((uu (bigfloat:to
($bfloat u
)))
3863 (mm (bigfloat:to
($bfloat m
))))
3864 (to (bigfloat:/ (bigfloat::dn uu mm
)
3865 (bigfloat::cn uu mm
))))))
3874 ((and $trigsign
(mminusp* u
))
3875 (ftake* '%jacobi_dc
(neg u
) m
))
3878 (member (caar u
) '(%inverse_jacobi_sn
3889 %inverse_jacobi_dc
))
3890 (alike1 (third u
) m
))
3891 (cond ((eq (caar u
) '%inverse_jacobi_dc
)
3894 ;; Express in terms of dn and cn
3895 (div (ftake '%jacobi_dn u m
)
3896 (ftake '%jacobi_cn u m
)))))
3897 ;; A&S 16.20 (Jacobi's Imaginary transformation)
3898 ((and $%iargs
(multiplep u
'$%i
))
3899 ;; dc(i*u) = dn(i*u)/cn(i*u) = dc(u,m1)/nc(u,m1) = dn(u,m1)
3900 (ftake* '%jacobi_dn
(coeff u
'$%i
1) (add 1 (neg m
))))
3901 ((setf coef
(kc-arg2 u m
))
3903 (destructuring-bind (lin const
)
3905 (cond ((integerp lin
)
3908 ;; dc(4*m*K + u) = dc(u)
3912 (ftake '%jacobi_dc const m
)))
3914 ;; dc(4*m*K + K + u) = dc(K+u) = -ns(u)
3917 (dbz-err1 'jacobi_dc
)
3918 (neg (ftake '%jacobi_ns const m
))))
3920 ;; dc(4*m*K + 2*K + u) = dc(2*K+u) = -dc(u)
3924 (neg (ftake '%jacobi_dc const m
))))
3926 ;; dc(4*m*K + 3*K + u) = dc(2*K + K + u) =
3928 ;; dc(3*K) = ns(0) = inf
3930 (dbz-err1 'jacobi_dc
)
3931 (ftake '%jacobi_dc const m
)))))
3932 ((and (alike1 lin
1//2)
3934 ;; jacobi_dn/jacobi_cn
3937 (mul 1//2 (ftake '%elliptic_kc m
))
3940 (mul 1//2 (ftake '%elliptic_kc m
))
3949 ;;; Other inverse Jacobian functions
3951 ;; inverse_jacobi_ns(x)
3953 ;; Let u = inverse_jacobi_ns(x). Then jacobi_ns(u) = x or
3954 ;; 1/jacobi_sn(u) = x or
3956 ;; jacobi_sn(u) = 1/x
3958 ;; so u = inverse_jacobi_sn(1/x)
3959 (defprop %inverse_jacobi_ns
3961 ;; Whittaker and Watson, example in 22.122
3962 ;; inverse_jacobi_ns(u,m) = integrate(1/sqrt(t^2-1)/sqrt(t^2-m), t, u, inf)
3963 ;; -> -1/sqrt(x^2-1)/sqrt(x^2-m)
3965 ((mexpt) ((mplus) -
1 ((mexpt) x
2)) ((rat) -
1 2))
3967 ((mplus) ((mtimes simp ratsimp
) -
1 m
) ((mexpt) x
2))
3970 ; ((%derivative) ((%inverse_jacobi_ns) x m) m 1)
3974 (def-simplifier inverse_jacobi_ns
(u m
)
3977 ((float-numerical-eval-p u m
)
3978 ;; Numerically evaluate asn
3980 ;; ans(x,m) = asn(1/x,m) = F(asin(1/x),m)
3981 (to (elliptic-f (cl:asin
(/ ($float u
))) ($float m
))))
3982 ((complex-float-numerical-eval-p u m
)
3983 (to (elliptic-f (cl:asin
(/ (complex ($realpart
($float u
)) ($imagpart
($float u
)))))
3984 (complex ($realpart
($float m
)) ($imagpart
($float m
))))))
3985 ((bigfloat-numerical-eval-p u m
)
3986 (to (bigfloat::bf-elliptic-f
(bigfloat:asin
(bigfloat:/ (bigfloat:to
($bfloat u
))))
3987 (bigfloat:to
($bfloat m
)))))
3988 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
3989 (destructuring-bind (u m
)
3991 (to (bigfloat::bf-elliptic-f
(bigfloat:asin
(bigfloat:/ (bigfloat:to
($bfloat u
))))
3992 (bigfloat:to
($bfloat m
))))))
3994 ;; ans(x,0) = F(asin(1/x),0) = asin(1/x)
3995 (ftake '%elliptic_f
(ftake '%asin
(div 1 u
)) 0))
3997 ;; ans(x,1) = F(asin(1/x),1) = log(tan(pi/2+asin(1/x)/2))
3998 (ftake '%elliptic_f
(ftake '%asin
(div 1 u
)) 1))
4000 (ftake '%elliptic_kc m
))
4002 (neg (ftake '%elliptic_kc m
)))
4003 ((and (eq $triginverses
'$all
)
4005 (eq (caar u
) '%jacobi_ns
)
4006 (alike1 (third u
) m
))
4007 ;; inverse_jacobi_ns(ns(u)) = u
4013 ;; inverse_jacobi_nc(x)
4015 ;; Let u = inverse_jacobi_nc(x). Then jacobi_nc(u) = x or
4016 ;; 1/jacobi_cn(u) = x or
4018 ;; jacobi_cn(u) = 1/x
4020 ;; so u = inverse_jacobi_cn(1/x)
4021 (defprop %inverse_jacobi_nc
4023 ;; Whittaker and Watson, example in 22.122
4024 ;; inverse_jacobi_nc(u,m) = integrate(1/sqrt(t^2-1)/sqrt((1-m)*t^2+m), t, 1, u)
4025 ;; -> 1/sqrt(x^2-1)/sqrt((1-m)*x^2+m)
4027 ((mexpt) ((mplus) -
1 ((mexpt) x
2)) ((rat) -
1 2))
4030 ((mtimes) -
1 ((mplus) -
1 m
) ((mexpt) x
2)))
4033 ; ((%derivative) ((%inverse_jacobi_nc) x m) m 1)
4037 (def-simplifier inverse_jacobi_nc
(u m
)
4038 (cond ((or (float-numerical-eval-p u m
)
4039 (complex-float-numerical-eval-p u m
)
4040 (bigfloat-numerical-eval-p u m
)
4041 (complex-bigfloat-numerical-eval-p u m
))
4043 (ftake '%inverse_jacobi_cn
($rectform
(div 1 u
)) m
))
4047 (mul 2 (ftake '%elliptic_kc m
)))
4048 ((and (eq $triginverses
'$all
)
4050 (eq (caar u
) '%jacobi_nc
)
4051 (alike1 (third u
) m
))
4052 ;; inverse_jacobi_nc(nc(u)) = u
4058 ;; inverse_jacobi_nd(x)
4060 ;; Let u = inverse_jacobi_nd(x). Then jacobi_nd(u) = x or
4061 ;; 1/jacobi_dn(u) = x or
4063 ;; jacobi_dn(u) = 1/x
4065 ;; so u = inverse_jacobi_dn(1/x)
4066 (defprop %inverse_jacobi_nd
4068 ;; Whittaker and Watson, example in 22.122
4069 ;; inverse_jacobi_nd(u,m) = integrate(1/sqrt(t^2-1)/sqrt(1-(1-m)*t^2), t, 1, u)
4070 ;; -> 1/sqrt(u^2-1)/sqrt(1-(1-m)*t^2)
4072 ((mexpt) ((mplus) -
1 ((mexpt simp ratsimp
) x
2))
4076 ((mtimes) ((mplus) -
1 m
) ((mexpt simp ratsimp
) x
2)))
4079 ; ((%derivative) ((%inverse_jacobi_nd) x m) m 1)
4083 (def-simplifier inverse_jacobi_nd
(u m
)
4084 (cond ((or (float-numerical-eval-p u m
)
4085 (complex-float-numerical-eval-p u m
)
4086 (bigfloat-numerical-eval-p u m
)
4087 (complex-bigfloat-numerical-eval-p u m
))
4088 (ftake '%inverse_jacobi_dn
($rectform
(div 1 u
)) m
))
4091 ((onep1 ($ratsimp
(mul (power (sub 1 m
) 1//2) u
)))
4092 ;; jacobi_nd(1/sqrt(1-m),m) = K(m). This follows from
4093 ;; jacobi_dn(sqrt(1-m),m) = K(m).
4094 (ftake '%elliptic_kc m
))
4095 ((and (eq $triginverses
'$all
)
4097 (eq (caar u
) '%jacobi_nd
)
4098 (alike1 (third u
) m
))
4099 ;; inverse_jacobi_nd(nd(u)) = u
4105 ;; inverse_jacobi_sc(x)
4107 ;; Let u = inverse_jacobi_sc(x). Then jacobi_sc(u) = x or
4108 ;; x = jacobi_sn(u)/jacobi_cn(u)
4115 ;; sn^2 = x^2/(1+x^2)
4117 ;; sn(u) = x/sqrt(1+x^2)
4119 ;; u = inverse_sn(x/sqrt(1+x^2))
4121 (defprop %inverse_jacobi_sc
4123 ;; Whittaker and Watson, example in 22.122
4124 ;; inverse_jacobi_sc(u,m) = integrate(1/sqrt(1+t^2)/sqrt(1+(1-m)*t^2), t, 0, u)
4125 ;; -> 1/sqrt(1+x^2)/sqrt(1+(1-m)*x^2)
4127 ((mexpt) ((mplus) 1 ((mexpt) x
2))
4131 ((mtimes) -
1 ((mplus) -
1 m
) ((mexpt) x
2)))
4134 ; ((%derivative) ((%inverse_jacobi_sc) x m) m 1)
4138 (def-simplifier inverse_jacobi_sc
(u m
)
4139 (cond ((or (float-numerical-eval-p u m
)
4140 (complex-float-numerical-eval-p u m
)
4141 (bigfloat-numerical-eval-p u m
)
4142 (complex-bigfloat-numerical-eval-p u m
))
4143 (ftake '%inverse_jacobi_sn
4144 ($rectform
(div u
(power (add 1 (mul u u
)) 1//2)))
4147 ;; jacobi_sc(0,m) = 0
4149 ((and (eq $triginverses
'$all
)
4151 (eq (caar u
) '%jacobi_sc
)
4152 (alike1 (third u
) m
))
4153 ;; inverse_jacobi_sc(sc(u)) = u
4159 ;; inverse_jacobi_sd(x)
4161 ;; Let u = inverse_jacobi_sd(x). Then jacobi_sd(u) = x or
4162 ;; x = jacobi_sn(u)/jacobi_dn(u)
4165 ;; = sn^2/(1-m*sn^2)
4169 ;; sn^2 = x^2/(1+m*x^2)
4171 ;; sn(u) = x/sqrt(1+m*x^2)
4173 ;; u = inverse_sn(x/sqrt(1+m*x^2))
4175 (defprop %inverse_jacobi_sd
4177 ;; Whittaker and Watson, example in 22.122
4178 ;; inverse_jacobi_sd(u,m) = integrate(1/sqrt(1-(1-m)*t^2)/sqrt(1+m*t^2), t, 0, u)
4179 ;; -> 1/sqrt(1-(1-m)*x^2)/sqrt(1+m*x^2)
4182 ((mplus) 1 ((mtimes) ((mplus) -
1 m
) ((mexpt) x
2)))
4184 ((mexpt) ((mplus) 1 ((mtimes) m
((mexpt) x
2)))
4187 ; ((%derivative) ((%inverse_jacobi_sd) x m) m 1)
4191 (def-simplifier inverse_jacobi_sd
(u m
)
4192 (cond ((or (float-numerical-eval-p u m
)
4193 (complex-float-numerical-eval-p u m
)
4194 (bigfloat-numerical-eval-p u m
)
4195 (complex-bigfloat-numerical-eval-p u m
))
4196 (ftake '%inverse_jacobi_sn
4197 ($rectform
(div u
(power (add 1 (mul m
(mul u u
))) 1//2)))
4201 ((eql 0 ($ratsimp
(sub u
(div 1 (power (sub 1 m
) 1//2)))))
4202 ;; inverse_jacobi_sd(1/sqrt(1-m), m) = elliptic_kc(m)
4204 ;; We can see this from inverse_jacobi_sd(x,m) =
4205 ;; inverse_jacobi_sn(x/sqrt(1+m*x^2), m). So
4206 ;; inverse_jacobi_sd(1/sqrt(1-m),m) = inverse_jacobi_sn(1,m)
4207 (ftake '%elliptic_kc m
))
4208 ((and (eq $triginverses
'$all
)
4210 (eq (caar u
) '%jacobi_sd
)
4211 (alike1 (third u
) m
))
4212 ;; inverse_jacobi_sd(sd(u)) = u
4218 ;; inverse_jacobi_cs(x)
4220 ;; Let u = inverse_jacobi_cs(x). Then jacobi_cs(u) = x or
4221 ;; 1/x = 1/jacobi_cs(u) = jacobi_sc(u)
4223 ;; u = inverse_sc(1/x)
4225 (defprop %inverse_jacobi_cs
4227 ;; Whittaker and Watson, example in 22.122
4228 ;; inverse_jacobi_cs(u,m) = integrate(1/sqrt(t^2+1)/sqrt(t^2+(1-m)), t, u, inf)
4229 ;; -> -1/sqrt(x^2+1)/sqrt(x^2+(1-m))
4231 ((mexpt) ((mplus) 1 ((mexpt simp ratsimp
) x
2))
4234 ((mtimes simp ratsimp
) -
1 m
)
4235 ((mexpt simp ratsimp
) x
2))
4238 ; ((%derivative) ((%inverse_jacobi_cs) x m) m 1)
4242 (def-simplifier inverse_jacobi_cs
(u m
)
4243 (cond ((or (float-numerical-eval-p u m
)
4244 (complex-float-numerical-eval-p u m
)
4245 (bigfloat-numerical-eval-p u m
)
4246 (complex-bigfloat-numerical-eval-p u m
))
4247 (ftake '%inverse_jacobi_sc
($rectform
(div 1 u
)) m
))
4249 (ftake '%elliptic_kc m
))
4254 ;; inverse_jacobi_cd(x)
4256 ;; Let u = inverse_jacobi_cd(x). Then jacobi_cd(u) = x or
4257 ;; x = jacobi_cn(u)/jacobi_dn(u)
4260 ;; = (1-sn^2)/(1-m*sn^2)
4264 ;; sn^2 = (1-x^2)/(1-m*x^2)
4266 ;; sn(u) = sqrt(1-x^2)/sqrt(1-m*x^2)
4268 ;; u = inverse_sn(sqrt(1-x^2)/sqrt(1-m*x^2))
4270 (defprop %inverse_jacobi_cd
4272 ;; Whittaker and Watson, example in 22.122
4273 ;; inverse_jacobi_cd(u,m) = integrate(1/sqrt(1-t^2)/sqrt(1-m*t^2), t, u, 1)
4274 ;; -> -1/sqrt(1-x^2)/sqrt(1-m*x^2)
4277 ((mplus) 1 ((mtimes) -
1 ((mexpt) x
2)))
4280 ((mplus) 1 ((mtimes) -
1 m
((mexpt) x
2)))
4283 ; ((%derivative) ((%inverse_jacobi_cd) x m) m 1)
4287 (def-simplifier inverse_jacobi_cd
(u m
)
4288 (cond ((or (complex-float-numerical-eval-p u m
)
4289 (complex-bigfloat-numerical-eval-p u m
))
4291 (ftake '%inverse_jacobi_sn
4292 ($rectform
(div (power (mul (sub 1 u
) (add 1 u
)) 1//2)
4293 (power (sub 1 (mul m
(mul u u
))) 1//2)))
4298 (ftake '%elliptic_kc m
))
4299 ((and (eq $triginverses
'$all
)
4301 (eq (caar u
) '%jacobi_cd
)
4302 (alike1 (third u
) m
))
4303 ;; inverse_jacobi_cd(cd(u)) = u
4309 ;; inverse_jacobi_ds(x)
4311 ;; Let u = inverse_jacobi_ds(x). Then jacobi_ds(u) = x or
4312 ;; 1/x = 1/jacobi_ds(u) = jacobi_sd(u)
4314 ;; u = inverse_sd(1/x)
4316 (defprop %inverse_jacobi_ds
4318 ;; Whittaker and Watson, example in 22.122
4319 ;; inverse_jacobi_ds(u,m) = integrate(1/sqrt(t^2-(1-m))/sqrt(t^2+m), t, u, inf)
4320 ;; -> -1/sqrt(x^2-(1-m))/sqrt(x^2+m)
4323 ((mplus) -
1 m
((mexpt simp ratsimp
) x
2))
4326 ((mplus) m
((mexpt simp ratsimp
) x
2))
4329 ; ((%derivative) ((%inverse_jacobi_ds) x m) m 1)
4333 (def-simplifier inverse_jacobi_ds
(u m
)
4334 (cond ((or (float-numerical-eval-p u m
)
4335 (complex-float-numerical-eval-p u m
)
4336 (bigfloat-numerical-eval-p u m
)
4337 (complex-bigfloat-numerical-eval-p u m
))
4338 (ftake '%inverse_jacobi_sd
($rectform
(div 1 u
)) m
))
4339 ((and $trigsign
(mminusp* u
))
4340 (neg (ftake* '%inverse_jacobi_ds
(neg u
) m
)))
4341 ((eql 0 ($ratsimp
(sub u
(power (sub 1 m
) 1//2))))
4342 ;; inverse_jacobi_ds(sqrt(1-m),m) = elliptic_kc(m)
4344 ;; Since inverse_jacobi_ds(sqrt(1-m), m) =
4345 ;; inverse_jacobi_sd(1/sqrt(1-m),m). And we know from
4346 ;; above that this is elliptic_kc(m)
4347 (ftake '%elliptic_kc m
))
4348 ((and (eq $triginverses
'$all
)
4350 (eq (caar u
) '%jacobi_ds
)
4351 (alike1 (third u
) m
))
4352 ;; inverse_jacobi_ds(ds(u)) = u
4359 ;; inverse_jacobi_dc(x)
4361 ;; Let u = inverse_jacobi_dc(x). Then jacobi_dc(u) = x or
4362 ;; 1/x = 1/jacobi_dc(u) = jacobi_cd(u)
4364 ;; u = inverse_cd(1/x)
4366 (defprop %inverse_jacobi_dc
4368 ;; Note: Whittaker and Watson, example in 22.122 says
4369 ;; inverse_jacobi_dc(u,m) = integrate(1/sqrt(t^2-1)/sqrt(t^2-m),
4370 ;; t, u, 1) but that seems wrong. A&S 17.4.47 says
4371 ;; integrate(1/sqrt(t^2-1)/sqrt(t^2-m), t, a, u) =
4372 ;; inverse_jacobi_cd(x,m). Lawden 3.2.8 says the same.
4373 ;; functions.wolfram.com says the derivative is
4374 ;; 1/sqrt(t^2-1)/sqrt(t^2-m).
4377 ((mplus) -
1 ((mexpt simp ratsimp
) x
2))
4381 ((mtimes simp ratsimp
) -
1 m
)
4382 ((mexpt simp ratsimp
) x
2))
4385 ; ((%derivative) ((%inverse_jacobi_dc) x m) m 1)
4389 (def-simplifier inverse_jacobi_dc
(u m
)
4390 (cond ((or (complex-float-numerical-eval-p u m
)
4391 (complex-bigfloat-numerical-eval-p u m
))
4392 (ftake '%inverse_jacobi_cd
($rectform
(div 1 u
)) m
))
4395 ((and (eq $triginverses
'$all
)
4397 (eq (caar u
) '%jacobi_dc
)
4398 (alike1 (third u
) m
))
4399 ;; inverse_jacobi_dc(dc(u)) = u
4405 ;; Convert an inverse Jacobian function into the equivalent elliptic
4408 ;; See A&S 17.4.41-17.4.52.
4409 (defun make-elliptic-f (e)
4412 ((member (caar e
) '(%inverse_jacobi_sc %inverse_jacobi_cs
4413 %inverse_jacobi_nd %inverse_jacobi_dn
4414 %inverse_jacobi_sn %inverse_jacobi_cd
4415 %inverse_jacobi_dc %inverse_jacobi_ns
4416 %inverse_jacobi_nc %inverse_jacobi_ds
4417 %inverse_jacobi_sd %inverse_jacobi_cn
))
4418 ;; We have some inverse Jacobi function. Convert it to the F form.
4419 (destructuring-bind ((fn &rest ops
) u m
)
4421 (declare (ignore ops
))
4425 (ftake '%elliptic_f
(ftake '%atan u
) m
))
4428 (ftake '%elliptic_f
(ftake '%atan
(div 1 u
)) m
))
4433 (mul (power m -
1//2)
4435 (power (add -
1 (mul u u
))
4443 (power (sub 1 (power u
2)) 1//2)))
4447 (ftake '%elliptic_f
(ftake '%asin u
) m
))
4452 (power (mul (sub 1 (mul u u
))
4453 (sub 1 (mul m u u
)))
4460 (power (mul (sub (mul u u
) 1)
4466 (ftake '%elliptic_f
(ftake '%asin
(div 1 u
)) m
))
4469 (ftake '%elliptic_f
(ftake '%acos
(div 1 u
)) m
))
4474 (power (add m
(mul u u
))
4482 (power (add 1 (mul m u u
))
4487 (ftake '%elliptic_f
(ftake '%acos u
) m
)))))
4489 (recur-apply #'make-elliptic-f e
))))
4491 (defmfun $make_elliptic_f
(e)
4494 (simplify (make-elliptic-f e
))))
4496 (defun make-elliptic-e (e)
4498 ((eq (caar e
) '$elliptic_eu
)
4499 (destructuring-bind ((ffun &rest ops
) u m
) e
4500 (declare (ignore ffun ops
))
4501 (ftake '%elliptic_e
(ftake '%asin
(ftake '%jacobi_sn u m
)) m
)))
4503 (recur-apply #'make-elliptic-e e
))))
4505 (defmfun $make_elliptic_e
(e)
4508 (simplify (make-elliptic-e e
))))
4511 ;; Eu(u,m) = integrate(jacobi_dn(v,m)^2,v,0,u)
4512 ;; = integrate(sqrt((1-m*t^2)/(1-t^2)),t,0,jacobi_sn(u,m))
4514 ;; Eu(u,m) = E(am(u),m)
4516 ;; where E(u,m) is elliptic-e above.
4519 ;; Lawden gives the following relationships
4521 ;; E(u+v) = E(u) + E(v) - m*sn(u)*sn(v)*sn(u+v)
4522 ;; E(u,0) = u, E(u,1) = tanh u
4524 ;; E(i*u,k) = i*sc(u,k')*dn(u,k') - i*E(u,k') + i*u
4526 ;; E(2*i*K') = 2*i*(K'-E')
4528 ;; E(u + 2*i*K') = E(u) + 2*i*(K' - E')
4530 ;; E(u+K) = E(u) + E - k^2*sn(u)*cd(u)
4531 (defun elliptic-eu (u m
)
4533 ;; E(u + 2*n*K) = E(u) + 2*n*E
4534 (let ((ell-k (to (elliptic-k m
)))
4535 (ell-e (elliptic-ec m
)))
4536 (multiple-value-bind (n u-rem
)
4537 (floor u
(* 2 ell-k
))
4540 (cond ((>= u-rem ell-k
)
4541 ;; 0 <= u-rem < K so
4542 ;; E(u + K) = E(u) + E - m*sn(u)*cd(u)
4543 (let ((u-k (- u ell-k
)))
4544 (- (+ (elliptic-e (cl:asin
(bigfloat::sn u-k m
)) m
)
4546 (/ (* m
(bigfloat::sn u-k m
) (bigfloat::cn u-k m
))
4547 (bigfloat::dn u-k m
)))))
4549 (elliptic-e (cl:asin
(bigfloat::sn u m
)) m
)))))))
4553 ;; E(u+i*v, m) = E(u,m) -i*E(v,m') + i*v + i*sc(v,m')*dn(v,m')
4554 ;; -i*m*sn(u,m)*sc(v,m')*sn(u+i*v,m)
4556 (let ((u-r (realpart u
))
4559 (+ (elliptic-eu u-r m
)
4562 (/ (* (bigfloat::sn u-i m1
) (bigfloat::dn u-i m1
))
4563 (bigfloat::cn u-i m1
)))
4564 (+ (elliptic-eu u-i m1
)
4565 (/ (* m
(bigfloat::sn u-r m
) (bigfloat::sn u-i m1
) (bigfloat::sn u m
))
4566 (bigfloat::cn u-i m1
))))))))))
4568 (defprop $elliptic_eu
4570 ((mexpt) ((%jacobi_dn
) u m
) 2)
4575 (def-simplifier elliptic_eu
(u m
)
4577 ;; as it stands, ELLIPTIC-EU can't handle bigfloats or complex bigfloats,
4578 ;; so handle only floats and complex floats here.
4579 ((float-numerical-eval-p u m
)
4580 (elliptic-eu ($float u
) ($float m
)))
4581 ((complex-float-numerical-eval-p u m
)
4582 (let ((u-r ($realpart u
))
4585 (complexify (elliptic-eu (complex u-r u-i
) m
))))
4589 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4590 ;; Integrals. At present with respect to first argument only.
4591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4593 ;; A&S 16.24.1: integrate(jacobi_sn(u,m),u)
4594 ;; = log(jacobi_dn(u,m)-sqrt(m)*jacobi_cn(u,m))/sqrt(m)
4597 ((mtimes simp
) ((mexpt simp
) m
((rat simp
) -
1 2))
4600 ((mtimes simp
) -
1 ((mexpt simp
) m
((rat simp
) 1 2))
4601 ((%jacobi_cn simp
) u m
))
4602 ((%jacobi_dn simp
) u m
))))
4606 ;; A&S 16.24.2: integrate(jacobi_cn(u,m),u) = acos(jacobi_dn(u,m))/sqrt(m)
4609 ((mtimes simp
) ((mexpt simp
) m
((rat simp
) -
1 2))
4610 ((%acos simp
) ((%jacobi_dn simp
) u m
)))
4614 ;; A&S 16.24.3: integrate(jacobi_dn(u,m),u) = asin(jacobi_sn(u,m))
4617 ((%asin simp
) ((%jacobi_sn simp
) u m
))
4621 ;; A&S 16.24.4: integrate(jacobi_cd(u,m),u)
4622 ;; = log(jacobi_nd(u,m)+sqrt(m)*jacobi_sd(u,m))/sqrt(m)
4625 ((mtimes simp
) ((mexpt simp
) m
((rat simp
) -
1 2))
4627 ((mplus simp
) ((%jacobi_nd simp
) u m
)
4628 ((mtimes simp
) ((mexpt simp
) m
((rat simp
) 1 2))
4629 ((%jacobi_sd simp
) u m
)))))
4633 ;; integrate(jacobi_sd(u,m),u)
4635 ;; A&S 16.24.5 gives
4636 ;; asin(-sqrt(m)*jacobi_cd(u,m))/sqrt(m*m_1), where m + m_1 = 1
4637 ;; but this does not pass some simple tests.
4639 ;; functions.wolfram.com 09.35.21.001.01 gives
4640 ;; -asin(sqrt(m)*jacobi_cd(u,m))*sqrt(1-m*jacobi_cd(u,m)^2)*jacobi_dn(u,m)/((1-m)*sqrt(m))
4641 ;; and this does pass.
4645 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
4646 ((mexpt simp
) m
((rat simp
) -
1 2))
4649 ((mtimes simp
) -
1 $m
((mexpt simp
) ((%jacobi_cd simp
) u m
) 2)))
4651 ((%jacobi_dn simp
) u m
)
4653 ((mtimes simp
) ((mexpt simp
) m
((rat simp
) 1 2))
4654 ((%jacobi_cd simp
) u m
))))
4658 ;; integrate(jacobi_nd(u,m),u)
4660 ;; A&S 16.24.6 gives
4661 ;; acos(jacobi_cd(u,m))/sqrt(m_1), where m + m_1 = 1
4662 ;; but this does not pass some simple tests.
4664 ;; functions.wolfram.com 09.32.21.0001.01 gives
4665 ;; sqrt(1-jacobi_cd(u,m)^2)*acos(jacobi_cd(u,m))/((1-m)*jacobi_sd(u,m))
4666 ;; and this does pass.
4669 ((mtimes simp
) ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
)) -
1)
4672 ((mtimes simp
) -
1 ((mexpt simp
) ((%jacobi_cd simp
) u m
) 2)))
4674 ((mexpt simp
) ((%jacobi_sd simp
) u m
) -
1)
4675 ((%acos simp
) ((%jacobi_cd simp
) u m
)))
4679 ;; A&S 16.24.7: integrate(jacobi_dc(u,m),u) = log(jacobi_nc(u,m)+jacobi_sc(u,m))
4682 ((%log simp
) ((mplus simp
) ((%jacobi_nc simp
) u m
) ((%jacobi_sc simp
) u m
)))
4686 ;; A&S 16.24.8: integrate(jacobi_nc(u,m),u)
4687 ;; = log(jacobi_dc(u,m)+sqrt(m_1)*jacobi_sc(u,m))/sqrt(m_1), where m + m_1 = 1
4691 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
))
4694 ((mplus simp
) ((%jacobi_dc simp
) u m
)
4696 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
))
4698 ((%jacobi_sc simp
) u m
)))))
4702 ;; A&S 16.24.9: integrate(jacobi_sc(u,m),u)
4703 ;; = log(jacobi_dc(u,m)+sqrt(m_1)*jacobi_nc(u,m))/sqrt(m_1), where m + m_1 = 1
4707 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
))
4710 ((mplus simp
) ((%jacobi_dc simp
) u m
)
4712 ((mexpt simp
) ((mplus simp
) 1 ((mtimes simp
) -
1 m
))
4714 ((%jacobi_nc simp
) u m
)))))
4718 ;; A&S 16.24.10: integrate(jacobi_ns(u,m),u)
4719 ;; = log(jacobi_ds(u,m)-jacobi_cs(u,m))
4723 ((mplus simp
) ((mtimes simp
) -
1 ((%jacobi_cs simp
) u m
))
4724 ((%jacobi_ds simp
) u m
)))
4728 ;; integrate(jacobi_ds(u,m),u)
4730 ;; A&S 16.24.11 gives
4731 ;; log(jacobi_ds(u,m)-jacobi_cs(u,m))
4732 ;; but this does not pass some simple tests.
4734 ;; functions.wolfram.com 09.30.21.0001.01 gives
4735 ;; log((1-jacobi_cn(u,m))/jacobi_sn(u,m))
4741 ((mplus simp
) 1 ((mtimes simp
) -
1 ((%jacobi_cn simp
) u m
)))
4742 ((mexpt simp
) ((%jacobi_sn simp
) u m
) -
1)))
4746 ;; A&S 16.24.12: integrate(jacobi_cs(u,m),u) = log(jacobi_ns(u,m)-jacobi_ds(u,m))
4750 ((mplus simp
) ((mtimes simp
) -
1 ((%jacobi_ds simp
) u m
))
4751 ((%jacobi_ns simp
) u m
)))
4755 ;; functions.wolfram.com 09.48.21.0001.01
4756 ;; integrate(inverse_jacobi_sn(u,m),u) =
4757 ;; inverse_jacobi_sn(u,m)*u
4758 ;; - log( jacobi_dn(inverse_jacobi_sn(u,m),m)
4759 ;; -sqrt(m)*jacobi_cn(inverse_jacobi_sn(u,m),m)) / sqrt(m)
4760 (defprop %inverse_jacobi_sn
4762 ((mplus simp
) ((mtimes simp
) u
((%inverse_jacobi_sn simp
) u m
))
4763 ((mtimes simp
) -
1 ((mexpt simp
) m
((rat simp
) -
1 2))
4766 ((mtimes simp
) -
1 ((mexpt simp
) m
((rat simp
) 1 2))
4767 ((%jacobi_cn simp
) ((%inverse_jacobi_sn simp
) u m
) m
))
4768 ((%jacobi_dn simp
) ((%inverse_jacobi_sn simp
) u m
) m
)))))
4772 ;; functions.wolfram.com 09.38.21.0001.01
4773 ;; integrate(inverse_jacobi_cn(u,m),u) =
4774 ;; u*inverse_jacobi_cn(u,m)
4775 ;; -%i*log(%i*jacobi_dn(inverse_jacobi_cn(u,m),m)/sqrt(m)
4776 ;; -jacobi_sn(inverse_jacobi_cn(u,m),m))
4778 (defprop %inverse_jacobi_cn
4780 ((mplus simp
) ((mtimes simp
) u
((%inverse_jacobi_cn simp
) u m
))
4781 ((mtimes simp
) -
1 $%i
((mexpt simp
) m
((rat simp
) -
1 2))
4784 ((mtimes simp
) $%i
((mexpt simp
) m
((rat simp
) -
1 2))
4785 ((%jacobi_dn simp
) ((%inverse_jacobi_cn simp
) u m
) m
))
4787 ((%jacobi_sn simp
) ((%inverse_jacobi_cn simp
) u m
) m
))))))
4791 ;; functions.wolfram.com 09.41.21.0001.01
4792 ;; integrate(inverse_jacobi_dn(u,m),u) =
4793 ;; u*inverse_jacobi_dn(u,m)
4794 ;; - %i*log(%i*jacobi_cn(inverse_jacobi_dn(u,m),m)
4795 ;; +jacobi_sn(inverse_jacobi_dn(u,m),m))
4796 (defprop %inverse_jacobi_dn
4798 ((mplus simp
) ((mtimes simp
) u
((%inverse_jacobi_dn simp
) u m
))
4799 ((mtimes simp
) -
1 $%i
4803 ((%jacobi_cn simp
) ((%inverse_jacobi_dn simp
) u m
) m
))
4804 ((%jacobi_sn simp
) ((%inverse_jacobi_dn simp
) u m
) m
)))))
4809 ;; Real and imaginary part for Jacobi elliptic functions.
4810 (defprop %jacobi_sn risplit-sn-cn-dn risplit-function
)
4811 (defprop %jacobi_cn risplit-sn-cn-dn risplit-function
)
4812 (defprop %jacobi_dn risplit-sn-cn-dn risplit-function
)
4814 (defun risplit-sn-cn-dn (expr)
4815 (let* ((arg (second expr
))
4816 (param (third expr
)))
4817 ;; We only split on the argument, not the order
4818 (destructuring-bind (arg-r . arg-i
)
4822 (cons (take (first expr
) arg-r param
)
4825 (let* ((s (ftake '%jacobi_sn arg-r param
))
4826 (c (ftake '%jacobi_cn arg-r param
))
4827 (d (ftake '%jacobi_dn arg-r param
))
4828 (s1 (ftake '%jacobi_sn arg-i
(sub 1 param
)))
4829 (c1 (ftake '%jacobi_cn arg-i
(sub 1 param
)))
4830 (d1 (ftake '%jacobi_dn arg-i
(sub 1 param
)))
4831 (den (add (mul c1 c1
)
4835 ;; Let s = jacobi_sn(x,m)
4836 ;; c = jacobi_cn(x,m)
4837 ;; d = jacobi_dn(x,m)
4838 ;; s1 = jacobi_sn(y,1-m)
4839 ;; c1 = jacobi_cn(y,1-m)
4840 ;; d1 = jacobi_dn(y,1-m)
4844 ;; jacobi_sn(x+%i*y,m) =
4846 ;; s*d1 + %i*c*d*s1*c1
4847 ;; -------------------
4850 (cons (div (mul s d1
) den
)
4851 (div (mul c
(mul d
(mul s1 c1
)))
4858 ;; c*c1 - %i*s*d*s1*d1
4859 ;; -------------------
4861 (cons (div (mul c c1
) den
)
4863 (mul s
(mul d
(mul s1 d1
))))
4870 ;; d*c1*d1 - %i*m*s*c*s1
4871 ;; ---------------------
4873 (cons (div (mul d
(mul c1 d1
))
4875 (div (mul -
1 (mul param
(mul s
(mul c s1
))))
4879 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4880 ;; Jacobi amplitude function.
4881 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4883 (def-simplifier jacobi_am
(u m
)
4890 ;; See https://dlmf.nist.gov/22.16.E4
4895 ;; See https://dlmf.nist.gov/22.16.E5. This is equivalent to
4896 ;; the Gudermannian function.
4898 ;; am(u,1) = 2*atan(exp(u))-%pi/2
4899 (sub (mul 2 (ftake '%atan
(ftake '%exp u
)))
4901 ((float-numerical-eval-p u m
)
4902 (to (bigfloat::bf-jacobi-am
($float u
)
4904 double-float-epsilon
)))
4905 ((setf args
(complex-float-numerical-eval-p u m
))
4906 (destructuring-bind (u m
)
4908 (to (bigfloat::bf-jacobi-am
(bigfloat:to
($float u
))
4909 (bigfloat:to
($float m
))
4910 double-float-epsilon
))))
4911 ((bigfloat-numerical-eval-p u m
)
4912 (to (bigfloat::bf-jacobi-am
(bigfloat:to
($bfloat u
))
4913 (bigfloat:to
($bfloat m
))
4914 (expt 2 (- fpprec
)))))
4915 ((setf args
(complex-bigfloat-numerical-eval-p u m
))
4916 (destructuring-bind (u m
)
4918 (to (bigfloat::bf-jacobi-am
(bigfloat:to
($bfloat u
))
4919 (bigfloat:to
($bfloat m
))
4920 (expt 2 (- fpprec
))))))
4925 ;; Derivative of jacobi_am wrt z and m.
4928 ;; WRT z. From http://functions.wolfram.com/09.24.20.0001.01
4930 ((%jacobi_dn
) $z $m
)
4931 ;; WRT m. From http://functions.wolfram.com/09.24.20.0003.01.
4932 ;; There are 5 different formulas listed; we chose the first,
4935 ;; (((m-1)*z+elliptic_e(jacobi_am(z,m),m))*jacobi_dn(z,m)
4936 ;; - m*jacobi_cn(z,m)*jacobi_sn(z,m))/(2*m*(m-1))
4937 ((mtimes) ((rat) 1 2) ((mexpt) ((mplus) -
1 $m
) -
1)
4940 ((mtimes) -
1 $m
((%jacobi_cn
) $z $m
) ((%jacobi_sn
) $z $m
))
4941 ((mtimes) ((%jacobi_dn
) $z $m
)
4942 ((mplus) ((mtimes) ((mplus) -
1 $m
) $z
)
4943 ((%elliptic_e
) ((%jacobi_am
) $z $m
) $m
)))))